Commit graph

3229 commits

Author SHA1 Message Date
Luke Wilde
18b75afef8 LibWeb: Fire resize event at VisualViewport in the resize steps
Used on x.com to determine the layout to use on resize.
2025-01-29 09:23:52 +01:00
Luke Wilde
d21bac8028 LibWeb: Mark the Window resize event as trusted 2025-01-29 09:23:52 +01:00
Luke Wilde
f4649aa40d LibWeb/WebGL: Implement copyTexSubImage2D
Used by d3wasm for effects that use the current framebuffer as the
texture, such as screen wipes.
2025-01-28 19:01:40 +01:00
Luke Wilde
46f986bc2b LibWeb/WebGL: Implement copyTexImage2D
Used by d3wasm for effects that use the current framebuffer as the
texture, such as screen wipes.
2025-01-28 19:01:40 +01:00
Aliaksandr Kalenik
748d316973 LibWeb: Avoid separate tree traversal to mark for inherited style update
...in hover style invalidation. Instead, pass down a flag that indicates
all subsequent nodes in tree traversal have to be marked for inherited
style update.
2025-01-28 18:55:42 +01:00
Aliaksandr Kalenik
db47fa3db1 LibWeb: Use ancestor filters for hover style invalidation
By using ancestor filters some selectors could be early rejected
skipping selector engine invocation. According to my measurements it's
30-80% hover selectors depending on the website.
2025-01-28 18:55:42 +01:00
Aliaksandr Kalenik
b153420feb LibWeb: Reduce memory usage in hover style invalidation
Instead of allocating 3 vectors with size equal to the number of
elements potentially affected by hover:
- for the elements themselves
- for selector match state of each element before hovered node change
- for selector match state of each element after hovered node change

now we allocate none of them, but mark element for style recalculation
as we traverse the tree.
2025-01-28 18:55:42 +01:00
Shannon Booth
eca68aad88 LibWeb/FileAPI: Implement FileReader readAsBinaryString 2025-01-28 11:39:23 +00:00
Aliaksandr Kalenik
d79bb1aac2 LibWeb: Fix underinvalidation when inline style has custom properties
We have an optimization that allows us to invalidate only the style of
the element itself and mark descendants for inherited properties update
when the "style" attribute changes (unless there are any CSS rules that
use the "style" attribute, then we also invalidate all descendants that
might be affected by those rules). This optimization was not taking into
account that when the inline style has custom properties, we also need
to invalidate all descendants whose style might be affected by them.

This change fixes this bug by saving a flag in Element that indicates
whether its style depends on any custom properties and then invalidating
all descendants with this flag set when the "style" attribute changes.
Unlike font relative lengths invalidation, for elements that depend on
custom properties, we need to actually recompute the style, instead of
individual properties, because values without expanded custom properties
are gone after cascading, and it has to be done again.

The test added for this change is a version of an existing test we had
restructured such that it doesn't trigger aggressive style invalidation
caused by DOM structured changes until the last moment when test results
are printed.
2025-01-28 11:38:06 +00:00
Tim Ledbetter
8b5a25e47f LibWeb: Generate correct timestamp values when updating animations
Previously, we were generating timestamps relative to the current time
of the monotonic clock. We now generate timestamps relative to the
event loop's last render opportunity time, per the spec.
2025-01-28 11:31:46 +00:00
Psychpsyo
67ed676831 LibWeb: Implement CSS 'contain' property 2025-01-28 11:24:40 +00:00
Andreas Kling
c53c781745 LibWeb: Inline CSSStyleValue::to_keyword()
Shaves 120 ms of loading time off of https://wpt.fyi/
2025-01-28 01:12:45 +01:00
Andreas Kling
30cbd4bcfb LibWeb: Avoid unnecessary copies in BorderRadiusStyleValue::absolutize()
Shaves 30ms off of the load time on https://wpt.fyi/
2025-01-28 01:12:45 +01:00
Andreas Kling
b5e70908aa LibWeb: Segregate StyleComputer rule caches per Document-or-ShadowRoot
This means we only need to consider rules from the document and the
current shadow root, instead of the document and *every* shadow root.

Dramatically reduces the amount of rules processed on many pages.

Shaves 2.5 seconds of load time off of https://wpt.fyi/ :^)
2025-01-28 01:12:45 +01:00
Jelle Raaijmakers
e8bc6e9e8e LibWeb: Set float Y offset using margin box bottom instead of height
When positioning floats against an edge, we are taking all current
relevant floats at that side into account to determine the Y offset at
which to place the new float. However, we were using the margin box
height instead of the absolute bottom position, which disregards the
current float's Y-position within the root, and we were setting the Y
offset to that height, instead of taking the new float's Y position
inside of the root into account.

The new code determines the lowest margin bottom value within the root
of the current floats, and adds the difference between that value and
the new float's Y position to the Y offset.
2025-01-28 01:12:23 +01:00
Jelle Raaijmakers
0cfc7f2c8a LibWeb: Move LayoutState::set_content_* methods inline
I see no good reason to keep them out of line, and having the methods
named differently than the property they're updating caused me some
confusion initially.
2025-01-28 01:12:23 +01:00
Shannon Booth
d4649db55e LibWeb/URLPattern: Add initial stub for URLPattern interface 2025-01-27 18:07:17 +00:00
Tim Ledbetter
05351dfe45 LibWeb: Return wall time from PerformanceTiming interface
This matches the behavior of other browsers.
2025-01-27 14:53:33 +01:00
Tim Ledbetter
7488136a51 LibWeb: Report performance based timestamps relative to ESO time origin 2025-01-27 14:53:33 +01:00
Tim Ledbetter
8963e62a5e LibWeb: Add a time origin property for all ESOs
This acts as a baseline for performance related timestamps.
2025-01-27 14:53:33 +01:00
Tim Ledbetter
a8904451ff LibWeb: Set navigation start time when creating a new Document
This currently uses a non spec-compliant property on the Response
object, which represents the time that the Response was created.

Setting this value allows `Performance.timeOrigin` to return a
reasonable value.
2025-01-27 14:53:33 +01:00
Tim Ledbetter
ddea1c6248 LibWeb: Store response creation time as MonotonicTime
This non-standard value is used for calculating durations relative to
when the response was created. MonotonicTime is more suitable for this
use case.
2025-01-27 14:53:33 +01:00
devgianlu
f2e530ec14 LibCrypto: Make SECPxxxr1Signature carry the scalar size
Our `UnsignedBigInteger` implementation cannot handle numbers whose
size is not a multiple of 4. For this reason we need to carry the real
size around for P-521 support.
2025-01-27 12:24:48 +01:00
Shannon Booth
802529bafc LibWeb/HTML: Iterate over select options in tree order
This also saves us from iterating twice over the children, and
instead do it in a single pass.
2025-01-27 00:10:14 +00:00
Shannon Booth
4f80c7a5f3 LibWeb/DOM: Use as_if for node of type checks in iteration helpers
These are very hot functions in profiles, so let's avoid a potential
double dynamic_cast or virtual call. For consistency, port all of
these classes of function over to 'as_if' instead.
2025-01-27 00:10:14 +00:00
Shannon Booth
31dc1fa662 LibWeb/HTML: Only get list of options once in 'update selectedness'
It is not cheap to do this, so only do it once within this function.
There is definitely some caching that we can do here, but this will
require some smart invalidation to detect _relevant_ changes in
the children.
2025-01-27 00:10:14 +00:00
Shannon Booth
14eb081af8 LibWeb: Add missing calls to Base::children_changed
Also making sure that it is called at the top of the implementation
for consistency.
2025-01-27 00:10:14 +00:00
Shannon Booth
22a7cd9700 LibWeb: Port Document encoding_parse_url and parse_url to Optional<URL>
This ports two more APIs away from URL::is_valid.
2025-01-27 00:03:07 +00:00
Aliaksandr Kalenik
cfe9b7a82b LibWeb: Recompute relative units in Element::recompute_inherited_style()
Properties with relative units has to be recomputed in inherited style
update as they depend on the parent's style.

Fixes https://github.com/LadybirdBrowser/ladybird/issues/3364
2025-01-26 23:10:58 +01:00
Andreas Kling
f35152cf61 LibWeb: Defer entire-subtree style invalidations
Instead of traversing the entire DOM subtrees and marking nodes for
style update, this patch adds a new mechanism where we can mark a
subtree root as "entire subtree needs style update".

A new pass in Document::update_style() then takes care of coalescing
all these invalidations in a single traversal of the DOM.

This shaves *minutes* of loading time off of https://wpt.fyi/ subpages.
2025-01-26 22:58:42 +01:00
Jelle Raaijmakers
84c4702b10 LibWeb: Handle continuation chain during hit-testing instead of after it
My previous attempt at resolving the continuation chain tried to deal
with `pointer-events: none` by repeatedly falling back to the parent
paintable until one was found that _would_ want to handle pointer
events. But since we were no longer performing hit-tests on those
paintables, false positives could pop up. This could happen for
out-of-flow block elements that did not overlap with their parent rects,
for example.

This approach works much better since it only handles the continuation
case that's relevant (the "middle" anonymous box) and it does so during
hit-testing instead of after, allowing all the other relevant logic to
come into play.
2025-01-26 17:30:00 +01:00
Jelle Raaijmakers
522aa41667 LibWeb: Honor pointer-events for PaintableBox in own stacking context
If a block element with its own stacking context has `pointer-events:
none` set, it should be ignored as far as hit-testing goes.

Fixes #3357.
2025-01-26 17:30:00 +01:00
Andreas Kling
a87ae785fd LibWeb: Cache style sheet's default namespace in MatchingRule
This avoids looking up the default namespace rule for every rule we
consider running.

