| Index: components/viz/host/hit_test/hit_test_query.cc
|
| diff --git a/components/viz/host/hit_test/hit_test_query.cc b/components/viz/host/hit_test/hit_test_query.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..485fec3f0dfd898e4a1446bd50cb3a6fbc37a1fb
|
| --- /dev/null
|
| +++ b/components/viz/host/hit_test/hit_test_query.cc
|
| @@ -0,0 +1,67 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "components/viz/host/hit_test/hit_test_query.h"
|
| +
|
| +#include "services/viz/hit_test/public/interfaces/hit_test_region_list.mojom.h"
|
| +
|
| +namespace viz {
|
| +
|
| +HitTestQuery::HitTestQuery() = default;
|
| +
|
| +HitTestQuery::~HitTestQuery() = default;
|
| +
|
| +Target HitTestQuery::FindTargetForLocation(const gfx::Point& location_in_root) {
|
| + Target target;
|
| + if (!aggregated_hit_test_region_list_size_)
|
| + return target;
|
| +
|
| + FindTargetInRegionForLocation(location_in_root,
|
| + aggregated_hit_test_region_list_, &target);
|
| + return target;
|
| +}
|
| +
|
| +bool HitTestQuery::FindTargetInRegionForLocation(
|
| + const gfx::Point& location_in_parent,
|
| + AggregatedHitTestRegion* region,
|
| + Target* target) const {
|
| + gfx::Point location_transformed(location_in_parent);
|
| + region->transform.TransformPoint(&location_transformed);
|
| + if (!region->rect.Contains(location_transformed))
|
| + return false;
|
| +
|
| + AggregatedHitTestRegion* child_region = region + 1;
|
| + AggregatedHitTestRegion* child_region_end =
|
| + child_region + region->child_count;
|
| + if (child_region_end > (aggregated_hit_test_region_list_ +
|
| + aggregated_hit_test_region_list_size_) ||
|
| + child_region_end < child_region) {
|
| + return false;
|
| + }
|
| +
|
| + gfx::Point location_in_target(location_transformed);
|
| + location_in_target.Offset(-region->rect.x(), -region->rect.y());
|
| + while (child_region < child_region_end) {
|
| + if (FindTargetInRegionForLocation(location_in_target, child_region,
|
| + target)) {
|
| + return true;
|
| + }
|
| +
|
| + AggregatedHitTestRegion* next_child_region =
|
| + child_region + child_region->child_count + 1;
|
| + if (next_child_region <= child_region)
|
| + return false;
|
| + child_region = next_child_region;
|
| + }
|
| +
|
| + if (region->flags & mojom::kHitTestMine) {
|
| + target->frame_sink_id = region->frame_sink_id;
|
| + target->location_in_target = location_in_target;
|
| + target->flags = region->flags;
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +} // namespace viz
|
|
|