Commit graph

19 commits

Author SHA1 Message Date
Sam Atkins
d42a5494d7 LibWeb/CSS: Parse @font-face descriptors as style values
CSSFontFaceRule now stores its values as a CSSFontFaceDescriptors, with
a ParsedFontFace produced on request. This is exposed via the `style`
attribute, so we pass a lot of tests that try to read values from
that.

We have one test regression, which we passed by mistake before: The test
wanted to ensure we don't allow `@font-face` nested inside other rules.
We passed it just because we discarded any `@font-face` without a
`font-family`. What we're supposed to do is 1) keep at-rules with
missing required descriptors and just not use them, and 2) reject
certain ones when nested.

We may want to cache the ParsedFontFace in the future, but I didn't here
because 1) it's called rarely, and 2) that would mean knowing to
invalidate it when the CSSFontFaceDescriptors changes, which isn't
obvious to me right now.
2025-04-03 14:04:21 +01:00
Sam Atkins
86b57a5205 LibWeb/CSS: Use font_format_is_supported() when parsing font sources 2025-04-02 15:53:50 +01:00
Tim Ledbetter
ac19b0cda8 LibWeb/CSS: Support media queries in import at-rules 2025-04-02 13:53:03 +01:00
Sam Atkins
285fbc8f1c LibWeb/CSS: Parse local() font sources more correctly
There were several issues with the previous parsing code, like ignoring
trailing tokens, not handling whitespace, and not requiring the value
to be a `<family-name>`. So, fix all that.

Also correct the serialization code, which didn't call
`serialize_a_string()` previously.
2025-03-25 07:53:59 +00:00
Sam Atkins
93a2c9946f LibWeb: Use FlyString for local font sources
The next commit will make it so we always have a FlyString, so this lets
us keep using it instead of turning it into a String.
2025-03-25 07:53:59 +00:00
Tim Ledbetter
c37a47f76f LibWeb/CSS: Implement import at-rule supports conditions
This indicates the features the browser must support for the given
stylesheet to be fetched.
2025-03-19 16:42:51 +01:00
Sam Atkins
9b06f66571 LibWeb/CSS: Return GC::Ref from Parser::convert_to_style_declaration() 2025-03-19 13:53:00 +00:00
Sam Atkins
83bb92c4e0 LibWeb/CSS: Merge style declaration subclasses into CSSStyleProperties
We previously had PropertyOwningCSSStyleDeclaration and
ResolvedCSSStyleDeclaration, representing the current style properties
and resolved style respectively. Both of these were the
CSSStyleDeclaration type in the CSSOM. (We also had
ElementInlineCSSStyleDeclaration but I removed that in a previous
commit.)

In the meantime, the spec has changed so that these should now be a new
CSSStyleProperties type in the CSSOM. Also, we need to subclass
CSSStyleDeclaration for things like CSSFontFaceRule's list of
descriptors, which means it wouldn't hold style properties.

So, this commit does the fairly messy work of combining these two types
into a new CSSStyleProperties class. A lot of what previously was done
as separate methods in the two classes, now follows the spec steps of
"if the readonly flag is set, do X" instead, which is hopefully easier
to follow too.

There is still some functionality in CSSStyleDeclaration that belongs in
CSSStyleProperties, but I'll do that next. To avoid a huge diff for
"CSSStyleDeclaration-all-supported-properties-and-default-values.txt"
both here and in the following commit, we don't apply the (currently
empty) CSSStyleProperties prototype yet.
2025-03-19 13:53:00 +00:00
Sam Atkins
6a4d80b9b6 LibWeb/CSS: Integrate ParsingContext into the Parser
This is not really a context, but more of a set of parameters for
creating a Parser. So, treat it as such: Rename it to ParsingParams,
and store its values and methods directly in the Parser instead of
keeping the ParsingContext around.

This has a nice side-effect of not including DOM/Document.h everywhere
that needs a Parser.
2025-02-06 16:47:25 +00:00
Sam Atkins
0ac133d73b LibWeb/CSS: Replace is_generic_font_family() with a CSS enum
Also add the missing "math" value to it.
2025-02-06 16:47:25 +00:00
Sam Atkins
1413760047 LibWeb/CSS: Split up Parser.cpp
This file has been a pain to edit for a while, even with the previous
splits. So, I've divided it up into 3 parts:
- Parser.cpp has the "base" code. It's the algorithms and entry-points
  defined in the Syntax spec.
- ValueParsing.cpp contains code for parsing single values, such as a
  length, or a color, or a calculation.
- PropertyParsing.cpp contains code for parsing an entire property's
  value. A few of these sit in a grey area between being a property's
  value and a value in their own right, but the rule I've used is "is
  this useful outside of a single property and its shorthands?"

This only moves code, with as few modifications as possible to make that
work. I did add explicit instantiations for the template implementations
as part of this, which revealed a few that are actually only compatible
with a single type, so I'll clear those up in a subsequent commit.
2025-02-06 16:47:25 +00:00
Sam Atkins
1d71662f31 LibWeb/CSS: Wrap calc()-resolution data in a struct
Initially I added this to the existing CalculationContext, but in
reality, we have some data at parse-time and different data at
resolve-time, so it made more sense to keep those separate.

Instead of needing a variety of methods for resolving a Foo, depending
on whether we have a Layout::Node available, or a percentage basis, or
a length resolution context... put those in a
CalculationResolutionContext, and just pass that one thing to these
methods. This also removes the need for separate resolve_*_percentage()
methods, because we can just pass the percentage basis in to the regular
resolve_foo() method.

This also corrects the issue that *any* calculation may need to resolve
lengths, but we previously only passed a length resolution context to
specific types in some situations. Now, they can all have one available,
though it's up to the caller to provide it.
2025-01-30 19:31:54 +01:00
Andreas Kling
c53c781745 LibWeb: Inline CSSStyleValue::to_keyword()
Shaves 120 ms of loading time off of https://wpt.fyi/
2025-01-28 01:12:45 +01:00
Andreas Kling
3bfb0534be LibGC: Rename MarkedVector => RootVector
Let's try to make it a bit more clear that this is a Vector of GC roots.
2024-12-26 19:10:44 +01:00
Sam Atkins
69a0f28d04 Revert "LibWeb/CSS: Rename CalculatedStyleValue -> CSSMathValue"
This reverts commit 76daba3069.

We're going to need separate types for the JS-exposed style values, so
it doesn't make sense for us to match their names with our internal
types.
2024-12-21 18:14:28 +01:00
Sam Atkins
e318316af7 LibWeb/CSS: Add missing parameter to CSSStyleValue::to_string() calls 2024-12-13 08:23:56 -08:00
Shannon Booth
0fa54c2327 LibURL+LibWeb: Make URL::serialize return a String
Simplifying a bunch of uneeded error handling around the place.
2024-12-04 16:34:13 +00:00
Shannon Booth
f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Renamed from Userland/Libraries/LibWeb/CSS/Parser/RuleParsing.cpp (Browse further)