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 #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( |
| 16 const gfx::Point& location_in_root) const { |
| 17 Target target; |
| 18 if (!aggregated_hit_test_region_list_size_) |
| 19 return target; |
| 20 |
| 21 FindTargetInRegionForLocation(location_in_root, |
| 22 aggregated_hit_test_region_list_, &target); |
| 23 return target; |
| 24 } |
| 25 |
| 26 bool HitTestQuery::FindTargetInRegionForLocation( |
| 27 const gfx::Point& location_in_parent, |
| 28 AggregatedHitTestRegion* region, |
| 29 Target* target) const { |
| 30 gfx::Point location_transformed(location_in_parent); |
| 31 region->transform.TransformPoint(&location_transformed); |
| 32 if (!region->rect.Contains(location_transformed)) |
| 33 return false; |
| 34 |
| 35 if (region->child_count < 0 || |
| 36 region->child_count > |
| 37 (aggregated_hit_test_region_list_ + |
| 38 aggregated_hit_test_region_list_size_ - region - 1)) { |
| 39 return false; |
| 40 } |
| 41 AggregatedHitTestRegion* child_region = region + 1; |
| 42 AggregatedHitTestRegion* child_region_end = |
| 43 child_region + region->child_count; |
| 44 gfx::Point location_in_target(location_transformed); |
| 45 location_in_target.Offset(-region->rect.x(), -region->rect.y()); |
| 46 while (child_region < child_region_end) { |
| 47 if (FindTargetInRegionForLocation(location_in_target, child_region, |
| 48 target)) { |
| 49 return true; |
| 50 } |
| 51 |
| 52 if (child_region->child_count < 0 || |
| 53 child_region->child_count >= region->child_count) { |
| 54 return false; |
| 55 } |
| 56 child_region = child_region + child_region->child_count + 1; |
| 57 } |
| 58 |
| 59 if (region->flags & mojom::kHitTestMine) { |
| 60 target->frame_sink_id = region->frame_sink_id; |
| 61 target->location_in_target = location_in_target; |
| 62 target->flags = region->flags; |
| 63 return true; |
| 64 } |
| 65 return false; |
| 66 } |
| 67 |
| 68 } // namespace viz |
OLD | NEW |