Commit graph

253 commits

Author SHA1 Message Date
Sam Atkins
995c19da56 LibWeb/CSS: Return unit names as FlyStrings
From the CSS token side, we already have these in FlyString form. From
the generated code side, we can easily return FlyStrings instead of
StringViews. So, let's do that, and save some work converting back and
forth.
2025-09-12 13:45:41 +02:00
Sam Atkins
583d74e3a9 LibWeb/DOM: Reduce AbstractElement.h's includes
This doesn't need all of Selector.h and its various includes, it just
needs the PseudoElement enum.

StringStyleValue.h was transitively including ComponentValue.h through
this, so it now includes it directly.
2025-09-11 18:45:35 +02: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
Callum Law
1c2c77b441 LibWeb: Remove unnecessary handling of StyleValueList border longhands
This is no longer needed as we parse border longhands directly to
ShorthandStyleValues
2025-09-09 11:45:47 +02:00
Callum Law
5ed3b2ed16 LibWeb: Support interpolation of CalculatedStyleValue
We also support interpolating from a CalculatedStyleValue to a
compatible dimension or percentage style value.

This also brings with it a couple of improvements in how we handle
interpolation between mixed dimension and percentage types in terms of:
 - Proper simplification of the resulting calc()
 - Improved handling of interpolation outside the 0-1 range
2025-09-08 11:58:44 +01:00
Psychpsyo
9ea8b5a0a3 LibWeb: Add CSS column-height property
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-09-07 15:59:39 +01:00
InvalidUsernameException
7afcf305b2 LibWeb/CSS: Resolve percentages against values in their canonical unit 2025-09-07 15:55:16 +01:00
Sam Atkins
930ee495e7 LibWeb/CSS: Remove the "Auto" type from Length
This has always been a bit of a hack. Initially it made sense as a lot
of properties that accept a length also accept `auto`, but while
convenient, that leads to problems: It's easy to forget to check if a
length is `auto`, and places that don't accept it end up with an
invalid state lurking in the type system, which makes things unclear.
2025-09-04 13:31:24 +01:00
Sam Atkins
dd122e2f74 LibWeb: Make LengthBox hold LengthPercentageOrAuto
Not every user of this requires an `auto` state, but most do.

This has quite a big diff but most of that is mechanical:
LengthPercentageOrAuto has `resolved_or_auto()` instead of `resolved()`,
and `to_px_or_zero()` instead of `to_px()`, to make their output
clearer.
2025-09-04 13:31:24 +01:00
Sam Atkins
04622f3940 LibWeb/CSS: Use LengthPercentageOrAuto for background sizes
...instead of `auto` Lengths.

This also fixes interpolating between two `auto` `<bg-size>`s, which
fixes a lot of animation tests for both `background-size` and `mask`.
2025-09-04 13:31:24 +01:00
Sam Atkins
d10eaa996e LibWeb/CSS: Use empty optional for stretch in FitContentSV
...instead of using an `auto` Length.
2025-09-04 13:31:24 +01:00
Ali Mohammad Pur
4462348916 Everywhere: Slap some [[clang::lifetimebound]] where appropriate
This first pass only applies to the following two cases:
- Public functions returning a view type into an object they own
- Public ctors storing a view type

This catches a grand total of one (1) issue, which is fixed in
the previous commit.
2025-09-01 11:11:38 +02:00
Sam Atkins
d29084997e LibWeb/CSS: Reify math functions into CSSMathValue types 2025-08-29 11:57:10 +02:00
ayeteadoe
3df8e00d91 LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Sam Atkins
24017e4ab7 LibWeb/CSS: Reify numbers, dimensions and percentages as CSSUnitValue 2025-08-22 09:48:30 +01:00
Sam Atkins
5bdc2981e3 LibWeb/CSS: Rename CSSNumericType to NumericType
The CSSNumericType defined in the spec is a simple dictionary which is
only used for OM purposes. This NumericType class is used internally
and matches the more abstract definition of a "type".
2025-08-22 09:48:30 +01:00
Sam Atkins
0fc512e56d LibWeb/CSS: Reify UnresolvedStyleValue as CSSUnparsedValue 2025-08-21 10:21:54 +01:00
Sam Atkins
3613181f54 LibWeb/CSS: Reify idents as CSSKeywordValue
For us, that's KeywordStyleValue and CustomIdentStyleValue.

