Commit graph

3222 commits

Author SHA1 Message Date
Andreas Kling
c9cd795257 LibWeb: Don't lose change events on MediaQueryList internal state change
MediaQueryList will now remember if a state change occurred when
evaluating its match state. This memory can then be used by the document
later on when it's updating all queries, to ensure that we don't forget
to fire at least one change event.

This also required plumbing the system visibility state to initial
about:blank documents, since otherwise they would be stuck in "hidden"
state indefinitely and never evaluate their media queries.
2025-02-13 20:52:31 +01:00
Andreas Kling
6fd24c2a68 LibWeb: Update layout when checking media queries inside iframes
This ensures that the containing iframe has up-to-date viewport metrics,
which is important since that may affect media query results.
2025-02-13 20:52:31 +01:00
Aliaksandr Kalenik
327dc8e82a LibWeb: Avoid full tree traversal for non-subject :has() invalidation
Instead of checking all elements in a document for containment in
`:has()` invalidation set, we could narrow this down to ancestors and
ancestor siblings, like we already do for subject `:has()` invalidation.

This change brings great improvement on GitHub that has selectors with
non-subject `:has()` and sibling combinators (e.g., `.a:has(.b) ~ .c`)
which prior to this change meant style invalidation for whole document.
2025-02-13 16:24:51 +01:00
Sam Atkins
604400f758 LibWeb/HTML: Ensure HTMLOrSVGElement is BC-connected when running steps 2025-02-13 14:49:19 +00:00
Sam Atkins
b6fc4ec892 LibWeb/HTML: Update radio group when a checked radio button is connected
Corresponds to https://github.com/whatwg/html/pull/10917
2025-02-13 14:49:19 +00:00
stasoid
2be8052f0a LibWeb: Remove assertions about type of IPC::Transport
These constexpr checks and static assertions are really just
loud FIXME comments, and should be comments instead.
2025-02-12 18:42:05 -07:00
Sam Atkins
f9e90ca430 LibWeb/DOM: Assert that composed_path() currentTarget is non-null
Corresponds to cbf4c0d6b4

The assert is a little different, because we do know it's an
EventTarget pointer, but it could be null.
2025-02-12 23:48:18 +00:00
Sam Atkins
f4d3a01d32 LibWeb/HTML: Update submit-button-related spec text
Corresponds to 69110cba07
2025-02-12 23:46:05 +00:00
Sam Atkins
29d5eda02d LibWeb/DOM: Add container option to scrollIntoView options
Corresponds to https://github.com/w3c/csswg-drafts/pull/11673 , with the
addition of the fixes in https://github.com/w3c/csswg-drafts/pull/11701
2025-02-12 22:08:17 +01:00
Sam Atkins
a01a3b18f5 LibWeb: Fix CSP navigation request blocking
Corresponds to 304782ca57
2025-02-12 17:05:37 +00:00
Sam Atkins
75faea3221 LibWeb/CSS: Don't serialize font shorthand with invalid longhand values
Some values that are valid in font's longhands individually are not
allowed inside the font shorthand.
2025-02-12 16:00:42 +00:00
Sam Atkins
80eee82ea9 LibWeb/CSS: Inline CSSStyleValue::to_font_variant_foo() methods
Now that these are only called from ComputedProperties getters, we can
put the code there directly.
2025-02-12 16:00:42 +00:00
Sam Atkins
62c18d1dec LibWeb/CSS: Serialize font-variant property closer to spec
It also needs special handling when reading it from CSSStyleDeclaration.
2025-02-12 16:00:42 +00:00
Sam Atkins
8236022152 LibWeb/CSS: Parse font-variant properties closer to spec
The spec wants these keywords to appear in a particular order when
serialized, so let's just put them in that order during parsing.

This also fixes a bug where we didn't reject `font-variant-east-asian`
that contains `normal` alongside another value.

Also, rather than always parsing them as a StyleValueList, parse single
values on their own, and then support that in the to_font_variant_foo()
methods.
2025-02-12 16:00:42 +00:00
Sam Atkins
cda3fe7a4b LibWeb/CSS: Reject trailing unparseable tokens in property values
Without this, we'd happily parse `font-variant-caps: small-caps potato`
as just `small-caps` and ignore the fact that unused tokens were left
over.

This fix gets us some WPT subtest passes, and removes the need for a
bespoke parsing function for font-variant-caps.
2025-02-12 16:00:42 +00:00
Sam Atkins
412b758107 LibWeb/CSS: Support nested shorthands in CSSStyleDeclaration
Without this, getting a property's value from `element.style.foo` would
fail if `foo` is a shorthand property which has a longhand that is also
a shorthand. For example, `border` expands to `border-width` which
expands to `border-top-width`.

This is because we used `property()` to get a longhand's value, but this
returns nothing if the property is a shorthand.

