Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: ash/wm/workspace/snap_sizer.cc

Issue 11434004: ash: Refactor some code that snaps windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/wm/workspace/snap_sizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/screen_ash.h" 9 #include "ash/screen_ash.h"
10 #include "ash/wm/property_util.h"
10 #include "ash/wm/window_resizer.h" 11 #include "ash/wm/window_resizer.h"
12 #include "ash/wm/window_util.h"
11 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
12 #include "ui/gfx/screen.h" 14 #include "ui/gfx/screen.h"
13 15
14 namespace ash { 16 namespace ash {
15 namespace internal { 17 namespace internal {
16 18
17 namespace { 19 namespace {
18 20
19 // A list of ideal window width in pixel which will be used to populate the 21 // A list of ideal window width in pixel which will be used to populate the
20 // |usable_width_| list. 22 // |usable_width_| list.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 start_x_(start.x()), 81 start_x_(start.x()),
80 input_type_(input_type), 82 input_type_(input_type),
81 usable_width_(BuildIdealWidthList(window)) { 83 usable_width_(BuildIdealWidthList(window)) {
82 DCHECK(!usable_width_.empty()); 84 DCHECK(!usable_width_.empty());
83 target_bounds_ = GetTargetBounds(); 85 target_bounds_ = GetTargetBounds();
84 } 86 }
85 87
86 SnapSizer::~SnapSizer() { 88 SnapSizer::~SnapSizer() {
87 } 89 }
88 90
91 void SnapSizer::SnapWindow(aura::Window* window, SnapSizer::Edge edge) {
92 if (!wm::CanSnapWindow(window))
93 return;
94 internal::SnapSizer sizer(window, gfx::Point(), edge,
95 internal::SnapSizer::OTHER_INPUT);
96 if (wm::IsWindowFullscreen(window) || wm::IsWindowMaximized(window)) {
97 // Before we can set the bounds we need to restore the window.
98 // Restoring the window will set the window to its restored bounds.
99 // 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,
101 // then reset the restore bounds. This way no unnecessary bounds
102 // changes occurs and the original restore bounds is remembered.
103 gfx::Rect restore = *GetRestoreBoundsInScreen(window);
104 SetRestoreBoundsInParent(window, sizer.GetSnapBounds(window->bounds()));
105 wm::RestoreWindow(window);
106 SetRestoreBoundsInScreen(window, restore);
107 } else {
108 window->SetBounds(sizer.GetSnapBounds(window->bounds()));
109 }
110 }
111
89 void SnapSizer::Update(const gfx::Point& location) { 112 void SnapSizer::Update(const gfx::Point& location) {
90 // See description above for details on this behavior. 113 // See description above for details on this behavior.
91 num_moves_since_adjust_++; 114 num_moves_since_adjust_++;
92 if ((base::TimeTicks::Now() - time_last_update_).InMilliseconds() > 115 if ((base::TimeTicks::Now() - time_last_update_).InMilliseconds() >
93 kDelayBeforeIncreaseMS) { 116 kDelayBeforeIncreaseMS) {
94 ChangeBounds(location.x(), 117 ChangeBounds(location.x(),
95 CalculateIncrement(location.x(), last_update_x_)); 118 CalculateIncrement(location.x(), last_update_x_));
96 } else { 119 } else {
97 bool along_edge = AlongEdge(location.x()); 120 bool along_edge = AlongEdge(location.x());
98 int pixels_before_adjust = kPixelsBeforeAdjust; 121 int pixels_before_adjust = kPixelsBeforeAdjust;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 return GetTargetBoundsForSize(size_index_); 218 return GetTargetBoundsForSize(size_index_);
196 } 219 }
197 220
198 bool SnapSizer::AlongEdge(int x) const { 221 bool SnapSizer::AlongEdge(int x) const {
199 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); 222 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_));
200 return (x <= area.x()) || (x >= area.right() - 1); 223 return (x <= area.x()) || (x >= area.right() - 1);
201 } 224 }
202 225
203 } // namespace internal 226 } // namespace internal
204 } // namespace ash 227 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/workspace/snap_sizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698