Commit Graph

437 Commits

Author SHA1 Message Date
Andreas Kling
b6097cf724 LibWeb: Add fast_is<SVG::SVGSVGElement>() 2022-03-13 00:04:51 +01:00
Andreas Kling
ba606d9057 LibWeb: Move PaintingBox to its own .cpp and .h files 2022-03-11 00:21:49 +01:00
Andreas Kling
cb0c5390ff LibWeb: Move mouse event and label logic from layout to painting tree
Input events have nothing to do with layout, so let's not send them to
layout nodes.

The job of Paintable starts to become clear. It represents a paintable
item that can be rendered into the viewport, which means it can also
be targeted by the mouse cursor.
2022-03-11 00:21:49 +01:00
Andreas Kling
053766d79c LibWeb: Split Paintable into Paintable and PaintableBox
To prepare for paintable inline content, we take the basic painting
functionality and hoist it into a base class.
2022-03-11 00:21:49 +01:00
Andreas Kling
9461e44afa LibWeb: Use Layout::Box::paint_box() accessor in more places 2022-03-11 00:21:49 +01:00
Andreas Kling
f6497b64ac LibWeb: Rename Painting::Box => Paintable
Calling this "Box" made it very confusing to look at code that used both
Layout::Box and Painting::Box. Let's try calling it Paintable instead.
2022-03-11 00:21:49 +01:00
Andreas Kling
9f5cbcaad3 LibWeb: Hang StackingContext off of the paint boxes
Stacking contexts have nothing to do with layout and everything with
painting, so let's keep them in Painting::Box.
2022-03-11 00:21:49 +01:00
Andreas Kling
a4d51b3dc2 LibWeb: Add Painting::Box and move things from Layout::Box into it
The "paintable" state in Layout::Box was actually not safe to access
until after layout had been performed.

As a first step towards making this harder to mess up accidentally,
this patch moves painting information from Layout::Box to a new class:
Painting::Box. Every layout can have a corresponding paint box, and
it holds the final used metrics determined by layout.

The paint box is created and populated by FormattingState::commit().

I've also added DOM::Node::paint_box() as a convenient way to access
the paint box (if available) of a given DOM node.

Going forward, I believe this will allow us to better separate data
that belongs to layout vs painting, and also open up opportunities
for naturally invalidating caches in the paint box (since it's
reconstituted by every layout.)
2022-03-11 00:21:49 +01:00
Sam Atkins
6de2b62906 LibWeb: Display pseudo-elements in the DOM inspector
This patch only makes them appear in the tree - they are not yet
inspectable themselves.
2022-03-10 17:30:09 +01:00
Ben Abraham
7594350376 Browser: Show currently loading host and remaining resource count 2022-03-10 00:51:05 +01:00
Andreas Kling
6499cf4d28 LibWeb: Always relayout document on element style change
Let's get this right before trying to make it fast. This patch removes
the code that tried to do less work when an element's style changes,
and instead simply invalidates the entire document.

Note that invalidations are still coalesced, and will not be
synchronized until update_style() and/or update_layout() is used.
2022-03-09 18:14:24 +01:00
Andreas Kling
bca3c2a443 LibWeb: Always call update_style() in update_layout()
If the style is dirty, update_style() may cause layout to become dirty.
Therefore we must always update style when updating layout, to ensure
up-to-date results.
2022-03-09 18:14:24 +01:00
Andreas Kling
c988cbb8b1 LibWeb: Invalidate document style when a node is removed
This forces us to recompute style everywhere, since all kinds of
selectors may produce different results now.

In the future, we should look at narrowing down the invalidation that
occurs here, but for now let's just invalidate everything and make the
results correct before worrying about performance.
2022-03-09 18:14:24 +01:00
Andreas Kling
9c6999ecf2 LibWeb: Implement "NodeIterator pre-removing steps"
These steps run when a node is about to be removed from its parent,
and adjust the position of any live NodeIterators so that they don't
point at a now-removed node.

Note that while this commit implements what's in the DOM specification,
the specification doesn't fully match what other browsers do.

