diff options
Diffstat (limited to 'Userland/Libraries/LibWeb/HTML')
12 files changed, 40 insertions, 28 deletions
diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp index b9ea743329..acce37c42d 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.cpp @@ -184,7 +184,7 @@ static bool is_form_control(DOM::Element const& element) } // https://html.spec.whatwg.org/multipage/forms.html#dom-form-elements -NonnullRefPtr<DOM::HTMLCollection> HTMLFormElement::elements() const +JS::NonnullGCPtr<DOM::HTMLCollection> HTMLFormElement::elements() const { // FIXME: This should return the same HTMLFormControlsCollection object every time, // but that would cause a reference cycle since HTMLCollection refs the root. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h index d548bf41e9..d7850506e7 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLFormElement.h @@ -28,7 +28,7 @@ public: void add_associated_element(Badge<FormAssociatedElement>, HTMLElement&); void remove_associated_element(Badge<FormAssociatedElement>, HTMLElement&); - NonnullRefPtr<DOM::HTMLCollection> elements() const; + JS::NonnullGCPtr<DOM::HTMLCollection> elements() const; unsigned length() const; private: diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp index b3d7589223..1763ad2c58 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.cpp @@ -4,19 +4,29 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include <LibWeb/Bindings/HTMLOptionsCollectionPrototype.h> #include <LibWeb/DOM/DOMException.h> #include <LibWeb/HTML/HTMLOptGroupElement.h> #include <LibWeb/HTML/HTMLOptionElement.h> #include <LibWeb/HTML/HTMLOptionsCollection.h> #include <LibWeb/HTML/HTMLSelectElement.h> +#include <LibWeb/HTML/Window.h> namespace Web::HTML { +JS::NonnullGCPtr<HTMLOptionsCollection> HTMLOptionsCollection::create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter) +{ + return *root.heap().allocate<HTMLOptionsCollection>(root.realm(), root, move(filter)); +} + HTMLOptionsCollection::HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter) : DOM::HTMLCollection(root, move(filter)) { + set_prototype(&root.window().ensure_web_prototype<Bindings::HTMLOptionsCollectionPrototype>("HTMLOptionsCollection")); } +HTMLOptionsCollection::~HTMLOptionsCollection() = default; + // https://html.spec.whatwg.org/multipage/common-dom-interfaces.html#dom-htmloptionscollection-add DOM::ExceptionOr<void> HTMLOptionsCollection::add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before) { diff --git a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h index e27b2491e3..780401e580 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLOptionsCollection.h @@ -16,24 +16,18 @@ using HTMLOptionOrOptGroupElement = Variant<JS::Handle<HTMLOptionElement>, JS::H using HTMLElementOrElementIndex = Variant<JS::Handle<HTMLElement>, i32>; class HTMLOptionsCollection final : public DOM::HTMLCollection { -public: - using WrapperType = Bindings::HTMLOptionsCollectionWrapper; + WEB_PLATFORM_OBJECT(HTMLOptionsCollection, DOM::HTMLCollection); - static NonnullRefPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter) - { - return adopt_ref(*new HTMLOptionsCollection(root, move(filter))); - } +public: + static JS::NonnullGCPtr<HTMLOptionsCollection> create(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter); + virtual ~HTMLOptionsCollection() override; DOM::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {}); -protected: +private: HTMLOptionsCollection(DOM::ParentNode& root, Function<bool(DOM::Element const&)> filter); }; } -namespace Web::Bindings { - -HTMLOptionsCollectionWrapper* wrap(JS::Realm&, HTML::HTMLOptionsCollection&); - -} +WRAPPER_HACK(HTMLOptionsCollection, Web::HTML) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp index 25027acd4d..3aacee7155 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.cpp @@ -22,8 +22,14 @@ HTMLSelectElement::HTMLSelectElement(DOM::Document& document, DOM::QualifiedName HTMLSelectElement::~HTMLSelectElement() = default; +void HTMLSelectElement::visit_edges(Cell::Visitor& visitor) +{ + Base::visit_edges(visitor); + visitor.visit(m_options.ptr()); +} + // https://html.spec.whatwg.org/multipage/form-elements.html#dom-select-options -RefPtr<HTMLOptionsCollection> const& HTMLSelectElement::options() +JS::GCPtr<HTMLOptionsCollection> const& HTMLSelectElement::options() { if (!m_options) { m_options = HTMLOptionsCollection::create(*this, [](DOM::Element const& element) { @@ -41,7 +47,7 @@ RefPtr<HTMLOptionsCollection> const& HTMLSelectElement::options() DOM::ExceptionOr<void> HTMLSelectElement::add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before) { // Similarly, the add(element, before) method must act like its namesake method on that same options collection. - return const_cast<RefPtr<HTMLOptionsCollection>&>(options())->add(move(element), move(before)); + return const_cast<HTMLOptionsCollection&>(*options()).add(move(element), move(before)); } // https://html.spec.whatwg.org/multipage/form-elements.html#concept-select-option-list diff --git a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h index 86b42eb07e..76024d0362 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLSelectElement.h @@ -23,7 +23,7 @@ class HTMLSelectElement final public: virtual ~HTMLSelectElement() override; - RefPtr<HTMLOptionsCollection> const& options(); + JS::GCPtr<HTMLOptionsCollection> const& options(); DOM::ExceptionOr<void> add(HTMLOptionOrOptGroupElement element, Optional<HTMLElementOrElementIndex> before = {}); @@ -56,7 +56,9 @@ public: private: HTMLSelectElement(DOM::Document&, DOM::QualifiedName); - RefPtr<HTMLOptionsCollection> m_options; + virtual void visit_edges(Cell::Visitor&) override; + + JS::GCPtr<HTMLOptionsCollection> m_options; }; } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp index e3da69c0d3..6bc0ee1fae 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.cpp @@ -222,7 +222,7 @@ void HTMLTableElement::delete_t_foot() } } -NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies() +JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::t_bodies() { return DOM::HTMLCollection::create(*this, [](DOM::Element const& element) { return element.local_name() == TagNames::tbody; @@ -253,7 +253,7 @@ JS::NonnullGCPtr<HTMLTableSectionElement> HTMLTableElement::create_t_body() return static_cast<HTMLTableSectionElement&>(*tbody); } -NonnullRefPtr<DOM::HTMLCollection> HTMLTableElement::rows() +JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableElement::rows() { HTMLTableElement* table_node = this; // FIXME: The elements in the collection must be ordered such that those elements whose parent is a thead are diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h index 1b6840d88e..601ae62a68 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableElement.h @@ -35,10 +35,10 @@ public: JS::NonnullGCPtr<HTMLTableSectionElement> create_t_foot(); void delete_t_foot(); - NonnullRefPtr<DOM::HTMLCollection> t_bodies(); + JS::NonnullGCPtr<DOM::HTMLCollection> t_bodies(); JS::NonnullGCPtr<HTMLTableSectionElement> create_t_body(); - NonnullRefPtr<DOM::HTMLCollection> rows(); + JS::NonnullGCPtr<DOM::HTMLCollection> rows(); DOM::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> insert_row(long index); DOM::ExceptionOr<void> delete_row(long index); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp index 307cc5cc8c..0a2012de0c 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.cpp @@ -23,7 +23,7 @@ HTMLTableRowElement::HTMLTableRowElement(DOM::Document& document, DOM::Qualified HTMLTableRowElement::~HTMLTableRowElement() = default; // https://html.spec.whatwg.org/multipage/tables.html#dom-tr-cells -NonnullRefPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const +JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableRowElement::cells() const { // The cells attribute must return an HTMLCollection rooted at this tr element, // whose filter matches only td and th elements that are children of the tr element. @@ -42,7 +42,7 @@ int HTMLTableRowElement::row_index() const // or a parent tbody, thead, or tfoot element and a grandparent table element, // return the index of this tr element in that table element's rows collection. // If there is no such table element, then the attribute must return −1. - auto rows_collection = [&]() -> RefPtr<DOM::HTMLCollection> { + auto rows_collection = [&]() -> JS::GCPtr<DOM::HTMLCollection> { if (!parent()) return nullptr; if (is<HTMLTableElement>(*parent())) @@ -67,7 +67,7 @@ int HTMLTableRowElement::section_row_index() const // return the index of the tr element in the parent element's rows collection // (for tables, that's HTMLTableElement's rows collection; for table sections, that's HTMLTableSectionElement's rows collection). // If there is no such parent element, then the attribute must return −1. - auto rows_collection = [&]() -> RefPtr<DOM::HTMLCollection> { + auto rows_collection = [&]() -> JS::GCPtr<DOM::HTMLCollection> { if (!parent()) return nullptr; if (is<HTMLTableElement>(*parent())) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h index 03b6cb1eb2..9a31461347 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableRowElement.h @@ -16,7 +16,7 @@ class HTMLTableRowElement final : public HTMLElement { public: virtual ~HTMLTableRowElement() override; - NonnullRefPtr<DOM::HTMLCollection> cells() const; + JS::NonnullGCPtr<DOM::HTMLCollection> cells() const; int row_index() const; int section_row_index() const; diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp index 6e66c9d33c..cc227cae63 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.cpp @@ -24,7 +24,7 @@ HTMLTableSectionElement::HTMLTableSectionElement(DOM::Document& document, DOM::Q HTMLTableSectionElement::~HTMLTableSectionElement() = default; // https://html.spec.whatwg.org/multipage/tables.html#dom-tbody-rows -NonnullRefPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const +JS::NonnullGCPtr<DOM::HTMLCollection> HTMLTableSectionElement::rows() const { // The rows attribute must return an HTMLCollection rooted at this element, // whose filter matches only tr elements that are children of this element. diff --git a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h index 112a92a9ff..69974cb09e 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLTableSectionElement.h @@ -17,7 +17,7 @@ class HTMLTableSectionElement final : public HTMLElement { public: virtual ~HTMLTableSectionElement() override; - NonnullRefPtr<DOM::HTMLCollection> rows() const; + JS::NonnullGCPtr<DOM::HTMLCollection> rows() const; DOM::ExceptionOr<JS::NonnullGCPtr<HTMLTableRowElement>> insert_row(long index); DOM::ExceptionOr<void> delete_row(long index); |