Commit graph

3222 commits

Author SHA1 Message Date
Andreas Kling
0084d992d4 LibWeb: Remove unnecessary re-measurement of cross sizes in flex layout
This was an old hack from before we understood how and when to resolve
percentages in flex layout. Removing it should not change anything,
but it does avoid a lot of redundant layout work on many pages.
2025-02-10 01:26:34 +01:00
Aliaksandr Kalenik
e677ab1699 LibWeb: Narrow :has() style invalidation to ancestor nodes
The current implementation of `:has()` style invalidation is divided
into two cases:
- When used in subject position (e.g., `.a:has(.b)`).
- When in a non-subject position (e.g., `.a > .b:has(.c)`).

This change focuses on improving the first case. For non-subject usage,
we still perform a full tree traversal and invalidate all elements
affected by the `:has()` pseudo-class invalidation set.

We already optimize subject `:has()` invalidations by limiting
invalidated elements to ones that were tested against `has()` selectors
during selector matching. However, selectors like `div:has(.a)`
currently cause every div element in the document to be invalidated.
By modifying the invalidation traversal to consider only ancestor nodes
(and, optionally, their siblings), we can drastically reduce the number
of invalidated elements for broad selectors like the example above.

On Discord, when scrolling through message history, this change allows
to reduce number of invalidated elements from ~1k to ~5.
2025-02-10 01:13:53 +01:00
Shannon Booth
7441aa34e4 LibWeb/HTML: Bail from HTML parsing when EOF hit on document.close
This fixes a crash in the included test that regressed in 0adf261,
and is hit by the following HTML:

```html
<body></body>
<script>
  const frame = document.body.appendChild(document.createElement("iframe"));
  frame.contentDocument.open();
  const child = frame.contentDocument.createElement("html")
  const html = frame.contentDocument.appendChild(child);
  frame.contentDocument.close();
</script>
```

I am not 100% sure this is fully the correct fix and there are other
cases which would not work properly. But it's definitely an improvement
to make the confuisingly named 'insert_an_eof' function of the tokenizer
actually do something.
2025-02-09 19:20:09 +00:00
Tim Ledbetter
9e556972ae LibWeb: Reset find-in-page index if selection is cleared
Previously, if the user made a find-in-page query, then cleared the
selection made by that query, subsequent queries would inadvertently
advance to the next match instead of reselecting the first match.
2025-02-09 18:19:58 +00:00
Andreas Kling
5f10f8c54c LibWeb: Do includes_properties_from_invalidation_set() for :link & co
Fixes #3511.
2025-02-09 15:20:53 +01:00
Tim Ledbetter
c4bc0842c1 LibWeb: Prevent AudioBuffer data being copied to or from a shared buffer 2025-02-09 14:13:46 +00:00
Luke Wilde
958938655d LibWeb/WebGL: Implement WEBGL_compressed_texture_s3tc extension 2025-02-09 01:00:51 +01:00
Luke Wilde
484008d440 LibWeb/WebGL: Implement compressedTex(Sub)Image2D 2025-02-09 01:00:51 +01:00
Luke Wilde
f1b81b1ae2 LibWeb/WebGL2: Implement getActiveUniforms 2025-02-09 01:00:51 +01:00
Luke Wilde
071a445015 LibWeb/WebGL2: Implement drawArraysInstanced 2025-02-09 01:00:51 +01:00
Luke Wilde
13f28cb941 LibWeb/WebGL: Reimplement OpenGLContext::clear_buffer_to_default_values
The implementation was removed with the migration to ANGLE. This
reimplements it. This is required by Stimulation Clicker on neal.fun,
which does not clear the framebuffer itself, instead relying on the
browser doing it.
2025-02-09 01:00:51 +01:00
Andreas Kling
39abd75d59 LibWeb: Use invalidation sets for link-related pseudo classes
- :any-link
- :link
- :local-link
2025-02-08 18:11:24 +01:00
Andreas Kling
719a2e448f LibWeb: Use invalidation sets for :checked style invalidation 2025-02-08 18:11:24 +01:00
Tim Ledbetter
8b2de413ae LibWeb: Ensure selected options collection is created prior to access 2025-02-08 07:32:24 -05:00
Tim Ledbetter
dccb374876 LibWeb: Treat execCommand command names as case insensitive 2025-02-08 07:30:27 -05:00
Luke Wilde
cae0ee6fa7 LibWeb: Implement TextEncoderStream
Required by the server-side rendering mode of React Router, used by
https://chatgpt.com/

Note that the imported tests do not have the worker variants to prevent
freezing on macOS.
2025-02-07 11:04:46 -05:00
Luke Wilde
24d5f24749 LibWeb: Extract the TextEncoderCommon mixin to its own IDL file
Co-Authored-By: Tim Flynn <trflynn89@pm.me>
2025-02-07 11:04:46 -05:00
Luke Wilde
c14d5f27f9 LibWeb: Use DefaultReader request in read_all_chunks instead of ReadLoop
ReadLoop requests require the chunks to be Uint8Array objects, however,
TextEncoderStream requires a String (Convertible) value. This is fixed
by implementing read_all_chunks as a loop of DefaultReader requests
instead, which is an identity transformation. This should be okay to
do, as stream chunk steps expect a JS::Value, and convert it to the
type they want.
2025-02-07 11:04:46 -05:00
Andreas Kling
187f8c5460 LibWeb: Run queued HTML tasks after associated document is destroyed
Before this change, tasks associated with a destroyed document would get
stuck in the task queue forever, since document-associated tasks are not
allowed to run when their document isn't fully active (and destroyed
documents never become fully active again). This caused everything
captured by task callbacks to leak.

We now treat tasks for destroyed documents as runnable immediately,
which gets them out of the queue.

This fixes another massive GC leak on Speedometer.
2025-02-07 16:53:11 +01:00
Andreas Kling
53c9c6f3ee LibWeb: Make Agent's MutationObserver list weak
Before this change, Agent held on to all of the live MutationObserver
objects via GC::Root. This prevented them from ever getting
garbage-collected.

Instead of roots, we now use a simple IntrusiveList and remove them
from it in the finalizer for MutationObserver.

This fixes a massive GC leak on Speedometer.
2025-02-07 16:53:11 +01:00
Aliaksandr Kalenik
ccb513abf7 LibWeb: Invalidate layout tree of parent of inserted node
f7a3f78 made the layout tree invalidate only the inserted nodes
themselves, but it turned out that CSS containment invalidation relies
on the parent being invalidated as well.
2025-02-07 01:23:10 +01:00
Aliaksandr Kalenik
a6bea99959 LibWeb: Use invalidation sets for :defined style invalidation 2025-02-06 20:07:11 +01:00
Aliaksandr Kalenik
51a5ebb91d LibWeb: Use bitfields for booleans in DOM::Element 2025-02-06 20:07:11 +01:00
Aliaksandr Kalenik
f7a3f785a8 LibWeb: Don't invalidate style of parent of inserted node
There is no need for this invalidation because taking care of siblings
is already done by invalidation with `NodeInsertBefore` reason. Parent
element itself (without subtree) is always invalidated by
`Node::children_changed()` hook, so `:empty` pseudo-class invalidation
is already covered.
2025-02-06 20:07:11 +01:00
Aliaksandr Kalenik
daf7c1ef60 LibWeb: Fix early return condition in Node::invalidate_style()
When checking whether an early return is possible because some ancestor
already has the whole subtree invalidation flag set, the check should
begin with the current node's parent rather than with the node itself.
Otherwise, if a node already has the whole subtree invalidation flag
set and is subsequently invalidated for the reason `NodeInsertBefore`
or `NodeRemove`, we will skip the sibling invalidation required for
these operations

