Files
serenity/Userland/Libraries/LibWeb/CSS/StyleValues/CSSKeywordValue.h
Sam Atkins 0a3b33e6f6 LibWeb: Rename "identifier" and "ValueID" to "Keyword" where correct
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.

(cherry picked from commit 6a74b0164423d63904cf5a5b594772b595f57600;
very minorly amended to fix conflict in GenerateCSSKeyword.cpp caused
by #22870, and in libweb_generators.cmake due to us not having
https://github.com/LadybirdBrowser/ladybird/pull/741)
2024-10-10 10:08:59 -04:00

46 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 };
};
}