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..8d6bd206ed97247252d2cd88ed76a70e01d36ba7 |
--- /dev/null |
+++ b/components/viz/host/hit_test/hit_test_query.cc |
@@ -0,0 +1,79 @@ |
+// 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 DisplayHitTestDataList 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; |
+ FindTargetInRegionForLocation(location_in_root, |
+ &display_hit_test_data_list_.front(), &target); |
+ return target; |
+} |
+ |
+bool HitTestQuery::FindTargetInRegionForLocation( |
+ const gfx::Point& location_in_parent, |
+ DisplayHitTestData* region, |
+ Target* target) const { |
+ gfx::Point location_transformed(location_in_parent); |
+ region->transform.TransformPoint(&location_transformed); |
+ |
+ if (!region->bounds.Contains(location_transformed)) |
+ return false; |
+ |
+ DisplayHitTestData* child_region = region + 1; |
+ DisplayHitTestData* child_region_end = region + region->child_count; |
+ if (child_region_end > &display_hit_test_data_list_.back()) |
+ return false; |
+ |
+ while (child_region <= child_region_end) { |
+ if (FindTargetInRegionForLocation(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 |