Commit graph

1714 commits

Author SHA1 Message Date
mikiubo
88e19ebc11 LibWeb: Handle empty string namespaces in selector matching
Per the CSS Namespaces spec, an empty string declared in an
@namespace rule represents no namespace.

Fixes WPT:
- css/css-namespaces/prefix-002.xml
- css/css-namespaces/prefix-003.xml
2025-11-14 08:16:53 +00:00
Psychpsyo
100f37995f Everywhere: Clean up AD-HOC and FIXME comments without colons 2025-11-13 15:56:04 +01:00
Psychpsyo
edccb92da7 LibWeb: Make CSSPerspective correctly clamp its input for toMatrix() 2025-11-13 15:47:00 +01:00
Callum Law
d6bb247bf7 LibWeb: Reject non-exclusive none in text-decoration-line
This updates the `parse_text_decoration_line_value` to reject values
which non-exclusively include `none` e.g. `underline none`.

It also simplifies handling by always producing a Vector (except for
`none`) and adding VERIFY_NOT_REACHED in more places which shouldn't be
reachable.
2025-11-13 10:15:02 +01:00
Psychpsyo
d284b4c2b8 LibWeb: Clamp any values less than 1 in perspective() transform function 2025-11-12 18:45:09 +01:00
Timothy Flynn
0cb9f4b66f LibWeb: Do not fetch empty CSS URLs
If a CSS rule has a URL like `url("")`, it would resolve to the document
URL itself. There isn't a context in which this would result in a valid
resource, so the spec tells us to drop it.

No test here because there isn't really a way to know when a CSS URL is
fetched. We could use PerformanceResourceTiming, but that is only for
HTTP(S) URLs. There is already an existing test for serialization of
empty URLs, which still passes.
2025-11-12 18:30:16 +01:00
Timothy Flynn
d8ec204be8 LibWeb: Do not return an exception from fetching CSS resources
The exception returned here is never used or logged. Let's just return
a null request, to make it clearer that these are not exceptions shown
to the user (thus not observable).
2025-11-12 18:30:16 +01:00
Jelle Raaijmakers
b9244903fc LibWeb: Undo ScalingMode::None for identical bitmap sizes
We always want to return the mapped scaling mode here, since the bitmap
might end up transformed, scaled, etc. and we do not want to fall back
to nearest neighbour in those cases.
2025-11-12 17:43:02 +01:00
Jelle Raaijmakers
d352c4673c LibWeb: Pass sizes instead of rects to to_gfx_scaling_mode()
Position is irrelevant when determining the right scaling mode. No
functional changes.
2025-11-12 15:59:01 +01:00
Jelle Raaijmakers
3f6cbeb87e LibGfx+LibWeb: Use mipmaps for downscaling images
This changes Gfx::ScalingMode to reflect the three modes of scaling we
support using Skia, which makes it a bit easier to reason about the mode
to select. New is ::BilinearMipmap, which uses linear interpolation
between mipmap levels to produce higher quality downscaled images.

The cubic resampling options Mitchell and its sibling CatmullRom both
produced weird artifacts or resulted in a worse quality than
BilinearMipmap when downscaling. We might not have been using these
correctly, but the new ::BilinearMipmap method seems to mirror what
Chrome uses for downscaled images.
2025-11-12 15:59:01 +01:00
Psychpsyo
e064fa19d2 LibWeb: Add transform-style and have it make a stacking context 2025-11-12 15:47:36 +01:00
Tim Ledbetter
0ec97eabab LibWeb: Extract device_pixels_per_css_pixel getter from loop
This reduces time spent in StyleComputer::compute_property_values() by
~10% when loading https://html.spec.whatwg.org/
2025-11-12 11:21:17 +01:00
Tim Ledbetter
df23b42b37 LibWeb: Don't store custom name on StyleProperty
This reduces time spent in `~StyleProperty()` from 2.18% to 0.67% on
https://cloudflare.com.
2025-11-12 11:19:37 +01:00
Psychpsyo
eb21ea890c LibWeb: Implement CSS perspective property 2025-11-12 00:41:14 +01:00
Psychpsyo
e0b5bd7894 LibWeb: Make transition order return -1 and 1 instead of 0 and 1
The old behavior was plain incorrect for a sorting function.
2025-11-11 21:57:47 +01:00
Psychpsyo
2c4f2a3cb6 LibWeb: Make transition order consider property name
class_specific_composite_order() also has no reason to return an
Optional<int>, since it can just return 0.
2025-11-11 13:46:56 +01:00
Callum Law
55afa9d37e LibWeb: Avoid unnecessary work when element display property changes
`play_or_cancel_animations_after_display_property_change` is called
whenever an element is inserted or removed, or it's display property
changes, but it is only required to run if we actually have animations
to play or cancel.

