| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 #if defined(USE_OZONE) | 363 #if defined(USE_OZONE) |
| 364 // TODO(rjkroege): Add cursor support in ozone: http://crbug.com/252315. | 364 // TODO(rjkroege): Add cursor support in ozone: http://crbug.com/252315. |
| 365 TEST_F(WindowTest, DISABLED_MoveCursorToWithTransformRootWindow) { | 365 TEST_F(WindowTest, DISABLED_MoveCursorToWithTransformRootWindow) { |
| 366 #else | 366 #else |
| 367 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { | 367 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { |
| 368 #endif | 368 #endif |
| 369 gfx::Transform transform; | 369 gfx::Transform transform; |
| 370 transform.Translate(100.0, 100.0); | 370 transform.Translate(100.0, 100.0); |
| 371 transform.Rotate(90.0); | 371 transform.Rotate(90.0); |
| 372 transform.Scale(2.0, 5.0); | 372 transform.Scale(2.0, 5.0); |
| 373 dispatcher()->host()->SetTransform(transform); | 373 host()->SetTransform(transform); |
| 374 dispatcher()->host()->MoveCursorTo(gfx::Point(10, 10)); | 374 host()->MoveCursorTo(gfx::Point(10, 10)); |
| 375 #if !defined(OS_WIN) | 375 #if !defined(OS_WIN) |
| 376 gfx::Point mouse_location; | 376 gfx::Point mouse_location; |
| 377 EXPECT_TRUE(dispatcher()->host()->QueryMouseLocation(&mouse_location)); | 377 EXPECT_TRUE(host()->QueryMouseLocation(&mouse_location)); |
| 378 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD | 378 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD |
| 379 EXPECT_EQ("50,120", mouse_location.ToString()); | 379 EXPECT_EQ("50,120", mouse_location.ToString()); |
| 380 #endif | 380 #endif |
| 381 EXPECT_EQ("10,10", gfx::Screen::GetScreenFor( | 381 EXPECT_EQ("10,10", gfx::Screen::GetScreenFor( |
| 382 root_window())->GetCursorScreenPoint().ToString()); | 382 root_window())->GetCursorScreenPoint().ToString()); |
| 383 } | 383 } |
| 384 | 384 |
| 385 // Tests Window::ConvertPointToWindow() with transform to non-root windows. | 385 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
| 386 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { | 386 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { |
| 387 scoped_ptr<Window> w1( | 387 scoped_ptr<Window> w1( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 gfx::Transform root_transform; | 444 gfx::Transform root_transform; |
| 445 root_transform.Translate(60.0, 70.0); | 445 root_transform.Translate(60.0, 70.0); |
| 446 root_transform.Rotate(-90.0); | 446 root_transform.Rotate(-90.0); |
| 447 root_transform.Translate(-50.0, -50.0); | 447 root_transform.Translate(-50.0, -50.0); |
| 448 root_transform.Scale(2.0, 3.0); | 448 root_transform.Scale(2.0, 3.0); |
| 449 | 449 |
| 450 gfx::Transform transform; | 450 gfx::Transform transform; |
| 451 transform.Translate(10.0, 20.0); | 451 transform.Translate(10.0, 20.0); |
| 452 transform.Rotate(10.0); | 452 transform.Rotate(10.0); |
| 453 transform.Scale(0.3f, 0.5f); | 453 transform.Scale(0.3f, 0.5f); |
| 454 dispatcher()->host()->SetTransform(root_transform); | 454 host()->SetTransform(root_transform); |
| 455 w1->SetTransform(transform); | 455 w1->SetTransform(transform); |
| 456 w11->SetTransform(transform); | 456 w11->SetTransform(transform); |
| 457 w111->SetTransform(transform); | 457 w111->SetTransform(transform); |
| 458 w1111->SetTransform(transform); | 458 w1111->SetTransform(transform); |
| 459 | 459 |
| 460 w1111->MoveCursorTo(gfx::Point(10, 10)); | 460 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 461 | 461 |
| 462 #if !defined(OS_WIN) | 462 #if !defined(OS_WIN) |
| 463 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. | 463 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413. |
| 464 gfx::Point mouse_location; | 464 gfx::Point mouse_location; |
| 465 EXPECT_TRUE(dispatcher()->host()->QueryMouseLocation(&mouse_location)); | 465 EXPECT_TRUE(host()->QueryMouseLocation(&mouse_location)); |
| 466 EXPECT_EQ("169,80", mouse_location.ToString()); | 466 EXPECT_EQ("169,80", mouse_location.ToString()); |
| 467 #endif | 467 #endif |
| 468 EXPECT_EQ("20,53", | 468 EXPECT_EQ("20,53", |
| 469 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 469 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 470 } | 470 } |
| 471 | 471 |
| 472 TEST_F(WindowTest, GetEventHandlerForPoint) { | 472 TEST_F(WindowTest, GetEventHandlerForPoint) { |
| 473 scoped_ptr<Window> w1( | 473 scoped_ptr<Window> w1( |
| 474 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), | 474 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), |
| 475 root_window())); | 475 root_window())); |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 EXPECT_FALSE(window->HasCapture()); | 1061 EXPECT_FALSE(window->HasCapture()); |
| 1062 | 1062 |
| 1063 // Do a capture. | 1063 // Do a capture. |
| 1064 window->SetCapture(); | 1064 window->SetCapture(); |
| 1065 EXPECT_TRUE(window->HasCapture()); | 1065 EXPECT_TRUE(window->HasCapture()); |
| 1066 | 1066 |
| 1067 // Destroy the window. | 1067 // Destroy the window. |
| 1068 window.reset(); | 1068 window.reset(); |
| 1069 | 1069 |
| 1070 // Make sure the root window doesn't reference the window anymore. | 1070 // Make sure the root window doesn't reference the window anymore. |
| 1071 EXPECT_EQ(NULL, dispatcher()->mouse_pressed_handler()); | 1071 EXPECT_EQ(NULL, host()->dispatcher()->mouse_pressed_handler()); |
| 1072 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); | 1072 EXPECT_EQ(NULL, aura::client::GetCaptureWindow(root_window())); |
| 1073 } | 1073 } |
| 1074 | 1074 |
| 1075 TEST_F(WindowTest, GetBoundsInRootWindow) { | 1075 TEST_F(WindowTest, GetBoundsInRootWindow) { |
| 1076 scoped_ptr<Window> viewport(CreateTestWindowWithBounds( | 1076 scoped_ptr<Window> viewport(CreateTestWindowWithBounds( |
| 1077 gfx::Rect(0, 0, 300, 300), root_window())); | 1077 gfx::Rect(0, 0, 300, 300), root_window())); |
| 1078 scoped_ptr<Window> child(CreateTestWindowWithBounds( | 1078 scoped_ptr<Window> child(CreateTestWindowWithBounds( |
| 1079 gfx::Rect(0, 0, 100, 100), viewport.get())); | 1079 gfx::Rect(0, 0, 100, 100), viewport.get())); |
| 1080 // Sanity check. | 1080 // Sanity check. |
| 1081 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); | 1081 EXPECT_EQ("0,0 100x100", child->GetBoundsInRootWindow().ToString()); |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 w121->set_ignore_events(true); | 1478 w121->set_ignore_events(true); |
| 1479 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1479 EXPECT_EQ(w12.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1480 w12->set_ignore_events(true); | 1480 w12->set_ignore_events(true); |
| 1481 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1481 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1482 w111->set_ignore_events(true); | 1482 w111->set_ignore_events(true); |
| 1483 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1483 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1484 } | 1484 } |
| 1485 | 1485 |
| 1486 // Tests transformation on the root window. | 1486 // Tests transformation on the root window. |
| 1487 TEST_F(WindowTest, Transform) { | 1487 TEST_F(WindowTest, Transform) { |
| 1488 gfx::Size size = dispatcher()->host()->GetBounds().size(); | 1488 gfx::Size size = host()->GetBounds().size(); |
| 1489 EXPECT_EQ(gfx::Rect(size), | 1489 EXPECT_EQ(gfx::Rect(size), |
| 1490 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( | 1490 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( |
| 1491 gfx::Point()).bounds()); | 1491 gfx::Point()).bounds()); |
| 1492 | 1492 |
| 1493 // Rotate it clock-wise 90 degrees. | 1493 // Rotate it clock-wise 90 degrees. |
| 1494 gfx::Transform transform; | 1494 gfx::Transform transform; |
| 1495 transform.Translate(size.height(), 0); | 1495 transform.Translate(size.height(), 0); |
| 1496 transform.Rotate(90.0); | 1496 transform.Rotate(90.0); |
| 1497 dispatcher()->host()->SetTransform(transform); | 1497 host()->SetTransform(transform); |
| 1498 | 1498 |
| 1499 // The size should be the transformed size. | 1499 // The size should be the transformed size. |
| 1500 gfx::Size transformed_size(size.height(), size.width()); | 1500 gfx::Size transformed_size(size.height(), size.width()); |
| 1501 EXPECT_EQ(transformed_size.ToString(), | 1501 EXPECT_EQ(transformed_size.ToString(), |
| 1502 root_window()->bounds().size().ToString()); | 1502 root_window()->bounds().size().ToString()); |
| 1503 EXPECT_EQ( | 1503 EXPECT_EQ( |
| 1504 gfx::Rect(transformed_size).ToString(), | 1504 gfx::Rect(transformed_size).ToString(), |
| 1505 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( | 1505 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( |
| 1506 gfx::Point()).bounds().ToString()); | 1506 gfx::Point()).bounds().ToString()); |
| 1507 | 1507 |
| 1508 // Host size shouldn't change. | 1508 // Host size shouldn't change. |
| 1509 EXPECT_EQ(size.ToString(), | 1509 EXPECT_EQ(size.ToString(), host()->GetBounds().size().ToString()); |
| 1510 dispatcher()->host()->GetBounds().size().ToString()); | |
| 1511 } | 1510 } |
| 1512 | 1511 |
| 1513 TEST_F(WindowTest, TransformGesture) { | 1512 TEST_F(WindowTest, TransformGesture) { |
| 1514 gfx::Size size = dispatcher()->host()->GetBounds().size(); | 1513 gfx::Size size = host()->GetBounds().size(); |
| 1515 | 1514 |
| 1516 scoped_ptr<GestureTrackPositionDelegate> delegate( | 1515 scoped_ptr<GestureTrackPositionDelegate> delegate( |
| 1517 new GestureTrackPositionDelegate); | 1516 new GestureTrackPositionDelegate); |
| 1518 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, | 1517 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, |
| 1519 gfx::Rect(0, 0, 20, 20), root_window())); | 1518 gfx::Rect(0, 0, 20, 20), root_window())); |
| 1520 | 1519 |
| 1521 // Rotate the root-window clock-wise 90 degrees. | 1520 // Rotate the root-window clock-wise 90 degrees. |
| 1522 gfx::Transform transform; | 1521 gfx::Transform transform; |
| 1523 transform.Translate(size.height(), 0.0); | 1522 transform.Translate(size.height(), 0.0); |
| 1524 transform.Rotate(90.0); | 1523 transform.Rotate(90.0); |
| 1525 dispatcher()->host()->SetTransform(transform); | 1524 host()->SetTransform(transform); |
| 1526 | 1525 |
| 1527 ui::TouchEvent press( | 1526 ui::TouchEvent press( |
| 1528 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); | 1527 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); |
| 1529 DispatchEventUsingWindowDispatcher(&press); | 1528 DispatchEventUsingWindowDispatcher(&press); |
| 1530 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); | 1529 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); |
| 1531 } | 1530 } |
| 1532 | 1531 |
| 1533 namespace { | 1532 namespace { |
| 1534 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); | 1533 DEFINE_WINDOW_PROPERTY_KEY(int, kIntKey, -2); |
| 1535 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); | 1534 DEFINE_WINDOW_PROPERTY_KEY(const char*, kStringKey, "squeamish"); |
| (...skipping 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2010 window->Show(); | 2009 window->Show(); |
| 2011 | 2010 |
| 2012 client.set_ignore_visibility_changes(true); | 2011 client.set_ignore_visibility_changes(true); |
| 2013 window->Hide(); | 2012 window->Hide(); |
| 2014 EXPECT_FALSE(window->IsVisible()); | 2013 EXPECT_FALSE(window->IsVisible()); |
| 2015 EXPECT_TRUE(window->layer()->visible()); | 2014 EXPECT_TRUE(window->layer()->visible()); |
| 2016 } | 2015 } |
| 2017 | 2016 |
| 2018 // Tests mouse events on window change. | 2017 // Tests mouse events on window change. |
| 2019 TEST_F(WindowTest, MouseEventsOnWindowChange) { | 2018 TEST_F(WindowTest, MouseEventsOnWindowChange) { |
| 2020 gfx::Size size = dispatcher()->host()->GetBounds().size(); | 2019 gfx::Size size = host()->GetBounds().size(); |
| 2021 | 2020 |
| 2022 EventGenerator generator(root_window()); | 2021 EventGenerator generator(root_window()); |
| 2023 generator.MoveMouseTo(50, 50); | 2022 generator.MoveMouseTo(50, 50); |
| 2024 | 2023 |
| 2025 EventCountDelegate d1; | 2024 EventCountDelegate d1; |
| 2026 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d1, 1, | 2025 scoped_ptr<Window> w1(CreateTestWindowWithDelegate(&d1, 1, |
| 2027 gfx::Rect(0, 0, 100, 100), root_window())); | 2026 gfx::Rect(0, 0, 100, 100), root_window())); |
| 2028 RunAllPendingInMessageLoop(); | 2027 RunAllPendingInMessageLoop(); |
| 2029 // The format of result is "Enter/Mouse/Leave". | 2028 // The format of result is "Enter/Mouse/Leave". |
| 2030 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 2029 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
| (...skipping 1255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3286 BuildRootLayerTreeDescription(*root.layer())) | 3285 BuildRootLayerTreeDescription(*root.layer())) |
| 3287 << "layer tree doesn't match at " << i; | 3286 << "layer tree doesn't match at " << i; |
| 3288 EXPECT_EQ(data[i].expected_description, | 3287 EXPECT_EQ(data[i].expected_description, |
| 3289 BuildRootWindowTreeDescription(root)) | 3288 BuildRootWindowTreeDescription(root)) |
| 3290 << "window tree doesn't match at " << i; | 3289 << "window tree doesn't match at " << i; |
| 3291 } | 3290 } |
| 3292 } | 3291 } |
| 3293 | 3292 |
| 3294 } // namespace test | 3293 } // namespace test |
| 3295 } // namespace aura | 3294 } // namespace aura |
| OLD | NEW |