Commit graph

37 commits

Author SHA1 Message Date
Callum Law
32b9ff21df LibWeb: Add generic int_from_style_value method
Reduces duplication in line with `number_from_style_value`,
`string_from_style_value` etc
2026-02-23 11:21:09 +00:00
Callum Law
e6669482e6 LibWeb: Parse font-variant-alternates functions 2026-02-20 22:01:44 +00:00
Callum Law
893eac18dd LibWeb: Add TupleStyleValue
Many CSS grammars call for us to parse `Foo || Bar` but we don't have a
good way to represent this unless we have a custom style value. Usually
we store the values in a `StyleValueList` but since that can only store
non-null elements we have to manually recheck which elements we have at
which index whenever we use it.

This style value holds a Vector of `RefPtr<StyleValue const>` so that we
can represent null values and know what values are at what index without
manually rechecking.
2026-02-20 22:01:44 +00:00
Callum Law
d998a0aeeb LibWeb: Add generic string_from_style_value method
Reduces duplication in line with `Time::from_style_value()`,
`Angle::from_style_value()` etc
2026-02-17 12:25:27 +00:00
Callum Law
846493831d LibWeb: Add generic number_from_style_value method 2026-02-16 12:09:23 +00:00
Callum Law
8a82d116d6 LibWeb: Always parse <counter-style> as such
Previously we parsed it as `<custom-ident>` in `<counter>` and as a
keyword in `list-style-type`.

The practical effect of this is:
 - Spec defined counter style names in `<counter>` are ASCII lowercased
   on parse.
 - Non spec defined counter style names are allowed in `list-style-type.

We are still to parse the `symbols()` function but this gives us a
better base for that.
2026-02-12 10:33:09 +00:00
Aliaksandr Kalenik
e76cf3e225 LibWeb: Remove Document.h include from Layout/Node.h
This reduces the recompilation cascade when Document.h is modified.
Add explicit includes to files that relied on the transitive dependency.
2026-02-08 18:51:13 +01:00
Callum Law
f60bfd9e9e LibWeb: Parse @counter-style system descriptor 2026-02-03 09:58:47 +00:00
Vahan Arakelyan
d04b74555b LibWeb/CSS: Make accentColor and accentColorText take accent-color value 2026-02-02 14:19:08 +00:00
Callum Law
eb5b73d3b5 LibWeb: Use existing StyleValues for math-depth
Previously we implemented an all encompassing `MathDepthStyleValue`
specifically for the `math-depth` property, this was unnecessary since
we can represent `auto-add` and `<integer>` using existing `StyleValue`
classes.

This brings the values created from parsing in line with those set via
`StylePropertyMap` which allows us to simplify computation
2026-01-15 12:03:16 +00:00
Tim Ledbetter
a27d269721 LibWeb: Pass StringBuilder around during StyleValue serialization
Previously, some StyleValues created a large number of intermediate
strings during serialization. Passing a StringBUilder into the
serialization function allows us to avoid a large number of these
unnecessary allocations.
2026-01-09 10:00:58 +01:00
Callum Law
84c6fd5730 LibWeb: Make parsing of border-radius value reusable
This is also useful for `<basic-shape-rect>`
2026-01-06 10:50:06 +01:00
Callum Law
4909e19aca LibWeb: Make <radal-size> parsing generic
Previously this was implemented inline within the parsing of
`{repeating}-radial-gradient()` functions but it will also be useful for
`circle()` and `ellipse()`.

We now support the CSS Images Module Level 4 additions to the
`<radial-size>` syntax, namely:
 - `<length-percentage>` rather than just `<length>` for circles.
 - Distinct `<radial-extent>` values for horizontal and vertical for
   ellipses.
 - Mixing of `<radial-extent>` and `<length-percentage>` values for
   ellipses.

The regressions are due to WPT not being updated to expect the first of
these additions.
2025-12-12 12:20:16 +00:00
Callum Law
2a5e389f63 LibWeb: Implement basic CSS random() function
At the moment this is limited to only fixed value sharing and does not
support step values
2025-12-01 11:00:33 +00:00
Callum Law
c8d91c127e LibWeb: Parse view() for the animation-timeline CSS property 2025-11-28 13:24:11 +00:00
Callum Law
7d70714eac LibWeb: Parse scroll() for the animation-timeline CSS property 2025-11-28 13:24:11 +00:00
Sam Atkins
c4b9e7eadf LibWeb: Parse and propagate extended text-indent property values
CSS Text 3 gives `text-indent` a couple of optional keywords to control
which lines are affected. This commit parses them, but doesn't yet do
anything with them.
2025-11-20 16:02:40 +01:00
Sam Atkins
07d77e89dd LibWeb/CSS: Implement "subdivide into iterations" for basic StyleValues
This algorithm is used by Typed-OM for producing a list of internal
style values from a single one, for properties that take a list. We
will probably need to implement this for more StyleValues later.
2025-11-03 10:21:51 -08:00
Callum Law
12716dccf0 LibWeb: Avoid including ComputedProperties.h in Element.h
This reduces the size of the recompile when ComputedProperties.h is
modified from ~1200 to ~70
2025-10-27 14:50:54 +00:00
Callum Law
8417d74328 LibWeb: Parse transition property as a coordinating list shorthand
We don't need all this specific logic for parsing the `transition`
property - we also now maintain `none` as such until use time which
gains us a couple extra tests
2025-10-23 10:09:11 +01:00
Callum Law
f49cf75d44 LibWeb: Don't pass unnecessary PropertyComputationDependencies struct
Since we now have access to the `AbstractElement` through the
`ComputationContext` we can just set the flag that this element relies
on tree counting functions directly, no need to pass this struct around.
2025-10-22 00:01:30 +02:00
Callum Law
2404f95e03 LibWeb: Invalidate style for tree counting functions when required
We mark any element that relies on tree counting functions as needing a
style update when a sibling is inserted/removed.
2025-10-20 16:12:08 +01:00
Callum Law
831e471444 LibWeb: Support top-level tree counting functions
Adds support for `sibling-index()` and `sibling-count()` when parsing
`<number>` and `<integer>`. This is achieved by a new
`TreeCountingFunctionStyleValue` class which is converted within
`absolutized` to `NumberStyleValue` and `IntegerStyleValue` respectively

There are still a few kinks to work out in order to support these
everywhere, namely:
 - There are some `StyleValue`s which aren't absolutized (i.e. those
   which are stored within another `StyleValue` without an
   `absolutize()` method.
 - We don't have a way to represent this new `StyleValue` within
   `{Number,Integer}OrCalculated`. This would be fixed if we were to
   instead just use the `StyleValue` classes until style computation at
   which time they would be absolutized into their respective
   primitives (double, i64, etc) bypassing the need for *OrCalculated
   entirely.
2025-10-20 16:12:08 +01:00
Luke Wilde
eeb5446c1b LibWeb: Avoid including Navigable.h in headers
This greatly reduces how much is recompiled when changing Navigable.h,
from >1000 to 82.
2025-10-20 10:16:55 +01:00
Callum Law
814efa9809 LibWeb: Parse corner-*-shape physical longhands 2025-10-09 10:23:20 +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
Sam Atkins
2de4fe8104 LibWeb/CSS: Store StyleValue pointer instead of string on CSSStyleValue
When setting style to a CSSStyleValue we need to convert it to a
StyleValue. If we already have one, we might as well use it avoid the
work of serialization and re-parsing.

I realised I misunderstood what "constructed from a USVString" means, so
I've adjusted based on that. It does raise a question on what the source
USVString is if that string resulted in multiple CSSStyleValues being
created - see the linked issue.
2025-10-04 22:57:00 +02:00
Sam Atkins
a30afafcc9 LibWeb/CSS: Use FlyString for CSSStyleValue property name 2025-10-02 13:46:04 +01:00
Callum Law
10793aef56 LibWeb: Move to_font_slope from StyleValue to FontStyleStyleValue
This method only operated on `FontStyleStyleValue`s anyway so this is a
better place to have it
2025-09-19 10:06:33 +01:00
Callum Law
425b7de44a LibWeb: Use compute_font_width for font-width descriptor
This allows us to remove `StyleValue::to_font_width`
2025-09-19 10:06:33 +01:00
Callum Law
45a4e9cd0f LibWeb: Use compute_font_weight for font-weight descriptor
This allows us to remove `StyleValue::to_font_weight`
2025-09-19 10:06:33 +01:00
Callum Law
b0e3af7d10 LibWeb: Parse text-underline-position property
This introduces the `TextUnderlinePositionStyleValue` class, it is
possible to represent `text-underline-position` as a `StyleValueList`
but would have required ugly workarounds for either serialization or in
`ComputedProperties::text_underline_position`
2025-09-15 15:24:20 +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
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
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
Renamed from Libraries/LibWeb/CSS/CSSStyleValue.cpp (Browse further)