Commit graph

8835 commits

Author SHA1 Message Date
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
Tim Ledbetter
c3680a02a7 LibWebView: Don't add '.com' to valid TLD when Ctrl is pressed
If Ctrl is pressed when a string is entered into the location bar and
that string doesn't contain a valid TLD, ".com" is added to that string.

Previously, only a small, fixed set of TLDs was checked. We now use the
public suffix list to determine if the given address contains a valid
TLD.
2025-01-26 14:27:21 +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
Sam Atkins
8d3e1b07cd LibWeb/CSS: Remove now-empty PercentageOr.cpp
All the code here was removed in commit
c282138fd0
2025-01-24 13:55:52 +01:00
Sam Atkins
d7ea949d2f LibWeb/HTML: Convert drop-shadow() lengths to pixels
Using the raw value meant that 1em would be incorrectly treated as 1px,
for example.

I've updated our canvas-filters test to demonstrate this - without the
code change this would instead have an x-offset of 2px.
2025-01-24 13:55:52 +01:00
Sam Atkins
0321d1392c LibWeb/CSS: Leave calc() in transformations unresolved for longer
We don't need to resolve these at this point, and we already don't do so
for lengths, so leave them in their calc() form until they're used.
2025-01-24 13:55:52 +01:00
Sam Atkins
db2e879839 LibWeb/CSS: Remove unused CalculationNode::Type::Unparsed
I missed this in 6969d1eba3
2025-01-24 13:55:52 +01:00
Luke Warlow
f5860a3b7d LibWeb: Implement hidden="until-found" IDL support
Follow-ups will implement the actual behaviour.
2025-01-24 09:08:37 +01:00
Tim Ledbetter
15fe8e7906 LibWeb: Add formatters for WebIDL exception types
This adds formatters for `WebIDL::Exception`, `WebIDL::SimpleException`
and `WebIDL::DOMException`. These are useful for displaying the content
of errors when debugging.
2025-01-23 21:39:02 +01:00
Andreas Kling
adc25af8e2 LibWeb: Make "assign slottables for a tree" fast when there are no slots
We achieve this by keeping track of the number of HTMLSlotElements
inside each ShadowRoot (do via ad-hoc insertion and removal steps.)

This allows slottables assignment to skip over entire shadow roots when
we know they have no slots anyway.

Massive speedup on https://wpt.fyi/ which no longer takes minutes/hours
to load, but instead a "mere" 19 seconds. :^)
2025-01-23 21:38:31 +01:00
Andreas Kling
003c045589 LibWeb: Add missing base class upcalls in Node::inserted() overrides 2025-01-23 21:38:31 +01:00
Andreas Kling
7269fc3e52 LibWeb: Pass old parent's root to Node::removed_from()
This will allow nodes to access the root they've just been removed from.
2025-01-23 21:38:31 +01:00
Andreas Kling
d465e2aa2b LibJS: Cache the Intl.Collator in String.prototype.localeCompare()
In the very common case that no special constructor options are provided
for the Intl.Collator when calling localeCompare() on a string, we can
cache and reuse a default-constructed Intl.Collator, saving lots of time
and space.

This shaves a fair bit of load time off of https://wpt.fyi/ where they
use Array.prototype.sort() and localeCompare() to sort a big JSON thing.

Time spent in sort():
- Before: 1656 ms
- After: 135 ms
2025-01-23 21:38:19 +01:00
Andreas Kling
51a91771b8 LibJS+LibGC: Run FinalizationRegistry cleanup host hook *after* GC
Before this change, it was possible for a second GC to get triggered
in the middle of a first GC, due to allocations happening in the
FinalizationRegistry cleanup host hook. To avoid this causing problems,
we add a "post-GC task" mechanism and use that to invoke the host hook
once all other GC activity is finished, and we've unset the "collecting
garbage" flag.

Note that the test included here only fails reliably when running with
the -g flag (collect garbage after each allocation).

Fixes #3051
2025-01-23 12:10:21 +01:00
Jelle Raaijmakers
b7a554d1f2 LibWeb: Reorder paintable hit-testing to account for pointer-events
Instead of ignoring any paintable immediately when they're invisible to
hit-testing, consider every candidate and while the most specific
candidate is invisible to hit-testing, traverse up to its parent
paintable.

This more closely reflects the behavior expected when wrapping block
elements inside inline elements, where although the block element might
have `pointer-events: none`, it still becomes part of the hit-test body
of the inline parent.

This makes the following link work as expected:

  <a href="https://ladybird.org">
    <div style="pointer-events: none">Ladybird</div>
  </a>
2025-01-23 09:33:10 +01:00
Jelle Raaijmakers
e076cb9b0e LibWeb: Simplify hit testing coordinate calculations
There are many simpler APIs that we can use here. No functional changes.
2025-01-23 09:33:10 +01:00
Jelle Raaijmakers
336684bc5c LibWeb: Support inserting non-inline elements into inline elements
Our layout tree requires that all containers either have inline or
non-inline children. In order to support the layout of non-inline
elements inside inline elements, we need to do a bit of tree
restructuring. It effectively simulates temporarily closing all inline
nodes, appending the block element, and resumes appending to the last
open inline node.

The acid1.txt expectation needed to be updated to reflect the fact that
we now hoist its <p> elements out of the inline <form> they were in.
Visually, the before and after situations for acid1.html are identical.
2025-01-23 09:33:10 +01:00
Jelle Raaijmakers
7eb4f3da37 LibGfx: Add Rect::unite()
The existing `::unite_horizontally()` and `::unite_vertically()` tests
did not properly test the edge cases where left/top in the Rect were
updated, so they get re-arranged a bit.
2025-01-23 09:33:10 +01:00
Jelle Raaijmakers
c0e861e2fa LibWeb: Add TreeNode::remove()
This allows for easy child removal similar to `DOM::Node::remove()`.
2025-01-23 09:33:10 +01:00
Shannon Booth
fd27eef0d1 LibWeb: Return OptionalNone from DOMURL::parse on failure
This ports one more function away from needing to use the awkward
valid state of the URL class.
2025-01-22 12:33:55 +00:00
Shannon Booth
b81d6945dc LibWeb: Update revokeObjectURL for reported spec bugs
The spec intends to pass through a URL record object as it needs to
be serialized on removal. This has no functional impact on our
implementation other than the double parsing of every URL being
revoked.

It is also missing an error check for an invalid URL being passed
through. This does not impact our implementation currently as we
just end up using an empty URL which is not part of the blob entry
map. This will cause problems once DOMURL::parse is updated to
return an Optional<URL::URL> however.
2025-01-22 12:33:55 +00:00
Shannon Booth
228750a9d2 LibWeb: Remove uneeded exception handling for DOMURL
This was all for OOM handling.
2025-01-22 12:33:55 +00:00
Shannon Booth
71cf49a06f LibWeb: Remove unused 'host_is_domain'
This already exists in URL::Host, and used appropriately.
2025-01-22 12:33:55 +00:00
Psychpsyo
d5c21301db LibWeb: Fix context menu and select dropdown position in iframe 2025-01-22 12:25:48 +00:00
Luke Wilde
30507681f7 LibJS: Parse dates like "2021-04-21T15:00:00+0000"
This is used on figma.com
2025-01-21 21:36:05 +01:00
Luke Wilde
3ab4efb7ef LibJS: Parse dates like "2025-01-13 00:00:00.000"
This is used on figma.com.
2025-01-21 21:36:05 +01:00
Luke Wilde
915c36c366 LibWeb/WebGL: Map WebGL extensions to the required extensions
This is used to put together the list of supported WebGL extensions
based on the available extensions, per-extension required extensions
and WebGL version.
2025-01-21 21:36:05 +01:00
Luke Wilde
55f7cb4f10 LibWeb/WebGL: Implement WEBGL_draw_buffers extension 2025-01-21 21:36:05 +01:00
Luke Wilde
de77a5e3ea LibWeb/WebGL: Move extensions into their own folder 2025-01-21 21:36:05 +01:00
Luke Wilde
cfbd125e57 LibWeb/WebGL: Make getExtension spec-compliant
Namely:
- Perform case-insensitive matching
- Return the same extension objects every time
- Only enable the extension if it's supported by the current context
2025-01-21 21:36:05 +01:00
Luke Wilde
442f0b9a13 LibWeb/WebGL: Implement OES_vertex_array_object extension 2025-01-21 21:36:05 +01:00
Luke Wilde
58942e1137 LibWeb/WebGL: Request GL_ANGLE_instanced_arrays extension when required 2025-01-21 21:36:05 +01:00
Luke Wilde
1156fe483d LibWeb/WebGL: Tell ANGLE to create a WebGL compatible EGL context
This causes it to enforce the sections "Differences Between WebGL and
OpenGL ES 2.0" from the WebGL 1 specification and "Differences Between
WebGL and OpenGL ES 3.0" from the WebGL 2 specification. It also
disables a bunch of extensions by default, which we must now request
with glRequestExtensionANGLE.
2025-01-21 21:36:05 +01:00
Luke Wilde
4cb5a980e5 LibWeb/WebGL: Implement getAttachedShaders 2025-01-21 21:36:05 +01:00
Luke Wilde
aa99853a5c LibWeb/WebGL: Track the shaders attached to a program
This is required to return original references to the shaders attached
to a program from getAttachedShaders. This is required for Figma (and
likely all other Emscripten compiled applications that use WebGL) to
get it's own generated shader IDs from the shaders returned from
getAttachedShaders.
2025-01-21 21:36:05 +01:00
Luke Wilde
3ab93667f5 LibWeb: Respect subarrays in TextEncoder::encode_into
This is the method that Figma uses to write strings into Wasm memory,
using subarrays to select a particular Wasm memory address to write to.
2025-01-21 21:36:05 +01:00