Skip to content

Commit

Permalink
make the concept of has_listeners_for follow other implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
gterzian committed Aug 20, 2018
1 parent 5c8ede4 commit 1465250
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 12 deletions.
4 changes: 2 additions & 2 deletions components/script/dom/document.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1665,7 +1665,7 @@ impl Document {
let event = beforeunload_event.upcast::<Event>();
event.set_trusted(true);
let event_target = self.window.upcast::<EventTarget>();
let has_listeners = event.has_listeners_for(&event_target, &atom!("beforeunload"));
let has_listeners = event_target.has_listeners_for(&atom!("beforeunload"));
event_target.dispatch_event_with_target(
document.root().upcast(),
&event,
Expand Down Expand Up @@ -1738,7 +1738,7 @@ impl Document {
);
event.set_trusted(true);
let event_target = self.window.upcast::<EventTarget>();
let has_listeners = event.has_listeners_for(&event_target, &atom!("unload"));
let has_listeners = event_target.has_listeners_for(&atom!("unload"));
let _ = event_target.dispatch_event_with_target(
document.root().upcast(),
&event,
Expand Down
10 changes: 0 additions & 10 deletions components/script/dom/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,6 @@ impl Event {
self.cancelable.set(cancelable);
}

// Determine if there are any listeners for a given target and type.
// See https://github.com/whatwg/dom/issues/453
pub fn has_listeners_for(&self, target: &EventTarget, type_: &Atom) -> bool {
// TODO: take 'removed' into account? Not implemented in Servo yet.
// https://dom.spec.whatwg.org/#event-listener-removed
let mut event_path = self.construct_event_path(&target);
event_path.push(DomRoot::from_ref(target));
event_path.iter().any(|target| target.has_listeners_for(type_))
}

// https://dom.spec.whatwg.org/#event-path
fn construct_event_path(&self, target: &EventTarget) -> Vec<DomRoot<EventTarget>> {
let mut event_path = vec![];
Expand Down
2 changes: 2 additions & 0 deletions components/script/dom/eventtarget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ impl EventTarget {
Ok(EventTarget::new(global))
}

// Determine if there are any listeners for a given event type.
// See https://github.com/whatwg/dom/issues/453
pub fn has_listeners_for(&self,
type_: &Atom)
-> bool {
Expand Down
Empty file.

0 comments on commit 1465250

Please sign in to comment.