mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-03 15:41:57 +00:00
Some checks are pending
CI / Lagom (arm64, Sanitizer_CI, false, macOS, macos-15, Clang) (push) Waiting to run
CI / Lagom (x86_64, Fuzzers_CI, false, Linux, blacksmith-16vcpu-ubuntu-2404, Clang) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, false, Linux, blacksmith-16vcpu-ubuntu-2404, GNU) (push) Waiting to run
CI / Lagom (x86_64, Sanitizer_CI, true, Linux, blacksmith-16vcpu-ubuntu-2404, Clang) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (arm64, macOS, macOS-universal2, macos-15) (push) Waiting to run
Package the js repl as a binary artifact / build-and-package (x86_64, Linux, Linux-x86_64, blacksmith-8vcpu-ubuntu-2404) (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
When serializing CSS declarations we now support combining multiple properties into a single shorthand property in some cases. This comes with a healthy dose of FIXMEs, including work to be done around supporting: - Nested shorthands (e.g. background, border, etc) - Shorthands which aren't represented by the ShorthandStyleValue type - Subproperties pending substitution This gains us a bunch of new test passes, both for WPT and in-tree
82 lines
3.5 KiB
C++
82 lines
3.5 KiB
C++
/*
|
|
* Copyright (c) 2018-2023, Andreas Kling <andreas@ladybird.org>
|
|
* Copyright (c) 2024-2025, Sam Atkins <sam@ladybird.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
|
#include <LibWeb/CSS/GeneratedCSSStyleProperties.h>
|
|
|
|
namespace Web::CSS {
|
|
|
|
// https://drafts.csswg.org/cssom/#cssstyleproperties
|
|
class CSSStyleProperties
|
|
: public CSSStyleDeclaration
|
|
, public Bindings::GeneratedCSSStyleProperties {
|
|
WEB_PLATFORM_OBJECT(CSSStyleProperties, CSSStyleDeclaration);
|
|
GC_DECLARE_ALLOCATOR(CSSStyleProperties);
|
|
|
|
public:
|
|
[[nodiscard]] static GC::Ref<CSSStyleProperties> create(JS::Realm&, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
|
|
|
|
[[nodiscard]] static GC::Ref<CSSStyleProperties> create_resolved_style(DOM::ElementReference);
|
|
[[nodiscard]] static GC::Ref<CSSStyleProperties> create_element_inline_style(DOM::ElementReference, Vector<StyleProperty>, HashMap<FlyString, StyleProperty> custom_properties);
|
|
|
|
virtual ~CSSStyleProperties() override = default;
|
|
virtual void initialize(JS::Realm&) override;
|
|
|
|
virtual size_t length() const override;
|
|
virtual String item(size_t index) const override;
|
|
|
|
Optional<StyleProperty> property(PropertyID) const;
|
|
Optional<StyleProperty const&> custom_property(FlyString const& custom_property_name) const;
|
|
|
|
WebIDL::ExceptionOr<void> set_property(PropertyID, StringView css_text, StringView priority = ""sv);
|
|
WebIDL::ExceptionOr<String> remove_property(PropertyID);
|
|
|
|
virtual WebIDL::ExceptionOr<void> set_property(StringView property_name, StringView css_text, StringView priority) override;
|
|
virtual WebIDL::ExceptionOr<String> remove_property(StringView property_name) override;
|
|
|
|
virtual String get_property_value(StringView property_name) const override;
|
|
virtual StringView get_property_priority(StringView property_name) const override;
|
|
|
|
Vector<StyleProperty> const& properties() const { return m_properties; }
|
|
HashMap<FlyString, StyleProperty> const& custom_properties() const { return m_custom_properties; }
|
|
|
|
size_t custom_property_count() const { return m_custom_properties.size(); }
|
|
|
|
String css_float() const;
|
|
WebIDL::ExceptionOr<void> set_css_float(StringView);
|
|
|
|
virtual String serialized() const final override;
|
|
String serialize_a_css_value(StyleProperty const&) const;
|
|
String serialize_a_css_value(Vector<StyleProperty>) const;
|
|
virtual WebIDL::ExceptionOr<void> set_css_text(StringView) override;
|
|
|
|
void set_declarations_from_text(StringView);
|
|
|
|
// ^Bindings::GeneratedCSSStyleProperties
|
|
virtual CSSStyleProperties& generated_style_properties_to_css_style_properties() override { return *this; }
|
|
|
|
private:
|
|
CSSStyleProperties(JS::Realm&, Computed, Readonly, Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties, Optional<DOM::ElementReference>);
|
|
|
|
virtual void visit_edges(Cell::Visitor&) override;
|
|
|
|
RefPtr<CSSStyleValue const> style_value_for_computed_property(Layout::NodeWithStyle const&, PropertyID) const;
|
|
Optional<StyleProperty> get_property_internal(PropertyID) const;
|
|
|
|
bool set_a_css_declaration(PropertyID, NonnullRefPtr<CSSStyleValue const>, Important);
|
|
void empty_the_declarations();
|
|
void set_the_declarations(Vector<StyleProperty> properties, HashMap<FlyString, StyleProperty> custom_properties);
|
|
|
|
void invalidate_owners(DOM::StyleInvalidationReason);
|
|
|
|
Vector<StyleProperty> m_properties;
|
|
HashMap<FlyString, StyleProperty> m_custom_properties;
|
|
};
|
|
|
|
}
|