summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 02:28:49 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-22 02:28:49 +0000
commitd8b42e288d8fc5994163eed9c77ba87a5c16e489 (patch)
tree7940b57497e58e745bfda55741850ef5e205ab61 /ash
parent1e6bd068e8d91c3cac8b7c3624800198e26fb346 (diff)
downloadchromium_src-d8b42e288d8fc5994163eed9c77ba87a5c16e489.zip
chromium_src-d8b42e288d8fc5994163eed9c77ba87a5c16e489.tar.gz
chromium_src-d8b42e288d8fc5994163eed9c77ba87a5c16e489.tar.bz2
Make sure the top of the window is visible when a window is added.
Use correct work area when adjusting the bounds. BUG=286302 TEST=covered by tests Review URL: https://codereview.chromium.org/28413003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@230016 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/display/display_manager.cc2
-rw-r--r--ash/wm/window_util.cc2
-rw-r--r--ash/wm/window_util.h10
-rw-r--r--ash/wm/workspace/workspace_layout_manager.cc25
-rw-r--r--ash/wm/workspace/workspace_layout_manager.h2
-rw-r--r--ash/wm/workspace/workspace_layout_manager_unittest.cc30
6 files changed, 51 insertions, 20 deletions
diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc
index ebaea67..9ffa6c8 100644
--- a/ash/display/display_manager.cc
+++ b/ash/display/display_manager.cc
@@ -271,7 +271,7 @@ DisplayIdPair DisplayManager::GetCurrentDisplayIdPair() const {
int64 mirrored_id = mirrored_display().id();
return std::make_pair(displays_[0].id(), mirrored_id);
} else {
- CHECK_LE(2u, displays_.size());
+ CHECK_GE(2u, displays_.size());
int64 id_at_zero = displays_[0].id();
if (id_at_zero == gfx::Display::InternalDisplayId() ||
id_at_zero == first_display_id()) {
diff --git a/ash/wm/window_util.cc b/ash/wm/window_util.cc
index 48947b8..66a6243 100644
--- a/ash/wm/window_util.cc
+++ b/ash/wm/window_util.cc
@@ -92,6 +92,8 @@ void AdjustBoundsToEnsureWindowVisibility(const gfx::Rect& visible_area,
} else if (bounds->bottom() - min_height < 0) {
bounds->set_y(min_height - bounds->height());
}
+ if (bounds->y() < 0)
+ bounds->set_y(0);
}
bool MoveWindowToEventRoot(aura::Window* window, const ui::Event& event) {
diff --git a/ash/wm/window_util.h b/ash/wm/window_util.h
index b33df78..fd71a0b 100644
--- a/ash/wm/window_util.h
+++ b/ash/wm/window_util.h
@@ -50,14 +50,16 @@ ASH_EXPORT void CenterWindow(aura::Window* window);
// Change the availability of animation to the fullscreen of the |window|.
ASH_EXPORT void SetAnimateToFullscreen(aura::Window* window, bool animate);
-// Move the given bounds inside the given |visible_area|, including a
-// safety margin given by |kMinimumOnScreenArea|.
+// Move the given bounds inside the given |visible_area| in parent coordinates,
+// including a safety margin given by |kMinimumOnScreenArea|.
+// This also ensures that the top of the bounds is visible.
ASH_EXPORT void AdjustBoundsToEnsureMinimumWindowVisibility(
const gfx::Rect& visible_area,
gfx::Rect* bounds);
-// Move the given bounds inside the given |visible_area|, including a
-// safety margin given by |min_width| and |min_height|.
+// Move the given bounds inside the given |visible_area| in parent coordinates,
+// including a safety margin given by |min_width| and |min_height|.
+// This also ensures that the top of the bounds is visible.
ASH_EXPORT void AdjustBoundsToEnsureWindowVisibility(
const gfx::Rect& visible_area,
int min_width,
diff --git a/ash/wm/workspace/workspace_layout_manager.cc b/ash/wm/workspace/workspace_layout_manager.cc
index a33f680..cbc886b 100644
--- a/ash/wm/workspace/workspace_layout_manager.cc
+++ b/ash/wm/workspace/workspace_layout_manager.cc
@@ -71,7 +71,7 @@ WorkspaceLayoutManager::WorkspaceLayoutManager(aura::Window* window)
: BaseLayoutManager(window->GetRootWindow()),
shelf_(NULL),
window_(window),
- work_area_(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
+ work_area_in_parent_(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
window->parent())) {
}
@@ -127,9 +127,10 @@ void WorkspaceLayoutManager::SetChildBounds(
if (!SetMaximizedOrFullscreenBounds(wm::GetWindowState(child))) {
// Non-maximized/full-screen windows have their size constrained to the
// work-area.
- child_bounds.set_width(std::min(work_area_.width(), child_bounds.width()));
+ child_bounds.set_width(std::min(work_area_in_parent_.width(),
+ child_bounds.width()));
child_bounds.set_height(
- std::min(work_area_.height(), child_bounds.height()));
+ std::min(work_area_in_parent_.height(), child_bounds.height()));
SetChildBoundsDirect(child, child_bounds);
}
UpdateDesktopVisibility();
@@ -138,7 +139,7 @@ void WorkspaceLayoutManager::SetChildBounds(
void WorkspaceLayoutManager::OnDisplayWorkAreaInsetsChanged() {
const gfx::Rect work_area(ScreenAsh::GetDisplayWorkAreaBoundsInParent(
window_->parent()));
- if (work_area != work_area_) {
+ if (work_area != work_area_in_parent_) {
AdjustAllWindowsBoundsForWorkAreaChange(
ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED);
}
@@ -203,7 +204,8 @@ void WorkspaceLayoutManager::ShowStateChanged(
void WorkspaceLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(
AdjustWindowReason reason) {
- work_area_ = ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent());
+ work_area_in_parent_ =
+ ScreenAsh::GetDisplayWorkAreaBoundsInParent(window_->parent());
BaseLayoutManager::AdjustAllWindowsBoundsForWorkAreaChange(reason);
}
@@ -233,10 +235,11 @@ void WorkspaceLayoutManager::AdjustWindowBoundsForWorkAreaChange(
case ADJUST_WINDOW_DISPLAY_SIZE_CHANGED:
// The work area may be smaller than the full screen. Put as much of the
// window as possible within the display area.
- bounds.AdjustToFit(work_area_);
+ bounds.AdjustToFit(work_area_in_parent_);
break;
case ADJUST_WINDOW_WORK_AREA_INSETS_CHANGED:
- ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(work_area_, &bounds);
+ ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
+ work_area_in_parent_, &bounds);
break;
}
if (window_state->window()->bounds() != bounds)
@@ -267,8 +270,8 @@ void WorkspaceLayoutManager::AdjustWindowBoundsWhenAdded(
// be further shrunk by the docked area. The logic ensures 30%
// visibility which should be enough to see where the window gets
// moved.
- gfx::Rect display_area =
- Shell::GetScreen()->GetDisplayNearestWindow(window).bounds();
+ gfx::Rect display_area = ScreenAsh::GetDisplayBoundsInParent(window);
+
ash::wm::AdjustBoundsToEnsureWindowVisibility(
display_area, min_width, min_height, &bounds);
if (window->bounds() != bounds)
@@ -296,13 +299,13 @@ void WorkspaceLayoutManager::UpdateBoundsFromShowState(
if (window_state->HasRestoreBounds()) {
bounds_in_parent = window_state->GetRestoreBoundsInParent();
ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
- work_area_, &bounds_in_parent);
+ work_area_in_parent_, &bounds_in_parent);
} else {
// Minimized windows have no restore bounds.
// Use the current bounds instead.
bounds_in_parent = window->bounds();
ash::wm::AdjustBoundsToEnsureMinimumWindowVisibility(
- work_area_, &bounds_in_parent);
+ work_area_in_parent_, &bounds_in_parent);
// Don't start animation if the bounds didn't change.
if (bounds_in_parent == window->bounds())
bounds_in_parent.SetRect(0, 0, 0, 0);
diff --git a/ash/wm/workspace/workspace_layout_manager.h b/ash/wm/workspace/workspace_layout_manager.h
index d7dcae7..30a88f2 100644
--- a/ash/wm/workspace/workspace_layout_manager.h
+++ b/ash/wm/workspace/workspace_layout_manager.h
@@ -92,7 +92,7 @@ class ASH_EXPORT WorkspaceLayoutManager : public BaseLayoutManager {
// The work area. Cached to avoid unnecessarily moving windows during a
// workspace switch.
- gfx::Rect work_area_;
+ gfx::Rect work_area_in_parent_;
DISALLOW_COPY_AND_ASSIGN(WorkspaceLayoutManager);
};
diff --git a/ash/wm/workspace/workspace_layout_manager_unittest.cc b/ash/wm/workspace/workspace_layout_manager_unittest.cc
index 13f2817..00d965f 100644
--- a/ash/wm/workspace/workspace_layout_manager_unittest.cc
+++ b/ash/wm/workspace/workspace_layout_manager_unittest.cc
@@ -4,6 +4,8 @@
#include "ash/wm/workspace/workspace_layout_manager.h"
+#include "ash/display/display_layout.h"
+#include "ash/display/display_manager.h"
#include "ash/root_window_controller.h"
#include "ash/screen_ash.h"
#include "ash/shelf/shelf_layout_manager.h"
@@ -89,6 +91,25 @@ TEST_F(WorkspaceLayoutManagerTest, RestoreFromMinimizeKeepsRestore) {
Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
}
+TEST_F(WorkspaceLayoutManagerTest, KeepMinimumVisibilityInDisplays) {
+ UpdateDisplay("300x400,400x500");
+ Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
+
+ DisplayLayout layout(DisplayLayout::TOP, 0);
+ Shell::GetInstance()->display_manager()->
+ SetLayoutForCurrentDisplays(layout);
+ EXPECT_EQ("0,-500 400x500", root_windows[1]->GetBoundsInScreen().ToString());
+
+ scoped_ptr<aura::Window> window1(
+ CreateTestWindowInShellWithBounds(gfx::Rect(10, -400, 200, 200)));
+ EXPECT_EQ("10,-400 200x200", window1->GetBoundsInScreen().ToString());
+
+ // Make sure the caption is visible.
+ scoped_ptr<aura::Window> window2(
+ CreateTestWindowInShellWithBounds(gfx::Rect(10, -600, 200, 200)));
+ EXPECT_EQ("10,-500 200x200", window2->GetBoundsInScreen().ToString());
+}
+
TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
if (!SupportsHostWindowResize())
return;
@@ -102,7 +123,8 @@ TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
window_state->Restore();
EXPECT_TRUE(
Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
- EXPECT_EQ("-20,-30 30x40", window->bounds().ToString());
+ // Y bounds should not be negative.
+ EXPECT_EQ("-20,0 30x40", window->bounds().ToString());
// Minimized -> Normal transition.
window->SetBounds(gfx::Rect(-100, -100, 30, 40));
@@ -113,7 +135,8 @@ TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
window->Show();
EXPECT_TRUE(
Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
- EXPECT_EQ("-20,-30 30x40", window->bounds().ToString());
+ // Y bounds should not be negative.
+ EXPECT_EQ("-20,0 30x40", window->bounds().ToString());
// Fullscreen -> Normal transition.
window->SetBounds(gfx::Rect(0, 0, 30, 40)); // reset bounds.
@@ -124,7 +147,8 @@ TEST_F(WorkspaceLayoutManagerTest, KeepRestoredWindowInDisplay) {
window_state->Restore();
EXPECT_TRUE(
Shell::GetPrimaryRootWindow()->bounds().Intersects(window->bounds()));
- EXPECT_EQ("-20,-30 30x40", window->bounds().ToString());
+ // Y bounds should not be negative.
+ EXPECT_EQ("-20,0 30x40", window->bounds().ToString());
}
TEST_F(WorkspaceLayoutManagerTest, MaximizeInDisplayToBeRestored) {