Commit Graph

2288 Commits

Author SHA1 Message Date
Tim Ledbetter
094acbdcf1 LibWeb: Default color-mix() interpolation method to Oklab 2026-04-16 12:06:10 +02:00
Tim Ledbetter
d8e150421f LibWeb: Align color interpolation with the css-color specification 2026-04-16 12:06:10 +02:00
Sam Atkins
08dbbf24c2 LibWeb/CSS: Tokenize custom property values when substituting var()
Co-authored-by: Shannon Booth <shannon@serenityos.org>
2026-04-15 16:42:15 +02:00
Sam Atkins
7f2ff6df4e LibWeb/CSS: Tokenize PercentageStyleValues properly
- These should be Percentage tokens, not Dimensions.
- The `unit_name` is "percent", so the serialization also came out wrong
  as e.g. `10percent` instead of `10%`.
2026-04-15 16:42:15 +02:00
Callum Law
8a547a3f31 LibWeb: Clear counter style cache when CSSCounterStyleRule modified 2026-04-15 11:07:38 +01:00
Callum Law
a1cc560caa LibWeb: Add CSSStyleSheet::for_each_owning_style_scope 2026-04-15 11:07:38 +01:00
Callum Law
8d2995c785 LibWeb: Apply correct invalidations when effective counter style changes
The counter style used for an element (in either the `content` or
`list-style-type`) may change despite the computed values of properties
on that element remaining the same (e.g. if a new rule is inserted with
higher cascade precedence).
2026-04-15 11:07:38 +01:00
Callum Law
8b69e2fc81 LibWeb: Simplify compute_property_invalidation 2026-04-15 11:07:38 +01:00
Callum Law
2313460ab6 LibWeb: Make null content on ComputedValues more explicit
In a later commit we can use the null state for an optimization.
2026-04-15 11:07:38 +01:00
Callum Law
595848b0fa LibWeb: Implement CounterStyle::equals
This makes `ValueComparingRefPtr<CounterStyle>` work
2026-04-15 11:07:38 +01:00
Callum Law
64ccb9a015 LibWeb: Make @counter-style tree-scoped
This was a pretty straightforward change of storing registered counter
styles on the relevant `StyleScope`s and resolving by following the
process to dereference a global tree-scoped name, the only things of
note are:
 - We only define predefined counter styles (e.g. decimal) on the
   document's scope (since otherwise overrides in outer scopes would
   themselves be overriden).
 - When registering counter styles we don't have the full list of
   extendable styles so we defer fallback to "decimal" for undefined
   styles until `CounterStyle::from_counter_style_definition`.
2026-04-15 11:07:38 +01:00
Callum Law
8d117725e5 LibWeb: Add helper method to dereference global tree-scoped references 2026-04-15 11:07:38 +01:00
Sam Atkins
5385d90e3c LibWeb/CSS: Output more details in Token::to_debug_string()
Include all the relevant fields for the type of Token, so that the
upcoming Tokenizer tests can verify that the produced Tokens are
correct.
2026-04-15 10:23:09 +01:00
Sam Atkins
d54305eb06 LibWeb/CSS: Ensure at-keyword name is consumed before input_since()
This relied on input_since() being called after
consume_an_ident_sequence(), which is not at all guaranteed. GCC
evidently evaluates the arguments in the opposite order.

This caused AtKeyword tokens to have their original source text be `@`
instead of the full `@whatever`, which apparently has no consequences
in our current code, but does mess up the debug output introduced in
the following commit.
2026-04-15 10:23:09 +01:00
Callum Law
76f0416b75 LibWeb: Resolve keywords in basic shape position at compute time
Previously we resolved these at parse time since that's what WPT
expected, but WPT was updated in web-platform-tests/wpt#59022 and
web-platform-tests/wpt#59176
2026-04-15 08:04:02 +02:00
Callum Law
de10db6da3 LibWeb: Remove unused interpolate_length_percentage{_auto} methods 2026-04-13 19:24:43 +02:00
Callum Law
1e36ccad0d LibWeb: Remove unused PercentageOr classes
These are only used at used value time (since we store as `StyleValue`s
before) by which time we resolve all percentages except for layout
relative length percentages.
2026-04-13 19:24:43 +02:00
Callum Law
d25f86da66 LibWeb: Remove unused CSS::Parser::Dimension 2026-04-13 19:24:43 +02:00
Sam Atkins
973b919153 LibWeb/CSS: Only serialize a space before combinators that need it
This has no effect on behaviour now, but means we won't have to adjust
this code when adding the invisible pseudo-element combinator.
2026-04-10 15:00:58 +01:00
Sam Atkins
f32ba2b1a5 LibWeb/CSS: Use Selector's methods to query its pseudo-elements
...instead of iterating through its components. This lets us initialize
the MatchingRule directly, now using designated initializers to
distinguish between the different bool fields.

No behaviour changes.
2026-04-10 15:00:58 +01:00
Sam Atkins
62527c1917 LibWeb/CSS: Separate pseudo-class and pseudo-element parsing code
Apart from making the code a bit easier to follow, we'll need to
distinguish between the two in order to insert a pseudo-element
combinator in front of pseudo-elements (including the single-colon
legacy ones).

next_is_pseudo_element() is its own function because it'll be needed in
a couple of other places, again to support pseudo-element combinators.
2026-04-10 15:00:58 +01:00
Sam Atkins
77308d8a5e LibWeb/CSS: VERIFY() that we don't call is_delim() incorrectly
This has bitten me too many times and it is non-intuitive to debug. So
let's make it very clear that something is wrong!
2026-04-10 15:00:58 +01:00
Sam Atkins
a55fc0f403 LibWeb/CSS: Check for OpenParen token, not '(' Delim
'(' never exists as a Delim token, only as an OpenParen or part of a
Block.
2026-04-10 15:00:58 +01:00
Sam Atkins
a997bb9546 LibWeb/CSS: Remove Optional from parse_compound_selector() return type
We always either return a CompoundSelector or an Error here. This
simplifies the user code.
2026-04-10 15:00:58 +01:00
Callum Law
919dba87b9 LibWeb: Support calculated <flex> values
This spec note reads to me as explicitly disallowing combining
`<length>` and `<flex>` (i.e. `calc(1px + 1fr)`). This behavior is
already implemented (as it is for all other combination of units i.e.
`<length>` and `<time>`).
2026-04-09 21:41:49 +01:00
Callum Law
8d4e1a97cf LibWeb: Remove unused is_computationally_independent methods
`Size` and `LengthPercentage` are no longer stored within any
`StyleValue` classes so these methods are unused
2026-04-09 21:41:49 +01:00
Callum Law
281028944e LibWeb: Store GridTrackSize::m_value as a StyleValue
This simplifies handling (particularly around absolutization and
interpolation) and allows us to support calculated flex values (which
will come in a later commit).
2026-04-09 21:41:49 +01:00
Callum Law
21ffc8e1fe LibWeb: Implement composition for FlexStyleValue
Non-functional change for now but will be required once `GridTrackSize`
stores flex values as `StyleValue`s
2026-04-09 21:41:49 +01:00
Callum Law
e376310a70 LibWeb: Implement interpolation for FlexStyleValue
Non-functional change for now but will be required once `GridTrackSize`
stores flex values as `StyleValue`s
2026-04-09 21:41:49 +01:00
Callum Law
f4e7e193da LibWeb: Implement composition for FitContentStyleValue 2026-04-09 21:41:49 +01:00
Callum Law
af17641b0a LibWeb: Implement interpolation for FitContentStyleValue 2026-04-09 21:41:49 +01:00
Callum Law
c6de8def49 LibWeb: Add Size::from_style_value method 2026-04-09 21:41:49 +01:00
Callum Law
06b22d620d LibWeb: Add Flex::from_style_value method 2026-04-09 21:41:49 +01:00
Callum Law
5807d201b7 LibWeb: Implement absolutization of FitContentStyleValue 2026-04-09 21:41:49 +01:00
Callum Law
aa7c30b7a9 LibWeb: Store fit-content() argument as StyleValue
This brings us in line with other `StyleValue` classes and will make it
easier to implement absolutization in a later commit
2026-04-09 21:41:49 +01:00
Callum Law
2d3c705c17 LibWeb: Split FitContentStyleValue into an implementation file
Brings us in line with the other `StyleValue` classes
2026-04-09 21:41:49 +01:00
R-Goc
d1cd391017 LibWeb: Deduplicate inline_axis functions
This commit deduplicates inline_axis_is_reversed and
block_axis_is_reversed.
2026-04-09 08:33:40 -04:00
Sam Atkins
f993362425 LibWeb/CSS: Reject trailing tokens inside :host() pseudo-class 2026-04-08 15:53:02 +01:00
Sam Atkins
8cd4a19bb0 LibWeb/CSS: Parse combinators and compound-selectors separately
This allows places that want to parse a lone `<compound-selector>` to do
so without also implicitly parsing a combinator before it.

Also add error reporting in a bunch of places that previously failed
silently.
2026-04-08 15:53:02 +01:00
Callum Law
42b93a85fe LibWeb: Remove fallbacks for computing style on disconnected elements
This were introduced in dfe5d00 but only papered over the underlying
issue that we were computing style for element belonging to detached
documents - this underlying fix was implemented in c173a66 so these
fallbacks/guards are no longer needed
2026-04-08 14:31:43 +01:00
Callum Law
8bd1b383ea LibWeb: Use correct inherited font size when canvas is not connected
The default font size for a canvas context is 10px as opposed to 16px
for the document as a whole.
2026-04-08 14:31:43 +01:00
Callum Law
2b0f94fb6f LibWeb: Remove unused method declaration
This method was removed in 1c1476f but this declaration was added back
in 32da7ed, presumably due to a rebase mistake
2026-04-08 14:31:43 +01:00
Callum Law
df73c0e9b5 LibWeb: Don't unnecessarily absolutize style value
We already do this in the caller
2026-04-08 14:31:43 +01:00
Callum Law
4fcb82143b LibWeb: Disallow tree counting functions in most canvas context setters
This matches the behavior of Chrome - tree counting functions are
allowed within on-screen (i.e. not OffscreenCanvas) font values, but
nowhere else.
2026-04-08 14:31:43 +01:00
Callum Law
1fdcea2b7b LibWeb: Disallow random() in canvas context value setters
This introduces two new top-level `ValueParsingContext`s,
`OnScreenCanvasContextFontValue` and `CanvasContextGenericValue`, while
these are handled the same for now, there is a distinction is whether or
not they allow tree counting functions (which will come in a later
commit)
2026-04-08 14:31:43 +01:00
Callum Law
243465391a LibWeb: Cache hardcoded counter styles
This avoids a bunch of string validations reducing time spent in
`CounterStyle::disc()` from ~3% to ~0.01% when loading
https://en.wikipedia.org/wiki/2023_in_American_television
2026-04-08 11:59:57 +01:00
Sam Atkins
67e4633638 LibWeb/CSS: Make SelectorEngine more compatible with AbstractElement
Pass AbstractElement around as the target for match_compound_selector()
and match_simple_selector().

This has no effect yet, as we currently handle the pseudo-element at the
top layer and then pass down an AbstractElement without it, but it'll
matter once we stop doing that.
2026-04-08 10:37:05 +01:00
Sam Atkins
73e602f921 LibWeb/CSS: Rename internal matches() functions
Having 3 different functions named `matches()` that work on different
parts of a selector, all of which take a lot of arguments, makes this
harder to reason about than it needs to be. Rename them like so:
- The public "matches an entire selector" function is still matches()
- matches_compound_selector() for compound selectors
- matches_simple_selector() for simple selectors
2026-04-08 10:37:05 +01:00
Sam Atkins
f11207fee1 LibWeb/CSS: Pass AbstractElement to SelectorEngine::matches
...instead of separate Element and PseudoElement arguments.

As noted, AbstractElement's constness is weird currently, but that's a
tangent I don't want to go on right now.
2026-04-08 10:37:05 +01:00
Sam Atkins
43f0b2845d LibWeb/CSS: Rename Selector::pseudo_element() to target_pseudo_element()
This really represents the final pseudo-element, the one that style
actually applies to. We'll want to know that even once we fully support
having multiple pseudo-elements in a selector.
2026-04-08 10:37:05 +01:00