1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:37:35 +00:00

LibWeb: Break friendship between CSS StyleRule and Parser

As before, this requires deviating from the spec slightly to create the
StyleRule fully-formed instead of creating it empty and then modifying
its internals.
This commit is contained in:
Sam Atkins 2022-04-12 17:03:14 +01:00 committed by Andreas Kling
parent 4bdfc2bb32
commit cf24dc2e0c
3 changed files with 36 additions and 21 deletions

View file

@ -16,15 +16,22 @@
namespace Web::CSS::Parser {
class StyleRule : public RefCounted<StyleRule> {
friend class Parser;
public:
enum class Type {
At,
Qualified,
};
StyleRule(Type);
static NonnullRefPtr<StyleRule> make_at_rule(FlyString name, Vector<ComponentValue> prelude, RefPtr<Block> block)
{
return adopt_ref(*new StyleRule(Type::At, move(name), move(prelude), move(block)));
}
static NonnullRefPtr<StyleRule> make_qualified_rule(Vector<ComponentValue> prelude, RefPtr<Block> block)
{
return adopt_ref(*new StyleRule(Type::Qualified, {}, move(prelude), move(block)));
}
~StyleRule();
bool is_qualified_rule() const { return m_type == Type::Qualified; }
@ -37,6 +44,8 @@ public:
String to_string() const;
private:
StyleRule(Type, FlyString name, Vector<ComponentValue> prelude, RefPtr<Block>);
Type const m_type;
FlyString m_at_rule_name;
Vector<ComponentValue> m_prelude;