| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ui/aura/window.h" | 5 #include "ui/aura/window.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 scoped_ptr<Window> w12( | 480 scoped_ptr<Window> w12( |
| 481 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), | 481 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), |
| 482 w1.get())); | 482 w1.get())); |
| 483 scoped_ptr<Window> w121( | 483 scoped_ptr<Window> w121( |
| 484 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); | 484 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); |
| 485 scoped_ptr<Window> w13( | 485 scoped_ptr<Window> w13( |
| 486 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); | 486 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); |
| 487 | 487 |
| 488 Window* root = root_window(); | 488 Window* root = root_window(); |
| 489 w1->parent()->SetBounds(gfx::Rect(500, 500)); | 489 w1->parent()->SetBounds(gfx::Rect(500, 500)); |
| 490 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5))); | 490 EXPECT_EQ(NULL, root->GetEventHandlerForPoint( |
| 491 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11))); | 491 gfx::Point(5, 5), ui::ET_MOUSE_ENTERED)); |
| 492 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16))); | 492 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint( |
| 493 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21))); | 493 gfx::Point(11, 11), ui::ET_MOUSE_ENTERED)); |
| 494 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); | 494 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint( |
| 495 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); | 495 gfx::Point(16, 16), ui::ET_MOUSE_ENTERED)); |
| 496 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); | 496 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint( |
| 497 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); | 497 gfx::Point(21, 21), ui::ET_MOUSE_ENTERED)); |
| 498 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint( |
| 499 gfx::Point(26, 26), ui::ET_MOUSE_ENTERED)); |
| 500 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint( |
| 501 gfx::Point(21, 431), ui::ET_MOUSE_ENTERED)); |
| 502 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint( |
| 503 gfx::Point(26, 436), ui::ET_MOUSE_ENTERED)); |
| 504 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint( |
| 505 gfx::Point(26, 481), ui::ET_MOUSE_ENTERED)); |
| 498 } | 506 } |
| 499 | 507 |
| 500 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { | 508 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { |
| 501 // If our child is flush to our top-left corner he gets events just inside the | 509 // If our child is flush to our top-left corner he gets events just inside the |
| 502 // window edges. | 510 // window edges. |
| 503 scoped_ptr<Window> parent( | 511 scoped_ptr<Window> parent( |
| 504 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL)); | 512 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL)); |
| 505 scoped_ptr<Window> child( | 513 scoped_ptr<Window> child( |
| 506 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); | 514 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); |
| 507 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 515 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 508 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 516 gfx::Point(0, 0), ui::ET_MOUSE_ENTERED)); |
| 517 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 518 gfx::Point(1, 1), ui::ET_MOUSE_ENTERED)); |
| 509 | 519 |
| 510 // We can override the hit test bounds of the parent to make the parent grab | 520 // We can override the hit test bounds of the parent to make the parent grab |
| 511 // events along that edge. | 521 // events along that edge. |
| 512 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); | 522 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); |
| 513 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 523 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 514 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 524 gfx::Point(0, 0), ui::ET_MOUSE_ENTERED)); |
| 525 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 526 gfx::Point(1, 1), ui::ET_MOUSE_ENTERED)); |
| 527 } |
| 528 |
| 529 TEST_F(WindowTest, GetEventHandlerForPointWithinDraggableRegion) { |
| 530 scoped_ptr<Window> parent( |
| 531 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL)); |
| 532 scoped_ptr<Window> child( |
| 533 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), |
| 534 parent.get())); |
| 535 |
| 536 // Child should grab all mouse events if draggable region is not set. |
| 537 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 538 gfx::Point(50, 50), ui::ET_MOUSE_PRESSED)); |
| 539 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 540 gfx::Point(50, 50), ui::ET_MOUSE_DRAGGED)); |
| 541 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 542 gfx::Point(50, 50), ui::ET_MOUSE_RELEASED)); |
| 543 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 544 gfx::Point(50, 50), ui::ET_MOUSE_MOVED)); |
| 545 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 546 gfx::Point(50, 50), ui::ET_MOUSE_ENTERED)); |
| 547 |
| 548 // Create a draggable region. |
| 549 SkRegion* draggable_region = new SkRegion; |
| 550 draggable_region->setRect(10, 10, 200, 100); |
| 551 parent->SetDraggableRegion(draggable_region); |
| 552 |
| 553 // Parent should grab all mouse click/drag related events. |
| 554 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 555 gfx::Point(50, 50), ui::ET_MOUSE_PRESSED)); |
| 556 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 557 gfx::Point(50, 50), ui::ET_MOUSE_DRAGGED)); |
| 558 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 559 gfx::Point(50, 50), ui::ET_MOUSE_RELEASED)); |
| 560 |
| 561 // Child should grab all other mouse events. |
| 562 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 563 gfx::Point(50, 50), ui::ET_MOUSE_MOVED)); |
| 564 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 565 gfx::Point(50, 50), ui::ET_MOUSE_ENTERED)); |
| 515 } | 566 } |
| 516 | 567 |
| 517 TEST_F(WindowTest, GetTopWindowContainingPoint) { | 568 TEST_F(WindowTest, GetTopWindowContainingPoint) { |
| 518 Window* root = root_window(); | 569 Window* root = root_window(); |
| 519 root->SetBounds(gfx::Rect(0, 0, 300, 300)); | 570 root->SetBounds(gfx::Rect(0, 0, 300, 300)); |
| 520 | 571 |
| 521 scoped_ptr<Window> w1( | 572 scoped_ptr<Window> w1( |
| 522 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); | 573 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); |
| 523 scoped_ptr<Window> w11( | 574 scoped_ptr<Window> w11( |
| 524 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); | 575 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1161 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, | 1212 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, |
| 1162 gfx::Rect(0, 0, 500, 500), NULL)); | 1213 gfx::Rect(0, 0, 500, 500), NULL)); |
| 1163 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, | 1214 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, |
| 1164 gfx::Rect(0, 0, 500, 500), w1.get())); | 1215 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1165 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1216 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, |
| 1166 gfx::Rect(50, 50, 450, 450), w11.get())); | 1217 gfx::Rect(50, 50, 450, 450), w11.get())); |
| 1167 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, | 1218 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, |
| 1168 gfx::Rect(0, 0, 500, 500), w1.get())); | 1219 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1169 | 1220 |
| 1170 gfx::Point target_point = w111->bounds().CenterPoint(); | 1221 gfx::Point target_point = w111->bounds().CenterPoint(); |
| 1171 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point)); | 1222 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint( |
| 1223 target_point, ui::ET_MOUSE_ENTERED)); |
| 1172 } | 1224 } |
| 1173 | 1225 |
| 1174 class VisibilityWindowDelegate : public TestWindowDelegate { | 1226 class VisibilityWindowDelegate : public TestWindowDelegate { |
| 1175 public: | 1227 public: |
| 1176 VisibilityWindowDelegate() | 1228 VisibilityWindowDelegate() |
| 1177 : shown_(0), | 1229 : shown_(0), |
| 1178 hidden_(0) { | 1230 hidden_(0) { |
| 1179 } | 1231 } |
| 1180 | 1232 |
| 1181 int shown() const { return shown_; } | 1233 int shown() const { return shown_; } |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 gfx::Rect(0, 0, 500, 500), NULL)); | 1319 gfx::Rect(0, 0, 500, 500), NULL)); |
| 1268 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, | 1320 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, |
| 1269 gfx::Rect(0, 0, 500, 500), w1.get())); | 1321 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1270 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1322 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, |
| 1271 gfx::Rect(50, 50, 450, 450), w11.get())); | 1323 gfx::Rect(50, 50, 450, 450), w11.get())); |
| 1272 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, | 1324 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, |
| 1273 gfx::Rect(0, 0, 500, 500), w1.get())); | 1325 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1274 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, | 1326 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, |
| 1275 gfx::Rect(150, 150, 50, 50), w12.get())); | 1327 gfx::Rect(150, 150, 50, 50), w12.get())); |
| 1276 | 1328 |
| 1277 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); | 1329 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint( |
| 1330 gfx::Point(10, 10), ui::ET_MOUSE_ENTERED)); |
| 1278 w12->set_ignore_events(true); | 1331 w12->set_ignore_events(true); |
| 1279 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); | 1332 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint( |
| 1333 gfx::Point(10, 10), ui::ET_MOUSE_ENTERED)); |
| 1280 w12->set_ignore_events(false); | 1334 w12->set_ignore_events(false); |
| 1281 | 1335 |
| 1282 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1336 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint( |
| 1337 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1283 w121->set_ignore_events(true); | 1338 w121->set_ignore_events(true); |
| 1284 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1339 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint( |
| 1340 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1285 w12->set_ignore_events(true); | 1341 w12->set_ignore_events(true); |
| 1286 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1342 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint( |
| 1343 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1287 w111->set_ignore_events(true); | 1344 w111->set_ignore_events(true); |
| 1288 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1345 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint( |
| 1346 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1289 } | 1347 } |
| 1290 | 1348 |
| 1291 // Tests transformation on the root window. | 1349 // Tests transformation on the root window. |
| 1292 TEST_F(WindowTest, Transform) { | 1350 TEST_F(WindowTest, Transform) { |
| 1293 gfx::Size size = root_window()->GetHostSize(); | 1351 gfx::Size size = root_window()->GetHostSize(); |
| 1294 EXPECT_EQ(gfx::Rect(size), | 1352 EXPECT_EQ(gfx::Rect(size), |
| 1295 gfx::Screen::GetDisplayNearestPoint(gfx::Point()).bounds()); | 1353 gfx::Screen::GetDisplayNearestPoint(gfx::Point()).bounds()); |
| 1296 | 1354 |
| 1297 // Rotate it clock-wise 90 degrees. | 1355 // Rotate it clock-wise 90 degrees. |
| 1298 ui::Transform transform; | 1356 ui::Transform transform; |
| (...skipping 1208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2507 // Move |w2| to be a child of |w1|. | 2565 // Move |w2| to be a child of |w1|. |
| 2508 w1->AddChild(w2.get()); | 2566 w1->AddChild(w2.get()); |
| 2509 // Sine we moved in the same root, observer shouldn't be notified. | 2567 // Sine we moved in the same root, observer shouldn't be notified. |
| 2510 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2568 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
| 2511 // |w2| should still have focus after moving. | 2569 // |w2| should still have focus after moving. |
| 2512 EXPECT_TRUE(w2->HasFocus()); | 2570 EXPECT_TRUE(w2->HasFocus()); |
| 2513 } | 2571 } |
| 2514 | 2572 |
| 2515 } // namespace test | 2573 } // namespace test |
| 2516 } // namespace aura | 2574 } // namespace aura |
| OLD | NEW |