CustomIdentStyleValue now has a .cpp file to reduce the number of
includes in its header file.
2025-08-21 10:21:54 +01:00
Andreas Kling
29278038a2 LibWeb: Don't assume grid-related properties don't have var() in them
When serializing the "style" attribute, we were incorrectly assuming
that some of the grid-related CSS properties would never contain var()
substitution functions.

With this fixed, we can now book appointments on https://cal.com/ :^)
2025-08-18 21:18:16 +02:00
Sam Atkins
1a7f6c8f87 LibWeb/CSS: Define and use serialize_a_number()
No behaviour change, this just moves things.
2025-08-18 16:52:39 +01:00
Sam Atkins
276540fbe9 LibWeb/CSS: Add ability to reify a StyleValue
When no better reification form is available, we produce an opaque
CSSStyleValue with a serialized value. For starters, this will be the
only way to reify, and then we'll add others later.
2025-08-18 10:12:53 +01:00
Callum Law
778da0175e LibWeb: Clamp and censor top-level calc results
We now clamp the values returned from calc into the allowed range (where
we know it) and censor any `NaN`s to `0` both when we resolve and when
we serialize.

Gains us 76 WPT passes.
2025-08-11 17:10:04 +01:00
Callum Law
3fe3adadc4 LibWeb: Remove unnecessary includes in Percentage.h 2025-08-11 17:10:04 +01:00
Callum Law
90948405fc LibWeb: Return an intermediate struct from CSV::resolve_value
Returning this struct will allow us to modify the underlying value of
the `CalculationResult` without requiring us to go through the process
of constructing a whole new `CalculationResult` to return.
2025-08-11 17:10:04 +01:00
Callum Law
6025805f19 LibWeb/Meta: Compute the accepted value range for CalculationContexts
This currently only applies to property-level calculation contexts, more
work to be done to generate accepted ranges for other calculation
contexts (e.g. within transformation functions, color functions, etc)
2025-08-11 17:10:04 +01:00
Callum Law
1a9dd70792 LibWeb: Serialize NumberStyleValue with 6 decimal places of precision 2025-08-11 17:10:04 +01:00
Timothy Flynn
4a8c70b3a5 LibWeb: Parse CSS/image URLs using DOMURL::parse
DOMURL::parse handles blob URLs.
2025-08-08 17:47:51 +01:00
Sam Atkins
5bd3bc309e LibWeb/CSS: Rename color style value types
The typed-om classes will be separate.
2025-08-08 15:19:03 +01:00
Sam Atkins
6cad3f1921 LibWeb/CSS: Rename CSSColorValue -> ColorStyleValue
The typed-om class will be a separate thing.
2025-08-08 15:19:03 +01:00
Sam Atkins
99bce9a94d LibWeb/CSS: Replace CSSUnitValue with DimensionStyleValue
CSSUnitValue is a typed-om type which we will implement separately in
the future. However, it still seems useful to give our dimension values
a base class. (Maybe they could be templated in the future?) So instead
of deleting it entirely, rename it to DimensionStyleValue and make its
API match our style better.
2025-08-08 15:19:03 +01:00
Sam Atkins
7157d19f56 LibWeb/CSS: Separate IntegerSV and NumberSV from CSSUnitValue
This inheritance exists for typed-om classes, but StyleValues aren't
typed-om.

Somehow this makes our z-index interpolation slightly more correct. 🎉
2025-08-08 15:19:03 +01:00
Sam Atkins
51a657ca47 LibWeb/CSS: Delete CSSNumericValue
This will need to be re-added later as a proper typed-om type, but right
now it's useless.
2025-08-08 15:19:03 +01:00
Sam Atkins
4e92ab52e3 LibWeb/CSS: Rename CSSKeywordValue -> KeywordStyleValue
The typed-om CSSKeywordValue will need to be a separate class.
2025-08-08 15:19:03 +01:00
Sam Atkins
c57975c9fd LibWeb: Move and rename CSSStyleValue to StyleValues/StyleValue.{h,cpp}
This reverts 0e3487b9ab.

