From 07e2f41c34d6676afd2a510cef9ea74b0fde576e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Thu, 14 Feb 2019 18:19:06 +0100 Subject: [PATCH] Retarget result of shadowRoot.element(s)FromPoint --- components/script/dom/documentorshadowroot.rs | 2 +- components/script/dom/node.rs | 6 ++-- components/script/dom/shadowroot.rs | 32 +++++++++++++++---- 3 files changed, 30 insertions(+), 10 deletions(-) diff --git a/components/script/dom/documentorshadowroot.rs b/components/script/dom/documentorshadowroot.rs index eda3432dc5a..51846baa443 100644 --- a/components/script/dom/documentorshadowroot.rs +++ b/components/script/dom/documentorshadowroot.rs @@ -155,7 +155,7 @@ impl DocumentOrShadowRoot { let point = &Point2D::new(x, y); let viewport = self.window.window_size().initial_viewport; - if has_browsing_context { + if !has_browsing_context { return vec![]; } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index e1a40c13982..7f8c2b611ce 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -1123,14 +1123,16 @@ impl Node { } /// https://dom.spec.whatwg.org/#retarget - pub fn retarget(&self, a: &Node, b: &Node) -> DomRoot { - let mut a = DomRoot::from_ref(&*a); + pub fn retarget(&self, b: &Node) -> DomRoot { + let mut a = DomRoot::from_ref(&*self); loop { + // Step 1. let a_root = a.GetRootNode(&GetRootNodeOptions::empty()); if !a_root.is::() || a_root.is_shadow_including_inclusive_ancestor_of(b) { return DomRoot::from_ref(&a); } + // Step 2. a = DomRoot::from_ref( a_root .downcast::() diff --git a/components/script/dom/shadowroot.rs b/components/script/dom/shadowroot.rs index aad85d4d087..a5d67ea30cc 100644 --- a/components/script/dom/shadowroot.rs +++ b/components/script/dom/shadowroot.rs @@ -88,26 +88,44 @@ impl ShadowRootMethods for ShadowRoot { // https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint fn ElementFromPoint(&self, x: Finite, y: Finite) -> Option> { - // XXX return the result of running the retargeting algorithm with context object - // and the original result as input - self.document_or_shadow_root.element_from_point( + // Return the result of running the retargeting algorithm with context object + // and the original result as input. + match self.document_or_shadow_root.element_from_point( x, y, None, self.document.has_browsing_context(), - ) + ) { + Some(e) => { + let retargeted_node = self.upcast::().retarget(e.upcast::()); + retargeted_node + .downcast::() + .map(|n| DomRoot::from_ref(n)) + }, + None => None, + } } // https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint fn ElementsFromPoint(&self, x: Finite, y: Finite) -> Vec> { - // XXX return the result of running the retargeting algorithm with context object + // Return the result of running the retargeting algorithm with context object // and the original result as input - self.document_or_shadow_root.elements_from_point( + let mut elements = Vec::new(); + for e in self.document_or_shadow_root.elements_from_point( x, y, None, self.document.has_browsing_context(), - ) + ).iter() { + let retargeted_node = self.upcast::().retarget(e.upcast::()); + if let Some(element) = retargeted_node + .downcast::() + .map(|n| DomRoot::from_ref(n)) { + elements.push(element); + } + } + elements + } /// https://dom.spec.whatwg.org/#dom-shadowroot-mode