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 "ash/display/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 #include "ash/display/multi_display_manager.h" | 6 #include "ash/display/multi_display_manager.h" |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/test/ash_test_base.h" | 8 #include "ash/test/ash_test_base.h" |
9 #include "ash/wm/window_cycle_controller.h" | 9 #include "ash/wm/window_cycle_controller.h" |
10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
11 #include "ui/aura/client/activation_client.h" | 11 #include "ui/aura/client/activation_client.h" |
12 #include "ui/aura/client/capture_client.h" | 12 #include "ui/aura/client/capture_client.h" |
13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
14 #include "ui/aura/focus_manager.h" | 14 #include "ui/aura/focus_manager.h" |
15 #include "ui/aura/root_window.h" | 15 #include "ui/aura/root_window.h" |
16 #include "ui/aura/test/event_generator.h" | 16 #include "ui/aura/test/event_generator.h" |
17 #include "ui/aura/test/test_windows.h" | 17 #include "ui/aura/test/test_windows.h" |
18 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
19 #include "ui/base/cursor/cursor.h" | 19 #include "ui/base/cursor/cursor.h" |
20 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
21 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
22 #include "ui/views/widget/widget_delegate.h" | 22 #include "ui/views/widget/widget_delegate.h" |
23 | 23 |
24 namespace ash { | 24 namespace ash { |
25 namespace { | 25 namespace { |
26 | 26 |
27 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { | 27 views::Widget* CreateTestWidgetWithParent(views::Widget* parent, |
| 28 const gfx::Rect& bounds, |
| 29 bool child) { |
28 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); | 30 views::Widget::InitParams params(views::Widget::InitParams::TYPE_WINDOW); |
| 31 params.parent_widget = parent; |
29 params.bounds = bounds; | 32 params.bounds = bounds; |
| 33 params.child = child; |
30 views::Widget* widget = new views::Widget; | 34 views::Widget* widget = new views::Widget; |
31 widget->Init(params); | 35 widget->Init(params); |
32 widget->Show(); | 36 widget->Show(); |
33 return widget; | 37 return widget; |
34 } | 38 } |
35 | 39 |
| 40 views::Widget* CreateTestWidget(const gfx::Rect& bounds) { |
| 41 return CreateTestWidgetWithParent(NULL, bounds, false); |
| 42 } |
| 43 |
36 class ModalWidgetDelegate : public views::WidgetDelegateView { | 44 class ModalWidgetDelegate : public views::WidgetDelegateView { |
37 public: | 45 public: |
38 ModalWidgetDelegate() {} | 46 ModalWidgetDelegate() {} |
39 virtual ~ModalWidgetDelegate() {} | 47 virtual ~ModalWidgetDelegate() {} |
40 | 48 |
41 // Overridden from views::WidgetDelegate: | 49 // Overridden from views::WidgetDelegate: |
42 virtual views::View* GetContentsView() OVERRIDE { | 50 virtual views::View* GetContentsView() OVERRIDE { |
43 return this; | 51 return this; |
44 } | 52 } |
45 virtual ui::ModalType GetModalType() const OVERRIDE { | 53 virtual ui::ModalType GetModalType() const OVERRIDE { |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
338 aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); | 346 aura::client::GetCaptureWindow(r2_w1->GetRootWindow())); |
339 generator2.MoveMouseBy(-10, -10); | 347 generator2.MoveMouseBy(-10, -10); |
340 generator2.ClickLeftButton(); | 348 generator2.ClickLeftButton(); |
341 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); | 349 EXPECT_EQ("1 1 0", r2_d1.GetMouseMotionCountsAndReset()); |
342 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); | 350 EXPECT_EQ("1 1", r2_d1.GetMouseButtonCountsAndReset()); |
343 // Make sure the mouse_moved_handler_ is properly reset. | 351 // Make sure the mouse_moved_handler_ is properly reset. |
344 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); | 352 EXPECT_EQ("0 0 0", r1_d2.GetMouseMotionCountsAndReset()); |
345 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); | 353 EXPECT_EQ("0 0", r1_d2.GetMouseButtonCountsAndReset()); |
346 } | 354 } |
347 | 355 |
| 356 TEST_F(ExtendedDesktopTest, MoveWindow) { |
| 357 internal::DisplayController::SetVirtualScreenCoordinatesEnabled(true); |
| 358 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 359 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 360 views::Widget* d1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 361 |
| 362 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 363 |
| 364 d1->SetBounds(gfx::Rect(1010, 10, 100, 100)); |
| 365 EXPECT_EQ("1010,10 100x100", |
| 366 d1->GetWindowBoundsInScreen().ToString()); |
| 367 |
| 368 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 369 |
| 370 d1->SetBounds(gfx::Rect(10, 10, 100, 100)); |
| 371 EXPECT_EQ("10,10 100x100", |
| 372 d1->GetWindowBoundsInScreen().ToString()); |
| 373 |
| 374 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 375 |
| 376 // Make sure the bounds which doesn't fit to the root window |
| 377 // works correctly. |
| 378 d1->SetBounds(gfx::Rect(1560, 30, 100, 100)); |
| 379 EXPECT_EQ(root_windows[1], d1->GetNativeView()->GetRootWindow()); |
| 380 EXPECT_EQ("1560,30 100x100", |
| 381 d1->GetWindowBoundsInScreen().ToString()); |
| 382 |
| 383 // Setting outside of root windows will be moved to primary root window. |
| 384 // TODO(oshima): This one probably should pick the closest root window. |
| 385 d1->SetBounds(gfx::Rect(200, 10, 100, 100)); |
| 386 EXPECT_EQ(root_windows[0], d1->GetNativeView()->GetRootWindow()); |
| 387 |
| 388 internal::DisplayController::SetVirtualScreenCoordinatesEnabled(false); |
| 389 } |
| 390 |
| 391 TEST_F(ExtendedDesktopTest, MoveWindowWithTransient) { |
| 392 internal::DisplayController::SetVirtualScreenCoordinatesEnabled(true); |
| 393 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
| 394 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 395 views::Widget* w1 = CreateTestWidget(gfx::Rect(10, 10, 100, 100)); |
| 396 views::Widget* w1_t1 = CreateTestWidgetWithParent( |
| 397 w1, gfx::Rect(50, 50, 50, 50), false /* transient */); |
| 398 // Transient child of the transient child. |
| 399 views::Widget* w1_t11 = CreateTestWidgetWithParent( |
| 400 w1_t1, gfx::Rect(1200, 70, 30, 30), false /* transient */); |
| 401 |
| 402 views::Widget* w11 = CreateTestWidgetWithParent( |
| 403 w1, gfx::Rect(10, 10, 40, 40), true /* child */); |
| 404 views::Widget* w11_t1 = CreateTestWidgetWithParent( |
| 405 w1, gfx::Rect(1300, 100, 80, 80), false /* transient */); |
| 406 |
| 407 EXPECT_EQ(root_windows[0], w1->GetNativeView()->GetRootWindow()); |
| 408 EXPECT_EQ(root_windows[0], w11->GetNativeView()->GetRootWindow()); |
| 409 EXPECT_EQ(root_windows[0], w1_t1->GetNativeView()->GetRootWindow()); |
| 410 EXPECT_EQ(root_windows[0], w1_t11->GetNativeView()->GetRootWindow()); |
| 411 EXPECT_EQ(root_windows[0], w11_t1->GetNativeView()->GetRootWindow()); |
| 412 EXPECT_EQ("50,50 50x50", |
| 413 w1_t1->GetWindowBoundsInScreen().ToString()); |
| 414 EXPECT_EQ("1200,70 30x30", |
| 415 w1_t11->GetWindowBoundsInScreen().ToString()); |
| 416 EXPECT_EQ("20,20 40x40", |
| 417 w11->GetWindowBoundsInScreen().ToString()); |
| 418 EXPECT_EQ("1300,100 80x80", |
| 419 w11_t1->GetWindowBoundsInScreen().ToString()); |
| 420 |
| 421 w1->SetBounds(gfx::Rect(1100,10,100,100)); |
| 422 |
| 423 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 424 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 425 EXPECT_EQ(root_windows[1], w1_t11->GetNativeView()->GetRootWindow()); |
| 426 EXPECT_EQ(root_windows[1], w11->GetNativeView()->GetRootWindow()); |
| 427 EXPECT_EQ(root_windows[1], w11_t1->GetNativeView()->GetRootWindow()); |
| 428 |
| 429 EXPECT_EQ("1110,20 40x40", |
| 430 w11->GetWindowBoundsInScreen().ToString()); |
| 431 // Transient window's screen bounds stays the same. |
| 432 EXPECT_EQ("50,50 50x50", |
| 433 w1_t1->GetWindowBoundsInScreen().ToString()); |
| 434 EXPECT_EQ("1200,70 30x30", |
| 435 w1_t11->GetWindowBoundsInScreen().ToString()); |
| 436 EXPECT_EQ("1300,100 80x80", |
| 437 w11_t1->GetWindowBoundsInScreen().ToString()); |
| 438 |
| 439 // Transient window doesn't move between root window unless |
| 440 // its transient parent moves. |
| 441 w1_t1->SetBounds(gfx::Rect(10, 50, 50, 50)); |
| 442 EXPECT_EQ(root_windows[1], w1_t1->GetNativeView()->GetRootWindow()); |
| 443 EXPECT_EQ("10,50 50x50", |
| 444 w1_t1->GetWindowBoundsInScreen().ToString()); |
| 445 |
| 446 internal::DisplayController::SetVirtualScreenCoordinatesEnabled(false); |
| 447 } |
| 448 |
348 namespace internal { | 449 namespace internal { |
349 // Test if the Window::ConvertPointToWindow works across root windows. | 450 // Test if the Window::ConvertPointToWindow works across root windows. |
350 // TODO(oshima): Move multiple display suport and this test to aura. | 451 // TODO(oshima): Move multiple display suport and this test to aura. |
351 TEST_F(ExtendedDesktopTest, ConvertPoint) { | 452 TEST_F(ExtendedDesktopTest, ConvertPoint) { |
352 UpdateDisplay("0+0-1000x600,1001+0-600x400"); | 453 UpdateDisplay("0+0-1000x600,1001+0-600x400"); |
353 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 454 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
354 gfx::Display& display_1 = | 455 gfx::Display& display_1 = |
355 display_manager()->FindDisplayForRootWindow(root_windows[0]); | 456 display_manager()->FindDisplayForRootWindow(root_windows[0]); |
356 EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); | 457 EXPECT_EQ("0,0", display_1.bounds().origin().ToString()); |
357 gfx::Display& display_2 = | 458 gfx::Display& display_2 = |
(...skipping 22 matching lines...) Expand all Loading... |
380 // Convert point in the Root1's window to the Root2's window Coord. | 481 // Convert point in the Root1's window to the Root2's window Coord. |
381 p.SetPoint(0, 0); | 482 p.SetPoint(0, 0); |
382 aura::Window::ConvertPointToWindow(root_windows[0], root_windows[1], &p); | 483 aura::Window::ConvertPointToWindow(root_windows[0], root_windows[1], &p); |
383 EXPECT_EQ("-500,-500", p.ToString()); | 484 EXPECT_EQ("-500,-500", p.ToString()); |
384 p.SetPoint(0, 0); | 485 p.SetPoint(0, 0); |
385 aura::Window::ConvertPointToWindow(d1, d2, &p); | 486 aura::Window::ConvertPointToWindow(d1, d2, &p); |
386 EXPECT_EQ("-510,-510", p.ToString()); | 487 EXPECT_EQ("-510,-510", p.ToString()); |
387 } | 488 } |
388 } // namespace internal | 489 } // namespace internal |
389 } // namespace ash | 490 } // namespace ash |
OLD | NEW |