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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 root->MoveCursorTo(gfx::Point(10, 10)); | 352 root->MoveCursorTo(gfx::Point(10, 10)); |
353 EXPECT_TRUE(w_test_api.ContainsMouse()); | 353 EXPECT_TRUE(w_test_api.ContainsMouse()); |
354 root->MoveCursorTo(gfx::Point(9, 10)); | 354 root->MoveCursorTo(gfx::Point(9, 10)); |
355 EXPECT_FALSE(w_test_api.ContainsMouse()); | 355 EXPECT_FALSE(w_test_api.ContainsMouse()); |
356 } | 356 } |
357 | 357 |
358 // Test Window::ConvertPointToWindow() with transform to root_window. | 358 // Test Window::ConvertPointToWindow() with transform to root_window. |
359 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { | 359 TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) { |
360 RootWindow* root = root_window(); | 360 RootWindow* root = root_window(); |
361 gfx::Transform transform; | 361 gfx::Transform transform; |
362 transform.ConcatScale(2, 5); | 362 transform.Translate(100.0, 100.0); |
363 transform.ConcatRotate(90.0f); | 363 transform.Rotate(90.0); |
364 transform.ConcatTranslate(100, 100); | 364 transform.Scale(2.0, 5.0); |
365 root->SetTransform(transform); | 365 root->SetTransform(transform); |
366 root->MoveCursorTo(gfx::Point(10, 10)); | 366 root->MoveCursorTo(gfx::Point(10, 10)); |
367 #if !defined(OS_WIN) | 367 #if !defined(OS_WIN) |
368 // 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 |
369 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); | 369 EXPECT_EQ("50,120", root->QueryMouseLocationForTest().ToString()); |
370 #endif | 370 #endif |
371 EXPECT_EQ("10,10", | 371 EXPECT_EQ("10,10", |
372 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); | 372 gfx::Screen::GetScreenFor(root)->GetCursorScreenPoint().ToString()); |
373 } | 373 } |
374 | 374 |
375 // Tests Window::ConvertPointToWindow() with transform to non-root windows. | 375 // Tests Window::ConvertPointToWindow() with transform to non-root windows. |
376 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { | 376 TEST_F(WindowTest, MoveCursorToWithTransformWindow) { |
377 scoped_ptr<Window> w1( | 377 scoped_ptr<Window> w1( |
378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 378 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
379 | 379 |
380 gfx::Transform transform1; | 380 gfx::Transform transform1; |
381 transform1.ConcatScale(2, 2); | 381 transform1.Scale(2, 2); |
382 w1->SetTransform(transform1); | 382 w1->SetTransform(transform1); |
383 w1->MoveCursorTo(gfx::Point(10, 10)); | 383 w1->MoveCursorTo(gfx::Point(10, 10)); |
384 EXPECT_EQ("30,30", | 384 EXPECT_EQ("30,30", |
385 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 385 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
386 | 386 |
387 gfx::Transform transform2; | 387 gfx::Transform transform2; |
388 transform2.ConcatTranslate(-10, 20); | 388 transform2.Translate(-10, 20); |
389 w1->SetTransform(transform2); | 389 w1->SetTransform(transform2); |
390 w1->MoveCursorTo(gfx::Point(10, 10)); | 390 w1->MoveCursorTo(gfx::Point(10, 10)); |
391 EXPECT_EQ("10,40", | 391 EXPECT_EQ("10,40", |
392 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 392 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
393 | 393 |
394 gfx::Transform transform3; | 394 gfx::Transform transform3; |
395 transform3.ConcatRotate(90.0f); | 395 transform3.Rotate(90.0); |
396 w1->SetTransform(transform3); | 396 w1->SetTransform(transform3); |
397 w1->MoveCursorTo(gfx::Point(5, 5)); | 397 w1->MoveCursorTo(gfx::Point(5, 5)); |
398 EXPECT_EQ("5,15", | 398 EXPECT_EQ("5,15", |
399 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 399 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
400 | 400 |
401 gfx::Transform transform4; | 401 gfx::Transform transform4; |
402 transform4.ConcatScale(2, 5); | 402 transform4.Translate(100.0, 100.0); |
403 transform4.ConcatRotate(90.0f); | 403 transform4.Rotate(90.0); |
404 transform4.ConcatTranslate(100, 100); | 404 transform4.Scale(2.0, 5.0); |
405 w1->SetTransform(transform4); | 405 w1->SetTransform(transform4); |
406 w1->MoveCursorTo(gfx::Point(10, 10)); | 406 w1->MoveCursorTo(gfx::Point(10, 10)); |
407 EXPECT_EQ("60,130", | 407 EXPECT_EQ("60,130", |
408 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); | 408 gfx::Screen::GetScreenFor(w1.get())->GetCursorScreenPoint().ToString()); |
409 } | 409 } |
410 | 410 |
411 // Test Window::ConvertPointToWindow() with complex transforms to both root and | 411 // Test Window::ConvertPointToWindow() with complex transforms to both root and |
412 // non-root windows. | 412 // non-root windows. |
413 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { | 413 TEST_F(WindowTest, MoveCursorToWithComplexTransform) { |
414 scoped_ptr<Window> w1( | 414 scoped_ptr<Window> w1( |
415 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); | 415 CreateTestWindow(SK_ColorWHITE, 1, gfx::Rect(10, 10, 500, 500), NULL)); |
416 scoped_ptr<Window> w11( | 416 scoped_ptr<Window> w11( |
417 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())); |
418 scoped_ptr<Window> w111( | 418 scoped_ptr<Window> w111( |
419 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); | 419 CreateTestWindow(SK_ColorCYAN, 111, gfx::Rect(5, 5, 75, 75), w11.get())); |
420 scoped_ptr<Window> w1111( | 420 scoped_ptr<Window> w1111( |
421 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); | 421 CreateTestWindow(SK_ColorRED, 1111, gfx::Rect(5, 5, 50, 50), w111.get())); |
422 | 422 |
423 RootWindow* root = root_window(); | 423 RootWindow* root = root_window(); |
424 | 424 |
425 // The root window expects transforms that produce integer rects. | 425 // The root window expects transforms that produce integer rects. |
426 gfx::Transform root_transform; | 426 gfx::Transform root_transform; |
427 root_transform.ConcatScale(2.0f, 3.0f); | 427 root_transform.Translate(60.0, 70.0); |
428 root_transform.ConcatTranslate(-50, -50); | 428 root_transform.Rotate(-90.0); |
429 root_transform.ConcatRotate(-90.0f); | 429 root_transform.Translate(-50.0, -50.0); |
430 root_transform.ConcatTranslate(60, 70); | 430 root_transform.Scale(2.0, 3.0); |
431 | 431 |
432 gfx::Transform transform; | 432 gfx::Transform transform; |
433 transform.ConcatScale(0.3f, 0.5f); | 433 transform.Translate(10.0, 20.0); |
434 transform.ConcatRotate(10.0f); | 434 transform.Rotate(10.0); |
435 transform.ConcatTranslate(10, 20); | 435 transform.Scale(0.3, 0.5); |
436 | 436 |
437 root->SetTransform(root_transform); | 437 root->SetTransform(root_transform); |
438 w1->SetTransform(transform); | 438 w1->SetTransform(transform); |
439 w11->SetTransform(transform); | 439 w11->SetTransform(transform); |
440 w111->SetTransform(transform); | 440 w111->SetTransform(transform); |
441 w1111->SetTransform(transform); | 441 w1111->SetTransform(transform); |
442 | 442 |
443 w1111->MoveCursorTo(gfx::Point(10, 10)); | 443 w1111->MoveCursorTo(gfx::Point(10, 10)); |
444 | 444 |
445 #if !defined(OS_WIN) | 445 #if !defined(OS_WIN) |
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 | 1340 |
1341 // Tests transformation on the root window. | 1341 // Tests transformation on the root window. |
1342 TEST_F(WindowTest, Transform) { | 1342 TEST_F(WindowTest, Transform) { |
1343 gfx::Size size = root_window()->GetHostSize(); | 1343 gfx::Size size = root_window()->GetHostSize(); |
1344 EXPECT_EQ(gfx::Rect(size), | 1344 EXPECT_EQ(gfx::Rect(size), |
1345 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( | 1345 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( |
1346 gfx::Point()).bounds()); | 1346 gfx::Point()).bounds()); |
1347 | 1347 |
1348 // Rotate it clock-wise 90 degrees. | 1348 // Rotate it clock-wise 90 degrees. |
1349 gfx::Transform transform; | 1349 gfx::Transform transform; |
1350 transform.SetRotate(90.0f); | 1350 transform.Translate(size.height(), 0); |
1351 transform.ConcatTranslate(size.height(), 0); | 1351 transform.Rotate(90.0); |
1352 root_window()->SetTransform(transform); | 1352 root_window()->SetTransform(transform); |
1353 | 1353 |
1354 // The size should be the transformed size. | 1354 // The size should be the transformed size. |
1355 gfx::Size transformed_size(size.height(), size.width()); | 1355 gfx::Size transformed_size(size.height(), size.width()); |
1356 EXPECT_EQ(transformed_size.ToString(), | 1356 EXPECT_EQ(transformed_size.ToString(), |
1357 root_window()->bounds().size().ToString()); | 1357 root_window()->bounds().size().ToString()); |
1358 EXPECT_EQ( | 1358 EXPECT_EQ( |
1359 gfx::Rect(transformed_size).ToString(), | 1359 gfx::Rect(transformed_size).ToString(), |
1360 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( | 1360 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( |
1361 gfx::Point()).bounds().ToString()); | 1361 gfx::Point()).bounds().ToString()); |
1362 | 1362 |
1363 // Host size shouldn't change. | 1363 // Host size shouldn't change. |
1364 EXPECT_EQ(size.ToString(), | 1364 EXPECT_EQ(size.ToString(), |
1365 root_window()->GetHostSize().ToString()); | 1365 root_window()->GetHostSize().ToString()); |
1366 } | 1366 } |
1367 | 1367 |
1368 TEST_F(WindowTest, TransformGesture) { | 1368 TEST_F(WindowTest, TransformGesture) { |
1369 gfx::Size size = root_window()->GetHostSize(); | 1369 gfx::Size size = root_window()->GetHostSize(); |
1370 | 1370 |
1371 scoped_ptr<GestureTrackPositionDelegate> delegate( | 1371 scoped_ptr<GestureTrackPositionDelegate> delegate( |
1372 new GestureTrackPositionDelegate); | 1372 new GestureTrackPositionDelegate); |
1373 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, | 1373 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, |
1374 gfx::Rect(0, 0, 20, 20), NULL)); | 1374 gfx::Rect(0, 0, 20, 20), NULL)); |
1375 | 1375 |
1376 // Rotate the root-window clock-wise 90 degrees. | 1376 // Rotate the root-window clock-wise 90 degrees. |
1377 gfx::Transform transform; | 1377 gfx::Transform transform; |
1378 transform.SetRotate(90.0f); | 1378 transform.Translate(size.height(), 0.0); |
1379 transform.ConcatTranslate(size.height(), 0); | 1379 transform.Rotate(90.0); |
1380 root_window()->SetTransform(transform); | 1380 root_window()->SetTransform(transform); |
1381 | 1381 |
1382 ui::TouchEvent press( | 1382 ui::TouchEvent press( |
1383 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); | 1383 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); |
1384 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); | 1384 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); |
1385 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); | 1385 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); |
1386 } | 1386 } |
1387 | 1387 |
1388 // Various assertions for transient children. | 1388 // Various assertions for transient children. |
1389 TEST_F(WindowTest, TransientChildren) { | 1389 TEST_F(WindowTest, TransientChildren) { |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1999 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 1999 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
2000 EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset()); | 2000 EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset()); |
2001 | 2001 |
2002 w11->Show(); | 2002 w11->Show(); |
2003 RunAllPendingInMessageLoop(); | 2003 RunAllPendingInMessageLoop(); |
2004 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); | 2004 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); |
2005 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); | 2005 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); |
2006 | 2006 |
2007 // Transform: move d11 by 100 100. | 2007 // Transform: move d11 by 100 100. |
2008 gfx::Transform transform; | 2008 gfx::Transform transform; |
2009 transform.ConcatTranslate(100, 100); | 2009 transform.Translate(100, 100); |
2010 w11->SetTransform(transform); | 2010 w11->SetTransform(transform); |
2011 RunAllPendingInMessageLoop(); | 2011 RunAllPendingInMessageLoop(); |
2012 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); | 2012 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); |
2013 EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset()); | 2013 EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset()); |
2014 | 2014 |
2015 w11->SetTransform(gfx::Transform()); | 2015 w11->SetTransform(gfx::Transform()); |
2016 RunAllPendingInMessageLoop(); | 2016 RunAllPendingInMessageLoop(); |
2017 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); | 2017 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); |
2018 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); | 2018 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); |
2019 | 2019 |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2559 // Move |w2| to be a child of |w1|. | 2559 // Move |w2| to be a child of |w1|. |
2560 w1->AddChild(w2.get()); | 2560 w1->AddChild(w2.get()); |
2561 // Sine we moved in the same root, observer shouldn't be notified. | 2561 // Sine we moved in the same root, observer shouldn't be notified. |
2562 EXPECT_EQ("0 0", observer.CountStringAndReset()); | 2562 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
2563 // |w2| should still have focus after moving. | 2563 // |w2| should still have focus after moving. |
2564 EXPECT_TRUE(w2->HasFocus()); | 2564 EXPECT_TRUE(w2->HasFocus()); |
2565 } | 2565 } |
2566 | 2566 |
2567 } // namespace test | 2567 } // namespace test |
2568 } // namespace aura | 2568 } // namespace aura |
OLD | NEW |