| 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 <limits.h> | 7 #include <limits.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 scoped_ptr<Window> w11( | 351 scoped_ptr<Window> w11( |
| 352 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 352 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 353 scoped_ptr<Window> w111( | 353 scoped_ptr<Window> w111( |
| 354 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 354 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 355 scoped_ptr<Window> w1111( | 355 scoped_ptr<Window> w1111( |
| 356 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 356 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 357 | 357 |
| 358 Window* root = root_window(); | 358 Window* root = root_window(); |
| 359 root->MoveCursorTo(gfx::Point(10, 10)); | 359 root->MoveCursorTo(gfx::Point(10, 10)); |
| 360 EXPECT_EQ("10,10", | 360 EXPECT_EQ("10,10", |
| 361 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 361 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 362 w1->MoveCursorTo(gfx::Point(10, 10)); | 362 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 363 EXPECT_EQ("20,20", | 363 EXPECT_EQ("20,20", |
| 364 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 364 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 365 w11->MoveCursorTo(gfx::Point(10, 10)); | 365 w11->MoveCursorTo(gfx::Point(10, 10)); |
| 366 EXPECT_EQ("25,25", | 366 EXPECT_EQ("25,25", |
| 367 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 367 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 368 w111->MoveCursorTo(gfx::Point(10, 10)); | 368 w111->MoveCursorTo(gfx::Point(10, 10)); |
| 369 EXPECT_EQ("30,30", | 369 EXPECT_EQ("30,30", |
| 370 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 370 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 371 w1111->MoveCursorTo(gfx::Point(10, 10)); | 371 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 372 EXPECT_EQ("35,35", | 372 EXPECT_EQ("35,35", |
| 373 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 373 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 374 } | 374 } |
| 375 | 375 |
| 376 TEST_F(WindowTest, ContainsMouse) { | 376 TEST_F(WindowTest, ContainsMouse) { |
| 377 scoped_ptr<Window> w( | 377 scoped_ptr<Window> w( |
| 378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 379 root_window())); | 379 root_window())); |
| 380 w->Show(); | 380 w->Show(); |
| 381 WindowTestApi w_test_api(w.get()); | 381 WindowTestApi w_test_api(w.get()); |
| 382 Window* root = root_window(); | 382 Window* root = root_window(); |
| 383 root->MoveCursorTo(gfx::Point(10, 10)); | 383 root->MoveCursorTo(gfx::Point(10, 10)); |
| 384 EXPECT_TRUE(w_test_api.ContainsMouse()); | 384 EXPECT_TRUE(w_test_api.ContainsMouse()); |
| 385 root->MoveCursorTo(gfx::Point(9, 10)); | 385 root->MoveCursorTo(gfx::Point(9, 10)); |
| 386 EXPECT_FALSE(w_test_api.ContainsMouse()); | 386 EXPECT_FALSE(w_test_api.ContainsMouse()); |
| 387 } | 387 } |
| 388 | 388 |
| 389 // Test Window::ConvertPointToWindow() with transform to root_window. | 389 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 390 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { | 390 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { |
| 391 gfx::Transform transform; | 391 gfx::Transform transform; |
| 392 transform.Translate(100.0, 100.0); | 392 transform.Translate(100.0, 100.0); |
| 393 transform.Rotate(90.0); | 393 transform.Rotate(90.0); |
| 394 transform.Scale(2.0, 5.0); | 394 transform.Scale(2.0, 5.0); |
| 395 host()->SetRootTransform(transform); | 395 host()->SetRootTransform(transform); |
| 396 host()->MoveCursorTo(gfx::Point(10, 10)); | 396 host()->MoveCursorTo(gfx::Point(10, 10)); |
| 397 #if !defined(OS_WIN) | 397 #if !defined(OS_WIN) |
| 398 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD | 398 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD |
| 399 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); | 399 EXPECT_EQ("50,120", QueryLatestMousePositionRequestInHost(host()).ToString()); |
| 400 #endif | 400 #endif |
| 401 EXPECT_EQ("10,10", gfx::Screen::GetScreenFor( | 401 EXPECT_EQ("10,10", |
| 402 root_window())->GetCursorScreenPoint().ToString()); | 402 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 403 } | 403 } |
| 404 | 404 |
| 405 // Tests Window::ConvertPointToWindow() with transform to non-root windows. | 405 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
| 406 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { | 406 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { |
| 407 scoped_ptr<Window> w1( | 407 scoped_ptr<Window> w1( |
| 408 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 408 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 409 root_window())); | 409 root_window())); |
| 410 | 410 |
| 411 gfx::Transform transform1; | 411 gfx::Transform transform1; |
| 412 transform1.Scale(2, 2); | 412 transform1.Scale(2, 2); |
| 413 w1->SetTransform(transform1); | 413 w1->SetTransform(transform1); |
| 414 w1->MoveCursorTo(gfx::Point(10, 10)); | 414 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 415 EXPECT_EQ("30,30", | 415 EXPECT_EQ("30,30", |
| 416 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 416 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 417 | 417 |
| 418 gfx::Transform transform2; | 418 gfx::Transform transform2; |
| 419 transform2.Translate(-10, 20); | 419 transform2.Translate(-10, 20); |
| 420 w1->SetTransform(transform2); | 420 w1->SetTransform(transform2); |
| 421 w1->MoveCursorTo(gfx::Point(10, 10)); | 421 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 422 EXPECT_EQ("10,40", | 422 EXPECT_EQ("10,40", |
| 423 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 423 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 424 | 424 |
| 425 gfx::Transform transform3; | 425 gfx::Transform transform3; |
| 426 transform3.Rotate(90.0); | 426 transform3.Rotate(90.0); |
| 427 w1->SetTransform(transform3); | 427 w1->SetTransform(transform3); |
| 428 w1->MoveCursorTo(gfx::Point(5, 5)); | 428 w1->MoveCursorTo(gfx::Point(5, 5)); |
| 429 EXPECT_EQ("5,15", | 429 EXPECT_EQ("5,15", |
| 430 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 430 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 431 | 431 |
| 432 gfx::Transform transform4; | 432 gfx::Transform transform4; |
| 433 transform4.Translate(100.0, 100.0); | 433 transform4.Translate(100.0, 100.0); |
| 434 transform4.Rotate(90.0); | 434 transform4.Rotate(90.0); |
| 435 transform4.Scale(2.0, 5.0); | 435 transform4.Scale(2.0, 5.0); |
| 436 w1->SetTransform(transform4); | 436 w1->SetTransform(transform4); |
| 437 w1->MoveCursorTo(gfx::Point(10, 10)); | 437 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 438 EXPECT_EQ("60,130", | 438 EXPECT_EQ("60,130", |
| 439 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 439 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 440 } | 440 } |
| 441 | 441 |
| 442 // Test Window::ConvertPointToWindow() with complex transforms to both root and | 442 // Test Window::ConvertPointToWindow() with complex transforms to both root and |
| 443 // non-root windows. | 443 // non-root windows. |
| 444 // Test Window::ConvertPointToWindow() with transform to root_window. | 444 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 445 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { | 445 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { |
| 446 scoped_ptr<Window> w1( | 446 scoped_ptr<Window> w1( |
| 447 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 447 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 448 root_window())); | 448 root_window())); |
| 449 scoped_ptr<Window> w11( | 449 scoped_ptr<Window> w11( |
| 450 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 450 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 451 scoped_ptr<Window> w111( | 451 scoped_ptr<Window> w111( |
| 452 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 452 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 453 scoped_ptr<Window> w1111( | 453 scoped_ptr<Window> w1111( |
| 454 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 454 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 455 | 455 |
| 456 Window* root = root_window(); | |
| 457 | |
| 458 // The root window expects transforms that produce integer rects. | 456 // The root window expects transforms that produce integer rects. |
| 459 gfx::Transform root_transform; | 457 gfx::Transform root_transform; |
| 460 root_transform.Translate(60.0, 70.0); | 458 root_transform.Translate(60.0, 70.0); |
| 461 root_transform.Rotate(-90.0); | 459 root_transform.Rotate(-90.0); |
| 462 root_transform.Translate(-50.0, -50.0); | 460 root_transform.Translate(-50.0, -50.0); |
| 463 root_transform.Scale(2.0, 3.0); | 461 root_transform.Scale(2.0, 3.0); |
| 464 | 462 |
| 465 gfx::Transform transform; | 463 gfx::Transform transform; |
| 466 transform.Translate(10.0, 20.0); | 464 transform.Translate(10.0, 20.0); |
| 467 transform.Rotate(10.0); | 465 transform.Rotate(10.0); |
| 468 transform.Scale(0.3f, 0.5f); | 466 transform.Scale(0.3f, 0.5f); |
| 469 host()->SetRootTransform(root_transform); | 467 host()->SetRootTransform(root_transform); |
| 470 w1->SetTransform(transform); | 468 w1->SetTransform(transform); |
| 471 w11->SetTransform(transform); | 469 w11->SetTransform(transform); |
| 472 w111->SetTransform(transform); | 470 w111->SetTransform(transform); |
| 473 w1111->SetTransform(transform); | 471 w1111->SetTransform(transform); |
| 474 | 472 |
| 475 w1111->MoveCursorTo(gfx::Point(10, 10)); | 473 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 476 | 474 |
| 477 #if !defined(OS_WIN) | 475 #if !defined(OS_WIN) |
| 478 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. | 476 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. |
| 479 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); | 477 EXPECT_EQ("169,80", QueryLatestMousePositionRequestInHost(host()).ToString()); |
| 480 #endif | 478 #endif |
| 481 EXPECT_EQ("20,53", | 479 EXPECT_EQ("20,53", |
| 482 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 480 gfx::Screen::GetScreen()->GetCursorScreenPoint().ToString()); |
| 483 } | 481 } |
| 484 | 482 |
| 485 // Tests that we do not crash when a Window is destroyed by going out of | 483 // Tests that we do not crash when a Window is destroyed by going out of |
| 486 // scope (as opposed to being explicitly deleted by its WindowDelegate). | 484 // scope (as opposed to being explicitly deleted by its WindowDelegate). |
| 487 TEST_F(WindowTest, NoCrashOnWindowDelete) { | 485 TEST_F(WindowTest, NoCrashOnWindowDelete) { |
| 488 CaptureWindowDelegateImpl delegate; | 486 CaptureWindowDelegateImpl delegate; |
| 489 scoped_ptr<Window> window(CreateTestWindowWithDelegate( | 487 scoped_ptr<Window> window(CreateTestWindowWithDelegate( |
| 490 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); | 488 &delegate, 0, gfx::Rect(0, 0, 20, 20), root_window())); |
| 491 } | 489 } |
| 492 | 490 |
| (...skipping 1088 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1581 w12->set_ignore_events(true); | 1579 w12->set_ignore_events(true); |
| 1582 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1580 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1583 w111->set_ignore_events(true); | 1581 w111->set_ignore_events(true); |
| 1584 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1582 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1585 } | 1583 } |
| 1586 | 1584 |
| 1587 // Tests transformation on the root window. | 1585 // Tests transformation on the root window. |
| 1588 TEST_F(WindowTest, Transform) { | 1586 TEST_F(WindowTest, Transform) { |
| 1589 gfx::Size size = host()->GetBounds().size(); | 1587 gfx::Size size = host()->GetBounds().size(); |
| 1590 EXPECT_EQ(gfx::Rect(size), | 1588 EXPECT_EQ(gfx::Rect(size), |
| 1591 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( | 1589 gfx::Screen::GetScreen()->GetDisplayNearestPoint( |
| 1592 gfx::Point()).bounds()); | 1590 gfx::Point()).bounds()); |
| 1593 | 1591 |
| 1594 // Rotate it clock-wise 90 degrees. | 1592 // Rotate it clock-wise 90 degrees. |
| 1595 gfx::Transform transform; | 1593 gfx::Transform transform; |
| 1596 transform.Translate(size.height(), 0); | 1594 transform.Translate(size.height(), 0); |
| 1597 transform.Rotate(90.0); | 1595 transform.Rotate(90.0); |
| 1598 host()->SetRootTransform(transform); | 1596 host()->SetRootTransform(transform); |
| 1599 | 1597 |
| 1600 // The size should be the transformed size. | 1598 // The size should be the transformed size. |
| 1601 gfx::Size transformed_size(size.height(), size.width()); | 1599 gfx::Size transformed_size(size.height(), size.width()); |
| 1602 EXPECT_EQ(transformed_size.ToString(), | 1600 EXPECT_EQ(transformed_size.ToString(), |
| 1603 root_window()->bounds().size().ToString()); | 1601 root_window()->bounds().size().ToString()); |
| 1604 EXPECT_EQ( | 1602 EXPECT_EQ( |
| 1605 gfx::Rect(transformed_size).ToString(), | 1603 gfx::Rect(transformed_size).ToString(), |
| 1606 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( | 1604 gfx::Screen::GetScreen()->GetDisplayNearestPoint( |
| 1607 gfx::Point()).bounds().ToString()); | 1605 gfx::Point()).bounds().ToString()); |
| 1608 | 1606 |
| 1609 // Host size shouldn't change. | 1607 // Host size shouldn't change. |
| 1610 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); | 1608 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); |
| 1611 } | 1609 } |
| 1612 | 1610 |
| 1613 TEST_F(WindowTest, TransformGesture) { | 1611 TEST_F(WindowTest, TransformGesture) { |
| 1614 gfx::Size size = host()->GetBounds().size(); | 1612 gfx::Size size = host()->GetBounds().size(); |
| 1615 | 1613 |
| 1616 scoped_ptr<GestureTrackPositionDelegate> delegate( | 1614 scoped_ptr<GestureTrackPositionDelegate> delegate( |
| (...skipping 1307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2924 | 2922 |
| 2925 EXPECT_TRUE(animator.get()); | 2923 EXPECT_TRUE(animator.get()); |
| 2926 EXPECT_FALSE(animator->is_animating()); | 2924 EXPECT_FALSE(animator->is_animating()); |
| 2927 EXPECT_TRUE(observer.animation_completed()); | 2925 EXPECT_TRUE(observer.animation_completed()); |
| 2928 EXPECT_FALSE(observer.animation_aborted()); | 2926 EXPECT_FALSE(observer.animation_aborted()); |
| 2929 animator->RemoveObserver(&observer); | 2927 animator->RemoveObserver(&observer); |
| 2930 } | 2928 } |
| 2931 | 2929 |
| 2932 } // namespace test | 2930 } // namespace test |
| 2933 } // namespace aura | 2931 } // namespace aura |
| OLD | NEW |