aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/script_task.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2014-11-24 20:12:17 +0530
committerManish Goregaokar <manishsmail@gmail.com>2014-12-05 18:33:03 -0800
commitc89ec3910f15f3a71be66d60da5cfd9aed1b30f1 (patch)
tree97546eded2fd8a314969e67721d689a39d52900a /components/script/script_task.rs
parente68119f82f4b0684918a76299d115b86285be97b (diff)
downloadservo-c89ec3910f15f3a71be66d60da5cfd9aed1b30f1.tar.gz
servo-c89ec3910f15f3a71be66d60da5cfd9aed1b30f1.zip
Hook up synthetic click activation to script_task and <>.click()
Diffstat (limited to 'components/script/script_task.rs')
-rw-r--r--components/script/script_task.rs19
1 files changed, 17 insertions, 2 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs
index acbd2cfbab3..9ccf7653af5 100644
--- a/components/script/script_task.rs
+++ b/components/script/script_task.rs
@@ -893,9 +893,9 @@ impl ScriptTask {
None, props.key_code).root();
let event = EventCast::from_ref(*keyevent);
let _ = target.DispatchEvent(event);
-
+ let mut prevented = event.DefaultPrevented();
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys
- if state != Released && props.is_printable() && !event.DefaultPrevented() {
+ if state != Released && props.is_printable() && !prevented {
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order
let event = KeyboardEvent::new(*window, "keypress".to_string(), true, true, Some(*window),
0, props.key.to_string(), props.code.to_string(),
@@ -904,9 +904,24 @@ impl ScriptTask {
props.char_code, 0).root();
let _ = target.DispatchEvent(EventCast::from_ref(*event));
+ let ev = EventCast::from_ref(*event);
+ prevented = ev.DefaultPrevented();
// TODO: if keypress event is canceled, prevent firing input events
}
+ // This behavior is unspecced
+ // We are supposed to dispatch synthetic click activation for Space and/or Return,
+ // however *when* we do it is up to us
+ // I'm dispatching it after the key event so the script has a chance to cancel it
+ // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337
+ match key {
+ Key::KeySpace | Key::KeyEnter if !prevented && state == Released => {
+ // TODO handle space and enter slightly differently
+ let maybe_elem: Option<JSRef<Element>> = ElementCast::to_ref(target);
+ maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.synthetic_click_activation(ctrl, alt, shift, meta)));
+ }
+ _ => ()
+ }
window.flush_layout();
}