Some reorganization of activation code:

- Make method name apply to trait implementor better (When a user agent is to run post-click activation steps on an element, it must run the activation behavior defined for that element)
 - Mention invariants and conditions on authentic_click_activation
This commit is contained in:
Manish Goregaokar 2014-11-23 08:28:05 +05:30
parent 03207dea81
commit 2ed9626f1a
2 changed files with 17 additions and 4 deletions

View file

@ -23,7 +23,7 @@ pub trait Activatable : Copy {
fn canceled_activation(&self);
// https://html.spec.whatwg.org/multipage/interaction.html#run-post-click-activation-steps
fn post_click_activation(&self);
fn activation_behavior(&self);
// https://html.spec.whatwg.org/multipage/interaction.html#run-synthetic-click-activation-steps
fn synthetic_click_activation(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
@ -52,7 +52,8 @@ pub trait Activatable : Copy {
if event.DefaultPrevented() {
self.canceled_activation();
} else {
self.post_click_activation();
// post click activation
self.activation_behavior();
}
// Step 6

View file

@ -1228,8 +1228,19 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
.filter(|e| e.as_maybe_activatable().is_some()).next()
}
// https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps
/// Please call this method *only* for real click events
///
/// https://html.spec.whatwg.org/multipage/interaction.html#run-authentic-click-activation-steps
///
/// Use an element's synthetic click activation (or handle_event) for any script-triggered clicks.
/// If the spec says otherwise, check with Manishearth first
fn authentic_click_activation<'b>(self, event: JSRef<'b, Event>) {
// Not explicitly part of the spec, however this helps enforce the invariants
// required to save state between pre-activation and post-activation
// Since we cannot nest authentic clicks (unlike synthetic click activation, where
// the script can generate more click events from the handler)
assert!(!self.click_in_progress());
let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
// Step 2 (requires canvas support)
// Step 3
@ -1246,7 +1257,8 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
}
el.as_maybe_activatable().map(|a| {
if event.DefaultPrevented() {
a.post_click_activation();
// post click activation
a.activation_behavior();
} else {
a.canceled_activation();
}