Commit graph

10658 commits

Author SHA1 Message Date
Kevin Meyer
e0f4fdc9b4 AK: Assert non-empty Utf32View, when initialized with non-zero length
This was useful in debugging a nullptr dereference, which was happening
through later, but was caused by this inconsistent initialization.
2020-06-15 22:32:18 +02:00
Andreas Kling
49cd03be95 LibWeb: Fix broken parsing of </form> during "in body" insertion 2020-06-15 20:31:19 +02:00
Andreas Kling
9bb4020195 LibWeb: Don't load stylesheets with rel="alternate"
We're not supposed to load these by default. Alternate stylesheets can
be offered in a menu or something, if the user is interested.
2020-06-15 20:31:18 +02:00
Andreas Kling
2f26d4c6a1 LibWeb: Fix broken parsing of </select> during "in select" insertion 2020-06-15 19:57:20 +02:00
Andreas Kling
17d26b92f8 LibWeb: Just ignore <script> elements that failed to load the script
We're never gonna be able to run them if we can't load them so just
let it go.
2020-06-15 18:37:48 +02:00
Andreas Kling
84f8c91a6f LibWeb: Use the URL encoder from AK instead of rolling a custom one 2020-06-15 17:56:00 +02:00
Andreas Kling
d883607e8f LibWeb: Force a full relayout if an element's CSS display changes
Not doing this was causing the wrong kind of LayoutNode to stay around
even though we had the final "display" value.
2020-06-15 17:56:00 +02:00
Andreas Kling
308c3ccc44 LibWeb: Allow block children of inlines
Hey, why not. We did all the hard work for display:inline-block already
and now we can just allow this.

This makes <a><h1>Hello friends!</h1></a> work :^)
2020-06-15 17:56:00 +02:00
Andreas Kling
96da15a8a4 LibWeb: Respect CSS z-index property while painting
To support z-ordering when painting, the layout tree now has a parallel
sparse tree of stacking contexts. The rules for which layout boxes
establish a stacking context are a bit complex, but the intent is to
encapsulate the decision making into establishes_stacking_context().

When we paint, we start from the ICB (LayoutDocument) who always has a
StackingContext and then paint the tree of StackingContexts where each
node has its children sorted by z-index.

This is pretty crude, but gets the basic job done. Note that this does
not yet support hit testing; hit testing is still done using a naive
treewalk from the root.
2020-06-15 17:56:00 +02:00
Andreas Kling
ce3260c6bf LibWeb: Layout nodes without own style can't be absolutely positioned
The only layout nodes that don't have their own style are LayoutText
(they inherit the style from their parent element since text cannot
be styled by CSS.)

However, it never makes sense for text nodes to have absolute position
so don't claim it.
2020-06-15 17:56:00 +02:00
Nico Weber
9825f7792b LibC: Add truncate().
Implemented in user space for now.
2020-06-15 17:34:52 +02:00
Andreas Kling
246e0e47ec LibWeb: Make the specificity sort comparator a bit more readable 2020-06-14 22:09:35 +02:00
Andreas Kling
9ad3e6cd8a LibWeb: Don't assert when containing block doesn't know how to place
We can just log that we don't know what to do for now.
2020-06-14 22:07:00 +02:00
Andreas Kling
0072370459 LibWeb: Don't animate images outside the visible viewport :^) 2020-06-14 19:35:10 +02:00
Andreas Kling
73c9f7ebf4 LibWeb: Move "visible in viewport" state tracking to ImageLoader
This should technically apply to any LayoutImage, so let's just move
it to ImageLoader.
2020-06-14 19:32:23 +02:00
Andreas Kling
c45615128b LibWeb: Move bitmap animation from HTMLImageElement to ImageLoader
Since ImageLoader manages the image decoder anyway, let it manage
animation as well.
2020-06-14 19:26:25 +02:00
Andreas Kling
63b1c8e882 LibWeb: Remove some unused functions from LayoutTable 2020-06-14 19:06:02 +02:00
Andreas Kling
ec39f419e5 LibWeb: Remove some unused functions from HTMLImageElement 2020-06-14 19:05:36 +02:00
Andreas Kling
c7d9229a0f LibWeb: Reorganize layout algorithm
Previously, layout recursively performed these steps (roughly):

