Files
ladybird/Libraries/LibWeb/CSS/StyleValues/ShorthandStyleValue.h
Sam Atkins 9f00425dad LibWeb/CSS: Let CSSStyleValue know its CSSStyleSheet
The CSS `fetch_foo()` functions resolve the URL relative to the
CSSStyleSheet if one is provided. So, style values that do so need to
know what CSSStyleSheet they are part of so that, for example, `url
(foo.png)` is loaded relative to the style sheet's URL instead of the
document's one.

That all works without this change because we currently absolutize URLs
during parsing, but we're in the process of stopping that.

This commit adds the infrastructure for telling style values what their
CSSStyleSheet is.
2025-04-15 09:54:35 +01:00

44 lines
1.6 KiB
C++

/*
* Copyright (c) 2023, Ali Mohammad Pur <mpfard@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibWeb/CSS/CSSStyleValue.h>
namespace Web::CSS {
class ShorthandStyleValue final : public StyleValueWithDefaultOperators<ShorthandStyleValue> {
public:
static ValueComparingNonnullRefPtr<ShorthandStyleValue> create(PropertyID shorthand, Vector<PropertyID> sub_properties, Vector<ValueComparingNonnullRefPtr<CSSStyleValue const>> values)
{
return adopt_ref(*new ShorthandStyleValue(shorthand, move(sub_properties), move(values)));
}
virtual ~ShorthandStyleValue() override;
Vector<PropertyID> const& sub_properties() const { return m_properties.sub_properties; }
Vector<ValueComparingNonnullRefPtr<CSSStyleValue const>> const& values() const { return m_properties.values; }
ValueComparingRefPtr<CSSStyleValue const> longhand(PropertyID) const;
virtual String to_string(SerializationMode) const override;
bool properties_equal(ShorthandStyleValue const& other) const { return m_properties == other.m_properties; }
private:
ShorthandStyleValue(PropertyID shorthand, Vector<PropertyID> sub_properties, Vector<ValueComparingNonnullRefPtr<CSSStyleValue const>> values);
virtual void set_style_sheet(GC::Ptr<CSSStyleSheet>) override;
struct Properties {
PropertyID shorthand_property;
Vector<PropertyID> sub_properties;
Vector<ValueComparingNonnullRefPtr<CSSStyleValue const>> values;
bool operator==(Properties const&) const = default;
} m_properties;
};
}