diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 6f0a33e6506..a38e282817f 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -139,6 +139,7 @@ set(SOURCES CSS/StyleValues/LinearGradientStyleValue.cpp CSS/StyleValues/MathDepthStyleValue.cpp CSS/StyleValues/NumberStyleValue.cpp + CSS/StyleValues/OpenTypeTaggedStyleValue.cpp CSS/StyleValues/PositionStyleValue.cpp CSS/StyleValues/RadialGradientStyleValue.cpp CSS/StyleValues/RectStyleValue.cpp diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp index 547cfa2b121..2697d8814d5 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -244,6 +245,12 @@ NumberStyleValue const& CSSStyleValue::as_number() const return static_cast(*this); } +OpenTypeTaggedStyleValue const& CSSStyleValue::as_open_type_tagged() const +{ + VERIFY(is_open_type_tagged()); + return static_cast(*this); +} + PercentageStyleValue const& CSSStyleValue::as_percentage() const { VERIFY(is_percentage()); diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h index d79352a2d5d..3fae67215e8 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleValue.h @@ -117,6 +117,7 @@ public: Math, MathDepth, Number, + OpenTypeTagged, Percentage, Position, RadialGradient, @@ -260,6 +261,10 @@ public: NumberStyleValue const& as_number() const; NumberStyleValue& as_number() { return const_cast(const_cast(*this).as_number()); } + bool is_open_type_tagged() const { return type() == Type::OpenTypeTagged; } + OpenTypeTaggedStyleValue const& as_open_type_tagged() const; + OpenTypeTaggedStyleValue& as_open_type_tagged() { return const_cast(const_cast(*this).as_open_type_tagged()); } + bool is_percentage() const { return type() == Type::Percentage; } PercentageStyleValue const& as_percentage() const; PercentageStyleValue& as_percentage() { return const_cast(const_cast(*this).as_percentage()); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.cpp new file mode 100644 index 00000000000..be7d1b9c578 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.cpp @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include "OpenTypeTaggedStyleValue.h" +#include + +namespace Web::CSS { + +String OpenTypeTaggedStyleValue::to_string() const +{ + StringBuilder builder; + serialize_a_string(builder, m_tag); + // FIXME: For font-feature-settings, a 1 value is implicit, so we shouldn't output it. + builder.appendff(" {}", m_value->to_string()); + + return builder.to_string_without_validation(); +} + +bool OpenTypeTaggedStyleValue::properties_equal(OpenTypeTaggedStyleValue const& other) const +{ + return other.tag() == tag() && other.value() == value(); +} + +} diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h new file mode 100644 index 00000000000..0eba1126351 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/OpenTypeTaggedStyleValue.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2024, Sam Atkins + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::CSS { + +// An `` followed by an optional value. +// For example, ( https://drafts.csswg.org/css-fonts/#feature-tag-value ) +// and the ` ` construct for `font-variation-settings`. +class OpenTypeTaggedStyleValue : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create(FlyString tag, ValueComparingNonnullRefPtr value) + { + return adopt_ref(*new (nothrow) OpenTypeTaggedStyleValue(move(tag), move(value))); + } + virtual ~OpenTypeTaggedStyleValue() override = default; + + FlyString const& tag() const { return m_tag; } + ValueComparingNonnullRefPtr const& value() const { return m_value; } + + virtual String to_string() const override; + + bool properties_equal(OpenTypeTaggedStyleValue const&) const; + +private: + explicit OpenTypeTaggedStyleValue(FlyString tag, ValueComparingNonnullRefPtr value) + : StyleValueWithDefaultOperators(Type::OpenTypeTagged) + , m_tag(move(tag)) + , m_value(move(value)) + { + } + + FlyString m_tag; + ValueComparingNonnullRefPtr m_value; +}; + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index eff5ee9cc41..497e56884cf 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -178,6 +178,7 @@ class MediaQueryListEvent; class Number; class NumberOrCalculated; class NumberStyleValue; +class OpenTypeTaggedStyleValue; class ParsedFontFace; class Percentage; class PercentageOrCalculated;