Commit graph

1157 commits

Author SHA1 Message Date
Sam Atkins
e17052a343 LibWeb/CSS: Implement CSSMathSum 2025-08-29 11:57:10 +02:00
Sam Atkins
a46c980629 LibWeb/CSS: Implement CSSNumericArray 2025-08-29 11:57:10 +02:00
Sam Atkins
6c8876cdb8 LibWeb/CSS: Implement CSSMathValue
This is a base class for the various math functions, so it's not used
directly anywhere.
2025-08-29 11:57:10 +02:00
Sam Atkins
46b55f0f46 LibWeb/CSS: Implement rectify_a_numberish_value() 2025-08-29 11:57:10 +02:00
Tim Ledbetter
5eff541804 LibWeb: Construct filter chain at paint time
This allows us to use style and box metrics when applying filters.
2025-08-29 10:15:24 +01:00
Sam Atkins
f93819eda2 LibWeb/CSS: Remove unused <an+b># code for pseudo-classes
This reverts e7890429aa and partly reverts
a59c15481f.

The one pseudo-class that accepted multiple of these was :heading(), and
since that got changed to take integers instead, there's no need to keep
this extra complexity (and memory usage) around.
2025-08-28 12:40:03 +02:00
Sam Atkins
d461e96f40 LibWeb/CSS: Make :heading() pseudo-class take integers not AN+B
Corresponds to 8eb3787e34
2025-08-28 12:40:03 +02:00
Sam Atkins
9ffc15ba3f LibWeb/CSS: Serialize :heading(...) pseudo-class properly
We originally had special handling for `:host()` as that had been the
only pseudo-class that could be both an identifier or a function.
However, this meant duplicating the serialization logic, and also we
had to manually remember to add the same hack for any other
identifier-and-function cases. Which I forgot to do with `:heading()`!

So instead, for these cases, detect if they actually have arguments
specified and use that to determine which form to serialize as. We do
still have to write a check for each one of these pseudo-classes, but
the VERIFY should make it easier to remember.
2025-08-28 12:40:03 +02:00
Tim Ledbetter
a87a9156d5 LibWeb/CSS: Parse the paint-order property 2025-08-28 10:31:09 +01:00
Callum Law
1052ee20b0 LibWeb: Move snap_a_length_as_a_border_width to StyleComputer.cpp
All users are in this file so it makes more sense to have it here
2025-08-28 09:29:46 +01:00
Callum Law
0ce6cc38b7 LibWeb: Store outline-width in computed form in ComputedProperties
We now also store `outline-width` in ComputedValues as a `CSSPixels`
since we know it's an absolute length at `apply_style` time - this saves
us some work in converting to CSSPixels during layout.

Gains us 46 new passes since we now interpolate keywords (thick, thin,
etc) correctly.

Also loses us 4 WPT tests as we longer clamp negative values produced by
interpolation from the point of view of getComputedStyle (although the
'used' value is still clamped).
2025-08-28 09:29:46 +01:00
Callum Law
6eae92511f LibWeb: Store border-*-width in computed form in ComputedProperties
Gains us 112 new passes since we now interpolate keywords (thick, thin,
etc) correctly.

Also loses us 4 WPT tests as we longer clamp negative values produced by
interpolation from the point of view of getComputedStyle (although the
'used' value is still clamped).
2025-08-28 09:29:46 +01:00
Callum Law
d4aa40a9fe LibWeb: Use computed not just absolutized value when computing keyframes
No functionality changes as we don't yet implement computing any
property values using this method.
2025-08-28 09:29:46 +01:00
Callum Law
f9e5332d16 LibWeb: Initial work to store ComputedProperties in computed form
`StyleValue`s stored within `ComputedProperties` should be in their
computed forms, this is for various reasons including:
 - Inheritance should be of computed values
 - Animations should work on computed values
 - Triggering transitions should work on computed values

Currently we store `StyleValue`s in an absolutized version of the
specified value - this is equivalent to the computed form in many cases
which is why this hasn't been causing significant issues but there are
some cases - such as `border-*-width` keywords where this is not the
case.

No functionality change as we are yet to implement any properties
2025-08-28 09:29:46 +01:00
Callum Law
ede80ccdfb LibWeb: Allow UseInitial in keyframes when updating animated style
This removes the AnimationRefresh argument from `collect_animation_into`
which was added in a9b8840 - it's only effect was disallowing
`UseInitial`s within keyframes when we were doing animated style
updates which I believe is unintentional.

