Commit graph

1062 commits

Author SHA1 Message Date
Callum Law
bc2ca96f50 LibWeb: Make signature of CSS::{Percentage,Number}::to_string consistent
By making this consistent with the other numeric data type classes we
can simplify cases where we are dealing with variants containing these
types.
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
f15153ea86 LibWeb: Move formatter for Percentage into 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
2af7016a77 LibWeb: Rename ValueType::OpenTypeTag to ValueType::OpentypeTag
This is the correct capitalization in line with what it is called in the
spec "opentype-tag".
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
Callum Law
7182a537f3 LibWeb: Reduce inaccuracies when creating rotation matrices
When converting rotate transform functions `sin` and `cos` can sometimes
be inaccurate. To avoid these inaccuracies we:
 - Mod the angle to minimise inaccuracies in the first place.
 - Discard tiny (smaller than epsilon) values returned by `sin` and
   `cos` as inaccuracies.

This is in line with  other browsers (e.g. Gecko and WebKit).
2025-08-11 17:10:04 +01:00
Callum Law
719ab5735e LibWeb: Avoid addition to infinity when rounding calc'd z-index 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
Callum Law
18d65b014f LibWeb: Add formatter for Web::CSS::ValueType
Currently unused but I found it useful for debugging
2025-08-08 09:45:00 +01:00
Callum Law
9bfd46ce31 LibWeb: Add formatter for Web::CSS::CSSStyleValue::Type
Currently unused but I found it useful for debugging
2025-08-08 09:45:00 +01:00
Callum Law
56b6987fd0 LibWeb: Use a macro for repetitive code in CSSStyleValue.{h,cpp}
This reduces the number of places we need to touch when creating a new
type
2025-08-08 09:45:00 +01:00
Sam Atkins
89b59cb5c3 LibWeb/CSS: Implement env() as an arbitrary substitution function
Technically, env() should not be an ASF. (😱) This is why some tests
still fail - env() as specced is expected to have its syntax checked
fully at parse-time, whereas ASFs are not properly syntax-checked until
later. However, I think this approach was worth doing for a few reasons:

- env() behaves like an ASF otherwise. (It is replaced with a set of
  arbitrary component-values that are not known until computed-value
  time.)
- env() was defined before the ASF concept existed, so I strongly
  suspect it will be updated in the future to match that definition,
  with a couple of adjustments. (eg, env() is allowed in some extra
  places compared to var() and attr().)
- This was much quicker and easier to implement (under 3 hours in total)
  compared to the greater amount of work to implement a whole separate
  system just for env().
- Most of these tests are marked tentative, and the spec definition of
  env() is still somewhat in flux, so failing some is not a huge deal.

If in the future I turn out to be wrong on this, we can convert it to
its own special thing.
2025-08-07 16:38:29 +02:00
Sam Atkins
7b30c94fcf LibWeb+CodeGenerators: Generate EnvironmentVariable enum and functions 2025-08-07 16:38:29 +02:00
Sam Atkins
5808eff1f4 LibWeb/CSS: Hyphenate request-url-modifier names
Corresponds to e1bf92d49a

Also update our imported WPT tests.
2025-08-07 13:38:25 +01:00
Sam Atkins
24f4356c3f LibWeb/CSS: Specify behavior for OOB CSSStyleDeclaration::item()
Corresponds to 56ed462ccd

We already did the right thing.
2025-08-07 14:29:17 +02:00
InvalidUsernameException
6c4483fe0e LibWeb/CSS: Serialize mask shorthand-property properly 2025-08-06 23:09:07 +01:00
InvalidUsernameException
39b64c9b5c LibWeb/CSS: Parse mask shorthand-property into longhands
This commit regresses a couple tests related to the mask shorthand
property. This is because we now parse the longhands but there are
errors related to serialization. Some of the failures are fixed again in
the next commit. However, for some animation tests this is not the case.
Those failures were simply masked by the fact that we did not parse the
property correctly.
2025-08-06 23:09:07 +01:00
InvalidUsernameException
5fca78e0f9 LibWeb/CSS: Parse mask-image property with multiple values 2025-08-06 23:09:07 +01:00
InvalidUsernameException
f953196cb4 LibWeb/CSS: Parse mask-clip property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
eea6792cf7 LibWeb/CSS: Parse mask-origin property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
866e12f688 LibWeb/CSS: Parse mask-size property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
7c5f1a93ed LibWeb/CSS: Parse mask-repeat property 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
InvalidUsernameException
667f195d1e LibWeb/CSS: Parse mask-position property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
d022eea9fc LibWeb/CSS: Parse mask-mode property 2025-08-06 23:09:07 +01:00
InvalidUsernameException
22d7a58998 LibWeb/CSS: Parse mask-composite property 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
c8bd58c0ba LibWeb: Add method to absolutize CalculatedOr 2025-08-06 17:44:12 +01:00
Callum Law
0df9c225aa LibWeb: Add method to absolutize PercentageOr 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
9db3c66a85 LibWeb: Use correct font size when absolutizing animated properties 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