Shaves ~900ms of loading time off of https://wpt.fyi/
2025-01-26 15:07:23 +01:00
Andreas Kling
801b3f434f LibWeb: Avoid calling Element::is_shadow_host() for each CSS rule
Instead just cache the element's shadow root locally, if any. This
shaves ~1 second off the loading time of https://wpt.fyi/
2025-01-26 15:07:23 +01:00
Andreas Kling
e03aedbdf0 LibWeb: Add direct pointer to CSS::Selector in MatchingRule struct
This avoids looking up the selector by index repeatedly, giving us a
~400ms reduction in load time on https://wpt.fyi/
2025-01-26 15:07:23 +01:00
Aliaksandr Kalenik
9f75e26385 LibWeb: Add missing handler in affected_by_invalidation_property()
...for :placeholder-shown pseudo-class.
2025-01-26 00:52:38 +01:00
Aliaksandr Kalenik
aaff6f98b1 LibWeb: Fix collection of pseudo class names used in :has()
Before this change we were saving all pseudo class names as used in
:has() regardless of whether they are nested inside :has() or not.
2025-01-26 00:52:38 +01:00
Aliaksandr Kalenik
d5a82040e3 LibWeb: Fix underinvalidation of :nth-child using invalidation sets
For all invalidation properties nested into nth-child argument list we
need to invalidate whole subtree to make sure style of sibling elements
will be recalculated.
2025-01-25 10:16:21 +01:00
Luke Warlow
391a08bf17 LibWeb: Update spec comments for dialog, popover and close watcher 2025-01-25 03:40:08 +00:00
Jelle Raaijmakers
0bb0061915 LibWeb: Fire input events in .execCommand()
We do not fire `beforeinput` events since other browsers do not seem to
do so either.

The spec asks us to check whether a command's action modified the DOM
tree. This means adding or removing nodes and attributes, or changing
character data anywhere in the tree. We have
`Document::dom_tree_version()` for node updates, but for character data
a new version number is introduced that allows us to easily keep track
of any text changes in the entire tree.
2025-01-24 23:53:26 +01:00
Jelle Raaijmakers
10d011c75f LibWeb: Disable formatBlock editing command for plaintext-only
This is a spec issue:

  https://github.com/w3c/editing/issues/478
2025-01-24 23:53:26 +01:00
Jelle Raaijmakers
f731cffbd8 LibWeb: Refuse to recursively execute .execCommand()
Spec issue:

  https://github.com/w3c/editing/issues/477
2025-01-24 23:53:26 +01:00
Jelle Raaijmakers
0c854f9afc LibWeb: Return true if invalid color was provided to an editing command
Both Chrome and Firefox return `true` whenever the value string provided
is an invalid color or the current color. Spec issue raised:

  https://github.com/w3c/editing/issues/476
2025-01-24 23:53:26 +01:00
Jelle Raaijmakers
2b7ff194f8 LibWeb: Only record overrides for editing commands that require it
I forgot to implement the "If a command preserves overrides" part of the
spec.
2025-01-24 23:53:26 +01:00
Jelle Raaijmakers
486bce8dad LibWeb: Only clear command states and values if range actually changed 2025-01-24 23:53:26 +01:00
Andreas Kling
055f07d742 LibWeb: Avoid copying large MatchingRule objects inside StyleComputer
Instead of creating and passing around Vector<MatchingRule> inside
StyleComputer (internally, not exposed in API), we now use vectors
of pointers/references instead.

Note that we use pointers in case we want to quick_sort() the vectors.

Knocks 4 seconds of loading time off of https://wpt.fyi/
2025-01-24 17:54:34 +01:00
Andreas Kling
4bef0d0aea LibWeb: Don't rebuild rule cache so eagerly to check for :has/:defined
Instead, change the APIs from "has :foo" to "may have :foo" and return
true if we don't have a valid rule cache at the moment.

This allows us to defer the rebuilding of the rule cache until a later
time, for the cost of a wider invalidation at the moment.

Do note that if our rule cache is invalid, the whole document has
invalid style anyway! So this is actually always less work. :^)

Knocks ~1 second of loading time off of https://wpt.fyi/
2025-01-24 17:54:34 +01:00
Andreas Kling
3b3f06ca68 LibWeb: Add per-layer rule caches in StyleComputer
This allows us to filter by layer *once* instead of doing it for every
rule that runs.

Knocks ~2 seconds of loading time off of https://wpt.fyi/
2025-01-24 17:54:34 +01:00
Sam Atkins
e65ca3a7d2 LibWeb/CSS: Add Length::make_px(double) overload
Saves us a round-trip to CSSPixels and back when we already have a
double value.
2025-01-24 13:55:52 +01:00
Sam Atkins
38b037990b LibWeb/CSS: Remove Flex as a percentage basis
`<flex-percentage>` is not a thing.
2025-01-24 13:55:52 +01:00