Commit graph

2302 commits

Author SHA1 Message Date
Sam Atkins
5d965d6d37 LibWeb/CSS: Simplify parse_as_pseudo_element_selector()
Now that we have a method that parses a single pseudo-element selector,
use that. This actually fixes a bug too.
2026-04-18 08:56:25 +02:00
Andreas Kling
bc01fc3280 LibWeb: Use pre-cached specificity when sorting matching CSS rules
sort_matching_rules() was calling Selector::specificity() inside the
sort comparator. MatchingRule already caches the specificity value
at rule insertion time, so use that directly instead.
2026-04-17 16:23:15 +02:00
Sam Atkins
2b47098301 LibWeb/CSS: Un-deprecate TokenStream::peek_token()
This is sometimes the best tool for the job. To try and make it less of
a footgun that peek_token() is identical to next_token(), make the
offset required, and note the shared behaviour. Also move them
together, and make the internal code match.
2026-04-16 14:52:22 +01:00
Sam Atkins
1f8a8870c3 LibWeb/CSS: Replace trivial peek_token() users with next_token()
`next_token()` does the same thing as `peek_token()` or `peek_token(0)`,
but is more idiomatic.
2026-04-16 14:52:22 +01:00
Sam Atkins
f938829619 LibWeb/CSS: Remove a couple of deprecated TokenStream methods 2026-04-16 14:52:22 +01:00
Sam Atkins
e7e0a48144 LibWeb/CSS: Stop reconsuming tokens in an+b parsing
The main change is that we now wait to consume the token until we know
we want it, instead of consuming it and then later putting it back.

While I was here, I spec-commented some parts and updated the URL.
2026-04-16 14:52:22 +01:00
Sam Atkins
d7c2524311 LibWeb: Stop reconsuming tokens to parse shorthands
Reconsuming the current token relies on parse_css_value_for_properties()
only consuming a single token, which may be true now but isn't safe to
assume. Wrapping that in a Transaction and reverting it if we need to
run manual parsing, is a much safer pattern.

Ideally we'll get parse_css_value_for_properties() to run the
per-property bespoke parsing code eventually.
2026-04-16 14:52:22 +01:00
Sam Atkins
b661c17117 LibWeb/CSS: Stop reconsuming tokens in parse_simple_selector()
No behaviour change, just a refactor to stop using a deprecated API.
2026-04-16 14:52:22 +01:00
Sam Atkins
7eabbfaa4b LibWeb/CSS: Use Transaction for checking tokens' substitution presence
Equivalent to using mark() and restore_a_mark() from before, except it
runs even if we return a SyntaxError.

Also removes the deprecated reconsume_current_input_token() call - this
never actually did anything useful anyway.
2026-04-16 14:52:22 +01:00
Sam Atkins
1239ebad29 LibWeb/CSS: Use transaction for attribute selector match-type parsing
No behaviour change, just a refactor to stop using a deprecated API -
reconsuming tokens.
2026-04-16 14:52:22 +01:00
Sam Atkins
3681452386 LibWeb/CSS: Stop reconsuming tokens in convert_to_keyframes_rule()
No behaviour change, just a refactor to stop using a deprecated API.
2026-04-16 14:52:22 +01:00
Sam Atkins
3342d880e8 LibWeb/CSS: Use a transaction for simple comma-separated list parsing
No behaviour change, just a refactor to stop using a deprecated API.
2026-04-16 14:52:22 +01:00
Tim Ledbetter
176e1a5a7c LibWeb: Don't clamp LCH/OKLCH chroma max value during serialization 2026-04-16 12:06:10 +02:00
Tim Ledbetter
49fa4d702d LibWeb: Apply color-mix() alpha multiplier in the absolutized path
When the two component percentages of color-mix() sum
to less than 100%, the remainder is used as an alpha multiplier applied
to the interpolated result's alpha. Previously, this was only applied
in the runtime `to_color()` path, not when computing the absolutized
value used by `getComputedStyle()`.

Switch both paths to use `perform_color_interpolation()` directly so the
alpha multiplier can be applied to the interpolated components before
they are converted to a style value.
2026-04-16 12:06:10 +02:00
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