mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +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
|
String CSSSupportsRule::condition_text() const
|
||||||
{
|
{
|
||||||
// FIXME: Serializing supports rules!
|
return m_supports->to_string();
|
||||||
return "<supports-condition>";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSSSupportsRule::set_condition_text(String text)
|
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 {
|
struct Declaration {
|
||||||
String declaration;
|
String declaration;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
|
String to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Selector {
|
struct Selector {
|
||||||
String selector;
|
String selector;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
|
String to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Feature {
|
struct Feature {
|
||||||
Variant<Declaration, Selector> value;
|
Variant<Declaration, Selector> value;
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
|
String to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Condition;
|
struct Condition;
|
||||||
|
@ -41,6 +44,7 @@ public:
|
||||||
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
|
||||||
|
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
|
String to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Condition {
|
struct Condition {
|
||||||
|
@ -53,6 +57,7 @@ public:
|
||||||
Vector<InParens> children;
|
Vector<InParens> children;
|
||||||
|
|
||||||
bool evaluate() const;
|
bool evaluate() const;
|
||||||
|
String to_string() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
|
||||||
|
@ -61,6 +66,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
bool matches() const { return m_matches; }
|
bool matches() const { return m_matches; }
|
||||||
|
String to_string() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Supports(NonnullOwnPtr<Condition>&&);
|
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