Commit Graph

2455 Commits

Author SHA1 Message Date
Tim Ledbetter
255d0d6973 LibWeb: Update Screen IDL definition to not inherit from EventTarget
(cherry picked from commit 8ad3479e0ecfb55ed382a4932256020e98edb9e6)
2024-11-26 22:37:15 -05:00
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
Sam Atkins
b6755e8189 LibWeb/CSS: Correct matching of calc() against <number-percentage>
This seems to have vanished from the spec, but in any case, we still
need it. Without this change we erroneously thought that calculations
that match <percentage> did not match <number-percentage>.

(cherry picked from commit 760943d584587899d2ba0390cad20797001e1b96)
2024-11-25 09:21:14 -05:00
thislooksfun
271f3c9bdd LibWeb/CSS: Evaluate media queries in shadow roots
This fixes a rendering issue on https://prodengi.kz/ that someone on
Discord reported. :^)

(cherry picked from commit 0b775da7c72a85c099f35d8caf2e7b66721a4483)
2024-11-25 08:50:54 -05:00
Aliaksandr Kalenik
df89bf53a0 LibWeb: Replaced remaining usage and delete Size::resolved()
(cherry picked from commit 7225087fa2015925d0a63dd103ac0157ffafd5d8)
2024-11-24 10:27:54 -05:00
Timothy Flynn
1d11a0b1a7 LibWeb: Begin implementing FontFaceSet.prototype.load
This implementation is incomplete in that we do not fully implement the
steps to match the given font against the fonts in the set.

This is used by fonts.google.com to load the fonts used for sample text.

(cherry picked from commit 9bdf2e928c448585a6349bef36d7cb98ccc0607b)
2024-11-24 10:27:41 -05:00
Psychpsyo
bc8a517703 LibWeb: Fix incorrect spec link for the @supports rule
(cherry picked from commit 628e1d98537c0dec03dfda5d1752c2b49d70d143)
2024-11-24 00:18:58 -05:00
Andreas Kling
303ec1c8a3 LibWeb: Don't let input element placeholders influence line-height
Before this change, we transferred the input element's line-height to
both the editable text *and* the placeholder. This caused some strange
doubling of the effective line-height when the editable text was empty,
pushing down the placeholder.

(cherry picked from commit 13ba491924c4fc3831d5a8986673d832a721f545;
amended some slighly different horizontal sizes in the expectations
file. Maybe due to serenity not using harfbuzz for shaping, or due
to not have another earlier change yet. If it's the latter, this will
fix itself when that's brought in.)
2024-11-23 23:48:34 -05:00
Luke Wilde
ca09ed4b37 LibWeb: Make CSSStyleDeclaration a legacy platform object with indices
CSSStyleDeclaration has an indexed property getter, which returns
properties associated with the object in the order they were specified
in.

(cherry picked from commit a94282e0e8dd344bcf94c1d098378bd46151ce47)
2024-11-23 22:07:22 -05:00
Luke Wilde
772be9dec0 LibWeb: Generate IDL attributes for all supported CSS properties
The CSSOM spec tells us to potentially add up to three different IDL
attributes to CSSStyleDeclaration for every CSS property we support:
- A camelCased attribute, where a dash indicates the next character
  should be uppercase
- A camelCased attribute for every -webkit- prefixed property, with the
  first letter always being lowercase
- A dashed-attribute for every property with a dash in it.

Additionally, every attribute must have the CEReactions and
LegacyNullToEmptyString extended attributes specified on it.

Since we specify every property we support with Properties.json, we can
use that file to generate the IDL file and it's implementation.

We import it from the Build directory with the help of multiple import
base paths. Then, we add it to CSSStyleDeclaration via the mixin
functionality and inheriting the generated class in
CSSStyleDeclaration.

(cherry picked from commit aacf9b08ed8c4286c84145b52fa70f399ed0bdff;
amended to fix tiny conflict in libweb_generators.cmake, and to change
the default value of all gap-related properties from 'auto' to 'normal'
since serenity does not yet have LadybirdBrowser/ladybird#2253 and
cherry-picking that has a pretty long dependency tree. It's easy to
update the test once that is cherry-picked)
2024-11-23 22:07:22 -05:00
Luke Wilde
8ff9aa177f LibWeb: Fix OBOE in bounds check of ResolvedCSSStyleDeclaration#item
Without this, it would return "(invalid CSS::PropertyID)" when
requesting item(decl.length).

(cherry picked from commit 5aacb053a3fa0cf0e2a825c63dd3a4ebd916eda4)
2024-11-23 22:07:22 -05:00
Andreas Kling
9b4db4a0e0 LibWeb: Make DOMException take error message as a String
There was no need to use FlyString for error messages, and it just
caused a bunch of churn since these strings typically only existed
during the lifetime of the error.

(cherry picked from commit 175f3febb8037a440d4ead7347d3266ee3d345e1;
minorly amended to fix conflict in WebSocket.cpp due to serenity
not having the adapter class removal in LadybirdBrowser/ladybird#1671)
2024-11-22 11:13:42 -05:00
Neil Viloria
a73fb690aa LibWeb/Layout: Implement align-content for grid layout
(cherry picked from commit b9e7c6a2f66d83c6af73bcc102c05d3056382c02)
2024-11-22 10:49:46 -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
Sam Atkins
4323e0fce8 LibWeb/CSS: Use writing-mode enum for writing-mode property
(cherry picked from commit 0a569a9034298d4735eec0fe5163232944590640)
2024-11-20 22:51:34 -05:00
BenJilks
de4fe9fcfe LibWeb: Add writing-mode CSS property, and its values
Introduce the `writing-mode` property, as specified in
https://drafts.csswg.org/css-writing-modes/#block-flow

(cherry picked from commit c3f3e93b7e46e2f366fbc904852763af546d3913;
amended to fix conflict on `height:` in expectation)
2024-11-19 11:02:38 -05:00
stelar7
ded4fc8b2f LibWeb: Add debug log message for missing calc() context
(cherry picked from commit 2b65e86ec7fb04d5c0e31256e80bee31a66c6d96)
2024-11-19 11:02:38 -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
Andreas Kling
e1ba881587 AK+LibWeb: Add {Fly,}String::to_ascii_{upper,lower}_case()
These don't have to worry about the input not being valid UTF-8 and
so can be infallible (and can even return self if no changes needed.)

We use this instead of Infra::to_ascii_{upper,lower}_case in LibWeb.

(cherry picked from commit 073bcfd3866852a4c4bcca2bd131bd65ae53541f)
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
Jonne Ransijn
f27d50afbc LibWeb: Return Web::CSS::Selector::pseudo_element by reference
This avoids many allocations and deallocations.

(cherry picked from commit 8409178a111424710492a0bcdf692bfa3439b4a5)
2024-11-18 13:21:10 -05:00
Sam Atkins
4e73ad50df LibWeb/CSS: Process style properties from CSSNestedDeclarations rules
These are created when a style rule has properties listed after another
rule. For example:

```css

.test {
  --a: 1;
  --b: 1;
  --c: 1;

  .thing {
    /* ... */
  }

  /* These are after a rule (.thing) so they're wrapped in a
     CSSNestedDeclarations: */
  --d: 1;
  --e: 1;
  --f: 1;
}
```

They're treated like a nested style rule with the exact same selectors
as their containing style rule.

(cherry picked from commit e4245dc39e68d9376dfb2344c78119a938533319)
2024-11-18 09:48:28 -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
40c8607316 LibWeb/CSS: Use SelectorList type instead of Vector<NNRP<Selector>>
(cherry picked from commit 74c448d744f55cde3bddfd2611b629b7535fb8cf)
2024-11-18 09:48:28 -05:00
Sam Atkins
afec5ff003 LibWeb/CSS: Clear CSSRule's cached layer name when it is moved
Through the CSSOM, rules can be moved around, and so anything cached
(for now just the qualified layer name) needs to be recalculated when
that happens. This method is virtual so that other rules will be able
to clear their cached data too.

(cherry picked from commit d935a00413cbfc0d292406a1b97a327715882078)
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
Sam Atkins
a4c7586337 LibWeb: Implement CSSNestedDeclarations type
This is basically a list of properties, without a block around it. It'll
be part of CSSStyleRules' contents.

(cherry picked from commit 9c66ab356ac96602e5c1dc23906288fa187e9f01)
2024-11-18 09:48:28 -05:00
Sam Atkins
8cd170fba3 LibWeb/CSS: Parse the & nesting selector
(cherry picked from commit 5b4d1b5b05c66cc82590f72451e58055c4df9e65)
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
ronak69
f0d743add5 LibWeb/CSS: Don't serialize empty rules in CSSStyleRule
This is a recent spec change:
https://github.com/w3c/csswg-drafts/pull/10974

(cherry picked from commit 592cf556a1b9567e450cebc6c955dec6b5a860bb)
2024-11-18 09:07:51 -05:00
Sam Atkins
b961998c1f LibWeb/CSS: Insert whitespace between tokens in serialized UnresolvedSV
Otherwise, `margin: var(--foo) var(--bar)` would be wrongly serialized
as `margin: var(--foo)var(--bar)`

(cherry picked from commit 6e68e8f3c9d74893e46ab0514169b950866457b4)
2024-11-17 23:31:49 -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
c6c27bf2cf LibWeb/CSS: Tokenize comments as whitespace tokens
This is in a weird position where the spec tells us to discard the
comments, but then we have to preserve the original source text which
may include comments. As a compromise, I'm treating each comment as a
whitespace token - comments are functionally equivalent to whitespace
so this should not have any behaviour changes beyond preserving the
original text.

(cherry picked from commit f8995d37a2bf71e98e273f4aa0764d9c022ac127)
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
059539d691 LibWeb/CSS: Implement "is a custom property name string" to spec
This will be needed in the Parser soon, so for lack of a better place,
it's going in a separate header.

(cherry picked from commit f11c0e6cc0aa173f2f6120448b40c1520b55e046)
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