Commit graph

359 commits

Author SHA1 Message Date
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
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
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
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
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
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
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
46153910ec LibWeb: Update to_color to take ColorResolutionContext
Using a generic context argument will allow us to resolve colors in
places where we have all the required information but not in the form of
a layout node as was expected previously.
2025-08-04 11:29:05 +01:00
norbiros
190745fd58 LibWeb/CSS: Parse initial value using syntax from @property
Now we pass all WPT tests in:
`css/css-properties-values-api/at-property-cssom`.

Note: Failing tests were false positives.
Proper handling of inheriting values and detecting computational
independence will be done in another PR.
2025-08-04 11:08:46 +01:00
Sam Atkins
1adddb158a WebContent+LibWeb/CSS: Add debug request to dump CSS errors 2025-08-04 10:50:09 +01:00
Sam Atkins
01661503b9 LibWeb/CSS: Remove unused Debug.h include from GradientParsing.cpp 2025-08-04 10:50:09 +01:00
Sam Atkins
dc91688f18 LibWeb/CSS: Use ErrorReporter for property/descriptor parsing errors 2025-08-04 10:50:09 +01:00
Sam Atkins
cebdcd9f69 LibWeb/CSS: Use ErrorReporter for value-parsing errors
Also remove some redundant reporting for `<urange>` parsing errors.
2025-08-04 10:50:09 +01:00
Sam Atkins
3b7aa736e7 LibWeb/CSS: Use ErrorReporter for media query parsing 2025-08-04 10:50:09 +01:00
Sam Atkins
1a599ceb98 LibWeb/CSS: Reject @font-face and margin rules that have a prelude
I couldn't find any WPT coverage for this, so here's a homemade test.
2025-08-04 10:50:09 +01:00
Sam Atkins
e072ddfebd LibWeb/CSS: Use ErrorReporter for rule-parsing errors
Unfortunately we already have an InvalidRuleError type defined in the
CSS Parser, so it has to be qualified here, at least for now.
2025-08-04 10:50:09 +01:00
Sam Atkins
0bd83dd996 LibWeb/CSS: Use ErrorReporter for "rule X not allowed in Y" errors
QualifiedRule::for_each_as_declaration_list() now takes a rule_name, so
that the error message can actually be useful - we only know what a
qualified rule is by context.
2025-08-04 10:50:09 +01:00
Sam Atkins
d6cfd56ae6 LibWeb/CSS: Use ErrorReporter for selector parsing errors
Also removed the error reporting from parse_a_n_plus_b_pattern() as its
caller already reports that error.
2025-08-04 10:50:09 +01:00
Sam Atkins
2a2a1986cc LibWeb/CSS: Add dump_string() method to TokenStream
This is to support error reporting. It's not the most elegant way of
getting the source CSS, but it works.
2025-08-04 10:50:09 +01:00
Sam Atkins
012f4735a7 LibWeb/CSS: Introduce structured reporting for CSS errors
Instead of random dbgln_if(CSS_PARSER_DEBUG) messages, this lets us
report what kind of error it was. Repeated errors are combined instead
of spamming the console.

Ideally this would also record where the error occurred, but not yet.
2025-08-04 10:50:09 +01:00
Sam Atkins
b7a108d7cb LibWeb/CSS: Remove unused ParseError::InternalError 2025-08-04 10:50:09 +01:00
Sam Atkins
d55626dc32 LibWeb/CSS: Remove debug logging I left in by accident 2025-08-04 10:50:09 +01:00
Sam Atkins
d86bcc795d LibWeb/CSS: Remove duplicate error reporting for invalid descriptors
parse_descriptor_value() already logs this.
2025-08-04 10:50:09 +01:00
Tim Ledbetter
1d9e4a6f62 LibWeb: Parse anchor() function for inset properties 2025-08-03 22:09:31 +02:00
Jelle Raaijmakers
c4f5e7bee3 LibWeb: Implement anchor-size(..) function parsing
This parses `anchor-size(..)` functions in CSS, but does not yet result
in a useful `Size`: we need style & layout interleaving similar to
container queries for this, since the resulting value depends on layout
results.

Not supported yet: `anchor-size()` appearing inside a `calc()` node.

