Commit graph

3222 commits

Author SHA1 Message Date
Luke
ab1df177d8 LibWeb: Fully implement all comment tokenizer states 2020-06-14 13:47:19 +02:00
Andreas Kling
3cc0c477db LibWeb: Add basic <object> element support
This patch implements a simple <object> element with fallback content.
If the URL from the data attribute fails to load (including 404),
we render the DOM tree inside the <object> as fallback content.

This works by generating a different layout tree for the <object>
depending on the state and success of the data load. Since we cannot
currently do incremental layout tree updates, we have to force a
complete layout tree rebuild when the resource load finishes/fails.
2020-06-13 22:24:49 +02:00
Andreas Kling
95d70addd8 LibWeb: Split out image loading logic from HTMLImageElement
Since more DOM nodes are going to want to load images (<object>, ...)
this patch splits out the image loading logic into an ImageLoader class
and then HTMLImageElement simply has an ImageLoader.

LayoutImage is then given a const ImageLoader& at construction and can
then provide layout and rendering for many kinds of DOM nodes.
2020-06-13 22:22:54 +02:00
Andreas Kling
d6d248c328 LibWeb: Add "data" to HTML::AttributeNames 2020-06-13 22:21:25 +02:00
Andreas Kling
1678aaa555 ProtocolServer+LibProtocol: Propagate HTTP status codes to clients
Clients now receive HTTP status codes like 200, 404, etc.
Note that a 404 with content is still considered a "successful"
download from ProtocolServer's perspective. It's up to the client
to interpret the status code.

I'm not sure if this is the best API, but it'll work for now.
2020-06-13 22:20:37 +02:00
Andreas Kling
d9ece296f0 LibWeb: Fix LayoutImage stupidly painting backgrounds over itself
The good boy fix here would be to implement all of the CSS paint phases
but for now, let's at least not paint a background over our image. :^)
2020-06-13 22:18:12 +02:00
Andreas Kling
502b5b76c8 LibWeb: Have DOM nodes start out in "needs style update" state
Otherwise we won't get the first fully styled look until you interact
with the page (e.g via hovering an element.)
2020-06-13 20:10:43 +02:00
Andreas Kling
0e65fc3a6d LibWeb: Expand background:none into background-color:transparent 2020-06-13 20:03:41 +02:00
Andreas Kling
2650005af8 LibWeb: <link rel> is actually a space-separated list of tokens
...so when we check for rel=stylesheet, we have to split it up into
parts first. :^)
2020-06-13 20:02:36 +02:00
Andreas Kling
d200385c1a LibWeb: Sort style properties by name in the inspector window 2020-06-13 19:53:28 +02:00
Andreas Kling
1e15fa30e4 LibWeb: Don't try to be clever about -libweb-center relative position
Let's just say that -libweb-center centers the block in its containing
block for now. We can get fancy with relative offsets later.
2020-06-13 15:44:52 +02:00
Andreas Kling
1f48d5a80d LibWeb: Remove some unused functions in LayoutTableRow 2020-06-13 15:30:27 +02:00
Andreas Kling
e46ee46ed6 LibWeb: Silence debug spam about reuse of cached resources 2020-06-13 15:27:53 +02:00
Andreas Kling
7e8945601a LibWeb: Turn <td align> into CSS text-align
Note that align=center and align=middle both behave like the <center>
element, and not like text-align:center.
2020-06-13 15:16:56 +02:00
Andreas Kling
07ccaa1934 LibWeb: Teach line layout to collapse whitespace across fragments
This kind of HTML now produces a single piece of whitespace:

<span> </span> <span> </span> <span> </span>