This fix is required for optimizations in subsequent commits.
2025-02-06 20:07:11 +01:00
Aliaksandr Kalenik
61c952fb43 LibWeb: Optimize style invalidation caused by DOM structural changes
With this change, siblings of an inserted node are no longer invalidated
unless the insertion could potentially affect their style. By
"potentially affected," we mean elements that are evaluated against the
following selectors during matching:
- Sibling combinators (+ or ~)
- Pseudo-classes :first-child and :last-child
- Pseudo-classes :nth-child, :nth-last-child, :nth-of-type, and
  :nth-last-of-type
2025-02-06 20:07:11 +01:00
Psychpsyo
402d8220dd LibWeb: Make style containment influence quotes 2025-02-06 17:44:50 +00:00
Sam Atkins
6a4d80b9b6 LibWeb/CSS: Integrate ParsingContext into the Parser
This is not really a context, but more of a set of parameters for
creating a Parser. So, treat it as such: Rename it to ParsingParams,
and store its values and methods directly in the Parser instead of
keeping the ParsingContext around.

This has a nice side-effect of not including DOM/Document.h everywhere
that needs a Parser.
2025-02-06 16:47:25 +00:00
Sam Atkins
30ba7e334e LibWeb/CSS: Avoid creating a new Parser unnecessarily
This attr() code can instead just tokenize the input manually, and then
re-use the existing Parser.
2025-02-06 16:47:25 +00:00
Sam Atkins
36e3963263 LibWeb: Add CSSNamespaceRule to Forward.h 2025-02-06 16:47:25 +00:00
Sam Atkins
0cb7f2ab6d LibWeb: Add some missing includes
These were being transitively included before via ParsingContext.h, but
that will break in a subsequent commit.
2025-02-06 16:47:25 +00:00
Sam Atkins
4d0537ee80 LibWeb/CSS: Make CSS Parser non-copyable/movable
We never actually need to do this, and doing so was complicated because
of the token stream, so just disable it altogether.
2025-02-06 16:47:25 +00:00
Sam Atkins
ca5dee4c55 LibWeb/CSS: Remove an unnecessary ParsingContext constructor
Anywhere we have a Node, we have a Document. So just use that.
2025-02-06 16:47:25 +00:00
Sam Atkins
0ac133d73b LibWeb/CSS: Replace is_generic_font_family() with a CSS enum
Also add the missing "math" value to it.
2025-02-06 16:47:25 +00:00
Sam Atkins
6da7a6eab5 LibWeb/CSS: Un-template some CSS Parser methods
A few of these are only ever called with T=Token, so let's simplify them
a bit.

As a drive-by change: Also correct the "unnecessairy" typos and use
discard_a_token().
2025-02-06 16:47:25 +00:00
Sam Atkins
1413760047 LibWeb/CSS: Split up Parser.cpp
This file has been a pain to edit for a while, even with the previous
splits. So, I've divided it up into 3 parts:
- Parser.cpp has the "base" code. It's the algorithms and entry-points
  defined in the Syntax spec.
- ValueParsing.cpp contains code for parsing single values, such as a
  length, or a color, or a calculation.
- PropertyParsing.cpp contains code for parsing an entire property's
  value. A few of these sit in a grey area between being a property's
  value and a value in their own right, but the rule I've used is "is
  this useful outside of a single property and its shorthands?"

This only moves code, with as few modifications as possible to make that
work. I did add explicit instantiations for the template implementations
as part of this, which revealed a few that are actually only compatible
with a single type, so I'll clear those up in a subsequent commit.
2025-02-06 16:47:25 +00:00
Timothy Flynn
ee649fc13b LibWeb+WebContent+WebDriver: Bring session start and close up to spec
Lots of editorial spec bugs here, but these changes largely affect how
the unhandledPromptBehavior capability is handled. We also now set an
additional capability for the default User Agent string.
2025-02-06 09:01:16 -05:00
Timothy Flynn
2583996e18 LibWeb+WebContent+WebDriver: Allow specifying multiple prompt handlers
WebDriver script authors may now provide either:
* A user prompt handler configuration to be used for all prompt types.
* A set of per-prompt-type user prompt handlers.

