LibWeb/CSS: Implement @supports font-format() and font-tech()

These let authors query whether we support font formats and features.
This commit is contained in:
Sam Atkins 2025-03-14 11:36:15 +00:00
commit b6fb4baeb7
Notes: github-actions[bot] 2025-03-17 10:01:17 +00:00
6 changed files with 242 additions and 2 deletions

View file

@ -6,6 +6,7 @@
#pragma once
#include <AK/FlyString.h>
#include <AK/NonnullOwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
@ -60,6 +61,50 @@ public:
bool m_matches;
};
class FontTech final : public BooleanExpression {
public:
static NonnullOwnPtr<FontTech> create(FlyString tech, bool matches)
{
return adopt_own(*new FontTech(move(tech), matches));
}
virtual ~FontTech() override = default;
virtual MatchResult evaluate(HTML::Window const*) const override;
virtual String to_string() const override;
virtual void dump(StringBuilder&, int indent_levels = 0) const override;
private:
FontTech(FlyString tech, bool matches)
: m_tech(move(tech))
, m_matches(matches)
{
}
FlyString m_tech;
bool m_matches;
};
class FontFormat final : public BooleanExpression {
public:
static NonnullOwnPtr<FontFormat> create(FlyString format, bool matches)
{
return adopt_own(*new FontFormat(move(format), matches));
}
virtual ~FontFormat() override = default;
virtual MatchResult evaluate(HTML::Window const*) const override;
virtual String to_string() const override;
virtual void dump(StringBuilder&, int indent_levels = 0) const override;
private:
FontFormat(FlyString format, bool matches)
: m_format(move(format))
, m_matches(matches)
{
}
FlyString m_format;
bool m_matches;
};
static NonnullRefPtr<Supports> create(NonnullOwnPtr<BooleanExpression>&& condition)
{
return adopt_ref(*new Supports(move(condition)));