1. Compute own width
2. Compute own position
3. Layout in-flow children
4. Compute own height
5. Layout absolutely positioned descendants

However, step (2) was pretty inconsistent. Some things computed their
own position, others had their parent do it for them, etc.
To get closer to CSS spec language, and make things easier in general,
this patch reorganizes the algorithm into:

1. Compute own width & height
2. Compute width & height of in-flow managed descendants
3. Move in-flow managed descendants to their final position
4. Layout absolutely positioned descendants

Block layout is now driven by the containing block, which will iterate
the descendants it's responsible for. There are a lot of inefficient
patterns in this logic right now, but they can easily be replaced with
better iteration functions once we settle on a long-term architecture.

Since the ICB (LayoutDocument) is at (0, 0), it doesn't rely on a
containing block to move it into place.

This code is still evolving along with my understanding of CSS layout,
so it's likely that we'll reorganize this again sooner or later. :^)
2020-06-14 19:01:54 +02:00
Andreas Kling
2b47ba6c3f LibWeb: Dump layout node style properties in alphabetical order 2020-06-14 18:47:21 +02:00
Andreas Kling
332c471301 LibWeb: Simplify LayoutBlock::layout_block_children() a little bit
No need to worry about inline children if children are not inline(!)
2020-06-14 16:48:17 +02:00
Andreas Kling
62615dfc31 LibWeb: Add LayoutNode::frame() reference getter
Any live layout tree always has a corresponding live Frame, as we will
never create a layout tree for a frameless document.
2020-06-14 16:45:45 +02:00
Andreas Kling
a93fb7299f LibWeb: Don't choke when trying to render a document-less <iframe>
Just paint it like an empty box if there's no document in the frame.
2020-06-14 15:32:38 +02:00
Luke
a01478c858 LibWeb: Fully implement HTML parser "in table" insertion mode
Also fixes some little mistakes in the "in body" insertion mode
that I found whilst cross-referencing.
2020-06-14 14:07:07 +02:00
Luke
6532c1e2fa LibWeb: Implement HTML parser "in column group" insertion mode 2020-06-14 14:07:07 +02:00
Luke
2241b09cd0 LibWeb: Implement HTML parser "in caption" insertion mode 2020-06-14 14:07:07 +02:00
Luke
a1838f676e LibWeb: Implement all CDATA tokenizer states
Even though we haven't implemented any switches to these states yet,
we may as well have them ready for when we do implement the switches.
2020-06-14 13:47:19 +02:00
Luke
821312729a LibWeb: Fully implement all DOCTYPE tokenizer states
Also fixes TagOpen having a seperate emit and reconsume in
ANYTHING_ELSE.
2020-06-14 13:47:19 +02:00
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
d51c1c136e LibGfx: Painter::draw_line() can just return early if alpha == 0 2020-06-13 20:38:36 +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
3bba163574 LibGfx: Add Color::Transparent as a named color 2020-06-13 20:03:19 +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
Paul Roukema
eb11ab2480 Base: Add some interlaced PNGs to the local copies of the pngsuite tests 2020-06-13 19:47:43 +02:00
Paul Roukema
b6147de1cb LibGfx: Implement support for decoding interlaced PNGs
This adds support for decoding the Adam7 interlacing used in some PNGs.
Notably this includes many of the images (such as the eyes) used in the acid2 test :^)
Note that the HTML engine still doesn't understand the <object> tag well enough to show the eyes on the test.
2020-06-13 19:47:43 +02:00
Paul Roukema
76553f9f06 LibGfx: Fix PNG decoder handling of 16-bit RGB images 2020-06-13 19:47:43 +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
bc5a862cbe LibGfx: Silence debug spam in the PNG decoder 2020-06-13 15:37:10 +02:00
Andreas Kling
1f48d5a80d LibWeb: Remove some unused functions in LayoutTableRow 2020-06-13 15:30:27 +02:00
Andreas Kling
dc0ed5c860 LibGfx: Don't keep an unused GIF decoder plugin in failed ImageDecoders
If we can't decode the input data, just have a null decoder. In this
state we simply return a null bitmap and whatever empty values make
sense for each API.

This way, we don't try to decode the same thing over and over since
it's not gonna work anyway. :^)
2020-06-13 15:29:29 +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