Commit graph

1454 commits

Author SHA1 Message Date
Sam Atkins
3716db1c61 LibWeb/CSS: Implement converting CSSTransformValues to StyleValues 2025-10-14 13:41:47 +01:00
Sam Atkins
5178d1ebe3 LibWeb/CSS: Add flag to disable create-internal-rep type checking
CSSTransformComponents hold other CSSStyleValues as their parameters. We
want to be able to create internal representations from those parameters
without them caring if they would be valid when directly assigned to the
property.

This is a temporary solution to make transform functions work. To be
completely correct, we need to know what is allowed in that context,
along with value ranges - a combination of the contexts we create when
parsing, and when computing calculations. For transform functions, this
doesn't matter, as there's no limit to the range of allowed values.
2025-10-14 13:41:47 +01:00
Sam Atkins
35fd3bda79 LibWeb/CSS: Promote <transform-list/function> to parsable types
The `transform` property is now parsed based on its JSON data, and
shouldn't behave any differently than before.

This makes `<transform-list>` and `<transform-function>` work in the
`syntax` descriptor for `@property`, and also means we know that
`transform` can accept the `none` keyword. We get a few WPT passes out
of that.
2025-10-14 13:41:47 +01:00
Sam Atkins
8fffce07df LibWeb/CSS: Remove unused GenericShorthands.h include 2025-10-14 13:41:47 +01:00
Tim Ledbetter
701ef22952 LibWeb: Use correct percentage basis when resolving line height
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-10-13 10:17:58 +01:00
Sam Atkins
078bc1a471 LibWeb/CSS: Allow converting CSSMathValues to StyleValues
Because we store calculations as a tree of CalculationNodes inside a
CalculatedStyleValue, instead of a tree of StyleValues directly, this
implements a create_calculation_node() method on CSSNumericValue.
CSSMathValue::create_an_internal_representation() then calls
create_calculation_node() on itself, and wraps it in a
CalculatedStyleValue.

Lots of WPT passes again! Some regressions, which are expected: `cursor`
fails a test for the same reason it fails other that set it to some
kind of numeric value: We don't distinguish between "can contain a
number" and "can accept a number by itself". This will affect any
similar properties, but overall this is a big improvement.
2025-10-13 09:59:38 +01:00
Sam Atkins
df7abe1dc2 LibWeb/CSS: Extract CSSUnitValue -> CSS Value code
create_numeric_value() will be used next to create a CalculationNode,
and I didn't want to have to duplicate the "create a value based on the
unit name" code.

No behaviour change.
2025-10-13 09:59:38 +01:00
Sam Atkins
0afa93e639 LibWeb/CSS: Add a Property -> CalculationContext factory method
We have this code duplicated in multiple places, and we'll want to
handle registered custom properties too at some point, so wrap it in a
reusable `CalculationContext::for_property()` method.

Noticed while doing this that ValueParsingContext will eventually need
to take a PropertyNameAndID, not a PropertyID, so I've added a FIXME.
2025-10-13 09:59:38 +01:00
Aliaksandr Kalenik
835081d66e LibWeb+LibWebView+WebContent: Reset pinch-to-zoom state on Ctrl/Cmd+0 2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
9862d8b4a6 LibWeb: Implement pinch-to-zoom support
Adds pinch event handling that adjusts the VisualViewport scale and
offset. VisualViewport's (offset, scale) is then used to construct a
transformation matrix which is applied before display list execution.
2025-10-10 15:37:45 +02:00
Aliaksandr Kalenik
b477c6bfc4 LibWeb: Implement VisualViewport aware viewport scrolling
Implements spec algorithm for viewport scrolling that first checks if
it's possible to use delta to move the visual viewport before falling
back to scrolling the layout viewport. This is a part of pinch-to-zoom
support.
2025-10-10 15:37:45 +02:00
Sam Atkins
f61c67792d LibWeb/CSS: Allow setting shorthand values with StylePropertyMap.set()
Shorthands should be broken up into their longhands, instead of setting
them directly.

There's a catch here with our "positional value list shorthands" like
`margin`: Setting margin to a single value like `CSSUnitValue(10, "px")`
is supposed to fail here, but our type-checking code thinks it's valid
because our JSON for `margin` says it accepts lengths. This is the same
kind of issue that we had for `cursor` discussed in the
"LibWeb/CSS: Support converting CSSUnitValue to a StyleValue" commit.

Will get us a few subtest passes for every shorthand that's tested.
2025-10-09 16:14:58 +02:00
Sam Atkins
0015ee310c LibWeb/CSS: Support converting CSSUnparsedValue to a StyleValue
Unfortunately this doesn't pass a lot of tests, because we strip out
whitespace when parsing property values. In particular, the WPT suite
tests with this:

```js
new CSSUnparsedValue([' ', new CSSVariableReferenceValue('--A')])
```

...which gets the whitespace stripped from the string, meaning when we
convert the value back to JS, we get the equivalent of this:

```js
new CSSUnparsedValue(['', new CSSVariableReferenceValue('--A')])
```

...and that's not the same so the test fails.
2025-10-09 16:14:58 +02:00
Sam Atkins
9ef523ebb2 LibWeb/CSS: Prevent infinite recursion in CSSUnparsedValue::to_string()
As noted in the linked spec issue, it's possible for an author to
construct a CSSUnparsedValue that contains itself, meaning
serialization would be infinitely recursive. So instead, detect that
and then return an empty string, which copies Blink's solution to this
issue.

Stops `css/css-typed-om/cycle-in-unparsed-value-crash.html` from
crashing after we implement converting a CSSUnparsedValue to an
UnresolvedStyleValue, as that relies on serialization.
2025-10-09 16:14:58 +02:00
Sam Atkins
882bdbb019 LibWeb/CSS: Stop asserting that UnresolvedSV contains an ASF
Typed-OM means that the author can set a property's value to a
CSSUnparsedValue, which may or may not have any arbitrary substitution
functions in it. This VERIFY was just there to catch parsing bugs that
created UnresolvedStyleValues unnecessarily, and removing it is
harmless.
2025-10-09 16:14:58 +02:00
Sam Atkins
97a9082251 LibWeb/CSS: Check for var() after converting strings in Typed OM set()
This avoids regressions in the next commit.

See the linked spec issue for details. Without this, we end up doing the
wrong thing in cases like this, from a WPT test:

```js
styleMap.set('transition-duration', '1s', 'var(--A)');
```

`'var(--A)'` is a string, not a CSSVariableReferenceValue or
CSSUnparsedValue. Following the spec literally, we wouldn't throw a
TypeError here, even though we really should: The purpose of the check
is for list-valued properties, to prevent authors putting a series of
tokens that would represent multiple list items, into a single list
item slot.

So, we delay the check until after we've converted strings into values.
This does mean we're checking StyleValues instead of CSSStyleValues,
and it also means we've done more work before rejecting the input as
invalid. But correctness is nice. :^)
2025-10-09 16:14:58 +02:00
Sam Atkins
3644e75de1 LibWeb/CSS: Allow setting any property to CSS-wide keywords in typed OM
A minor thing I missed before. Gets us 4 WPT passes per property that's
tested, which is quite a lot.
2025-10-09 16:14:58 +02:00
Sam Atkins
b2d55e4caa LibWeb/CSS: Support converting CSSUnitValue to a StyleValue
A lone CSSUnitValue can now be converted to a dimension StyleValue of
the relevant type, as long as the property allows that type. If the
value is out of the allowed range, it's wrapped in calc().

There are a few failing tests still, involving setting a negative
percentage and expecting to read the computed value as 0. Those also
fail in Chromium, and a similar negative-length test expects a negative
computed value (not 0), so this appears to be an incorrect test.