Spec bug: https://github.com/whatwg/dom/issues/907
2022-03-09 16:43:56 +01:00
Andreas Kling
acbdb95b0a LibWeb: Add support for DOM's TreeWalker
This patch adds TreeWalker (created via Document.createTreeWalker())
which allows you to traverse a filtered view of the DOM in all
directions.
2022-03-09 16:43:55 +01:00
Andreas Kling
fabcee016f LibWeb: Add basic support for DOM's NodeIterator and NodeFilter
This patch adds NodeIterator (created via Document.createNodeIterator())
which allows you to iterate through all the nodes in a subtree while
filtering with a provided NodeFilter callback along the way.

This first cut implements the full API, but does not yet handle nodes
being removed from the document while referenced by the iterator. That
will be done in a subsequent patch.
2022-03-09 16:43:00 +01:00
networkException
3e7869d57d LibWeb: Remove outdated FIXME comment in Namespaces validate_and_extract
As step "2. Validate qualifiedName" got implemented in
bfa7aad0f6, parts is known to have a
length of 2.
2022-03-08 16:23:35 +01:00
Linus Groh
0706f0d487 LibWeb: Move Timer from DOM directory & namespace to HTML
Timers are part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timers
2022-03-08 00:30:30 +01:00
Linus Groh
1422bd45eb LibWeb: Move Window from DOM directory & namespace to HTML
The Window object is part of the HTML spec. :^)
https://html.spec.whatwg.org/multipage/window-object.html
2022-03-08 00:30:30 +01:00
Sam Atkins
deea129b8c LibWeb: Add Ratio type to MediaFeatureValue
As noted, the Parser can't handle the `<number>` syntax for this - it
gets parsed instead by the `<number>` branch. We can't actually resolve
the ambiguity without making the Parser aware of what type each
media-feature is, but I will get to that soon. :^)
2022-03-07 13:42:25 +01:00
Sam Atkins
e30bfabbca LibWeb: Correct "color" media-feature value
This is bits per color channel, not bits per pixel, so 32 was a little
over-optimistic. :^)
2022-03-07 13:42:25 +01:00
Luke Wilde
8d05c4a675 LibWeb: Fire resize event at the Window instead of Document
The spec says "fire an event named resize at the Window object
associated with doc."

However, we were accidentally firing it at `doc` instead of the Window.
2022-03-06 15:35:10 +01:00
Linus Groh
2f021e92a5 LibWeb: Add Window::browsing_context()
https://html.spec.whatwg.org/multipage/window-object.html#window-bc

> The Window object's browsing context is the Window object's associated
> Document's browsing context.
> NOTE: It is either null or a browsing context.
2022-03-05 10:24:53 +01:00
Andreas Kling
7d052250f2 LibWeb: Don't create unwanted layout nodes when recomputing style
When recomputing the style for an element that previously didn't have
a corresponding layout node, it may become necessary to create a layout
node for it.

However, we should not do this if it's within a subtree that can't have
layout children. Nor should we do it for elements who have an ancestor
with display:none.
2022-03-04 23:40:21 +01:00
Timothy Flynn
18b9d02edd LibWeb: Implement setTimeout/setInterval with ESO according to the spec
Our setInterval implementation currently crashes on DuckDuckGo when it's
invoked with a string argument. In this path, we were creating a native
function to evaluate and execute that string. That evaluation was always
returning a Completion, but NativeFunction expects ThrowCompletionOr.
The conversion from Completion to ThrowCompletionOr would fail a VERIFY
because that conversion is only valid if the Completion is an error; but
we would trigger this conversion even on success.