We achieve this by checking if the last fragment on the last line ends
in whitespace. If so, we either don't add a fragment at all (for the
current chunk) or we simply skip over all whitespace at the head of
the current chunk (instead of collapsing it to a single ' '.)
2020-06-13 15:03:16 +02:00
Andreas Kling
47df0cbbc8 LibWeb: Fix broken tokenization of hexadecimal character references
We were interpreting 'A'-'F' as decimal digits which didn't work right.
2020-06-13 13:46:12 +02:00
Andreas Kling
784ed004e6 LibWeb: Implement <center> as -libweb-center
To get the expected behavior for <center>, we needed a special text
alignment mode that centers block-level elements (and not just line
box fragments.)
2020-06-13 12:49:20 +02:00
Andreas Kling
6de937a689 LibWeb: Turn <table bgcolor> into CSS background-color
More presentational attribute stuff. HN looking more and more like it's
supposed to. :^)
2020-06-13 12:49:20 +02:00
Andreas Kling
0b4f92e452 LibWeb: Tweak UA style to reset text-align on table elements
I think maybe this is only supposed to happen in quirks mode but I'm
not entirely sure. This makes "<center><table>..." behave as expected.
2020-06-13 12:49:20 +02:00
Matthew Olsson
e8e728454c AK: JsonParser improvements
- Parsing invalid JSON no longer asserts
    Instead of asserting when coming across malformed JSON,
    JsonParser::parse now returns an Optional<JsonValue>.
- Disallow trailing commas in JSON objects and arrays
- No longer parse 'undefined', as that is a purely JS thing
- No longer allow non-whitespace after anything consumed by the initial
  parse() call. Examples of things that were valid and no longer are:
    - undefineddfz
    - {"foo": 1}abcd
    - [1,2,3]4
- JsonObject.for_each_member now iterates in original insertion order
2020-06-13 12:43:22 +02:00
Andreas Kling
384b5f15c9 LibWeb: Sort matched style rules by specificity, document order
If two rules have equal specificity, they should be applied in the
order in which we encountered them.
2020-06-13 00:44:26 +02:00
Andreas Kling
fa5e8be31c LibWeb: Fix broken Specificity::operator== 2020-06-13 00:43:32 +02:00
Andreas Kling
ae3e5e9d37 LibWeb: Include selector pseudo-class in style sheet dumps 2020-06-13 00:43:06 +02:00
Andreas Kling
256898431c LibWeb: Simplify Node::is_link()
No need to check for presence of the href attribute as that is already
checked by enclosing_link_element().
2020-06-13 00:23:32 +02:00
Andreas Kling
483b371a7b LibWeb: Parse and match the :visited pseudo-class (always fails)
If we don't do this, something like "a:visited" is parsed as "a" which
may then take precedence over a previous "a:link" etc.
2020-06-13 00:23:30 +02:00
Andreas Kling
62893a54cc LibWeb: More work on table layout
Table row layout is now split into two phases:

1. Compute all the column widths (even taking colspan into account!)
2. Place all cells at the correct x,y offsets based on column widths.

Both phases visit all rows and all cells.
2020-06-13 00:12:23 +02:00
Andreas Kling
365703e3f3 LibWeb: Allow url("foo") and url('foo') in CSS background-image values
This is very hackish and will be fixed by writing a proper CSS parser.
2020-06-13 00:11:38 +02:00
Andreas Kling
0306ada1ff LibWeb: Add "colspan" to HTML::AttributeNames 2020-06-13 00:11:14 +02:00
Andreas Kling
0061a82be3 LibWeb: Add LayoutTableCell::colspan()
A convenient function for looking up a cell's colspan attribute.
2020-06-13 00:10:52 +02:00
Andreas Kling
196a3986d6 LibWeb: First cut of extremely naive table row layout
This first version simply auto-sizes all table cells and then places
them on a horizontal line.
2020-06-12 23:18:51 +02:00
Andreas Kling
c5a3d99dd5 LibWeb: Turn <table width> into the CSS width property 2020-06-12 22:52:38 +02:00
Andreas Kling
ca41c2e4a0 LibWeb: Turn <td bgcolor> into background-color 2020-06-12 22:47:51 +02:00
Andreas Kling
e9e2226544 LibWeb: Add "bgcolor" to HTML::AttributeNames 2020-06-12 22:47:41 +02:00
Andreas Kling
6f19067c9a LibWeb+Browser: Add a barebones LayoutTreeModel to the inspector window
This allows you to inspect the layout tree, along side the DOM tree.
It will need more functionality to be truly useful, but it's a start.
2020-06-12 22:30:11 +02:00
Andreas Kling
fdfda6dec2 AK: Make string-to-number conversion helpers return Optional
Get rid of the weird old signature:

