diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp index bfdbb076f59..256b857b428 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.cpp @@ -51,6 +51,7 @@ #include #include #include +#include #include #include @@ -325,6 +326,12 @@ UnsetStyleValue const& StyleValue::as_unset() const return static_cast(*this); } +URLStyleValue const& StyleValue::as_url() const +{ + VERIFY(is_url()); + return static_cast(*this); +} + StyleValueList const& StyleValue::as_value_list() const { VERIFY(is_value_list()); diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index f4feaca106f..85edc7fa08f 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -131,6 +131,7 @@ public: Transformation, Unresolved, Unset, + Url, ValueList }; @@ -180,6 +181,7 @@ public: bool is_transformation() const { return type() == Type::Transformation; } bool is_unresolved() const { return type() == Type::Unresolved; } bool is_unset() const { return type() == Type::Unset; } + bool is_url() const { return type() == Type::Url; } bool is_value_list() const { return type() == Type::ValueList; } bool is_builtin() const { return is_inherit() || is_initial() || is_unset(); } @@ -228,6 +230,7 @@ public: TransformationStyleValue const& as_transformation() const; UnresolvedStyleValue const& as_unresolved() const; UnsetStyleValue const& as_unset() const; + URLStyleValue const& as_url() const; StyleValueList const& as_value_list() const; AbstractImageStyleValue& as_abstract_image() { return const_cast(const_cast(*this).as_abstract_image()); } @@ -274,6 +277,7 @@ public: TransformationStyleValue& as_transformation() { return const_cast(const_cast(*this).as_transformation()); } UnresolvedStyleValue& as_unresolved() { return const_cast(const_cast(*this).as_unresolved()); } UnsetStyleValue& as_unset() { return const_cast(const_cast(*this).as_unset()); } + URLStyleValue& as_url() { return const_cast(const_cast(*this).as_url()); } StyleValueList& as_value_list() { return const_cast(const_cast(*this).as_value_list()); } bool has_auto() const; diff --git a/Userland/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h new file mode 100644 index 00000000000..e0c37663444 --- /dev/null +++ b/Userland/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2023, MacDue + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include +#include + +namespace Web::CSS { + +class URLStyleValue final : public StyleValueWithDefaultOperators { +public: + static ValueComparingNonnullRefPtr create(AK::URL const& url) + { + return adopt_ref(*new URLStyleValue(url)); + } + + virtual ~URLStyleValue() override = default; + + AK::URL const& url() const { return m_url; } + + bool properties_equal(URLStyleValue const& other) const { return m_url == other.m_url; } + + virtual ErrorOr to_string() const override + { + return serialize_a_url(m_url.to_deprecated_string()); + } + +private: + URLStyleValue(AK::URL const& url) + : StyleValueWithDefaultOperators(Type::Url) + , m_url(url) + { + } + + AK::URL m_url; +}; + +} diff --git a/Userland/Libraries/LibWeb/Forward.h b/Userland/Libraries/LibWeb/Forward.h index 04214b5bf45..eb75da5b534 100644 --- a/Userland/Libraries/LibWeb/Forward.h +++ b/Userland/Libraries/LibWeb/Forward.h @@ -155,6 +155,7 @@ class TransformationStyleValue; class UnicodeRange; class UnresolvedStyleValue; class UnsetStyleValue; +class URLStyleValue; enum class MediaFeatureID; enum class PropertyID;