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

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

Issue 23645009: Make resizing a window by snapping it left or right take into account the window's minimum width (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 months 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/ash.gyp ('k') | ash/wm/workspace/snap_sizer_unittest.cc » ('j') | 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/property_util.h"
11 #include "ash/wm/window_resizer.h" 11 #include "ash/wm/window_resizer.h"
12 #include "ash/wm/window_util.h" 12 #include "ash/wm/window_util.h"
13 #include "ui/aura/window.h" 13 #include "ui/aura/window.h"
14 #include "ui/aura/window_delegate.h"
14 #include "ui/gfx/screen.h" 15 #include "ui/gfx/screen.h"
15 16
16 namespace ash { 17 namespace ash {
17 namespace internal { 18 namespace internal {
18 19
19 namespace { 20 namespace {
20 21
21 // A list of ideal window width in pixel which will be used to populate the 22 // A list of ideal window widths in DIP which will be used to populate the
22 // |usable_width_| list. 23 // |usable_width_| list.
23 const int kIdealWidth[] = { 1280, 1024, 768, 640 }; 24 const int kIdealWidth[] = { 1280, 1024, 768, 640 };
24 25
25 // Windows are initially snapped to the size in |usable_width_| at index 0. 26 // Windows are initially snapped to the size in |usable_width_| at index 0.
26 // The index into |usable_width_| is changed if any of the following happen: 27 // The index into |usable_width_| is changed if any of the following happen:
27 // . The user stops moving the mouse for |kDelayBeforeIncreaseMS| and then 28 // . The user stops moving the mouse for |kDelayBeforeIncreaseMS| and then
28 // moves the mouse again. 29 // moves the mouse again.
29 // . The mouse moves |kPixelsBeforeAdjust| horizontal pixels. 30 // . The mouse moves |kPixelsBeforeAdjust| horizontal pixels.
30 // . The mouse is against the edge of the screen and the mouse is moved 31 // . The mouse is against the edge of the screen and the mouse is moved
31 // |kMovesBeforeAdjust| times. 32 // |kMovesBeforeAdjust| times.
32 const int kDelayBeforeIncreaseMS = 500; 33 const int kDelayBeforeIncreaseMS = 500;
33 const int kMovesBeforeAdjust = 25; 34 const int kMovesBeforeAdjust = 25;
34 const int kPixelsBeforeAdjust = 100; 35 const int kPixelsBeforeAdjust = 100;
35 36
36 // When the smallest resolution does not fit on the screen, we take this 37 // The maximum fraction of the screen width that a snapped window is allowed
37 // fraction of the available space. 38 // to take up.
38 const int kMinimumScreenPercent = 90; 39 const int kMaximumScreenPercent = 90;
39 40
40 // Create the list of possible width for the current screen configuration: 41 // The width that a window should be snapped to if resizing is disabled in the
42 // SnapSizer for devices with small screen resolutions.
43 const int kDefaultWidthSmallScreen = 1024;
44
45 // Returns the minimum width that |window| can be snapped to. The returned width
46 // may not be in the width list generated by BuildIdealWidthList().
47 int GetMinWidth(aura::Window* window) {
48 return window->delegate() ? window->delegate()->GetMinimumSize().width() : 0;
49 }
50
51 // Returns the maximum width that |window| can be snapped to. The returned width
52 // may not be in the width list generated by BuildIdealWidthList().
53 // The aura::WindowDelegate's max size is ignored because
54 // ash::wm::CanSnapWindow() returns false when a max size is specified.
55 int GetMaxWidth(aura::Window* window) {
56 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window));
57 return std::max(work_area.width() * kMaximumScreenPercent / 100,
58 GetMinWidth(window));
59 }
60
61 // Returns the width that |window| should be snapped to if resizing is disabled
62 // in the SnapSizer.
63 int GetDefaultWidth(aura::Window* window) {
64 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window));
65 int width = std::max(kDefaultWidthSmallScreen, work_area.width() / 2);
66
67 width = std::min(width, GetMaxWidth(window));
68 return std::max(width, GetMinWidth(window));
69 }
70
71 // Create the list of possible widths for the current screen configuration:
41 // Fill the |usable_width_| list with items from |kIdealWidth| which fit on 72 // Fill the |usable_width_| list with items from |kIdealWidth| which fit on
42 // the screen and supplement it with the 'half of screen' size. Furthermore, 73 // the screen and supplement it with the 'half of screen' size. Furthermore,
43 // add an entry for 90% of the screen size if it is smaller then the biggest 74 // add an entry for 90% of the screen size if it is smaller than the biggest
44 // value in the |kIdealWidth| list (to get a step between the values). 75 // value in the |kIdealWidth| list (to get a step between the values).
45 std::vector<int> BuildIdealWidthList(aura::Window* window) { 76 std::vector<int> BuildIdealWidthList(aura::Window* window) {
77 int minimum_width = GetMinWidth(window);
78 int maximum_width = GetMaxWidth(window);
79
80 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window));
81 int half_width = work_area.width() / 2;
82 if (half_width < minimum_width || half_width > maximum_width)
83 half_width = 0;
84
46 std::vector<int> ideal_width_list; 85 std::vector<int> ideal_width_list;
47 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window));
48 int half_size = work_area.width() / 2;
49 int maximum_width = (kMinimumScreenPercent * work_area.width()) / 100;
50 for (size_t i = 0; i < arraysize(kIdealWidth); i++) { 86 for (size_t i = 0; i < arraysize(kIdealWidth); i++) {
51 if (maximum_width >= kIdealWidth[i]) { 87 if (kIdealWidth[i] >= minimum_width && kIdealWidth[i] <= maximum_width) {
52 if (i && !ideal_width_list.size() && maximum_width != kIdealWidth[i]) 88 if (i && !ideal_width_list.size() && maximum_width != kIdealWidth[i])
53 ideal_width_list.push_back(maximum_width); 89 ideal_width_list.push_back(maximum_width);
54 if (half_size > kIdealWidth[i]) 90 if (half_width > kIdealWidth[i])
55 ideal_width_list.push_back(half_size); 91 ideal_width_list.push_back(half_width);
56 if (half_size >= kIdealWidth[i]) 92 if (half_width >= kIdealWidth[i])
57 half_size = 0; 93 half_width = 0;
58 ideal_width_list.push_back(kIdealWidth[i]); 94 ideal_width_list.push_back(kIdealWidth[i]);
59 } 95 }
60 } 96 }
61 if (half_size) 97 if (half_width)
62 ideal_width_list.push_back(half_size); 98 ideal_width_list.push_back(half_width);
99 if (ideal_width_list.empty()) {
100 if (minimum_width > 0)
101 ideal_width_list.push_back(minimum_width);
102 else
103 ideal_width_list.push_back(maximum_width);
104 }
63 105
64 return ideal_width_list; 106 return ideal_width_list;
65 } 107 }
66 108
67 } // namespace 109 } // namespace
68 110
69 SnapSizer::SnapSizer(aura::Window* window, 111 SnapSizer::SnapSizer(aura::Window* window,
70 const gfx::Point& start, 112 const gfx::Point& start,
71 Edge edge, 113 Edge edge,
72 InputType input_type) 114 InputType input_type)
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 198
157 void SnapSizer::SelectDefaultSizeAndDisableResize() { 199 void SnapSizer::SelectDefaultSizeAndDisableResize() {
158 resize_disabled_ = true; 200 resize_disabled_ = true;
159 size_index_ = 0; 201 size_index_ = 0;
160 target_bounds_ = GetTargetBounds(); 202 target_bounds_ = GetTargetBounds();
161 } 203 }
162 204
163 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const { 205 gfx::Rect SnapSizer::GetTargetBoundsForSize(size_t size_index) const {
164 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_)); 206 gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_));
165 int y = work_area.y(); 207 int y = work_area.y();
166 // We don't align to the bottom of the grid as the launcher may not
167 // necessarily align to the grid (happens when auto-hidden).
168 int max_y = work_area.bottom(); 208 int max_y = work_area.bottom();
169 int width = 0; 209 int width = 0;
170 if (resize_disabled_) { 210 if (resize_disabled_) {
171 // Make sure that we keep the size of the window smaller then a certain 211 width = GetDefaultWidth(window_);
172 // fraction of the screen space.
173 int minimum_size = (kMinimumScreenPercent * work_area.width()) / 100;
174 width = std::max(std::min(minimum_size, 1024), work_area.width() / 2);
175 } else { 212 } else {
176 DCHECK(size_index < usable_width_.size()); 213 DCHECK(size_index < usable_width_.size());
177 width = usable_width_[size_index]; 214 width = usable_width_[size_index];
178 } 215 }
179 216
180 if (edge_ == LEFT_EDGE) { 217 if (edge_ == LEFT_EDGE) {
181 int x = work_area.x(); 218 int x = work_area.x();
182 int mid_x = x + width; 219 int mid_x = x + width;
183 return gfx::Rect(x, y, mid_x - x, max_y - y); 220 return gfx::Rect(x, y, mid_x - x, max_y - y);
184 } 221 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
218 return GetTargetBoundsForSize(size_index_); 255 return GetTargetBoundsForSize(size_index_);
219 } 256 }
220 257
221 bool SnapSizer::AlongEdge(int x) const { 258 bool SnapSizer::AlongEdge(int x) const {
222 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_)); 259 gfx::Rect area(ScreenAsh::GetDisplayBoundsInParent(window_));
223 return (x <= area.x()) || (x >= area.right() - 1); 260 return (x <= area.x()) || (x >= area.right() - 1);
224 } 261 }
225 262
226 } // namespace internal 263 } // namespace internal
227 } // namespace ash 264 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash.gyp ('k') | ash/wm/workspace/snap_sizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698