| 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/wm/drag_window_resizer.h" | 5 #include "ash/wm/drag_window_resizer.h" |
| 6 | 6 |
| 7 #include "ash/display/mouse_cursor_event_filter.h" | 7 #include "ash/display/mouse_cursor_event_filter.h" |
| 8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" | 9 #include "ash/shelf/shelf_layout_manager.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 12 #include "ash/test/ash_test_base.h" | 12 #include "ash/test/ash_test_base.h" |
| 13 #include "ash/test/cursor_manager_test_api.h" | 13 #include "ash/test/cursor_manager_test_api.h" |
| 14 #include "ash/wm/drag_window_controller.h" | 14 #include "ash/wm/drag_window_controller.h" |
| 15 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
| 18 #include "ui/aura/client/aura_constants.h" | 18 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/test/test_window_delegate.h" | 19 #include "ui/aura/test/test_window_delegate.h" |
| 20 #include "ui/aura/window_event_dispatcher.h" | 20 #include "ui/aura/window_event_dispatcher.h" |
| 21 #include "ui/base/hit_test.h" | 21 #include "ui/base/hit_test.h" |
| 22 #include "ui/base/ui_base_types.h" | 22 #include "ui/base/ui_base_types.h" |
| 23 #include "ui/compositor/layer_tree_owner.h" | 23 #include "ui/compositor/layer_tree_owner.h" |
| 24 #include "ui/gfx/insets.h" | 24 #include "ui/gfx/insets.h" |
| 25 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
| 26 #include "ui/views/widget/widget.h" | 26 #include "ui/views/widget/widget.h" |
| 27 #include "ui/wm/core/window_util.h" | 27 #include "ui/wm/core/window_util.h" |
| 28 | 28 |
| 29 namespace ash { | 29 namespace ash { |
| 30 namespace internal { | |
| 31 namespace { | 30 namespace { |
| 32 | 31 |
| 33 const int kRootHeight = 600; | 32 const int kRootHeight = 600; |
| 34 | 33 |
| 35 } // namespace | 34 } // namespace |
| 36 | 35 |
| 37 class DragWindowResizerTest : public test::AshTestBase { | 36 class DragWindowResizerTest : public test::AshTestBase { |
| 38 public: | 37 public: |
| 39 DragWindowResizerTest() {} | 38 DragWindowResizerTest() {} |
| 40 virtual ~DragWindowResizerTest() {} | 39 virtual ~DragWindowResizerTest() {} |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 protected: | 99 protected: |
| 101 gfx::Point CalculateDragPoint(const WindowResizer& resizer, | 100 gfx::Point CalculateDragPoint(const WindowResizer& resizer, |
| 102 int delta_x, | 101 int delta_x, |
| 103 int delta_y) const { | 102 int delta_y) const { |
| 104 gfx::Point location = resizer.GetInitialLocation(); | 103 gfx::Point location = resizer.GetInitialLocation(); |
| 105 location.set_x(location.x() + delta_x); | 104 location.set_x(location.x() + delta_x); |
| 106 location.set_y(location.y() + delta_y); | 105 location.set_y(location.y() + delta_y); |
| 107 return location; | 106 return location; |
| 108 } | 107 } |
| 109 | 108 |
| 110 internal::ShelfLayoutManager* shelf_layout_manager() { | 109 ShelfLayoutManager* shelf_layout_manager() { |
| 111 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); | 110 return Shell::GetPrimaryRootWindowController()->GetShelfLayoutManager(); |
| 112 } | 111 } |
| 113 | 112 |
| 114 static WindowResizer* CreateDragWindowResizer( | 113 static WindowResizer* CreateDragWindowResizer( |
| 115 aura::Window* window, | 114 aura::Window* window, |
| 116 const gfx::Point& point_in_parent, | 115 const gfx::Point& point_in_parent, |
| 117 int window_component) { | 116 int window_component) { |
| 118 return CreateWindowResizer( | 117 return CreateWindowResizer( |
| 119 window, | 118 window, |
| 120 point_in_parent, | 119 point_in_parent, |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 ASSERT_EQ(2U, root_windows.size()); | 348 ASSERT_EQ(2U, root_windows.size()); |
| 350 | 349 |
| 351 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 350 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 352 Shell::GetScreen()->GetPrimaryDisplay()); | 351 Shell::GetScreen()->GetPrimaryDisplay()); |
| 353 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 352 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 354 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 353 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 355 { | 354 { |
| 356 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 355 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
| 357 window_.get(), gfx::Point(), HTCAPTION)); | 356 window_.get(), gfx::Point(), HTCAPTION)); |
| 358 ASSERT_TRUE(resizer.get()); | 357 ASSERT_TRUE(resizer.get()); |
| 359 internal::DragWindowResizer* drag_resizer = DragWindowResizer::instance_; | 358 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; |
| 360 ASSERT_TRUE(drag_resizer); | 359 ASSERT_TRUE(drag_resizer); |
| 361 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); | 360 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); |
| 362 | 361 |
| 363 // The pointer is inside the primary root. The drag window controller | 362 // The pointer is inside the primary root. The drag window controller |
| 364 // should be NULL. | 363 // should be NULL. |
| 365 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); | 364 resizer->Drag(CalculateDragPoint(*resizer, 10, 10), 0); |
| 366 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); | 365 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); |
| 367 | 366 |
| 368 // The window spans both root windows. | 367 // The window spans both root windows. |
| 369 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0); | 368 resizer->Drag(CalculateDragPoint(*resizer, 798, 10), 0); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 | 400 |
| 402 // Do the same test with RevertDrag(). | 401 // Do the same test with RevertDrag(). |
| 403 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), | 402 window_->SetBoundsInScreen(gfx::Rect(0, 0, 50, 60), |
| 404 Shell::GetScreen()->GetPrimaryDisplay()); | 403 Shell::GetScreen()->GetPrimaryDisplay()); |
| 405 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 404 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 406 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 405 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 407 { | 406 { |
| 408 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 407 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
| 409 window_.get(), gfx::Point(), HTCAPTION)); | 408 window_.get(), gfx::Point(), HTCAPTION)); |
| 410 ASSERT_TRUE(resizer.get()); | 409 ASSERT_TRUE(resizer.get()); |
| 411 internal::DragWindowResizer* drag_resizer = DragWindowResizer::instance_; | 410 DragWindowResizer* drag_resizer = DragWindowResizer::instance_; |
| 412 ASSERT_TRUE(drag_resizer); | 411 ASSERT_TRUE(drag_resizer); |
| 413 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); | 412 EXPECT_FALSE(drag_resizer->drag_window_controller_.get()); |
| 414 | 413 |
| 415 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); | 414 resizer->Drag(CalculateDragPoint(*resizer, 0, 610), 0); |
| 416 resizer->RevertDrag(); | 415 resizer->RevertDrag(); |
| 417 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); | 416 EXPECT_EQ(root_windows[0], window_->GetRootWindow()); |
| 418 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); | 417 EXPECT_FLOAT_EQ(1.0f, window_->layer()->opacity()); |
| 419 } | 418 } |
| 420 } | 419 } |
| 421 | 420 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 501 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
| 503 resizer->CompleteDrag(); | 502 resizer->CompleteDrag(); |
| 504 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 503 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
| 505 } | 504 } |
| 506 | 505 |
| 507 // Move window from the root window with 2.0 device scale factor to the root | 506 // Move window from the root window with 2.0 device scale factor to the root |
| 508 // window with 1.0 device scale factor. | 507 // window with 1.0 device scale factor. |
| 509 { | 508 { |
| 510 // Make sure the window is on the default container first. | 509 // Make sure the window is on the default container first. |
| 511 aura::Window* default_container = | 510 aura::Window* default_container = |
| 512 GetRootWindowController(root_windows[1])->GetContainer( | 511 GetRootWindowController(root_windows[1]) |
| 513 internal::kShellWindowId_DefaultContainer); | 512 ->GetContainer(kShellWindowId_DefaultContainer); |
| 514 default_container->AddChild(window_.get()); | 513 default_container->AddChild(window_.get()); |
| 515 window_->SetBoundsInScreen( | 514 window_->SetBoundsInScreen( |
| 516 gfx::Rect(600, 0, 50, 60), | 515 gfx::Rect(600, 0, 50, 60), |
| 517 Shell::GetScreen()->GetDisplayNearestWindow(root_windows[1])); | 516 Shell::GetScreen()->GetDisplayNearestWindow(root_windows[1])); |
| 518 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 517 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
| 519 // Grab (0, 0) of the window. | 518 // Grab (0, 0) of the window. |
| 520 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 519 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
| 521 window_.get(), gfx::Point(), HTCAPTION)); | 520 window_.get(), gfx::Point(), HTCAPTION)); |
| 522 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); | 521 EXPECT_EQ(2.0f, cursor_test_api.GetDisplay().device_scale_factor()); |
| 523 ASSERT_TRUE(resizer.get()); | 522 ASSERT_TRUE(resizer.get()); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( | 625 scoped_ptr<WindowResizer> resizer(CreateDragWindowResizer( |
| 627 window, gfx::Point(), HTCAPTION)); | 626 window, gfx::Point(), HTCAPTION)); |
| 628 ASSERT_TRUE(resizer.get()); | 627 ASSERT_TRUE(resizer.get()); |
| 629 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); | 628 resizer->Drag(CalculateDragPoint(*resizer, 399, 200), 0); |
| 630 EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[0], | 629 EXPECT_TRUE(WarpMouseCursorIfNecessary(root_windows[0], |
| 631 gfx::Point(399, 200))); | 630 gfx::Point(399, 200))); |
| 632 resizer->CompleteDrag(); | 631 resizer->CompleteDrag(); |
| 633 } | 632 } |
| 634 } | 633 } |
| 635 | 634 |
| 636 } // namespace internal | |
| 637 } // namespace ash | 635 } // namespace ash |
| OLD | NEW |