1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:17:44 +00:00

LibWeb: Implement CSS parsing convenience functions

These mostly match the API in `DeprecatedCSSParser.h`. The exception is
that `parse_selector()` returns a `SelectorList` instead of just one
`Selector`. The only uses of that are in
`ParentNode::query_selector[_all]()` which should be matching against a
list, according to the spec.

`parse_html_length()` is an odd case. It's used for `width="200"` cases
in HTML, so is not really CSS related, but does produce a StyleValue.
The values allowed in `width/height` in HTML vary per element, but they
are a lot more restricted than in CSS, so it's slightly inappropriate to
use the CSS parser for them, even though it's convenient.

We also ignore a few functions:

- `parse_line_width()`
- `parse_line_style()`
- `parse_color()`

These are all only used in `StyleResolver`, when it is given a property
value as a String. That won't happen once the old parser is removed.
This commit is contained in:
Sam Atkins 2021-07-30 17:48:23 +01:00 committed by Ali Mohammad Pur
parent eadcdd21e3
commit 4065eb169c
2 changed files with 63 additions and 0 deletions

View file

@ -93,6 +93,8 @@ public:
Optional<SelectorList> parse_as_selector();
Optional<SelectorList> parse_as_relative_selector();
RefPtr<StyleValue> parse_as_css_value(PropertyID);
// FIXME: These want to be private, but StyleResolver still uses them for now.
RefPtr<StyleValue> parse_css_value(PropertyID, TokenStream<StyleComponentValueRule>&);
static RefPtr<StyleValue> parse_css_value(ParsingContext const&, PropertyID, StyleComponentValueRule const&);
@ -206,3 +208,14 @@ private:
};
}
namespace Web {
RefPtr<CSS::CSSStyleSheet> parse_css(CSS::ParsingContext const&, StringView const&);
RefPtr<CSS::CSSStyleDeclaration> parse_css_declaration(CSS::ParsingContext const&, StringView const&);
RefPtr<CSS::StyleValue> parse_css_value(CSS::ParsingContext const&, StringView const&, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
Optional<CSS::SelectorList> parse_selector(CSS::ParsingContext const&, StringView const&);
RefPtr<CSS::StyleValue> parse_html_length(DOM::Document const&, StringView const&);
}