Commit graph

129 commits

Author SHA1 Message Date
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
Psychpsyo
27e4793c5d LibWeb: Make ObjectPosition more reusable 2025-11-21 11:14:28 +00:00
Callum Law
408bbead31 LibWeb: Don't mangle inherited properties when updating animated style 2025-11-21 09:24:53 +01:00
Sam Atkins
c4b9e7eadf LibWeb: Parse and propagate extended text-indent property values
CSS Text 3 gives `text-indent` a couple of optional keywords to control
which lines are affected. This commit parses them, but doesn't yet do
anything with them.
2025-11-20 16:02:40 +01:00
Psychpsyo
100f37995f Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
Callum Law
d6bb247bf7 LibWeb: Reject non-exclusive none in text-decoration-line
This updates the `parse_text_decoration_line_value` to reject values
which non-exclusively include `none` e.g. `underline none`.

It also simplifies handling by always producing a Vector (except for
`none`) and adding VERIFY_NOT_REACHED in more places which shouldn't be
reachable.
2025-11-13 10:15:02 +01:00
Psychpsyo
e064fa19d2 LibWeb: Add transform-style and have it make a stacking context 2025-11-12 15:47:36 +01:00
Psychpsyo
eb21ea890c LibWeb: Implement CSS perspective property 2025-11-12 00:41:14 +01:00
Callum Law
bbb344d534 LibWeb: Compute font features in ComputedProperties
By doing this in computed properties rather than InlineLevelIterator we
only do it once per element rather than once per text fragment.

Reduces runtime of this process from ~15% to ~0.2% when loading
https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-10 12:11:36 +01:00
Callum Law
7a5b948b5b LibWeb: Resolve more calculated values in ComputedProperties
We simplify these at style computation time so there is no need to
maintain them as {Number|Length}OrCalculated

Reduces the time spent in `Length::ResolutionContext::for_layout_node`
from 3.3% to 0.4% when loading
https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-10 12:11:36 +01:00
stelar7
0f3a9a6958 LibWeb/CSS: Use correct property when looking up container-type 2025-11-06 13:28:17 +01:00
Callum Law
76dadd45d6 LibWeb: Favour !important property values over animated values 2025-10-27 09:51:50 +00:00
Callum Law
823dd11b67 LibWeb: Add ComputedProperties::set_property_without_modifying_flags
There are a few places in style computation where we want to update the
value of a property without modifying the inherited or important flags.

Previously we would look up these flags and pass them to the normal
`set_property` method but this is unnecessary and was easy to forget to
do.
2025-10-27 09:51:50 +00:00
Callum Law
84762021b8 LibWeb: Support triggering multiple animations per animation property
We also now use the computed (rather than cascaded) values when
triggering animations.
2025-10-27 09:48:25 +00:00
Callum Law
fc5cdd69a0 LibWeb: Extract transition coordination logic to reusable method
This will be useful for other coordinating list property groups (e.g.
background and animation)
2025-10-23 10:09:11 +01:00
Callum Law
309ff33278 LibWeb: Add convenience from_style_value for LengthPercentage{OrAuto} 2025-10-07 10:50:01 +01:00
Sam Atkins
3916e33276 LibWeb/CSS: Parse the container-type property
This applies size, inline-size, and style containment in some cases.
There are other WPT tests for that, but we seem to not implement enough
of containment for this to have an effect so I've not imported those.

Gets us 35 WPT subtests.
2025-09-30 22:05:45 +01:00
Pascal Pomper
5b1eba7ac8 LibWeb: Position absolute block-level boxes below previous siblings
Whether an absbox is positioned below or to the right of its previous
sibling in an `InlineFormattingContext` is determined by the
display-outside value before blockification, so we store the
pre-blockification `display` value in `ComputedValues` to access it in
`InlineFormattingContext` and position the box accordingly.
2025-09-29 18:37:53 +02:00
Sam Atkins
0314606c73 LibWeb/CSS: Replace resolve_length_deprecated() with resolve_length() 2025-09-24 16:33:53 +01:00
Sam Atkins
0dba531772 LibWeb/CSS: Replace resolve_number_deprecated() with resolve_number() 2025-09-24 16:33:53 +01:00
Sam Atkins
d9a386fa81 LibWeb/CSS: Replace resolve_integer_deprecated() with resolve_integer() 2025-09-24 16:33:53 +01:00
Callum Law
af32413dec LibWeb: Store line-height in ComputedProperties in computed form
We now fail a few more tests in properties-value-inherit-001.txt as we
no longer overwrite the non-animated value of `line-height` with the
animated value, this is in line with other major browsers.
2025-09-23 15:57:32 +01:00
Callum Law
dc41d045d8 LibWeb: Store font-style in ComputedProperties in computed form 2025-09-19 10:06:33 +01:00
Callum Law
335c8c7ffb LibWeb: Store font-width in ComputedProperties in computed form 2025-09-19 10:06:33 +01:00
Callum Law
39484e2027 LibWeb: Store font-weight in ComputedProperties in computed form
We now also more closely follow the spec when computing values for
font-weight and we now:
 - Support relative lengths in `calc()`s
 - Properly clamp `calc()`s
 - Support relative keywords (e.g. lighter, bolder)
 - Respect that font-weight can be a non-integer number.

This does expose a few false positives in the font-weight-computed.html
WPT test. This is because we don't recompute non-inherited font-weight
within `recompute_inherited_style` which means that relative keyword
values can fall out of sync with their parent's value. These previously
passed as we treated `bolder` and `lighter` as aliases for `bold` and
`normal` respectively.
2025-09-19 10:06:33 +01:00
Callum Law
cfbe0244d4 LibWeb: Use computed value of font-size in keyframes
Remaining test failures in font-size-interpolation-00* are either:
 - Rounding of font-size to CSSPixels when setting the expected value
 - Not clamping negative values from the point of view of
   getComputedStyle (used values are still clamped)
2025-09-19 10:06:33 +01:00
Callum Law
004bd3dc8f LibWeb: Clamp calc()'d shadow blur radius to positive values 2025-09-18 15:21:22 +01:00
Callum Law
34b8947ca0 LibWeb: Support text-underline-position: under 2025-09-15 15:24:20 +01:00
Callum Law
815e77c04d LibWeb: Respect text-underline-offset when rendering underlines 2025-09-12 07:07:15 +01:00
Sam Atkins
b3e32445d3 LibWeb/CSS: Use generated FooUnit types instead of Foo::Type
I've also renamed the `m_type` and `type()` members to be `m_unit` and
`unit()` instead, to match what they actually are.
2025-09-11 17:06:44 +01:00
Tim Ledbetter
831088939a LibWeb: Return word-spacing computed value as CSSPixels 2025-09-10 16:12:29 +01:00
Tim Ledbetter
099247d502 LibWeb: Return letter-spacing computed value as CSSPixels 2025-09-10 16:12:29 +01:00
Callum Law
f061f565b9 LibWeb: Remove unused ComputedProperties::resolve_opacity_value 2025-09-08 11:03:32 +01:00
Callum Law
5a7eaf6f73 LibWeb: Store flood-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
91e88ad6e8 LibWeb: Store stroke-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
c045969234 LibWeb: Store stop-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
9434b08bed LibWeb: Store fill-opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00
Callum Law
1ba84de4f6 LibWeb: Store opacity in computed form in ComputedProperties 2025-09-08 11:03:32 +01:00