Commit graph

634 commits

Author SHA1 Message Date
Sam Atkins
86b57a5205 LibWeb/CSS: Use font_format_is_supported() when parsing font sources 2025-04-02 15:53:50 +01:00
Tim Ledbetter
cbb169820a LibWeb/CSS: Implement the CSSImportRule.media attribute 2025-04-02 13:53:03 +01:00
Tim Ledbetter
ac19b0cda8 LibWeb/CSS: Support media queries in import at-rules 2025-04-02 13:53:03 +01:00
Aliaksandr Kalenik
24527b6ae3 LibWeb: Pass PaintingSurface into DisplayListPlayer::execute()
Deleteing set_surface() makes DisplayListPlayer API a bit more intuitive
because now caller doesn't have to think whether it's necessary to
restore previous surface after execution, instead DisplayListPlayer
takes care of it by maintaining a stack of surfaces.
2025-04-01 23:39:05 +02:00
Glenn Skrzypczak
9973b01848 LibWeb/CSS: Improved implementation of background-blend-mode
This is a improved version of a73cd88f0c
The old commit was reverted in 552dd18696

The new version only paints an element into a new layer if background
blend modes other than normal are used. The rasterization performance
of most websites should therefore not suffer.

Co-Authored-By: Alexander Kalenik <kalenik.aliaksandr@gmail.com>
2025-04-01 13:38:00 +02:00
Aliaksandr Kalenik
552dd18696 Revert "LibWeb/CSS: Implement 'background-blend-mode'"
This reverts commit a73cd88f0c.

Emitting SaveLayer for each paintable made rasterization a lot slower
on every website because now Skia has to allocate enormous amounts of
temporary surfaces. Let's revert it for now and figure how to implement
it with less aggressive SaveLayer usage.
2025-03-28 16:48:03 +00:00
Glenn Skrzypczak
a73cd88f0c LibWeb/CSS: Implement 'background-blend-mode'
This implements the 'background-blend-mode' CSS property.
2025-03-28 09:41:06 +00:00
Sam Atkins
09b8f73e11 LibWeb/CSS: Implement UnicodeRangeStyleValue
This is preparation for storing at-rule descriptors as style values.
2025-03-28 09:15:02 +00:00
Sam Atkins
ef3a2bf907 LibWeb/CSS: Move functions for detecting var()/attr() into Token types
This makes them accessible outside of PropertyParsing.cpp (which will be
useful if/when descriptors can include them). I've also renamed them to
use the correct term: "arbitrary substitution function".
2025-03-28 09:15:02 +00:00
Sam Atkins
2b67cb5f98 LibWeb/CSS: Move "serialize a CSS declaration" to Serialize.{h,cpp}
We need this in other places, so make it available for reuse. Also,
update step 4 which now only appends `value` if it contains
non-whitespace.
2025-03-27 11:53:09 +00:00
Sam Atkins
a2c89f585f LibWeb/CSS: Give all style values a visit_edges() method
Having this hidden away in ImageStyleValue meant that
CSSStyleProperties (and anyone else who holds style values) had to know
exactly which types need visiting. This is a footgun waiting to happen,
so make this a virtual method on CSSStyleValue instead.
2025-03-27 11:53:09 +00:00
Sam Atkins
2d3dea0770 LibWeb/CSS: Update quirks-mode styling for form elements
The current HTML spec uses margin-block-end instead of margin-bottom.
2025-03-26 09:47:45 +00:00
Sam Atkins
b2873d7ed6 LibWeb/CSS: Add new list-style-position quirk
Corresponds to d79381d822

In quirks mode, a `<li>` with no parent list element now has
`list-style-position: inside`.
2025-03-26 09:47:45 +00:00
Andreas Kling
ba030f0363 LibWeb: Add an engine-internal CSS realm for internal style parsing
This is used for default UA style right now, and we'll expand its use in
the near future.

Note that this required teaching the CSS parser to handle url()
functions when there's no document URL to resolve them against. If we
don't handle that, namespace rules in UA style don't parse correctly.
2025-03-25 23:57:00 +00:00
Jelle Raaijmakers
6a3c3ee291 LibWeb: Coerce NaNs to 0 when escaping top-level calculations 2025-03-25 19:53:36 +00:00
Jelle Raaijmakers
545d151948 LibWeb: Make transform: scale(calc(..)) work
The `transform` property supports transform functions that sometimes
need their `calc(percentage)` values to be converted to a number instead
of a length. Currently this only applies to the `scale*` family of
functions, which are marked as such in `TransformFunctions.json`.