Also, we regress some of the `cursor` tests. This is because our "does
property X accept type Y?" code is too naive: `cursor` is defined to
accept "number [-∞,∞]" in the JSON, and that value range is used when
clamping the result of calculations or interpolation. But because that
entry is there, we think a single number is a valid value for `cursor`.
Solving this generally is a larger task than I want to take on right
now. :^)
2025-10-09 16:14:58 +02:00
Sam Atkins
bd545af210 LibWeb/CSS: Support calculated percentages in line-height
Without this, the imported test will crash once we implement
`CSSUnitValue::create_an_internal_representation()`.
2025-10-09 16:14:58 +02:00
Callum Law
102edf638d LibWeb: Support interpolation of SuperellipseStyleValue
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
2025-10-09 10:23:20 +01:00
Callum Law
20a2e8ab12 LibWeb: Store corner-*-shape properties in computed form 2025-10-09 10:23:20 +01:00
Callum Law
397e39f316 LibWeb: Support corner-*-shape logical properties 2025-10-09 10:23:20 +01:00
Callum Law
7305b3fa28 LibWeb: Parse corner-*-shape physical shorthands 2025-10-09 10:23:20 +01:00
Callum Law
814efa9809 LibWeb: Parse corner-*-shape physical longhands 2025-10-09 10:23:20 +01:00
Tim Ledbetter
03fa367d9d LibWeb: Parse the anchor-scope property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
85a15ea1d4 LibWeb: Parse the position-visibility value 2025-10-07 11:30:23 +01:00
Tim Ledbetter
47966ed589 LibWeb: Parse the position-try-order property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
2bde14b148 LibWeb: Parse the position-try-fallbacks property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
27cdf3a2c8 LibWeb: Parse the position-anchor property 2025-10-07 11:30:23 +01:00
Tim Ledbetter
7374a07fbc LibWeb: Parse the anchor-name property 2025-10-07 11:30:23 +01:00
Callum Law
846f1626dd LibWeb: Remove unused {Calculated,Percentage}Or::absolutized methods
Reverts c8bd58c and 0df9c22. These were used to absolutize values stored
within other `StyleValue`s but we should instead store these values as
`StyleValue`s directly instead of within `{Calculated,Percentage}Or`.
2025-10-07 10:50:01 +01:00
Callum Law
e772a992be LibWeb: Store CursorStyleValue sub-values directly
Storing these within NumberOrCalculated is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
25192d3c20 LibWeb: Store BorderRadiusStyleValue sub-values directly
Storing these within LengthPercentage is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
2ebf446cbf LibWeb: Store BackgroundSizeStyleValue sub-values directly
Storing these within LengthPercentage is unnecessary
2025-10-07 10:50:01 +01:00
Callum Law
309ff33278 LibWeb: Add convenience from_style_value for LengthPercentage{OrAuto} 2025-10-07 10:50:01 +01:00
Callum Law
4a998879d5 LibWeb: Add absolutized method for TransformStyleValue 2025-10-07 10:50:01 +01:00
Callum Law
e675b95f51 LibWeb: Add absolutized method to OpenTypeTaggedStyleValue 2025-10-07 10:50:01 +01:00
Callum Law
2c7b56511b LibWeb: Add absolutized method to CounterDefinitionsStyleValue
This avoids a crash when a counter value relies on relative units
2025-10-07 10:50:01 +01:00
Callum Law
52192a308b LibWeb: Update absolutize to take a ComputationContext struct
This struct will in the future hold information other than a length
resolution context (e.g. context for tree counting functions) and a
single struct is easier to work with than multiple parameters.
2025-10-07 10:50:01 +01:00
Callum Law
47ffffb775 LibWeb: Absolutize value at start of compute_value_of_property
This saves us having to do it in various places later on.
2025-10-07 10:50:01 +01:00
Callum Law
28c12324c2 LibWeb: Remove unused NumericCalculationNode::to_style_value 2025-10-07 10:50:01 +01:00
Callum Law
f2a302663c LibWeb: Simplify value parsing code
We know that `parse_calculated_value` returns a
`RefPtr<CalculatedStyleValue const>` so we can avoid various checks on
the StyleValue type.
2025-10-07 10:50:01 +01:00
Callum Law
2098e516d2 LibWeb: Update layout of ancestor documents when getting computed style
Pending changes to an ancestor document's layout can affect an element's
computed style e.g. an IFrame's width being changed can affect media
query evaluation and the value of the `vw` unit.
2025-10-07 10:32:59 +01:00
Callum Law
05c336ea4e LibWeb: Use document's viewport when resolving lengths in media queries
Previously we would always use the window's viewport which was incorrect
if we were within an iframe.

This is likely applicable to all uses of
`Length::ResolutionContext::for_window`.
2025-10-07 10:32:59 +01:00
Callum Law
c33be71df9 LibWeb: Use correct value for font size in MediaFeature::compare
We were using the font's point size instead of it's pixel size, we were
already computing this information earlier in the function anyway so
let's just use that.
2025-10-07 10:32:59 +01:00
Callum Law
eeb3890ad7 LibWeb: Resolve stroke-dasharray percentages as lengths
Fixes a crash on https://collabskus.github.io/
2025-10-07 10:19:26 +01:00
Tim Ledbetter
51ea4a7e2a LibWeb: Align position-area values with the specification
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This change renames the following `position-area` values:

x-self-start -> self-x-start
x-self-end -> self-x-end
y-self-start -> self-y-start
y-self-end -> self-y-end
span-x-self-start -> span-self-x-start
span-x-self-end -> span-self-x-end
span-y-self-start -> span-self-y-start
span-y-self-end -> span-self-y-end
2025-10-05 15:48:21 +01:00
Sam Atkins
feafaf09fc LibWeb/CSS: Support converting CSSImageValue to a StyleValue
Some checks are pending
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
No known WPT improvements. CSSImageValue is a black box which we
implement the same as CSSStyleValue, so this may not be observably
different.
2025-10-04 22:57:00 +02:00
Sam Atkins
d855b3d90f LibWeb/CSS: Support converting CSSKeywordValue to a StyleValue
Either KeywordStyleValue or CustomIdentStyleValue depending on whether
we recognize it as a CSS::Keyword.
2025-10-04 22:57:00 +02:00
Sam Atkins
84f0f37a29 LibWeb/CSS: Implement StylePropertyMap::set()
With this commit, only direct CSSStyleValues created from internal
StyleValues can be converted back to a StyleValue. More subtests will
pass as create_an_internal_representation() is implemented for the
various CSSStyleValue subclasses. :^)

Gets us... a LOT of WPT passes, because there's a ton of coverage for
each property.
2025-10-04 22:57:00 +02:00