Adds 4280 WPT subtest passes in `css/css-anchor-position`.
2025-07-30 18:13:59 +01:00
Jelle Raaijmakers
02598040ad LibWeb: Add CSS::Parser::parse_dashed_ident() 2025-07-30 18:13:59 +01:00
Aliaksandr Kalenik
d1fbb7b51e LibWeb: Invalidate less elements affected by CSS custom properties
Before this change, whenever element's attributes changed, we would add
a flag to "pending invalidation", indicating that all descendants whose
style uses CSS custom properties needed to be recomputed. This resulted
in severe overinvalidation, because we would run invalidation regardless
of whether any custom property on affected element actually changed.

This change takes another approach, and now we decide whether
descendant's style needs to be recomputed based on whether ancestor's
style recomputation results in a change of custom properties, though
this approach adds a little overhead to style computation as now we have
to compare old vs new hashmap of custom properties.

This brings substantial improvement on discord and x.com where, before
this change, advantage of using invalidation sets was lost and we had
to recompute all descendants, because almost all of them use custom
properties.
2025-07-30 11:06:05 +02:00
Aliaksandr Kalenik
cbe4ba60c3 LibWeb: Implement faster equals() for UnresolvedStyleValue
Compare `Vector<Parser::ComponentValue>` directly instead of
serializing them into strings first.

This is required for the upcoming changes where we would compare
previous and new sets of custom properties to figure out whether we need
to invalidate descendant elements. Without this change `equals()` would
show up being hot in profiles.
2025-07-30 11:06:05 +02:00
Aliaksandr Kalenik
b1efd62ce6 LibWeb: Save more details about ASF presence in UnresolvedStyleValue
In the upcoming changes we would have to know specifically whether
`var()`, `attr()` or both are included in UnresolvedStyleValue.
2025-07-30 11:06:05 +02:00
Sam Atkins
943cc0e32a LibWeb/CSS: Implement "legacy value aliases" in generated code
This uses a `foo>bar` notation in the `valid-identifiers` field of
Properties.json, to say "replace `foo` with `bar`".

The motivation here is to avoid calling `parse_css_value_for_property()`
inside the per-property switch in `parse_css_value()`. Eventually we'll
need to be able to call that switch from
`parse_css_value_for_properties()` so that shorthands can make use of
any bespoke parsing code to parse their longhands.
2025-07-23 12:50:42 +01:00
norbiros
90c0decd95 LibWeb/CSS: Add CSS.registerProperty JS method
This adds an *almost* complete implementation of `CSS.registerProperty`
method enabling further progress on the `@property` feature.
2025-07-22 10:57:54 +01:00
Andreas Kling
038d8ade50 LibWeb: Always parse calc() inside CSS color functions consistently
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
Before this change, calc() would resolve to different types depending on
the nearest containing value context. This meant that rgb(calc(), ...)
by itself worked correctly due to fallbacks, but rgb(calc(), ...) inside
e.g a linear-gradient would create a calc() value that resolves to a
length, which subsequently got rejected by the color value parser.

Fixing this makes various little gradients show up on Discord.
2025-07-22 08:47:22 +01:00
Sam Atkins
11e2dbb555 LibWeb/CSS: Support text-justify: distribute legacy value alias
...for `text-justify: inter-character`.

We previously had this mapped in Enums.json, but the behaviour is
different: `a=b` in Enums.json keeps `a` around but makes it behave the
same as `b`. A legacy name alias is instead expected to replace `a`
with `b`, so we have to do that separately.
2025-07-21 10:04:42 +01:00
Sam Atkins
db75405881 LibWeb/CSS: Support overlay keyword as alias to auto in overflow
We don't yet have a system for "legacy value aliases", but until we have
a lot of them we can handle them manually.

We also have to do this in two places because
parse_css_value_for_property() doesn't call any property-specific
parsing code.
2025-07-21 10:04:42 +01:00
Gingeh
f38e07e0c5 LibWeb: Don't crash when an unknown property begins with a single dash 2025-07-20 08:54:53 +02:00
Callum Law
4ee8110449 LibWeb: Handle flood-opacity in line with other opacity properties
We now do the proper thing in terms of:
 - Allowing percentages
 - Returning the computed value in getComputedStyle
 - Handling values out of the [0,1] range

Gains us 13 WPT passes in the imported tests.
2025-07-18 11:04:55 -04:00