We were not consistently applying the `NumberPercentage` type to these
functions though, and in addition, any `NumberPercentage` value would
not consider calculated values.
2025-03-25 19:53:36 +00:00
Aliaksandr Kalenik
090ac66af1 LibWeb: Repeat grid track sizing with minmax where both are not definite
...should be treated as invalid value.
2025-03-25 09:53:04 +00:00
Sam Atkins
88e11eea2d LibWeb: Implement functional pseudo-element parsing
"Functional" as in "it's a function token" and not "it works", because
the behaviour for these is unimplemented. :^)

This is modeled after the pseudo-class parsing, but with some changes
based on things I don't like about that implementation. I've
implemented the `<pt-name-selector>` parameter used by view-transitions
for now, but nothing else.
2025-03-25 07:54:13 +00:00
Sam Atkins
5cf04a33ad LibWeb/CSS: Add method for parsing <custom-ident> directly
We specifically want to parse one inside a selector, where we only care
about the string itself and don't want a whole style value.
2025-03-25 07:54:13 +00: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
Sam Atkins
f8536fc48a LibWeb/CSS: Split out <family-name> parsing
This type is used individually elsewhere in the spec. This also lets us
separate out the `<generic-family>` type.
2025-03-25 07:53:59 +00:00
Tim Ledbetter
9ce5bbe059 LibWeb: Remove CubicBezier cached sample inline cache
This reduces the size of CubicBezier objects from 1592 bytes to 56
bytes.
2025-03-25 07:51:27 +00:00
Sam Atkins
9e65291ebd LibWeb/CSS: Discard unsupported style properties on pseudo-elements
Quite simply, ignore any declarations for properties we don't want,
while computing a pseudo-element's style.

I've imported a WPT test for this, which fails without this patch.
2025-03-24 09:49:50 +00:00
Sam Atkins
1108988656 LibWeb/CSS: Generate property-filtering code for pseudo-elements
Pseudo-elements have specific rules about which CSS properties can be
applied to them. This is a first step to supporting that.

- If a property whitelist isn't present, all properties are allowed.
- Properties are named as in CSS.
- Names of property groups are prefixed with `#`, which makes this match
  the spec more clearly. These groups are implemented directly in the
  code generator for now.
- Any property name beginning with "FIXME:" is ignored, so we can mark
  properties we don't implement yet.
2025-03-24 09:49:50 +00:00
Sam Atkins
193adee164 LibWeb/CSS: Implement aliases for pseudo-elements
We previously supported a few -webkit vendor-prefixed pseudo-elements.
This patch adds those back, along with -moz equivalents, by aliasing
them to standard ones. They behave identically, except for serializing
with their original name, just like for unrecognized -webkit
pseudo-elements.

It's likely to be a while before the forms spec settles and authors
start using the new pseudo-elements, so until then, we can still make
use of styles they've written for the non-standard ones.
2025-03-24 09:49:50 +00:00
Sam Atkins
021e3f5c7d LibWeb/CSS: Generate is_has_allowed_pseudo_element() 2025-03-24 09:49:50 +00:00
Sam Atkins
ffa1dba96a LibWeb: Generate pseudo-element code from JSON
Initially, this generates the enum and to/from-string functions. The
JSON itself contains more data than that, but it's unused for now.
2025-03-24 09:49:50 +00:00
Sam Atkins
0ed2e71801 LibWeb/CSS: Move and rename PseudoElement types to prep for code gen
The upcoming generated types will match those for pseudo-classes: A
PseudoElementSelector type, that then holds a PseudoElement enum
defining what it is. That enum will be at the top level in the Web::CSS
namespace.

