Skip to content

Commit

Permalink
Call synthetic_click_activation for all clicks
Browse files Browse the repository at this point in the history
Moved synthetic_click_actiavtion out of Activatable trait so it can be
called by all elements (not just activatable). Calls appropriately
from click. Also updates the isdisabled check in click to check for all
types of elements
  • Loading branch information
rebstar6 committed Mar 10, 2016
1 parent 57a96ec commit d6678a1
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 66 deletions.
95 changes: 55 additions & 40 deletions components/script/dom/activation.rs
Expand Up @@ -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);
}

/// 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
fn synthetic_click_activation(&self,
// 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>();
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::<EventTarget>();
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>();
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);
}
10 changes: 7 additions & 3 deletions components/script/dom/document.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -1077,9 +1078,12 @@ impl Document {
Key::Space if !prevented && state == KeyState::Released => {
let maybe_elem = target.downcast::<Element>();
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 => {
Expand Down
9 changes: 7 additions & 2 deletions components/script/dom/htmlbuttonelement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -256,6 +256,11 @@ impl Activatable for HTMLButtonElement {
node.query_selector_iter(DOMString::from("button[type=submit]")).unwrap()
.filter_map(Root::downcast::<HTMLButtonElement>)
.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));
}
}
17 changes: 8 additions & 9 deletions components/script/dom/htmlelement.rs
Expand Up @@ -2,14 +2,14 @@
* 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;
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;
Expand Down Expand Up @@ -182,15 +182,14 @@ impl HTMLElementMethods for HTMLElement {

// https://html.spec.whatwg.org/multipage/#dom-click
fn Click(&self) {
if let Some(i) = self.downcast::<HTMLInputElement>() {
if i.Disabled() {
return;
}
if !self.upcast::<Element>().get_disabled_state() {
synthetic_click_activation(self.upcast::<Element>(),
false,
false,
false,
false,
ActivationSource::FromClick)
}
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27430 ?
self.upcast::<Element>()
.as_maybe_activatable()
.map(|a| a.synthetic_click_activation(false, false, false, false));
}

// https://html.spec.whatwg.org/multipage/#dom-focus
Expand Down
9 changes: 7 additions & 2 deletions components/script/dom/htmlinputelement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -900,7 +900,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 => {
Expand Down
11 changes: 7 additions & 4 deletions components/script/dom/htmllabelelement.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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::<Element>()
.as_maybe_activatable()
.map(|a| a.synthetic_click_activation(false, false, false, false));
synthetic_click_activation(self.upcast::<Element>(),
false,
false,
false,
false,
ActivationSource::NotFromClick);
}

// https://html.spec.whatwg.org/multipage/#implicit-submission
Expand Down
4 changes: 4 additions & 0 deletions tests/wpt/include.ini
Expand Up @@ -15,6 +15,10 @@ skip: true
skip: false
[html]
skip: false
[editing]
skip: true
[activation]
skip: false
[url]
skip: false
[touch-events]
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion tests/wpt/metadata/html/editing/__dir__.ini

This file was deleted.

0 comments on commit d6678a1

Please sign in to comment.