This commit solves that by moving most of get_property_value() into a
separate method that returns a StyleProperty instead of a String, and
which calls itself recursively for shorthands. Also move the manual
shorthand construction out of ResolvedCSSStyleDeclaration so that all
CSSStyleDeclarations can use it.
2025-02-12 16:00:42 +00:00
Sam Atkins
006c8ba2d4 LibWeb/CSS: Serialize font property more correctly
Anything that's default shouldn't be included.
2025-02-12 16:00:42 +00:00
Sam Atkins
531b92d467 LibWeb/CSS: Make font implicitly reset some properties
This is a weird behaviour specific to `font` - it can reset some
properties that it never actually sets. As such, it didn't seem worth
adding this concept to the code generator, but just manually stuffing
the ShorthandStyleValue with them during parsing.
2025-02-12 16:00:42 +00:00
Aliaksandr Kalenik
976af84287 LibWeb: Check all siblings in ancestors chain while invalidating :has()
Fixes underinvalidaiton of `:has()` selectors with sibling combinators.
2025-02-12 16:15:14 +01:00
Sam Atkins
49b505e4ae LibWeb/DOM: Cache computed style for ::marker
This allows us to inspect its properties. To avoid wasted work, we only
compute and cache the properties if the originating element was, or is,
displaying as a list item.
2025-02-12 13:48:53 +00:00
Psychpsyo
86859b77a2 LibWeb: Hide hidden select children from dropdown 2025-02-12 13:44:50 +00:00
devgianlu
718d338d68 LibWeb: Remove useless JS::ThrowCompletionOr return types
All `SubtleCrypto` methods except `import_key` do not require
`JS::ThrowCompletionOr` as they return only rejected promises.
2025-02-12 00:40:17 +01:00
Andreas Kling
0705efda13 LibWeb: Use cached UsedValues pointer for floating boxes in more places 2025-02-12 00:39:36 +01:00
Andreas Kling
81deaad7ad LibWeb: Cache UsedValues pointers in GridFormattingContext and use them 2025-02-12 00:39:36 +01:00
Andreas Kling
fee0d408a1 LibWeb: Assume flex container forms containing block of abspos items
This avoids a dubious-looking UsedValues lookup.
2025-02-12 00:39:36 +01:00
Andreas Kling
d43cc82b1c LibWeb: Use cached UsedValues pointer in FlexFormattingContext more 2025-02-12 00:39:36 +01:00
Andreas Kling
2f5ce0fcb6 LibWeb: Make LayoutState::UsedValues::m_node a const pointer
No mutations should ever be made to the layout node through this
pointer (and none were).
2025-02-12 00:39:36 +01:00
Aliaksandr Kalenik
761e9aeaf7 LibWeb: Optimize inherited style update
This commit changes the strategy for updating inherited styles. Instead
of marking all potentially affected nodes during style invalidation, the
decision is now made on-the-fly during style recalculation. Child nodes
will only have their inherited styles recalculated if their parent's
properties have changed.

On Discord this allows to 1000x reduce number of nodes with recalculated
inherited style.
2025-02-11 19:23:12 +01:00
Andreas Kling
bf15c7fa4b LibWeb: Remove "temporary content size" hack from flex layout
This was an old hack intended to make percentage sizes on flex items
before we had implemented the appropriate special behavior of definite
sizes in flex layout.

Removing it makes flex layout less magical and should not change
behavior in any observable way.
2025-02-11 14:23:13 +01:00
Andreas Kling
4cbd975b66 LibWeb: Simplify determination of flex item's hypothetical cross size
The spec tells us to treat `auto` as `fit-content` when determining
flex item cross sizes, so let's just do *that* instead of awkwardly
doing an uncacheable nested layout of the item.

This was the only instance of `LayoutState` nesting outside of intrinsic
sizing, so removing it is an important step towards simplifying layout.
Turns out it was a lot easier than expected.
2025-02-11 14:23:13 +01:00
Sam Atkins
0fd0596dbf LibWeb: Support strings as list-style-types
We've long claimed to support this, but then silently ignored string
values, until 4cb2063577 which would
not-so-silently crash instead. (Oops)

So, actually pass the string value along and use it in the list marker.

As part of this, rename our `list-style-type` enum to
`counter-style-name-keyword`. This is an awkward name, attempting to be
spec-based. (The spec says `<counter-style>`, which is either a
`<counter-style-name>` or a function, and the `<counter-style-name>` is
a `<custom-ident>` that also has a few predefined values. So this is the
best I could come up with.)

Unfortunately only one WPT test for this passes - the others fail
because we produce a different layout when text is in `::before` than
when it's in `::marker`, and similar issues.
2025-02-11 10:39:27 +01:00
Sam Atkins
b987d53926 LibWeb: Migrate ListItemMarkerBox's text from ByteString to String 2025-02-11 10:39:27 +01:00
Sam Atkins
0a805fe7a5 LibWeb/HTML: Add CanvasColorType
We don't implement the affected algorithms, and so the only change to
apply here is adding the dictionary member to IDL.

