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

Side by Side Diff: ash/wm/window_resizer.cc

Issue 11087037: Dont allow the user to 'resize a window out of the workarea' (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 2 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/wm/window_resizer.h ('k') | ash/wm/workspace/workspace_window_resizer_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/window_resizer.h" 5 #include "ash/wm/window_resizer.h"
6 6
7 #include "ash/screen_ash.h" 7 #include "ash/screen_ash.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/wm/property_util.h" 9 #include "ash/wm/property_util.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 // static 93 // static
94 const int WindowResizer::kBoundsChange_Resizes = 2; 94 const int WindowResizer::kBoundsChange_Resizes = 2;
95 95
96 // static 96 // static
97 const int WindowResizer::kBoundsChangeDirection_None = 0; 97 const int WindowResizer::kBoundsChangeDirection_None = 0;
98 // static 98 // static
99 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1; 99 const int WindowResizer::kBoundsChangeDirection_Horizontal = 1;
100 // static 100 // static
101 const int WindowResizer::kBoundsChangeDirection_Vertical = 2; 101 const int WindowResizer::kBoundsChangeDirection_Vertical = 2;
102 102
103 // static
104 const int WindowResizer::kMinimumOnScreenSize = 10;
105
103 WindowResizer::Details::Details() 106 WindowResizer::Details::Details()
104 : window(NULL), 107 : window(NULL),
105 window_component(HTNOWHERE), 108 window_component(HTNOWHERE),
106 bounds_change(0), 109 bounds_change(0),
107 position_change_direction(0), 110 position_change_direction(0),
108 size_change_direction(0), 111 size_change_direction(0),
109 is_resizable(false) { 112 is_resizable(false) {
110 } 113 }
111 114
112 WindowResizer::Details::Details(aura::Window* window, 115 WindowResizer::Details::Details(aura::Window* window,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 break; 165 break;
163 default: 166 default:
164 break; 167 break;
165 } 168 }
166 return bounds_change; 169 return bounds_change;
167 } 170 }
168 171
169 // static 172 // static
170 gfx::Rect WindowResizer::CalculateBoundsForDrag( 173 gfx::Rect WindowResizer::CalculateBoundsForDrag(
171 const Details& details, 174 const Details& details,
172 const gfx::Point& location) { 175 const gfx::Point& passed_location) {
173 if (!details.is_resizable) 176 if (!details.is_resizable)
174 return details.initial_bounds; 177 return details.initial_bounds;
175 178
179 gfx::Point location = passed_location;
180 gfx::Rect work_area =
sky 2012/10/09 23:58:53 Move work_area inside if.
Mr4D (OOO till 08-26) 2012/10/10 23:14:35 cannot since it's being used in line 233 as well.
181 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window);
182
183 // Don't allow the user to "resize a window" out of the screen.
184 if (details.bounds_change & kBoundsChange_Resizes) {
185 if (details.size_change_direction & kBoundsChangeDirection_Horizontal) {
186 if (IsRightEdge(details.window_component)) {
187 location.set_x(
188 std::max(location.x(),
189 work_area.x() + WindowResizer::kMinimumOnScreenSize));
190 } else {
191 location.set_x(
192 std::min(location.x(),
193 work_area.right() - WindowResizer::kMinimumOnScreenSize));
194 }
195 }
196 if (details.size_change_direction & kBoundsChangeDirection_Vertical) {
197 if (!IsBottomEdge(details.window_component)) {
198 location.set_y(
199 std::min(location.y(), work_area.bottom() -
200 WindowResizer::kMinimumOnScreenSize));
201 }
202 }
203 }
204
176 int delta_x = location.x() - details.initial_location_in_parent.x(); 205 int delta_x = location.x() - details.initial_location_in_parent.x();
177 int delta_y = location.y() - details.initial_location_in_parent.y(); 206 int delta_y = location.y() - details.initial_location_in_parent.y();
178 207
179 // The minimize size constraint may limit how much we change the window 208 // The minimize size constraint may limit how much we change the window
180 // position. For example, dragging the left edge to the right should stop 209 // position. For example, dragging the left edge to the right should stop
181 // repositioning the window when the minimize size is reached. 210 // repositioning the window when the minimize size is reached.
182 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y); 211 gfx::Size size = GetSizeForDrag(details, &delta_x, &delta_y);
183 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y); 212 gfx::Point origin = GetOriginForDrag(details, delta_x, delta_y);
184 213
185 // When we might want to reposition a window which is also restored to its 214 // When we might want to reposition a window which is also restored to its
186 // previous size, to keep the cursor within the dragged window. 215 // previous size, to keep the cursor within the dragged window.
187 if (!details.restore_bounds.IsEmpty() && 216 if (!details.restore_bounds.IsEmpty() &&
188 details.bounds_change & kBoundsChange_Repositions) { 217 details.bounds_change & kBoundsChange_Repositions) {
189 // However - it is not desirable to change the origin if the window would 218 // However - it is not desirable to change the origin if the window would
190 // be still hit by the cursor. 219 // be still hit by the cursor.
191 if (details.initial_location_in_parent.x() > 220 if (details.initial_location_in_parent.x() >
192 details.initial_bounds.x() + details.restore_bounds.width()) 221 details.initial_bounds.x() + details.restore_bounds.width())
193 origin.set_x(location.x() - details.restore_bounds.width() / 2); 222 origin.set_x(location.x() - details.restore_bounds.width() / 2);
194 } 223 }
195 224
196 gfx::Rect new_bounds(origin, size); 225 gfx::Rect new_bounds(origin, size);
197 // Update bottom edge to stay in the work area when we are resizing 226 // Update bottom edge to stay in the work area when we are resizing
198 // by dragging the bottome edge or corners. 227 // by dragging the bottom edge or corners.
199 if (details.window_component == HTBOTTOM || 228 if (details.window_component == HTBOTTOM ||
200 details.window_component == HTBOTTOMRIGHT || 229 details.window_component == HTBOTTOMRIGHT ||
201 details.window_component == HTBOTTOMLEFT) { 230 details.window_component == HTBOTTOMLEFT) {
202 gfx::Rect work_area =
203 ScreenAsh::GetDisplayWorkAreaBoundsInParent(details.window);
204 if (new_bounds.bottom() > work_area.bottom()) 231 if (new_bounds.bottom() > work_area.bottom())
205 new_bounds.Inset(0, 0, 0, 232 new_bounds.Inset(0, 0, 0,
206 new_bounds.bottom() - work_area.bottom()); 233 new_bounds.bottom() - work_area.bottom());
207 } 234 }
208 if (details.bounds_change & kBoundsChange_Resizes && 235 if (details.bounds_change & kBoundsChange_Resizes &&
209 details.bounds_change & kBoundsChange_Repositions && new_bounds.y() < 0) { 236 details.bounds_change & kBoundsChange_Repositions && new_bounds.y() < 0) {
210 int delta = new_bounds.y(); 237 int delta = new_bounds.y();
211 new_bounds.set_y(0); 238 new_bounds.set_y(0);
212 new_bounds.set_height(new_bounds.height() + delta); 239 new_bounds.set_height(new_bounds.height() + delta);
213 } 240 }
241
214 return new_bounds; 242 return new_bounds;
215 } 243 }
216 244
217 // static 245 // static
218 bool WindowResizer::IsBottomEdge(int window_component) { 246 bool WindowResizer::IsBottomEdge(int window_component) {
219 return window_component == HTBOTTOMLEFT || 247 return window_component == HTBOTTOMLEFT ||
220 window_component == HTBOTTOM || 248 window_component == HTBOTTOM ||
221 window_component == HTBOTTOMRIGHT || 249 window_component == HTBOTTOMRIGHT ||
222 window_component == HTGROWBOX; 250 window_component == HTGROWBOX;
223 } 251 }
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height(); 331 gfx::Screen::GetDisplayNearestWindow(details.window).bounds().height();
304 if (height > max_height) { 332 if (height > max_height) {
305 height = max_height; 333 height = max_height;
306 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height); 334 *delta_y = -y_multiplier * (details.initial_bounds.height() - max_height);
307 } 335 }
308 } 336 }
309 return height; 337 return height;
310 } 338 }
311 339
312 } // namespace aura 340 } // namespace aura
OLDNEW
« no previous file with comments | « ash/wm/window_resizer.h ('k') | ash/wm/workspace/workspace_window_resizer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698