- int StringType::to_int(bool& ok) const

And replace it with sensible new signature:

- Optional<int> StringType::to_int() const
2020-06-12 21:28:55 +02:00
Andreas Kling
c91981eba8 LibWeb: Handle negative values when collapsing vertical margins
In the presence of negative margins, we subtract the largest negative
margin from max(0, largest positive margin).
2020-06-12 18:47:18 +02:00
Andreas Kling
21b1f1653d LibWeb: Implement very basic margin collapsing
We now collapse a block's top margin with the previous sibling's
bottom margin so that the larger margin wins.
2020-06-12 18:47:18 +02:00
Andreas Kling
08f29be87a LibWeb: Remove absolutely positioned elements from the normal flow
Skip over absolutely positioned children when laying out the inline
children of a block. This takes them out of the flow and allows them
to be positioned correctly relative to the (absolute) containing block.
2020-06-12 15:27:52 +02:00
Andreas Kling
f3ea8d49a9 LibWeb: Remove absolute positioning logic from LayoutReplaced
Absolutely positioned elements are placed by their containing block.
Instead of trying to compute its own position, LayoutReplaced will
now simply add itself as an absolutely positioned descendant of its
containing block.
2020-06-12 15:24:33 +02:00
Andreas Kling
137f6d44ec LibWeb: Add basic support for position:fixed
Fixed position elements have the ICB as their containing block.
The magic of fixed positioning is implemented at the rendering stage,
where we temporarily translate painting by the current scroll offset.

Note that "absolutely positioned" includes both position:absolute
and position:fixed.
2020-06-12 14:20:07 +02:00
Andreas Kling
bd33bfd120 LibWeb: Whine about unrecognized CSS properties in debug log 2020-06-12 14:15:55 +02:00
Andreas Kling
9cbef10bdd LibWeb: Rename BoxModelMetrics::full_margin() => margin_box()
This matches the other member names (padding_box() and border_box().)
2020-06-12 13:44:11 +02:00
Andreas Kling
260427f0ad LibWeb: Some improvements to absolute positioning
Absolutely positioned blocks now register themselves with their
containing block (and note that the containing block of an absolutely
positioned box is the nearest non-statically positioned block ancestor
or the ICB as fallback.)

Containing blocks then drive the layout of their tracked absolutely
positioned descendants as a separate layout pass.

This is very far from perfect but the general direction seems good.
2020-06-12 13:43:46 +02:00
Andreas Kling
ff2c949d70 LibWeb: Include class names in layout tree dumps
This makes it a lot easier to see which layout node is which DOM node.
2020-06-12 13:23:07 +02:00
Matthew Olsson
78155a6668 LibJS: Consolidate error messages into ErrorTypes.h
Now, exceptions can be thrown with
interpreter.throw_exception<T>(ErrorType:TYPE, "format", "args",
"here").
2020-06-11 07:46:20 +02:00
Andreas Kling
01bb6f0249 LibWeb: Don't try to expand shorthands from non-string CSS values
If something is already e.g a length or a color value, we don't need
to try to expand it by stringifying and looking at the parts.
2020-06-10 19:34:49 +02:00
Andreas Kling
9c786cd7e0 LibWeb: Expand "background: url()" into "background-image: url()"
This gives us a yellow forehead on ACID2! :^)
2020-06-10 17:47:04 +02:00
Andreas Kling
2622ead6c6 LibWeb: Expand 2-part border-width shorthand CSS properties 2020-06-10 16:42:58 +02:00
Andreas Kling
7fe2f5f170 LibWeb: Apply style rules in order of specificity (kinda)
We now sort the matched rules by the specificity of the first selector
in them. This is not perfect, since a rule can have multiple selectors,
but it is a nice chin-related progression on ACID2. :^)
2020-06-10 16:42:36 +02:00
Andreas Kling
4e1939c635 LibWeb: Expand border-{top,right,bottom-left} CSS shorthand properties
This code is pretty rough, but it's something that will also improve
with the eventual new CSS parser.
2020-06-10 16:14:31 +02:00