mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:17:35 +00:00
LibWeb: Move CSS Parser into new Web::CSS::Parser namespace
The goal here is to move the parser-internal classes into this namespace so they can have more convenient names without causing collisions. The Parser itself won't collide, and would be more convenient to just remain `CSS::Parser`, but having a namespace and a class with the same name makes C++ unhappy.
This commit is contained in:
parent
1304bf5a21
commit
c449cabae3
23 changed files with 61 additions and 58 deletions
|
@ -73,7 +73,7 @@ void CSSImportRule::resource_did_load()
|
|||
dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Resource did load, has encoded data. URL: {}", resource()->url());
|
||||
}
|
||||
|
||||
auto sheet = parse_css_stylesheet(CSS::ParsingContext(*m_document, resource()->url()), resource()->encoded_data());
|
||||
auto sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(*m_document, resource()->url()), resource()->encoded_data());
|
||||
if (!sheet) {
|
||||
dbgln_if(CSS_LOADER_DEBUG, "CSSImportRule: Failed to parse stylesheet: {}", resource()->url());
|
||||
return;
|
||||
|
|
|
@ -65,7 +65,7 @@ DOM::ExceptionOr<void> PropertyOwningCSSStyleDeclaration::set_property(PropertyI
|
|||
return {};
|
||||
|
||||
// 5. Let component value list be the result of parsing value for property property.
|
||||
auto component_value_list = parse_css_value(CSS::ParsingContext {}, value, property_id);
|
||||
auto component_value_list = parse_css_value(CSS::Parser::ParsingContext {}, value, property_id);
|
||||
|
||||
// 6. If component value list is null, then return.
|
||||
if (!component_value_list)
|
||||
|
|
|
@ -27,7 +27,7 @@ DOM::ExceptionOr<unsigned> CSSStyleSheet::insert_rule(StringView rule, unsigned
|
|||
// FIXME: 2. If the disallow modification flag is set, throw a NotAllowedError DOMException.
|
||||
|
||||
// 3. Let parsed rule be the return value of invoking parse a rule with rule.
|
||||
auto parsed_rule = parse_css_rule(CSS::ParsingContext {}, rule);
|
||||
auto parsed_rule = parse_css_rule(CSS::Parser::ParsingContext {}, rule);
|
||||
|
||||
// 4. If parsed rule is a syntax error, return parsed rule.
|
||||
if (!parsed_rule)
|
||||
|
|
|
@ -213,7 +213,7 @@ private:
|
|||
};
|
||||
|
||||
class MediaQuery : public RefCounted<MediaQuery> {
|
||||
friend class Parser;
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
~MediaQuery() = default;
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
namespace Web::CSS {
|
||||
|
||||
class Declaration {
|
||||
friend class Parser;
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
Declaration();
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
namespace Web::CSS {
|
||||
|
||||
class DeclarationOrAtRule {
|
||||
friend class Parser;
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
explicit DeclarationOrAtRule(RefPtr<StyleRule> at);
|
||||
|
|
|
@ -34,7 +34,7 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur
|
|||
dbgln_if(CSS_PARSER_DEBUG, "Parse error (CSS) {}", location);
|
||||
}
|
||||
|
||||
namespace Web::CSS {
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
ParsingContext::ParsingContext(DOM::Document const& document, Optional<AK::URL> const url)
|
||||
: m_document(&document)
|
||||
|
@ -5741,8 +5741,8 @@ RefPtr<StyleValue> Parser::parse_css_value(Badge<StyleComputer>, ParsingContext
|
|||
if (tokens.is_empty() || property_id == CSS::PropertyID::Invalid || property_id == CSS::PropertyID::Custom)
|
||||
return {};
|
||||
|
||||
CSS::Parser parser(context, "");
|
||||
CSS::TokenStream<CSS::ComponentValue> token_stream { tokens };
|
||||
Parser parser(context, "");
|
||||
TokenStream<ComponentValue> token_stream { tokens };
|
||||
auto result = parser.parse_css_value(property_id, token_stream);
|
||||
if (result.is_error())
|
||||
return {};
|
||||
|
@ -5868,59 +5868,59 @@ TimePercentage Parser::Dimension::time_percentage() const
|
|||
|
||||
namespace Web {
|
||||
|
||||
RefPtr<CSS::CSSStyleSheet> parse_css_stylesheet(CSS::ParsingContext const& context, StringView css, Optional<AK::URL> location)
|
||||
RefPtr<CSS::CSSStyleSheet> parse_css_stylesheet(CSS::Parser::ParsingContext const& context, StringView css, Optional<AK::URL> location)
|
||||
{
|
||||
if (css.is_empty())
|
||||
return CSS::CSSStyleSheet::create({}, location);
|
||||
CSS::Parser parser(context, css);
|
||||
CSS::Parser::Parser parser(context, css);
|
||||
return parser.parse_as_css_stylesheet(location);
|
||||
}
|
||||
|
||||
RefPtr<CSS::ElementInlineCSSStyleDeclaration> parse_css_style_attribute(CSS::ParsingContext const& context, StringView css, DOM::Element& element)
|
||||
RefPtr<CSS::ElementInlineCSSStyleDeclaration> parse_css_style_attribute(CSS::Parser::ParsingContext const& context, StringView css, DOM::Element& element)
|
||||
{
|
||||
if (css.is_empty())
|
||||
return CSS::ElementInlineCSSStyleDeclaration::create(element, {}, {});
|
||||
CSS::Parser parser(context, css);
|
||||
CSS::Parser::Parser parser(context, css);
|
||||
return parser.parse_as_style_attribute(element);
|
||||
}
|
||||
|
||||
RefPtr<CSS::StyleValue> parse_css_value(CSS::ParsingContext const& context, StringView string, CSS::PropertyID property_id)
|
||||
RefPtr<CSS::StyleValue> parse_css_value(CSS::Parser::ParsingContext const& context, StringView string, CSS::PropertyID property_id)
|
||||
{
|
||||
if (string.is_empty())
|
||||
return {};
|
||||
CSS::Parser parser(context, string);
|
||||
CSS::Parser::Parser parser(context, string);
|
||||
return parser.parse_as_css_value(property_id);
|
||||
}
|
||||
|
||||
RefPtr<CSS::CSSRule> parse_css_rule(CSS::ParsingContext const& context, StringView css_text)
|
||||
RefPtr<CSS::CSSRule> parse_css_rule(CSS::Parser::ParsingContext const& context, StringView css_text)
|
||||
{
|
||||
CSS::Parser parser(context, css_text);
|
||||
CSS::Parser::Parser parser(context, css_text);
|
||||
return parser.parse_as_css_rule();
|
||||
}
|
||||
|
||||
Optional<CSS::SelectorList> parse_selector(CSS::ParsingContext const& context, StringView selector_text)
|
||||
Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingContext const& context, StringView selector_text)
|
||||
{
|
||||
CSS::Parser parser(context, selector_text);
|
||||
CSS::Parser::Parser parser(context, selector_text);
|
||||
return parser.parse_as_selector();
|
||||
}
|
||||
|
||||
RefPtr<CSS::MediaQuery> parse_media_query(CSS::ParsingContext const& context, StringView string)
|
||||
RefPtr<CSS::MediaQuery> parse_media_query(CSS::Parser::ParsingContext const& context, StringView string)
|
||||
{
|
||||
CSS::Parser parser(context, string);
|
||||
CSS::Parser::Parser parser(context, string);
|
||||
return parser.parse_as_media_query();
|
||||
}
|
||||
|
||||
NonnullRefPtrVector<CSS::MediaQuery> parse_media_query_list(CSS::ParsingContext const& context, StringView string)
|
||||
NonnullRefPtrVector<CSS::MediaQuery> parse_media_query_list(CSS::Parser::ParsingContext const& context, StringView string)
|
||||
{
|
||||
CSS::Parser parser(context, string);
|
||||
CSS::Parser::Parser parser(context, string);
|
||||
return parser.parse_as_media_query_list();
|
||||
}
|
||||
|
||||
RefPtr<CSS::Supports> parse_css_supports(CSS::ParsingContext const& context, StringView string)
|
||||
RefPtr<CSS::Supports> parse_css_supports(CSS::Parser::ParsingContext const& context, StringView string)
|
||||
{
|
||||
if (string.is_empty())
|
||||
return {};
|
||||
CSS::Parser parser(context, string);
|
||||
CSS::Parser::Parser parser(context, string);
|
||||
return parser.parse_as_supports();
|
||||
}
|
||||
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#include <LibWeb/CSS/UnicodeRange.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
class ParsingContext {
|
||||
public:
|
||||
|
@ -375,13 +375,13 @@ private:
|
|||
|
||||
namespace Web {
|
||||
|
||||
RefPtr<CSS::CSSStyleSheet> parse_css_stylesheet(CSS::ParsingContext const&, StringView, Optional<AK::URL> location = {});
|
||||
RefPtr<CSS::ElementInlineCSSStyleDeclaration> parse_css_style_attribute(CSS::ParsingContext const&, StringView, DOM::Element&);
|
||||
RefPtr<CSS::StyleValue> parse_css_value(CSS::ParsingContext const&, StringView, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
|
||||
Optional<CSS::SelectorList> parse_selector(CSS::ParsingContext const&, StringView);
|
||||
RefPtr<CSS::CSSRule> parse_css_rule(CSS::ParsingContext const&, StringView);
|
||||
RefPtr<CSS::MediaQuery> parse_media_query(CSS::ParsingContext const&, StringView);
|
||||
NonnullRefPtrVector<CSS::MediaQuery> parse_media_query_list(CSS::ParsingContext const&, StringView);
|
||||
RefPtr<CSS::Supports> parse_css_supports(CSS::ParsingContext const&, StringView);
|
||||
RefPtr<CSS::CSSStyleSheet> parse_css_stylesheet(CSS::Parser::ParsingContext const&, StringView, Optional<AK::URL> location = {});
|
||||
RefPtr<CSS::ElementInlineCSSStyleDeclaration> parse_css_style_attribute(CSS::Parser::ParsingContext const&, StringView, DOM::Element&);
|
||||
RefPtr<CSS::StyleValue> parse_css_value(CSS::Parser::ParsingContext const&, StringView, CSS::PropertyID property_id = CSS::PropertyID::Invalid);
|
||||
Optional<CSS::SelectorList> parse_selector(CSS::Parser::ParsingContext const&, StringView);
|
||||
RefPtr<CSS::CSSRule> parse_css_rule(CSS::Parser::ParsingContext const&, StringView);
|
||||
RefPtr<CSS::MediaQuery> parse_media_query(CSS::Parser::ParsingContext const&, StringView);
|
||||
NonnullRefPtrVector<CSS::MediaQuery> parse_media_query_list(CSS::Parser::ParsingContext const&, StringView);
|
||||
RefPtr<CSS::Supports> parse_css_supports(CSS::Parser::ParsingContext const&, StringView);
|
||||
|
||||
}
|
||||
|
|
|
@ -11,11 +11,12 @@
|
|||
#include <AK/Vector.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/CSS/Parser/Token.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class StyleBlockRule : public RefCounted<StyleBlockRule> {
|
||||
friend class Parser;
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
StyleBlockRule();
|
||||
|
|
|
@ -11,13 +11,12 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
#include <LibWeb/CSS/Parser/ComponentValue.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class ComponentValue;
|
||||
|
||||
class StyleFunctionRule : public RefCounted<StyleFunctionRule> {
|
||||
friend class Parser;
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
explicit StyleFunctionRule(String name);
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
namespace Web::CSS {
|
||||
|
||||
class StyleRule : public RefCounted<StyleRule> {
|
||||
friend class Parser;
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
enum class Type {
|
||||
|
|
|
@ -114,7 +114,7 @@ static StyleSheet& default_stylesheet()
|
|||
if (!sheet) {
|
||||
extern char const default_stylesheet_source[];
|
||||
String css = default_stylesheet_source;
|
||||
sheet = parse_css_stylesheet(CSS::ParsingContext(), css).leak_ref();
|
||||
sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(), css).leak_ref();
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ static StyleSheet& quirks_mode_stylesheet()
|
|||
if (!sheet) {
|
||||
extern char const quirks_mode_stylesheet_source[];
|
||||
String css = quirks_mode_stylesheet_source;
|
||||
sheet = parse_css_stylesheet(CSS::ParsingContext(), css).leak_ref();
|
||||
sheet = parse_css_stylesheet(CSS::Parser::ParsingContext(), css).leak_ref();
|
||||
}
|
||||
return *sheet;
|
||||
}
|
||||
|
@ -652,7 +652,7 @@ RefPtr<StyleValue> StyleComputer::resolve_unresolved_style_value(DOM::Element& e
|
|||
if (!expand_unresolved_values(element, string_from_property_id(property_id), dependencies, unresolved.values(), expanded_values, 0))
|
||||
return {};
|
||||
|
||||
if (auto parsed_value = Parser::parse_css_value({}, ParsingContext { document() }, property_id, expanded_values))
|
||||
if (auto parsed_value = Parser::Parser::parse_css_value({}, Parser::ParsingContext { document() }, property_id, expanded_values))
|
||||
return parsed_value.release_nonnull();
|
||||
|
||||
return {};
|
||||
|
|
|
@ -52,13 +52,13 @@ bool Supports::InParens::evaluate() const
|
|||
|
||||
bool Supports::Declaration::evaluate() const
|
||||
{
|
||||
auto style_property = Parser({}, declaration).parse_as_supports_condition();
|
||||
auto style_property = Parser::Parser({}, declaration).parse_as_supports_condition();
|
||||
return style_property.has_value();
|
||||
}
|
||||
|
||||
bool Supports::Selector::evaluate() const
|
||||
{
|
||||
auto style_property = Parser({}, selector).parse_as_selector();
|
||||
auto style_property = Parser::Parser({}, selector).parse_as_selector();
|
||||
return style_property.has_value();
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Web::CSS {
|
|||
|
||||
// https://www.w3.org/TR/css-conditional-4/#at-supports
|
||||
class Supports final : public RefCounted<Supports> {
|
||||
friend class Parser;
|
||||
friend class Parser::Parser;
|
||||
|
||||
public:
|
||||
struct Declaration {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue