Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: components/viz/host/hit_test/hit_test_query.cc

Issue 2933493003: Add viz-host HitTestQuery. (Closed)
Patch Set: comments # 16 17 18 Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/viz/host/hit_test/hit_test_query.h"
6
7 namespace viz {
8 namespace hit_test {
9
10 HitTestQuery::HitTestQuery() {}
11
12 HitTestQuery::~HitTestQuery() {}
13
14 Target HitTestQuery::FindTargetForLocation(const gfx::Point& location_in_root) {
15 // TODO(riajiang): Assumptions about the DisplayHitTestDataList received.
16 // 1. The list is in ascending (front to back) z-order.
17 // 2. Children count includes children of children.
18 // 3. After applying transform to the incoming point, point is in the same
19 // coordinate system as the bounds it is comparing against.
20 // For example,
21 // +e-------------+
22 // | +c---------|
23 // | 1 |+a--+ |
24 // | || 2 | |
25 // | |+b--------|
26 // | || |
27 // | || 3 |
28 // +--------------+
29 // In this case, after applying identity transform, 1 is in the coordinate
30 // system of e; apply the transfrom-from-e-to-c and transform-from-c-to-a
31 // then we get 2 in the coordinate system of a; apply the
32 // transfrom-from-e-to-c and transform-from-c-to-b then we get 3 in the
33 // coordinate system of b.
34 // 4. Transform contains transform for the position.
35 // 5. HIT_TEST_MINE means the region can receive events, i.e., not just a
36 // bounding box. The opposite is HIT_TEST_IGNORE.
37 DCHECK(!display_hit_test_data_list_.empty());
38 Target target;
39 FindTargetInRegionForLocation(location_in_root,
40 &display_hit_test_data_list_.front(), &target);
41 return target;
42 }
43
44 bool HitTestQuery::FindTargetInRegionForLocation(
45 const gfx::Point& location_in_parent,
46 DisplayHitTestData* region,
47 Target* target) const {
48 gfx::Point location_transformed(location_in_parent);
49 region->transform.TransformPoint(&location_transformed);
50
51 if (!region->bounds.Contains(location_transformed))
52 return false;
53
54 DisplayHitTestData* child_region = region + 1;
55 DisplayHitTestData* child_region_end = region + region->child_count;
56 if (child_region_end > &display_hit_test_data_list_.back())
57 return false;
58
59 while (child_region <= child_region_end) {
60 if (FindTargetInRegionForLocation(location_transformed, child_region,
61 target))
62 return true;
63
64 child_region = child_region + child_region->child_count + 1;
65 }
66
67 // TODO(riajiang): Use flag values defined in
68 // https://codereview.chromium.org/2938953002/.
69 if (region->flags) {
70 target->id = region->id;
71 target->location_in_target = location_transformed;
72 target->flags = region->flags;
73 return true;
74 }
75 return false;
76 }
77
78 } // namespace hit_test
79 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698