aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/script/dom/documentorshadowroot.rs2
-rw-r--r--components/script/dom/node.rs6
-rw-r--r--components/script/dom/shadowroot.rs32
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<Node> {
- let mut a = DomRoot::from_ref(&*a);
+ pub fn retarget(&self, b: &Node) -> DomRoot<Node> {
+ let mut a = DomRoot::from_ref(&*self);
loop {
+ // Step 1.
let a_root = a.GetRootNode(&GetRootNodeOptions::empty());
if !a_root.is::<ShadowRoot>() || a_root.is_shadow_including_inclusive_ancestor_of(b) {
return DomRoot::from_ref(&a);
}
+ // Step 2.
a = DomRoot::from_ref(
a_root
.downcast::<ShadowRoot>()
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<f64>, y: Finite<f64>) -> Option<DomRoot<Element>> {
- // 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::<Node>().retarget(e.upcast::<Node>());
+ retargeted_node
+ .downcast::<Element>()
+ .map(|n| DomRoot::from_ref(n))
+ },
+ None => None,
+ }
}
// https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint
fn ElementsFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Vec<DomRoot<Element>> {
- // 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::<Node>().retarget(e.upcast::<Node>());
+ if let Some(element) = retargeted_node
+ .downcast::<Element>()
+ .map(|n| DomRoot::from_ref(n)) {
+ elements.push(element);
+ }
+ }
+ elements
+
}
/// https://dom.spec.whatwg.org/#dom-shadowroot-mode