OLD | NEW |
---|---|
(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 DisplayHitTestData 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 FindTargetForLocationInRegion(location_in_root, | |
40 &display_hit_test_data_list_.front(), &target); | |
41 return target; | |
42 } | |
43 | |
44 bool HitTestQuery::FindTargetForLocationInRegion( | |
45 const gfx::Point& location_in_region, | |
46 DisplayHitTestDataRegion* region, | |
47 Target* target) { | |
48 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
| |
49 if (!region->transform.IsIdentity()) | |
50 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.
| |
51 | |
52 if (!region->bounds.Contains(location_transformed)) | |
53 return false; | |
54 | |
55 DisplayHitTestDataRegion* child_region = region + 1; | |
56 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|.
| |
57 while (child_region <= child_region_end) { | |
58 if (FindTargetForLocationInRegion(location_transformed, child_region, | |
59 target)) | |
60 return true; | |
61 | |
62 child_region = child_region + child_region->child_count + 1; | |
63 } | |
64 | |
65 // TODO(riajiang): Use flag values defined in | |
66 // https://codereview.chromium.org/2938953002/. | |
67 if (region->flags) { | |
68 target->id = region->id; | |
69 target->location_in_target = location_transformed; | |
70 target->flags = region->flags; | |
71 return true; | |
72 } | |
73 return false; | |
74 } | |
75 | |
76 } // namespace hit_test | |
77 } // namespace viz | |
OLD | NEW |