Commit graph

3222 commits

Author SHA1 Message Date
Tim Ledbetter
6178557a07 LibWeb: Implement the HTMLInputElement.list attribute
This returns the `HTMLDataListElement` pointed to by the `list`
content attribute.
2025-03-09 15:10:55 +00:00
Aliaksandr Kalenik
868981a46b LibWeb: Skip animation invalidation for elements nested in display none
Paper over the fact we sometimes fail to cancel animations for elements
nested in display none, and do lots of wasted work.
2025-03-09 00:06:13 +01:00
Aliaksandr Kalenik
268143681e LibWeb: Don't drop layout tree in CSS animation invalidation
It's possible to do a partial tree rebuild instead.
2025-03-09 00:06:13 +01:00
Andreas Kling
067d21b8a4 LibWeb: Don't drop entire layout tree on media query state change
This isn't actually necessary, since we already invalidate style for the
entire document, and the subsequent style update will discover any
additional layout invalidation needed as well.
2025-03-08 20:22:01 +01:00
Andreas Kling
0a300fe59b LibWeb: Update the layout tree when CSS text-transform changes
Because we cache the transformed text string in text nodes affected by
text-transform, we have to actually update the layout tree when this
property value changes.
2025-03-08 20:22:01 +01:00
Andreas Kling
def0bcdfa2 LibWeb: Don't unconditionally relayout on animation/transition changes
If a CSS animation or transition was being used to manipulate a property
that itself does not affect layout, we were still doing a full relayout
whenever any animation or transition related property was changed.

As it turns out, we can just not do that, and we avoid a bunch of
unnecessary layout work on many pages. When a layout-affecting property
is being animated, the animation/transition update code takes care to
invalidate layout as appropriate anyway!

This was very noticeable on GitHub, where moving the mouse cursor
between "Issues" and "Pull requests" would trigger a full relayout every
time. Now that doesn't happen, and it's much more responsive. :^)
2025-03-08 17:32:53 +01:00
Aliaksandr Kalenik
a4463c45b9 LibWeb: Bring back cache of intrinsic sizes across layout runs
12c6ac78e2 with fixed mistake when cache
slot is copied instead of being referenced:
```cpp
auto cache =
    box.cached_intrinsic_sizes().min_content_height.ensure(width);
```
while it should've been:
```cpp
auto& cache =
    box.cached_intrinsic_sizes().min_content_height.ensure(width);
```
2025-03-08 14:52:33 +01:00
Andreas Kling
73a4b176cf Revert "LibWeb: Cache intrinsic sizes across layout runs"
This reverts commit 12c6ac78e2.

Very large performance regression when viewing GitHub repository pages.
2025-03-08 12:08:51 +01:00
Aliaksandr Kalenik
12c6ac78e2 LibWeb: Cache intrinsic sizes across layout runs
This change moves intrinsic sizes cache from
LayoutState, which is local to current layout run,
to layout nodes, so it could be reused between
layout runs. This optimization is possible because
we can guarantee that these measurements will
remain unchanged unless the style of the element
or any of its descendants changes.

For now, invalidation is implemented simply by
resetting cache on whole ancestors chain once we
figured that element needs layout update.
The case when layout is invalidated by DOM's
structural changes is covered by layout tree
invalidation that drops intrinsic sizes cache
along with layout nodes.

I measured improvement on couple websites:
- Mail list on GMail 28ms -> 6ms
- GitHub large code page 47ms -> 36ms
- Discord chat history 15ms -> 8ms
(Time does not include `commit()`)
2025-03-08 11:45:36 +01:00
Andreas Kling
180a58b3d2 LibWeb: Don't drop entire layout tree on <input type=file> update
This was completely unnecessary, and we can just let the internal
DOM tree changes trigger partial layout updates instead.

Noticed we were repeatedly dropping layout trees on ChatGPT and this
was one of the culprits.
2025-03-08 03:37:38 +01:00
Andreas Kling
6c6f9936e2 LibWeb: Avoid more unnecessary relayouts on CharacterData text change
If the CharacterData node has no layout node when we're changing its
text, we don't need to mark the document for relayout.

This is fine, because if the node ends up getting a layout node attached
to it, we'll naturally perform relayout after that anyway.
2025-03-08 03:37:38 +01:00
Andreas Kling
267b84ebb6 LibWeb: Skip flex/grid layout when doing intrinsic sizing for ancestor
We don't need to perform inside layout of flex and grid formatting
contexts when one of their ancestors is undergoing intrinsic size
measurement. This is because the parent formatting context will have
already sized the flex/grid container, and thus inside layout is
completely redundant work.
2025-03-08 03:37:38 +01:00
Andreas Kling
6444fdf5ae LibWeb: Remove unnecessary full layout tree drop in SVGUseElement
This full invalidation was just papering over earlier bugs in the
partial layout tree update code. The DOM mutations that happen here
should be enough to drive the necessary invalidation now.

