auto merge of #4374 : thiagopnts/servo/dispatch-event, r=Ms2ger

servo/pull/4369 with the right commit.
This commit is contained in:
bors-servo 2014-12-16 06:36:47 -07:00
commit 746b262ff4
7 changed files with 21 additions and 15 deletions

View file

@ -49,7 +49,7 @@ pub trait Activatable : Copy {
0, None).root();
let event: JSRef<Event> = EventCast::from_ref(*mouse);
event.set_trusted(true);
target.dispatch_event_with_target(None, event).ok();
target.dispatch_event(event);
// Step 5
if event.DefaultPrevented() {

View file

@ -1381,7 +1381,7 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
Some(elem) => {
// Step 5-6
elem.pre_click_activation();
target.dispatch_event_with_target(None, event).ok();
target.dispatch_event(event);
if !event.DefaultPrevented() {
// post click activation
elem.activation_behavior();
@ -1390,10 +1390,10 @@ impl<'a> ActivationElementHelpers<'a> for JSRef<'a, Element> {
}
}
// Step 6
None => {target.dispatch_event_with_target(None, event).ok();}
None => {target.dispatch_event(event);}
},
// Step 6
None => {target.dispatch_event_with_target(None, event).ok();}
None => {target.dispatch_event(event);}
}
// Step 7
self.set_click_in_progress(false);

View file

@ -16,6 +16,7 @@ pub fn dispatch_event<'a, 'b>(target: JSRef<'a, EventTarget>,
pseudo_target: Option<JSRef<'b, EventTarget>>,
event: JSRef<Event>) -> bool {
assert!(!event.dispatching());
assert!(event.initialized());
event.set_target(match pseudo_target {
Some(pseudo_target) => pseudo_target,

View file

@ -107,7 +107,8 @@ impl EventTarget {
pub trait EventTargetHelpers {
fn dispatch_event_with_target(self,
target: Option<JSRef<EventTarget>>,
event: JSRef<Event>) -> Fallible<bool>;
event: JSRef<Event>) -> bool;
fn dispatch_event(self, event: JSRef<Event>) -> bool;
fn set_inline_event_listener(self,
ty: DOMString,
listener: Option<EventListener>);
@ -128,11 +129,12 @@ pub trait EventTargetHelpers {
impl<'a> EventTargetHelpers for JSRef<'a, EventTarget> {
fn dispatch_event_with_target(self,
target: Option<JSRef<EventTarget>>,
event: JSRef<Event>) -> Fallible<bool> {
if event.dispatching() || !event.initialized() {
return Err(InvalidState);
}
Ok(dispatch_event(self, target, event))
event: JSRef<Event>) -> bool {
dispatch_event(self, target, event)
}
fn dispatch_event(self, event: JSRef<Event>) -> bool {
self.dispatch_event_with_target(None, event)
}
fn set_inline_event_listener(self,
@ -290,7 +292,10 @@ impl<'a> EventTargetMethods for JSRef<'a, EventTarget> {
}
fn DispatchEvent(self, event: JSRef<Event>) -> Fallible<bool> {
self.dispatch_event_with_target(None, event)
if event.dispatching() || !event.initialized() {
return Err(InvalidState);
}
Ok(self.dispatch_event(event))
}
}

View file

@ -81,7 +81,7 @@ impl MessageEvent {
scope, "message".to_string(), false, false, message,
"".to_string(), "".to_string()).root();
let event: JSRef<Event> = EventCast::from_ref(*messageevent);
target.dispatch_event_with_target(None, event).unwrap();
target.dispatch_event(event);
}
}

View file

@ -817,7 +817,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
"readystatechange".to_string(),
DoesNotBubble, Cancelable).root();
let target: JSRef<EventTarget> = EventTargetCast::from_ref(self);
target.dispatch_event_with_target(None, *event).ok();
target.dispatch_event(*event);
}
fn process_partial_response(self, progress: XHRProgress) {
@ -957,7 +957,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for JSRef<'a, XMLHttpRequest> {
EventTargetCast::from_ref(self)
};
let event: JSRef<Event> = EventCast::from_ref(*progressevent);
target.dispatch_event_with_target(None, event).ok();
target.dispatch_event(event);
}
fn dispatch_upload_progress_event(self, type_: DOMString, partial_load: Option<u64>) {

View file

@ -1070,7 +1070,7 @@ impl ScriptTask {
let event: JSRef<Event> = EventCast::from_ref(*uievent);
let wintarget: JSRef<EventTarget> = EventTargetCast::from_ref(*window);
let _ = wintarget.dispatch_event_with_target(None, event);
wintarget.dispatch_event(event);
}
None => ()
}