mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-31 05:09:12 +00:00
LibWeb: Implement HTMLAllCollection
This collection has some pretty strange behaviour, particularly with the IsHTMLDDA slot which is defined in the javascript spec specifically for this object. This commit implements pretty much all of this interface, besides from the custom [[Call]]. There is also no caching over this collection. Since it is a live collection over the entire document, the performance is never going to be great, and I am not convinced any speedup for this legacy interface is worth a massive cache.
This commit is contained in:
parent
897f55ca8a
commit
1f59e21829
Notes:
sideshowbarker
2024-07-16 18:03:21 +09:00
Author: https://github.com/shannonbooth
Commit: 1f59e21829
Pull-request: https://github.com/SerenityOS/serenity/pull/23788
6 changed files with 312 additions and 0 deletions
63
Userland/Libraries/LibWeb/HTML/HTMLAllCollection.h
Normal file
63
Userland/Libraries/LibWeb/HTML/HTMLAllCollection.h
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Shannon Booth <shannon@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Function.h>
|
||||
#include <LibJS/Forward.h>
|
||||
#include <LibJS/Heap/GCPtr.h>
|
||||
#include <LibWeb/Bindings/PlatformObject.h>
|
||||
#include <LibWeb/DOM/HTMLCollection.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::HTML {
|
||||
|
||||
// FIXME: Should be part of HTML namespace!
|
||||
|
||||
class HTMLAllCollection : public Bindings::PlatformObject {
|
||||
WEB_PLATFORM_OBJECT(HTMLAllCollection, Bindings::PlatformObject);
|
||||
JS_DECLARE_ALLOCATOR(HTMLAllCollection);
|
||||
|
||||
public:
|
||||
enum class Scope {
|
||||
Children,
|
||||
Descendants,
|
||||
};
|
||||
[[nodiscard]] static JS::NonnullGCPtr<HTMLAllCollection> create(DOM::ParentNode& root, Scope, Function<bool(DOM::Element const&)> filter);
|
||||
|
||||
virtual ~HTMLAllCollection() override;
|
||||
|
||||
size_t length() const;
|
||||
Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> item(Optional<FlyString> const& name_or_index) const;
|
||||
Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> named_item(FlyString const& name) const;
|
||||
|
||||
JS::MarkedVector<JS::NonnullGCPtr<DOM::Element>> collect_matching_elements() const;
|
||||
|
||||
virtual WebIDL::ExceptionOr<JS::Value> item_value(size_t index) const override;
|
||||
virtual WebIDL::ExceptionOr<JS::Value> named_item_value(FlyString const& name) const override;
|
||||
virtual Vector<FlyString> supported_property_names() const override;
|
||||
virtual bool is_supported_property_index(u32) const override;
|
||||
|
||||
protected:
|
||||
HTMLAllCollection(DOM::ParentNode& root, Scope, Function<bool(DOM::Element const&)> filter);
|
||||
|
||||
virtual void initialize(JS::Realm&) override;
|
||||
|
||||
virtual bool is_htmldda() const override { return true; }
|
||||
|
||||
private:
|
||||
Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> get_the_all_named_elements(FlyString const& name) const;
|
||||
JS::GCPtr<DOM::Element> get_the_all_indexed_element(u32 index) const;
|
||||
Variant<JS::NonnullGCPtr<DOM::HTMLCollection>, JS::NonnullGCPtr<DOM::Element>, Empty> get_the_all_indexed_or_named_elements(JS::PropertyKey const& name_or_index) const;
|
||||
|
||||
virtual void visit_edges(Cell::Visitor&) override;
|
||||
|
||||
JS::NonnullGCPtr<DOM::ParentNode> m_root;
|
||||
Function<bool(DOM::Element const&)> m_filter;
|
||||
Scope m_scope { Scope::Descendants };
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue