mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-05-04 18:23:39 +00:00
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.
61 lines
1.2 KiB
C++
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 };
|
|
};
|
|
|
|
}
|