In order to keep the diffs clearer, this commit renames and moves the
types, and then a following one will replace the handwritten enum with
a generated one.
2025-03-24 09:49:50 +00:00
Tim Ledbetter
7b0b6e7493 LibWeb/CSS: Make empty GridTrackSize value serialize to "none"
This is the default value of the `grid-template-rows` and
`grid-template-columns` properties.
2025-03-22 17:33:37 +01:00
Tim Ledbetter
cbf47abd24 LibWeb/CSS: Set the initial value of the appearance property to "none" 2025-03-22 17:05:17 +01:00
Tim Ledbetter
ecd6636b3e LibWeb/CSS: Use "0s" as the initial value for animation-duration 2025-03-22 17:04:33 +01:00
Tim Ledbetter
40760308c6 LibWeb: Don't crash when border-spacing is set to a calc() value
Previously, the browser would crash if the `border-spacing` property
had 2 lengths and either one of these was set to a `calc()` value.
2025-03-21 08:16:30 +00:00
Andrew Kaster
603df37a88 LibWeb: Devirtualize CSS::CalculatedOr
This fixes a compile warning on GCC 13.3.0 where it warns about the
use of Variant within this class with no key function. Since the class
was almost a CRTP base class, make it a real one.
2025-03-20 11:36:09 -06:00
Tim Ledbetter
5bfbb7abe6 LibWeb: Preserve unit when serializing angle values
Previously, when serializing an angle value, we would always convert it
to degrees. We now canonicalize the angle value only when serializing
its computed value.
2025-03-20 16:59:27 +00:00
Tim Ledbetter
d0be5a0cdf LibWeb: Preserve unit when serializing time values
Previously, when serializing a time value, we would always convert it
to seconds. We now canonicalize the time value only when serializing
its computed value.
2025-03-20 16:59:27 +00:00
Tim Ledbetter
2672fe99b7 LibWeb: Set correct longhands if grid-area subproperties are omitted 2025-03-20 16:59:27 +00:00
Tim Ledbetter
c029a9c98c LibWeb: Serialize grid-area as auto if all sub-properties are auto 2025-03-20 16:59:27 +00:00
Tim Ledbetter
54351e7327 LibWeb: Use shortest serialization for shorthands with repeated values
For shorthands where all the values are repeated, we now only output
the value once.
2025-03-20 14:30:55 +01:00
Tim Ledbetter
5d57723ebf LibWeb: Implement CSSImportRule.supportsText
Returns the supports condition specified by the given import at-rule.
2025-03-19 16:42:51 +01: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
Tim Ledbetter
d38b5e260e LibWeb: Mark CSSImportRule.styleSheet IDL definition as nullable
The stylesheet may be null if its `supports()` condition does not match.
This matches the current specification.
2025-03-19 16:42:51 +01:00
Sam Atkins
2d220a8bbc LibWeb: Return CSSStyleProperties as a GC::Ref 2025-03-19 13:53:00 +00: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
a28197669a LibWeb/CSS: Move property code from CSSStyleDeclaration to *Properties
CSSStyleDeclaration is a base class that's used by various collections
of style properties or descriptors. This commit moves all
style-property-related code into CSSStyleProperties, where it belongs.

As noted in the previous commit, we also apply the CSSStyleProperties
prototype now.
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
687d32b712 LibWeb: Remove ElementInlineCSSStyleDeclaration entirely
All of its behavior has now been moved up into its parent classes.
2025-03-19 13:53:00 +00:00
Sam Atkins
50455c2f5e LibWeb: Stop constructing temporary ElementInlineCSSStyleDeclarations
Previously, parse_css_style_attribute() would parse the string, extract
the properties, add them to a newly-created
ElementInlineCSSStyleDeclarations, and then user code would take the
properties back out of it again and throw it away. Instead, just return
the list of properties, and the caller can create an EICSD if it needs
one.
2025-03-19 13:53:00 +00:00
Sam Atkins
f0d198ca3f LibWeb/CSS: Move CSSStyleDeclaration subclasses' fields into it
The spec defines several properties on the declaration which we
previously made virtual or stored on subclasses. This commit moves these
into CSSStyleDeclaration itself, and updates some of the naming.
2025-03-19 13:53:00 +00:00
Sam Atkins
d5b9c39a98 LibWeb: Replace webkit meter-state pseudo-elements with pseudo-classes
This also implements the `:high-value` and `:low-value` that are in the
spec.

Same note as before about this being based on the very-drafty CSS Forms
spec. In fact, some of this isn't even in that spec yet. Specifically,
the `:suboptimal-value` and `:even-less-good-value` names are undecided
and subject to change. However, it's clear that this is a pseudo-class
situation, not a pseudo-element one, so I think this is still an
improvement, as it allows styling of the `::fill` pseudo-element
regardless of what state it is in.

Relevant spec issue: https://github.com/openui/open-ui/issues/1130
2025-03-19 10:10:03 +00:00