Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8)

Side by Side Diff: ui/aura/window_unittest.cc

Issue 11145005: Migrate ui::Transform to gfx::Transform (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Hopefully should work this time Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/window.cc ('k') | ui/base/animation/tween.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 RootWindow* root = root_window(); 351 RootWindow* root = root_window();
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 ui::Transform transform; 361 gfx::Transform transform;
362 transform.ConcatScale(2, 5); 362 transform.ConcatScale(2, 5);
363 transform.ConcatRotate(90.0f); 363 transform.ConcatRotate(90.0f);
364 transform.ConcatTranslate(100, 100); 364 transform.ConcatTranslate(100, 100);
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 ui::Transform transform1; 380 gfx::Transform transform1;
381 transform1.ConcatScale(2, 2); 381 transform1.ConcatScale(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 ui::Transform transform2; 387 gfx::Transform transform2;
388 transform2.ConcatTranslate(-10, 20); 388 transform2.ConcatTranslate(-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 ui::Transform transform3; 394 gfx::Transform transform3;
395 transform3.ConcatRotate(90.0f); 395 transform3.ConcatRotate(90.0f);
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 ui::Transform transform4; 401 gfx::Transform transform4;
402 transform4.ConcatScale(2, 5); 402 transform4.ConcatScale(2, 5);
403 transform4.ConcatRotate(90.0f); 403 transform4.ConcatRotate(90.0f);
404 transform4.ConcatTranslate(100, 100); 404 transform4.ConcatTranslate(100, 100);
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 ui::Transform transform; 424 gfx::Transform transform;
425 transform.ConcatScale(0.3f, 0.5f); 425 transform.ConcatScale(0.3f, 0.5f);
426 transform.ConcatRotate(10.0f); 426 transform.ConcatRotate(10.0f);
427 transform.ConcatTranslate(10, 20); 427 transform.ConcatTranslate(10, 20);
428 428
429 root->SetTransform(transform); 429 root->SetTransform(transform);
430 w1->SetTransform(transform); 430 w1->SetTransform(transform);
431 w11->SetTransform(transform); 431 w11->SetTransform(transform);
432 w111->SetTransform(transform); 432 w111->SetTransform(transform);
433 w1111->SetTransform(transform); 433 w1111->SetTransform(transform);
434 434
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 } 1331 }
1332 1332
1333 // Tests transformation on the root window. 1333 // Tests transformation on the root window.
1334 TEST_F(WindowTest, Transform) { 1334 TEST_F(WindowTest, Transform) {
1335 gfx::Size size = root_window()->GetHostSize(); 1335 gfx::Size size = root_window()->GetHostSize();
1336 EXPECT_EQ(gfx::Rect(size), 1336 EXPECT_EQ(gfx::Rect(size),
1337 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( 1337 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint(
1338 gfx::Point()).bounds()); 1338 gfx::Point()).bounds());
1339 1339
1340 // Rotate it clock-wise 90 degrees. 1340 // Rotate it clock-wise 90 degrees.
1341 ui::Transform transform; 1341 gfx::Transform transform;
1342 transform.SetRotate(90.0f); 1342 transform.SetRotate(90.0f);
1343 transform.ConcatTranslate(size.height(), 0); 1343 transform.ConcatTranslate(size.height(), 0);
1344 root_window()->SetTransform(transform); 1344 root_window()->SetTransform(transform);
1345 1345
1346 // The size should be the transformed size. 1346 // The size should be the transformed size.
1347 gfx::Size transformed_size(size.height(), size.width()); 1347 gfx::Size transformed_size(size.height(), size.width());
1348 EXPECT_EQ(transformed_size.ToString(), 1348 EXPECT_EQ(transformed_size.ToString(),
1349 root_window()->bounds().size().ToString()); 1349 root_window()->bounds().size().ToString());
1350 EXPECT_EQ( 1350 EXPECT_EQ(
1351 gfx::Rect(transformed_size).ToString(), 1351 gfx::Rect(transformed_size).ToString(),
1352 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint( 1352 gfx::Screen::GetScreenFor(root_window())->GetDisplayNearestPoint(
1353 gfx::Point()).bounds().ToString()); 1353 gfx::Point()).bounds().ToString());
1354 1354
1355 // Host size shouldn't change. 1355 // Host size shouldn't change.
1356 EXPECT_EQ(size.ToString(), 1356 EXPECT_EQ(size.ToString(),
1357 root_window()->GetHostSize().ToString()); 1357 root_window()->GetHostSize().ToString());
1358 } 1358 }
1359 1359
1360 TEST_F(WindowTest, TransformGesture) { 1360 TEST_F(WindowTest, TransformGesture) {
1361 gfx::Size size = root_window()->GetHostSize(); 1361 gfx::Size size = root_window()->GetHostSize();
1362 1362
1363 scoped_ptr<GestureTrackPositionDelegate> delegate( 1363 scoped_ptr<GestureTrackPositionDelegate> delegate(
1364 new GestureTrackPositionDelegate); 1364 new GestureTrackPositionDelegate);
1365 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234, 1365 scoped_ptr<Window> window(CreateTestWindowWithDelegate(delegate.get(), -1234,
1366 gfx::Rect(0, 0, 20, 20), NULL)); 1366 gfx::Rect(0, 0, 20, 20), NULL));
1367 1367
1368 // Rotate the root-window clock-wise 90 degrees. 1368 // Rotate the root-window clock-wise 90 degrees.
1369 ui::Transform transform; 1369 gfx::Transform transform;
1370 transform.SetRotate(90.0f); 1370 transform.SetRotate(90.0f);
1371 transform.ConcatTranslate(size.height(), 0); 1371 transform.ConcatTranslate(size.height(), 0);
1372 root_window()->SetTransform(transform); 1372 root_window()->SetTransform(transform);
1373 1373
1374 ui::TouchEvent press( 1374 ui::TouchEvent press(
1375 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime()); 1375 ui::ET_TOUCH_PRESSED, gfx::Point(size.height() - 10, 10), 0, getTime());
1376 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press); 1376 root_window()->AsRootWindowHostDelegate()->OnHostTouchEvent(&press);
1377 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString()); 1377 EXPECT_EQ(gfx::Point(10, 10).ToString(), delegate->position().ToString());
1378 } 1378 }
1379 1379
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
1990 RunAllPendingInMessageLoop(); 1990 RunAllPendingInMessageLoop();
1991 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); 1991 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset());
1992 EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset()); 1992 EXPECT_EQ("0 0 0", d11.GetMouseMotionCountsAndReset());
1993 1993
1994 w11->Show(); 1994 w11->Show();
1995 RunAllPendingInMessageLoop(); 1995 RunAllPendingInMessageLoop();
1996 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); 1996 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset());
1997 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); 1997 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset());
1998 1998
1999 // Transform: move d11 by 100 100. 1999 // Transform: move d11 by 100 100.
2000 ui::Transform transform; 2000 gfx::Transform transform;
2001 transform.ConcatTranslate(100, 100); 2001 transform.ConcatTranslate(100, 100);
2002 w11->SetTransform(transform); 2002 w11->SetTransform(transform);
2003 RunAllPendingInMessageLoop(); 2003 RunAllPendingInMessageLoop();
2004 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); 2004 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset());
2005 EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset()); 2005 EXPECT_EQ("0 0 1", d11.GetMouseMotionCountsAndReset());
2006 2006
2007 w11->SetTransform(ui::Transform()); 2007 w11->SetTransform(gfx::Transform());
2008 RunAllPendingInMessageLoop(); 2008 RunAllPendingInMessageLoop();
2009 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset()); 2009 EXPECT_EQ("0 0 1", d1.GetMouseMotionCountsAndReset());
2010 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset()); 2010 EXPECT_EQ("1 1 0", d11.GetMouseMotionCountsAndReset());
2011 2011
2012 // Closing a window. 2012 // Closing a window.
2013 w11.reset(); 2013 w11.reset();
2014 RunAllPendingInMessageLoop(); 2014 RunAllPendingInMessageLoop();
2015 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset()); 2015 EXPECT_EQ("1 1 0", d1.GetMouseMotionCountsAndReset());
2016 } 2016 }
2017 #endif 2017 #endif
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after
2551 // Move |w2| to be a child of |w1|. 2551 // Move |w2| to be a child of |w1|.
2552 w1->AddChild(w2.get()); 2552 w1->AddChild(w2.get());
2553 // 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.
2554 EXPECT_EQ("0 0", observer.CountStringAndReset()); 2554 EXPECT_EQ("0 0", observer.CountStringAndReset());
2555 // |w2| should still have focus after moving. 2555 // |w2| should still have focus after moving.
2556 EXPECT_TRUE(w2->HasFocus()); 2556 EXPECT_TRUE(w2->HasFocus());
2557 } 2557 }
2558 2558
2559 } // namespace test 2559 } // namespace test
2560 } // namespace aura 2560 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | ui/base/animation/tween.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698