Commit Graph

880 Commits

Author SHA1 Message Date
Pavel Shliak
fcb45f4893 LibWeb: Fix extra validation for EasingStyleValue intervals
(cherry picked from commit b342758dbf8d1138353db89708964e75b9128400)
2024-11-25 12:19:48 -05:00
Gingeh
be681da6a7 LibWeb: Use substrings instead of pointers when parsing unicode ranges
Fixes a segfault when parsing a wildcard-only unicode range

(cherry picked from commit a4b38dda5611e87987c855de8a6e06aa0351bd1b)
2024-11-25 09:21:14 -05:00
Tim Ledbetter
4dd2c42239 LibWeb: Use correct specifier to pad font language override value
(cherry picked from commit 7fe110225b7de2177e3463424ab437ffd9d7d5cd)
2024-11-20 22:51:34 -05:00
stelar7
c39fa9a033 LibWeb: Parse the rotate css property
(cherry picked from commit 488436fb54347e69040cfed4f523926241a136a3)
2024-11-19 11:02:38 -05:00
Jelle Raaijmakers
ef09e057ee LibWeb: Fix filter: drop-shadow argument parsing
We were not discarding enough whitespace to actually get to the radius
and color values.

(cherry picked from commit c99fad77e1cfc8789f2a8d33e958d7b5bcf35ea9)
2024-11-19 11:02:38 -05:00
Jelle Raaijmakers
93a8c61fe9 LibWeb: Parse and store filter property
This shares its implementation with `backdrop-filter`.

