Commit Graph

328 Commits

Author SHA1 Message Date
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
0a3b33e6f6 LibWeb: Rename "identifier" and "ValueID" to "Keyword" where correct
For a long time, we've used two terms, inconsistently:
- "Identifier" is a spec term, but refers to a sequence of alphanumeric
  characters, which may or may not be a keyword. (Keywords are a
  subset of all identifiers.)
- "ValueID" is entirely non-spec, and is directly called a "keyword" in
  the CSS specs.

So to avoid confusion as much as possible, let's align with the spec
terminology. I've attempted to change variable names as well, but
obviously we use Keywords in a lot of places in LibWeb and so I may
have missed some.

One exception is that I've not renamed "valid-identifiers" in
Properties.json... I'd like to combine that and the "valid-types" array
together eventually, so there's no benefit to doing an extra rename
now.

(cherry picked from commit 6a74b0164423d63904cf5a5b594772b595f57600;
very minorly amended to fix conflict in GenerateCSSKeyword.cpp caused
by #22870, and in libweb_generators.cmake due to us not having
https://github.com/LadybirdBrowser/ladybird/pull/741)
2024-10-10 10:08:59 -04:00
Sam Atkins
a4981ae745 LibWeb: Rename StyleValue -> CSSStyleValue
This matches the name in the CSS Typed OM spec.
https://drafts.css-houdini.org/css-typed-om-1/#cssstylevalue

No behaviour changes.

(cherry picked from commit 0e3487b9ab455a7648185995363bb3b487551d40)
2024-10-10 10:08:59 -04:00
Sam Atkins
b75c0b629a LibWeb/CSS: Add quick-and-dirty parsing for pseudo-element selectors
As noted, this is hacky because the parser wasn't written to allow
parsing an individual component of a selector. (Fox example, the
convenient-sounding `parse_pseudo_simple_selector()` assumes the first
colon has already been consumed...) So until that changes, this parses
the input as an entire selector-list, and then throws it away if it's
not a single pseudo-element selector.

It's only temporary though, I promise. 😅

(cherry picked from commit dae9c9be40e069989e0079745b7077dd9bab1c26)
2024-09-28 14:14:28 -04:00
Sam Atkins
afe2c819df LibWeb/CSS: Bring previous CSSRule parsing up to standard
GCPtrs instead of raw pointers, and logging when the media rule is
invalid.

(cherry picked from commit 80a20be176d2b2274613ec92cd6e74f37592bca8)
2024-09-27 21:21:11 -04:00
Sam Atkins
f891e52587 LibWeb/CSS: Parse gradient functions with TokenStream
They already used TokenStream for parsing the function parameters, but
this makes the `parse_foo_gradient()` functions themselves take a
TokenStream.

(cherry picked from commit 9de73bf89b061d6f168f7c1c3278e8f203959b3a)
2024-09-27 21:21:11 -04:00
Sam Atkins
b1d2ceb012 LibWeb/CSS: Parse url() functions with TokenStream
(cherry picked from commit 29d7aa9fc9de76491d0f400526f53699176c3c07)
2024-09-27 21:21:11 -04:00
Sam Atkins
28393589cf LibWeb/CSS: Split out @keyframes parsing code
Changes are very minimal, this is just a code move.

(cherry picked from commit d5f3a610acd33b4b92d56896d71f3bb4c189cbaf)
2024-09-27 21:21:11 -04:00
Sam Atkins
53ffb9c5b2 LibWeb/CSS: Split out @supports parsing code
(cherry picked from commit e5737232c059c1a1d6eabaf2560832599343a6fb)
2024-09-27 21:21:11 -04:00
Sam Atkins
9e295d9b97 LibWeb/CSS: Split out @namespace parsing code
(cherry picked from commit 5b883929e0fd9e128969551e67a8e63c743582d9)
2024-09-27 21:21:11 -04:00
Sam Atkins
2d09e4868d LibWeb/CSS: Split out @import parsing and convert it to TokenStream
(cherry picked from commit 16049db560f98ddae21d21cf4f3145125851ded7)
2024-09-27 21:21:11 -04:00
Sam Atkins
be8b9e81e1 LibWeb/CSS: Parse builtin values using TokenStream
(cherry picked from commit b9b2fd62b5308b1d006cadd8f3b2d5fcf9e1f1f5)
2024-09-27 21:21:11 -04:00
Sam Atkins
a53a6c4067 LibWeb/CSS: Flatten parse_basic_shape_function() into only caller
(cherry picked from commit 98963e0c9ac5eb7eb84e28e4199baea8864156fe)
2024-09-27 21:21:11 -04:00
Sam Atkins
c1a210a61e LibWeb/CSS: Make parse_color() take a TokenStream
This makes the parse_color_value() code a lot simpler.

(cherry picked from commit e5553d6d2f1274d8fa1a9c9fafc030703452dc68)
2024-09-27 21:21:11 -04:00
Sam Atkins
94674c6999 LibWeb/CSS: Parse custom-idents more consistently
These have a few rules that we didn't follow in most cases:
- CSS-wide keywords are not allowed. (inherit, initial, etc)
- `default` is not allowed.
- The above and any other disallowed identifiers must be tested
  case-insensitively.

This introduces a `parse_custom_ident_value()` method, which takes a
list of disallowed identifier names, and handles the above rules.

(cherry picked from commit 6ae2b8c3d901d8a7255046a4517fddd8b0fa84c4)
2024-07-28 20:21:39 -04:00
Sam Atkins
c90492a50c LibWeb/CSS: Make CSS Parser::create() infallible
Now that `Tokenizer::tokenize()` just returns a String, there are no
errors to propagate, and we can simplify the user code a bit.

(cherry picked from commit 59778d2b365476ecb5b50218dae4457493ee7bf7)
2024-07-28 16:44:00 -04:00
Sam Atkins
07fe3e57c6 LibWeb: Implement CounterStyleValue
This is `counter(name, style?)` or `counters(name, link, style?)`. The
difference being, `counter()` matches only the nearest level (eg, "1"),
and `counters()` combines all the levels in the tree (eg, "3.4.1").

(cherry picked from commit 576a4314084e5c3b839006da00dddb16e58b3503)
2024-07-28 13:31:02 -04:00
Sam Atkins
1bc896fa60 LibWeb: Implement counter-[increment,reset,set] properties
These control the state of CSS counters.

Parsing code for `reversed(counter-name)` is implemented, but disabled
for now until we are able to resolve values for those.

(cherry picked from commit 017d6c3314d57d4e351764f328c1d25dbc9d033a)
2024-07-28 13:31:02 -04:00
Sam Atkins
bab7f225c6 LibWeb/CSS: Refactor contains_single_none_ident() to actually parse it
The new method is Parser::parse_all_as_single_none_value(), which has a
few advantages:

1. There's no need for user code to manually create a StyleValue.
2. It consumes tokens so that doesn't have to be done manually.
3. Whitespace before or after the `none` is consumed correctly.

It does mean we create and then discard a `none` StyleValue in a couple
of places, namely parsing for `grid-*` properties. We may or may not
want to migrate those to returning the IdentifierStyleValue instead.

(cherry picked from commit ca10fb412947f6b6080326573418bfa8a3759c12)
2024-07-28 13:31:02 -04:00
Edwin Hoksberg
dd843ae282 LibWeb: Implement grid-template function fit-content()
(cherry picked from commit e5deaa1c073f4762fe2cdc7d36f90099f0ca4d11)
2024-07-28 07:31:47 -04:00
Luke Warlow
e8bcd3842d LibWeb: Implement support for scrollbar-gutter
This property is now correctly parsed.

Ladybird always uses overlay scrollbars so this property does nothing.

(cherry picked from commit 662317726549cd2dde4c7902b99f0b83397a3396)
2024-07-14 20:44:46 -04:00
Gingeh
d532331f34 LibWeb/CSS: Support hwb, oklab and oklch color functions
(cherry picked from commit e8d32bab58d9ffb183ee71ee6516d49556db136b,
manually amended to fix the two diags mentioned in
https://github.com/LadybirdBrowser/ladybird/pull/385#issuecomment-2227126447
)
2024-07-13 21:43:38 -04:00
Gingeh
052ff6e141 LibWeb/CSS: Split parse_rgb_or_hsl_color into separate functions
(cherry picked from commit 490a36bab18873db632496e594152b68cd2b8ca3)
2024-07-13 21:43:38 -04:00
Edwin Hoksberg
e2bf7d1a36 LibWeb: Add attribute list that must always be compared without casing
(cherry picked from commit 2b30414c1d8641eaf4212db69e40a4381005314c)
2024-06-28 10:56:14 +02:00
MacDue
120915048c LibWeb: Parse the polygon() basic shape function 2024-05-26 07:55:50 +02:00
Andrew Kaster
60b3436ea3 LibWeb: Support loading FontFaces constructed with binary data 2024-05-14 12:31:10 -06:00
Andrew Kaster
de98c122d1 LibWeb: Move CSS unicode-ranges parsing code into a common helper 2024-05-11 07:30:29 +01:00
Andrew Kaster
3a5eabc43b LibWeb: Rename CSS::FontFace to CSS::ParsedFontFace
This implementation detail of CSSFontFaceRule is hogging the name of a
Web API from CSS Font Loading Module Level 3.
2024-05-08 10:39:16 +02:00
Sam Atkins
59c79e848c LibWeb: Parse dimension values using TokenStream 2024-04-22 06:47:05 +02:00
Sam Atkins
efce563abd LibWeb: Parse identifier values using TokenStream 2024-04-22 06:47:05 +02:00
Sam Atkins
e4e048f278 LibWeb: Parse color values using TokenStream 2024-04-22 06:47:05 +02:00
Sam Atkins
710e5c24d3 LibWeb: Parse string values using TokenStream 2024-04-22 06:47:05 +02:00
Sam Atkins
e42f052b00 LibWeb: Parse rect() values using TokenStream 2024-04-22 06:47:05 +02:00
Sam Atkins
e00f41a274 LibWeb: Parse URL values using TokenStream 2024-04-22 06:47:05 +02:00
Sam Atkins
cfa221944c LibWeb: Parse image values using TokenStream 2024-04-22 06:47:05 +02:00
Sam Atkins
384b18b271 LibWeb: Make parse_color_stop_list() a CSS Parser method
This lets us remove the color/dimension-parsing lambdas, since these
always forwarded to the same methods. This will make it easier to later
convert those methods to take a TokenStream.
2024-04-22 06:47:05 +02:00
Matthew Olsson
5dce559ed8 LibWeb: Parse transition style values 2024-03-29 21:58:12 +01:00
Matthew Olsson
1f53727a3f LibWeb: Remove Badge from CSS::Parser::resolve_unresolved_style_value
KeyframeEffect needs to use this method to resolve unresolved properties
in the same way that StyleComputer does.
2024-03-20 09:17:33 +01:00
Shannon Booth
e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00
Andreas Kling
c0e0cb86e1 LibWeb: Make CSS::string_from_property_id() return FlyString const&
This avoids costly conversions from StringView to FlyString in CSS
parsing and variable expansion.
2024-03-16 14:27:59 +01:00
Shannon Booth
9ce8189f21 Everywhere: Use unqualified AK::URL
Now possible in LibWeb now that there is no longer a Web::URL.
2024-02-25 08:54:31 +01:00
Bastiaan van der Plaat
c443f80137 LibWeb: Allow percentages on CSS transform scale functions 2024-01-10 09:48:25 +01:00
Sam Atkins
8b69f41bcd LibWeb: Remove old parse_length(ComponentValue const&) method 2023-12-30 20:11:24 +01:00
Sam Atkins
306acf43c4 LibWeb: Convert parse_source_size_value() to TokenStream 2023-12-30 20:11:24 +01:00
Sam Atkins
e62d692205 LibWeb: Implement helpers for parsing CSS numeric types
Frequently we want to parse "anything that's a `<length-percentage>`" or
similar, which could be a constant value or a calculation, but didn't
have a nice way of doing so. That meant repeating the same "try and
parse a dimension, see if it's the right type, then maybe try and parse
a calculation and see if that's the right type" boilerplate code. Or
more often, forgetting about calculations entirely.

These helpers should make that a lot more convenient to do. And they
also use TokenStream, so we can eventually drop the old `parse_length()`
method.
2023-12-30 20:11:24 +01:00
Sam Atkins
69f88c9a64 LibWeb: Parse grid property using TokenStream 2023-12-26 19:58:20 +00:00
Sam Atkins
5f99edad3b LibWeb: Parse grid-template property using TokenStream 2023-12-26 19:58:20 +00:00
Sam Atkins
b8c6c75ae1 LibWeb: Parse grid-template-[columns,rows] properties using TokenStream 2023-12-26 19:58:20 +00:00
Sam Atkins
ee5b00d1ee LibWeb: Parse grid-auto-[columns,rows] properties using TokenStream 2023-12-26 19:58:20 +00:00