OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/window_sizer.h" | 5 #include "chrome/browser/window_sizer.h" |
6 | 6 |
7 #include "chrome/browser/browser.h" | 7 #include "chrome/browser/browser.h" |
8 #include "chrome/browser/browser_list.h" | 8 #include "chrome/browser/browser_list.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/browser_window.h" | 10 #include "chrome/browser/browser_window.h" |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 break; | 226 break; |
227 case RIGHT: | 227 case RIGHT: |
228 if (position <= work_area.right()) | 228 if (position <= work_area.right()) |
229 return false; | 229 return false; |
230 break; | 230 break; |
231 } | 231 } |
232 } | 232 } |
233 return true; | 233 return true; |
234 } | 234 } |
235 | 235 |
| 236 namespace { |
| 237 // Minimum height of the visible part of a window. |
| 238 static const int kMinVisibleHeight = 30; |
| 239 // Minimum width of the visible part of a window. |
| 240 static const int kMinVisibleWidth = 30; |
| 241 } |
| 242 |
236 void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining( | 243 void WindowSizer::AdjustBoundsToBeVisibleOnMonitorContaining( |
237 const gfx::Rect& other_bounds, gfx::Rect* bounds) const { | 244 const gfx::Rect& other_bounds, gfx::Rect* bounds) const { |
238 DCHECK(bounds); | 245 DCHECK(bounds); |
239 DCHECK(monitor_info_provider_); | 246 DCHECK(monitor_info_provider_); |
240 | 247 |
241 // Find the size of the work area of the monitor that intersects the bounds | 248 // Find the size of the work area of the monitor that intersects the bounds |
242 // of the anchor window. | 249 // of the anchor window. |
243 gfx::Rect work_area = | 250 gfx::Rect work_area = |
244 monitor_info_provider_->GetMonitorWorkAreaMatching(other_bounds); | 251 monitor_info_provider_->GetMonitorWorkAreaMatching(other_bounds); |
245 | 252 |
246 // If height or width are 0, reset to the default size. | 253 // If height or width are 0, reset to the default size. |
247 gfx::Rect default_bounds; | 254 gfx::Rect default_bounds; |
248 GetDefaultWindowBounds(&default_bounds); | 255 GetDefaultWindowBounds(&default_bounds); |
249 if (bounds->height() <= 0) | 256 if (bounds->height() <= 0) |
250 bounds->set_height(default_bounds.height()); | 257 bounds->set_height(default_bounds.height()); |
251 if (bounds->width() <= 0) | 258 if (bounds->width() <= 0) |
252 bounds->set_width(default_bounds.width()); | 259 bounds->set_width(default_bounds.width()); |
253 | 260 |
254 // First determine which screen edge(s) the window is offscreen on. | 261 // Ensure the minimum height and width. |
255 monitor_info_provider_->UpdateWorkAreas(); | 262 bounds->set_height(std::max(kMinVisibleHeight, bounds->height())); |
256 bool top_offscreen = PositionIsOffscreen(bounds->y(), TOP); | 263 bounds->set_width(std::max(kMinVisibleWidth, bounds->width())); |
257 bool left_offscreen = PositionIsOffscreen(bounds->x(), LEFT); | |
258 bool bottom_offscreen = PositionIsOffscreen(bounds->bottom(), BOTTOM); | |
259 bool right_offscreen = PositionIsOffscreen(bounds->right(), RIGHT); | |
260 | 264 |
261 // Bump the window back onto the screen in the direction that it's offscreen. | 265 // Ensure at least kMinVisibleWidth * kMinVisibleHeight is visible. |
262 int min_x = work_area.x() + kWindowTilePixels; | 266 const int min_y = work_area.y() + kMinVisibleHeight - bounds->height(); |
263 int min_y = work_area.y() + kWindowTilePixels; | 267 const int min_x = work_area.x() + kMinVisibleWidth - bounds->width(); |
264 if (bottom_offscreen) { | 268 const int max_y = work_area.bottom() - kMinVisibleHeight; |
265 bounds->set_y(std::max( | 269 const int max_x = work_area.right() - kMinVisibleWidth; |
266 work_area.bottom() - kWindowTilePixels - bounds->height(), min_y)); | 270 bounds->set_y(std::max(min_y, std::min(max_y, bounds->y()))); |
267 } | 271 bounds->set_x(std::max(min_x, std::min(max_x, bounds->x()))); |
268 if (right_offscreen) { | |
269 bounds->set_x(std::max( | |
270 work_area.right() - kWindowTilePixels - bounds->width(), min_x)); | |
271 } | |
272 if (top_offscreen) | |
273 bounds->set_y(min_y); | |
274 if (left_offscreen) | |
275 bounds->set_x(min_x); | |
276 | |
277 // Now that we've tried to correct the x/y position to something reasonable, | |
278 // see if the window is still too tall or wide to fit, and resize it if need | |
279 // be. | |
280 if ((bottom_offscreen || top_offscreen) && | |
281 bounds->bottom() > work_area.bottom()) | |
282 bounds->set_height(work_area.height() - 2 * kWindowTilePixels); | |
283 if ((left_offscreen || right_offscreen) && | |
284 bounds->right() > work_area.right()) | |
285 bounds->set_width(work_area.width() - 2 * kWindowTilePixels); | |
286 } | 272 } |
OLD | NEW |