diff options
Diffstat (limited to 'components/script/dom')
-rw-r--r-- | components/script/dom/document.rs | 29 | ||||
-rw-r--r-- | components/script/dom/window.rs | 14 |
2 files changed, 23 insertions, 20 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 9366f9e18bb..5f1bf4c45cd 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -672,9 +672,7 @@ impl Document { }; debug!("{}: at {:?}", mouse_event_type_string, client_point); - let page_point = Point2D::new(client_point.x + self.window.PageXOffset() as f32, - client_point.y + self.window.PageYOffset() as f32); - let node = match self.window.hit_test_query(page_point, false) { + let node = match self.window.hit_test_query(client_point, false) { Some(node_address) => { debug!("node address is {:?}", node_address); node::from_untrusted_node_address(js_runtime, node_address) @@ -786,9 +784,7 @@ impl Document { return; } - let page_point = Point2D::new(client_point.x + self.window.PageXOffset() as f32, - client_point.y + self.window.PageYOffset() as f32); - let node = match self.window.hit_test_query(page_point, false) { + let node = match self.window.hit_test_query(client_point, false) { Some(node_address) => node::from_untrusted_node_address(js_runtime, node_address), None => return }; @@ -864,22 +860,17 @@ impl Document { js_runtime: *mut JSRuntime, client_point: Option<Point2D<f32>>, prev_mouse_over_target: &MutNullableHeap<JS<Element>>) { - let page_point = match client_point { + let client_point = match client_point { None => { // If there's no point, there's no target under the mouse // FIXME: dispatch mouseout here. We have no point. prev_mouse_over_target.set(None); return; } - Some(ref client_point) => { - Point2D::new(client_point.x + self.window.PageXOffset() as f32, - client_point.y + self.window.PageYOffset() as f32) - } + Some(client_point) => client_point, }; - let client_point = client_point.unwrap(); - - let maybe_new_target = self.window.hit_test_query(page_point, true).and_then(|address| { + let maybe_new_target = self.window.hit_test_query(client_point, true).and_then(|address| { let node = node::from_untrusted_node_address(js_runtime, address); node.inclusive_ancestors() .filter_map(Root::downcast::<Element>) @@ -1593,7 +1584,11 @@ impl Document { } pub fn nodes_from_point(&self, page_point: &Point2D<f32>) -> Vec<UntrustedNodeAddress> { - self.window.layout().nodes_from_point(*page_point) + let client_point = + Point2D::new(page_point.x - self.window.PageXOffset() as f32, + page_point.y - self.window.PageYOffset() as f32); + + self.window.layout().nodes_from_point(*page_point, client_point) } } @@ -2824,10 +2819,10 @@ impl DocumentMethods for Document { return None; } - let js_runtime = unsafe { JS_GetRuntime(window.get_cx()) }; - match self.window.hit_test_query(*point, false) { Some(untrusted_node_address) => { + let js_runtime = unsafe { JS_GetRuntime(window.get_cx()) }; + let node = node::from_untrusted_node_address(js_runtime, untrusted_node_address); let parent_node = node.GetParentNode().unwrap(); let element_ref = node.downcast::<Element>().unwrap_or_else(|| { diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 8aaa0adcde3..e6e527aea9c 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -1271,10 +1271,18 @@ impl Window { self.layout_rpc.node_geometry().client_rect } - pub fn hit_test_query(&self, hit_test_request: Point2D<f32>, update_cursor: bool) + pub fn hit_test_query(&self, + client_point: Point2D<f32>, + update_cursor: bool) -> Option<UntrustedNodeAddress> { + let translated_point = + Point2D::new(client_point.x + self.PageXOffset() as f32, + client_point.y + self.PageYOffset() as f32); + if !self.reflow(ReflowGoal::ForScriptQuery, - ReflowQueryType::HitTestQuery(hit_test_request, update_cursor), + ReflowQueryType::HitTestQuery(translated_point, + client_point, + update_cursor), ReflowReason::Query) { return None } @@ -1770,7 +1778,7 @@ fn debug_reflow_events(id: PipelineId, goal: &ReflowGoal, query_type: &ReflowQue ReflowQueryType::NoQuery => "\tNoQuery", ReflowQueryType::ContentBoxQuery(_n) => "\tContentBoxQuery", ReflowQueryType::ContentBoxesQuery(_n) => "\tContentBoxesQuery", - ReflowQueryType::HitTestQuery(_n, _o) => "\tHitTestQuery", + ReflowQueryType::HitTestQuery(..) => "\tHitTestQuery", ReflowQueryType::NodeGeometryQuery(_n) => "\tNodeGeometryQuery", ReflowQueryType::NodeLayerIdQuery(_n) => "\tNodeLayerIdQuery", ReflowQueryType::NodeOverflowQuery(_n) => "\tNodeOverFlowQuery", |