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/workspace/workspace_window_resizer.h" | 5 #include "ash/wm/workspace/workspace_window_resizer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "ash/display/display_controller.h" | |
10 #include "ash/screen_ash.h" | 11 #include "ash/screen_ash.h" |
11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/wm/coordinate_conversion.h" | |
12 #include "ash/wm/cursor_manager.h" | 14 #include "ash/wm/cursor_manager.h" |
13 #include "ash/wm/property_util.h" | 15 #include "ash/wm/property_util.h" |
14 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
15 #include "ash/wm/workspace/phantom_window_controller.h" | 17 #include "ash/wm/workspace/phantom_window_controller.h" |
16 #include "ash/wm/workspace/snap_sizer.h" | 18 #include "ash/wm/workspace/snap_sizer.h" |
19 #include "ui/aura/client/aura_constants.h" | |
17 #include "ui/aura/env.h" | 20 #include "ui/aura/env.h" |
18 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
23 #include "ui/aura/root_window.h" | |
Daniel Erat
2012/08/06 18:16:20
nit: fix alphabetization
Yusuke Sato
2012/08/06 18:27:06
Done.
| |
20 #include "ui/base/hit_test.h" | 24 #include "ui/base/hit_test.h" |
21 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
22 #include "ui/compositor/scoped_layer_animation_settings.h" | 26 #include "ui/compositor/scoped_layer_animation_settings.h" |
23 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
24 #include "ui/gfx/transform.h" | 28 #include "ui/gfx/transform.h" |
25 | 29 |
26 namespace ash { | 30 namespace ash { |
27 namespace internal { | 31 namespace internal { |
28 | 32 |
29 namespace { | 33 namespace { |
30 | 34 |
31 // Duration of the animation when snapping the window into place. | 35 // Duration of the animation when snapping the window into place. |
32 const int kSnapDurationMS = 100; | 36 const int kSnapDurationMS = 100; |
33 | 37 |
34 // Returns true if should snap to the edge. | 38 // Returns true if should snap to the edge. |
35 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { | 39 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { |
36 return distance_from_edge <= grid_size / 2 && | 40 return distance_from_edge <= grid_size / 2 && |
37 distance_from_edge > -grid_size * 2; | 41 distance_from_edge > -grid_size * 2; |
38 } | 42 } |
39 | 43 |
40 } // namespace | 44 } // namespace |
41 | 45 |
42 // static | 46 // static |
43 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; | 47 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; |
44 | 48 |
45 // static | 49 // static |
46 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; | 50 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; |
47 | 51 |
48 WorkspaceWindowResizer::~WorkspaceWindowResizer() { | 52 WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
49 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); | 53 Shell* shell = Shell::GetInstance(); |
54 shell->display_controller()->set_dont_warp_mouse(false); | |
55 shell->cursor_manager()->UnlockCursor(); | |
50 } | 56 } |
51 | 57 |
52 // static | 58 // static |
53 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( | 59 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( |
54 aura::Window* window, | 60 aura::Window* window, |
55 const gfx::Point& location_in_parent, | 61 const gfx::Point& location_in_parent, |
56 int window_component, | 62 int window_component, |
57 const std::vector<aura::Window*>& attached_windows) { | 63 const std::vector<aura::Window*>& attached_windows) { |
58 Details details(window, location_in_parent, window_component); | 64 Details details(window, location_in_parent, window_component); |
59 return details.is_resizable ? | 65 return details.is_resizable ? |
60 new WorkspaceWindowResizer(details, attached_windows) : NULL; | 66 new WorkspaceWindowResizer(details, attached_windows) : NULL; |
61 } | 67 } |
62 | 68 |
63 void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 69 void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
70 std::pair<aura::RootWindow*, gfx::Point> actual_location = | |
71 wm::GetRootWindowRelativeToWindow(window()->parent(), location); | |
72 | |
73 // TODO(yusukes): Implement dragging a window from one display to another. | |
74 aura::RootWindow* current_root = actual_location.first; | |
75 if (current_root != window()->GetRootWindow()) | |
76 return; | |
77 | |
64 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? | 78 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? |
65 0 : ash::Shell::GetInstance()->GetGridSize(); | 79 0 : ash::Shell::GetInstance()->GetGridSize(); |
66 gfx::Rect bounds = CalculateBoundsForDrag(details_, location, grid_size); | 80 gfx::Rect bounds = CalculateBoundsForDrag(details_, location, grid_size); |
67 | 81 |
68 if (wm::IsWindowNormal(details_.window)) | 82 if (wm::IsWindowNormal(details_.window)) |
69 AdjustBoundsForMainWindow(&bounds, grid_size); | 83 AdjustBoundsForMainWindow(&bounds, grid_size); |
70 if (bounds != details_.window->bounds()) { | 84 if (bounds != details_.window->bounds()) { |
71 if (!did_move_or_resize_) | 85 if (!did_move_or_resize_) |
72 RestackWindows(); | 86 RestackWindows(); |
73 did_move_or_resize_ = true; | 87 did_move_or_resize_ = true; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 const Details& details, | 171 const Details& details, |
158 const std::vector<aura::Window*>& attached_windows) | 172 const std::vector<aura::Window*>& attached_windows) |
159 : details_(details), | 173 : details_(details), |
160 attached_windows_(attached_windows), | 174 attached_windows_(attached_windows), |
161 did_move_or_resize_(false), | 175 did_move_or_resize_(false), |
162 total_min_(0), | 176 total_min_(0), |
163 total_initial_size_(0), | 177 total_initial_size_(0), |
164 snap_type_(SNAP_NONE), | 178 snap_type_(SNAP_NONE), |
165 num_mouse_moves_since_bounds_change_(0) { | 179 num_mouse_moves_since_bounds_change_(0) { |
166 DCHECK(details_.is_resizable); | 180 DCHECK(details_.is_resizable); |
167 ash::Shell::GetInstance()->cursor_manager()->LockCursor(); | 181 |
182 Shell* shell = Shell::GetInstance(); | |
183 shell->cursor_manager()->LockCursor(); | |
184 | |
185 // The pointer should be confined in one display during resizing a window | |
186 // because the window cannot span two displays at the same time anyway. The | |
187 // exception is window/tab dragging operation. During that operation, | |
188 // |dont_warp_mouse_| should be set to false so that the user could move a | |
189 // window/tab to another display. | |
190 shell->display_controller()->set_dont_warp_mouse(!ShouldAllowMouseWarp()); | |
168 | 191 |
169 // Only support attaching to the right/bottom. | 192 // Only support attaching to the right/bottom. |
170 DCHECK(attached_windows_.empty() || | 193 DCHECK(attached_windows_.empty() || |
171 (details.window_component == HTRIGHT || | 194 (details.window_component == HTRIGHT || |
172 details.window_component == HTBOTTOM)); | 195 details.window_component == HTBOTTOM)); |
173 | 196 |
174 // TODO: figure out how to deal with window going off the edge. | 197 // TODO: figure out how to deal with window going off the edge. |
175 | 198 |
176 // Calculate sizes so that we can maintain the ratios if we need to resize. | 199 // Calculate sizes so that we can maintain the ratios if we need to resize. |
177 int total_available = 0; | 200 int total_available = 0; |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
434 // TODO: this likely only wants total display area, not the area of a single | 457 // TODO: this likely only wants total display area, not the area of a single |
435 // display. | 458 // display. |
436 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(details_.window)); | 459 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(details_.window)); |
437 if (location.x() <= area.x()) | 460 if (location.x() <= area.x()) |
438 return SNAP_LEFT_EDGE; | 461 return SNAP_LEFT_EDGE; |
439 if (location.x() >= area.right() - 1) | 462 if (location.x() >= area.right() - 1) |
440 return SNAP_RIGHT_EDGE; | 463 return SNAP_RIGHT_EDGE; |
441 return SNAP_NONE; | 464 return SNAP_NONE; |
442 } | 465 } |
443 | 466 |
467 bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const { | |
468 return (details_.window_component == HTCAPTION) && | |
469 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && | |
470 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); | |
471 } | |
472 | |
444 } // namespace internal | 473 } // namespace internal |
445 } // namespace ash | 474 } // namespace ash |
OLD | NEW |