Skip to content

Commit

Permalink
Add auxiliary method to EventTargetHelpers for events without target
Browse files Browse the repository at this point in the history
fixup! Add auxiliary method to EventTargetHelpers for events without target
  • Loading branch information
thiagopnts authored and Thiago Pontes committed Dec 16, 2014
1 parent 1bc2c8a commit 7948725
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
2 changes: 1 addition & 1 deletion components/script/dom/activation.rs
Expand Up @@ -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() {
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/element.rs
Expand Up @@ -1262,7 +1262,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();
Expand All @@ -1271,10 +1271,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);
Expand Down
1 change: 1 addition & 0 deletions components/script/dom/eventdispatcher.rs
Expand Up @@ -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,
Expand Down
19 changes: 12 additions & 7 deletions components/script/dom/eventtarget.rs
Expand Up @@ -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>);
Expand All @@ -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,
Expand Down Expand Up @@ -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))
}
}

Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/messageevent.rs
Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/xmlhttprequest.rs
Expand Up @@ -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) {
Expand Down Expand Up @@ -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>) {
Expand Down
2 changes: 1 addition & 1 deletion components/script/script_task.rs
Expand Up @@ -1078,7 +1078,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 => ()
}
Expand Down

5 comments on commit 7948725

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from Ms2ger
at thiagopnts@7948725

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging thiagopnts/servo/dispatch-event = 7948725 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thiagopnts/servo/dispatch-event = 7948725 merged ok, testing candidate = 746b262

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 746b262

Please sign in to comment.