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

Unified Diff: components/viz/host/hit_test/hit_test_query.cc

Issue 2933493003: Add viz-host HitTestQuery. (Closed)
Patch Set: don't combine uint and int; check for overflow 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 side-by-side diff with in-line comments
Download patch
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..a4bdaa618d65b2f7d570002412d5f33573b19648
--- /dev/null
+++ b/components/viz/host/hit_test/hit_test_query.cc
@@ -0,0 +1,68 @@
+// 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) const {
+ 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;
+
+ if (region->child_count < 0 ||
+ region->child_count >
+ (aggregated_hit_test_region_list_ +
+ aggregated_hit_test_region_list_size_ - region - 1)) {
+ return false;
+ }
+ AggregatedHitTestRegion* child_region = region + 1;
+ AggregatedHitTestRegion* child_region_end =
+ child_region + region->child_count;
+ 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;
+ }
+
+ if (child_region->child_count < 0 ||
+ child_region->child_count >= region->child_count) {
+ return false;
+ }
+ child_region = child_region + child_region->child_count + 1;
+ }
+
+ 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

Powered by Google App Engine
This is Rietveld 408576698