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..d8423c3cb3c42dc98a46cafeeb0ba8637a943da7 |
--- /dev/null |
+++ b/components/viz/host/hit_test/hit_test_query.cc |
@@ -0,0 +1,77 @@ |
+// 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 about the DisplayHitTestData received. |
+ // 1. The list is in ascending (front to back) z-order. |
+ // 2. Children count includes children of children. |
+ // 3. 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. |
+ // 4. Transform contains transform for the position. |
+ // 5. HIT_TEST_MINE means the region can receive events, i.e., not just a |
+ // bounding box. The opposite is HIT_TEST_IGNORE. |
+ DCHECK(!display_hit_test_data_list_.empty()); |
+ Target target; |
+ FindTargetForLocationInRegion(location_in_root, |
+ &display_hit_test_data_list_.front(), &target); |
+ return target; |
+} |
+ |
+bool HitTestQuery::FindTargetForLocationInRegion( |
+ const gfx::Point& location_in_region, |
+ DisplayHitTestDataRegion* region, |
+ Target* target) { |
+ gfx::Point location_transformed(location_in_region); |
sadrul
2017/06/27 03:37:54
Can you document in the header file what the coord
riajiang
2017/06/27 15:51:44
Sry it is indeed confusing. Changed FindTargetForL
|
+ if (!region->transform.IsIdentity()) |
+ region->transform.TransformPoint(&location_transformed); |
sadrul
2017/06/27 03:37:54
TransformPoint() already early-outs for identity t
riajiang
2017/06/27 15:51:44
I see, removed.
|
+ |
+ if (!region->bounds.Contains(location_transformed)) |
+ return false; |
+ |
+ DisplayHitTestDataRegion* child_region = region + 1; |
+ DisplayHitTestDataRegion* child_region_end = region + region->child_count; |
sadrul
2017/06/27 03:37:54
This code makes me nervous. We are reading data ge
riajiang
2017/06/27 15:51:44
Added check for |child_region_end|.
|
+ while (child_region <= child_region_end) { |
+ if (FindTargetForLocationInRegion(location_transformed, child_region, |
+ target)) |
+ return true; |
+ |
+ child_region = child_region + child_region->child_count + 1; |
+ } |
+ |
+ // TODO(riajiang): Use flag values defined in |
+ // https://codereview.chromium.org/2938953002/. |
+ if (region->flags) { |
+ target->id = region->id; |
+ target->location_in_target = location_transformed; |
+ target->flags = region->flags; |
+ return true; |
+ } |
+ return false; |
+} |
+ |
+} // namespace hit_test |
+} // namespace viz |