(cherry picked from commit 29974de852fb14eef78a18232bd36d5c8955a214;
amended to resolve conflict on `height:` in expectations file, and to
remove change to DisplayListPlayerSkia.cpp which serenity doesn't have;
also updated FilterPainting.{h,cpp} for changes since serenity does not
have LadybirdBrowser/ladybird#736 and LadybirdBrowser/ladybird#886)
2024-11-19 11:02:38 -05:00
Lucas CHOLLET
5148cd3122 LibWeb/CSS: Start parsing the color() function
This is really bare bone as we only support the `xyz-d50` color space
for the moment.

It makes us pass the following WPT tests:
 - css/css-color/predefined-016.html
 - css/css-color/xyz-d50-001.html
 - css/css-color/xyz-d50-002.html

(cherry picked from commit 48bbebc636598eca905b8eef984ee2cba548ff64)
2024-11-18 20:22:45 -05:00
Lucas CHOLLET
32830bf961 LibWeb/CSS: Add support for the lch color function
This makes us pass all `css/css-color/lch-00*.html` tests.

(cherry picked from commit f253246a6cd013af2b81d7ab8d24a1baef857c20)
2024-11-18 13:21:10 -05:00
Lucas CHOLLET
12c57e3026 LibWeb/CSS: Introduce a base class for LCH-based color values
This will be used by both CSSLCH and CSSOKLCH.

(cherry picked from commit e8fc731b8cde75a0af9571a3b491f6149038ea21)
2024-11-18 13:21:10 -05:00
Lucas CHOLLET
bbddfc4408 LibWeb/CSS: Factorize the parsing code for lch-like color functions
(cherry picked from commit 7a94709cd2f7a47af8c336fccf3f656bbfeb65bf)
2024-11-18 13:21:10 -05:00
Lucas CHOLLET
d61a8096f4 LibWeb/CSS: Make all children of CSSLabLike share the create() method
Small code deduplication. NFC.

(cherry picked from commit 15121d63adebc18ba6d5432eabe04f56928d9fde)
2024-11-18 13:21:10 -05:00
Sam Atkins
f157983f10 LibWeb/CSS: Parse and use nested style rules
For example, this:

```css
.foo {
  color: red;
  &:hover {
    color: green;
  }
}
```

now has the same effect as this:

```css
.foo {
  color: red;
}
.foo:hover {
  color: green;
}
```

CSSStyleRule now has "absolutized selectors", which are its selectors
with any `&`s resolved. We use these instead of the "real" selectors
when matching them, meaning the style computer doesn't have to know or
care about where the selector appears in the CSS document.

(cherry picked from commit 53f99e51f8382a20cec7752480d505957a2680b1)
2024-11-18 09:48:28 -05:00
Sam Atkins
61fae972c6 LibWeb/CSS: Parse nested rules in style blocks
Nested lists of declarations become CSSNestedDeclarations; at-rules are
allowed as long as they are CSSGroupingRules.

(cherry picked from commit 36afff97d18b6c67e718894f2fc9742c3f9d0122)
2024-11-18 09:48:28 -05:00
Lucas CHOLLET
a683961f24 LibGfx+LibWeb/CSS: Add support for the lab() color function
The support in LibWeb is quite easy as the previous commits introduced
helpers to support lab-like colors.

Now for the methods in Color:
 - The formulas in `from_lab()` are derived from the CIEXYZ to CIELAB
   formulas the "Colorimetry" paper published by the CIE.
 - The conversion in `from_xyz50()` can be decomposed in multiple steps
   XYZ D50 -> XYZ D65 -> Linear sRGB -> sRGB. The two first conversion
   are done with a singular matrix operation. This matrix was generated
   with a Python script [1].

This commit makes us pass all the `css/css-color/lab-00*.html` WPT
tests (0 to 7 at the time of writing).

[1] Python script used to generate the XYZ D50 -> Linear sRGB
conversion:

```python
import numpy as np

m_a = np.array([
    [0.8951000, 0.2664000, -0.1614000],
    [-0.7502000, 1.7135000, 0.0367000],
    [0.0389000, -0.0685000, 1.0296000]
])

chromaticities_source = np.array([0.96422, 1, 0.82521])
chromaticities_destination = np.array([0.9505, 1, 1.0890])

cone_response_source = m_a @ chromaticities_source
cone_response_destination = m_a @ chromaticities_destination

cone_response_ratio = cone_response_destination / cone_response_source
m = np.linalg.inv(m_a) @ np.diagflat(cone_response_ratio) @ m_a

D50_to_D65 = m

xyz_65_to_srgb = np.array([
    [3.2406, - 1.5372, - 0.4986],
    [-0.9689, + 1.8758, 0.0415],
    [0.0557, - 0.2040, 1.0570]
])

xyz_50_to_srgb = xyz_65_to_srgb @ D50_to_D65

print(xyz_50_to_srgb)
```

(cherry picked from commit 3406b69614e27dcb6036a6d2e5ca62833070c0a1;
amended to fix -Wdouble-promotion warnings)
2024-11-18 09:07:51 -05:00
Lucas CHOLLET
b49cc740e8 LibWeb/CSS: Make CSSOKLab inherit from a new CSSLabLike class
This class provides the common base for both CSSOKLab and the future
CSSLab classes.

(cherry picked from commit 8efa046e0c56d970cabe5644e0e8b4eef85013c3)
2024-11-18 09:07:51 -05:00
Lucas CHOLLET
6a77d5687e LibWeb/CSS: Extract code to parse a lab-like color value
This is currently only used for `oklab()` but will soon be also used for
`lab()` as well.

(cherry picked from commit 707bcaf6045b1eb36887bbf3af107b87d3def302)
2024-11-18 09:07:51 -05:00
Sam Atkins
fbca9efcbe LibWeb/CSS: Preserve whitespace and comments in custom properties
A couple of parts of this:
- Store the source text for Declarations of custom properties.
- Then save that in the UnresolvedStyleValue.
- Serialize UnresolvedStyleValue using the saved source when available -
  that is, for custom properties but not for regular properties that
  include var() or attr().

(cherry picked from commit bf3e6daedbc8fd0d8e03f5f0eafebf5bbe3abf03)
2024-11-17 23:31:49 -05:00
Sam Atkins
f4131ef46b LibWeb/CSS: Preserve original source text for ComponentValues
This requires a little bit of ad-hoc tracking of start/end Tokens for
Function and SimpleBlock.

(cherry picked from commit ea164124de271e511778326280347ebc28d948d8)
2024-11-17 23:31:49 -05:00
Sam Atkins
6a7f208cad LibWeb/CSS: Rename Token::representation() to original_source_text()
This is the term used in the Syntax-3 spec as of right now.

(cherry picked from commit 04939d68f0bf35894d5fd48bc5005095b30b5a1d)
2024-11-17 23:31:49 -05:00
Sam Atkins
fe9ab2c91e LibWeb/CSS: Rewrite CSS Parser core methods according to new spec
CSS Syntax 3 (https://drafts.csswg.org/css-syntax) has changed
significantly since we implemented it a couple of years ago. Just about
every parsing algorithm has been rewritten in terms of the new token
stream concept, and to support nested styles. As all of those
algorithms call into each other, this is an unfortunately chonky diff.

As part of this, the transitory types (Declaration, Function, AtRule...)
have been rewritten. That's both because we have new requirements of
what they should be and contain, and also because the spec asks us to
create and then gradually modify them in place, which is easier if they
are plain structs.

(cherry picked from commit e0be17e4fbf1870f35614d0cde8f63e72f78bd16;
amended to tweak test expectation due to serenity not yet having
LadybirdBrowser/ladybird#1603)
2024-11-17 22:08:57 -05:00
Sam Atkins
519d4d9564 LibWeb/CSS: Make CSSStyleRule be a CSSGroupingRule
As part of this, we can now fill in the missing serialization steps.

The parsing is a stub for now, and will be filled out in a subsequent
commit.

(cherry picked from commit 77238730165641f2bab7409f5c9fbaf575cbd99f)
2024-11-17 22:08:57 -05:00
Sam Atkins
962207a2db LibWeb/CSS: Bring TokenStream in line with spec
When the TokenStream code was originally written, there was no such
concept in the CSS Syntax spec. But since then, it's been officially
added, (https://drafts.csswg.org/css-syntax/#css-token-stream) and the
parsing algorithms are described in terms of it. This patch brings our
implementation in line with the spec. A few deprecated TokenStream
methods are left around until their users are also updated to match the
newer spec.

There are a few differences:

- They name things differently. The main confusing one is we had
  `next_token()` which consumed a token and returned it, but the spec
  has a `next_token()` which peeks the next token. The spec names are
  honestly better than what I'd come up with. (`discard_a_token()` is a
  nice addition too!)

- We used to store the index of the token that was just consumed, and
  they instead store the index of the token that will be consumed next.
  This is a perfect breeding ground for off-by-one errors, so I've
  finally added a test suite for TokenStream itself.

- We use a transaction system for rewinding, and the spec uses a stack
  of "marks", which can be manually rewound to. These should be able to
  coexist as long as we stick with marks in the parser spec algorithms,
  and stick with transactions elsewhere.

(cherry picked from commit b645e26e9b29437c0e248b5e43e3ec76aacf960d)
2024-11-17 18:57:30 -05:00
Andreas Kling
afbb213552 LibWeb: Fail CSS color parse for "rgba(123, 123, 123, "
This matches the behavior of other browsers and fixes a WPT test.

(cherry picked from commit 902586a21de3ef8335e447053d82057c4c927d72;
amended expected output because serenity does not yet have
LadybirdBrowser/ladybird#1603)
2024-11-17 16:48:43 -05:00
Andreas Kling
0b5719685d LibWeb+LibGfx: Serialize HTML canvas fill/strokeStyle colors correctly
Before this change we were serializing them in a bogus 8-digit hex color
format that isn't actually recognized by HTML.

This code will need more work when we start supporting color spaces
other than sRGB.

(cherry picked from commit 4590c081c2eb257232463ed660498a02f9bbe7b8;
amended expected output because serenity does not yet have
LadybirdBrowser/ladybird#1603)
2024-11-17 16:48:43 -05:00
Glenn Skrzypczak
34247c4251 LibWeb: Don't crash when encountering a resolution in a calculation
calc() seems to support resolutions by now.

The change allows us to pass this WPT test:
http://wpt.live/css/css-values/round-mod-rem-invalid.html

(cherry picked from commit 3804c4dea1a8e4296327ca570e012264ee2580b3)
2024-11-12 19:57:55 -05:00
Ankush Chatterjee
d5ed665461 LibWeb/CSS: Add math expression support for transform-origin
(cherry picked from commit 85356094b50878e78d40d79c2a9e96ff9aac5a6b)
2024-11-12 10:45:53 -05:00
Annya
265c942698 LibWeb/CSS: Implement revert-layer
With the introduction of the cascade layer, the 5th CSS-wide keyword,
`revert-layer`, has been added.

(cherry picked from commit bea7eec5183a816a100d190e409a622f429d7405)
2024-10-31 21:51:50 -04:00
Sam Atkins
cbd9e88ffd LibWeb/CSS: Handle calculated integers when expanding unresolved values
In order to know whether `calc(2.5)` is a number or an integer, we have
to see what the property will accept. So, add that knowledge to
`Parser::expand_unresolved_values()`.

This makes `counter-increment: foo calc(2 * var(--n));` work correctly,
in a test I'm working on.

(cherry picked from commit 69d064697ad8bbf602eb2dc73fc532b0e1b16716)
2024-10-27 16:58:12 -04:00
Andreas Kling
4a4da86792 LibWeb: Don't crash when encountering calc() inside a CSS rect() value
This allows us to run the WPT tests under quirks/unitless-length/
without crashing, giving us over 4600 new passing subtests. :^)

(cherry picked from commit 5df6c6eecff678bf2a1fe8960149302d42015439)
2024-10-26 23:26:45 -04:00
Sam Atkins
9b9b5fef6d LibWeb/CSS: Parse font-[feature,variation]-settings descriptors
(cherry picked from commit e43f3e4808b0775dfcd8ef9d7218d87e6f617d21)
2024-10-26 09:29:16 -04:00
Sam Atkins
f8a66c346e LibWeb/CSS: Parse and propagate font-feature-settings property
(cherry picked from commit 95c17dfab51fefdd5ca364652e8571827d9693b1)
2024-10-26 09:29:16 -04:00
Sam Atkins
7b35ed0c66 LibWeb/CSS: Parse and propagate font-variation-settings property
(cherry picked from commit 55812aaed20ce8f7aeea233a47bcab73b60edd5e;
amended to include AK/QuickSort.h in Parser.cpp to fix a compile
error, and to update height: in getComputedStyle-print-all.txt)
2024-10-26 09:29:16 -04:00
Sam Atkins
f23d61c8ae LibWeb/CSS: Expand single-none-parsing helper to parse any keyword
Multiple font properties are either the `normal` keyword or some
non-keyword value, so this lets us avoid some boilerplate for those, at
the cost of the existing `none` users having marginally more verbose
code.

(cherry picked from commit 1a127c9d37e47b8793057ab68305bf399ad3106f)
2024-10-26 09:29:16 -04:00
Sam Atkins
1df9984d5c LibWeb/CSS: Add parsing for <opentype-tag>
This is a special form of `<string>` so doesn't need its own style value
type. It's used in a couple of font-related properties. For completeness
it's included in ValueType.

(cherry picked from commit cd13b30fb871ab521777ce164bff7696aa0fbfca)
2024-10-26 09:29:16 -04:00
Sam Atkins
60a1bcd250 LibWeb/CSS: Return StringStyleValue from parse_string_value()
Callers already relied on this being true, so let's make it contractual.

(cherry picked from commit 2516297c865f44c51d09a07001169b08ba430631)
2024-10-26 09:29:16 -04:00
Sam Atkins
a6b7c0eefb LibWeb/CSS: Parse the font-language-override descriptor
(cherry picked from commit 20af2eb2b0d196b464db536222d8b9f0df75a79d)
2024-10-21 09:36:47 -04:00
Sam Atkins
ee3710f681 LibWeb/CSS: Parse and propagate the font-language-override property
(cherry picked from commit 1d8867d9ae9de1312fe6624bf9040dde12bfa9df;
amended to fix `height:` line in getComputedStyle-print-all.txt)
2024-10-21 09:36:47 -04:00
Sam Atkins
6936b2c3e6 LibWeb/CSS: Parse font-width descriptor and its font-stretch alias
(cherry picked from commit b1870e70298b9d5933fd4cee4fc6d947b8198d98)
2024-10-21 09:36:47 -04:00
Sam Atkins
a627165df9 LibWeb/CSS: Make font-stretch a legacy alias for new font-width
CSS Fonts level 4 renames font-stretch to font-width, with font-stretch
being left as a legacy alias. Unfortunately the other specs have not yet
been updated, so both terms are used in different places.

(cherry picked from commit 4a67b28600437901e6d8a366c56a5ddd8665deb1)
2024-10-21 09:36:47 -04:00
Sam Atkins
5606a54a22 LibWeb/CSS: Parse font-named-instance descriptor
(cherry picked from commit 7c50a31402c0240ccd19658284dec48ff876fc17)
2024-10-21 09:36:47 -04:00
Sam Atkins
85b5d7b93e LibWeb/CSS: Parse font-display descriptor
(cherry picked from commit 3eb6d510fd0c7d4b6b21b64ac36a06571ea1fd9f)
2024-10-21 09:36:47 -04:00
Sam Atkins
272c1c64cb LibWeb: Parse ascent-, descent-, and line-gap-override descriptors
(cherry picked from commit 2f7d18865dc509a0d7c9e1c751266ede92f58ca6)
2024-10-21 09:36:47 -04:00
Sam Atkins
e47c20c994 LibWeb/CSS: Rename CalculatedStyleValue -> CSSMathValue
This matches the name in the CSS Typed OM spec. There's quite a lot
still to do to make it match the spec behavior, but this is the first
step.

(cherry picked from commit 76daba3069de4c184c6b2317d0c89b50f81a8c00)
2024-10-20 22:24:57 -04:00
Sam Atkins
22f54eb951 LibWeb/CSS: Parse @layer rules
This causes us to pass all of
http://wpt.live/css/css-cascade/parsing/layer.html :^)

(cherry picked from commit 4c98906e2c00200d7652abf7df5c044fab64dbfc)
2024-10-20 21:09:21 -04:00
Sam Atkins
d76b7744fd LibWeb/CSS: Implement legacy name aliases for properties
When a property is a "legacy name alias", any time it is used in CSS or
via the CSSOM its aliased name is used instead.
(See https://drafts.csswg.org/css-cascade-5/#legacy-name-alias)

This means we only care about the alias when parsing a string as a
PropertyID - and we can just return the PropertyID it is an alias for.
No need for a distinct PropertyID for it, and no need for LibWeb to
care about it at all.

Previously, we had a bunch of these properties, which misused our code
for "logical aliases", some of which I've discovered were not even
fully implemented. But with this change, all that code can go away, and
making a legacy alias is just a case of putting it in the JSON. This
also shrinks `StyleProperties` as it doesn't need to contain data for
these aliases, and removes a whole load of `-webkit-*` spam from the
style inspector.

(cherry picked from commit fdcece2e88b91b9ec6cf63c3466525fb77540316;
amended to:
* resolve a conflict on height: in getComputedStyle-print-all.txt
* run prettier on CSSGeneratedFiles.md)
2024-10-20 10:29:44 -04:00
Adam Harald Jørgensen
9c20df1684 LibWeb: Set correct longhand values when using grid-placement shorthand
According to https://www.w3.org/TR/css-grid-2/#placement-shorthands
when setting the 'grid-row' and 'grid-column' shorthand property to a
single <custom-ident> value, both 'grid-row-start'/'grid-column-start'
and 'grid-row-end'/'grid-column-end' should be set to that
<custom_ident>.

(cherry picked from commit 3e92ec80f3873bb81cbc8b0dc93bb3a6a145172c)
2024-10-11 21:15:26 -04:00
Samuel Fry
ad4bd36c59 LibWeb: Support parsing columns
(cherry picked from commit c42679597a4157bda4e2f560b8b820e2653027a2)
2024-10-11 10:12:44 -04:00
Sam Atkins
b65ccb4dc6 LibWeb: Introduce color-function-specific style values
Instead of CSSColorValue holding a Gfx::Color, make it an abstract class
with subclasses for each different color function, to match the Typed-OM
spec. This means moving the color calculations from the parsing code to
the `to_color()` method on the style value.

This lets us have calc() inside a color function, instead of having to
fully resolve the color at parse time. The canvas fillStyle tests have
been updated to reflect this.

The other test change is Screenshot/css-color-functions.html: previously
we produced slightly different colors for an alpha of 0.5 and one of
50%, and this incorrect behavior was baked into the test. So now it's
more correct. :^)

(cherry picked from commit 3af6a69f1e13803c64466a9b24b7bd7d75d459df;
amended to:
* resolve a minor conflict in Parser.cpp due to upstream not having
  https://github.com/LadybirdBrowser/ladybird/pull/385#issuecomment-2227130015
* rebaseline canvas-fillstyle-rgb.png since the diff didn't apply due to
  us not having https://github.com/LadybirdBrowser/ladybird/pull/999
* remove css-color-functions-ref.png and instead update
  css-color-functions-ref.html since that file is still a reftest due to us
  not having https://github.com/LadybirdBrowser/ladybird/pull/736
  Makes it much easier to see what actually changed.
)
2024-10-11 10:12:33 -04:00
Sam Atkins
e1c1c03c37 LibWeb/CSS: Introduce helper methods for parsing numeric values
"Parse a style value for <foo>", where we don't care if it's a literal
<foo> or a calculated one, is a really common thing that we previously
didn't have methods for.

A couple of methods we had have been extended to parse calc(), and the
others have been filled in.

The method for parsing the `flex` property's value is renamed
`parse_flex_shorthand_value()` as it conflicted.

(cherry picked from commit 27be8678c973da41379f47f07c8b0a9ff692bcd3)
2024-10-11 10:12:33 -04:00
Sam Atkins
945577e6ba LibWeb/CSS: Inline number/integer parsing
For simplicity in user code, the `parse_foo_value()` methods should
parse anything that is a `<foo>`. In these cases, that means a
number/integer or calculation that resolves to them.

These uses in parse_css_value_for_properties() specifically only want a
literal IntegerStyleValue/NumberStyleValue, as calc-parsing is done
elsewhere. So, do the parsing for them locally.

(cherry picked from commit 79bd942dd1284112db24fd50203ff4f1fe6263b1)
2024-10-11 10:12:33 -04:00