Initial spec-incompliant implementation of default click action for anchor elements.

This is cherry-picked from https://github.com/mozilla/servo/pull/1688:

  * Initial spec-incompliant implementation of default click action for anchor elements.
  * Add documentation; gut the new document URL loading method
    and move it all into the new Window method.
  * Add test for default event prevention.

Original developer: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
Tetsuharu OHZEKI 2014-05-14 08:31:50 +09:00
parent c753f3ee05
commit 46d31632e0
7 changed files with 169 additions and 39 deletions

View file

@ -4,10 +4,11 @@
use dom::bindings::callback::ReportExceptions;
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast, NodeDerived};
use dom::bindings::js::{JSRef, OptionalSettable, Root};
use dom::bindings::js::{JSRef, OptionalSettable, OptionalRootable, Root};
use dom::eventtarget::{Capturing, Bubbling, EventTarget};
use dom::event::{Event, PhaseAtTarget, PhaseNone, PhaseBubbling, PhaseCapturing, EventMethods};
use dom::node::{Node, NodeHelpers};
use dom::virtualmethods::vtable_for;
// See http://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm
pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
@ -115,6 +116,22 @@ pub fn dispatch_event<'a, 'b>(target: &JSRef<'a, EventTarget>,
}
}
/* default action */
let target = event.GetTarget().root();
match target {
Some(mut target) => {
let node: Option<&mut JSRef<Node>> = NodeCast::to_mut_ref(&mut *target);
match node {
Some(node) =>{
let vtable = vtable_for(node);
vtable.handle_event(event);
}
None => {}
}
}
None => {}
}
// Root ordering restrictions mean we need to unroot the chain entries
// in the same order they were rooted.
while chain.len() > 0 {