Commit graph

36 commits

Author SHA1 Message Date
Callum Law
fec79b62e4 LibWeb: Always pass ASF presence to UnresolvedSV::create()
There was only one place that we weren't passing this where we could
have ASFs so let's just handle that there and explicitly mark the others
as having no ASFs to avoid unnecessary work.

No functional changes
2026-03-30 19:57:36 +01:00
Callum Law
03d479c1da LibWeb: Validate ASF syntax at parse time 2026-03-30 19:57:36 +01:00
Callum Law
071b000d9f LibWeb: Only allow ASFs in descriptor values if explicitly supported
`@function` descriptors are the only ones that support ASFs, while most
descriptors enforce this through their syntaxes implicitly disallowing
ASFs, this wasn't the case for `@property/initial-value`.

We now explictly disallow ASFs unless they are marked as allowed within
`Descriptors.json`.
2026-03-30 19:57:36 +01:00
Callum Law
8b66e7f463 LibWeb: Consider semicolon in parse_descriptor_value a SyntaxError
Everywhere we use this expects us to parse the whole value, either
because we are parsing the value of a declaration (in which case there
will be no semicolons), or because it is called from a JS setter which
takes whole values and semicolons make the value invalid.

Previously we would just ignore everything after a semicolon.

This also allows us to avoid creating a new `Vector` and copying all the
component values
2026-03-30 19:57:36 +01:00
Callum Law
e7243f0090 LibWeb: Support custom descriptors
Some at-rules (i.e. `@function`) require us to support custom
descriptors (e.g. `--foo`).

We do this by adding `DescriptorID::Custom` and using a new
`DescriptorNameAndID` class in a bunch of places where we previously
just used `DescriptorID`
2026-03-27 11:19:28 +00:00
Callum Law
b86377b9dc LibWeb: Clamp CSS <integer> value to i32 at parse time
This matches the behavior of other browsers. Previously we implemented
this at used-value time for z-index specifically.
2026-03-26 12:30:01 +01:00
Callum Law
93bd066639 LibWeb: Ensure <declaration-value>? descriptors are valid
Currently this only applies to the `@property` `syntax` descriptor.

As with custom properties in the previous commit we assumed that any
consumed values were valid but that's not the case.
2026-03-26 01:11:39 +00:00
Sam Atkins
f657a4b71b LibWeb/CSS: Parse @font-face { font-weight } with two values
WPT has coverage for matching but not parsing, so the test is homemade.
2026-02-24 10:05:09 +00:00
Callum Law
f0434655f9 LibWeb: Reduce recompilation from editing Enums.json
Reduces the recompilation caused by editing `Enums.json` from ~1528 to
~327
2026-02-19 11:27:06 +00:00
Callum Law
b0274268f8 LibWeb: Support calculated values in @counter-style range descriptor
Calculated values are resolved and confirmed to be valid (in line with
non-calculated values) at parse time
2026-02-12 01:26:52 +01:00
Callum Law
a541c09d61 LibWeb: Support calculated value in additive-symbols descriptor
Calculated weight values are resolved and verified to be in strictly
decreasing order (as with non-calculated values) at parse time.
2026-02-12 01:26:52 +01:00
Callum Law
85d64a1215 LibWeb: Parse @counter-style additive-symbols descriptor 2026-02-03 09:58:47 +00:00
Callum Law
ecfdf252b8 LibWeb: Parse @counter-style symbols descriptor 2026-02-03 09:58:47 +00:00
Callum Law
1f8c9cf662 LibWeb: Parse @counter-style fallback descriptor 2026-02-03 09:58:47 +00:00
Callum Law
9b376240f9 LibWeb: Parse @counter-style pad descriptor 2026-02-03 09:58:47 +00:00
Callum Law
afca221d47 LibWeb: Parse @counter-style range descriptor 2026-02-03 09:58:47 +00:00
Callum Law
f1e8d54717 LibWeb: Parse @counter-style prefix and suffix descriptors 2026-02-03 09:58:47 +00:00
Callum Law
70c8d8746f LibWeb: Parse @counter-style negative descriptor 2026-02-03 09:58:47 +00:00
Callum Law
f60bfd9e9e LibWeb: Parse @counter-style system descriptor 2026-02-03 09:58:47 +00:00
Sam Atkins
995b7eb7b4 LibWeb/CSS: Replace resolve_percentage_deprecated() with undeprecated 2025-09-24 16:33:53 +01:00
Callum Law
a7e5ded188 LibWeb: Add generic logic for parsing "positional-value-list-shorthands"
Continues the work started in #5386 to simplify handling of positional
value list shorthand properties.

Previously we would parse these as `StyleValueList`s and then rely on
`StyleComputer::for_each_property_expanding_shorthands` to expand them
into longhands.

This required a bit of work to handle `ShorthandStyleValue`s for the
`@page` `margin` descriptor.
2025-09-09 11:45:47 +02: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
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
Sam Atkins
dc91688f18 LibWeb/CSS: Use ErrorReporter for property/descriptor parsing errors 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
Sam Atkins
d18b0c07ca LibWeb/CSS: Make UnresolvedStyleValue figure out if it contains ASFs
UnresolvedStyleValue::create() has one user where we know if there are
any arbitrary substitution functions in the list of CVs, and two users
where we don't know and just hope there aren't any. I'm about to add
another user that also doesn't know, and so it seems worth just making
UnresolvedStyleValue::create() do that work instead.

We keep the parameter, now Optional<>, so that we save some redundant
work in that one place where we do already know.
2025-07-16 14:47:45 +01:00
Callum Law
afa95c2815 LibWeb: Mark CalculatedStyleValue::resolve_* methods as deprecated
The existing resolve methods are not to spec and we are working to
replace them with new ones based on the `simplify_a_calculation_tree`
method.

These are marked as deprecated rather than replaced outright as work
will need to be done on the caller side to be made compatible with the
new methods, for instance the new methods can fail to resolve (e.g.
if we are missing required context), where the existing methods will
always resolve (albeit sometimes with an incorrect value).

No functionality changes.
2025-07-16 13:05:33 +01:00
Tim Ledbetter
af60e36122 LibWeb/CSS: Don't remove whitespace early when parsing descriptor values 2025-07-03 08:22:30 +01:00
Sam Atkins
3a235e9050 LibWeb/CSS: Parse @page bleed, marks, page-orientation descriptors
These don't have WPT tests so I've added some myself.
2025-05-15 09:53:29 +01:00
Sam Atkins
9415bffd9b LibWeb/CSS: Parse @page size descriptor 2025-05-15 09:53:29 +01:00
Andrew Kaster
6d11414957 LibWeb: Make storage of CSS::StyleValues const-correct
Now we consistently use `RefPtr<StyleValue const>` for all StyleValues.
2025-04-16 10:41:44 -06:00
Sam Atkins
52a4259ef2 LibWeb/CSS: Make @font-face src parsing more forgiving
As noted in the spec, an invalid (or unsupported) font source should not
make the `src` declaration invalid.
2025-04-15 21:40:41 +02:00
Sam Atkins
a80408fea6 LibWeb/CSS: Store @property initial value as a style value
For now, it's the "raw" UnresolvedStyleValue. Later, we'll need to try
to parse it into a "real" style value using the property's syntax.
2025-04-08 09:59:41 +01:00
Sam Atkins
f87b454fa9 LibWeb/CSS: Parse @font-face descriptors as style values
CSSFontFaceRule now stores its values as a CSSFontFaceDescriptors, with
a ParsedFontFace produced on request. This is exposed via the `style`
attribute, so we pass a lot of tests that try to read values from
that.

We have one test regression, which we passed by mistake before: The test
wanted to ensure we don't allow `@font-face` nested inside other rules.
We passed it just because we discarded any `@font-face` without a
`font-family`. What we're supposed to do is 1) keep at-rules with
missing required descriptors and just not use them, and 2) reject
certain ones when nested.

We may want to cache the ParsedFontFace in the future, but I didn't here
because 1) it's called rarely, and 2) that would mean knowing to
invalidate it when the CSSFontFaceDescriptors changes, which isn't
obvious to me right now.
2025-04-04 10:40:32 +01:00
Sam Atkins
fd45c53c11 LibWeb: Parse descriptors as style values, using the JSON data
The goal here is to do something a bit smarter with the parsing here
than we do for properties. Instead of the JSON saying "here are the
values, and here are the keywords, and we can have up to 3", here we
place the syntax in the JSON directly (though currently broken up as
one string per option) and then we attempt to parse each one in
sequence. It's something we'll need eventually for `@property` among
other things.

...However, in this first pass, I've gone with the simplest option of
hard-coding the types instead of figuring them out properly. So there's
a PositivePercentage type and a UnicodeRangeTokens type, instead of
properly implementing the grammar for those in a generic way.
2025-04-04 10:40:32 +01:00