From d1547e3a7c7ebc1b870b65793d6387ef7f12af5f Mon Sep 17 00:00:00 2001 From: Manish Goregaokar Date: Mon, 24 Nov 2014 06:04:04 +0530 Subject: [PATCH] Move InputSubmit to Activatable --- components/script/dom/element.rs | 23 +++++------ components/script/dom/htmlinputelement.rs | 47 ++++++++++++++++++++--- 2 files changed, 54 insertions(+), 16 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 31e5358393f..2708e0def6c 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -1202,9 +1202,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { let node: JSRef = NodeCast::from_ref(*self); match node.type_id() { ElementNodeTypeId(HTMLInputElementTypeId) => { - let _element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(self).unwrap(); - // Some(element as &'a Activatable + 'a) - None + let element: &'a JSRef<'a, HTMLInputElement> = HTMLInputElementCast::to_borrowed_ref(self).unwrap(); + Some(element as &'a Activatable + 'a) }, _ => { None @@ -1222,10 +1221,15 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { // https://html.spec.whatwg.org/multipage/interaction.html#nearest-activatable-element fn nearest_activable_element(self) -> Option> { - let node: JSRef = NodeCast::from_ref(self); - node.ancestors() - .filter_map(|node| ElementCast::to_ref(node)) - .filter(|e| e.as_maybe_activatable().is_some()).next() + match self.as_maybe_activatable() { + Some(el) => Some(*el.as_element().root()), + None => { + let node: JSRef = NodeCast::from_ref(self); + node.ancestors() + .filter_map(|node| ElementCast::to_ref(node)) + .filter(|e| e.as_maybe_activatable().is_some()).next() + } + } } /// Please call this method *only* for real click events @@ -1252,11 +1256,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> { // Step 6 target.dispatch_event_with_target(None, event).ok(); e.map(|el| { - if NodeCast::from_ref(el).is_in_doc() { - return; // XXXManishearth do we need this check? - } el.as_maybe_activatable().map(|a| { - if event.DefaultPrevented() { + if !event.DefaultPrevented() { // post click activation a.activation_behavior(); } else { diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 30b4dcaa820..148beb08cab 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.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::{Attr, AttrValue, UIntAttrValue}; use dom::attr::AttrHelpers; use dom::bindings::cell::DOMRefCell; @@ -429,11 +430,6 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLInputElement> { match self.input_type.get() { InputCheckbox => self.SetChecked(!self.checked.get()), InputRadio => self.SetChecked(true), - InputSubmit => { - self.form_owner().map(|o| { - o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone())) - }); - } _ => {} } @@ -499,3 +495,44 @@ impl<'a> FormControl<'a> for JSRef<'a, HTMLInputElement> { !(self.Disabled() || self.ReadOnly()) } } + + +impl<'a> Activatable for JSRef<'a, HTMLInputElement> { + fn as_element(&self) -> Temporary { + Temporary::from_rooted(ElementCast::from_ref(*self)) + } + + // https://html.spec.whatwg.org/multipage/interaction.html#run-pre-click-activation-steps + fn pre_click_activation(&self) { + match self.input_type.get() { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + // InputSubmit => (), // No behavior defined + _ => () + } + } + + // https://html.spec.whatwg.org/multipage/interaction.html#run-canceled-activation-steps + fn canceled_activation(&self) { + match self.input_type.get() { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + // InputSubmit => (), // No behavior defined + _ => () + } + } + + // https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps + fn activation_behavior(&self) { + match self.input_type.get() { + InputSubmit => { + // https://html.spec.whatwg.org/multipage/forms.html#submit-button-state-%28type=submit%29 + // FIXME (Manishearth): + if self.mutable() /* and document owner is fully active */ { + self.form_owner().map(|o| { + o.root().submit(NotFromFormSubmitMethod, InputElement(self.clone())) + }); + } + }, + _ => () + } + } +}