mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Auto merge of #9734 - nox:finish-event-dispatch, r=Ms2ger
Fix the "get the parent" loop when dispatching event (fixes #6733) The DOM specification says: > A document's get the parent algorithm, given an event, returns null > if event's type attribute value is "load" or document does not have > a browsing context, and the document's associated Window object > otherwise. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/9734) <!-- Reviewable:end -->
This commit is contained in:
commit
d5ce8f308f
17 changed files with 66 additions and 86 deletions
|
@ -10,6 +10,7 @@ use dom::bindings::inheritance::Castable;
|
|||
use dom::bindings::js::{JS, Root, RootedReference};
|
||||
use dom::bindings::reflector::Reflectable;
|
||||
use dom::bindings::trace::RootedVec;
|
||||
use dom::document::Document;
|
||||
use dom::event::{Event, EventPhase};
|
||||
use dom::eventtarget::{CompiledEventListener, EventTarget, ListenerPhase};
|
||||
use dom::node::Node;
|
||||
|
@ -153,6 +154,13 @@ pub fn dispatch_event(target: &EventTarget, pseudo_target: Option<&EventTarget>,
|
|||
for ancestor in target_node.ancestors() {
|
||||
chain.push(JS::from_ref(ancestor.upcast()));
|
||||
}
|
||||
let top_most_ancestor_or_target =
|
||||
Root::from_ref(chain.r().last().cloned().unwrap_or(target));
|
||||
if let Some(document) = Root::downcast::<Document>(top_most_ancestor_or_target) {
|
||||
if event.type_() != atom!("load") && document.browsing_context().is_some() {
|
||||
chain.push(JS::from_ref(document.window().upcast()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dispatch_to_listeners(event, target, chain.r());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue