mirror of
https://github.com/servo/servo.git
synced 2025-07-24 15:50:21 +01:00
Retarget result of shadowRoot.element(s)FromPoint
This commit is contained in:
parent
8641866a50
commit
07e2f41c34
3 changed files with 30 additions and 10 deletions
|
@ -155,7 +155,7 @@ impl DocumentOrShadowRoot {
|
||||||
let point = &Point2D::new(x, y);
|
let point = &Point2D::new(x, y);
|
||||||
let viewport = self.window.window_size().initial_viewport;
|
let viewport = self.window.window_size().initial_viewport;
|
||||||
|
|
||||||
if has_browsing_context {
|
if !has_browsing_context {
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1123,14 +1123,16 @@ impl Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://dom.spec.whatwg.org/#retarget
|
/// https://dom.spec.whatwg.org/#retarget
|
||||||
pub fn retarget(&self, a: &Node, b: &Node) -> DomRoot<Node> {
|
pub fn retarget(&self, b: &Node) -> DomRoot<Node> {
|
||||||
let mut a = DomRoot::from_ref(&*a);
|
let mut a = DomRoot::from_ref(&*self);
|
||||||
loop {
|
loop {
|
||||||
|
// Step 1.
|
||||||
let a_root = a.GetRootNode(&GetRootNodeOptions::empty());
|
let a_root = a.GetRootNode(&GetRootNodeOptions::empty());
|
||||||
if !a_root.is::<ShadowRoot>() || a_root.is_shadow_including_inclusive_ancestor_of(b) {
|
if !a_root.is::<ShadowRoot>() || a_root.is_shadow_including_inclusive_ancestor_of(b) {
|
||||||
return DomRoot::from_ref(&a);
|
return DomRoot::from_ref(&a);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Step 2.
|
||||||
a = DomRoot::from_ref(
|
a = DomRoot::from_ref(
|
||||||
a_root
|
a_root
|
||||||
.downcast::<ShadowRoot>()
|
.downcast::<ShadowRoot>()
|
||||||
|
|
|
@ -88,26 +88,44 @@ impl ShadowRootMethods for ShadowRoot {
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint
|
// https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint
|
||||||
fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<DomRoot<Element>> {
|
fn ElementFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Option<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
|
// and the original result as input.
|
||||||
self.document_or_shadow_root.element_from_point(
|
match self.document_or_shadow_root.element_from_point(
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
None,
|
None,
|
||||||
self.document.has_browsing_context(),
|
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
|
// https://drafts.csswg.org/cssom-view/#dom-document-elementsfrompoint
|
||||||
fn ElementsFromPoint(&self, x: Finite<f64>, y: Finite<f64>) -> Vec<DomRoot<Element>> {
|
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
|
// 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,
|
x,
|
||||||
y,
|
y,
|
||||||
None,
|
None,
|
||||||
self.document.has_browsing_context(),
|
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
|
/// https://dom.spec.whatwg.org/#dom-shadowroot-mode
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue