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" | |
20 #include "ui/aura/client/screen_position_client.h" | |
17 #include "ui/aura/env.h" | 21 #include "ui/aura/env.h" |
18 #include "ui/aura/window.h" | 22 #include "ui/aura/window.h" |
19 #include "ui/aura/window_delegate.h" | 23 #include "ui/aura/window_delegate.h" |
24 #include "ui/aura/root_window.h" | |
20 #include "ui/base/hit_test.h" | 25 #include "ui/base/hit_test.h" |
21 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
22 #include "ui/compositor/scoped_layer_animation_settings.h" | 27 #include "ui/compositor/scoped_layer_animation_settings.h" |
23 #include "ui/gfx/screen.h" | 28 #include "ui/gfx/screen.h" |
24 #include "ui/gfx/transform.h" | 29 #include "ui/gfx/transform.h" |
25 | 30 |
26 namespace ash { | 31 namespace ash { |
27 namespace internal { | 32 namespace internal { |
28 | 33 |
29 namespace { | 34 namespace { |
30 | 35 |
31 // Duration of the animation when snapping the window into place. | 36 // Duration of the animation when snapping the window into place. |
32 const int kSnapDurationMS = 100; | 37 const int kSnapDurationMS = 100; |
33 | 38 |
34 // Returns true if should snap to the edge. | 39 // Returns true if should snap to the edge. |
35 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { | 40 bool ShouldSnapToEdge(int distance_from_edge, int grid_size) { |
36 return distance_from_edge <= grid_size / 2 && | 41 return distance_from_edge <= grid_size / 2 && |
37 distance_from_edge > -grid_size * 2; | 42 distance_from_edge > -grid_size * 2; |
38 } | 43 } |
39 | 44 |
40 } // namespace | 45 } // namespace |
41 | 46 |
42 // static | 47 // static |
43 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; | 48 const int WorkspaceWindowResizer::kMinOnscreenSize = 20; |
44 | 49 |
45 // static | 50 // static |
46 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; | 51 const int WorkspaceWindowResizer::kMinOnscreenHeight = 32; |
47 | 52 |
48 WorkspaceWindowResizer::~WorkspaceWindowResizer() { | 53 WorkspaceWindowResizer::~WorkspaceWindowResizer() { |
49 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); | 54 Shell* shell = Shell::GetInstance(); |
55 if (ShouldAllowCursorWarp()) | |
56 shell->display_controller()->set_allow_warp_during_lock(false); | |
57 shell->cursor_manager()->UnlockCursor(); | |
50 } | 58 } |
51 | 59 |
52 // static | 60 // static |
53 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( | 61 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( |
54 aura::Window* window, | 62 aura::Window* window, |
55 const gfx::Point& location_in_parent, | 63 const gfx::Point& location_in_parent, |
56 int window_component, | 64 int window_component, |
57 const std::vector<aura::Window*>& attached_windows) { | 65 const std::vector<aura::Window*>& attached_windows) { |
58 Details details(window, location_in_parent, window_component); | 66 Details details(window, location_in_parent, window_component); |
59 return details.is_resizable ? | 67 return details.is_resizable ? |
60 new WorkspaceWindowResizer(details, attached_windows) : NULL; | 68 new WorkspaceWindowResizer(details, attached_windows) : NULL; |
61 } | 69 } |
62 | 70 |
63 void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 71 void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
72 std::pair<aura::RootWindow*, gfx::Point> actual_location = | |
73 wm::GetRootWindowRelativeToWindow(window()->parent(), location); | |
74 | |
75 aura::RootWindow* current_root = actual_location.first; | |
76 gfx::Point location_in_root = actual_location.second; | |
77 gfx::Point location_in_screen = actual_location.second; | |
78 aura::client::GetScreenPositionClient(current_root)-> | |
79 ConvertPointToScreen(current_root, &location_in_screen); | |
80 | |
81 // TODO(yusukes): Implement dragging a window from one display to another. | |
82 if (current_root != window()->GetRootWindow()) | |
83 return; | |
84 | |
64 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? | 85 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? |
65 0 : ash::Shell::GetInstance()->GetGridSize(); | 86 0 : ash::Shell::GetInstance()->GetGridSize(); |
66 gfx::Rect bounds = CalculateBoundsForDrag(details_, location, grid_size); | 87 gfx::Rect bounds = |
88 CalculateBoundsForDrag(details_, location_in_root, grid_size); | |
67 | 89 |
68 if (wm::IsWindowNormal(details_.window)) | 90 if (wm::IsWindowNormal(details_.window)) |
69 AdjustBoundsForMainWindow(&bounds, grid_size); | 91 AdjustBoundsForMainWindow(&bounds, grid_size); |
70 if (bounds != details_.window->bounds()) { | 92 if (bounds != details_.window->bounds()) { |
71 if (!did_move_or_resize_) | 93 if (!did_move_or_resize_) |
72 RestackWindows(); | 94 RestackWindows(); |
73 did_move_or_resize_ = true; | 95 did_move_or_resize_ = true; |
74 } | 96 } |
75 UpdatePhantomWindow(location, bounds, grid_size); | 97 UpdatePhantomWindow(location_in_root, bounds, grid_size); |
76 if (!attached_windows_.empty()) | 98 if (!attached_windows_.empty()) |
77 LayoutAttachedWindows(bounds, grid_size); | 99 LayoutAttachedWindows(bounds, grid_size); |
78 if (bounds != details_.window->bounds()) | 100 if (bounds != details_.window->bounds()) |
79 details_.window->SetBounds(bounds); | 101 details_.window->SetBounds(bounds); |
80 // WARNING: we may have been deleted. | 102 // WARNING: we may have been deleted. |
81 } | 103 } |
82 | 104 |
83 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { | 105 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
84 phantom_window_controller_.reset(); | 106 phantom_window_controller_.reset(); |
85 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 107 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 const Details& details, | 179 const Details& details, |
158 const std::vector<aura::Window*>& attached_windows) | 180 const std::vector<aura::Window*>& attached_windows) |
159 : details_(details), | 181 : details_(details), |
160 attached_windows_(attached_windows), | 182 attached_windows_(attached_windows), |
161 did_move_or_resize_(false), | 183 did_move_or_resize_(false), |
162 total_min_(0), | 184 total_min_(0), |
163 total_initial_size_(0), | 185 total_initial_size_(0), |
164 snap_type_(SNAP_NONE), | 186 snap_type_(SNAP_NONE), |
165 num_mouse_moves_since_bounds_change_(0) { | 187 num_mouse_moves_since_bounds_change_(0) { |
166 DCHECK(details_.is_resizable); | 188 DCHECK(details_.is_resizable); |
167 ash::Shell::GetInstance()->cursor_manager()->LockCursor(); | 189 |
190 Shell* shell = Shell::GetInstance(); | |
191 shell->cursor_manager()->LockCursor(); | |
192 if (ShouldAllowCursorWarp()) | |
193 shell->display_controller()->set_allow_warp_during_lock(true); | |
sky
2012/08/03 17:07:18
I don't get why we need this. Can't it be inferred
Yusuke Sato
2012/08/03 23:18:45
I think we need to confine a mouse pointer in one
| |
168 | 194 |
169 // Only support attaching to the right/bottom. | 195 // Only support attaching to the right/bottom. |
170 DCHECK(attached_windows_.empty() || | 196 DCHECK(attached_windows_.empty() || |
171 (details.window_component == HTRIGHT || | 197 (details.window_component == HTRIGHT || |
172 details.window_component == HTBOTTOM)); | 198 details.window_component == HTBOTTOM)); |
173 | 199 |
174 // TODO: figure out how to deal with window going off the edge. | 200 // TODO: figure out how to deal with window going off the edge. |
175 | 201 |
176 // Calculate sizes so that we can maintain the ratios if we need to resize. | 202 // Calculate sizes so that we can maintain the ratios if we need to resize. |
177 int total_available = 0; | 203 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 | 460 // TODO: this likely only wants total display area, not the area of a single |
435 // display. | 461 // display. |
436 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(details_.window)); | 462 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(details_.window)); |
437 if (location.x() <= area.x()) | 463 if (location.x() <= area.x()) |
438 return SNAP_LEFT_EDGE; | 464 return SNAP_LEFT_EDGE; |
439 if (location.x() >= area.right() - 1) | 465 if (location.x() >= area.right() - 1) |
440 return SNAP_RIGHT_EDGE; | 466 return SNAP_RIGHT_EDGE; |
441 return SNAP_NONE; | 467 return SNAP_NONE; |
442 } | 468 } |
443 | 469 |
470 bool WorkspaceWindowResizer::ShouldAllowCursorWarp() const { | |
471 return (details_.window_component == HTCAPTION) && | |
472 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && | |
473 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); | |
474 } | |
475 | |
444 } // namespace internal | 476 } // namespace internal |
445 } // namespace ash | 477 } // namespace ash |
OLD | NEW |