Commit graph

652 commits

Author SHA1 Message Date
Tim Ledbetter
04fde1c550 LibWeb: Ensure lang pseudoclass matches multiple segment subcodes 2025-04-28 11:29:30 +01:00
Tim Ledbetter
74c803c87b LibWeb: Ensure |= value selector handles multiple segments correctly
Previously, the `|=` would not compare strings containing `-`
characters correctly because it would only compare the element
attribute up to the first `-` character.
2025-04-28 11:29:30 +01:00
Tim Ledbetter
f854f644a7 LibWeb: Don't crash when interpolating non <number> scale values 2025-04-28 11:46:34 +02:00
Tim Ledbetter
8a398e7a88 LibWeb: Parse all transition-property value as keyword
We were previously parsing this value, as a custom-ident, meaning that
the code path for handling the `all` case wasn't being followed.
2025-04-27 09:49:00 +01:00
Andreas Kling
d8ea16d94e LibWeb: Don't assume calc() simplification worked on invalid tree
Fixes #4469
2025-04-25 16:55:05 +02:00
Timothy Flynn
ad34fdad48 LibWeb: Convert trivial attributes to FrozenArray 2025-04-25 16:43:43 +02:00
Andreas Kling
cf704cfbfc LibWeb: Implement interpolation for CSS scale values
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
And let's handle the 3rd (Z) scale parameter as well, while we're here.

At least 242 new passes on WPT.
2025-04-25 14:08:12 +02:00
Timothy Flynn
fe6d8131ae LibWeb: Return correct type from CSSNestedDeclarations::style
We implement CSSStyleProperties so let's use it.
2025-04-25 08:48:29 +02:00
Andreas Kling
0553bcb35b LibWeb: Simplify standalone CSS math functions when used outside calc()
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
Math functions like abs(), clamp(), round(), etc, can be used by
themselves in property values, without wrapping them in calc().

Before this change, we were neglecting to run calc simplification on the
generated calculation node trees. By doing that manually after parsing a
standalone math function, we score at least a couple hundred WPT points.
2025-04-24 20:38:00 +02:00
Andreas Kling
cf34a7bb32 LibWeb: Invalidate owner sheet on add/remove in CSSStyleProperties
Fixes at least 2 WPT subtests.
2025-04-24 18:26:54 +02:00
Andreas Kling
1772adb600 LibWeb: Don't crash on non-finite values in CSS clamp() function
Stops a WPT test from crashing, giving us 29 new subtest passes. :^)
2025-04-24 18:26:54 +02:00
Andreas Kling
2f76b24b89 LibWeb: Throw on deleting CSS @namespace rule in disallowed conditions
Fixes one(!) WPT test :^)
2025-04-24 18:26:54 +02:00
Tim Ledbetter
fc1026984c LibWeb: Don't crash when processing a transition with value none 2025-04-24 00:00:23 +02:00
Tim Ledbetter
64577ad704 LibWeb: Allow multiple values for the transition-duration property 2025-04-23 21:02:59 +01:00
Tim Ledbetter
1ca9f2a44d LibWeb: Allow multiple values for the transition-delay property 2025-04-23 21:02:59 +01:00
Tim Ledbetter
c5f1f36119 LibWeb: Allow multiple values for transition-timing-function property 2025-04-23 21:02:59 +01:00
Tim Ledbetter
7a391f419a LibWeb: Handle single value properties when normalizing transition lists
Previously, if a transition property was not wrapped in a list, it
would be replaced with the default value in
`StyleComputer::compute_transitioned_properties`.
2025-04-23 21:02:59 +01:00
Tim Ledbetter
1f8f3804a3 LibWeb: Allow transition-property with multiple values 2025-04-23 21:02:59 +01:00
Sam Atkins
658569b533 LibWeb/CSS: Use CSSRule's context to parse new child rules
Keep track of which CSSRule owns a CSSRuleList, and then use that to
produce a stack of RuleContexts for the CSS Parser to use.