Corresponds to a5853ca8fa
2025-02-11 10:22:45 +01:00
Aliaksandr Kalenik
875a7141a3 LibWeb: Skip pending :has() invalidations if there are no :has()
`invalidate_style()` already tries to avoid scheduling invalidation for
`:has()` by checking result of `may_have_has_selectors()`, but it might
still result in unnecessary work because `may_have_has_selectors()`
does not force building of rules cache. This change adds
`have_has_selectors()` that forces building of rules cache and is
invoked in `update_style()` to double-check whether we actually need to
process scheduled `:has()` invalidations.

This allows to skip ~100000 ancestor traversals on this WPT test:
https://wpt.live/html/select/options-length-too-large.html
2025-02-11 10:22:23 +01:00
Aliaksandr Kalenik
90ba4b16c2 LibWeb: Postpone :has() style invalidation until update_style()
This allows to do ancestors traversal only once even if
`invalidate_style()` was called multiple times for the same node.
2025-02-11 10:22:23 +01:00
Shannon Booth
8088ab5306 LibWeb/URLPattern: Add a stub for URLPattern.exec
Just enough to get the IDL compiling :^)
2025-02-10 17:05:15 +00:00
Shannon Booth
f3ec727555 LibWeb/Bindings: Support returning nullable types in dictionaries
We were previously assuming that dictionary members were always
required when being returned.

This is a bit of a weird case, because unlike _input_ dictionaries
which the spec marks as required, 'result' dictionaries do not seem to
be marked in spec IDL as required. This is still fine from the POV that
the spec is written as it states that we should only be putting the
values into the dictionary if the value exists.

We could do this through some metaprogramming constexpr type checks.
For example, if the type in our C++ representation was not an
Optional, we can skip the has_value check.

Instead of doing that, change the IDL of the result dictionaries to
annotate these members so that the IDL generator knows this
information up front. While all current cases have every single
member returned or not returned, it is conceivable that the spec
could have a situation that one member is always returned (and
should get marked as required), while the others are optionally
returned. Therefore, this new GenerateAsRequired attribute is
applied for each individual member.
2025-02-10 17:05:15 +00:00
Timothy Flynn
d873dc0744 LibWeb+WebDriver: Validate WebDriver proxy capabilities
We don't yet support a proxy configuration, but we can still validate
the capability received from the WebDriver client. We should also fail
to create a WebDriver session if a proxy configuration is present.
2025-02-10 11:33:53 -05:00
Timothy Flynn
88eda159af LibWeb: Remove "serenity:" prefix from custom WebDriver capabilities
We currently define our custom WebDriver capabilities with a dictionary
of the form:

    "serenity:ladybird": {
        "headless": true
    }

This patch flattens the configuration, such that each Ladybird option
will be its own capability. This matches how Firefox configures their
own options with geckodriver. So we now have:

    "ladybird:headless": true
2025-02-10 11:33:53 -05:00
Timothy Flynn
e0ecf3b033 LibWeb: Do not reject unknown WebDriver extension capabilities 2025-02-10 11:33:53 -05:00
Timothy Flynn
de34351ba8 LibWeb+WebDriver: Convert WebDriver session flags to an enumeration
Rather than a list of strings, this will be easier to deal with as a
bitwise enumeration.
2025-02-10 11:33:53 -05:00
Shannon Booth
03370dc76a LibWeb/HTML: Improve assertion for apply the history step mismatch
This more directly catches the bug we have that causes this
assertion to happen on certain sites and WPT tests.
2025-02-10 15:55:46 +00:00
Sam Atkins
dc58f6567f LibWeb: Support :open for file and color <input> elements 2025-02-10 13:57:36 +00:00
Sam Atkins
52a92b7937 LibWeb/HTML: Extract dialog show_modal() into its own algorithm
Corresponds to https://github.com/whatwg/html/pull/10961
2025-02-10 13:56:59 +00:00
Kenneth Myhra
21989ef543 LibWeb: Align ReadableByteStreamControllerEnqueue
Align ReadableByteStreamControllerEnqueue with current spec steps.
2025-02-10 13:25:51 +00:00
Kenneth Myhra
4699bf24dc LibWeb: Align ReadableByteStreamControllerRespondInClosedState
Align ReadableByteStreamControllerRespondInClosedState with current spec
steps.
2025-02-10 13:25:51 +00:00
Kenneth Myhra
4b917d366c LibWeb: Align ReadableByteStream(...)FillPullIntoDescriptorFromQueue
Align ReadableByteStreamControllerFillPullIntoDescriptorFromQueue with
current spec steps.
2025-02-10 13:25:51 +00:00
Psychpsyo
14e354bc29 LibWeb: Implement playbackRate 2025-02-10 11:38:02 +00:00
Shannon Booth
c954d0be27 LibWeb/DOM: Add missing UTF-8 decode without BOM on fragment ID
We were previously crashing instead of using the replacement
character on invalid bytes.
2025-02-10 09:48:08 +00:00
Aliaksandr Kalenik
adc17c3576 LibWeb: Deduplicate code for pseudo class selector matching
Moves pseudo class matching helpers into Element methods, so they don't
have to be duplicated between SelectorEngine and function that checks if
element is included in invalidation set.
2025-02-10 01:26:47 +01:00