mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
LibWeb: Add URLStyleValue to represent general url() values
This is primarily being added to support `fill: url(#gradient)` for SVGs.
This commit is contained in:
parent
b19d2634f6
commit
2fbe5b969b
4 changed files with 55 additions and 0 deletions
|
@ -51,6 +51,7 @@
|
|||
#include <LibWeb/CSS/StyleValues/TextDecorationStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/TimeStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/TransformationStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/UnsetStyleValue.h>
|
||||
|
||||
|
@ -325,6 +326,12 @@ UnsetStyleValue const& StyleValue::as_unset() const
|
|||
return static_cast<UnsetStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
URLStyleValue const& StyleValue::as_url() const
|
||||
{
|
||||
VERIFY(is_url());
|
||||
return static_cast<URLStyleValue const&>(*this);
|
||||
}
|
||||
|
||||
StyleValueList const& StyleValue::as_value_list() const
|
||||
{
|
||||
VERIFY(is_value_list());
|
||||
|
|
|
@ -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<AbstractImageStyleValue&>(const_cast<StyleValue const&>(*this).as_abstract_image()); }
|
||||
|
@ -274,6 +277,7 @@ public:
|
|||
TransformationStyleValue& as_transformation() { return const_cast<TransformationStyleValue&>(const_cast<StyleValue const&>(*this).as_transformation()); }
|
||||
UnresolvedStyleValue& as_unresolved() { return const_cast<UnresolvedStyleValue&>(const_cast<StyleValue const&>(*this).as_unresolved()); }
|
||||
UnsetStyleValue& as_unset() { return const_cast<UnsetStyleValue&>(const_cast<StyleValue const&>(*this).as_unset()); }
|
||||
URLStyleValue& as_url() { return const_cast<URLStyleValue&>(const_cast<StyleValue const&>(*this).as_url()); }
|
||||
StyleValueList& as_value_list() { return const_cast<StyleValueList&>(const_cast<StyleValue const&>(*this).as_value_list()); }
|
||||
|
||||
bool has_auto() const;
|
||||
|
|
43
Userland/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
Normal file
43
Userland/Libraries/LibWeb/CSS/StyleValues/URLStyleValue.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/URL.h>
|
||||
#include <LibWeb/CSS/Serialize.h>
|
||||
#include <LibWeb/CSS/StyleValue.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
class URLStyleValue final : public StyleValueWithDefaultOperators<URLStyleValue> {
|
||||
public:
|
||||
static ValueComparingNonnullRefPtr<URLStyleValue> 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<String> 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;
|
||||
};
|
||||
|
||||
}
|
|
@ -155,6 +155,7 @@ class TransformationStyleValue;
|
|||
class UnicodeRange;
|
||||
class UnresolvedStyleValue;
|
||||
class UnsetStyleValue;
|
||||
class URLStyleValue;
|
||||
|
||||
enum class MediaFeatureID;
|
||||
enum class PropertyID;
|
||||
|
|
Loading…
Add table
Reference in a new issue