Commit graph

374 commits

Author SHA1 Message Date
Sam Atkins
2aac9f9258 LibWeb: Bring parse_a_declaration() to spec and add comments
User code now calls `parse_as_supports_condition()` which actually does
the conversion to a StyleProperty.
2022-03-30 18:43:07 +02:00
Sam Atkins
239c36a19e LibWeb: Spec-comment parse_a_rule()
We now correctly call convert_to_rule() outside of this function.

As before, I've renamed `parse_as_rule()` -> `parse_as_css_rule()` to
match the free function that calls it.
2022-03-30 18:43:07 +02:00
Sam Atkins
12a787ef8a LibWeb: Use parse_a_list_of_rules() for @media and @supports
From the spec:
> "Parse a list of rules" is intended for the content of at-rules such
> as @media. It differs from "Parse a stylesheet" in the handling of
> <CDO-token> and <CDC-token>.
- https://www.w3.org/TR/css-syntax-3/#ref-for-parse-a-list-of-rules
2022-03-30 18:43:07 +02:00
Sam Atkins
7a225a380c LibWeb: Bring parse_a_list_of_rules() to spec
This is not actually used by anything currently, but it should be used
for `@media` and other at-rules.

Removed the public parse_as_list_of_rules() because public functions
should be things that outside classes actually need to use.
2022-03-30 18:43:07 +02:00
Sam Atkins
85d8c652e9 LibWeb: Implement and use "parse a CSS stylesheet" algorithm
`parse_a_stylesheet()` should not do any conversion on its rules. This
change corrects that. There are other places where we get this wrong,
but one thing at a time. :^)
2022-03-30 18:43:07 +02:00
Sam Atkins
fc3d51c59e LibWeb: Use an enum class for the "top-level flag" 2022-03-30 18:43:07 +02:00
Sam Atkins
87b125dcb9 LibWeb: Spec-comment parse_a_stylesheet()
Also introduce a `location` parameter when parsing a CSSStyleSheet. This
is not provided by anyone yet.
2022-03-30 18:43:07 +02:00
Sam Atkins
05bd0ca3ee LibWeb: Rename parse_css() -> parse_css_stylesheet() 2022-03-30 18:43:07 +02:00
Simon Wanner
6437f5da36 LibWeb: Add basic support for the attr() CSS function
CSS Values and Units Module Level 5 defines attr as:
  `attr(<q-name> <attr-type>?, <declaration-value>?)`

This implementation does not contain support for the type argument,
effectively supporting `attr(<q-name>, <declaration-value>?)`
2022-03-30 03:18:14 +02:00
Daniel Glazman
91e1383b85 LibWeb: Implement attribute selector case identifier 2022-03-29 18:53:20 +02:00
Andreas Kling
427beb97b5 LibWeb: Streamline how inline CSS style declarations are constructed
When parsing the "style" attribute on elements, we'd previously ask the
CSS parser for a PropertyOwningCSSStyleDeclaration. Then we'd create a
new ElementCSSInlineStyleDeclaration and transfer the properties from
the first object to the second object.

This patch teaches the parser to make ElementCSSInlineStyleDeclaration
objects directly.
2022-03-29 16:35:46 +02:00
Sam Atkins
6672c19c93 LibWeb: Parse @font-face rules
This is very limited for now, only caring about `font-family` and `src`.
2022-03-28 22:25:25 +02:00
Sam Atkins
1dcde57922 LibWeb: Bring "parse a list of declarations" closer to spec
The work to create a PropertyOwningCSSStyleDeclaration is now moved to
convert_to_style_declaration() instead.
2022-03-28 22:25:25 +02:00
Sam Atkins
da1a819858 LibWeb: Rename parse_css_declaration() -> parse_css_style_attribute() 2022-03-28 22:25:25 +02:00
Andreas Kling
fda25f9505 LibWeb: Move HTML dimension value parsing from CSS to HTML namespace
These are part of HTML, not CSS, so let's not confuse things.
2022-03-26 17:31:01 +01:00
Andreas Kling
434970f022 LibWeb: Remove the totally ad-hoc parse_html_length()
All clients of this API have been migrated to HTML dimension value
parsing instead.
2022-03-26 17:31:01 +01:00
Andreas Kling
28c929e85c LibWeb: Add parser for the HTML "non-zero dimensions value" microsyntax 2022-03-26 17:31:01 +01:00
Andreas Kling
075bdfdef8 LibWeb: Add a parser for the HTML "dimension value" microsyntax 2022-03-26 17:31:01 +01:00
Sam Atkins
c914e732d2 LibWeb+Base: Fix An+B of foo parsing
When I wrote the An+B parser, it was guaranteed to have no
non-whitespace tokens after it. This is no longer true with the `of
foo` syntax, so this patch corrects the logic when there is no `+B`
segment.

This makes this case shown on Twitter work correctly. :^)
https://twitter.com/simevidas/status/1506657566012678151
2022-03-24 18:08:45 +01:00
Sam Atkins
03daa4653f LibWeb: Parse and compute text-shadow property 2022-03-24 18:08:34 +01:00
Sam Atkins
f078bb8294 LibWeb: Implement disallowing inset when parsing shadows
`text-shadow` does not support this, so this way we can still use the
same parsing code.

It's OK that we still assign a ShadowPlacement value to the
ShadowStyleValue, since it will just get ignored when painting
text-shadows, but if it appears in the property value then that is a
syntax error.
2022-03-24 18:08:34 +01:00
Sam Atkins
1094654adc LbWeb: Rename BoxShadowFoo => ShadowFoo
The `text-shadow` property is almost identical to `box-shadow`:
> Values are interpreted as for box-shadow [CSS-BACKGROUNDS-3].
> (But note that the inset keyword are not allowed.)

So, let's use the same data structures and parsing code for both. :^)
2022-03-24 18:08:34 +01:00
Sam Atkins
004f69b535 LibWeb: Restore :is() and :where() selector parsing
This was a casualty in a recent merge-conflict resolution. Oops!
2022-03-23 15:46:48 -04:00
Andreas Kling
5118a4c1e7 LibWeb: Parse CSS "font-variant" as part of "font"
This allows us to parse CSS "font" values that contain e.g "small-caps"
or "normal", as used on Acid3.
2022-03-23 14:54:21 +01:00
Sam Atkins
c0d3f1a5e4 LibWeb: Use CSS::Number for CalculatedStyleValue numbers 2022-03-22 15:47:36 +01:00
Sam Atkins
fe372cd073 LibWeb: Use CSS::Number for Token numeric values 2022-03-22 15:47:36 +01:00
Sam Atkins
0795b9f7bb LibWeb: Use floats instead of doubles for CSS numbers
Using doubles isn't necessary, and they make things slightly bigger and
slower, so let's use floats instead.
2022-03-22 15:47:36 +01:00
Sam Atkins
404a7cb63a LibGfx+LibWeb: Use floats not doubles to create HSL colors
There's really no reason to use doubles here, except at the time I
wanted to use doubles everywhere in CSS. I now realize that is
excessive, so everything can be floats instead.
2022-03-22 15:47:36 +01:00
Sam Atkins
75ec960495 LibWeb: Initialize PseudoClass/PseudoElement selectors in one go
There was no real benefit to creating the SimpleSelector early and then
modifying it, and doing so made this code harder to follow than it
needs to be.
2022-03-22 15:47:36 +01:00
Sam Atkins
c0db19f63c LibWeb: Use a Variant for SimpleSelector's contents
This reduces SimpleSelector's size from 112 bytes to 80 bytes. :^)
2022-03-22 15:47:36 +01:00
Simon Wanner
dc94879b83 LibWeb: Support transform: translate(...) by percentage 2022-03-22 02:06:21 +01:00
Simon Wanner
63055ff5ad LibWeb: Parse the CSS transform-origin property
This is almost a PositionStyleValue, but it's serialized differently,
so let's use a StyleValueList with 2 length-percentage values.
2022-03-22 02:06:21 +01:00
Andreas Kling
1206dd2215 LibWeb: Make parse_html_length() accept floating point numbers
This makes stuff like <img width="12.5"> work. This code is not great,
so I've left a FIXME about improving it.
2022-03-21 15:58:21 +01:00
Hendiadyoin1
fff12847d5 LibWeb: Pull out larger parsing parts from Parser::parse_simple_selector
This lowers its cognitive complexity from 271 to under 100.
The new `parse_pseudo_simple_selector` still has a complexity of 114.
2022-03-21 12:49:00 +01:00
Hendiadyoin1
397d8b4aca LibWeb: Use a switch-statement on the delimiter for MatchType selection
... in Parser::parse_simple_selector
2022-03-21 12:49:00 +01:00
Hendiadyoin1
19cca57f8a LibWeb: Condense Delim checks in Parser::parse_simple_selector
This also removes some else-after-returns and adds some const qualifiers
2022-03-21 12:49:00 +01:00
Hendiadyoin1
3f8347718c LibWeb: Use a u32 for a delim tokens value
The spec says:
> <delim-token> has a value composed of a single code point.

So using StringView is a bit overkill.
This also allows us to use switch statements in the future.
2022-03-21 12:49:00 +01:00
Sam Atkins
d60b3be29a LibWeb: Implement the :focus-within selector
This matches if it has focus, or any nodes inside it do.
2022-03-20 17:35:31 +00:00
Andreas Kling
bdd42c9b0e LibWeb: Add basic support for :lang() CSS selector
This doesn't have parsing support for multiple languages in the same
selector. Support for language subcodes is not great either. But it
does do the basics.
2022-03-20 13:36:45 +01:00
Simon Wanner
c4f46893f6 LibWeb: Add parsing support for the remaining transform functions 2022-03-18 18:51:42 +01:00
Sam Atkins
174a25db5b LibWeb: Combine identical relative/regular selector parsing functions 2022-03-18 11:34:02 +01:00
Sam Atkins
5b0187477b LibWeb: Implement :nth-[last-]child(n of foo) syntax
In Selectors level 4, `:nth-child()` and `:nth-last-child()` can both
optionally take a selector-list argument. This selector-list acts as a
filter, so that only elements matching the list are counted. For
example, this means that the following are equivalent:

```css
:nth-child(2n+1 of p) {}
p:nth-of-type(2n+1) {}
```
2022-03-18 11:34:02 +01:00
Sam Atkins
993653317c LibWeb: Implement the :where() selector
This is identical to :is() except for specificity, so we can use the
same code paths. :^)
2022-03-18 11:34:02 +01:00
Sam Atkins
c148ed50bb LibWeb: Implement the :is() selector
This lets us finally get rid of a FIXME in the default style sheet. :^)
2022-03-18 11:34:02 +01:00
Sam Atkins
5319e2ba8e LibWeb: Parse forgiving selector-lists
`<forgiving-selector-list>` and `<forgiving-relative-selector-list>` are
the same as regular selector-lists, except that an invalid selector
does not make the whole list invalid. The former is used by the `:is()`
pseudo-class.

For example:

```css
/* This entire selector-list is invalid */
.foo, .bar, !?invalid { }

/* This is valid, but the "!?invalid" selector is removed */
:is(.foo, .bar, !?invalid) { }
```

Also as part of this, I've removed the `parse_a_selector(TokenStream)`
and `parse_a_relative_selector(TokenStream)` methods as they don't add
anything useful.
2022-03-18 11:34:02 +01:00
Lenny Maiorani
c37820b898 Libraries: Use default constructors/destructors in LibWeb
https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#cother-other-default-operation-rules

"The compiler is more likely to get the default semantics right and
you cannot implement these functions better than the compiler."
2022-03-17 17:23:49 +00:00
Simon Wanner
1ed5e79478 LibWeb: Fix resolving relative URLs in style sheets
Relative URLs in style sheets should be resolved relative to the
style sheet they're in instead of the document.
2022-03-14 22:22:53 +01:00
Sam Atkins
1c18bb13a2 LibWeb: Move pseudo-element-from-string code into Selector 2022-03-10 17:30:09 +01:00
Sam Atkins
56a36da44e LibWeb: Only try parsing valid types of media-feature values
This resolves the ambiguity between whether a single number is a number
or a ratio. :^)

Also removed the "no more tokens" checks from
deea129b8c - that logic was completely
wrong, since there are always tokens after a value in the `(123 < foo <
456)` syntax.
2022-03-09 23:06:30 +01:00
Sam Atkins
fd47460141 LibWeb: Use ValueID for media-query identifiers 2022-03-09 23:06:30 +01:00