| 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/snap_sizer.h" | 5 #include "ash/wm/workspace/snap_sizer.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "ash/ash_switches.h" |
| 9 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
| 10 #include "ash/wm/property_util.h" | 11 #include "ash/wm/property_util.h" |
| 11 #include "ash/wm/window_resizer.h" | 12 #include "ash/wm/window_resizer.h" |
| 12 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 14 #include "ash/wm/workspace/workspace_window_resizer.h" |
| 15 #include "base/command_line.h" |
| 13 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 14 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
| 15 | 18 |
| 16 namespace ash { | 19 namespace ash { |
| 17 namespace internal { | 20 namespace internal { |
| 18 | 21 |
| 19 namespace { | 22 namespace { |
| 20 | 23 |
| 21 // A list of ideal window width in pixel which will be used to populate the | 24 // A list of ideal window width in pixel which will be used to populate the |
| 22 // |usable_width_| list. | 25 // |usable_width_| list. |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 } | 89 } |
| 87 | 90 |
| 88 SnapSizer::~SnapSizer() { | 91 SnapSizer::~SnapSizer() { |
| 89 } | 92 } |
| 90 | 93 |
| 91 void SnapSizer::SnapWindow(aura::Window* window, SnapSizer::Edge edge) { | 94 void SnapSizer::SnapWindow(aura::Window* window, SnapSizer::Edge edge) { |
| 92 if (!wm::CanSnapWindow(window)) | 95 if (!wm::CanSnapWindow(window)) |
| 93 return; | 96 return; |
| 94 internal::SnapSizer sizer(window, gfx::Point(), edge, | 97 internal::SnapSizer sizer(window, gfx::Point(), edge, |
| 95 internal::SnapSizer::OTHER_INPUT); | 98 internal::SnapSizer::OTHER_INPUT); |
| 99 gfx::Rect bounds = sizer.GetSnapBounds(window->bounds()); |
| 96 if (wm::IsWindowFullscreen(window) || wm::IsWindowMaximized(window)) { | 100 if (wm::IsWindowFullscreen(window) || wm::IsWindowMaximized(window)) { |
| 97 // Before we can set the bounds we need to restore the window. | 101 // Before we can set the bounds we need to restore the window. |
| 98 // Restoring the window will set the window to its restored bounds. | 102 // Restoring the window will set the window to its restored bounds. |
| 99 // To avoid an unnecessary bounds changes (which may have side effects) | 103 // To avoid an unnecessary bounds changes (which may have side effects) |
| 100 // we set the restore bounds to the bounds we want, restore the window, | 104 // we set the restore bounds to the bounds we want, restore the window, |
| 101 // then reset the restore bounds. This way no unnecessary bounds | 105 // then reset the restore bounds. This way no unnecessary bounds |
| 102 // changes occurs and the original restore bounds is remembered. | 106 // changes occurs and the original restore bounds is remembered. |
| 103 gfx::Rect restore = *GetRestoreBoundsInScreen(window); | 107 gfx::Rect restore = *GetRestoreBoundsInScreen(window); |
| 104 SetRestoreBoundsInParent(window, sizer.GetSnapBounds(window->bounds())); | 108 SetRestoreBoundsInParent(window, bounds); |
| 105 wm::RestoreWindow(window); | 109 wm::RestoreWindow(window); |
| 106 SetRestoreBoundsInScreen(window, restore); | 110 SetRestoreBoundsInScreen(window, restore); |
| 107 } else { | 111 } else { |
| 108 window->SetBounds(sizer.GetSnapBounds(window->bounds())); | 112 window->SetBounds(bounds); |
| 109 } | 113 } |
| 114 gfx::Rect bounds_in_parent = ScreenAsh::ConvertRectToScreen( |
| 115 window->parent(), |
| 116 ScreenAsh::GetMaximizedWindowBoundsInParent(window)); |
| 117 int stuck_edges_mask = |
| 118 internal::WorkspaceWindowResizer::CalculateStuckEdges( |
| 119 bounds, bounds_in_parent); |
| 120 if (GetStuckToEdge(window) != stuck_edges_mask && |
| 121 CommandLine::ForCurrentProcess()->HasSwitch( |
| 122 switches::kAshEnableDockedWindows)) |
| 123 SetStuckToEdge(window, stuck_edges_mask); |
| 110 } | 124 } |
| 111 | 125 |
| 112 void SnapSizer::Update(const gfx::Point& location) { | 126 void SnapSizer::Update(const gfx::Point& location) { |
| 113 // See description above for details on this behavior. | 127 // See description above for details on this behavior. |
| 114 num_moves_since_adjust_++; | 128 num_moves_since_adjust_++; |
| 115 if ((base::TimeTicks::Now() - time_last_update_).InMilliseconds() > | 129 if ((base::TimeTicks::Now() - time_last_update_).InMilliseconds() > |
| 116 kDelayBeforeIncreaseMS) { | 130 kDelayBeforeIncreaseMS) { |
| 117 ChangeBounds(location.x(), | 131 ChangeBounds(location.x(), |
| 118 CalculateIncrement(location.x(), last_update_x_)); | 132 CalculateIncrement(location.x(), last_update_x_)); |
| 119 } else { | 133 } else { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return GetTargetBoundsForSize(size_index_); | 232 return GetTargetBoundsForSize(size_index_); |
| 219 } | 233 } |
| 220 | 234 |
| 221 bool SnapSizer::AlongEdge(int x) const { | 235 bool SnapSizer::AlongEdge(int x) const { |
| 222 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); | 236 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); |
| 223 return (x <= area.x()) || (x >= area.right() - 1); | 237 return (x <= area.x()) || (x >= area.right() - 1); |
| 224 } | 238 } |
| 225 | 239 |
| 226 } // namespace internal | 240 } // namespace internal |
| 227 } // namespace ash | 241 } // namespace ash |
| OLD | NEW |