Back when I made that change, I thought we could make our StyleValue
classes match the typed-om definitions directly. However, they have
different requirements. Typed-om types need to be mutable and GCed,
whereas StyleValues are immutable and ideally wouldn't require a JS VM.

While I was already making such a cataclysmic change, I've moved it into
the StyleValues directory, because it *not* being there has bothered me
for a long time. 😅
2025-08-08 15:19:03 +01:00
Callum Law
e260ba54e0 LibWeb: Propagate NaN in CSS clamp function
Gains us 10 WPT tests.
2025-08-08 11:43:49 +01:00
Callum Law
4ba54a7a1c LibWeb: Handle NaN and Infinite values in CSS round function
Gains us 10 WPT tests
2025-08-08 11:43:49 +01:00
Callum Law
376b992f0e LibWeb: Handle NaN within CSS min and max functions
Gains us 10 WPT tests
2025-08-08 11:43:49 +01:00
Callum Law
a1037e28d6 LibWeb: Improve support for CalculatedStyleValue in scale
Some checks are pending
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / macOS, arm64, Sanitizer, 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
- Properly serialize CalculatedStyleValue components
- Allow CSV to be the 'Z' component in interpolated value

Gains us 52 WPT tests
2025-08-08 09:45:00 +01:00
Callum Law
39fdcbc526 LibWeb: Improve support for CalculatedStyleValue in translate
- Omit calcs that are resolved to `0px` from the serialized value
- Allow CSV to be the 'Z' component in interpolated value.
- Allow calcs with mixed percentages in the first two arguments.

To achieve the third item above the concept of a "special" value parsing
context has been added - this will also be useful for instance for
different arguments of color functions having different contexts.

Gains us 23 WPT tests
2025-08-08 09:45:00 +01:00
InvalidUsernameException
6c4483fe0e LibWeb/CSS: Serialize mask shorthand-property properly 2025-08-06 23:09:07 +01:00
InvalidUsernameException
add3a095d8 LibWeb/CSS: Rename background-repeat related symbols to align with spec
These will be used for the mask-repeat property as well in an upcoming
commit, hence the more generic names. Also, this more closely matches
the names used in the spec.
2025-08-06 23:09:07 +01:00
Callum Law
04ac06f3c4 LibWeb: Absolutize CursorStyleValues in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
c49afd7b28 LibWeb: Absolutize LengthPercentage members of BorderRadiusStyleValues 2025-08-06 17:44:12 +01:00
Callum Law
315f811d69 LibWeb: Absolutize BackgroundSizeSVs in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
ba4a57b34d LibWeb: Absolutize StyleValueList in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
a2ceed27e2 LibWeb: Absolutize CalculatedSVs in StyleComputer::absolutize_values 2025-08-06 17:44:12 +01:00
Callum Law
011ab5f714 LibWeb: Use correct SerializationMode when serializing CalculatedOr 2025-08-06 17:44:12 +01:00
Callum Law
a5cbcaf698 LibWeb: Use correct SerializationMode when serializing PercentageOr 2025-08-06 17:44:12 +01:00
Callum Law
a44e28fd56 LibWeb: Avoid premature creation of CSSPixels in calc simplification
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
Previously we were converting lengths to CSSPixels values when we didn't
need to, this had a couple of effects in that:
 - We rounded to CSSPixel resolution prematurely (sometimes giving
   incorrect results)
 - We converted NaN to 0 when we shouldn't have.

We now avoid prematurely converting lengths to CSSPixels values in two
places:
 - `CalculationResult::from_value`
 - `CalculatedStyleValue::resolve_length_deprecated` (the new method
   already avoided rounding).

Gains us 16 WPT tests.
2025-08-06 14:57:34 +01:00
Callum Law
3fa7bc1919 LibWeb: Simplify calc products including unresolved percentages 2025-08-06 14:53:22 +01:00