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

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

Issue 2933493003: Add viz-host HitTestQuery. (Closed)
Patch Set: more check for |child_count| 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 #include "services/viz/hit_test/public/interfaces/hit_test_region_list.mojom.h"
8
9 namespace viz {
10
11 HitTestQuery::HitTestQuery() = default;
12
13 HitTestQuery::~HitTestQuery() = default;
14
15 Target HitTestQuery::FindTargetForLocation(const gfx::Point& location_in_root) {
16 Target target;
17 if (!aggregated_hit_test_region_list_size_)
18 return target;
19
20 FindTargetInRegionForLocation(location_in_root,
21 aggregated_hit_test_region_list_, &target);
22 return target;
23 }
24
25 bool HitTestQuery::FindTargetInRegionForLocation(
26 const gfx::Point& location_in_parent,
27 AggregatedHitTestRegion* region,
28 Target* target) const {
29 gfx::Point location_transformed(location_in_parent);
30 region->transform.TransformPoint(&location_transformed);
31 if (!region->rect.Contains(location_transformed))
32 return false;
33
34 AggregatedHitTestRegion* child_region = region + 1;
35 AggregatedHitTestRegion* child_region_end =
36 child_region + region->child_count;
37 if (child_region_end > (aggregated_hit_test_region_list_ +
38 aggregated_hit_test_region_list_size_) ||
39 child_region_end < child_region) {
40 return false;
41 }
42
43 gfx::Point location_in_target(location_transformed);
44 location_in_target.Offset(-region->rect.x(), -region->rect.y());
45 while (child_region < child_region_end) {
46 if (FindTargetInRegionForLocation(location_in_target, child_region,
47 target)) {
48 return true;
49 }
50
51 AggregatedHitTestRegion* next_child_region =
52 child_region + child_region->child_count + 1;
53 if (next_child_region <= child_region)
54 return false;
55 child_region = next_child_region;
56 }
57
58 if (region->flags & mojom::kHitTestMine) {
59 target->frame_sink_id = region->frame_sink_id;
60 target->location_in_target = location_in_target;
61 target->flags = region->flags;
62 return true;
63 }
64 return false;
65 }
66
67 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698