mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 04:39:06 +00:00
LibWeb: Add CustomStateSet IDL type
This commit is contained in:
parent
bc94431b99
commit
e63d81b36e
Notes:
github-actions[bot]
2025-07-04 17:11:54 +00:00
Author: https://github.com/AtkinsSJ
Commit: e63d81b36e
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5302
Reviewed-by: https://github.com/tcl3 ✅
9 changed files with 104 additions and 0 deletions
|
@ -362,6 +362,7 @@ set(SOURCES
|
||||||
HTML/CustomElements/CustomElementName.cpp
|
HTML/CustomElements/CustomElementName.cpp
|
||||||
HTML/CustomElements/CustomElementReactionNames.cpp
|
HTML/CustomElements/CustomElementReactionNames.cpp
|
||||||
HTML/CustomElements/CustomElementRegistry.cpp
|
HTML/CustomElements/CustomElementRegistry.cpp
|
||||||
|
HTML/CustomElements/CustomStateSet.cpp
|
||||||
HTML/DataTransfer.cpp
|
HTML/DataTransfer.cpp
|
||||||
HTML/DataTransferItem.cpp
|
HTML/DataTransferItem.cpp
|
||||||
HTML/DataTransferItemList.cpp
|
HTML/DataTransferItemList.cpp
|
||||||
|
|
|
@ -56,6 +56,7 @@ enum class ShouldComputeRole {
|
||||||
X(CSSStylePropertiesSetProperty) \
|
X(CSSStylePropertiesSetProperty) \
|
||||||
X(CSSStylePropertiesTextChange) \
|
X(CSSStylePropertiesTextChange) \
|
||||||
X(CustomElementStateChange) \
|
X(CustomElementStateChange) \
|
||||||
|
X(CustomStateSetChange) \
|
||||||
X(DidLoseFocus) \
|
X(DidLoseFocus) \
|
||||||
X(DidReceiveFocus) \
|
X(DidReceiveFocus) \
|
||||||
X(EditingInsertion) \
|
X(EditingInsertion) \
|
||||||
|
|
|
@ -507,6 +507,7 @@ class CloseWatcher;
|
||||||
class CloseWatcherManager;
|
class CloseWatcherManager;
|
||||||
class CustomElementDefinition;
|
class CustomElementDefinition;
|
||||||
class CustomElementRegistry;
|
class CustomElementRegistry;
|
||||||
|
class CustomStateSet;
|
||||||
class DataTransfer;
|
class DataTransfer;
|
||||||
class DataTransferItem;
|
class DataTransferItem;
|
||||||
class DataTransferItemList;
|
class DataTransferItemList;
|
||||||
|
|
53
Libraries/LibWeb/HTML/CustomElements/CustomStateSet.cpp
Normal file
53
Libraries/LibWeb/HTML/CustomElements/CustomStateSet.cpp
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibGC/CellAllocator.h>
|
||||||
|
#include <LibJS/Runtime/PrimitiveString.h>
|
||||||
|
#include <LibJS/Runtime/Realm.h>
|
||||||
|
#include <LibWeb/Bindings/Intrinsics.h>
|
||||||
|
#include <LibWeb/DOM/Element.h>
|
||||||
|
#include <LibWeb/HTML/CustomElements/CustomStateSet.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
GC_DEFINE_ALLOCATOR(CustomStateSet);
|
||||||
|
|
||||||
|
GC::Ref<CustomStateSet> CustomStateSet::create(JS::Realm& realm, GC::Ref<DOM::Element> element)
|
||||||
|
{
|
||||||
|
return realm.create<CustomStateSet>(realm, element);
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomStateSet::CustomStateSet(JS::Realm& realm, GC::Ref<DOM::Element> element)
|
||||||
|
: Bindings::PlatformObject(realm)
|
||||||
|
, m_set_entries(JS::Set::create(realm))
|
||||||
|
, m_element(element)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomStateSet::initialize(JS::Realm& realm)
|
||||||
|
{
|
||||||
|
WEB_SET_PROTOTYPE_FOR_INTERFACE(CustomStateSet);
|
||||||
|
Base::initialize(realm);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomStateSet::visit_edges(Cell::Visitor& visitor)
|
||||||
|
{
|
||||||
|
Base::visit_edges(visitor);
|
||||||
|
visitor.visit(m_set_entries);
|
||||||
|
visitor.visit(m_element);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CustomStateSet::has_state(FlyString const& state) const
|
||||||
|
{
|
||||||
|
return m_set_entries->set_has(JS::PrimitiveString::create(realm().vm(), state));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CustomStateSet::on_set_modified_from_js(Badge<Bindings::CustomStateSetPrototype>)
|
||||||
|
{
|
||||||
|
m_element->invalidate_style(DOM::StyleInvalidationReason::CustomStateSetChange);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
40
Libraries/LibWeb/HTML/CustomElements/CustomStateSet.h
Normal file
40
Libraries/LibWeb/HTML/CustomElements/CustomStateSet.h
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibJS/Runtime/Set.h>
|
||||||
|
#include <LibJS/Runtime/SetIterator.h>
|
||||||
|
#include <LibWeb/Bindings/CustomStateSetPrototype.h>
|
||||||
|
#include <LibWeb/Bindings/PlatformObject.h>
|
||||||
|
|
||||||
|
namespace Web::HTML {
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#customstateset
|
||||||
|
class CustomStateSet final : public Bindings::PlatformObject {
|
||||||
|
WEB_PLATFORM_OBJECT(CustomStateSet, Bindings::PlatformObject);
|
||||||
|
GC_DECLARE_ALLOCATOR(CustomStateSet);
|
||||||
|
|
||||||
|
public:
|
||||||
|
[[nodiscard]] static GC::Ref<CustomStateSet> create(JS::Realm&, GC::Ref<DOM::Element>);
|
||||||
|
virtual ~CustomStateSet() override = default;
|
||||||
|
|
||||||
|
GC::Ref<JS::Set> set_entries() const { return m_set_entries; }
|
||||||
|
bool has_state(FlyString const&) const;
|
||||||
|
|
||||||
|
void on_set_modified_from_js(Badge<Bindings::CustomStateSetPrototype>);
|
||||||
|
|
||||||
|
private:
|
||||||
|
CustomStateSet(JS::Realm&, GC::Ref<DOM::Element>);
|
||||||
|
|
||||||
|
virtual void initialize(JS::Realm&) override;
|
||||||
|
virtual void visit_edges(Cell::Visitor&) override;
|
||||||
|
|
||||||
|
GC::Ref<JS::Set> m_set_entries;
|
||||||
|
GC::Ref<DOM::Element> m_element;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
5
Libraries/LibWeb/HTML/CustomElements/CustomStateSet.idl
Normal file
5
Libraries/LibWeb/HTML/CustomElements/CustomStateSet.idl
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
// https://html.spec.whatwg.org/multipage/custom-elements.html#customstateset
|
||||||
|
[Exposed=Window]
|
||||||
|
interface CustomStateSet {
|
||||||
|
setlike<DOMString>;
|
||||||
|
};
|
|
@ -128,6 +128,7 @@ libweb_js_bindings(HTML/CloseEvent)
|
||||||
libweb_js_bindings(HTML/CloseWatcher)
|
libweb_js_bindings(HTML/CloseWatcher)
|
||||||
libweb_js_bindings(HTML/CommandEvent)
|
libweb_js_bindings(HTML/CommandEvent)
|
||||||
libweb_js_bindings(HTML/CustomElements/CustomElementRegistry)
|
libweb_js_bindings(HTML/CustomElements/CustomElementRegistry)
|
||||||
|
libweb_js_bindings(HTML/CustomElements/CustomStateSet)
|
||||||
libweb_js_bindings(HTML/DataTransfer)
|
libweb_js_bindings(HTML/DataTransfer)
|
||||||
libweb_js_bindings(HTML/DataTransferItem)
|
libweb_js_bindings(HTML/DataTransferItem)
|
||||||
libweb_js_bindings(HTML/DataTransferItemList)
|
libweb_js_bindings(HTML/DataTransferItemList)
|
||||||
|
|
|
@ -54,6 +54,7 @@ static bool is_platform_object(Type const& type)
|
||||||
"Credential"sv,
|
"Credential"sv,
|
||||||
"CredentialsContainer"sv,
|
"CredentialsContainer"sv,
|
||||||
"CryptoKey"sv,
|
"CryptoKey"sv,
|
||||||
|
"CustomStateSet"sv,
|
||||||
"DataTransfer"sv,
|
"DataTransfer"sv,
|
||||||
"Document"sv,
|
"Document"sv,
|
||||||
"DocumentType"sv,
|
"DocumentType"sv,
|
||||||
|
|
|
@ -85,6 +85,7 @@ Crypto
|
||||||
CryptoKey
|
CryptoKey
|
||||||
CustomElementRegistry
|
CustomElementRegistry
|
||||||
CustomEvent
|
CustomEvent
|
||||||
|
CustomStateSet
|
||||||
DOMException
|
DOMException
|
||||||
DOMImplementation
|
DOMImplementation
|
||||||
DOMMatrix
|
DOMMatrix
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue