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

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

Issue 2933493003: Add viz-host HitTestQuery. (Closed)
Patch Set: comments 48-50 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 return false;
40 }
41
42 gfx::Point location_in_target(location_transformed);
43 location_in_target.Offset(-region->rect.x(), -region->rect.y());
44 while (child_region < child_region_end) {
45 if (FindTargetInRegionForLocation(location_in_target, child_region,
46 target)) {
47 return true;
48 }
49
50 child_region = child_region + child_region->child_count + 1;
51 }
52
53 if (region->flags & mojom::kHitTestMine) {
54 target->frame_sink_id = region->frame_sink_id;
55 target->location_in_target = location_in_target;
56 target->flags = region->flags;
57 return true;
58 }
59 return false;
60 }
61
62 } // namespace viz
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698