mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 17:29:01 +00:00
LibWeb/CSS: Implement CSSNumericArray
This commit is contained in:
parent
6c8876cdb8
commit
a46c980629
Notes:
github-actions[bot]
2025-08-29 10:00:05 +00:00
Author: https://github.com/AtkinsSJ
Commit: a46c980629
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5955
Reviewed-by: https://github.com/trflynn89
8 changed files with 113 additions and 0 deletions
|
@ -120,6 +120,7 @@ set(SOURCES
|
||||||
CSS/CSSMediaRule.cpp
|
CSS/CSSMediaRule.cpp
|
||||||
CSS/CSSNamespaceRule.cpp
|
CSS/CSSNamespaceRule.cpp
|
||||||
CSS/CSSNestedDeclarations.cpp
|
CSS/CSSNestedDeclarations.cpp
|
||||||
|
CSS/CSSNumericArray.cpp
|
||||||
CSS/CSSNumericValue.cpp
|
CSS/CSSNumericValue.cpp
|
||||||
CSS/CSSPageRule.cpp
|
CSS/CSSPageRule.cpp
|
||||||
CSS/CSSPageDescriptors.cpp
|
CSS/CSSPageDescriptors.cpp
|
||||||
|
|
60
Libraries/LibWeb/CSS/CSSNumericArray.cpp
Normal file
60
Libraries/LibWeb/CSS/CSSNumericArray.cpp
Normal file
|
@ -0,0 +1,60 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "CSSNumericArray.h"
|
||||||
|
#include <LibWeb/Bindings/CSSNumericArrayPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/CSS/CSSNumericValue.h>
|
||||||
|
|
||||||
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
GC_DEFINE_ALLOCATOR(CSSNumericArray);
|
||||||
|
|
||||||
|
GC::Ref<CSSNumericArray> CSSNumericArray::create(JS::Realm& realm, Vector<GC::Ref<CSSNumericValue>> values)
|
||||||
|
{
|
||||||
|
return realm.create<CSSNumericArray>(realm, move(values));
|
||||||
|
}
|
||||||
|
|
||||||
|
CSSNumericArray::CSSNumericArray(JS::Realm& realm, Vector<GC::Ref<CSSNumericValue>> values)
|
||||||
|
: Bindings::PlatformObject(realm)
|
||||||
|
, m_values(move(values))
|
||||||
|
{
|
||||||
|
m_legacy_platform_object_flags = LegacyPlatformObjectFlags {
|
||||||
|
.supports_indexed_properties = true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
CSSNumericArray::~CSSNumericArray() = default;
|
||||||
|
|
||||||
|
void CSSNumericArray::initialize(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSNumericArray);
|
||||||
|
Base::initialize(realm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSSNumericArray::visit_edges(Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_values);
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#dom-cssnumericarray-length
|
||||||
|
WebIDL::UnsignedLong CSSNumericArray::length() const
|
||||||
|
{
|
||||||
|
// The length attribute of CSSNumericArray indicates how many CSSNumericValues are contained within the CSSNumericArray.
|
||||||
|
return m_values.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#cssnumericarray-indexed-property-getter
|
||||||
|
Optional<JS::Value> CSSNumericArray::item_value(size_t index) const
|
||||||
|
{
|
||||||
|
// The indexed property getter of CSSNumericArray retrieves the CSSNumericValue at the provided index.
|
||||||
|
if (auto item = m_values.get(index); item.has_value())
|
||||||
|
return item.release_value();
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
37
Libraries/LibWeb/CSS/CSSNumericArray.h
Normal file
37
Libraries/LibWeb/CSS/CSSNumericArray.h
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
#include <LibWeb/WebIDL/Types.h>
|
||||||
|
|
||||||
|
namespace Web::CSS {
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#cssnumericarray
|
||||||
|
class CSSNumericArray : public Bindings::PlatformObject {
|
||||||
|
WEB_PLATFORM_OBJECT(CSSNumericArray, Bindings::PlatformObject);
|
||||||
|
GC_DECLARE_ALLOCATOR(CSSNumericArray);
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]] static GC::Ref<CSSNumericArray> create(JS::Realm&, Vector<GC::Ref<CSSNumericValue>>);
|
||||||
|
|
||||||
|
virtual ~CSSNumericArray() override;
|
||||||
|
|
||||||
|
WebIDL::UnsignedLong length() const;
|
||||||
|
virtual Optional<JS::Value> item_value(size_t index) const override;
|
||||||
|
Vector<GC::Ref<CSSNumericValue>> values() { return m_values; }
|
||||||
|
|
||||||
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
virtual void visit_edges(Visitor&) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
CSSNumericArray(JS::Realm&, Vector<GC::Ref<CSSNumericValue>>);
|
||||||
|
|
||||||
|
Vector<GC::Ref<CSSNumericValue>> m_values;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
11
Libraries/LibWeb/CSS/CSSNumericArray.idl
Normal file
11
Libraries/LibWeb/CSS/CSSNumericArray.idl
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
#import <CSS/CSSNumericValue.idl>
|
||||||
|
|
||||||
|
// https://drafts.css-houdini.org/css-typed-om-1/#cssnumericarray
|
||||||
|
[Exposed=(Window, Worker, PaintWorklet, LayoutWorklet)]
|
||||||
|
interface CSSNumericArray {
|
||||||
|
readonly attribute unsigned long length;
|
||||||
|
getter CSSNumericValue (unsigned long index);
|
||||||
|
|
||||||
|
// FIXME: Different order than the spec, because IDLParser requires that this comes after the indexed property getter.
|
||||||
|
iterable<CSSNumericValue>;
|
||||||
|
};
|
|
@ -246,6 +246,7 @@ class CSSMathValue;
|
||||||
class CSSMediaRule;
|
class CSSMediaRule;
|
||||||
class CSSNamespaceRule;
|
class CSSNamespaceRule;
|
||||||
class CSSNestedDeclarations;
|
class CSSNestedDeclarations;
|
||||||
|
class CSSNumericArray;
|
||||||
class CSSNumericValue;
|
class CSSNumericValue;
|
||||||
class CSSPageRule;
|
class CSSPageRule;
|
||||||
class CSSPageDescriptors;
|
class CSSPageDescriptors;
|
||||||
|
|
|
@ -41,6 +41,7 @@ libweb_js_bindings(CSS/CSSMediaRule)
|
||||||
libweb_js_bindings(CSS/CSS NAMESPACE)
|
libweb_js_bindings(CSS/CSS NAMESPACE)
|
||||||
libweb_js_bindings(CSS/CSSNamespaceRule)
|
libweb_js_bindings(CSS/CSSNamespaceRule)
|
||||||
libweb_js_bindings(CSS/CSSNestedDeclarations)
|
libweb_js_bindings(CSS/CSSNestedDeclarations)
|
||||||
|
libweb_js_bindings(CSS/CSSNumericArray)
|
||||||
libweb_js_bindings(CSS/CSSNumericValue)
|
libweb_js_bindings(CSS/CSSNumericValue)
|
||||||
libweb_js_bindings(CSS/CSSPageRule)
|
libweb_js_bindings(CSS/CSSPageRule)
|
||||||
libweb_js_bindings(CSS/CSSPageDescriptors)
|
libweb_js_bindings(CSS/CSSPageDescriptors)
|
||||||
|
|
|
@ -55,6 +55,7 @@ static bool is_platform_object(Type const& type)
|
||||||
"CredentialsContainer"sv,
|
"CredentialsContainer"sv,
|
||||||
"CryptoKey"sv,
|
"CryptoKey"sv,
|
||||||
"CSSKeywordValue"sv,
|
"CSSKeywordValue"sv,
|
||||||
|
"CSSNumericArray"sv,
|
||||||
"CSSNumericValue"sv,
|
"CSSNumericValue"sv,
|
||||||
"CSSStyleValue"sv,
|
"CSSStyleValue"sv,
|
||||||
"CSSUnitValue"sv,
|
"CSSUnitValue"sv,
|
||||||
|
|
|
@ -53,6 +53,7 @@ CSSMathValue
|
||||||
CSSMediaRule
|
CSSMediaRule
|
||||||
CSSNamespaceRule
|
CSSNamespaceRule
|
||||||
CSSNestedDeclarations
|
CSSNestedDeclarations
|
||||||
|
CSSNumericArray
|
||||||
CSSNumericValue
|
CSSNumericValue
|
||||||
CSSPageDescriptors
|
CSSPageDescriptors
|
||||||
CSSPageRule
|
CSSPageRule
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue