From 036e8dabe2d38e21348766d1a5cda99381b015f8 Mon Sep 17 00:00:00 2001 From: Patrick Shaughnessy Date: Thu, 2 Jan 2020 15:44:29 -0500 Subject: Labels are a live list in tree order --- components/script/dom/htmlbuttonelement.rs | 6 +- components/script/dom/htmlelement.rs | 70 ++++++++++++---------- components/script/dom/htmlinputelement.rs | 16 +++-- components/script/dom/htmllabelelement.rs | 50 ++++++++++++---- components/script/dom/htmlmeterelement.rs | 8 +-- components/script/dom/htmloutputelement.rs | 6 +- components/script/dom/htmlprogresselement.rs | 8 +-- components/script/dom/htmlselectelement.rs | 6 +- components/script/dom/htmltextareaelement.rs | 6 +- components/script/dom/macros.rs | 15 +++++ components/script/dom/nodelist.rs | 38 ++++++++++++ .../script/dom/webidls/HTMLInputElement.webidl | 2 +- 12 files changed, 161 insertions(+), 70 deletions(-) (limited to 'components/script') diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 6a60a88b25c..b7c7da1e9bf 100755 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -41,6 +41,7 @@ pub struct HTMLButtonElement { htmlelement: HTMLElement, button_type: Cell, form_owner: MutNullableDom, + labels_node_list: MutNullableDom, } impl HTMLButtonElement { @@ -58,6 +59,7 @@ impl HTMLButtonElement { ), button_type: Cell::new(ButtonType::Submit), form_owner: Default::default(), + labels_node_list: Default::default(), } } @@ -149,9 +151,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement { make_setter!(SetValue, "value"); // https://html.spec.whatwg.org/multipage/#dom-lfe-labels - fn Labels(&self) -> DomRoot { - self.upcast::().labels() - } + make_labels_getter!(Labels, labels_node_list); } impl HTMLButtonElement { diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 7bec738f382..c5b7e6d0251 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -4,10 +4,10 @@ use crate::dom::activation::{synthetic_click_activation, ActivationSource}; use crate::dom::attr::Attr; -use crate::dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use crate::dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use crate::dom::bindings::codegen::Bindings::HTMLElementBinding; use crate::dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; +use crate::dom::bindings::codegen::Bindings::HTMLLabelElementBinding::HTMLLabelElementMethods; use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeBinding::NodeMethods; use crate::dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use crate::dom::bindings::error::{Error, ErrorResult}; @@ -29,7 +29,6 @@ use crate::dom::htmlinputelement::{HTMLInputElement, InputType}; use crate::dom::htmllabelelement::HTMLLabelElement; use crate::dom::node::{document_from_node, window_from_node}; use crate::dom::node::{BindContext, Node, NodeFlags, ShadowIncluding}; -use crate::dom::nodelist::NodeList; use crate::dom::text::Text; use crate::dom::virtualmethods::VirtualMethods; use dom_struct::dom_struct; @@ -677,43 +676,48 @@ impl HTMLElement { } // https://html.spec.whatwg.org/multipage/#dom-lfe-labels - pub fn labels(&self) -> DomRoot { - debug_assert!(self.is_labelable_element()); - + // This gets the nth label in tree order. + pub fn label_at(&self, index: u32) -> Option> { let element = self.upcast::(); - let window = window_from_node(element); - - // Traverse ancestors for implicitly associated