There are certainly other places we should do this!
2025-04-23 10:55:45 +01:00
Sam Atkins
763b1b0ee2 LibWeb/CSS: Move RuleContext type out of Parser.h
This was previously internal to the Parser, but we'd like to pass it in
from outside.
2025-04-23 10:55:45 +01:00
Sam Atkins
9465492edf LibWeb/CSS: Combine the CSSRuleList constructors 2025-04-23 10:55:45 +01:00
Sam Atkins
3d1665cc80 LibWeb/CSS: Parse nested declarations in insert_a_css_rule()
The spec algorithm changed at some point to support nested declarations,
but I only just noticed. The subtest regression is one we were passing
incorrectly.
2025-04-23 10:55:45 +01:00
Sam Atkins
fa8bbfa6a5 LibWeb/CSS: Align declaration block parsing with the spec
We have two different code paths that implement the "parse a CSS
declaration block" algorithm, for properties and descriptors. COmbining
them isn't straightforward, and doesn't seem especially useful.
2025-04-23 10:55:45 +01:00
Tim Ledbetter
8a20899382 LibWeb: Canonicalize color space when parsing color-mix() function
This amounts to replacing the "xyz" color space with "xyz-d65".
2025-04-23 11:26:27 +02:00
Tim Ledbetter
04d7228c51 LibWeb: Implement interpolation of repeatable lists 2025-04-23 09:13:45 +01:00
Tim Ledbetter
0beb22f19e LibWeb: Implement interpolation of edge values 2025-04-23 09:13:45 +01:00
Tim Ledbetter
6f5b107fcc LibWeb: Resolve absolute calc() values in color functions
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
Currently, `calc()` values with relative units are not handled
correctly and will output an error to the console.
2025-04-22 12:20:26 +02:00
Tim Ledbetter
9cf04f40f6 LibWeb: Implement the color-mix() function
This takes 2 color values and returns the result of mixing them by a
given amount.
2025-04-22 12:19:51 +02:00
Aliaksandr Kalenik
8e2d1559ec LibGfx: Join ScaledFont into Font
Since ScaledFont is the only class inherited from Font we could simply
merge them.
2025-04-21 09:51:16 +02:00
Andreas Kling
a6dfc74e93 LibWeb: Only set prototype once for object with IDL interface
Before this change, we were going through the chain of base classes for
each IDL interface object and having them set the prototype to their
prototype.

Instead of doing that, reorder things so that we set the right prototype
immediately in Foo::initialize(), and then don't bother in all the base
class overrides.

This knocks off a ~1% profile item on Speedometer 3.
2025-04-20 18:43:11 +02:00
Tim Ledbetter
4283c73d02 LibWeb: Return correct computed value for lab-like and lch-like colors 2025-04-20 16:51:20 +02:00
Tim Ledbetter
e860dd4f65 LibWeb: Implement serialization of lch-like color values 2025-04-20 16:51:20 +02:00
Tim Ledbetter
5074d90888 LibWeb: Implement serialization of lab-like color values 2025-04-20 16:51:20 +02:00
Shannon Booth
f48b760011 LibWeb/CSS: Avoid URL validity check parsing CSS URLs 2025-04-19 07:18:43 -04:00
Andreas Kling
5df3838a80 LibWeb: Evaluate style sheet media rules immediately on insertion
Before this change, we were waiting for Document to lazily evaluate
sheet media and media rules. This often meant that we'd get two
full-document style invalidations: one from adding a new style sheet,
and one from the media queries changing state.

