Index: components/viz/host/hit_test/hit_test_query.cc |
diff --git a/components/viz/host/hit_test/hit_test_query.cc b/components/viz/host/hit_test/hit_test_query.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..85ee961681dd014ea894a783beb76c60679c3fa6 |
--- /dev/null |
+++ b/components/viz/host/hit_test/hit_test_query.cc |
@@ -0,0 +1,69 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "components/viz/host/hit_test/hit_test_query.h" |
+ |
+namespace viz { |
+namespace hit_test { |
+ |
+HitTestQuery::HitTestQuery() {} |
+ |
+HitTestQuery::~HitTestQuery() {} |
+ |
+Target HitTestQuery::FindTargetForLocation(const gfx::Point& location_in_root) { |
+ // TODO(riajiang): Assumptions I'm making about the list of DisplayHitTestData |
+ // 1. The list is in descending (back to front) z-order. |
+ // 2. Children regions have their own FrameSinkId, but those that are just |
+ // bounding boxes have the FrameSinkId of their parent. |
+ // 3. Children count includes children of children. |
+ // 4. After applying transform to the incoming point, point is in the same |
+ // coordinate system as the bounds it is comparing against. |
+ // For example, |
+ // +e-------------+ |
+ // | +c---------| |
+ // | 1 |+a--+ | |
+ // | || 2 | | |
+ // | |+b--------| |
+ // | || | |
+ // | || 3 | |
+ // +--------------+ |
+ // In this case, after applying identity transform, 1 is in the coordinate |
+ // system of e; apply the transfrom-from-e-to-c and transform-from-c-to-a |
+ // then we get 2 in the coordinate system of a; apply the |
+ // transfrom-from-e-to-c and transform-from-c-to-b then we get 3 in the |
+ // coordinate system of b. |
+ // 5. Transform contains transform for the position. |
+ // 6. HIT_TEST_MINE means the region can receive events, i.e., not just a |
+ // bounding box. |
+ DCHECK(!display_hit_test_data_list_.empty()); |
+ Target confirmed_target_so_far; |
+ Target tentative_target_so_far; |
+ tentative_target_so_far.location_in_target = location_in_root; |
+ |
+ for (DisplayHitTestData::const_iterator it = |
+ display_hit_test_data_list_.begin(); |
+ it != display_hit_test_data_list_.end(); ++it) { |
sadrul
2017/06/16 17:09:51
Use for (const auto& region : display_hit_test_dat
|
+ gfx::Point location(tentative_target_so_far.location_in_target); |
+ if (!it->transform.IsIdentity()) |
+ it->transform.TransformPoint(&location); |
+ if (it->bounds.Contains(location)) { |
+ tentative_target_so_far.id = it->id; |
+ tentative_target_so_far.location_in_target = location; |
+ tentative_target_so_far.flags = it->flags; |
+ // TODO(riajiang): Check properly once HitTestRegionFlags is well defined |
+ // after https://codereview.chromium.org/2908783002/. |
+ // HIT_TEST_MINE is set to be true, which means it can receive events. |
sadrul
2017/06/16 17:09:51
I would be OK with starting with a different set o
|
+ if (it->flags) |
+ confirmed_target_so_far = tentative_target_so_far; |
sadrul
2017/06/16 17:09:51
It's not clear to me yet how kHitTestIgnore flag w
riajiang
2017/06/23 02:46:36
If it's kHitTestIgnore, then that child cannot rec
|
+ if (!it->child_count) |
+ break; |
+ } else { |
+ it += it->child_count; |
+ } |
+ } |
+ return confirmed_target_so_far; |
+} |
+ |
+} // namespace hit_test |
+} // namespace viz |