ladybird/Userland/Libraries/LibWeb/CSS/Supports.h
Sam Atkins dea4f83037 LibWeb: Use a string instead of an internal Parser class in Supports
Now that we can serialize CSS tokens, we can just hold a string and then
re-parse it when the Supports is evaluated. This feels a little weird,
but it only happens once so it's not going to slow it down much, and it
keep the API cleaner.
2021-11-24 22:57:46 +01:00

61 lines
1.2 KiB
C++

/*
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/NonnullOwnPtr.h>
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <AK/Variant.h>
#include <AK/Vector.h>
#include <LibWeb/CSS/GeneralEnclosed.h>
#include <LibWeb/CSS/Parser/StyleDeclarationRule.h>
namespace Web::CSS {
class Supports final : public RefCounted<Supports> {
friend class Parser;
public:
struct Feature {
String declaration;
MatchResult evaluate() const;
};
struct Condition;
struct InParens {
Variant<NonnullOwnPtr<Condition>, Feature, GeneralEnclosed> value;
MatchResult evaluate() const;
};
struct Condition {
enum class Type {
Not,
And,
Or,
};
Type type;
Vector<InParens> children;
MatchResult evaluate() const;
};
static NonnullRefPtr<Supports> create(NonnullOwnPtr<Condition>&& condition)
{
return adopt_ref(*new Supports(move(condition)));
}
bool matches() const { return m_matches; }
private:
Supports(NonnullOwnPtr<Condition>&&);
NonnullOwnPtr<Condition> m_condition;
bool m_matches { false };
};
}