By evaluating the rules eagerly on insertion, we coalesce the two
invalidations into one. This reduces the number of full-document
invalidations on Speedometer 3 from 51 to 34.
2025-04-19 01:14:02 +02:00
Andreas Kling
57809b1100 LibWeb: Skip dynamic_cast in CSSRGB after we already did a type check 2025-04-18 14:45:56 +02:00
Shannon Booth
3e17b1c9ae LibWeb: Make Node::parent_element return GC::Ptr
This is useful for people like myself who run with debug mode to
more reliably get stacktraces without spinning up a debugger.
2025-04-18 10:49:02 +02:00
Andreas Kling
e1777f6e79 LibWeb: Make :hover invalidation logic reusable for all pseudo classes
We achieve this by keeping track of all checked pseudo class selectors
in the SelectorEngine code. We also give StyleComputer per-pseudo-class
rule caches.
2025-04-17 19:45:55 +02:00
Andreas Kling
ed35f9e7c2 LibWeb: Remove unused MatchingRule::must_be_hovered flag
This was a vestige from an earlier version of hover selector work
avoidance optimizations.
2025-04-17 19:45:55 +02:00
Tim Ledbetter
ca200142e9 LibWeb: Don't construct stylesheet when modifying CSSStyleSheet rules
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macos-15, macOS, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, ubuntu-24.04, Linux, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, ubuntu-24.04, Linux, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, ubuntu-24.04, Linux, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macos-15, macOS, macOS-universal2) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, ubuntu-24.04, Linux, 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
Previously, `CSSStyleSheet.replace()` and `CSSStyleSheet.replaceSync()`
parsed the given CSS text into a temporary stylesheet object, from
which a list of rules was extracted. Doing this had the unintended
side-effect that a fetch request would be started if the given CSS text
referenced any external resources. This fetch request would cause a
crash, since the temporary stylesheet object didn't set the constructed
flag, or constructor document. We now parse the given CSS text as a
list of rules without constructing a temporary stylesheet.
2025-04-16 22:03:12 +01:00
Andrew Kaster
c36c7ed67b LibWeb: Launder const in CSS::Selector::absolutized when returning self
This const method tries to return a RefPtr to non-const self. That's
not kosher, but fixing it needs some architecture work.
2025-04-16 10:41:44 -06:00
Andrew Kaster
be2dd91289 LibGfx+LibWeb: Store Typeface and Font-related types in RefPtr to const 2025-04-16 10:41:44 -06:00
Andrew Kaster
d1f6f5649e LibWeb: Make storage of CSS::CalculationNodes const-correct
Now we consistently use `RefPtr<CalculationNode const>` for all
CalculationNodes.
2025-04-16 10:41:44 -06: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
9f333c424c LibWeb/CSS: Ensure a font source format() only contains one string/ident 2025-04-15 21:40:41 +02: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
c224644bed LibWeb/CSS: Fetch ImageStyleValue images closer to spec
We now don't absolutize the URL during parsing, keeping it as a CSS::URL
object which we then pass to the "fetch an external image for a
stylesheet" algorithm. Our version of this algorithm is a bit ad-hoc,
in order to make use of SharedResourceRequest. To try and reduce
duplication, I've pulled all of fetch_a_style_resource() into a static
function, apart from the "actually do the fetch" step.
2025-04-15 09:54:35 +01:00
Sam Atkins
9f00425dad LibWeb/CSS: Let CSSStyleValue know its CSSStyleSheet
The CSS `fetch_foo()` functions resolve the URL relative to the
CSSStyleSheet if one is provided. So, style values that do so need to
know what CSSStyleSheet they are part of so that, for example, `url
(foo.png)` is loaded relative to the style sheet's URL instead of the
document's one.

That all works without this change because we currently absolutize URLs
during parsing, but we're in the process of stopping that.

This commit adds the infrastructure for telling style values what their
CSSStyleSheet is.
2025-04-15 09:54:35 +01:00
Sam Atkins
aebbb008c1 LibWeb/CSS: Expose owning document of CSSStyleSheet
This will be needed for fetching images from CSS.
2025-04-15 09:54:35 +01:00
Sam Atkins
f1af4bcc58 LibWeb: Include SharedResourceRequest.h where it's used
ImageStyleValue.h can rely on the forward-declaration.
2025-04-15 09:54:35 +01:00