Note that this is covered by a regression test added with the
invalidation.
2025-03-08 03:37:38 +01:00
Andreas Kling
2abbf99a95 LibWeb: Add opt-in tracing of set_needs_layout() calls with reason 2025-03-08 03:37:38 +01:00
Andreas Kling
415079bc11 LibWeb: Add opt-in tracing of invalidate_layout_tree() calls with reason 2025-03-08 03:37:38 +01:00
Andreas Kling
c333042e63 LibWeb: Add opt-in tracing of update_layout() calls with reason 2025-03-08 03:37:38 +01:00
Timothy Flynn
2c4b420acc LibWeb+LibWebView+WebContent: Inform the UI about DOM mutations
This will allow our DevTools server to inform the Firefox DevTools
client about DOM mutations.
2025-03-08 01:25:55 +01:00
Timothy Flynn
bf723aad98 LibWeb: Correctly set mutation record attribute namespace values
Here, we were setting the attribute_name string to the namespace string.
2025-03-08 01:25:55 +01:00
Timothy Flynn
3847d64542 LibWeb: Slightly delay queueing a character data mutation event
For DevTools, we will want to forward mutation events to the UI in order
to inform the DevTools client about changed DOM nodes. The API for this
requires the new values associated with the events; for example, for
character data events, this will be the node's new text data.

This patch moves the queueing of the mutation record until after we have
the new character data stored. This is not observable.
2025-03-08 01:25:55 +01:00
sideshowbarker
cf1425d09e LibWeb: Implement “suffering from overflow/underflow” for inputs
This change implements the requirements for the “suffering from an
overflow” and “suffering from an underflow” algorithms for
HTMLInputElement constraint validation.
2025-03-07 08:32:18 +00:00
Feng Yu
ad9f70dff9 LibWeb: Clean up unused module script fetching algorithms
This patch removes those unused 2 algorithms:
1. `fetch_internal_module_script_graph`
2. `fetch_descendants_of_a_module_script`

Those 2 algorithms were removed in spec and are not used in our
codebase.
2025-03-07 02:25:31 +01:00
Aliaksandr Kalenik
9b26f7eb0f LibWeb: Use partial layout tree rebuild in element's style invalidation
This allows us to avoid a full layout tree rebuild after change of
"display" property, which happens frequently in practice. It also
allows us to avoid a full rebuild after DOM node insertion, since
previously, computing styles for newly inserted nodes would trigger a
complete layout tree rebuild.
2025-03-06 23:48:34 +01:00
Luke Wilde
6d1f78198d LibWeb: Implement Resource Timing 2025-03-06 09:00:53 -07:00
Luke Wilde
23c84e62a5 LibWeb/Fetch: Update timing info with the timings received from RS 2025-03-06 09:00:53 -07:00
Luke Wilde
618697ef13 LibWeb: Make reference to global in report timing steps non-const
Marking a resource timing entry requires calling non-const methods on
the global object to append to the performance buffer.
2025-03-06 09:00:53 -07:00
Luke Wilde
67cfb64d07 LibWeb: Separate adding to performance buffers and queueing to observers
The User Timing, Resource Timing and Navigation Timing specifications
have not been updated to account for the queue method to also append to
the underlying performance buffer and it's method of checking it's
full.

This separates the functionality into a different function, with a flag
to indicate whether to use the custom full buffer logic or not.
2025-03-06 09:00:53 -07:00
Luke Wilde
209b10e53e RequestServer: Retrieve timing info from curl and pipe it to LibWeb
This timing info will be used to create a PerformanceResourceTiming
entry.
2025-03-06 09:00:53 -07:00
Shannon Booth
21d26c5c3e LibWeb/HTML: Implement valueAsNumber for 'time' input type 2025-03-06 09:01:18 -05:00
Shannon Booth
4bd4d777eb LibWeb/HTML: Use a helper for converting 'time' value to string
This will make it trivial to implement valueAsNumber for 'time' input
type.
2025-03-06 09:01:18 -05:00
Shannon Booth
f344eca39d LibWeb/HTML: Reuse number to date string conversion helper
This shares the code to convert to a date string for this algorithm
and the valueAsNumber implementation.
2025-03-06 09:01:18 -05:00
sideshowbarker
13f9670f20 LibWeb: Fix “step base” computation for HTMLInputElement
This change fixes a bug in our implementation of the “step base”
algorithm at https://html.spec.whatwg.org/#concept-input-min-zero. We
were using the “value” IDL/DOM attribute in a particular step, where the
spec instead actually requires using the “value” content attribute.
2025-03-06 09:00:22 -05:00
Luke Wilde
9ca25eed7f LibWeb/WebGL2: Implement EXT_color_buffer_float extension
This makes the Point Of Sale model on https://www.shopify.com/ have
colour instead of being completely black.
2025-03-06 12:59:28 +01:00
Gingeh
31853c13d3 LibWeb: Implement css gradient-interpolation-method 2025-03-06 11:33:12 +00:00
Andreas Kling
02a642b87b LibWeb: Prevent infinitely growing font size due to rem units in root
A font-size with rem units need to resolve against the default font
metrics for the root element, otherwise every time we compute style,
the reference value for rem units grows.

This fixes an issue where text on some web pages would grow every time
there was a relayout. This was very noticeable on https://proton.me/

Fixes #339
2025-03-05 22:46:06 +01:00
Aliaksandr Kalenik
dd78d5d50e LibWeb: Don't layout grid descendants in intrinsic layout mode
We already have a check to skip the layout of descendants if the
available size is intrinsic, but this is not sufficient in nested
intrinsic layout cases, where the available size might be definite even
though we are in intrinsic layout mode.
2025-03-05 21:40:59 +01:00
Aliaksandr Kalenik
b51c026f3d LibWeb: Don't layout flex descendants in intrinsic layout mode
We already have a check to skip the layout of descendants if the
available size is intrinsic, but this is not sufficient in nested
intrinsic layout cases, where the available size might be definite even
though we are in intrinsic layout mode.
2025-03-05 21:40:59 +01:00
Aliaksandr Kalenik
16b14273d1 Revert "LibWeb: Do not deform bitmaps partially outside the img-box"
This change broken image rendering.

This reverts commit e055927ead.
2025-03-05 19:44:49 +01:00
Lukas Scheller
ce93088a81 LibWeb: Respect margin boxes when center-aligning flex items 2025-03-05 18:07:10 +01:00
InvalidUsernameException
e055927ead LibWeb: Do not deform bitmaps partially outside the img-box
Instead of trying to manually determine which parts of a bitmap fall
within the box of the `<img>` element, just draw the whole bitmap and
let Skia clip the draw-area to the correct rectangle.

This fixes a bug where the entire bitmap was squashed into the rectangle
of the image box instead of being clipped.

With this change, image rendering is now correct enough to import some
of the WPT tests for object-fit and object-position. To get some good
coverage I have imported all tests for the `<img>` tag. I also wanted to
import a subset of the tests for the `<object>` tag, since those are
passing as well now. Unfortunately, they are flaky for unknown reasons.
2025-03-05 16:32:47 +01:00
sideshowbarker
7df9e00650 LibWeb: Implement HTMLInputElement type=email constraint validation
This change implements HTMLInputElement type=email constraint validation
in conformance with the current spec requirements (which happens to also
produce behavior that’s interoperable with other existing engines).
2025-03-05 13:20:08 +00:00
Tommy van der Vorst
056205aa76 LibWeb/CSS: Treat 'mask' as a longhand property
Before this change, an element masked with 'mask-image: url(...)' would
show the mask, but 'mask: url(...)' would not. On e.g. dialogic.nl it
would show white boxes instead of the actual images in the top
navigation bar. We still do not support many of the other mask
properties, but with this change at least the masks show up in both
cases.
2025-03-05 12:10:02 +00:00
Lucas CHOLLET
4bf197872b LibWeb/CSS: Remove an ad-hoc simplification step in calc() parsing 2025-03-05 12:05:45 +00:00
Lucas CHOLLET
715bf0de2c LibWeb/HTML: Implement ImageData initialization closer to spec 2025-03-05 11:35:27 +00:00
Shannon Booth
569ebeb6a4 LibWeb/URLPattern: Implement IDL interface for URLPattern test and exec
There is further work needed to complete the implementation of
URL::Pattern::Pattern, but this implements the remaining URLPattern
exec and test IDL interfaces, leaving all remaining work to LibURL.
2025-03-04 16:32:09 -05:00
Shannon Booth
ba93e2a8a3 LibWeb/URLPattern: Implement the URLPattern constructors
The underlying URL::Pattern implementation still has to be fully
implemented, but this does complete the IDL wrapper layer of the
implementation.
2025-03-04 16:32:09 -05:00
Shannon Booth
097f7fe169 LibWeb/Loader: Explicitly parse URL generating directory response
Removing one more caller of the implicit URL constructors.
2025-03-04 16:24:19 -05:00
Shannon Booth
277aceac98 LibWeb/HTML: Parse URL track URL before creating fetch request
This is a bit weird in the spec in it passing through a string here
instead of a URL record. However, the string being used in this
case should only ever be a valid URL string if it is not the empty
string.
2025-03-04 16:24:19 -05:00
Shannon Booth
1257d0c1a8 LibWeb/HTML: Explicitly basic parse URL when following the hyperlink
Instead of relying on the implicit URL constuctor. Parsing should
never fail here as urlString before adding the suffix is already
parsed above, and the suffix should only be a valid query string.
2025-03-04 16:24:19 -05:00
Shannon Booth
f857c6a6e6 LibWeb/HTML: Make HTMLImageRequests currentURL a String
This is the same type as what is spec'd. We cannot use a URL record
for this member as the spec in some scenarios will set and compare
the URL string to an invalid URL value, such as the empty string.

With implicit string constructors for the URL class removed
explicitly using URL::Parser::basic_parse makes the code look
quite silly in those places.
2025-03-04 16:24:19 -05:00
sideshowbarker
38197916c3 LibWeb: Implement HTMLInputElement type=url constraint validation
This change implements HTMLInputElement type=url constraint validation
in such a way as to match the behavior in other existing engines (which
is, however, very different from what the spec currently requires).
2025-03-04 19:15:40 +00:00