mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-27 12:46:06 +00:00
LibWeb/CSS: Stub out StylePropertyMapReadOnly
Nothing yet produces this, and the useful parts of get() and get_all() will have to wait until type reification is implemented.
This commit is contained in:
parent
05884f1d91
commit
1620fc5bf6
Notes:
github-actions[bot]
2025-08-13 09:16:12 +00:00
Author: https://github.com/AtkinsSJ
Commit: 1620fc5bf6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5823
Reviewed-by: https://github.com/trflynn89
7 changed files with 191 additions and 1 deletions
|
@ -186,6 +186,7 @@ set(SOURCES
|
||||||
CSS/StyleInvalidation.cpp
|
CSS/StyleInvalidation.cpp
|
||||||
CSS/StyleInvalidationData.cpp
|
CSS/StyleInvalidationData.cpp
|
||||||
CSS/StyleProperty.cpp
|
CSS/StyleProperty.cpp
|
||||||
|
CSS/StylePropertyMapReadOnly.cpp
|
||||||
CSS/StyleSheet.cpp
|
CSS/StyleSheet.cpp
|
||||||
CSS/StyleSheetIdentifier.cpp
|
CSS/StyleSheetIdentifier.cpp
|
||||||
CSS/StyleSheetList.cpp
|
CSS/StyleSheetList.cpp
|
||||||
|
|
127
Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
Normal file
127
Libraries/LibWeb/CSS/StylePropertyMapReadOnly.cpp
Normal file
|
@ -0,0 +1,127 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "StylePropertyMapReadOnly.h"
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/Bindings/StylePropertyMapReadOnlyPrototype.h>
|
||||||
|
#include <LibWeb/CSS/CSSStyleDeclaration.h>
|
||||||
|
#include <LibWeb/CSS/PropertyName.h>
|
||||||
|
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||||
|
|
||||||
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
GC_DEFINE_ALLOCATOR(StylePropertyMapReadOnly);
|
||||||
|
|
||||||
|
GC::Ref<StylePropertyMapReadOnly> StylePropertyMapReadOnly::create_computed_style(JS::Realm& realm, DOM::AbstractElement element)
|
||||||
|
{
|
||||||
|
return realm.create<StylePropertyMapReadOnly>(realm, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
StylePropertyMapReadOnly::StylePropertyMapReadOnly(JS::Realm& realm, Optional<DOM::AbstractElement> element)
|
||||||
|
: Bindings::PlatformObject(realm)
|
||||||
|
, m_source_element(move(element))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
StylePropertyMapReadOnly::StylePropertyMapReadOnly(JS::Realm& realm, GC::Ref<CSSStyleDeclaration> declaration)
|
||||||
|
: Bindings::PlatformObject(realm)
|
||||||
|
, m_source_declaration(declaration)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
StylePropertyMapReadOnly::~StylePropertyMapReadOnly() = default;
|
||||||
|
|
||||||
|
void StylePropertyMapReadOnly::initialize(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(StylePropertyMapReadOnly);
|
||||||
|
Base::initialize(realm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StylePropertyMapReadOnly::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
|
||||||
|
visitor.visit(m_source_declaration);
|
||||||
|
if (m_source_element.has_value())
|
||||||
|
m_source_element->visit(visitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-get
|
||||||
|
WebIDL::ExceptionOr<Variant<GC::Ref<CSSStyleValue>, Empty>> StylePropertyMapReadOnly::get(String property)
|
||||||
|
{
|
||||||
|
// The get(property) method, when called on a StylePropertyMapReadOnly this, must perform the following steps:
|
||||||
|
|
||||||
|
// 1. If property is not a custom property name string, set property to property ASCII lowercased.
|
||||||
|
if (!is_a_custom_property_name_string(property))
|
||||||
|
property = property.to_ascii_lowercase();
|
||||||
|
|
||||||
|
// 2. If property is not a valid CSS property, throw a TypeError.
|
||||||
|
if (!is_a_valid_css_property(property))
|
||||||
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("'{}' is not a valid CSS property", property)) };
|
||||||
|
|
||||||
|
// 3. Let props be the value of this’s [[declarations]] internal slot.
|
||||||
|
auto& props = m_declarations;
|
||||||
|
|
||||||
|
// FIXME: 4. If props[property] exists, subdivide into iterations props[property], then reify the first item of the result and return it.
|
||||||
|
(void)props;
|
||||||
|
|
||||||
|
// 5. Otherwise, return undefined.
|
||||||
|
return Empty {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-getall
|
||||||
|
WebIDL::ExceptionOr<Vector<GC::Ref<CSSStyleValue>>> StylePropertyMapReadOnly::get_all(String property)
|
||||||
|
{
|
||||||
|
// The getAll(property) method, when called on a StylePropertyMap this, must perform the following steps:
|
||||||
|
|
||||||
|
// 1. If property is not a custom property name string, set property to property ASCII lowercased.
|
||||||
|
if (!is_a_custom_property_name_string(property))
|
||||||
|
property = property.to_ascii_lowercase();
|
||||||
|
|
||||||
|
// 2. If property is not a valid CSS property, throw a TypeError.
|
||||||
|
if (!is_a_valid_css_property(property))
|
||||||
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("'{}' is not a valid CSS property", property)) };
|
||||||
|
|
||||||
|
// 3. Let props be the value of this’s [[declarations]] internal slot.
|
||||||
|
auto& props = m_declarations;
|
||||||
|
|
||||||
|
// FIXME: 4. If props[property] exists, subdivide into iterations props[property], then reify each item of the result, and return the list.
|
||||||
|
(void)props;
|
||||||
|
|
||||||
|
// 5. Otherwise, return an empty list.
|
||||||
|
return Vector<GC::Ref<CSSStyleValue>> {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-has
|
||||||
|
WebIDL::ExceptionOr<bool> StylePropertyMapReadOnly::has(String property)
|
||||||
|
{
|
||||||
|
// The has(property) method, when called on a StylePropertyMapReadOnly this, must perform the following steps:
|
||||||
|
|
||||||
|
// 1. If property is not a custom property name string, set property to property ASCII lowercased.
|
||||||
|
if (!is_a_custom_property_name_string(property))
|
||||||
|
property = property.to_ascii_lowercase();
|
||||||
|
|
||||||
|
// 2. If property is not a valid CSS property, throw a TypeError.
|
||||||
|
if (!is_a_valid_css_property(property))
|
||||||
|
return WebIDL::SimpleException { WebIDL::SimpleExceptionType::TypeError, MUST(String::formatted("'{}' is not a valid CSS property", property)) };
|
||||||
|
|
||||||
|
// 3. Let props be the value of this’s [[declarations]] internal slot.
|
||||||
|
auto& props = m_declarations;
|
||||||
|
|
||||||
|
// 4. If props[property] exists, return true. Otherwise, return false.
|
||||||
|
return props.contains(property);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#dom-stylepropertymapreadonly-size
|
||||||
|
WebIDL::UnsignedLong StylePropertyMapReadOnly::size() const
|
||||||
|
{
|
||||||
|
// The size attribute, on getting from a StylePropertyMapReadOnly this, must perform the following steps:
|
||||||
|
|
||||||
|
// 1. Return the size of the value of this’s [[declarations]] internal slot.
|
||||||
|
return m_declarations.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
47
Libraries/LibWeb/CSS/StylePropertyMapReadOnly.h
Normal file
47
Libraries/LibWeb/CSS/StylePropertyMapReadOnly.h
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
* 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:
|
||||||
|
explicit StylePropertyMapReadOnly(JS::Realm&, GC::Ref<CSSStyleDeclaration>);
|
||||||
|
explicit StylePropertyMapReadOnly(JS::Realm&, Optional<DOM::AbstractElement> = {});
|
||||||
|
|
||||||
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
|
Optional<DOM::AbstractElement> m_source_element;
|
||||||
|
GC::Ptr<CSSStyleDeclaration> m_source_declaration;
|
||||||
|
|
||||||
|
// 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.
|
||||||
|
HashMap<FlyString, NonnullRefPtr<StyleValue>> m_declarations;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
12
Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl
Normal file
12
Libraries/LibWeb/CSS/StylePropertyMapReadOnly.idl
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#import <CSS/CSSStyleValue.idl>
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#stylepropertymapreadonly
|
||||||
|
// FIXME: [Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
|
||||||
|
[Exposed=(Window, Worker)]
|
||||||
|
interface StylePropertyMapReadOnly {
|
||||||
|
// FIXME: iterable<USVString, sequence<CSSStyleValue>>;
|
||||||
|
(undefined or CSSStyleValue) get(USVString property);
|
||||||
|
sequence<CSSStyleValue> getAll(USVString property);
|
||||||
|
boolean has(USVString property);
|
||||||
|
readonly attribute unsigned long size;
|
||||||
|
};
|
|
@ -223,6 +223,7 @@ class ColorMixStyleValue;
|
||||||
class ColorSchemeStyleValue;
|
class ColorSchemeStyleValue;
|
||||||
class ColorFunctionStyleValue;
|
class ColorFunctionStyleValue;
|
||||||
class ColorStyleValue;
|
class ColorStyleValue;
|
||||||
|
class ComputedProperties;
|
||||||
class ConicGradientStyleValue;
|
class ConicGradientStyleValue;
|
||||||
class ContentStyleValue;
|
class ContentStyleValue;
|
||||||
class CounterDefinitionsStyleValue;
|
class CounterDefinitionsStyleValue;
|
||||||
|
@ -336,7 +337,7 @@ class Size;
|
||||||
class ScrollbarColorStyleValue;
|
class ScrollbarColorStyleValue;
|
||||||
class StringStyleValue;
|
class StringStyleValue;
|
||||||
class StyleComputer;
|
class StyleComputer;
|
||||||
class ComputedProperties;
|
class StylePropertyMapReadOnly;
|
||||||
class StyleSheet;
|
class StyleSheet;
|
||||||
class StyleSheetList;
|
class StyleSheetList;
|
||||||
class StyleValue;
|
class StyleValue;
|
||||||
|
|
|
@ -58,6 +58,7 @@ libweb_js_bindings(CSS/MediaQueryList)
|
||||||
libweb_js_bindings(CSS/MediaQueryListEvent)
|
libweb_js_bindings(CSS/MediaQueryListEvent)
|
||||||
libweb_js_bindings(CSS/Screen)
|
libweb_js_bindings(CSS/Screen)
|
||||||
libweb_js_bindings(CSS/ScreenOrientation)
|
libweb_js_bindings(CSS/ScreenOrientation)
|
||||||
|
libweb_js_bindings(CSS/StylePropertyMapReadOnly)
|
||||||
libweb_js_bindings(CSS/StyleSheet)
|
libweb_js_bindings(CSS/StyleSheet)
|
||||||
libweb_js_bindings(CSS/StyleSheetList)
|
libweb_js_bindings(CSS/StyleSheetList)
|
||||||
libweb_js_bindings(CSS/TransitionEvent)
|
libweb_js_bindings(CSS/TransitionEvent)
|
||||||
|
|
|
@ -409,6 +409,7 @@ Storage
|
||||||
StorageEvent
|
StorageEvent
|
||||||
StorageManager
|
StorageManager
|
||||||
String
|
String
|
||||||
|
StylePropertyMapReadOnly
|
||||||
StyleSheet
|
StyleSheet
|
||||||
StyleSheetList
|
StyleSheetList
|
||||||
SubmitEvent
|
SubmitEvent
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue