summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-28 13:57:30 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-28 13:57:30 +0000
commitf11929b8a1d1f22767957c5131f9869f6380960d (patch)
tree62a3a56fbaf6f8ca440cdfa7c3628c2a217a9b92 /ash
parent929246acd3732965b984ff46bcdf96e3d604942f (diff)
downloadchromium_src-f11929b8a1d1f22767957c5131f9869f6380960d.zip
chromium_src-f11929b8a1d1f22767957c5131f9869f6380960d.tar.gz
chromium_src-f11929b8a1d1f22767957c5131f9869f6380960d.tar.bz2
Make sure at least 2/3 of the window is visible when a window is added to workspace,
either as a new window, or when display is disconnected. BUG=178629 TEST=covered by test. Review URL: https://chromiumcodereview.appspot.com/12388005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185238 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/wm/window_util.cc20
-rw-r--r--ash/wm/window_util.h15
-rw-r--r--ash/wm/workspace/auto_window_management.cc2
-rw-r--r--ash/wm/workspace/workspace_layout_manager.cc16
-rw-r--r--ash/wm/workspace/workspace_layout_manager.h3
-rw-r--r--ash/wm/workspace/workspace_layout_manager_unittest.cc6
6 files changed, 48 insertions, 14 deletions
diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc
index 632d1d3..6f591a4 100644
--- a/ash/wm/window_util.cc
+++ b/ash/wm/window_util.cc
@@ -171,23 +171,31 @@ void SetPreAutoManageWindowBounds(aura::Window* window,
new gfx::Rect(bounds));
}
-void AdjustBoundsToEnsureWindowVisibility(gfx::Rect* bounds,
- const gfx::Rect& work_area) {
+void AdjustBoundsToEnsureMinimumWindowVisibility(const gfx::Rect& work_area,
+ gfx::Rect* bounds) {
+ AdjustBoundsToEnsureWindowVisibility(
+ work_area, kMinimumOnScreenArea, kMinimumOnScreenArea, bounds);
+}
+
+void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& work_area,
+ int min_width,
+ int min_height,
+ gfx::Rect* bounds) {
bounds->set_width(std::min(bounds->width(), work_area.width()));
bounds->set_height(std::min(bounds->height(), work_area.height()));
if (!work_area.Intersects(*bounds)) {
int y_offset = 0;
if (work_area.bottom() < bounds->y()) {
- y_offset = work_area.bottom() - bounds->y() - kMinimumOnScreenArea;
+ y_offset = work_area.bottom() - bounds->y() - min_height;
} else if (bounds->bottom() < work_area.y()) {
- y_offset = work_area.y() - bounds->bottom() + kMinimumOnScreenArea;
+ y_offset = work_area.y() - bounds->bottom() + min_height;
}
int x_offset = 0;
if (work_area.right() < bounds->x()) {
- x_offset = work_area.right() - bounds->x() - kMinimumOnScreenArea;
+ x_offset = work_area.right() - bounds->x() - min_width;
} else if (bounds->right() < work_area.x()) {
- x_offset = work_area.x() - bounds->right() + kMinimumOnScreenArea;
+ x_offset = work_area.x() - bounds->right() + min_width;
}
bounds->Offset(x_offset, y_offset);
}
diff --git a/ash/wm/window_util.h b/ash/wm/window_util.h
index 69be9cc..3eac811 100644
--- a/ash/wm/window_util.h
+++ b/ash/wm/window_util.h
@@ -110,10 +110,19 @@ ASH_EXPORT const gfx::Rect* GetPreAutoManageWindowBounds(
ASH_EXPORT void SetPreAutoManageWindowBounds(aura::Window* window,
const gfx::Rect& bounds);
-// Move the given bounds inside the given work area, including a safety margin.
+// Move the given bounds inside the given work area, including a safety margin
+// given by |kMinimumOnScreenArea|.
+ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility(
+ const gfx::Rect& work_area,
+ gfx::Rect* bounds);
+
+// Move the given bounds inside the given work area, including a safety margin
+// given by |min_width| and |min_height|.
ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility(
- gfx::Rect* bounds,
- const gfx::Rect& work_area);
+ const gfx::Rect& work_area,
+ int min_width,
+ int min_height,
+ gfx::Rect* bounds);
} // namespace wm
} // namespace ash
diff --git a/ash/wm/workspace/auto_window_management.cc b/ash/wm/workspace/auto_window_management.cc
index d00ba0f2..067ee9e 100644
--- a/ash/wm/workspace/auto_window_management.cc
+++ b/ash/wm/workspace/auto_window_management.cc
@@ -120,7 +120,7 @@ void AutoPlaceSingleWindow(aura::Window* window, bool animated) {
ash::wm::GetPreAutoManageWindowBounds(window);
if (user_defined_area) {
bounds = *user_defined_area;
- ash::wm::AdjustBoundsToEnsureWindowVisibility(&bounds, work_area);
+ ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area, &bounds);
} else {
// Center the window (only in x).
bounds.set_x((work_area.width() - bounds.width()) / 2);
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc
index 9888823..1b052d2 100644
--- a/ash/wm/workspace/workspace_layout_manager.cc
+++ b/ash/wm/workspace/workspace_layout_manager.cc
@@ -33,6 +33,10 @@ namespace internal {
namespace {
+// This specifies how much percent (2/3=66%) of a window must be visible when
+// the window is added to the workspace.
+const float kMinimumPercentOnScreenArea = 0.66f;
+
typedef std::map<const aura::Window*, gfx::Rect> BoundsMap;
// Adds an entry from |window| to its bounds and recursively invokes this for
@@ -93,7 +97,7 @@ WorkspaceLayoutManager::~WorkspaceLayoutManager() {
void WorkspaceLayoutManager::OnWindowAddedToLayout(Window* child) {
// Adjust window bounds in case that the new child is out of the workspace.
- AdjustWindowSizeForScreenChange(child, ADJUST_WINDOW_DISPLAY_INSETS_CHANGED);
+ AdjustWindowSizeForScreenChange(child, ADJUST_WINDOW_WINDOW_ADDED);
windows_.insert(child);
child->AddObserver(this);
@@ -313,7 +317,15 @@ void WorkspaceLayoutManager::AdjustWindowSizeForScreenChange(
window->SetBounds(bounds);
} else if (reason == ADJUST_WINDOW_DISPLAY_INSETS_CHANGED) {
gfx::Rect bounds = window->bounds();
- ash::wm::AdjustBoundsToEnsureWindowVisibility(&bounds, work_area_);
+ ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds);
+ if (window->bounds() != bounds)
+ window->SetBounds(bounds);
+ } else if (reason == ADJUST_WINDOW_WINDOW_ADDED) {
+ gfx::Rect bounds = window->bounds();
+ int min_width = bounds.width() * kMinimumPercentOnScreenArea;
+ int min_height = bounds.height() * kMinimumPercentOnScreenArea;
+ ash::wm::AdjustBoundsToEnsureWindowVisibility(
+ work_area_, min_width, min_height, &bounds);
if (window->bounds() != bounds)
window->SetBounds(bounds);
}
diff --git a/ash/wm/workspace/workspace_layout_manager.h b/ash/wm/workspace/workspace_layout_manager.h
index b29342e..5094268 100644
--- a/ash/wm/workspace/workspace_layout_manager.h
+++ b/ash/wm/workspace/workspace_layout_manager.h
@@ -83,7 +83,8 @@ class ASH_EXPORT WorkspaceLayoutManager
enum AdjustWindowReason {
ADJUST_WINDOW_SCREEN_SIZE_CHANGED,
- ADJUST_WINDOW_DISPLAY_INSETS_CHANGED
+ ADJUST_WINDOW_DISPLAY_INSETS_CHANGED,
+ ADJUST_WINDOW_WINDOW_ADDED
};
// Adjusts the sizes of the windows during a screen change. If this is called
diff --git a/ash/wm/workspace/workspace_layout_manager_unittest.cc b/ash/wm/workspace/workspace_layout_manager_unittest.cc
index 06e9b10..93f0f16 100644
--- a/ash/wm/workspace/workspace_layout_manager_unittest.cc
+++ b/ash/wm/workspace/workspace_layout_manager_unittest.cc
@@ -127,7 +127,11 @@ TEST_F(WorkspaceLayoutManagerTest, WindowShouldBeOnScreenWhenAdded) {
scoped_ptr<aura::Window> out_window(
CreateTestWindowInShellWithBounds(window_bounds));
EXPECT_EQ(window_bounds.size(), out_window->bounds().size());
- EXPECT_TRUE(out_window->bounds().Intersects(root_window_bounds));
+ gfx::Rect bounds = out_window->bounds();
+ bounds.Intersect(root_window_bounds);
+ // 2/3 of the window must be visible.
+ EXPECT_GT(bounds.width(), out_window->bounds().width() * 0.6);
+ EXPECT_GT(bounds.height(), out_window->bounds().height() * 0.6);
}
// Verifies the size of a window is enforced to be smaller than the work area.