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