mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-10-04 23:29:52 +00:00
After looking into this more, the `[[declarations]]` slot does not seem to need to be a literal map of property names and values. Instead, it can just point at the source (an element or style declaration), and then direct all read or write operations to that. This means the `has()` and `delete()` methods actually work now. A few remaining failures in these tests are because of: - StylePropertyMap[ReadOnly]s not being iterable yet - We're not populating an element's custom properties map, which get fixed whenever someone gets around to producing proper computed values of them.
45 lines
1.6 KiB
C++
45 lines
1.6 KiB
C++
/*
|
||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||
*
|
||
* SPDX-License-Identifier: BSD-2-Clause
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include <LibWeb/Bindings/PlatformObject.h>
|
||
#include <LibWeb/CSS/StyleValues/StyleValue.h>
|
||
#include <LibWeb/DOM/AbstractElement.h>
|
||
#include <LibWeb/WebIDL/Types.h>
|
||
|
||
namespace Web::CSS {
|
||
|
||
// https://drafts.css-houdini.org/css-typed-om-1/#stylepropertymapreadonly
|
||
class StylePropertyMapReadOnly : public Bindings::PlatformObject {
|
||
WEB_PLATFORM_OBJECT(StylePropertyMapReadOnly, Bindings::PlatformObject);
|
||
GC_DECLARE_ALLOCATOR(StylePropertyMapReadOnly);
|
||
|
||
public:
|
||
[[nodiscard]] static GC::Ref<StylePropertyMapReadOnly> create_computed_style(JS::Realm&, DOM::AbstractElement);
|
||
|
||
virtual ~StylePropertyMapReadOnly() override;
|
||
|
||
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> get(String property);
|
||
WebIDL::ExceptionOr<Vector<GC::Ref<CSSStyleValue>>> get_all(String property);
|
||
WebIDL::ExceptionOr<bool> has(String property);
|
||
WebIDL::UnsignedLong size() const;
|
||
|
||
protected:
|
||
using Source = Variant<DOM::AbstractElement, GC::Ref<CSSStyleDeclaration>>;
|
||
explicit StylePropertyMapReadOnly(JS::Realm&, Source);
|
||
|
||
virtual void initialize(JS::Realm&) override;
|
||
virtual void visit_edges(Cell::Visitor&) override;
|
||
|
||
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-declarations-slot
|
||
// A StylePropertyMapReadOnly object has a [[declarations]] internal slot, which is a map reflecting the CSS
|
||
// declaration block’s declarations.
|
||
// NB: We just directly refer to our source, at least for now.
|
||
Source m_declarations;
|
||
};
|
||
|
||
}
|