| 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" |
| 12 #include "ash/wm/cursor_manager.h" | 13 #include "ash/wm/cursor_manager.h" |
| 13 #include "ash/wm/property_util.h" | 14 #include "ash/wm/property_util.h" |
| 14 #include "ash/wm/window_util.h" | 15 #include "ash/wm/window_util.h" |
| 15 #include "ash/wm/workspace/phantom_window_controller.h" | 16 #include "ash/wm/workspace/phantom_window_controller.h" |
| 16 #include "ash/wm/workspace/snap_sizer.h" | 17 #include "ash/wm/workspace/snap_sizer.h" |
| 18 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/client/screen_position_client.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" |
| 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 if (ShouldAllowCursorWarp()) |
| 55 shell->display_controller()->set_allow_warp_during_lock(false); |
| 56 shell->cursor_manager()->UnlockCursor(); |
| 50 } | 57 } |
| 51 | 58 |
| 52 // static | 59 // static |
| 53 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( | 60 WorkspaceWindowResizer* WorkspaceWindowResizer::Create( |
| 54 aura::Window* window, | 61 aura::Window* window, |
| 55 const gfx::Point& location_in_parent, | 62 const gfx::Point& location_in_parent, |
| 56 int window_component, | 63 int window_component, |
| 57 const std::vector<aura::Window*>& attached_windows) { | 64 const std::vector<aura::Window*>& attached_windows) { |
| 58 Details details(window, location_in_parent, window_component); | 65 Details details(window, location_in_parent, window_component); |
| 59 return details.is_resizable ? | 66 return details.is_resizable ? |
| 60 new WorkspaceWindowResizer(details, attached_windows) : NULL; | 67 new WorkspaceWindowResizer(details, attached_windows) : NULL; |
| 61 } | 68 } |
| 62 | 69 |
| 63 void WorkspaceWindowResizer::Drag(const gfx::Point& location, int event_flags) { | 70 void WorkspaceWindowResizer::Drag(const gfx::Point& location_in_screen, |
| 71 int event_flags) { |
| 72 // TODO(yusukes): Implement dragging a window from one display to another. |
| 73 aura::RootWindow* current_root = Shell::GetRootWindowAt(location_in_screen); |
| 74 if (current_root != window()->GetRootWindow()) |
| 75 return; |
| 76 |
| 77 gfx::Point location_in_root = location_in_screen; |
| 78 aura::client::GetScreenPositionClient(current_root)-> |
| 79 ConvertPointFromScreen(current_root, &location_in_root); |
| 80 |
| 64 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? | 81 int grid_size = event_flags & ui::EF_CONTROL_DOWN ? |
| 65 0 : ash::Shell::GetInstance()->GetGridSize(); | 82 0 : ash::Shell::GetInstance()->GetGridSize(); |
| 66 gfx::Rect bounds = CalculateBoundsForDrag(details_, location, grid_size); | 83 gfx::Rect bounds = |
| 84 CalculateBoundsForDrag(details_, location_in_root, grid_size); |
| 67 | 85 |
| 68 if (wm::IsWindowNormal(details_.window)) | 86 if (wm::IsWindowNormal(details_.window)) |
| 69 AdjustBoundsForMainWindow(&bounds, grid_size); | 87 AdjustBoundsForMainWindow(&bounds, grid_size); |
| 70 if (bounds != details_.window->bounds()) { | 88 if (bounds != details_.window->bounds()) { |
| 71 if (!did_move_or_resize_) | 89 if (!did_move_or_resize_) |
| 72 RestackWindows(); | 90 RestackWindows(); |
| 73 did_move_or_resize_ = true; | 91 did_move_or_resize_ = true; |
| 74 } | 92 } |
| 75 UpdatePhantomWindow(location, bounds, grid_size); | 93 UpdatePhantomWindow(location_in_root, bounds, grid_size); |
| 76 if (!attached_windows_.empty()) | 94 if (!attached_windows_.empty()) |
| 77 LayoutAttachedWindows(bounds, grid_size); | 95 LayoutAttachedWindows(bounds, grid_size); |
| 78 if (bounds != details_.window->bounds()) | 96 if (bounds != details_.window->bounds()) |
| 79 details_.window->SetBounds(bounds); | 97 details_.window->SetBounds(bounds); |
| 80 // WARNING: we may have been deleted. | 98 // WARNING: we may have been deleted. |
| 81 } | 99 } |
| 82 | 100 |
| 83 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { | 101 void WorkspaceWindowResizer::CompleteDrag(int event_flags) { |
| 84 phantom_window_controller_.reset(); | 102 phantom_window_controller_.reset(); |
| 85 if (!did_move_or_resize_ || details_.window_component != HTCAPTION) | 103 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, | 175 const Details& details, |
| 158 const std::vector<aura::Window*>& attached_windows) | 176 const std::vector<aura::Window*>& attached_windows) |
| 159 : details_(details), | 177 : details_(details), |
| 160 attached_windows_(attached_windows), | 178 attached_windows_(attached_windows), |
| 161 did_move_or_resize_(false), | 179 did_move_or_resize_(false), |
| 162 total_min_(0), | 180 total_min_(0), |
| 163 total_initial_size_(0), | 181 total_initial_size_(0), |
| 164 snap_type_(SNAP_NONE), | 182 snap_type_(SNAP_NONE), |
| 165 num_mouse_moves_since_bounds_change_(0) { | 183 num_mouse_moves_since_bounds_change_(0) { |
| 166 DCHECK(details_.is_resizable); | 184 DCHECK(details_.is_resizable); |
| 167 ash::Shell::GetInstance()->cursor_manager()->LockCursor(); | 185 |
| 186 Shell* shell = Shell::GetInstance(); |
| 187 shell->cursor_manager()->LockCursor(); |
| 188 if (ShouldAllowCursorWarp()) |
| 189 shell->display_controller()->set_allow_warp_during_lock(true); |
| 168 | 190 |
| 169 // Only support attaching to the right/bottom. | 191 // Only support attaching to the right/bottom. |
| 170 DCHECK(attached_windows_.empty() || | 192 DCHECK(attached_windows_.empty() || |
| 171 (details.window_component == HTRIGHT || | 193 (details.window_component == HTRIGHT || |
| 172 details.window_component == HTBOTTOM)); | 194 details.window_component == HTBOTTOM)); |
| 173 | 195 |
| 174 // TODO: figure out how to deal with window going off the edge. | 196 // TODO: figure out how to deal with window going off the edge. |
| 175 | 197 |
| 176 // Calculate sizes so that we can maintain the ratios if we need to resize. | 198 // Calculate sizes so that we can maintain the ratios if we need to resize. |
| 177 int total_available = 0; | 199 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 | 456 // TODO: this likely only wants total display area, not the area of a single |
| 435 // display. | 457 // display. |
| 436 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(details_.window)); | 458 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(details_.window)); |
| 437 if (location.x() <= area.x()) | 459 if (location.x() <= area.x()) |
| 438 return SNAP_LEFT_EDGE; | 460 return SNAP_LEFT_EDGE; |
| 439 if (location.x() >= area.right() - 1) | 461 if (location.x() >= area.right() - 1) |
| 440 return SNAP_RIGHT_EDGE; | 462 return SNAP_RIGHT_EDGE; |
| 441 return SNAP_NONE; | 463 return SNAP_NONE; |
| 442 } | 464 } |
| 443 | 465 |
| 466 bool WorkspaceWindowResizer::ShouldAllowCursorWarp() const { |
| 467 return (details_.window_component == HTCAPTION) && |
| 468 (window()->GetProperty(aura::client::kModalKey) == ui::MODAL_TYPE_NONE) && |
| 469 (window()->type() == aura::client::WINDOW_TYPE_NORMAL); |
| 470 } |
| 471 |
| 444 } // namespace internal | 472 } // namespace internal |
| 445 } // namespace ash | 473 } // namespace ash |
| OLD | NEW |