Gains us 214 WPT tests.
2025-08-27 14:50:58 +02:00
Callum Law
d69e62425e LibWeb: Resolve CSS-wide keywords in keyframe properties
Also resolves the `revert` keyword against longhand properties rather
than potential shorthands as this could cause a crash.

Gains us 20 WPT tests.
2025-08-27 14:50:58 +02:00
Viktor Szépe
1c01e183b7 Everywhere: Fix even more typos 2025-08-27 08:48:01 +02:00
Callum Law
912ffc3f84 LibWeb: Remove unnecessary ComputedProperties::maybe_null_property
We know that all (longhand) properties have a value so this is
unnecessary.
2025-08-26 12:17:55 +02:00
Callum Law
6bccc7c242 LibWeb: Don't allocate space for shorthands in ComputedProperties
Only longhands have computed values so allocating space for shorthands
is just wasted memory
2025-08-26 12:17:55 +02:00
Callum Law
9f5696e9c5 LibWeb: Avoid getting shorthand property from ComputedProperties
ComputedProperties only includes longhands so we shouldn't try to get
shorthands - this will be asserted in a later commit.
2025-08-26 12:17:55 +02:00
Callum Law
1ba64a1d7e LibWeb: Remove StyleComputer as friend of ComputedProperties
Everything we need to do with ComputedProperties in StyleComputer can be
done via the public APIs
2025-08-26 12:17:55 +02:00
Callum Law
ed947940d7 LibWeb: Simplify conversion of percentage line-height to absolute length
We can take advantage of the fact that we already do this in
`compute_line_height`.
2025-08-26 12:17:55 +02:00
Callum Law
1a3da3d825 LibWeb: Don't store separate computed value for font_size
The StyleValue stored in m_property_values is already in it's computed
form and it's trivial to pull the underlying value out so there is no
need to store this separately.

Also removes unnecessary handling of percentage values in
`absolutize_values` - this is already handled within `compute_font`.
2025-08-26 12:17:55 +02:00
Callum Law
fba4187c8f LibWeb: Add a constant for the number of longhand properties
We use this in multiple places (and will in more places in the future)
so it's worth having as a constant from a clarity point of view
2025-08-26 12:17:55 +02:00
Callum Law
5431f1534a LibWeb: Remove unnecessary check on ComputedProperties array size
This is a constant length array - this check will always be false
2025-08-26 12:17:55 +02:00
Jelle Raaijmakers
518c048eb4 LibWeb+WebContent: Rename Document::focused_element to ::focused_area
And make it a DOM::Node, not DOM::Element. This makes everything flow
much better, such as spec texts that explicitly mention "focused area"
as the fact that we don't necessarily need to traverse a tree of
elements, since a Node can be focusable as well.

Eventually this will need to be a struct with a separate "focused area"
and "DOM anchor", but this change will make it easier to achieve that.
2025-08-26 10:25:59 +02:00
Tim Ledbetter
cb1a1a5cb5 LibWeb: Replace is<T>() with as_if<T>() where possible
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
2025-08-25 18:45:00 +02:00
ayeteadoe
3df8e00d91 LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
Callum Law
5c2fe12772 LibWeb: Don't consider null -> null as a change for invalidation
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
This avoids excessive invalidation within `recompute_inherited_style`
where we inherit a value but not an animated value.
2025-08-22 12:17:55 +02:00
Sam Atkins
da88db04cf LibWeb/CSS: Implement the "numeric factory" methods (CSS.px() and pals) 2025-08-22 09:48:30 +01:00
Sam Atkins
24017e4ab7 LibWeb/CSS: Reify numbers, dimensions and percentages as CSSUnitValue 2025-08-22 09:48:30 +01:00
Sam Atkins
5384338788 LibWeb/CSS: Implement CSSUnitValue 2025-08-22 09:48:30 +01:00
Sam Atkins
0fa1099ce5 LibWeb/CSS: Support creating a NumericType from Flex units 2025-08-22 09:48:30 +01:00
Sam Atkins
6cb8e92bd4 LibWeb/CSS: Stub out CSSNumericValue
Most of the methods on this rely on its subclasses existing, so for now
it's very basic.
2025-08-22 09:48:30 +01:00
Sam Atkins
5bdc2981e3 LibWeb/CSS: Rename CSSNumericType to NumericType
The CSSNumericType defined in the spec is a simple dictionary which is
only used for OM purposes. This NumericType class is used internally
and matches the more abstract definition of a "type".
2025-08-22 09:48:30 +01:00
Callum Law
6373ab68ee LibWeb: Use inherited value of math-style when computing math-depth
The spec calls for us to use the inherited value but we were using our
own value.
2025-08-22 09:48:52 +02:00
Callum Law
4efbd0dc4d LibWeb: Support relative lengths in math-depth calcs
As this is computed before font-size we use the parent's length
resolution context.
2025-08-22 09:48:52 +02:00
Callum Law
944b985929 LibWeb: Remove handling of invalid values in compute_math_depth
This was unnecessary as the parser will never produce values other than
MathDepthStyleValue
2025-08-22 09:48:52 +02:00
Callum Law
a2c9ab9c9a LibWeb: Return AbstractElement from element_to_inherit_style_from
No functional changes.
2025-08-22 09:48:52 +02:00
Callum Law
9122d0d014 LibWeb: Remove compute_defaulted_{values|property_value}
These functions are unused.
2025-08-21 13:49:21 +02:00
Callum Law
ce0fef7c45 LibWeb: Initialize properties before calling compute_{math_depth|font}
`StyleComputer::create_document_style` was the only place this wasn't
the case so we can remove the calls to
`compute_defaulted_property_value`. The call to
`compute_defaulted_values` in `create_document_style` is now redundant
so has been removed`
2025-08-21 13:49:21 +02:00
Callum Law
b267012ba7 LibWeb: Handle color: currentcolor in compute_properties
This was the last thing that `compute_defaulted_values` was doing when
called from here.

It also comes with the added benefit of us correctly inheriting animated
colors.
2025-08-21 13:49:21 +02:00
Callum Law
48832972b1 LibWeb: Handle -libweb-inherit-or-center in compute_text_align
This seems like a more natural place to handle this
2025-08-21 13:49:21 +02:00
Callum Law
ca9cb42ed4 LibWeb: Handle unset immediately in compute_properties
Previously we would hand off to `compute_defaulted_properties` to
resolve these values but there is no need as we can just resolve them
immediately.
2025-08-21 13:49:21 +02:00
Callum Law
9330bf4b72 LibWeb: Propagate animated values in recompute_inherited_style
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
As `recompute_inherited_style` works in-place rather than building
ComputedProperties from scratch we need to keep track of which animated
properties are inherited to know whether we should remove them when we
have no more inherited value.
2025-08-21 10:46:55 +01:00
Sam Atkins
0fc512e56d LibWeb/CSS: Reify UnresolvedStyleValue as CSSUnparsedValue 2025-08-21 10:21:54 +01:00
Sam Atkins
6428c9990d LibWeb/CSS: Implement CSSUnparsedValue and CSSVariableReferenceValue
We don't serialize these the way WPT expects, because we don't implement
the comment-insertion rules from CSS-Syntax. We don't implement that
for regular serialization either, so it's something we can worry about
later.
2025-08-21 10:21:54 +01:00
Sam Atkins
213a548b1f LibWeb/CSS: Implement CSSStyleValue.parse() and .parseAll()
The "subdivide into iterations" part is left as a FIXME for now, until
we have a way of knowing if a property is a list or not.

The parse_a_css_style_value() helper has an unwieldy return type because
of the requirement that it return either one value or a list of values,
but sticking to the spec here seems worthwhile for now.
2025-08-21 10:21:54 +01:00
Sam Atkins
3613181f54 LibWeb/CSS: Reify idents as CSSKeywordValue
For us, that's KeywordStyleValue and CustomIdentStyleValue.

CustomIdentStyleValue now has a .cpp file to reduce the number of
includes in its header file.
2025-08-21 10:21:54 +01:00
Sam Atkins
a93c6a347f LibWeb/CSS: Implement CSSKeywordValue
CSSStyleValue is adjusted to allow for subclasses. Serialization for
CSSKeywordValue is implemented differently than the spec says because
of a spec bug: https://github.com/w3c/csswg-drafts/issues/12545
2025-08-21 10:21:54 +01:00