This change re-implements setTimeout & setInterval in direct accordance
with the spec. So we avoid making that NativeFunction altogether, and
DDG can progress past its invocation to the timer. With this change, we
also have other features we did not previously support, such as passing
any number of arguments to the timers. This does not implement handling
of nesting levels yet.
2022-03-04 19:51:26 +01:00
Andreas Kling
205208db11 LibWeb: Reduce HashMap thrashing during custom property cascade
Build the final custom property map right away instead of first making
a temporary pointer-only map. We also precompute the final needed
capacity for the map to avoid incremental rehashing.
2022-03-03 13:56:37 +01:00
Andreas Kling
e4fdb40158 LibWeb: Use FlyString for CSS custom property names 2022-03-03 13:56:37 +01:00
Andreas Kling
88aa356606 LibWeb: Update element style when focus state changes
To ensure that :focus rules get included (or excluded), we have to
update style whenever focus moves.
2022-03-03 13:24:03 +01:00
Andreas Kling
9888e29c14 LibWeb: Streamline Node::enclosing_link_element() somewhat
No need to verify_cast repeatedly once we've confirmed the type.
2022-03-02 17:40:18 +01:00
Andreas Kling
ad9f3f7ae6 LibWeb: Add fast_is<T> for HTML::HTMLAnchorElement
We were spending 20% of style computation time on the HTML spec on
deciding whether DOM nodes were HTML anchor (a) tags or not.
2022-03-02 17:40:18 +01:00
Andreas Kling
bfa7aad0f6 LibWeb: Support (and validate) prefixes in Document.createElementNS()
1% progression on ACID3. :^)
2022-03-02 10:55:16 +01:00
Andreas Kling
4fb67c1621 LibWeb: Fix logic error in Document::validate_qualified_name()
We were mixing up the "name character" and "name start character"
validation checks. Also, we were not checking the first character after
a colon against the "name start character" set.
2022-03-02 10:53:38 +01:00
Andreas Kling
7231c1c895 LibWeb: Fix bogus result from "validate and extract" DOM operation
We were returning a QualifiedName with the localName and namespace
fields swapped.
2022-03-02 10:21:57 +01:00
Andreas Kling
05e9dceba6 LibWeb: Support DOMImplementation.createDocument() doctype parameter
1% progression on ACID3. :^)
2022-03-02 09:18:19 +01:00
Andreas Kling
cd5c17d88e LibWeb: Improve Layout::Box has-definite-size? computation
We now consider a layout box as having definite size in these cases:

- The size is a <length>.
- The size is a <percentage> and the containing block has definite size.

This is not complete, but a bit more accurate than what we had before.
2022-02-28 14:17:44 +01:00
Idan Horowitz
feb00b7105 Everywhere: Make JSON serialization fallible
This allows us to eliminate a major source of infallible allocation in
the Kernel, as well as lay down the groundwork for OOM fallibility in
userland.
2022-02-27 20:37:57 +01:00
Andreas Kling
262488ea33 LibWeb: Validate the qualified name in createDocumentType()
1% progression on ACID3. :^)
2022-02-26 17:26:37 +01:00
Andreas Kling
f855cbac92 LibWeb: Add simple ad-hoc version of window.postMessage()
This allows us to use the wpt.live copy of the ACID3 test, which is kept
updated, unlike the acidtests.org version.
2022-02-26 17:21:40 +01:00
Andreas Kling
fc5e414596 LibWeb: Reorganize window.parent so it looks a bit more like the spec 2022-02-26 16:03:06 +01:00
Luke Wilde
ad5fb1fd7e LibWeb: Implement Range.comparePoint 2022-02-26 12:53:32 +01:00
Luke Wilde
62b76e0658 LibWeb: Implement Range.isPointInRange 2022-02-26 12:53:32 +01:00
Luke Wilde
386ee5ab17 LibWeb: Implement Range.intersectsNode 2022-02-26 12:53:32 +01:00
Luke Wilde
4c08757ff9 LibWeb: Add Range.detach 2022-02-26 12:53:32 +01:00
Luke Wilde
8a755726ad LibWeb: Implement Range.selectNodeContents 2022-02-26 12:53:32 +01:00
Luke Wilde
2b2dbdc74f LibWeb: Implement Range.collapse 2022-02-26 12:53:32 +01:00
Luke Wilde
dfdc2ddb9e LibWeb: Implement Range.selectNode 2022-02-26 12:53:32 +01:00
Luke Wilde
a26f1b2ff9 LibWeb: Implement Range.compareBoundaryPoints 2022-02-26 12:53:32 +01:00
Luke Wilde
d73fb7e10f LibWeb: Implement Range.set{Start,End}{Before,After} 2022-02-26 12:53:32 +01:00
Luke Wilde
46ce50f74e LibWeb: Make Range.setStart and Range.setEnd spec compliant
These functions are way more involved than simply setting their
respective boundary points :^)
2022-02-26 12:53:32 +01:00
Luke Wilde
3d44118595 LibWeb: Implement StaticRange 2022-02-26 12:53:32 +01:00