This also paves the way for interaction with the beforeunload prompt,
though we do not yet support that feature in LibWeb.

See: https://github.com/w3c/webdriver/commit/43903d0
2025-02-06 09:01:16 -05:00
Andrew Kaster
adfb371e4f LibWeb: Reference multipage spec for form element constraints 2025-02-05 17:35:10 -07:00
Psychpsyo
9b8120d8e8 Meta: Disallow links to single-page HTML spec 2025-02-05 16:04:50 -07:00
Felipe Muñoz Mazur
c2cc0d9cd0 LibWeb: Check if input is disabled before submit event to form 2025-02-05 14:45:57 -07:00
devgianlu
da9eaf8788 LibWeb: Stub for Credential Management API
Stub out basic Credential Management APIs and import IDL tests.

Spec: https://w3c.github.io/webappsec-credential-management/
2025-02-05 13:18:47 -07:00
Andreas Kling
8cf16da6c2 Fix build breakage caused by badly sequenced PR merges 2025-02-05 19:49:24 +01:00
Sam Atkins
070c4a2045 LibWeb: Implement text-align: match-parent
At computed-value time, this is converted to whatever the parent's
computed value is. So it behaves a little like `inherit`, except that
an inherited start/end value uses the parent's start/end, which might
be different from the child's.
2025-02-05 17:45:44 +00:00
Andreas Kling
4f855286d7 LibWeb: Clamp layout content sizes to a max value instead of crashing
We've historically asserted that no "saturated" size values end up as
final metrics for boxes in layout. This always had a chance of producing
false positives, since you can trivially create extremely large boxes
with CSS.

The reason we had those assertions was to catch bugs in our own engine
code where we'd incorrectly end up with non-finite values in layout
algorithms. At this point, we've found and fixed all known bugs of that
nature, and what remains are a bunch of false positives on pages that
create very large scrollable areas, iframes etc.

So, let's change it! We now clamp content width and height of boxes to
17895700 pixels, apparently the same cap as Firefox uses.

There's also the issue of calc() being able to produce non-finite
values. Note that we don't clamp the result of calc() directly, but
instead just clamp values when assigning them to content sizes.

Fixes #645.
Fixes #1236.
Fixes #1249.
Fixes #1908.
Fixes #3057.
2025-02-05 18:28:55 +01:00
Aliaksandr Kalenik
da579e11b0 LibWeb: Start implementing render-blocking mechanism from HTML spec
This change implements enough spec steps to block rendering until
execution of sync scripts inserted from HTML parser is complete.
2025-02-05 18:28:46 +01:00
Sam Atkins
75168fa4d6 LibWeb/CSS: Remove redundant CSS:: namespaces from ComputedProperties
We're already in the CSS namespace, so let's remove the clutter.
2025-02-05 18:12:36 +01:00
Sam Atkins
4cb2063577 LibWeb/CSS: Stop returning Optional for enum properties
While keyword_to_foo() does return Optional<Foo>, in practice the
invalid keywords get rejected at parse-time, so we don't have to worry
about them here. This simplifies the user code quite a bit.
2025-02-05 18:12:36 +01:00
Luke Wilde
d3057a9c79 LibWeb: Preserve opening quotation in string token original source text
Used by chess.com, where it stores URLs to assets in CSS URL variables.
It then receives the value of them with getComputedStyle() and then
getPropertyValue(). With this, it trims off the url('') wrapper with a
simple slice(5, -2). Since we didn't preserve the opening quotation, it
would slice off the `h` in `https` instead of the quotation.
2025-02-05 16:02:09 +00:00
Aliaksandr Kalenik
a5e4a51b52 LibWeb: Change animation to schedule repaint only when necessary
Animation should trigger repaint only if it's required by animated style
update.
2025-02-05 14:34:41 +01:00