mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 16:57:46 +00:00
LibWeb: Add CustomIdentStyleValue, along with parsing for it
This corresponds to the `<custom-ident>` type in CSS grammar.
This commit is contained in:
parent
b76219f702
commit
f6fae315e3
6 changed files with 61 additions and 2 deletions
|
@ -41,6 +41,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
|
@ -7205,7 +7206,11 @@ ErrorOr<Parser::PropertyAndValue> Parser::parse_css_value_for_properties(Readonl
|
|||
}
|
||||
}
|
||||
|
||||
// FIXME: Custom idents. https://www.w3.org/TR/css-values-4/#identifier-value
|
||||
// Custom idents
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::CustomIdent); property.has_value()) {
|
||||
(void)tokens.next_token();
|
||||
return PropertyAndValue { *property, TRY(CustomIdentStyleValue::create(TRY(FlyString::from_utf8(peek_token.token().ident())))) };
|
||||
}
|
||||
}
|
||||
|
||||
if (auto property = any_property_accepts_type(property_ids, ValueType::Color); property.has_value()) {
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||
|
@ -143,6 +144,12 @@ ContentStyleValue const& StyleValue::as_content() const
|
|||
return static_cast<ContentStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
CustomIdentStyleValue const& StyleValue::as_custom_ident() const
|
||||
{
|
||||
VERIFY(is_custom_ident());
|
||||
return static_cast<CustomIdentStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
DisplayStyleValue const& StyleValue::as_display() const
|
||||
{
|
||||
VERIFY(is_display());
|
||||
|
|
|
@ -98,6 +98,7 @@ public:
|
|||
Color,
|
||||
ConicGradient,
|
||||
Content,
|
||||
CustomIdent,
|
||||
Display,
|
||||
Edge,
|
||||
FilterValueList,
|
||||
|
@ -150,6 +151,7 @@ public:
|
|||
bool is_color() const { return type() == Type::Color; }
|
||||
bool is_conic_gradient() const { return type() == Type::ConicGradient; }
|
||||
bool is_content() const { return type() == Type::Content; }
|
||||
bool is_custom_ident() const { return type() == Type::CustomIdent; }
|
||||
bool is_display() const { return type() == Type::Display; }
|
||||
bool is_edge() const { return type() == Type::Edge; }
|
||||
bool is_filter_value_list() const { return type() == Type::FilterValueList; }
|
||||
|
@ -201,6 +203,7 @@ public:
|
|||
ColorStyleValue const& as_color() const;
|
||||
ConicGradientStyleValue const& as_conic_gradient() const;
|
||||
ContentStyleValue const& as_content() const;
|
||||
CustomIdentStyleValue const& as_custom_ident() const;
|
||||
DisplayStyleValue const& as_display() const;
|
||||
EdgeStyleValue const& as_edge() const;
|
||||
FilterValueListStyleValue const& as_filter_value_list() const;
|
||||
|
@ -250,6 +253,7 @@ public:
|
|||
ColorStyleValue& as_color() { return const_cast<ColorStyleValue&>(const_cast<StyleValue const&>(*this).as_color()); }
|
||||
ConicGradientStyleValue& as_conic_gradient() { return const_cast<ConicGradientStyleValue&>(const_cast<StyleValue const&>(*this).as_conic_gradient()); }
|
||||
ContentStyleValue& as_content() { return const_cast<ContentStyleValue&>(const_cast<StyleValue const&>(*this).as_content()); }
|
||||
CustomIdentStyleValue& as_custom_ident() { return const_cast<CustomIdentStyleValue&>(const_cast<StyleValue const&>(*this).as_custom_ident()); }
|
||||
DisplayStyleValue& as_display() { return const_cast<DisplayStyleValue&>(const_cast<StyleValue const&>(*this).as_display()); }
|
||||
EdgeStyleValue& as_edge() { return const_cast<EdgeStyleValue&>(const_cast<StyleValue const&>(*this).as_edge()); }
|
||||
FilterValueListStyleValue& as_filter_value_list() { return const_cast<FilterValueListStyleValue&>(const_cast<StyleValue const&>(*this).as_filter_value_list()); }
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
// https://www.w3.org/TR/css-values-4/#custom-idents
|
||||
class CustomIdentStyleValue final : public StyleValueWithDefaultOperators<CustomIdentStyleValue> {
|
||||
public:
|
||||
static ErrorOr<ValueComparingNonnullRefPtr<CustomIdentStyleValue>> create(FlyString custom_ident)
|
||||
{
|
||||
return adopt_nonnull_ref_or_enomem(new (nothrow) CustomIdentStyleValue(move(custom_ident)));
|
||||
}
|
||||
virtual ~CustomIdentStyleValue() override = default;
|
||||
|
||||
FlyString const& custom_ident() const { return m_custom_ident; }
|
||||
|
||||
virtual ErrorOr<String> to_string() const override { return m_custom_ident.to_string(); }
|
||||
|
||||
bool properties_equal(CustomIdentStyleValue const& other) const { return m_custom_ident == other.m_custom_ident; }
|
||||
|
||||
private:
|
||||
explicit CustomIdentStyleValue(FlyString custom_ident)
|
||||
: StyleValueWithDefaultOperators(Type::CustomIdent)
|
||||
, m_custom_ident(move(custom_ident))
|
||||
{
|
||||
}
|
||||
|
||||
FlyString m_custom_ident;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue