diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index 6fd1882c579..9fd94ae6690 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -29,55 +29,70 @@ pub trait Activatable { // https://html.spec.whatwg.org/multipage/#implicit-submission fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool); +} - // https://html.spec.whatwg.org/multipage/#run-synthetic-click-activation-steps - fn synthetic_click_activation(&self, +/// Whether an activation was initiated via the click() method +#[derive(PartialEq)] +pub enum ActivationSource { + FromClick, + NotFromClick, +} + +// https://html.spec.whatwg.org/multipage/#run-synthetic-click-activation-steps +pub fn synthetic_click_activation(element: &Element, ctrlKey: bool, shiftKey: bool, altKey: bool, - metaKey: bool) { - let element = self.as_element(); - // Step 1 - if element.click_in_progress() { - return; - } - // Step 2 - element.set_click_in_progress(true); - // Step 3 - self.pre_click_activation(); + metaKey: bool, + source: ActivationSource) { + // Step 1 + if element.click_in_progress() { + return; + } + // Step 2 + element.set_click_in_progress(true); + // Step 3 + let activatable = element.as_maybe_activatable(); + if let Some(a) = activatable { + a.pre_click_activation(); + } - // Step 4 - // https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event - let win = window_from_node(element); - let target = element.upcast(); - let mouse = MouseEvent::new(win.r(), - DOMString::from("click"), - EventBubbles::DoesNotBubble, - EventCancelable::NotCancelable, - Some(win.r()), - 1, - 0, - 0, - 0, - 0, - ctrlKey, - shiftKey, - altKey, - metaKey, - 0, - None); - let event = mouse.upcast::(); - event.fire(target); + // Step 4 + // https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event + let win = window_from_node(element); + let target = element.upcast::(); + let mouse = MouseEvent::new(win.r(), + DOMString::from("click"), + EventBubbles::DoesNotBubble, + EventCancelable::NotCancelable, + Some(win.r()), + 1, + 0, + 0, + 0, + 0, + ctrlKey, + shiftKey, + altKey, + metaKey, + 0, + None); + let event = mouse.upcast::(); + if source == ActivationSource::FromClick { + event.set_trusted(false); + } + target.dispatch_event(event); - // Step 5 + // Step 5 + if let Some(a) = activatable { if event.DefaultPrevented() { - self.canceled_activation(); + a.canceled_activation(); } else { // post click activation - self.activation_behavior(event, target); + a.activation_behavior(event, target); } - - // Step 6 - element.set_click_in_progress(false); } + + // Step 6 + element.set_click_in_progress(false); } diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e0f4c0c5592..db565414ce1 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -4,6 +4,7 @@ use devtools_traits::CSSError; use document_loader::{DocumentLoader, LoadType}; +use dom::activation::{ActivationSource, synthetic_click_activation}; use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; @@ -1083,9 +1084,12 @@ impl Document { Key::Space if !prevented && state == KeyState::Released => { let maybe_elem = target.downcast::(); if let Some(el) = maybe_elem { - if let Some(a) = el.as_maybe_activatable() { - a.synthetic_click_activation(ctrl, alt, shift, meta); - } + synthetic_click_activation(el, + false, + false, + false, + false, + ActivationSource::NotFromClick) } } Key::Enter if !prevented && state == KeyState::Released => { diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs index 31d4b0a8740..661fb3d6f68 100644 --- a/components/script/dom/htmlbuttonelement.rs +++ b/components/script/dom/htmlbuttonelement.rs @@ -2,7 +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::activation::{Activatable, ActivationSource, synthetic_click_activation}; use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods; @@ -256,6 +256,11 @@ impl Activatable for HTMLButtonElement { node.query_selector_iter(DOMString::from("button[type=submit]")).unwrap() .filter_map(Root::downcast::) .find(|r| r.form_owner() == owner) - .map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey)); + .map(|s| synthetic_click_activation(s.r().as_element(), + ctrlKey, + shiftKey, + altKey, + metaKey, + ActivationSource::NotFromClick)); } } diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs index 7c37c3ca9e2..aa2ee98ad1f 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.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::{ActivationSource, synthetic_click_activation}; use dom::attr::Attr; use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; @@ -9,7 +10,6 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNonNull; use dom::bindings::codegen::Bindings::HTMLElementBinding; use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods; -use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::error::{Error, ErrorResult}; use dom::bindings::inheritance::Castable; @@ -200,15 +200,14 @@ impl HTMLElementMethods for HTMLElement { // https://html.spec.whatwg.org/multipage/#dom-click fn Click(&self) { - if let Some(i) = self.downcast::() { - if i.Disabled() { - return; - } + if !self.upcast::().get_disabled_state() { + synthetic_click_activation(self.upcast::(), + false, + false, + false, + false, + ActivationSource::FromClick) } - // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27430 ? - self.upcast::() - .as_maybe_activatable() - .map(|a| a.synthetic_click_activation(false, false, false, false)); } // https://html.spec.whatwg.org/multipage/#dom-focus diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 8cce6576890..03c3bf83d0c 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use caseless::compatibility_caseless_match_str; -use dom::activation::Activatable; +use dom::activation::{Activatable, ActivationSource, synthetic_click_activation}; use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; @@ -1091,7 +1091,12 @@ impl Activatable for HTMLInputElement { match submit_button { Some(ref button) => { if button.is_instance_activatable() { - button.synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey) + synthetic_click_activation(button.as_element(), + ctrlKey, + shiftKey, + altKey, + metaKey, + ActivationSource::NotFromClick) } } None => { diff --git a/components/script/dom/htmllabelelement.rs b/components/script/dom/htmllabelelement.rs index 01e05761cf2..7042b98f0d7 100644 --- a/components/script/dom/htmllabelelement.rs +++ b/components/script/dom/htmllabelelement.rs @@ -2,7 +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::activation::{Activatable, ActivationSource, synthetic_click_activation}; use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::HTMLLabelElementBinding; use dom::bindings::codegen::Bindings::HTMLLabelElementBinding::HTMLLabelElementMethods; @@ -63,9 +63,12 @@ impl Activatable for HTMLLabelElement { // 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)); + synthetic_click_activation(self.upcast::(), + false, + false, + false, + false, + ActivationSource::NotFromClick); } // https://html.spec.whatwg.org/multipage/#implicit-submission diff --git a/tests/wpt/include.ini b/tests/wpt/include.ini index cde8875eb7a..77436641c36 100644 --- a/tests/wpt/include.ini +++ b/tests/wpt/include.ini @@ -15,6 +15,10 @@ skip: true skip: false [html] skip: false + [editing] + skip: true + [activation] + skip: false [url] skip: false [touch-events] diff --git a/tests/wpt/metadata/DOMEvents/throwing-in-listener-when-all-have-not-run-yet.html.ini b/tests/wpt/metadata/DOMEvents/throwing-in-listener-when-all-have-not-run-yet.html.ini deleted file mode 100644 index ceee767f904..00000000000 --- a/tests/wpt/metadata/DOMEvents/throwing-in-listener-when-all-have-not-run-yet.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[throwing-in-listener-when-all-have-not-run-yet.html] - type: testharness - [Throwing in event listener] - expected: FAIL - diff --git a/tests/wpt/metadata/html/editing/__dir__.ini b/tests/wpt/metadata/html/editing/__dir__.ini deleted file mode 100644 index 163ca23a12f..00000000000 --- a/tests/wpt/metadata/html/editing/__dir__.ini +++ /dev/null @@ -1 +0,0 @@ -disabled: for now