| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/wm/common/window_positioning_utils.h" |
| 6 |
| 7 #include <algorithm> |
| 8 |
| 9 #include "ui/gfx/geometry/rect.h" |
| 10 #include "ui/gfx/geometry/size.h" |
| 11 |
| 12 namespace ash { |
| 13 namespace wm { |
| 14 |
| 15 void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) { |
| 16 bounds->set_width(std::min(bounds->width(), max_size.width())); |
| 17 bounds->set_height(std::min(bounds->height(), max_size.height())); |
| 18 } |
| 19 |
| 20 void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area, |
| 21 int min_width, |
| 22 int min_height, |
| 23 gfx::Rect* bounds) { |
| 24 AdjustBoundsSmallerThan(visible_area.size(), bounds); |
| 25 |
| 26 min_width = std::min(min_width, visible_area.width()); |
| 27 min_height = std::min(min_height, visible_area.height()); |
| 28 |
| 29 if (bounds->right() < visible_area.x() + min_width) { |
| 30 bounds->set_x(visible_area.x() + min_width - bounds->width()); |
| 31 } else if (bounds->x() > visible_area.right() - min_width) { |
| 32 bounds->set_x(visible_area.right() - min_width); |
| 33 } |
| 34 if (bounds->bottom() < visible_area.y() + min_height) { |
| 35 bounds->set_y(visible_area.y() + min_height - bounds->height()); |
| 36 } else if (bounds->y() > visible_area.bottom() - min_height) { |
| 37 bounds->set_y(visible_area.bottom() - min_height); |
| 38 } |
| 39 if (bounds->y() < visible_area.y()) |
| 40 bounds->set_y(visible_area.y()); |
| 41 } |
| 42 |
| 43 void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area, |
| 44 gfx::Rect* bounds) { |
| 45 AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea, |
| 46 kMinimumOnScreenArea, bounds); |
| 47 } |
| 48 |
| 49 } // namespace wm |
| 50 } // namespace ash |
| OLD | NEW |