From f9c0f2df13dcb2869c1fd03597ff91ded0de2748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 10 Aug 2016 19:33:40 -0700 Subject: [PATCH] dom: getElementsFromPoint does the hit testing on viewport coordinates. We got this wrong, I was just writing a test for #12777 when I found this. --- components/layout/query.rs | 4 +- components/script/dom/document.rs | 10 ++--- tests/wpt/mozilla/meta/MANIFEST.json | 6 +++ .../tests/mozilla/hit_test_pos_fixed.html | 42 +++++++++++++++++++ 4 files changed, 56 insertions(+), 6 deletions(-) create mode 100644 tests/wpt/mozilla/tests/mozilla/hit_test_pos_fixed.html diff --git a/components/layout/query.rs b/components/layout/query.rs index ee06f3865ba..5e0e9711c24 100644 --- a/components/layout/query.rs +++ b/components/layout/query.rs @@ -147,7 +147,9 @@ impl LayoutRPC for LayoutRPCImpl { let result = match rw_data.display_list { None => panic!("Tried to hit test without a DisplayList"), Some(ref display_list) => { - display_list.hit_test(&page_point, &client_point, &rw_data.stacking_context_scroll_offsets) + display_list.hit_test(&page_point, + &client_point, + &rw_data.stacking_context_scroll_offsets) } }; diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 5f1bf4c45cd..646b307a3e6 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1583,12 +1583,12 @@ impl Document { self.browsing_context.is_none() || !url_has_network_scheme(&self.url) } - pub fn nodes_from_point(&self, page_point: &Point2D) -> Vec { - let client_point = - Point2D::new(page_point.x - self.window.PageXOffset() as f32, - page_point.y - self.window.PageYOffset() as f32); + pub fn nodes_from_point(&self, client_point: &Point2D) -> Vec { + let page_point = + Point2D::new(client_point.x + self.window.PageXOffset() as f32, + client_point.y + self.window.PageYOffset() as f32); - self.window.layout().nodes_from_point(*page_point, client_point) + self.window.layout().nodes_from_point(page_point, *client_point) } } diff --git a/tests/wpt/mozilla/meta/MANIFEST.json b/tests/wpt/mozilla/meta/MANIFEST.json index 4291bf726aa..10eadce4697 100644 --- a/tests/wpt/mozilla/meta/MANIFEST.json +++ b/tests/wpt/mozilla/meta/MANIFEST.json @@ -6624,6 +6624,12 @@ "url": "/_mozilla/mozilla/global.html" } ], + "mozilla/hit_test_pos_fixed.html": [ + { + "path": "mozilla/hit_test_pos_fixed.html", + "url": "/_mozilla/mozilla/hit_test_pos_fixed.html" + } + ], "mozilla/htmlcollection.html": [ { "path": "mozilla/htmlcollection.html", diff --git a/tests/wpt/mozilla/tests/mozilla/hit_test_pos_fixed.html b/tests/wpt/mozilla/tests/mozilla/hit_test_pos_fixed.html new file mode 100644 index 00000000000..fd00a540a98 --- /dev/null +++ b/tests/wpt/mozilla/tests/mozilla/hit_test_pos_fixed.html @@ -0,0 +1,42 @@ + + +Hit-test of an element with position: fixed should discard scroll offset + + + +
+
+
+