mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Add Page::hit_test().
This commit is contained in:
parent
7d511f4baf
commit
fff94a35b3
1 changed files with 26 additions and 13 deletions
|
@ -26,6 +26,7 @@ use layout_interface::{DocumentDamageLevel, HitTestQuery, HitTestResponse, Layou
|
||||||
use layout_interface::{LayoutChan, MatchSelectorsDocumentDamage, QueryMsg};
|
use layout_interface::{LayoutChan, MatchSelectorsDocumentDamage, QueryMsg};
|
||||||
use layout_interface::{Reflow, ReflowDocumentDamage, ReflowForDisplay, ReflowGoal, ReflowMsg};
|
use layout_interface::{Reflow, ReflowDocumentDamage, ReflowForDisplay, ReflowGoal, ReflowMsg};
|
||||||
use layout_interface::ContentChangedDocumentDamage;
|
use layout_interface::ContentChangedDocumentDamage;
|
||||||
|
use layout_interface::UntrustedNodeAddress;
|
||||||
use layout_interface;
|
use layout_interface;
|
||||||
|
|
||||||
use geom::point::Point2D;
|
use geom::point::Point2D;
|
||||||
|
@ -435,6 +436,27 @@ impl Page {
|
||||||
js_context: Untraceable::new(js_context),
|
js_context: Untraceable::new(js_context),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn hit_test(&self, point: &Point2D<f32>) -> Option<UntrustedNodeAddress> {
|
||||||
|
let frame = self.frame();
|
||||||
|
let document = frame.get_ref().document.clone();
|
||||||
|
let root = document.get().GetDocumentElement();
|
||||||
|
if root.is_none() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
let root: JS<Node> = NodeCast::from(&root.unwrap());
|
||||||
|
let (chan, port) = channel();
|
||||||
|
let address = match self.query_layout(HitTestQuery(root.to_trusted_node_address(), *point, chan), port) {
|
||||||
|
Ok(HitTestResponse(node_address)) => {
|
||||||
|
Some(node_address)
|
||||||
|
}
|
||||||
|
Err(()) => {
|
||||||
|
debug!("layout query error");
|
||||||
|
None
|
||||||
|
}
|
||||||
|
};
|
||||||
|
address
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information for one frame in the browsing context.
|
/// Information for one frame in the browsing context.
|
||||||
|
@ -1031,17 +1053,8 @@ impl ScriptTask {
|
||||||
|
|
||||||
ClickEvent(_button, point) => {
|
ClickEvent(_button, point) => {
|
||||||
debug!("ClickEvent: clicked at {:?}", point);
|
debug!("ClickEvent: clicked at {:?}", point);
|
||||||
|
match page.hit_test(&point) {
|
||||||
let frame = page.frame();
|
Some(node_address) => {
|
||||||
let document = frame.get_ref().document.clone();
|
|
||||||
let root = document.get().GetDocumentElement();
|
|
||||||
if root.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let (chan, port) = channel();
|
|
||||||
let root: JS<Node> = NodeCast::from(&root.unwrap());
|
|
||||||
match page.query_layout(HitTestQuery(root.to_trusted_node_address(), point, chan), port) {
|
|
||||||
Ok(HitTestResponse(node_address)) => {
|
|
||||||
debug!("node address is {:?}", node_address);
|
debug!("node address is {:?}", node_address);
|
||||||
let mut node: JS<Node> =
|
let mut node: JS<Node> =
|
||||||
NodeHelpers::from_untrusted_node_address(self.js_runtime.deref().ptr,
|
NodeHelpers::from_untrusted_node_address(self.js_runtime.deref().ptr,
|
||||||
|
@ -1063,8 +1076,8 @@ impl ScriptTask {
|
||||||
self.load_url_from_element(page, &element)
|
self.load_url_from_element(page, &element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
Err(()) => debug!("layout query error"),
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
MouseDownEvent(..) => {}
|
MouseDownEvent(..) => {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue