Commit graph

166 commits

Author SHA1 Message Date
Aliaksandr Kalenik
795222fab3 LibWeb: Validate grid-template-areas rectangles at parse time
Move grid area rectangle computation and validation from layout to the
CSS parser. Named grid areas that don't form filled-in rectangles now
correctly invalidate the declaration per spec.
2026-02-21 21:46:34 +01:00
Callum Law
e6669482e6 LibWeb: Parse font-variant-alternates functions 2026-02-20 22:01:44 +00:00
Callum Law
1be9f1ae9d LibWeb: Move Gfx::FontVariantAlternates to CSS namespace
This is only ever used in the CSS namespace
2026-02-20 22:01:44 +00:00
Callum Law
1faaf83121 LibWeb: Move Gfx::FontVariantLigatures to the CSS namespace
This is only ever used in the CSS namespace and having it there allows
us to reuse existing enums
2026-02-20 22:01:44 +00:00
Callum Law
849e55b7ae LibWeb: Simplify parsing of font-variant-numeric 2026-02-20 22:01:44 +00:00
Callum Law
afc6b7b24c LibWeb: Move Gfx::FontVariantLigatures to the CSS namespace
This is only ever used in the CSS namespace and having it there allows
us to reuse existing enums
2026-02-20 22:01:44 +00:00
Callum Law
f511b95b81 LibWeb: Simplify parsing of font-variant-ligatures 2026-02-20 22:01:44 +00:00
Callum Law
f0dd7ec4e9 LibWeb: Move Gfx::FontVariantEastAsian to CSS namespace
This is only ever used in the CSS namespace and having it there allows
us to reuse existing enums
2026-02-20 22:01:44 +00:00
Callum Law
d6b94951cf LibWeb: Simplify parsing of font-variant-east-asian 2026-02-20 22:01:44 +00:00
Callum Law
d998a0aeeb LibWeb: Add generic string_from_style_value method
Reduces duplication in line with `Time::from_style_value()`,
`Angle::from_style_value()` etc
2026-02-17 12:25:27 +00:00
Callum Law
cd799aa7e7 LibWeb: Forward declare CSS::FilterOperation structs
This means we don't need to include `FilterValueListStyleValue.h` in as
many places - reducing the rebuild from editing that file from 717 files
to 19.
2026-02-16 12:09:23 +00:00
Callum Law
3d3d0a50b6 LibWeb: Add generic Length::from_style_value method 2026-02-16 12:09:23 +00:00
Callum Law
846493831d LibWeb: Add generic number_from_style_value method 2026-02-16 12:09:23 +00:00
Callum Law
8a82d116d6 LibWeb: Always parse <counter-style> as such
Previously we parsed it as `<custom-ident>` in `<counter>` and as a
keyword in `list-style-type`.

The practical effect of this is:
 - Spec defined counter style names in `<counter>` are ASCII lowercased
   on parse.
 - Non spec defined counter style names are allowed in `list-style-type.

We are still to parse the `symbols()` function but this gives us a
better base for that.
2026-02-12 10:33:09 +00:00
Callum Law
05cafdb5d0 LibWeb: Remove none from counter-style-name-keyword
`none` isn't a supported value for `<counter-style-name>` and is only
supported directly by `list-style-type` (i.e. not within `counter{s}()`
functions)
2026-02-12 10:33:09 +00:00
Callum Law
258f223a41 LibWeb: Support calculated number values for stroke-dasharray 2026-02-12 10:26:43 +00:00
Callum Law
e8354fed48 LibWeb: Avoid use of NumberOrCalculated for stroke-dasharray
This is already fully absolutized as part of the computation process so
we can resolve it in `ComputedProperties::stroke_dasharray` instead of
persisting it as a `NumberOrCalculated`
2026-02-12 10:26:43 +00:00
Callum Law
87eef9e21a LibWeb: Always apply stroke-dasharray
Previously we didn't apply the value of `stroke-dasharray` if it was
`none`.

We also move resolution of this property into `ComputedProperties` in
line with other properties.
2026-02-12 10:26:43 +00:00
Callum Law
379db7a42c LibWeb: Support animation-timeline scroll() value 2026-02-11 10:49:34 +01:00
Callum Law
61b0b20f11 LibWeb: Respect animation-timeline: none 2026-02-11 10:49:34 +01:00
Callum Law
11d524bda4 LibWeb: Support CSS font-optical-sizing property 2026-02-03 11:44:25 +00:00
Callum Law
0c4bab4390 LibWeb: Simplify ComputedProperties::length_box
Value clamping is no longer required since we now do it at interpolation
time (96b628f)
2026-02-03 10:33:04 +00:00
Callum Law
f13e0bb8a5 LibWeb: Replace ComputedProperties::length_percentage
Since we now clamp values as part of interpolation (96b628f) this
function is equivalent to `LengthPercentage::from_style_value`
2026-02-03 10:33:04 +00:00
Callum Law
b55023fad3 LibGfx+LibWeb: Resolve font features per font rather than per element
Previously we would resolve font features
(https://drafts.csswg.org/css-fonts-4/#feature-variation-precedence)
per element, while this works for the current subset of the font feature
resolution algorithm that we support, some as yet unimplemented parts
require us to know whether we are resolving against a CSS @font-face
rule, and if so which one (e.g. applying descriptors from the @font-face
rule, deciding which @font-feature-values rules to apply, etc).

To achieve this we store the data required to resolve font features in a
struct and pass that to `FontComputer` which resolves the font features
and stores them with the computed `Font`.

We no longer need to invalidate the font shaping cache when features
change since the features are defined per font (and therefore won't ever
change).
2026-02-02 14:11:43 +00:00
Callum Law
a76ed0e3a9 LibWeb: Use FlyString for ComputedProperties::font_feature_settings()
We are going to be storing this returned value in a future commit so we
should use `FlyString` rather than `StringView` to avoid use after free
2026-02-02 14:11:43 +00:00
Callum Law
2c3ddc294f LibWeb: Compute math-depth in line with other font properties
The main change here is that we now properly absolutize values which
means we now support `random()` and `sibling-{count,index}()`

We are also more consistent with how we handle computation for the other
font properties
2026-01-15 12:03:16 +00:00
Callum Law
27dd77a538 LibWeb: Don't store resolved math depth directly
There's no need to store this twice

We also now use `set_property_without_modifying_flags` to avoid
overwriting inherited/important flags
2026-01-15 12:03:16 +00:00
Callum Law
eb5b73d3b5 LibWeb: Use existing StyleValues for math-depth
Previously we implemented an all encompassing `MathDepthStyleValue`
specifically for the `math-depth` property, this was unnecessary since
we can represent `auto-add` and `<integer>` using existing `StyleValue`
classes.

This brings the values created from parsing in line with those set via
`StylePropertyMap` which allows us to simplify computation
2026-01-15 12:03:16 +00:00
Jonathan Gamble
4579bb5bed LibWeb: Add resize property plumbing 2026-01-12 11:00:14 +00:00
Callum Law
2e66203ede LibWeb: Add early return from ComputedProperties::animations()
If all the values of `animation-name` are `none` we can exit early and
save a bunch of work.

Reduces time spent in this function from 1.23% to 0.01% when loading
https://en.wikipedia.org/wiki/2023_in_American_television
2026-01-05 11:35:26 +00:00
Callum Law
79740b04b3 LibWeb: Don't generate layer for background-image none entry
Reduces the time spent in `background_layers()` from 1.5% to 0.04% when
loading https://en.wikipedia.org/wiki/2023_in_American_television
2026-01-05 11:35:26 +00:00
Callum Law
1708ce2e2b LibWeb: Propagate background-clip value for color layer separately
This is required for an optimization in a later commit
2026-01-05 11:35:26 +00:00
Callum Law
558f034007 LibWeb: Consolidate transition computation
Previously the logic to compute transitions was split across
`ComputedProperties`, `StyleComputer`, and `Animatable` - this commit
consolidates it all in `ComputedProperties`
2026-01-05 11:35:26 +00:00
Callum Law
6964593377 LibWeb: Add absolutized method to EdgeStyleValue
Fixes #7192.

We absolutize `EdgeStyleValue` to always be relative to the top/left
edge which allows for some simplification.
2026-01-02 11:43:10 +01:00
Callum Law
e6ddb7db9e LibWeb: Store EdgeStyleValue sub-values directly
As well as being required to implement absolutization this also means we
now bypass a limitation with `LengthPercentage` where we would always
use `SerializationMode::Normal` for the constituent lengths which gains
us some WPT passes
2026-01-02 11:43:10 +01:00
Sam Atkins
c446281844 LibWeb/CSS: Remove Transformation in favor of TransformationStyleValue
The Transformation class wasn't really accomplishing anything. It still
had to store StyleValues, so it was basically the same as
TransformationStyleValue, with extra steps to convert from one to the
other. So... let's just use TransformationStyleValue instead!

Apart from moving code around, the behavior has changed a bit. We now
actually acknowledge unresolvable parameters and return an error when
we try to produce a matrix from them. Previously we just skipped over
them, which was pretty wrong. This gets us an extra pass in the
typed-om test.

We also get some slightly different results with our transform
serialization, because we're not converting to CSSPixels and back.
2025-12-19 14:51:53 +01:00
Callum Law
a11666e097 LibWeb: Simplify creation of background layers
We can deduplicate some code by using `assemble_coordinated_value_list`,
also moves this to a method in `ComputedProperties` to be in line with
other values
2025-12-08 11:46:50 +00:00
Callum Law
dca80ad5eb LibWeb: Account for animated values when computing font
Computing the font for an element in `compute_font` is premature since
we are yet to apply animated properties - instead we should compute the
value on the fly (with a cache to avoid unnecessary work) to ensure we
are respecting the latest values
2025-12-05 10:03:15 +00:00
Callum Law
dfa47d9ed6 LibWeb: Simplify handling of font-variation-settings
Since we resolve any relative lengths at compute time there's no need
for the value to be passed around as a `NumberOrCalculated` and we can
just resolve it within `ComputedProperties::font_variation_settings`.

The only place this is used it is used with value_or so there's no need
to return it is an `Optional`.

This is only used for loading fonts (which occurs during style
computation) so there's no need to store it in `ComputedValues`
2025-12-05 10:03:15 +00:00
Callum Law
38efc39e17 LibWeb: Simplify assemble_coordinated_value_list
We know that all coordinated value list longhands are parsed as
`StyleValueList`s
2025-12-02 12:47:10 +00:00
Sam Atkins
d9abfdf2ab LibWeb/CSS: Allow non-StyleValueLists in animation properties
Reverts 51f694c6af and
b52beb5105.

The animation-* properties are in an awkward place currently, where
they *should* be lists, and a lot of our code acts as if they are, but
actually we parse them as single values. The above commits caused a few
WPT tests to crash - see link below. I've imported one of them to
prevent future regressions.
https://wpt.fyi/results/css/css-typed-om/the-stylepropertymap/properties?diff&filter=ADC&run_id=6293362870321152&run_id=5123272984494080
2025-12-02 09:48:32 +00:00
Sam Atkins
d5d1b5351e LibWeb: Hide stepper buttons on appearance: textfield number inputs
The spec says:

> For the purpose of this specification, they all have the same effect
  as auto. However, the host language may also take these values into
  account when defining the native appearance of the element.

https://drafts.csswg.org/css-ui/#typedef-appearance-compat-special

Firefox at least hides the stepper buttons when this is set.
2025-12-01 11:10:13 +00:00
Callum Law
47bed173b4 LibWeb: Simplify ComputedProperties::will_change()
We know that `will-change` parses as either `Keyword::Auto` or
`StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
b52beb5105 LibWeb: Simplify assemble_coordinated_value_list
We know that all coordinated value list longhands are parsed as
`StyleValueList`s
2025-12-01 10:16:41 +00:00
Callum Law
0595d52be2 LibWeb: Simplify handling of {text,box}-shadow
We know that shadow values are always parsed as a `KeywordStyleValue`
with `Keyword::None` or a `StyleValueList`
2025-12-01 10:16:41 +00:00
Callum Law
63538c8a75 LibWeb: Prefer transitioned property values over important
CSS transitions have a higher precedence in the cascade than important
properties
2025-11-28 16:15:49 +00:00
Callum Law
826e947920 LibWeb: Propagate 'auto' value of animation-duration
Avoids a crash when `animation-duration` was `auto`
2025-11-28 13:24:11 +00:00
Callum Law
b2b889e1da LibWeb: Ensure registered transitions are reflective of properties
Previously we would only update these if:
a) We had a cascaded value for `transition-property`
b) The source of that cascaded value had changed since we last
   registered transitions

This meant that there were a lot of changes we didn't apply:
 - Changes exclusively to properties other than `transition-property`
   (e.g. `transition-duration`, `transition-behavior`, etc)
 - Removing the `transition-property` property
 - Updating the `transition-property` property in a way that didn't
   change it's source (e.g. setting it within inline-style)

Unfortunately this does mean that we now register transitions for all
properties on most elements since "all" is the initial value for
"transition-property" which isn't great for performance, but that can be
looked at in later commits.
2025-11-23 09:43:24 +01:00
Callum Law
2f0cd9f739 LibWeb: Add Time::from_style_value
This method takes a `TimeStyleValue`, `PercentageStyleValue` or
fully-simplified `CalculatedStyleValue` with a numeric type of time, as
well as a percentage basis and produces the equivalent `Time` value.

This saves us having to reimplement this logic in multiple places
2025-11-23 09:43:24 +01:00
Psychpsyo
2db3796fd3 LibWeb: Implement CSS perspective-origin 2025-11-21 11:14:28 +00:00