| Index: ash/wm/common/window_positioning_utils.cc
|
| diff --git a/ash/wm/common/window_positioning_utils.cc b/ash/wm/common/window_positioning_utils.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..7ba629babc2eadcc9004da5bf1fd6c96bde662ad
|
| --- /dev/null
|
| +++ b/ash/wm/common/window_positioning_utils.cc
|
| @@ -0,0 +1,50 @@
|
| +// Copyright 2016 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ash/wm/common/window_positioning_utils.h"
|
| +
|
| +#include <algorithm>
|
| +
|
| +#include "ui/gfx/geometry/rect.h"
|
| +#include "ui/gfx/geometry/size.h"
|
| +
|
| +namespace ash {
|
| +namespace wm {
|
| +
|
| +void AdjustBoundsSmallerThan(const gfx::Size& max_size, gfx::Rect* bounds) {
|
| + bounds->set_width(std::min(bounds->width(), max_size.width()));
|
| + bounds->set_height(std::min(bounds->height(), max_size.height()));
|
| +}
|
| +
|
| +void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area,
|
| + int min_width,
|
| + int min_height,
|
| + gfx::Rect* bounds) {
|
| + AdjustBoundsSmallerThan(visible_area.size(), bounds);
|
| +
|
| + min_width = std::min(min_width, visible_area.width());
|
| + min_height = std::min(min_height, visible_area.height());
|
| +
|
| + if (bounds->right() < visible_area.x() + min_width) {
|
| + bounds->set_x(visible_area.x() + min_width - bounds->width());
|
| + } else if (bounds->x() > visible_area.right() - min_width) {
|
| + bounds->set_x(visible_area.right() - min_width);
|
| + }
|
| + if (bounds->bottom() < visible_area.y() + min_height) {
|
| + bounds->set_y(visible_area.y() + min_height - bounds->height());
|
| + } else if (bounds->y() > visible_area.bottom() - min_height) {
|
| + bounds->set_y(visible_area.bottom() - min_height);
|
| + }
|
| + if (bounds->y() < visible_area.y())
|
| + bounds->set_y(visible_area.y());
|
| +}
|
| +
|
| +void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& visible_area,
|
| + gfx::Rect* bounds) {
|
| + AdjustBoundsToEnsureWindowVisibility(visible_area, kMinimumOnScreenArea,
|
| + kMinimumOnScreenArea, bounds);
|
| +}
|
| +
|
| +} // namespace wm
|
| +} // namespace ash
|
|
|