diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 0bdca0714a7..bdcc21ca158 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -42,6 +42,7 @@ use dom::htmlfieldsetelement::HTMLFieldSetElement; use dom::htmlfontelement::HTMLFontElement; use dom::htmliframeelement::HTMLIFrameElement; use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers}; +use dom::htmllabelelement::HTMLLabelElement; use dom::htmllegendelement::HTMLLegendElement; use dom::htmloptgroupelement::HTMLOptGroupElement; use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementLayoutHelpers}; @@ -1753,6 +1754,10 @@ impl Element { let element = self.downcast::().unwrap(); Some(element as &Activatable) }, + NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLabelElement)) => { + let element = self.downcast::().unwrap(); + Some(element as &Activatable) + }, _ => { None } diff --git a/components/script/dom/htmllabelelement.rs b/components/script/dom/htmllabelelement.rs index bcda8df24cc..ae1aa580cc3 100644 --- a/components/script/dom/htmllabelelement.rs +++ b/components/script/dom/htmllabelelement.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +use dom::activation::Activatable; use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::HTMLLabelElementBinding; use dom::bindings::codegen::Bindings::HTMLLabelElementBinding::HTMLLabelElementMethods; @@ -9,6 +10,8 @@ use dom::bindings::conversions::Castable; use dom::bindings::js::Root; use dom::document::Document; use dom::element::Element; +use dom::event::Event; +use dom::eventtarget::EventTarget; use dom::htmlelement::HTMLElement; use dom::htmlformelement::{FormControl, HTMLFormElement}; use dom::node::{document_from_node, Node}; @@ -40,6 +43,40 @@ impl HTMLLabelElement { } } +impl Activatable for HTMLLabelElement { + fn as_element(&self) -> &Element { + self.upcast::() + } + + fn is_instance_activatable(&self) -> bool { + return true; + } + + // https://html.spec.whatwg.org/multipage/#run-pre-click-activation-steps + // https://html.spec.whatwg.org/multipage/#the-button-element:activation-behavior + fn pre_click_activation(&self) { + } + + // https://html.spec.whatwg.org/multipage/#run-canceled-activation-steps + fn canceled_activation(&self) { + } + + // https://html.spec.whatwg.org/multipage/#run-post-click-activation-steps + fn activation_behavior(&self, _event: &Event, _target: &EventTarget) { + self.upcast::() + .as_maybe_activatable() + .map(|a| a.synthetic_click_activation(false, false, false, false)); + } + + // https://html.spec.whatwg.org/multipage/#implicit-submission + fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) { + //FIXME: Investigate and implement implicit submission for label elements + // Issue filed at https://github.com/servo/servo/issues/8263 + } + + +} + impl HTMLLabelElementMethods for HTMLLabelElement { // https://html.spec.whatwg.org/multipage/#dom-fae-form fn GetForm(&self) -> Option> {