| 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 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 private: | 229 private: |
| 230 gfx::Point position_; | 230 gfx::Point position_; |
| 231 | 231 |
| 232 DISALLOW_COPY_AND_ASSIGN(GestureTrackPositionDelegate); | 232 DISALLOW_COPY_AND_ASSIGN(GestureTrackPositionDelegate); |
| 233 }; | 233 }; |
| 234 | 234 |
| 235 base::TimeDelta getTime() { | 235 base::TimeDelta getTime() { |
| 236 return base::Time::NowFromSystemTime() - base::Time(); | 236 return base::Time::NowFromSystemTime() - base::Time(); |
| 237 } | 237 } |
| 238 | 238 |
| 239 class ClickthoughWindowDelegate : public TestWindowDelegate { |
| 240 public: |
| 241 ClickthoughWindowDelegate() {} |
| 242 |
| 243 virtual bool ShouldDescendIntoChildForEventHandling( |
| 244 Window* child, |
| 245 const gfx::Point& event_location, |
| 246 ui::EventType event_type) OVERRIDE { |
| 247 return event_type != ui::ET_MOUSE_PRESSED && |
| 248 event_type != ui::ET_MOUSE_DRAGGED && |
| 249 event_type != ui::ET_MOUSE_RELEASED; |
| 250 } |
| 251 |
| 252 private: |
| 253 DISALLOW_COPY_AND_ASSIGN(ClickthoughWindowDelegate); |
| 254 }; |
| 255 |
| 239 } // namespace | 256 } // namespace |
| 240 | 257 |
| 241 TEST_F(WindowTest, GetChildById) { | 258 TEST_F(WindowTest, GetChildById) { |
| 242 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); | 259 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 243 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); | 260 scoped_ptr<Window> w11(CreateTestWindowWithId(11, w1.get())); |
| 244 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); | 261 scoped_ptr<Window> w111(CreateTestWindowWithId(111, w11.get())); |
| 245 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); | 262 scoped_ptr<Window> w12(CreateTestWindowWithId(12, w1.get())); |
| 246 | 263 |
| 247 EXPECT_EQ(NULL, w1->GetChildById(57)); | 264 EXPECT_EQ(NULL, w1->GetChildById(57)); |
| 248 EXPECT_EQ(w12.get(), w1->GetChildById(12)); | 265 EXPECT_EQ(w12.get(), w1->GetChildById(12)); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 480 scoped_ptr<Window> w12( | 497 scoped_ptr<Window> w12( |
| 481 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), | 498 CreateTestWindow(SK_ColorMAGENTA, 12, gfx::Rect(10, 420, 25, 25), |
| 482 w1.get())); | 499 w1.get())); |
| 483 scoped_ptr<Window> w121( | 500 scoped_ptr<Window> w121( |
| 484 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); | 501 CreateTestWindow(SK_ColorYELLOW, 121, gfx::Rect(5, 5, 5, 5), w12.get())); |
| 485 scoped_ptr<Window> w13( | 502 scoped_ptr<Window> w13( |
| 486 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); | 503 CreateTestWindow(SK_ColorGRAY, 13, gfx::Rect(5, 470, 50, 50), w1.get())); |
| 487 | 504 |
| 488 Window* root = root_window(); | 505 Window* root = root_window(); |
| 489 w1->parent()->SetBounds(gfx::Rect(500, 500)); | 506 w1->parent()->SetBounds(gfx::Rect(500, 500)); |
| 490 EXPECT_EQ(NULL, root->GetEventHandlerForPoint(gfx::Point(5, 5))); | 507 EXPECT_EQ(NULL, root->GetEventHandlerForPoint( |
| 491 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint(gfx::Point(11, 11))); | 508 gfx::Point(5, 5), ui::ET_MOUSE_ENTERED)); |
| 492 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint(gfx::Point(16, 16))); | 509 EXPECT_EQ(w1.get(), root->GetEventHandlerForPoint( |
| 493 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint(gfx::Point(21, 21))); | 510 gfx::Point(11, 11), ui::ET_MOUSE_ENTERED)); |
| 494 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint(gfx::Point(26, 26))); | 511 EXPECT_EQ(w11.get(), root->GetEventHandlerForPoint( |
| 495 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint(gfx::Point(21, 431))); | 512 gfx::Point(16, 16), ui::ET_MOUSE_ENTERED)); |
| 496 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint(gfx::Point(26, 436))); | 513 EXPECT_EQ(w111.get(), root->GetEventHandlerForPoint( |
| 497 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint(gfx::Point(26, 481))); | 514 gfx::Point(21, 21), ui::ET_MOUSE_ENTERED)); |
| 515 EXPECT_EQ(w1111.get(), root->GetEventHandlerForPoint( |
| 516 gfx::Point(26, 26), ui::ET_MOUSE_ENTERED)); |
| 517 EXPECT_EQ(w12.get(), root->GetEventHandlerForPoint( |
| 518 gfx::Point(21, 431), ui::ET_MOUSE_ENTERED)); |
| 519 EXPECT_EQ(w121.get(), root->GetEventHandlerForPoint( |
| 520 gfx::Point(26, 436), ui::ET_MOUSE_ENTERED)); |
| 521 EXPECT_EQ(w13.get(), root->GetEventHandlerForPoint( |
| 522 gfx::Point(26, 481), ui::ET_MOUSE_ENTERED)); |
| 498 } | 523 } |
| 499 | 524 |
| 500 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { | 525 TEST_F(WindowTest, GetEventHandlerForPointWithOverride) { |
| 501 // If our child is flush to our top-left corner he gets events just inside the | 526 // If our child is flush to our top-left corner he gets events just inside the |
| 502 // window edges. | 527 // window edges. |
| 503 scoped_ptr<Window> parent( | 528 scoped_ptr<Window> parent( |
| 504 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL)); | 529 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 20, 400, 500), NULL)); |
| 505 scoped_ptr<Window> child( | 530 scoped_ptr<Window> child( |
| 506 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); | 531 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 60, 70), parent.get())); |
| 507 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 532 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 508 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 533 gfx::Point(0, 0), ui::ET_MOUSE_ENTERED)); |
| 534 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 535 gfx::Point(1, 1), ui::ET_MOUSE_ENTERED)); |
| 509 | 536 |
| 510 // We can override the hit test bounds of the parent to make the parent grab | 537 // We can override the hit test bounds of the parent to make the parent grab |
| 511 // events along that edge. | 538 // events along that edge. |
| 512 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); | 539 parent->set_hit_test_bounds_override_inner(gfx::Insets(1, 1, 1, 1)); |
| 513 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint(gfx::Point(0, 0))); | 540 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 514 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint(gfx::Point(1, 1))); | 541 gfx::Point(0, 0), ui::ET_MOUSE_ENTERED)); |
| 542 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 543 gfx::Point(1, 1), ui::ET_MOUSE_ENTERED)); |
| 544 } |
| 545 |
| 546 TEST_F(WindowTest, GetEventHandlerForPointWithinClickthroughRegion) { |
| 547 scoped_ptr<ClickthoughWindowDelegate> paren_delegate( |
| 548 new ClickthoughWindowDelegate); |
| 549 scoped_ptr<Window> parent(CreateTestWindowWithDelegate( |
| 550 paren_delegate.get(), 1, gfx::Rect(10, 20, 400, 500), NULL)); |
| 551 scoped_ptr<Window> child( |
| 552 CreateTestWindow(SK_ColorRED, 2, gfx::Rect(0, 0, 390, 480), |
| 553 parent.get())); |
| 554 |
| 555 // Parent should grab all mouse click/drag related events. |
| 556 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 557 gfx::Point(50, 50), ui::ET_MOUSE_PRESSED)); |
| 558 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 559 gfx::Point(50, 50), ui::ET_MOUSE_DRAGGED)); |
| 560 EXPECT_EQ(parent.get(), parent->GetEventHandlerForPoint( |
| 561 gfx::Point(50, 50), ui::ET_MOUSE_RELEASED)); |
| 562 |
| 563 // Child should grab all other mouse events. |
| 564 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 565 gfx::Point(50, 50), ui::ET_MOUSE_MOVED)); |
| 566 EXPECT_EQ(child.get(), parent->GetEventHandlerForPoint( |
| 567 gfx::Point(50, 50), ui::ET_MOUSE_ENTERED)); |
| 515 } | 568 } |
| 516 | 569 |
| 517 TEST_F(WindowTest, GetTopWindowContainingPoint) { | 570 TEST_F(WindowTest, GetTopWindowContainingPoint) { |
| 518 Window* root = root_window(); | 571 Window* root = root_window(); |
| 519 root->SetBounds(gfx::Rect(0, 0, 300, 300)); | 572 root->SetBounds(gfx::Rect(0, 0, 300, 300)); |
| 520 | 573 |
| 521 scoped_ptr<Window> w1( | 574 scoped_ptr<Window> w1( |
| 522 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); | 575 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 100, 100), NULL)); |
| 523 scoped_ptr<Window> w11( | 576 scoped_ptr<Window> w11( |
| 524 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(0, 0, 120, 120), w1.get())); | 577 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, | 1214 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(NULL, 1, |
| 1162 gfx::Rect(0, 0, 500, 500), NULL)); | 1215 gfx::Rect(0, 0, 500, 500), NULL)); |
| 1163 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, | 1216 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(NULL, 11, |
| 1164 gfx::Rect(0, 0, 500, 500), w1.get())); | 1217 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1165 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1218 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, |
| 1166 gfx::Rect(50, 50, 450, 450), w11.get())); | 1219 gfx::Rect(50, 50, 450, 450), w11.get())); |
| 1167 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, | 1220 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(NULL, 12, |
| 1168 gfx::Rect(0, 0, 500, 500), w1.get())); | 1221 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1169 | 1222 |
| 1170 gfx::Point target_point = w111->bounds().CenterPoint(); | 1223 gfx::Point target_point = w111->bounds().CenterPoint(); |
| 1171 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(target_point)); | 1224 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint( |
| 1225 target_point, ui::ET_MOUSE_ENTERED)); |
| 1172 } | 1226 } |
| 1173 | 1227 |
| 1174 class VisibilityWindowDelegate : public TestWindowDelegate { | 1228 class VisibilityWindowDelegate : public TestWindowDelegate { |
| 1175 public: | 1229 public: |
| 1176 VisibilityWindowDelegate() | 1230 VisibilityWindowDelegate() |
| 1177 : shown_(0), | 1231 : shown_(0), |
| 1178 hidden_(0) { | 1232 hidden_(0) { |
| 1179 } | 1233 } |
| 1180 | 1234 |
| 1181 int shown() const { return shown_; } | 1235 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)); | 1321 gfx::Rect(0, 0, 500, 500), NULL)); |
| 1268 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, | 1322 scoped_ptr<Window> w11(CreateTestWindowWithDelegate(&d11, 11, |
| 1269 gfx::Rect(0, 0, 500, 500), w1.get())); | 1323 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1270 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, | 1324 scoped_ptr<Window> w111(CreateTestWindowWithDelegate(&d111, 111, |
| 1271 gfx::Rect(50, 50, 450, 450), w11.get())); | 1325 gfx::Rect(50, 50, 450, 450), w11.get())); |
| 1272 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, | 1326 scoped_ptr<Window> w12(CreateTestWindowWithDelegate(&d12, 12, |
| 1273 gfx::Rect(0, 0, 500, 500), w1.get())); | 1327 gfx::Rect(0, 0, 500, 500), w1.get())); |
| 1274 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, | 1328 scoped_ptr<Window> w121(CreateTestWindowWithDelegate(&d121, 121, |
| 1275 gfx::Rect(150, 150, 50, 50), w12.get())); | 1329 gfx::Rect(150, 150, 50, 50), w12.get())); |
| 1276 | 1330 |
| 1277 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); | 1331 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint( |
| 1332 gfx::Point(10, 10), ui::ET_MOUSE_ENTERED)); |
| 1278 w12->set_ignore_events(true); | 1333 w12->set_ignore_events(true); |
| 1279 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(10, 10))); | 1334 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint( |
| 1335 gfx::Point(10, 10), ui::ET_MOUSE_ENTERED)); |
| 1280 w12->set_ignore_events(false); | 1336 w12->set_ignore_events(false); |
| 1281 | 1337 |
| 1282 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1338 EXPECT_EQ(w121.get(), w1->GetEventHandlerForPoint( |
| 1339 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1283 w121->set_ignore_events(true); | 1340 w121->set_ignore_events(true); |
| 1284 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1341 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint( |
| 1342 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1285 w12->set_ignore_events(true); | 1343 w12->set_ignore_events(true); |
| 1286 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1344 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint( |
| 1345 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1287 w111->set_ignore_events(true); | 1346 w111->set_ignore_events(true); |
| 1288 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1347 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint( |
| 1348 gfx::Point(160, 160), ui::ET_MOUSE_ENTERED)); |
| 1289 } | 1349 } |
| 1290 | 1350 |
| 1291 // Tests transformation on the root window. | 1351 // Tests transformation on the root window. |
| 1292 TEST_F(WindowTest, Transform) { | 1352 TEST_F(WindowTest, Transform) { |
| 1293 gfx::Size size = root_window()->GetHostSize(); | 1353 gfx::Size size = root_window()->GetHostSize(); |
| 1294 EXPECT_EQ(gfx::Rect(size), | 1354 EXPECT_EQ(gfx::Rect(size), |
| 1295 gfx::Screen::GetDisplayNearestPoint(gfx::Point()).bounds()); | 1355 gfx::Screen::GetDisplayNearestPoint(gfx::Point()).bounds()); |
| 1296 | 1356 |
| 1297 // Rotate it clock-wise 90 degrees. | 1357 // Rotate it clock-wise 90 degrees. |
| 1298 ui::Transform transform; | 1358 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|. | 2567 // Move |w2| to be a child of |w1|. |
| 2508 w1->AddChild(w2.get()); | 2568 w1->AddChild(w2.get()); |
| 2509 // Sine we moved in the same root, observer shouldn't be notified. | 2569 // Sine we moved in the same root, observer shouldn't be notified. |
| 2510 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2570 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
| 2511 // |w2| should still have focus after moving. | 2571 // |w2| should still have focus after moving. |
| 2512 EXPECT_TRUE(w2->HasFocus()); | 2572 EXPECT_TRUE(w2->HasFocus()); |
| 2513 } | 2573 } |
| 2514 | 2574 |
| 2515 } // namespace test | 2575 } // namespace test |
| 2516 } // namespace aura | 2576 } // namespace aura |
| OLD | NEW |