| 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 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 scoped_ptr<WindowResizer> CreateWindowResizer( | 45 scoped_ptr<WindowResizer> CreateWindowResizer( |
| 46 aura::Window* window, | 46 aura::Window* window, |
| 47 const gfx::Point& point_in_parent, | 47 const gfx::Point& point_in_parent, |
| 48 int window_component, | 48 int window_component, |
| 49 aura::client::WindowMoveSource source) { | 49 aura::client::WindowMoveSource source) { |
| 50 DCHECK(window); | 50 DCHECK(window); |
| 51 wm::WindowState* window_state = wm::GetWindowState(window); | 51 wm::WindowState* window_state = wm::GetWindowState(window); |
| 52 // No need to return a resizer when the window cannot get resized or when a | 52 // No need to return a resizer when the window cannot get resized or when a |
| 53 // resizer already exists for this window. | 53 // resizer already exists for this window. |
| 54 if ((!window_state->CanResize() && window_component != HTCAPTION) || | 54 if ((!window_state->CanResize() && window_component != HTCAPTION) || |
| 55 window_state->window_resizer()) { | 55 window_state->drag_details()) { |
| 56 return scoped_ptr<WindowResizer>(); | 56 return scoped_ptr<WindowResizer>(); |
| 57 } | 57 } |
| 58 | 58 |
| 59 // TODO(varkha): The chaining of window resizers causes some of the logic | 59 // TODO(varkha): The chaining of window resizers causes some of the logic |
| 60 // to be repeated and the logic flow difficult to control. With some windows | 60 // to be repeated and the logic flow difficult to control. With some windows |
| 61 // classes using reparenting during drag operations it becomes challenging to | 61 // classes using reparenting during drag operations it becomes challenging to |
| 62 // implement proper transition from one resizer to another during or at the | 62 // implement proper transition from one resizer to another during or at the |
| 63 // end of the drag. This also causes http://crbug.com/247085. | 63 // end of the drag. This also causes http://crbug.com/247085. |
| 64 // It seems the only thing the panel or dock resizer needs to do is notify the | 64 // It seems the only thing the panel or dock resizer needs to do is notify the |
| 65 // layout manager when a docked window is being dragged. We should have a | 65 // layout manager when a docked window is being dragged. We should have a |
| 66 // better way of doing this, perhaps by having a way of observing drags or | 66 // better way of doing this, perhaps by having a way of observing drags or |
| 67 // having a generic drag window wrapper which informs a layout manager that a | 67 // having a generic drag window wrapper which informs a layout manager that a |
| 68 // drag has started or stopped. | 68 // drag has started or stopped. |
| 69 // It may be possible to refactor and eliminate chaining. | 69 // It may be possible to refactor and eliminate chaining. |
| 70 WindowResizer* window_resizer = NULL; | 70 WindowResizer* window_resizer = NULL; |
| 71 | 71 |
| 72 if (!window_state->IsNormalShowState()) { | 72 if (!window_state->IsNormalShowState()) |
| 73 if (window->parent() && | 73 return scoped_ptr<WindowResizer>(); |
| 74 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || | |
| 75 window->parent()->id() == internal::kShellWindowId_DockedContainer || | |
| 76 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { | |
| 77 // Allow dragging maximized windows only when dragged by a tab. | |
| 78 if (window_component != HTCAPTION || !window_state->is_dragged()) | |
| 79 return scoped_ptr<WindowResizer>(); | |
| 80 } else { | |
| 81 return scoped_ptr<WindowResizer>(); | |
| 82 } | |
| 83 } | |
| 84 | 74 |
| 85 if (!window_state->CreateDragDetails( | 75 int bounds_change = WindowResizer::GetBoundsChangeForWindowComponent( |
| 86 window, point_in_parent, window_component, source)) { | 76 window_component); |
| 77 if (bounds_change == WindowResizer::kBoundsChangeDirection_None) |
| 87 return scoped_ptr<WindowResizer>(); | 78 return scoped_ptr<WindowResizer>(); |
| 88 } | 79 |
| 80 window_state->CreateDragDetails(window, point_in_parent, window_component, |
| 81 source); |
| 89 if (window->parent() && | 82 if (window->parent() && |
| 90 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || | 83 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || |
| 91 window->parent()->id() == internal::kShellWindowId_DockedContainer || | 84 window->parent()->id() == internal::kShellWindowId_DockedContainer || |
| 92 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { | 85 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { |
| 93 window_resizer = internal::WorkspaceWindowResizer::Create( | 86 window_resizer = internal::WorkspaceWindowResizer::Create( |
| 94 window_state, | 87 window_state, |
| 95 std::vector<aura::Window*>()); | 88 std::vector<aura::Window*>()); |
| 96 } else { | 89 } else { |
| 97 window_resizer = DefaultWindowResizer::Create(window_state); | 90 window_resizer = DefaultWindowResizer::Create(window_state); |
| 98 } | 91 } |
| 99 if (window_resizer) { | 92 window_resizer = internal::DragWindowResizer::Create(window_resizer, |
| 100 window_resizer = internal::DragWindowResizer::Create(window_resizer, | 93 window_state); |
| 101 window_state); | 94 if (window->type() == ui::wm::WINDOW_TYPE_PANEL) |
| 102 } | |
| 103 if (window_resizer && window->type() == ui::wm::WINDOW_TYPE_PANEL) | |
| 104 window_resizer = PanelWindowResizer::Create(window_resizer, window_state); | 95 window_resizer = PanelWindowResizer::Create(window_resizer, window_state); |
| 105 if (switches::UseDockedWindows() && | 96 if (switches::UseDockedWindows() && |
| 106 window_resizer && window->parent() && | 97 window_resizer && window->parent() && |
| 107 !views::corewm::GetTransientParent(window) && | 98 !views::corewm::GetTransientParent(window) && |
| 108 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || | 99 (window->parent()->id() == internal::kShellWindowId_DefaultContainer || |
| 109 window->parent()->id() == internal::kShellWindowId_DockedContainer || | 100 window->parent()->id() == internal::kShellWindowId_DockedContainer || |
| 110 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { | 101 window->parent()->id() == internal::kShellWindowId_PanelContainer)) { |
| 111 window_resizer = internal::DockedWindowResizer::Create(window_resizer, | 102 window_resizer = internal::DockedWindowResizer::Create(window_resizer, |
| 112 window_state); | 103 window_state); |
| 113 } | 104 } |
| 114 window_state->drag_details()->window_resizer = window_resizer; | |
| 115 return make_scoped_ptr<WindowResizer>(window_resizer); | 105 return make_scoped_ptr<WindowResizer>(window_resizer); |
| 116 } | 106 } |
| 117 | 107 |
| 118 namespace internal { | 108 namespace internal { |
| 119 | 109 |
| 120 namespace { | 110 namespace { |
| 121 | 111 |
| 122 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset | 112 // Snapping distance used instead of WorkspaceWindowResizer::kScreenEdgeInset |
| 123 // when resizing a window using touchscreen. | 113 // when resizing a window using touchscreen. |
| 124 const int kScreenEdgeInsetForTouchResize = 32; | 114 const int kScreenEdgeInsetForTouchResize = 32; |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 switches::kAshEnableStickyEdges)) { | 367 switches::kAshEnableStickyEdges)) { |
| 378 sticky_size = kStickyDistancePixels; | 368 sticky_size = kStickyDistancePixels; |
| 379 } else if ((details().bounds_change & kBoundsChange_Resizes) && | 369 } else if ((details().bounds_change & kBoundsChange_Resizes) && |
| 380 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { | 370 details().source == aura::client::WINDOW_MOVE_SOURCE_TOUCH) { |
| 381 sticky_size = kScreenEdgeInsetForTouchResize; | 371 sticky_size = kScreenEdgeInsetForTouchResize; |
| 382 } else { | 372 } else { |
| 383 sticky_size = kScreenEdgeInset; | 373 sticky_size = kScreenEdgeInset; |
| 384 } | 374 } |
| 385 // |bounds| is in |GetTarget()->parent()|'s coordinates. | 375 // |bounds| is in |GetTarget()->parent()|'s coordinates. |
| 386 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent); | 376 gfx::Rect bounds = CalculateBoundsForDrag(location_in_parent); |
| 387 if (window_state()->IsNormalShowState()) | 377 AdjustBoundsForMainWindow(sticky_size, &bounds); |
| 388 AdjustBoundsForMainWindow(sticky_size, &bounds); | |
| 389 | 378 |
| 390 if (bounds != GetTarget()->bounds()) { | 379 if (bounds != GetTarget()->bounds()) { |
| 391 if (!did_move_or_resize_) { | 380 if (!did_move_or_resize_) { |
| 392 if (!details().restore_bounds.IsEmpty()) | 381 if (!details().restore_bounds.IsEmpty()) |
| 393 window_state()->ClearRestoreBounds(); | 382 window_state()->ClearRestoreBounds(); |
| 394 RestackWindows(); | 383 RestackWindows(); |
| 395 } | 384 } |
| 396 did_move_or_resize_ = true; | 385 did_move_or_resize_ = true; |
| 397 } | 386 } |
| 398 | 387 |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1036 } else { | 1025 } else { |
| 1037 if (dock_layout_->is_dragged_window_docked()) { | 1026 if (dock_layout_->is_dragged_window_docked()) { |
| 1038 dock_layout_->UndockDraggedWindow(); | 1027 dock_layout_->UndockDraggedWindow(); |
| 1039 window_state()->set_bounds_changed_by_user(true); | 1028 window_state()->set_bounds_changed_by_user(true); |
| 1040 } | 1029 } |
| 1041 } | 1030 } |
| 1042 } | 1031 } |
| 1043 | 1032 |
| 1044 } // namespace internal | 1033 } // namespace internal |
| 1045 } // namespace ash | 1034 } // namespace ash |
| OLD | NEW |