mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:37:34 +00:00
LibWeb: Implement @supports
serialization
This commit is contained in:
parent
1cec8e473f
commit
dfba0cb2d9
3 changed files with 55 additions and 2 deletions
|
@ -17,8 +17,7 @@ CSSSupportsRule::CSSSupportsRule(NonnullRefPtr<Supports>&& supports, NonnullRefP
|
|||
|
||||
String CSSSupportsRule::condition_text() const
|
||||
{
|
||||
// FIXME: Serializing supports rules!
|
||||
return "<supports-condition>";
|
||||
return m_supports->to_string();
|
||||
}
|
||||
|
||||
void CSSSupportsRule::set_condition_text(String text)
|
||||
|
|
|
@ -73,4 +73,44 @@ bool Supports::Feature::evaluate() const
|
|||
});
|
||||
}
|
||||
|
||||
String Supports::Declaration::to_string() const
|
||||
{
|
||||
return String::formatted("({})", declaration);
|
||||
}
|
||||
|
||||
String Supports::Selector::to_string() const
|
||||
{
|
||||
return String::formatted("selector({})", selector);
|
||||
}
|
||||
|
||||
String Supports::Feature::to_string() const
|
||||
{
|
||||
return value.visit([](auto& it) { return it.to_string(); });
|
||||
}
|
||||
|
||||
String Supports::InParens::to_string() const
|
||||
{
|
||||
return value.visit(
|
||||
[](NonnullOwnPtr<Condition> const& condition) -> String { return String::formatted("({})", condition->to_string()); },
|
||||
[](auto& it) -> String { return it.to_string(); });
|
||||
}
|
||||
|
||||
String Supports::Condition::to_string() const
|
||||
{
|
||||
switch (type) {
|
||||
case Type::Not:
|
||||
return String::formatted("not {}", children.first().to_string());
|
||||
case Type::And:
|
||||
return String::join(" and ", children);
|
||||
case Type::Or:
|
||||
return String::join(" or ", children);
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
String Supports::to_string() const
|
||||
{
|
||||
return m_condition->to_string();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,16 +24,19 @@ public:
|
|||
struct Declaration {
|
||||
String declaration;
|
||||
bool evaluate() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Selector {
|
||||
String selector;
|
||||
bool evaluate() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Feature {
|
||||
Variant<Declaration, Selector> value;
|
||||
bool evaluate() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Condition;
|
||||
|
@ -41,6 +44,7 @@ public:
|
|||
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
||||
|
||||
bool evaluate() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
struct Condition {
|
||||
|
@ -53,6 +57,7 @@ public:
|
|||
Vector<InParens> children;
|
||||
|
||||
bool evaluate() const;
|
||||
String to_string() const;
|
||||
};
|
||||
|
||||
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
||||
|
@ -61,6 +66,7 @@ public:
|
|||
}
|
||||
|
||||
bool matches() const { return m_matches; }
|
||||
String to_string() const;
|
||||
|
||||
private:
|
||||
Supports(NonnullOwnPtr<Condition>&&);
|
||||
|
@ -70,3 +76,11 @@ private:
|
|||
};
|
||||
|
||||
}
|
||||
|
||||
template<>
|
||||
struct AK::Formatter<Web::CSS::Supports::InParens> : AK::Formatter<StringView> {
|
||||
ErrorOr<void> format(FormatBuilder& builder, Web::CSS::Supports::InParens const& in_parens)
|
||||
{
|
||||
return Formatter<StringView>::format(builder, in_parens.to_string());
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue