mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 20:37:34 +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
|
@ -17,7 +17,7 @@ ErrorOr<void> generate_implementation_file(JsonObject& properties, Core::File& f
|
||||||
|
|
||||||
static bool type_name_is_enum(StringView type_name)
|
static bool type_name_is_enum(StringView type_name)
|
||||||
{
|
{
|
||||||
return !AK::first_is_one_of(type_name, "angle"sv, "color"sv, "frequency"sv, "image"sv, "integer"sv, "length"sv, "number"sv, "percentage"sv, "rect"sv, "resolution"sv, "string"sv, "time"sv, "url"sv);
|
return !AK::first_is_one_of(type_name, "angle"sv, "color"sv, "custom-ident"sv, "frequency"sv, "image"sv, "integer"sv, "length"sv, "number"sv, "percentage"sv, "rect"sv, "resolution"sv, "string"sv, "time"sv, "url"sv);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||||
|
@ -118,6 +118,7 @@ ErrorOr<NonnullRefPtr<StyleValue>> property_initial_value(JS::Realm&, PropertyID
|
||||||
enum class ValueType {
|
enum class ValueType {
|
||||||
Angle,
|
Angle,
|
||||||
Color,
|
Color,
|
||||||
|
CustomIdent,
|
||||||
FilterValueList,
|
FilterValueList,
|
||||||
Frequency,
|
Frequency,
|
||||||
Image,
|
Image,
|
||||||
|
@ -455,6 +456,8 @@ bool property_accepts_type(PropertyID property_id, ValueType value_type)
|
||||||
property_generator.appendln(" case ValueType::Angle:");
|
property_generator.appendln(" case ValueType::Angle:");
|
||||||
} else if (type_name == "color") {
|
} else if (type_name == "color") {
|
||||||
property_generator.appendln(" case ValueType::Color:");
|
property_generator.appendln(" case ValueType::Color:");
|
||||||
|
} else if (type_name == "custom-ident") {
|
||||||
|
property_generator.appendln(" case ValueType::CustomIdent:");
|
||||||
} else if (type_name == "frequency") {
|
} else if (type_name == "frequency") {
|
||||||
property_generator.appendln(" case ValueType::Frequency:");
|
property_generator.appendln(" case ValueType::Frequency:");
|
||||||
} else if (type_name == "image") {
|
} else if (type_name == "image") {
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ColorStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.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()) {
|
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/ColorStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ConicGradientStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/ContentStyleValue.h>
|
||||||
|
#include <LibWeb/CSS/StyleValues/CustomIdentStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/DisplayStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/EdgeStyleValue.h>
|
||||||
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
#include <LibWeb/CSS/StyleValues/FilterValueListStyleValue.h>
|
||||||
|
@ -143,6 +144,12 @@ ContentStyleValue const& StyleValue::as_content() const
|
||||||
return static_cast<ContentStyleValue const&>(*this);
|
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
|
DisplayStyleValue const& StyleValue::as_display() const
|
||||||
{
|
{
|
||||||
VERIFY(is_display());
|
VERIFY(is_display());
|
||||||
|
|
|
@ -98,6 +98,7 @@ public:
|
||||||
Color,
|
Color,
|
||||||
ConicGradient,
|
ConicGradient,
|
||||||
Content,
|
Content,
|
||||||
|
CustomIdent,
|
||||||
Display,
|
Display,
|
||||||
Edge,
|
Edge,
|
||||||
FilterValueList,
|
FilterValueList,
|
||||||
|
@ -150,6 +151,7 @@ public:
|
||||||
bool is_color() const { return type() == Type::Color; }
|
bool is_color() const { return type() == Type::Color; }
|
||||||
bool is_conic_gradient() const { return type() == Type::ConicGradient; }
|
bool is_conic_gradient() const { return type() == Type::ConicGradient; }
|
||||||
bool is_content() const { return type() == Type::Content; }
|
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_display() const { return type() == Type::Display; }
|
||||||
bool is_edge() const { return type() == Type::Edge; }
|
bool is_edge() const { return type() == Type::Edge; }
|
||||||
bool is_filter_value_list() const { return type() == Type::FilterValueList; }
|
bool is_filter_value_list() const { return type() == Type::FilterValueList; }
|
||||||
|
@ -201,6 +203,7 @@ public:
|
||||||
ColorStyleValue const& as_color() const;
|
ColorStyleValue const& as_color() const;
|
||||||
ConicGradientStyleValue const& as_conic_gradient() const;
|
ConicGradientStyleValue const& as_conic_gradient() const;
|
||||||
ContentStyleValue const& as_content() const;
|
ContentStyleValue const& as_content() const;
|
||||||
|
CustomIdentStyleValue const& as_custom_ident() const;
|
||||||
DisplayStyleValue const& as_display() const;
|
DisplayStyleValue const& as_display() const;
|
||||||
EdgeStyleValue const& as_edge() const;
|
EdgeStyleValue const& as_edge() const;
|
||||||
FilterValueListStyleValue const& as_filter_value_list() 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()); }
|
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()); }
|
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()); }
|
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()); }
|
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()); }
|
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()); }
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -84,6 +84,7 @@ class CSSStyleDeclaration;
|
||||||
class CSSStyleRule;
|
class CSSStyleRule;
|
||||||
class CSSStyleSheet;
|
class CSSStyleSheet;
|
||||||
class CSSSupportsRule;
|
class CSSSupportsRule;
|
||||||
|
class CustomIdentStyleValue;
|
||||||
class Display;
|
class Display;
|
||||||
class DisplayStyleValue;
|
class DisplayStyleValue;
|
||||||
class EdgeStyleValue;
|
class EdgeStyleValue;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue