Commit graph

1090 commits

Author SHA1 Message Date
Callum Law
84fb0b458f LibWeb: Properly initialize KeyframeEffect contained in CSSTransition
This commit updates the CSSTransition constructor to:
 - Leave the KeyframeEffect start time unresolved
 - Set the KeyframeEffect start delay

Gains us 14 WPT passes but exposes one false positive in
properties-value-inherit-001.html
2025-08-18 11:18:34 +01:00
Jelle Raaijmakers
39f36327d4 LibWeb: Simplify obtaining used value for PaintableBox
No functional changes.
2025-08-18 11:04:34 +01:00
Callum Law
3aff3327c4 LibWeb: Invalidate layout on opacity change to/from zero
As of 7dc8062 paintables compute and cache their visibility (which
depends on opacity) at construction - this cached value can fall out of
sync with reality if if the opacity changes to/from zero within the
lifetime of that paintable.

This commit invalidates layout when an opacity changes to/from zero so
that we reconstruct paintables with the correct visibility.
2025-08-18 10:21:44 +01:00
Sam Atkins
089f70a918 LibWeb/CSS: Reify StyleValues in StylePropertyMap get()/getAll()
The limitations right now are:
- We don't know if a property is a list or not.
- We always reify as a CSSStyleValue directly.

So, we pass some tests but only ones that expect a CSSStyleValue.
2025-08-18 10:12:53 +01:00
Sam Atkins
25c4c2397e LibWeb/CSS: Add StyleValue getter to CSSStyleDeclarations
Will be used by StylePropertyMap, as that wants a StyleValue to reify,
not a string representation.
2025-08-18 10:12:53 +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
b80930ae34 LibWeb/CSS: Connect up StylePropertyMaps to their source
After looking into this more, the `[[declarations]]` slot does not seem
to need to be a literal map of property names and values. Instead, it
can just point at the source (an element or style declaration), and
then direct all read or write operations to that.

This means the `has()` and `delete()` methods actually work now.

A few remaining failures in these tests are because of:
- StylePropertyMap[ReadOnly]s not being iterable yet
- We're not populating an element's custom properties map, which get
  fixed whenever someone gets around to producing proper computed
  values of them.
2025-08-18 10:12:53 +01:00
Sam Atkins
37ea9a4ce3 LibWeb/CSS: Add has_property() to CSSStyleDeclaration
This isn't part of the CSSOM API directly, but will be used by
StylePropertyMapReadOnly.has() to avoid doing the work to serialize a
string version of the property's value, just to throw it away again.
2025-08-18 10:12:53 +01:00
Andreas Kling
efd4f63454 LibWeb: Allow blockification across display: contents boundary
Flex/grid items are always blockified (have their CSS display forced
into "block") by style computation.

We were doing this by looking at the CSS display of the parent. However,
if the parent has `display: contents`, we must look at the *grandparent*
instead.

This corrects the layout of buttons underneath Reddit article cards.
2025-08-17 19:09:50 +02:00
Tim Ledbetter
ad06ac0d58 LibWeb: Implement the color-interpolation property for SVG gradients
This changes the operating color space for gradient `<linearGradient>`
and `<radialGradient>` elements.
2025-08-17 10:51:05 +02:00
Andreas Kling
9208a54b0b LibWeb: Allow style inheritance through slots
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
When a subtree is projected through a slot, its root now inherits style
from the slot's parent, rather than the parent of the unprojected root.

This fixes a ton of subtle issues, and is very noticeable on Reddit.
2025-08-16 21:03:31 +02:00
Sam Atkins
888cb038e8 LibWeb/CSS: Expose a couple of types on PaintWorklet and LayoutWorklet
This has no actual effect, but it's nice to remove the FIXMEs.
2025-08-15 09:21:28 +02:00
norbiros
783ae44462 LibWeb: Fix color interpolation by premultiplying alpha
The current Color::interpolate_color method does not follow the specs
properly. Started improving it by handling premultiplied alpha in color
interpolation.

Only one WPT test covers this (color-transition-premultiplied), which we
currently pass due to a different approach in Color.mixed_with.
2025-08-14 11:09:05 +02:00
Timothy Flynn
70db474cf0 LibJS+LibWeb: Port interned bytecode strings to UTF-16
This was almost a no-op, except we intern JS exception messages. So the
bulk of this patch is porting exception messages to UTF-16.
2025-08-14 10:27:08 +02:00
Sam Atkins
911274a84d LibWeb/CSS: Implement ElementCSSInlineStyle.attributeStyleMap
Again, this isn't yet very usable, but it does appease some tests.
2025-08-13 09:47:50 +01:00
Sam Atkins
215d8b8076 LibWeb/CSS: Implement CSSStyleRule.styleMap
StylePropertyMap is just a stub, so this doesn't yet accomplish much.
2025-08-13 09:47:50 +01:00
Sam Atkins
3bb54ffd59 LibWeb/CSS: Stub out StylePropertyMap 2025-08-13 09:47:50 +01:00
Sam Atkins
c768cc7208 LibWeb/CSS: Implement Element.computedStyleMap()
Currently the map doesn't return any values, so it's not very useful,
but this does make a few tests pass just by existing. :^)
2025-08-13 09:47:50 +01:00
Sam Atkins
1620fc5bf6 LibWeb/CSS: Stub out StylePropertyMapReadOnly
Nothing yet produces this, and the useful parts of get() and get_all()
will have to wait until type reification is implemented.
2025-08-13 09:47:50 +01:00
Sam Atkins
05884f1d91 LibWeb/CSS: Implement is_a_valid_css_property()
Also mark these functions as inline instead of static, to fix a compiler
error about them being unused.
2025-08-13 09:47:50 +01:00
Sam Atkins
882288bf86 LibWeb/CSS: Stub out CSSStyleValue 2025-08-13 09:47:50 +01:00
Sam Atkins
00cadf41d8 LibWeb/CSS: Update UA stylesheet to use :heading
Corresponds to part of
65dc095e44
2025-08-13 09:47:28 +01:00
Sam Atkins
503d41d02d LibWeb/CSS: Implement the :heading/:heading() pseudo-class
Corresponds to part of
65dc095e44
2025-08-13 09:47:28 +01:00
Sam Atkins
e7890429aa LibWeb/CSS: Add support for pseudo-classes taking <an+b># 2025-08-13 09:47:28 +01:00
Sam Atkins
fbae3b824a LibWeb/CSS: Move An+B matching code into ANPlusBPattern::matches()
Not everything we want to match is an "nth element".

Also moved its serialization function's implementation out of the header
while I was at it.
2025-08-13 09:47:28 +01:00
Sam Atkins
a59c15481f LibWeb/CSS: Prepare pseudo-classes for multiple An+B patterns
The upcoming `:heading()` pseudo-class takes multiple comma-separated
An+Bs. Also rename this field as the `:nth-[last-]child()`
pseudo-classes are only a subset of the users.
2025-08-13 09:47:28 +01:00
Callum Law
ed6cac89b9 LibWeb: Discard inaccuracies when interpolating rotate 2025-08-12 14:35:02 +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
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