Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "components/viz/service/hit_test/hit_test_aggregator.h" | 5 #include "components/viz/service/hit_test/hit_test_aggregator.h" |
| 6 | 6 |
| 7 #include "components/viz/common/surfaces/frame_sink_id.h" | 7 #include "components/viz/common/surfaces/frame_sink_id.h" |
| 8 #include "components/viz/common/surfaces/local_surface_id.h" | 8 #include "components/viz/common/surfaces/local_surface_id.h" |
| 9 #include "components/viz/common/surfaces/surface_id.h" | 9 #include "components/viz/common/surfaces/surface_id.h" |
| 10 #include "components/viz/host/hit_test/hit_test_query.h" | |
| 10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 11 | 12 |
| 12 namespace viz { | 13 namespace viz { |
| 13 | 14 |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 constexpr FrameSinkId kDisplayFrameSink(2, 0); | 17 constexpr FrameSinkId kDisplayFrameSink(2, 0); |
| 17 | 18 |
| 18 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { | 19 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { |
| 19 return SurfaceId( | 20 return SurfaceId( |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 68 | 69 |
| 69 class HitTestAggregatorTest : public testing::Test { | 70 class HitTestAggregatorTest : public testing::Test { |
| 70 public: | 71 public: |
| 71 HitTestAggregatorTest() = default; | 72 HitTestAggregatorTest() = default; |
| 72 ~HitTestAggregatorTest() override = default; | 73 ~HitTestAggregatorTest() override = default; |
| 73 | 74 |
| 74 // testing::Test: | 75 // testing::Test: |
| 75 void SetUp() override {} | 76 void SetUp() override {} |
| 76 void TearDown() override { aggregator_.Reset(); } | 77 void TearDown() override { aggregator_.Reset(); } |
| 77 | 78 |
| 78 TestHitTestAggregator aggregator_; | |
| 79 | |
| 80 // Creates a hit test data element with 8 children recursively to | 79 // Creates a hit test data element with 8 children recursively to |
| 81 // the specified depth. SurfaceIds are generated in sequential order and | 80 // the specified depth. SurfaceIds are generated in sequential order and |
| 82 // the method returns the next unused id. | 81 // the method returns the next unused id. |
| 83 int CreateAndSubmitHitTestRegionListWith8Children(int id, int depth) { | 82 int CreateAndSubmitHitTestRegionListWith8Children(int id, int depth) { |
| 84 SurfaceId surface_id = MakeSurfaceId(kDisplayFrameSink, id); | 83 SurfaceId surface_id = MakeSurfaceId(kDisplayFrameSink, id); |
| 85 id++; | 84 id++; |
| 86 | 85 |
| 87 auto hit_test_region_list = mojom::HitTestRegionList::New(); | 86 auto hit_test_region_list = mojom::HitTestRegionList::New(); |
| 88 hit_test_region_list->surface_id = surface_id; | 87 hit_test_region_list->surface_id = surface_id; |
| 89 hit_test_region_list->flags = mojom::kHitTestMine; | 88 hit_test_region_list->flags = mojom::kHitTestMine; |
| 90 hit_test_region_list->bounds.SetRect(0, 0, 1024, 768); | 89 hit_test_region_list->bounds.SetRect(0, 0, 1024, 768); |
| 91 | 90 |
| 92 for (int i = 0; i < 8; i++) { | 91 for (int i = 0; i < 8; i++) { |
| 93 auto hit_test_region = mojom::HitTestRegion::New(); | 92 auto hit_test_region = mojom::HitTestRegion::New(); |
| 94 hit_test_region->rect.SetRect(100, 100, 100, 100); | 93 hit_test_region->rect.SetRect(100, 100, 100, 100); |
| 95 | 94 |
| 96 if (depth > 0) { | 95 if (depth > 0) { |
| 97 hit_test_region->flags = mojom::kHitTestChildSurface; | 96 hit_test_region->flags = mojom::kHitTestChildSurface; |
| 98 hit_test_region->surface_id = MakeSurfaceId(kDisplayFrameSink, id); | 97 hit_test_region->surface_id = MakeSurfaceId(kDisplayFrameSink, id); |
| 99 id = CreateAndSubmitHitTestRegionListWith8Children(id, depth - 1); | 98 id = CreateAndSubmitHitTestRegionListWith8Children(id, depth - 1); |
| 100 } else { | 99 } else { |
| 101 hit_test_region->flags = mojom::kHitTestMine; | 100 hit_test_region->flags = mojom::kHitTestMine; |
| 102 } | 101 } |
| 103 hit_test_region_list->regions.push_back(std::move(hit_test_region)); | 102 hit_test_region_list->regions.push_back(std::move(hit_test_region)); |
| 104 } | 103 } |
| 105 | 104 |
| 106 aggregator_.SubmitHitTestRegionList(std::move(hit_test_region_list)); | 105 aggregator_.SubmitHitTestRegionList(std::move(hit_test_region_list)); |
| 107 return id; | 106 return id; |
| 108 } | 107 } |
| 108 | |
| 109 TestHitTestAggregator aggregator_; | |
| 110 HitTestQuery hit_test_query_; | |
| 109 }; | 111 }; |
| 110 | 112 |
| 111 // TODO(gklassen): Add tests for 3D use cases as suggested by and with | 113 // TODO(gklassen): Add tests for 3D use cases as suggested by and with |
| 112 // input from rjkroege. | 114 // input from rjkroege. |
| 113 | 115 |
| 114 // One surface. | 116 // One surface. |
| 115 // | 117 // |
| 116 // +----------+ | 118 // +----------+ |
| 117 // | | | 119 // | | |
| 118 // | | | 120 // | | |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 148 | 150 |
| 149 AggregatedHitTestRegion* regions = aggregator_.GetRegions(); | 151 AggregatedHitTestRegion* regions = aggregator_.GetRegions(); |
| 150 | 152 |
| 151 AggregatedHitTestRegion* region = nullptr; | 153 AggregatedHitTestRegion* region = nullptr; |
| 152 | 154 |
| 153 region = ®ions[0]; | 155 region = ®ions[0]; |
| 154 EXPECT_EQ(mojom::kHitTestMine, region->flags); | 156 EXPECT_EQ(mojom::kHitTestMine, region->flags); |
| 155 EXPECT_EQ(display_surface_id.frame_sink_id(), region->frame_sink_id); | 157 EXPECT_EQ(display_surface_id.frame_sink_id(), region->frame_sink_id); |
| 156 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect); | 158 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect); |
| 157 EXPECT_EQ(0, region->child_count); | 159 EXPECT_EQ(0, region->child_count); |
| 160 | |
| 161 hit_test_query_.set_aggregated_hit_test_region_list(regions); | |
| 162 hit_test_query_.set_aggregated_hit_test_region_list_size(1); | |
| 163 | |
| 164 // All points are in e's coordinate system when we reach this case. | |
| 165 gfx::Point point1(1, 1); | |
| 166 gfx::Point point2(1024, 768); | |
| 167 gfx::Point point3(0, 0); | |
| 168 | |
| 169 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
| 170 EXPECT_EQ(display_surface_id.frame_sink_id(), target1.frame_sink_id); | |
| 171 EXPECT_EQ(point1, target1.location_in_target); | |
| 172 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
| 173 | |
| 174 // point2 is on the bounds of e so no target found. | |
| 175 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
| 176 EXPECT_EQ(FrameSinkId(), target2.frame_sink_id); | |
| 177 EXPECT_EQ(gfx::Point(), target2.location_in_target); | |
| 178 EXPECT_FALSE(target2.flags); | |
| 179 | |
| 180 // There's a valid Target for point3, see Rect::Contains. | |
| 181 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
| 182 EXPECT_EQ(display_surface_id.frame_sink_id(), target3.frame_sink_id); | |
| 183 EXPECT_EQ(point3, target3.location_in_target); | |
| 184 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
|
gklassen
2017/07/18 13:12:57
Nice. Thank you for adding these to the test case
| |
| 158 } | 185 } |
| 159 | 186 |
| 160 // One opaque embedder with two regions. | 187 // One opaque embedder with two regions. |
| 161 // | 188 // |
| 162 // +e-------------+ | 189 // +e-------------+ |
| 163 // | +r1-+ +r2--+ | | 190 // | +r1-+ +r2--+ | |
| 164 // | | | | | | | 191 // | | | | | | |
| 165 // | | | | | | | 192 // | | | | | | |
| 166 // | +---+ +----+ | | 193 // | +---+ +----+ | |
| 167 // +--------------+ | 194 // +--------------+ |
| 168 // | 195 // |
| 169 TEST_F(HitTestAggregatorTest, OneEmbedderTwoRegions) { | 196 TEST_F(HitTestAggregatorTest, OneEmbedderTwoRegions) { |
| 170 EXPECT_EQ(0, aggregator_.Count()); | 197 EXPECT_EQ(0, aggregator_.Count()); |
| 171 | 198 |
| 172 SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); | 199 SurfaceId e_surface_id = MakeSurfaceId(kDisplayFrameSink, 1); |
| 173 | 200 |
| 174 auto e_hit_test_data = mojom::HitTestRegionList::New(); | 201 auto e_hit_test_data = mojom::HitTestRegionList::New(); |
| 175 e_hit_test_data->surface_id = e_surface_id; | 202 e_hit_test_data->surface_id = e_surface_id; |
| 176 e_hit_test_data->flags = mojom::kHitTestMine; | 203 e_hit_test_data->flags = mojom::kHitTestMine; |
| 177 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768); | 204 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768); |
| 178 | 205 |
| 179 auto e_hit_test_region_r1 = mojom::HitTestRegion::New(); | 206 auto e_hit_test_region_r1 = mojom::HitTestRegion::New(); |
| 207 e_hit_test_region_r1->surface_id = e_surface_id; | |
| 180 e_hit_test_region_r1->flags = mojom::kHitTestMine; | 208 e_hit_test_region_r1->flags = mojom::kHitTestMine; |
| 181 e_hit_test_region_r1->rect.SetRect(100, 100, 200, 400); | 209 e_hit_test_region_r1->rect.SetRect(100, 100, 200, 400); |
| 182 | 210 |
| 183 auto e_hit_test_region_r2 = mojom::HitTestRegion::New(); | 211 auto e_hit_test_region_r2 = mojom::HitTestRegion::New(); |
| 212 e_hit_test_region_r2->surface_id = e_surface_id; | |
| 184 e_hit_test_region_r2->flags = mojom::kHitTestMine; | 213 e_hit_test_region_r2->flags = mojom::kHitTestMine; |
| 185 e_hit_test_region_r2->rect.SetRect(400, 100, 300, 400); | 214 e_hit_test_region_r2->rect.SetRect(400, 100, 300, 400); |
| 186 | 215 |
| 187 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r1)); | 216 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r1)); |
| 188 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r2)); | 217 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_r2)); |
| 189 | 218 |
| 190 // Submit mojom::HitTestRegionList. | 219 // Submit mojom::HitTestRegionList. |
| 191 | 220 |
| 192 EXPECT_EQ(0, aggregator_.GetPendingCount()); | 221 EXPECT_EQ(0, aggregator_.GetPendingCount()); |
| 193 | 222 |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 222 | 251 |
| 223 region = ®ions[1]; | 252 region = ®ions[1]; |
| 224 EXPECT_EQ(mojom::kHitTestMine, region->flags); | 253 EXPECT_EQ(mojom::kHitTestMine, region->flags); |
| 225 EXPECT_EQ(gfx::Rect(100, 100, 200, 400), region->rect); | 254 EXPECT_EQ(gfx::Rect(100, 100, 200, 400), region->rect); |
| 226 EXPECT_EQ(0, region->child_count); | 255 EXPECT_EQ(0, region->child_count); |
| 227 | 256 |
| 228 region = ®ions[2]; | 257 region = ®ions[2]; |
| 229 EXPECT_EQ(mojom::kHitTestMine, region->flags); | 258 EXPECT_EQ(mojom::kHitTestMine, region->flags); |
| 230 EXPECT_EQ(gfx::Rect(400, 100, 300, 400), region->rect); | 259 EXPECT_EQ(gfx::Rect(400, 100, 300, 400), region->rect); |
| 231 EXPECT_EQ(0, region->child_count); | 260 EXPECT_EQ(0, region->child_count); |
| 261 | |
| 262 hit_test_query_.set_aggregated_hit_test_region_list(regions); | |
| 263 hit_test_query_.set_aggregated_hit_test_region_list_size(3); | |
| 264 | |
| 265 // All points are in e's coordinate system when we reach this case. | |
| 266 gfx::Point point1(99, 200); | |
| 267 gfx::Point point2(150, 150); | |
| 268 gfx::Point point3(400, 400); | |
| 269 gfx::Point point4(1200, 350); | |
| 270 | |
| 271 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
| 272 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id); | |
| 273 EXPECT_EQ(point1, target1.location_in_target); | |
| 274 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
| 275 | |
| 276 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
| 277 EXPECT_EQ(e_surface_id.frame_sink_id(), target2.frame_sink_id); | |
| 278 EXPECT_EQ(gfx::Point(50, 50), target2.location_in_target); | |
| 279 EXPECT_EQ(mojom::kHitTestMine, target2.flags); | |
| 280 | |
| 281 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
| 282 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id); | |
| 283 EXPECT_EQ(gfx::Point(0, 300), target3.location_in_target); | |
| 284 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
| 285 | |
| 286 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
| 287 EXPECT_EQ(FrameSinkId(), target4.frame_sink_id); | |
| 288 EXPECT_EQ(gfx::Point(), target4.location_in_target); | |
| 289 EXPECT_FALSE(target4.flags); | |
| 232 } | 290 } |
| 233 | 291 |
| 234 // One embedder with two children. | 292 // One embedder with two children. |
| 235 // | 293 // |
| 236 // +e-------------+ | 294 // +e-------------+ |
| 237 // | +c1-+ +c2--+ | | 295 // | +c1-+ +c2--+ | |
| 238 // | | | | | | | 296 // | | | | | | |
| 239 // | | | | | | | 297 // | | | | | | |
| 240 // | +---+ +----+ | | 298 // | +---+ +----+ | |
| 241 // +--------------+ | 299 // +--------------+ |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags); | 381 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags); |
| 324 EXPECT_EQ(c1_surface_id.frame_sink_id(), region->frame_sink_id); | 382 EXPECT_EQ(c1_surface_id.frame_sink_id(), region->frame_sink_id); |
| 325 EXPECT_EQ(gfx::Rect(100, 100, 200, 300), region->rect); | 383 EXPECT_EQ(gfx::Rect(100, 100, 200, 300), region->rect); |
| 326 EXPECT_EQ(0, region->child_count); | 384 EXPECT_EQ(0, region->child_count); |
| 327 | 385 |
| 328 region = ®ions[2]; | 386 region = ®ions[2]; |
| 329 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags); | 387 EXPECT_EQ(mojom::kHitTestChildSurface, region->flags); |
| 330 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id); | 388 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id); |
| 331 EXPECT_EQ(gfx::Rect(400, 100, 400, 300), region->rect); | 389 EXPECT_EQ(gfx::Rect(400, 100, 400, 300), region->rect); |
| 332 EXPECT_EQ(0, region->child_count); | 390 EXPECT_EQ(0, region->child_count); |
| 391 | |
| 392 hit_test_query_.set_aggregated_hit_test_region_list(regions); | |
| 393 hit_test_query_.set_aggregated_hit_test_region_list_size(3); | |
| 394 | |
| 395 // All points are in e's coordinate system when we reach this case. | |
| 396 // They all go to e since c1 and c2 cannot receive events. | |
| 397 gfx::Point point1(99, 200); | |
| 398 gfx::Point point2(150, 150); | |
| 399 gfx::Point point3(400, 400); | |
| 400 gfx::Point point4(1200, 350); | |
| 401 | |
| 402 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
| 403 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id); | |
| 404 EXPECT_EQ(point1, target1.location_in_target); | |
| 405 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
| 406 | |
| 407 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
| 408 EXPECT_EQ(e_surface_id.frame_sink_id(), target2.frame_sink_id); | |
| 409 EXPECT_EQ(point2, target2.location_in_target); | |
| 410 EXPECT_EQ(mojom::kHitTestMine, target2.flags); | |
| 411 | |
| 412 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
| 413 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id); | |
| 414 EXPECT_EQ(point3, target3.location_in_target); | |
| 415 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
| 416 | |
| 417 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
| 418 EXPECT_EQ(FrameSinkId(), target4.frame_sink_id); | |
| 419 EXPECT_EQ(gfx::Point(), target4.location_in_target); | |
| 420 EXPECT_FALSE(target4.flags); | |
| 333 } | 421 } |
| 334 | 422 |
| 335 // Occluded child frame (OOPIF). | 423 // Occluded child frame (OOPIF). |
| 336 // | 424 // |
| 337 // +e-----------+ | 425 // +e-----------+ |
| 338 // | +c--+ | | 426 // | +c--+ | |
| 339 // | | +div-+ | | 427 // | | +div-+ | |
| 340 // | | | | | | 428 // | | | | | |
| 341 // | | +----+ | | 429 // | | +----+ | |
| 342 // | +---+ | | 430 // | +---+ | |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 417 EXPECT_EQ(mojom::kHitTestMine, region->flags); | 505 EXPECT_EQ(mojom::kHitTestMine, region->flags); |
| 418 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); | 506 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); |
| 419 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect); | 507 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect); |
| 420 EXPECT_EQ(0, region->child_count); | 508 EXPECT_EQ(0, region->child_count); |
| 421 | 509 |
| 422 region = ®ions[2]; | 510 region = ®ions[2]; |
| 423 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); | 511 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); |
| 424 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); | 512 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); |
| 425 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect); | 513 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect); |
| 426 EXPECT_EQ(0, region->child_count); | 514 EXPECT_EQ(0, region->child_count); |
| 515 | |
| 516 hit_test_query_.set_aggregated_hit_test_region_list(regions); | |
| 517 hit_test_query_.set_aggregated_hit_test_region_list_size(3); | |
| 518 | |
| 519 // All points are in e's coordinate system when we reach this case. | |
| 520 gfx::Point point1(99, 200); | |
| 521 gfx::Point point2(150, 150); | |
| 522 gfx::Point point3(250, 250); | |
| 523 | |
| 524 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
| 525 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id); | |
| 526 EXPECT_EQ(point1, target1.location_in_target); | |
| 527 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
| 528 | |
| 529 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
| 530 EXPECT_EQ(c_surface_id.frame_sink_id(), target2.frame_sink_id); | |
| 531 EXPECT_EQ(gfx::Point(50, 50), target2.location_in_target); | |
| 532 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
| 533 | |
| 534 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
| 535 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id); | |
| 536 EXPECT_EQ(gfx::Point(50, 50), target3.location_in_target); | |
| 537 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
| 427 } | 538 } |
| 428 | 539 |
| 429 // Foreground child frame (OOPIF). | 540 // Foreground child frame (OOPIF). |
| 430 // Same as the previous test except the child is foreground. | 541 // Same as the previous test except the child is foreground. |
| 431 // | 542 // |
| 432 // +e-----------+ | 543 // +e-----------+ |
| 433 // | +c--+ | | 544 // | +c--+ | |
| 434 // | | |div-+ | | 545 // | | |div-+ | |
| 435 // | | | | | | 546 // | | | | | |
| 436 // | | |----+ | | 547 // | | |----+ | |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 512 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); | 623 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); |
| 513 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); | 624 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); |
| 514 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect); | 625 EXPECT_EQ(gfx::Rect(100, 100, 200, 500), region->rect); |
| 515 EXPECT_EQ(0, region->child_count); | 626 EXPECT_EQ(0, region->child_count); |
| 516 | 627 |
| 517 region = ®ions[2]; | 628 region = ®ions[2]; |
| 518 EXPECT_EQ(mojom::kHitTestMine, region->flags); | 629 EXPECT_EQ(mojom::kHitTestMine, region->flags); |
| 519 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); | 630 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); |
| 520 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect); | 631 EXPECT_EQ(gfx::Rect(200, 200, 300, 200), region->rect); |
| 521 EXPECT_EQ(0, region->child_count); | 632 EXPECT_EQ(0, region->child_count); |
| 633 | |
| 634 hit_test_query_.set_aggregated_hit_test_region_list(regions); | |
| 635 hit_test_query_.set_aggregated_hit_test_region_list_size(3); | |
| 636 | |
| 637 // All points are in e's coordinate system when we reach this case. | |
| 638 gfx::Point point1(99, 200); | |
| 639 gfx::Point point2(150, 150); | |
| 640 gfx::Point point3(250, 250); | |
| 641 gfx::Point point4(350, 300); | |
| 642 | |
| 643 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
| 644 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id); | |
| 645 EXPECT_EQ(point1, target1.location_in_target); | |
| 646 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
| 647 | |
| 648 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
| 649 EXPECT_EQ(c_surface_id.frame_sink_id(), target2.frame_sink_id); | |
| 650 EXPECT_EQ(gfx::Point(50, 50), target2.location_in_target); | |
| 651 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
| 652 | |
| 653 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
| 654 EXPECT_EQ(c_surface_id.frame_sink_id(), target3.frame_sink_id); | |
| 655 EXPECT_EQ(gfx::Point(150, 150), target3.location_in_target); | |
| 656 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target3.flags); | |
| 657 | |
| 658 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
| 659 EXPECT_EQ(e_surface_id.frame_sink_id(), target4.frame_sink_id); | |
| 660 EXPECT_EQ(gfx::Point(150, 100), target4.location_in_target); | |
| 661 EXPECT_EQ(mojom::kHitTestMine, target4.flags); | |
| 522 } | 662 } |
| 523 | 663 |
| 524 // One embedder with a clipped child with a tab and transparent background. | 664 // One embedder with a clipped child with a tab and transparent background. |
| 525 // | 665 // |
| 526 // +e-------------+ | 666 // +e-------------+ |
| 527 // | +c---------| Point maps to | 667 // | +c---------| Point maps to |
| 528 // | 1 |+a--+ | ----- ------- | 668 // | 1 |+a--+ | ----- ------- |
| 529 // | || 2 | 3 | 1 e | 669 // | || 2 | 3 | 1 e |
| 530 // | |+b--------| 2 a | 670 // | |+b--------| 2 a |
| 531 // | || | 3 e (transparent area in c) | 671 // | || | 3 e (transparent area in c) |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 542 SurfaceId b_surface_id = MakeSurfaceId(kDisplayFrameSink, 4); | 682 SurfaceId b_surface_id = MakeSurfaceId(kDisplayFrameSink, 4); |
| 543 | 683 |
| 544 auto e_hit_test_data = mojom::HitTestRegionList::New(); | 684 auto e_hit_test_data = mojom::HitTestRegionList::New(); |
| 545 e_hit_test_data->surface_id = e_surface_id; | 685 e_hit_test_data->surface_id = e_surface_id; |
| 546 e_hit_test_data->flags = mojom::kHitTestMine; | 686 e_hit_test_data->flags = mojom::kHitTestMine; |
| 547 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768); | 687 e_hit_test_data->bounds.SetRect(0, 0, 1024, 768); |
| 548 | 688 |
| 549 auto e_hit_test_region_c = mojom::HitTestRegion::New(); | 689 auto e_hit_test_region_c = mojom::HitTestRegion::New(); |
| 550 e_hit_test_region_c->flags = mojom::kHitTestChildSurface; | 690 e_hit_test_region_c->flags = mojom::kHitTestChildSurface; |
| 551 e_hit_test_region_c->surface_id = c_surface_id; | 691 e_hit_test_region_c->surface_id = c_surface_id; |
| 552 e_hit_test_region_c->rect.SetRect(200, 100, 1600, 800); | 692 e_hit_test_region_c->rect.SetRect(300, 100, 1600, 800); |
| 553 e_hit_test_region_c->transform.Translate(200, 100); | 693 e_hit_test_region_c->transform.Translate(200, 100); |
| 554 | 694 |
| 555 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c)); | 695 e_hit_test_data->regions.push_back(std::move(e_hit_test_region_c)); |
| 556 | 696 |
| 557 auto c_hit_test_data = mojom::HitTestRegionList::New(); | 697 auto c_hit_test_data = mojom::HitTestRegionList::New(); |
| 558 c_hit_test_data->surface_id = c_surface_id; | 698 c_hit_test_data->surface_id = c_surface_id; |
| 559 c_hit_test_data->flags = mojom::kHitTestIgnore; | 699 c_hit_test_data->flags = mojom::kHitTestIgnore; |
| 560 c_hit_test_data->bounds.SetRect(0, 0, 1600, 800); | 700 c_hit_test_data->bounds.SetRect(0, 0, 1600, 800); |
| 561 | 701 |
| 562 auto c_hit_test_region_a = mojom::HitTestRegion::New(); | 702 auto c_hit_test_region_a = mojom::HitTestRegion::New(); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 631 | 771 |
| 632 region = ®ions[0]; | 772 region = ®ions[0]; |
| 633 EXPECT_EQ(mojom::kHitTestMine, region->flags); | 773 EXPECT_EQ(mojom::kHitTestMine, region->flags); |
| 634 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); | 774 EXPECT_EQ(e_surface_id.frame_sink_id(), region->frame_sink_id); |
| 635 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect); | 775 EXPECT_EQ(gfx::Rect(0, 0, 1024, 768), region->rect); |
| 636 EXPECT_EQ(3, region->child_count); | 776 EXPECT_EQ(3, region->child_count); |
| 637 | 777 |
| 638 region = ®ions[1]; | 778 region = ®ions[1]; |
| 639 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestIgnore); | 779 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestIgnore); |
| 640 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); | 780 EXPECT_EQ(c_surface_id.frame_sink_id(), region->frame_sink_id); |
| 641 EXPECT_EQ(gfx::Rect(200, 100, 1600, 800), region->rect); | 781 EXPECT_EQ(gfx::Rect(300, 100, 1600, 800), region->rect); |
| 642 EXPECT_EQ(2, region->child_count); | 782 EXPECT_EQ(2, region->child_count); |
| 643 | 783 |
| 644 gfx::Point point(300, 300); | 784 gfx::Point point(300, 300); |
| 645 region->transform.TransformPointReverse(&point); | 785 region->transform.TransformPointReverse(&point); |
| 646 EXPECT_TRUE(point == gfx::Point(100, 200)); | 786 EXPECT_TRUE(point == gfx::Point(100, 200)); |
| 647 | 787 |
| 648 region = ®ions[2]; | 788 region = ®ions[2]; |
| 649 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); | 789 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); |
| 650 EXPECT_EQ(a_surface_id.frame_sink_id(), region->frame_sink_id); | 790 EXPECT_EQ(a_surface_id.frame_sink_id(), region->frame_sink_id); |
| 651 EXPECT_EQ(gfx::Rect(0, 0, 200, 100), region->rect); | 791 EXPECT_EQ(gfx::Rect(0, 0, 200, 100), region->rect); |
| 652 EXPECT_EQ(0, region->child_count); | 792 EXPECT_EQ(0, region->child_count); |
| 653 | 793 |
| 654 region = ®ions[3]; | 794 region = ®ions[3]; |
| 655 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); | 795 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); |
| 656 EXPECT_EQ(b_surface_id.frame_sink_id(), region->frame_sink_id); | 796 EXPECT_EQ(b_surface_id.frame_sink_id(), region->frame_sink_id); |
| 657 EXPECT_EQ(gfx::Rect(0, 100, 800, 600), region->rect); | 797 EXPECT_EQ(gfx::Rect(0, 100, 800, 600), region->rect); |
| 658 EXPECT_EQ(0, region->child_count); | 798 EXPECT_EQ(0, region->child_count); |
| 799 | |
| 800 hit_test_query_.set_aggregated_hit_test_region_list(regions); | |
| 801 hit_test_query_.set_aggregated_hit_test_region_list_size(4); | |
| 802 | |
| 803 // All points are in e's coordinate system when we reach this case. | |
| 804 gfx::Point point1(1, 1); | |
| 805 gfx::Point point2(100, 50); | |
| 806 gfx::Point point3(400, 70); | |
| 807 gfx::Point point4(200, 200); | |
| 808 | |
| 809 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
| 810 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id); | |
| 811 EXPECT_EQ(point1, target1.location_in_target); | |
| 812 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
| 813 | |
| 814 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
| 815 EXPECT_EQ(a_surface_id.frame_sink_id(), target2.frame_sink_id); | |
| 816 EXPECT_EQ(gfx::Point(0, 50), target2.location_in_target); | |
| 817 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
| 818 | |
| 819 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
| 820 EXPECT_EQ(e_surface_id.frame_sink_id(), target3.frame_sink_id); | |
| 821 EXPECT_EQ(point3, target3.location_in_target); | |
| 822 EXPECT_EQ(mojom::kHitTestMine, target3.flags); | |
| 823 | |
| 824 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
| 825 EXPECT_EQ(b_surface_id.frame_sink_id(), target4.frame_sink_id); | |
| 826 EXPECT_EQ(gfx::Point(100, 100), target4.location_in_target); | |
| 827 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags); | |
| 659 } | 828 } |
| 660 | 829 |
| 661 // Three children deep. | 830 // Three children deep. |
| 662 // | 831 // |
| 663 // +e------------+ | 832 // +e------------+ |
| 664 // | +c1-------+ | | 833 // | +c1-------+ | |
| 665 // | | +c2---+ | | | 834 // | | +c2---+ | | |
| 666 // | | | +c3-| | | | 835 // | | | +c3-| | | |
| 667 // | | | | | | | | 836 // | | | | | | | |
| 668 // | | | +---| | | | 837 // | | | +---| | | |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 783 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); | 952 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); |
| 784 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id); | 953 EXPECT_EQ(c2_surface_id.frame_sink_id(), region->frame_sink_id); |
| 785 EXPECT_EQ(gfx::Rect(100, 100, 500, 500), region->rect); | 954 EXPECT_EQ(gfx::Rect(100, 100, 500, 500), region->rect); |
| 786 EXPECT_EQ(1, region->child_count); | 955 EXPECT_EQ(1, region->child_count); |
| 787 | 956 |
| 788 region = ®ions[3]; | 957 region = ®ions[3]; |
| 789 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); | 958 EXPECT_EQ(region->flags, mojom::kHitTestChildSurface | mojom::kHitTestMine); |
| 790 EXPECT_EQ(c3_surface_id.frame_sink_id(), region->frame_sink_id); | 959 EXPECT_EQ(c3_surface_id.frame_sink_id(), region->frame_sink_id); |
| 791 EXPECT_EQ(gfx::Rect(100, 100, 300, 300), region->rect); | 960 EXPECT_EQ(gfx::Rect(100, 100, 300, 300), region->rect); |
| 792 EXPECT_EQ(0, region->child_count); | 961 EXPECT_EQ(0, region->child_count); |
| 962 | |
| 963 hit_test_query_.set_aggregated_hit_test_region_list(regions); | |
| 964 hit_test_query_.set_aggregated_hit_test_region_list_size(4); | |
| 965 | |
| 966 // All points are in e's coordinate system when we reach this case. | |
| 967 gfx::Point point1(1, 1); | |
| 968 gfx::Point point2(100, 150); | |
| 969 gfx::Point point3(250, 450); | |
| 970 gfx::Point point4(450, 550); | |
| 971 | |
| 972 Target target1 = hit_test_query_.FindTargetForLocation(point1); | |
| 973 EXPECT_EQ(e_surface_id.frame_sink_id(), target1.frame_sink_id); | |
| 974 EXPECT_EQ(point1, target1.location_in_target); | |
| 975 EXPECT_EQ(mojom::kHitTestMine, target1.flags); | |
| 976 | |
| 977 Target target2 = hit_test_query_.FindTargetForLocation(point2); | |
| 978 EXPECT_EQ(c3_surface_id.frame_sink_id(), target2.frame_sink_id); | |
| 979 EXPECT_EQ(gfx::Point(0, 50), target2.location_in_target); | |
| 980 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target2.flags); | |
| 981 | |
| 982 Target target3 = hit_test_query_.FindTargetForLocation(point3); | |
| 983 EXPECT_EQ(c2_surface_id.frame_sink_id(), target3.frame_sink_id); | |
| 984 EXPECT_EQ(gfx::Point(50, 250), target3.location_in_target); | |
| 985 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target3.flags); | |
| 986 | |
| 987 Target target4 = hit_test_query_.FindTargetForLocation(point4); | |
| 988 EXPECT_EQ(c1_surface_id.frame_sink_id(), target4.frame_sink_id); | |
| 989 EXPECT_EQ(gfx::Point(150, 250), target4.location_in_target); | |
| 990 EXPECT_EQ(mojom::kHitTestChildSurface | mojom::kHitTestMine, target4.flags); | |
| 793 } | 991 } |
| 794 | 992 |
| 795 // Missing / late child. | 993 // Missing / late child. |
| 796 // | 994 // |
| 797 // +e-----------+ | 995 // +e-----------+ |
| 798 // | +c--+ | | 996 // | +c--+ | |
| 799 // | | |div-+ | | 997 // | | |div-+ | |
| 800 // | | | | | | 998 // | | | | | |
| 801 // | | |----+ | | 999 // | | |----+ | |
| 802 // | +---+ | | 1000 // | +---+ | |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1008 // Discard Surface and ensure active count goes down. | 1206 // Discard Surface and ensure active count goes down. |
| 1009 | 1207 |
| 1010 aggregator_.CallOnSurfaceDiscarded(c_surface_id); | 1208 aggregator_.CallOnSurfaceDiscarded(c_surface_id); |
| 1011 EXPECT_EQ(2, aggregator_.GetActiveRegionCount()); | 1209 EXPECT_EQ(2, aggregator_.GetActiveRegionCount()); |
| 1012 | 1210 |
| 1013 aggregator_.CallOnSurfaceDiscarded(e_surface_id); | 1211 aggregator_.CallOnSurfaceDiscarded(e_surface_id); |
| 1014 EXPECT_EQ(0, aggregator_.GetActiveRegionCount()); | 1212 EXPECT_EQ(0, aggregator_.GetActiveRegionCount()); |
| 1015 } | 1213 } |
| 1016 | 1214 |
| 1017 } // namespace viz | 1215 } // namespace viz |
| OLD | NEW |