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/display/display_controller.h" |
11 #include "ash/screen_ash.h" | 11 #include "ash/screen_ash.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/wm/coordinate_conversion.h" | 13 #include "ash/wm/coordinate_conversion.h" |
14 #include "ash/wm/cursor_manager.h" | 14 #include "ash/wm/cursor_manager.h" |
15 #include "ash/wm/property_util.h" | 15 #include "ash/wm/property_util.h" |
16 #include "ash/wm/window_util.h" | 16 #include "ash/wm/window_util.h" |
17 #include "ash/wm/workspace/phantom_window_controller.h" | 17 #include "ash/wm/workspace/phantom_window_controller.h" |
18 #include "ash/wm/workspace/snap_sizer.h" | 18 #include "ash/wm/workspace/snap_sizer.h" |
19 #include "ui/aura/client/aura_constants.h" | 19 #include "ui/aura/client/aura_constants.h" |
20 #include "ui/aura/env.h" | |
21 #include "ui/aura/root_window.h" | 20 #include "ui/aura/root_window.h" |
22 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
23 #include "ui/aura/window_delegate.h" | 22 #include "ui/aura/window_delegate.h" |
24 #include "ui/base/hit_test.h" | 23 #include "ui/base/hit_test.h" |
25 #include "ui/compositor/layer.h" | 24 #include "ui/compositor/layer.h" |
26 #include "ui/compositor/scoped_layer_animation_settings.h" | 25 #include "ui/compositor/scoped_layer_animation_settings.h" |
27 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
28 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
29 | 28 |
30 namespace ash { | 29 namespace ash { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 } | 83 } |
85 | 84 |
86 void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 85 void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) { |
87 std::pair<aura::RootWindow*, gfx::Point> actual_location = | 86 std::pair<aura::RootWindow*, gfx::Point> actual_location = |
88 wm::GetRootWindowRelativeToWindow(window()->parent(), location); | 87 wm::GetRootWindowRelativeToWindow(window()->parent(), location); |
89 aura::RootWindow* current_root = actual_location.first; | 88 aura::RootWindow* current_root = actual_location.first; |
90 gfx::Point location_in_parent = actual_location.second; | 89 gfx::Point location_in_parent = actual_location.second; |
91 aura::Window::ConvertPointToTarget(current_root, | 90 aura::Window::ConvertPointToTarget(current_root, |
92 window()->parent(), | 91 window()->parent(), |
93 &location_in_parent); | 92 &location_in_parent); |
| 93 last_mouse_location_ = location_in_parent; |
94 | 94 |
95 // Do not use |location| below this point, use |location_in_parent| instead. | 95 // Do not use |location| below this point, use |location_in_parent| instead. |
96 // When the pointer is on |window()->GetRootWindow()|, |location| and | 96 // When the pointer is on |window()->GetRootWindow()|, |location| and |
97 // |location_in_parent| have the same value and both of them are in | 97 // |location_in_parent| have the same value and both of them are in |
98 // |window()->parent()|'s coordinates, but once the pointer enters the | 98 // |window()->parent()|'s coordinates, but once the pointer enters the |
99 // other root window, you will see an unexpected value on the former. See | 99 // other root window, you will see an unexpected value on the former. See |
100 // comments in wm::GetRootWindowRelativeToWindow() for details. | 100 // comments in wm::GetRootWindowRelativeToWindow() for details. |
101 | 101 |
102 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? | 102 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? |
103 0 : ash::Shell::GetInstance()->GetGridSize(); | 103 0 : ash::Shell::GetInstance()->GetGridSize(); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 | 140 |
141 if (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE) { | 141 if (snap_type_ == SNAP_LEFT_EDGE || snap_type_ == SNAP_RIGHT_EDGE) { |
142 if (!GetRestoreBoundsInScreen(details_.window)) | 142 if (!GetRestoreBoundsInScreen(details_.window)) |
143 SetRestoreBoundsInParent(details_.window, details_.initial_bounds); | 143 SetRestoreBoundsInParent(details_.window, details_.initial_bounds); |
144 details_.window->SetBounds(snap_sizer_->target_bounds()); | 144 details_.window->SetBounds(snap_sizer_->target_bounds()); |
145 return; | 145 return; |
146 } | 146 } |
147 | 147 |
148 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? | 148 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? |
149 0 : ash::Shell::GetInstance()->GetGridSize(); | 149 0 : ash::Shell::GetInstance()->GetGridSize(); |
150 if (grid_size <= 1) | 150 gfx::Rect bounds(GetFinalBounds(details_.window->bounds(), grid_size)); |
| 151 |
| 152 // Check if the destination is another display. |
| 153 gfx::Point last_mouse_location_in_screen = last_mouse_location_; |
| 154 wm::ConvertPointToScreen(window()->parent(), &last_mouse_location_in_screen); |
| 155 const gfx::Display dst_display = |
| 156 gfx::Screen::GetDisplayNearestPoint(last_mouse_location_in_screen); |
| 157 |
| 158 if (dst_display.id() != |
| 159 gfx::Screen::GetDisplayNearestWindow(window()->GetRootWindow()).id()) { |
| 160 // Don't animate when moving to another display. |
| 161 const gfx::Rect dst_bounds = |
| 162 ScreenAsh::ConvertRectToScreen(details_.window->parent(), bounds); |
| 163 details_.window->SetBoundsInScreen(dst_bounds, dst_display); |
151 return; | 164 return; |
| 165 } |
152 | 166 |
153 gfx::Rect bounds(GetFinalBounds(details_.window->bounds(), grid_size)); | 167 if (grid_size <= 1 || bounds == details_.window->bounds()) |
154 if (bounds == details_.window->bounds()) | |
155 return; | 168 return; |
156 | 169 |
157 if (bounds.size() != details_.window->bounds().size()) { | 170 if (bounds.size() != details_.window->bounds().size()) { |
158 // Don't attempt to animate a size change. | 171 // Don't attempt to animate a size change. |
159 details_.window->SetBounds(bounds); | 172 details_.window->SetBounds(bounds); |
160 return; | 173 return; |
161 } | 174 } |
162 // TODO(oshima|yusukes): This is temporary solution until better drag & move | 175 |
163 // is implemented. (crbug.com/136816). | 176 ui::ScopedLayerAnimationSettings scoped_setter( |
164 gfx::Rect dst_bounds = | 177 details_.window->layer()->GetAnimator()); |
165 ScreenAsh::ConvertRectToScreen(details_.window->parent(), bounds); | 178 // Use a small duration since the grid is small. |
166 gfx::Display dst_display = gfx::Screen::GetDisplayMatching(dst_bounds); | 179 scoped_setter.SetTransitionDuration( |
167 if (dst_display.id() != | 180 base::TimeDelta::FromMilliseconds(kSnapDurationMS)); |
168 gfx::Screen::GetDisplayNearestWindow(details_.window).id()) { | 181 details_.window->SetBounds(bounds); |
169 // Don't animate when moving to another display. | |
170 details_.window->SetBoundsInScreen(dst_bounds); | |
171 } else { | |
172 ui::ScopedLayerAnimationSettings scoped_setter( | |
173 details_.window->layer()->GetAnimator()); | |
174 // Use a small duration since the grid is small. | |
175 scoped_setter.SetTransitionDuration( | |
176 base::TimeDelta::FromMilliseconds(kSnapDurationMS)); | |
177 details_.window->SetBounds(bounds); | |
178 } | |
179 } | 182 } |
180 | 183 |
181 void WorkspaceWindowResizer::RevertDrag() { | 184 void WorkspaceWindowResizer::RevertDrag() { |
182 drag_phantom_window_controller_.reset(); | 185 drag_phantom_window_controller_.reset(); |
183 snap_phantom_window_controller_.reset(); | 186 snap_phantom_window_controller_.reset(); |
184 | 187 |
185 if (!did_move_or_resize_) | 188 if (!did_move_or_resize_) |
186 return; | 189 return; |
187 | 190 |
188 details_.window->SetBounds(details_.initial_bounds); | 191 details_.window->SetBounds(details_.initial_bounds); |
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
538 } | 541 } |
539 | 542 |
540 bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const { | 543 bool WorkspaceWindowResizer::ShouldAllowMouseWarp() const { |
541 return (details_.window_component == HTCAPTION) && | 544 return (details_.window_component == HTCAPTION) && |
542 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && | 545 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && |
543 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); | 546 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); |
544 } | 547 } |
545 | 548 |
546 } // namespace internal | 549 } // namespace internal |
547 } // namespace ash | 550 } // namespace ash |
OLD | NEW |