mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-11-10 02:01:03 +00:00
For a long time, we've used two terms, inconsistently: - "Identifier" is a spec term, but refers to a sequence of alphanumeric characters, which may or may not be a keyword. (Keywords are a subset of all identifiers.) - "ValueID" is entirely non-spec, and is directly called a "keyword" in the CSS specs. So to avoid confusion as much as possible, let's align with the spec terminology. I've attempted to change variable names as well, but obviously we use Keywords in a lot of places in LibWeb and so I may have missed some. One exception is that I've not renamed "valid-identifiers" in Properties.json... I'd like to combine that and the "valid-types" array together eventually, so there's no benefit to doing an extra rename now.
45 lines
1.3 KiB
C++
45 lines
1.3 KiB
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
|
* Copyright (c) 2021-2024, Sam Atkins <sam@ladybird.org>
|
|
* Copyright (c) 2022-2023, MacDue <macdue@dueutil.tech>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/CSS/CSSStyleValue.h>
|
|
#include <LibWeb/CSS/Keyword.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
// https://drafts.css-houdini.org/css-typed-om-1/#csskeywordvalue
|
|
class CSSKeywordValue final : public StyleValueWithDefaultOperators<CSSKeywordValue> {
|
|
public:
|
|
static ValueComparingNonnullRefPtr<CSSKeywordValue> create(Keyword keyword)
|
|
{
|
|
return adopt_ref(*new (nothrow) CSSKeywordValue(keyword));
|
|
}
|
|
virtual ~CSSKeywordValue() override = default;
|
|
|
|
Keyword keyword() const { return m_keyword; }
|
|
|
|
static bool is_color(Keyword);
|
|
virtual bool has_color() const override;
|
|
virtual Color to_color(Optional<Layout::NodeWithStyle const&> node) const override;
|
|
virtual String to_string() const override;
|
|
|
|
bool properties_equal(CSSKeywordValue const& other) const { return m_keyword == other.m_keyword; }
|
|
|
|
private:
|
|
explicit CSSKeywordValue(Keyword keyword)
|
|
: StyleValueWithDefaultOperators(Type::Keyword)
|
|
, m_keyword(keyword)
|
|
{
|
|
}
|
|
|
|
Keyword m_keyword { Keyword::Invalid };
|
|
};
|
|
|
|
}
|