Reduces time spent in the aforementioned function from ~2% to ~0.03%
when loading https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-11 08:35:39 +00:00
Callum Law
cfc22a4075 LibWeb: Dont try to transition custom properties
Fixes a crash introduced in dd9d6d2
2025-11-11 07:53:41 +00:00
Tim Ledbetter
ec435a12ca LibWeb: Lower case only ASCII characters for selector comparisons
According to the specificcation all selector syntax is ASCII
case-insensitive.
2025-11-10 22:55:38 +01:00
Tim Ledbetter
61af399b50 LibWeb: Remove unnecessary lowercase name property from Attr 2025-11-10 22:55:38 +01:00
Callum Law
dd9d6d22ee LibWeb: Iterate over fewer properties in start_needed_transitions
We don't need to iterate every property in start_needed_transitions,
only those that appear in transition-property or have an existing
transition

Reduces the time spent in start_needed_transitions from ~5% to ~0.03%
when loading https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-10 12:11:36 +01:00
Callum Law
bbb344d534 LibWeb: Compute font features in ComputedProperties
By doing this in computed properties rather than InlineLevelIterator we
only do it once per element rather than once per text fragment.

Reduces runtime of this process from ~15% to ~0.2% when loading
https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-10 12:11:36 +01:00
Callum Law
7a5b948b5b LibWeb: Resolve more calculated values in ComputedProperties
We simplify these at style computation time so there is no need to
maintain them as {Number|Length}OrCalculated

Reduces the time spent in `Length::ResolutionContext::for_layout_node`
from 3.3% to 0.4% when loading
https://en.wikipedia.org/wiki/2023_in_American_television
2025-11-10 12:11:36 +01:00
Sam Atkins
3166dabcd6 LibWeb/CSS: Implement StylePropertyMap::append() 2025-11-07 10:26:56 +00:00
Luke Wilde
82bd3d3891 LibWeb: Avoid invoking Trusted Types where avoidable
Prevents observably calling Trusted Types, which can run arbitrary JS,
cause crashes due to use of MUST and allow arbitrary JS to modify
internal elements.
2025-11-06 11:43:06 -05:00
stelar7
0f3a9a6958 LibWeb/CSS: Use correct property when looking up container-type 2025-11-06 13:28:17 +01:00
Sam Atkins
1bcc489310 LibWeb/CSS: Subdivide into iterations when reading from StylePropertyMap 2025-11-06 10:34:48 +00:00
Sam Atkins
7292714592 LibWeb/CSS: Mark cursor as not a list-valued property
This is apparently supposed to always be treated as a single composite
value, for Typed OM at least.
2025-11-06 10:34:48 +00:00
Timothy Flynn
ac246caa0c LibWeb: Remove now-unused Resource and ResourceClient
And deal with the fallout of transitive includes.
2025-11-05 18:27:36 +01:00
Jelle Raaijmakers
f9b4fa9702 LibWeb: Add CSS::Size::is_intrinsic_sizing_constraint() 2025-11-05 12:01:40 +01:00
Tim Ledbetter
8d81421526 LibWeb: Cache font matching algorithm results
The majority of time in `compute_font()` was spent in
`font_matching_algorithm()` repeatedly computing the same values. We
now cache these values to avoid unnecessary work.
2025-11-05 09:12:02 +01:00
Andreas Kling
213e20c97b LibWeb: Use new DecodedImageData::paint() API in ImageStyleValue 2025-11-05 09:11:49 +01:00
norbiros
d8e80718d7 LibWeb/CSS: Absolutize values while computing font variation settings
Makes the `compute_font_variation_settings` function match other
`compute_font_*` by absolutizing values passed into them. It resolves a
crash related to using `siblings-count` inside `font-variation-settings`

Co-authored-by: Sam Atkins <sam@ladybird.org>
2025-11-04 21:44:32 +01:00
norbiros
3829a85fde LibWeb: Add basic variable font support
Integrates the new `FontVariationSettings` from LibGfx into LibWeb to
enable initial variable font functionality. Currently, only the `wght`
(weight) axis is fully supported and tested. This update also introduces
support for the CSS `font-variation-settings` property.
2025-11-04 21:44:32 +01:00
Sam Atkins
e026c98d64 LibWeb/CSS: Insert required comments when serializing lists of tokens
Certain pairs of tokens are required to have `/**/` inserted between
them to prevent eg two `<ident>`s getting merged together when
round-tripping.
2025-11-04 14:05:31 +01:00
Sam Atkins
7d96fbaf7a LibWeb/CSS: Parse list values as lists in CSSStyleValue parsing 2025-11-03 10:21:51 -08: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
Sam Atkins
d739c8c22a LibWeb/CSS: Mark transform as not a list-valued property
The different transform functions together form a single transform, so
this isn't a list.
2025-11-03 10:21:51 -08:00
Sam Atkins
61a0898f5f LibWeb/CSS: Stop inserting whitespace when serializing component values
Now that we don't remove whitespace when parsing, we don't need to
artificially insert it back in again when serializing. We do now need
to trim leading and trailing whitespace from UnresolvedStyleValues, as
this previously was done as part of the whitespace insertion.

This makes our serialization of UnresolvedStyleValues more correct and
gets us a few WPT passes for each property in the Typed OM tests.
2025-11-03 11:23:21 +00:00
Sam Atkins
427d7fabd7 LibWeb/CSS: Stop copying the input in parse_css_value()
Now that we don't strip out whitespace, this method was copying the
input TokenStream into a Vector, and then creating new TokenStreams
from that. So, stop doing that and use the input TokenStream instead.
2025-11-03 11:23:21 +00:00
Sam Atkins
2bbf578737 LibWeb/CSS: Commit transaction when parsing valid anchor()
I'm honestly not sure how this worked before.
2025-11-03 11:23:21 +00:00
Sam Atkins
1b1bb3b897 LibWeb/CSS: Remove "strip-whitespace" flag from Properties.json
Now that it's not on any properties, remove support for it entirely.
2025-11-03 11:23:21 +00:00
Sam Atkins
01417d1e53 LibWeb/CSS: Stop stripping whitespace from remaining properties 2025-11-03 11:23:21 +00:00
Sam Atkins
4286a2c154 LibWeb/CSS: Handle whitespace properly in quotes property 2025-11-03 11:23:21 +00:00
Sam Atkins
b12851427b LibWeb/CSS: Handle whitespace properly in transformation properties
We can no longer rely on the remaining token count, so these required
significant rearranging.
2025-11-03 11:23:21 +00:00
Sam Atkins
3341a526a3 LibWeb/CSS: Stop stripping whitespace from display property 2025-11-03 11:23:21 +00:00
Sam Atkins
fd40df12e8 LibWeb/CSS: Stop stripping whitespace from cursor property 2025-11-03 11:23:21 +00:00
Sam Atkins
ed55d968e8 LibWeb/CSS: Stop stripping whitespace from opacity properties 2025-11-03 11:23:21 +00:00
Sam Atkins
12588b6f9d LibWeb/CSS: Handle whitespace properly in content property 2025-11-03 11:23:21 +00:00
Sam Atkins
676a343525 LibWeb/CSS: Stop stripping whitespace from clip properties 2025-11-03 11:23:21 +00:00