| 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 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 320 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 321 scoped_ptr<Window> w11( | 321 scoped_ptr<Window> w11( |
| 322 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 322 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 323 scoped_ptr<Window> w111( | 323 scoped_ptr<Window> w111( |
| 324 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 324 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
| 325 scoped_ptr<Window> w1111( | 325 scoped_ptr<Window> w1111( |
| 326 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 326 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
| 327 | 327 |
| 328 RootWindow* root = root_window(); | 328 RootWindow* root = root_window(); |
| 329 root->MoveCursorTo(gfx::Point(10, 10)); | 329 root->MoveCursorTo(gfx::Point(10, 10)); |
| 330 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString()); | 330 EXPECT_EQ("10,10", |
| 331 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 331 w1->MoveCursorTo(gfx::Point(10, 10)); | 332 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 332 EXPECT_EQ("20,20", gfx::Screen::GetCursorScreenPoint().ToString()); | 333 EXPECT_EQ("20,20", |
| 334 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 333 w11->MoveCursorTo(gfx::Point(10, 10)); | 335 w11->MoveCursorTo(gfx::Point(10, 10)); |
| 334 EXPECT_EQ("25,25", gfx::Screen::GetCursorScreenPoint().ToString()); | 336 EXPECT_EQ("25,25", |
| 337 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 335 w111->MoveCursorTo(gfx::Point(10, 10)); | 338 w111->MoveCursorTo(gfx::Point(10, 10)); |
| 336 EXPECT_EQ("30,30", gfx::Screen::GetCursorScreenPoint().ToString()); | 339 EXPECT_EQ("30,30", |
| 340 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 337 w1111->MoveCursorTo(gfx::Point(10, 10)); | 341 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 338 EXPECT_EQ("35,35", gfx::Screen::GetCursorScreenPoint().ToString()); | 342 EXPECT_EQ("35,35", |
| 343 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 339 } | 344 } |
| 340 | 345 |
| 341 TEST_F(WindowTest, ContainsMouse) { | 346 TEST_F(WindowTest, ContainsMouse) { |
| 342 scoped_ptr<Window> w( | 347 scoped_ptr<Window> w( |
| 343 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 348 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 344 w->Show(); | 349 w->Show(); |
| 345 Window::TestApi w_test_api(w.get()); | 350 Window::TestApi w_test_api(w.get()); |
| 346 RootWindow* root = root_window(); | 351 RootWindow* root = root_window(); |
| 347 root->MoveCursorTo(gfx::Point(10, 10)); | 352 root->MoveCursorTo(gfx::Point(10, 10)); |
| 348 EXPECT_TRUE(w_test_api.ContainsMouse()); | 353 EXPECT_TRUE(w_test_api.ContainsMouse()); |
| 349 root->MoveCursorTo(gfx::Point(9, 10)); | 354 root->MoveCursorTo(gfx::Point(9, 10)); |
| 350 EXPECT_FALSE(w_test_api.ContainsMouse()); | 355 EXPECT_FALSE(w_test_api.ContainsMouse()); |
| 351 } | 356 } |
| 352 | 357 |
| 353 // Test Window::ConvertPointToWindow() with transform to root_window. | 358 // Test Window::ConvertPointToWindow() with transform to root_window. |
| 354 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { | 359 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { |
| 355 RootWindow* root = root_window(); | 360 RootWindow* root = root_window(); |
| 356 ui::Transform transform; | 361 ui::Transform transform; |
| 357 transform.ConcatScale(2, 5); | 362 transform.ConcatScale(2, 5); |
| 358 transform.ConcatRotate(90.0f); | 363 transform.ConcatRotate(90.0f); |
| 359 transform.ConcatTranslate(100, 100); | 364 transform.ConcatTranslate(100, 100); |
| 360 root->SetTransform(transform); | 365 root->SetTransform(transform); |
| 361 root->MoveCursorTo(gfx::Point(10, 10)); | 366 root->MoveCursorTo(gfx::Point(10, 10)); |
| 362 #if !defined(OS_WIN) | 367 #if !defined(OS_WIN) |
| 363 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD | 368 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD |
| 364 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); | 369 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); |
| 365 #endif | 370 #endif |
| 366 EXPECT_EQ("10,10", gfx::Screen::GetCursorScreenPoint().ToString()); | 371 EXPECT_EQ("10,10", |
| 372 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 367 } | 373 } |
| 368 | 374 |
| 369 // Tests Window::ConvertPointToWindow() with transform to non-root windows. | 375 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
| 370 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { | 376 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { |
| 371 scoped_ptr<Window> w1( | 377 scoped_ptr<Window> w1( |
| 372 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 373 | 379 |
| 374 ui::Transform transform1; | 380 ui::Transform transform1; |
| 375 transform1.ConcatScale(2, 2); | 381 transform1.ConcatScale(2, 2); |
| 376 w1->SetTransform(transform1); | 382 w1->SetTransform(transform1); |
| 377 w1->MoveCursorTo(gfx::Point(10, 10)); | 383 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 378 EXPECT_EQ("30,30", gfx::Screen::GetCursorScreenPoint().ToString()); | 384 EXPECT_EQ("30,30", |
| 385 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
| 379 | 386 |
| 380 ui::Transform transform2; | 387 ui::Transform transform2; |
| 381 transform2.ConcatTranslate(-10, 20); | 388 transform2.ConcatTranslate(-10, 20); |
| 382 w1->SetTransform(transform2); | 389 w1->SetTransform(transform2); |
| 383 w1->MoveCursorTo(gfx::Point(10, 10)); | 390 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 384 EXPECT_EQ("10,40", gfx::Screen::GetCursorScreenPoint().ToString()); | 391 EXPECT_EQ("10,40", |
| 392 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
| 385 | 393 |
| 386 ui::Transform transform3; | 394 ui::Transform transform3; |
| 387 transform3.ConcatRotate(90.0f); | 395 transform3.ConcatRotate(90.0f); |
| 388 w1->SetTransform(transform3); | 396 w1->SetTransform(transform3); |
| 389 w1->MoveCursorTo(gfx::Point(5, 5)); | 397 w1->MoveCursorTo(gfx::Point(5, 5)); |
| 390 EXPECT_EQ("5,15", gfx::Screen::GetCursorScreenPoint().ToString()); | 398 EXPECT_EQ("5,15", |
| 399 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
| 391 | 400 |
| 392 ui::Transform transform4; | 401 ui::Transform transform4; |
| 393 transform4.ConcatScale(2, 5); | 402 transform4.ConcatScale(2, 5); |
| 394 transform4.ConcatRotate(90.0f); | 403 transform4.ConcatRotate(90.0f); |
| 395 transform4.ConcatTranslate(100, 100); | 404 transform4.ConcatTranslate(100, 100); |
| 396 w1->SetTransform(transform4); | 405 w1->SetTransform(transform4); |
| 397 w1->MoveCursorTo(gfx::Point(10, 10)); | 406 w1->MoveCursorTo(gfx::Point(10, 10)); |
| 398 EXPECT_EQ("60,130", gfx::Screen::GetCursorScreenPoint().ToString()); | 407 EXPECT_EQ("60,130", |
| 408 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
| 399 } | 409 } |
| 400 | 410 |
| 401 // Test Window::ConvertPointToWindow() with complex transforms to both root and | 411 // Test Window::ConvertPointToWindow() with complex transforms to both root and |
| 402 // non-root windows. | 412 // non-root windows. |
| 403 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { | 413 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { |
| 404 scoped_ptr<Window> w1( | 414 scoped_ptr<Window> w1( |
| 405 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 415 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
| 406 scoped_ptr<Window> w11( | 416 scoped_ptr<Window> w11( |
| 407 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); | 417 CreateTestWindow(SK_ColorGREEN, 11, gfx::Rect(5, 5, 100, 100), w1.get())); |
| 408 scoped_ptr<Window> w111( | 418 scoped_ptr<Window> w111( |
| (...skipping 12 matching lines...) Expand all Loading... |
| 421 w11->SetTransform(transform); | 431 w11->SetTransform(transform); |
| 422 w111->SetTransform(transform); | 432 w111->SetTransform(transform); |
| 423 w1111->SetTransform(transform); | 433 w1111->SetTransform(transform); |
| 424 | 434 |
| 425 w1111->MoveCursorTo(gfx::Point(10, 10)); | 435 w1111->MoveCursorTo(gfx::Point(10, 10)); |
| 426 | 436 |
| 427 #if !defined(OS_WIN) | 437 #if !defined(OS_WIN) |
| 428 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD | 438 // TODO(yoshiki): fix this to build on Windows. See crbug.com/133413.OD |
| 429 EXPECT_EQ("11,47", root->QueryMouseLocationForTest().ToString()); | 439 EXPECT_EQ("11,47", root->QueryMouseLocationForTest().ToString()); |
| 430 #endif | 440 #endif |
| 431 EXPECT_EQ("20,53", gfx::Screen::GetCursorScreenPoint().ToString()); | 441 EXPECT_EQ("20,53", |
| 442 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
| 432 } | 443 } |
| 433 | 444 |
| 434 TEST_F(WindowTest, HitTest) { | 445 TEST_F(WindowTest, HitTest) { |
| 435 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); | 446 Window w1(new ColorTestWindowDelegate(SK_ColorWHITE)); |
| 436 w1.set_id(1); | 447 w1.set_id(1); |
| 437 w1.Init(ui::LAYER_TEXTURED); | 448 w1.Init(ui::LAYER_TEXTURED); |
| 438 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); | 449 w1.SetBounds(gfx::Rect(10, 20, 50, 60)); |
| 439 w1.Show(); | 450 w1.Show(); |
| 440 w1.SetParent(NULL); | 451 w1.SetParent(NULL); |
| 441 | 452 |
| (...skipping 874 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1316 w12->set_ignore_events(true); | 1327 w12->set_ignore_events(true); |
| 1317 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1328 EXPECT_EQ(w111.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1318 w111->set_ignore_events(true); | 1329 w111->set_ignore_events(true); |
| 1319 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); | 1330 EXPECT_EQ(w11.get(), w1->GetEventHandlerForPoint(gfx::Point(160, 160))); |
| 1320 } | 1331 } |
| 1321 | 1332 |
| 1322 // Tests transformation on the root window. | 1333 // Tests transformation on the root window. |
| 1323 TEST_F(WindowTest, Transform) { | 1334 TEST_F(WindowTest, Transform) { |
| 1324 gfx::Size size = root_window()->GetHostSize(); | 1335 gfx::Size size = root_window()->GetHostSize(); |
| 1325 EXPECT_EQ(gfx::Rect(size), | 1336 EXPECT_EQ(gfx::Rect(size), |
| 1326 gfx::Screen::GetDisplayNearestPoint(gfx::Point()).bounds()); | 1337 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( |
| 1338 gfx::Point()).bounds()); |
| 1327 | 1339 |
| 1328 // Rotate it clock-wise 90 degrees. | 1340 // Rotate it clock-wise 90 degrees. |
| 1329 ui::Transform transform; | 1341 ui::Transform transform; |
| 1330 transform.SetRotate(90.0f); | 1342 transform.SetRotate(90.0f); |
| 1331 transform.ConcatTranslate(size.height(), 0); | 1343 transform.ConcatTranslate(size.height(), 0); |
| 1332 root_window()->SetTransform(transform); | 1344 root_window()->SetTransform(transform); |
| 1333 | 1345 |
| 1334 // The size should be the transformed size. | 1346 // The size should be the transformed size. |
| 1335 gfx::Size transformed_size(size.height(), size.width()); | 1347 gfx::Size transformed_size(size.height(), size.width()); |
| 1336 EXPECT_EQ(transformed_size.ToString(), | 1348 EXPECT_EQ(transformed_size.ToString(), |
| 1337 root_window()->bounds().size().ToString()); | 1349 root_window()->bounds().size().ToString()); |
| 1338 EXPECT_EQ( | 1350 EXPECT_EQ( |
| 1339 gfx::Rect(transformed_size).ToString(), | 1351 gfx::Rect(transformed_size).ToString(), |
| 1340 gfx::Screen::GetDisplayNearestPoint(gfx::Point()).bounds().ToString()); | 1352 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( |
| 1353 gfx::Point()).bounds().ToString()); |
| 1341 | 1354 |
| 1342 // Host size shouldn't change. | 1355 // Host size shouldn't change. |
| 1343 EXPECT_EQ(size.ToString(), | 1356 EXPECT_EQ(size.ToString(), |
| 1344 root_window()->GetHostSize().ToString()); | 1357 root_window()->GetHostSize().ToString()); |
| 1345 } | 1358 } |
| 1346 | 1359 |
| 1347 TEST_F(WindowTest, TransformGesture) { | 1360 TEST_F(WindowTest, TransformGesture) { |
| 1348 gfx::Size size = root_window()->GetHostSize(); | 1361 gfx::Size size = root_window()->GetHostSize(); |
| 1349 | 1362 |
| 1350 scoped_ptr<GestureTrackPositionDelegate> delegate( | 1363 scoped_ptr<GestureTrackPositionDelegate> delegate( |
| (...skipping 1187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2538 // Move |w2| to be a child of |w1|. | 2551 // Move |w2| to be a child of |w1|. |
| 2539 w1->AddChild(w2.get()); | 2552 w1->AddChild(w2.get()); |
| 2540 // Sine we moved in the same root, observer shouldn't be notified. | 2553 // Sine we moved in the same root, observer shouldn't be notified. |
| 2541 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2554 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
| 2542 // |w2| should still have focus after moving. | 2555 // |w2| should still have focus after moving. |
| 2543 EXPECT_TRUE(w2->HasFocus()); | 2556 EXPECT_TRUE(w2->HasFocus()); |
| 2544 } | 2557 } |
| 2545 | 2558 |
| 2546 } // namespace test | 2559 } // namespace test |
| 2547 } // namespace aura | 2560 } // namespace aura |
| OLD | NEW |