summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-30 15:33:18 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-30 15:33:18 +0000
commit13b4a8882c128d91da9af5aef7f4136bc83c2a80 (patch)
tree4a3c17d0b3435a16be5af5638d46e342598c8473
parent4d1ad8a1add3379004da95cb2c7634048c822529 (diff)
downloadchromium_src-13b4a8882c128d91da9af5aef7f4136bc83c2a80.zip
chromium_src-13b4a8882c128d91da9af5aef7f4136bc83c2a80.tar.gz
chromium_src-13b4a8882c128d91da9af5aef7f4136bc83c2a80.tar.bz2
Always adjust the bounds to work area if the new window is the first window.
I think this is correct behavior. Cleanup: remove set_target_root_window() when adding new root window. This was old hack for test and no longer necessary. BUG=286391 TEST=covered by unit test. Review URL: https://codereview.chromium.org/46183004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231840 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ash/ash.gyp5
-rw-r--r--ash/root_window_controller.cc5
-rw-r--r--ash/shell/toplevel_window.cc10
-rw-r--r--ash/shell/toplevel_window.h7
-rw-r--r--ash/test/ash_test_base.cc6
-rw-r--r--ash/wm/window_positioner.cc14
-rw-r--r--ash/wm/window_positioner_unittest.cc52
7 files changed, 83 insertions, 16 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp
index 3c07f66..99e51f6 100644
--- a/ash/ash.gyp
+++ b/ash/ash.gyp
@@ -621,6 +621,8 @@
'ash_resources',
],
'sources': [
+ 'shell/toplevel_window.cc',
+ 'shell/toplevel_window.h',
'test/app_list_controller_test_api.cc',
'test/app_list_controller_test_api.h',
'test/ash_test_base.cc',
@@ -771,8 +773,6 @@
'shell/panel_window.h',
'shell/shell_delegate_impl.cc',
'shell/shell_delegate_impl.h',
- 'shell/toplevel_window.cc',
- 'shell/toplevel_window.h',
'shell/widgets.cc',
'shell/window_type_launcher.cc',
'shell/window_type_launcher.h',
@@ -825,6 +825,7 @@
'wm/window_cycle_controller_unittest.cc',
'wm/window_manager_unittest.cc',
'wm/window_modality_controller_unittest.cc',
+ 'wm/window_positioner_unittest.cc',
'wm/window_util_unittest.cc',
'wm/workspace/magnetism_matcher_unittest.cc',
'wm/workspace/multi_window_resize_controller_unittest.cc',
diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc
index 072608c..22eeda4 100644
--- a/ash/root_window_controller.cc
+++ b/ash/root_window_controller.cc
@@ -283,7 +283,7 @@ void RootWindowController::Shutdown() {
// being removed triggers a relayout of the shelf it will try to build a
// window list adding windows from the target root window's containers which
// may have already gone away.
- if (Shell::GetTargetRootWindow()->GetDispatcher() == root_window_) {
+ if (Shell::GetTargetRootWindow() == root_window_.get()) {
Shell::GetInstance()->set_target_root_window(
Shell::GetPrimaryRootWindow() == root_window_.get() ?
NULL : Shell::GetPrimaryRootWindow());
@@ -608,9 +608,6 @@ void RootWindowController::Init(RootWindowType root_window_type,
root_window_.get());
shell->high_contrast_controller()->OnRootWindowAdded(root_window_.get());
root_window_->ShowRootWindow();
- // Activate new root for testing.
- // TODO(oshima): remove this.
- shell->set_target_root_window(root_window_.get());
// Create a launcher if a user is already logged.
if (shell->session_state_delegate()->NumberOfLoggedInUsers())
diff --git a/ash/shell/toplevel_window.cc b/ash/shell/toplevel_window.cc
index fbea77e..b12a37c 100644
--- a/ash/shell/toplevel_window.cc
+++ b/ash/shell/toplevel_window.cc
@@ -36,13 +36,21 @@ ToplevelWindow::CreateParams::CreateParams()
}
// static
-void ToplevelWindow::CreateToplevelWindow(const CreateParams& params) {
+views::Widget* ToplevelWindow::CreateToplevelWindow(
+ const CreateParams& params) {
views::Widget* widget = views::Widget::CreateWindowWithContext(
new ToplevelWindow(params), Shell::GetPrimaryRootWindow());
widget->GetNativeView()->SetName("Examples:ToplevelWindow");
wm::WindowState* window_state = wm::GetWindowState(widget->GetNativeView());
window_state->set_window_position_managed(true);
widget->Show();
+ return widget;
+}
+
+// static
+void ToplevelWindow::ClearSavedStateForTest() {
+ delete saved_state;
+ saved_state = NULL;
}
ToplevelWindow::ToplevelWindow(const CreateParams& params) : params_(params) {
diff --git a/ash/shell/toplevel_window.h b/ash/shell/toplevel_window.h
index 77b29aa..71bbfa2 100644
--- a/ash/shell/toplevel_window.h
+++ b/ash/shell/toplevel_window.h
@@ -18,7 +18,12 @@ class ToplevelWindow : public views::WidgetDelegateView {
bool can_resize;
bool can_maximize;
};
- static void CreateToplevelWindow(const CreateParams& params);
+ static views::Widget* CreateToplevelWindow(
+ const CreateParams& params);
+
+ // Clears saved show state and bounds used to position
+ // a new window.
+ static void ClearSavedStateForTest();
private:
explicit ToplevelWindow(const CreateParams& params);
diff --git a/ash/test/ash_test_base.cc b/ash/test/ash_test_base.cc
index 945b7ca..0da80aa 100644
--- a/ash/test/ash_test_base.cc
+++ b/ash/test/ash_test_base.cc
@@ -11,6 +11,7 @@
#include "ash/display/display_controller.h"
#include "ash/screen_ash.h"
#include "ash/shell.h"
+#include "ash/shell/toplevel_window.h"
#include "ash/test/ash_test_helper.h"
#include "ash/test/display_manager_test_api.h"
#include "ash/test/test_session_state_delegate.h"
@@ -101,6 +102,11 @@ AshTestBase::~AshTestBase() {
void AshTestBase::SetUp() {
setup_called_ = true;
+
+ // Clears the saved state so that test doesn't use on the wrong
+ // default state.
+ shell::ToplevelWindow::ClearSavedStateForTest();
+
// TODO(jamescook): Can we do this without changing command line?
// Use the origin (1,1) so that it doesn't over
// lap with the native mouse cursor.
diff --git a/ash/wm/window_positioner.cc b/ash/wm/window_positioner.cc
index ceef02f..58f4fb9 100644
--- a/ash/wm/window_positioner.cc
+++ b/ash/wm/window_positioner.cc
@@ -227,20 +227,18 @@ void WindowPositioner::GetBoundsAndShowStateForNewWindow(
if (top_window == new_window)
top_window = NULL;
- // If there is no valid other window we take the coordinates as is.
+ // If there is no valid other window we take and adjust the passed coordinates
+ // and show state.
if (!top_window) {
gfx::Rect work_area = screen->GetDisplayNearestWindow(target).work_area();
- if (is_saved_bounds) {
- // Restore to saved state - if there is one.
- bounds_in_out->AdjustToFit(work_area);
+ bounds_in_out->AdjustToFit(work_area);
+ // Use adjusted saved bounds, if there is one.
+ if (is_saved_bounds)
return;
- }
-
// When using "small screens" we want to always open in full screen mode.
if (show_state_in == ui::SHOW_STATE_DEFAULT &&
- work_area.width() <=
- WindowPositioner::GetForceMaximizedWidthLimit() &&
+ work_area.width() <= GetForceMaximizedWidthLimit() &&
(!new_window || !wm::GetWindowState(new_window)->IsFullscreen())) {
*show_state_out = ui::SHOW_STATE_MAXIMIZED;
}
diff --git a/ash/wm/window_positioner_unittest.cc b/ash/wm/window_positioner_unittest.cc
new file mode 100644
index 0000000..497e014
--- /dev/null
+++ b/ash/wm/window_positioner_unittest.cc
@@ -0,0 +1,52 @@
+// Copyright 2013 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/window_positioner.h"
+
+#include "ash/shell.h"
+#include "ash/shell/toplevel_window.h"
+#include "ash/test/ash_test_base.h"
+#include "ash/wm/window_state.h"
+#include "ui/aura/root_window.h"
+#include "ui/gfx/screen.h"
+#include "ui/views/widget/widget.h"
+
+namespace ash {
+
+typedef test::AshTestBase WindowPositionerTest;
+
+TEST_F(WindowPositionerTest, OpenMaximizedWindowOnSecondDisplay) {
+ if (!SupportsMultipleDisplays())
+ return;
+ UpdateDisplay("400x400,500x500");
+ Shell::GetInstance()->set_target_root_window(
+ Shell::GetAllRootWindows()[1]);
+ shell::ToplevelWindow::CreateParams params;
+ params.can_resize = true;
+ params.can_maximize = true;
+ views::Widget* widget =
+ shell::ToplevelWindow::CreateToplevelWindow(params);
+ EXPECT_EQ("400,0 500x453", widget->GetWindowBoundsInScreen().ToString());
+}
+
+TEST_F(WindowPositionerTest, OpenDefaultWindowOnSecondDisplay) {
+ if (!SupportsMultipleDisplays())
+ return;
+ UpdateDisplay("400x400,1400x900");
+ aura::Window* second_root_window = Shell::GetAllRootWindows()[1];
+ Shell::GetInstance()->set_target_root_window(
+ second_root_window);
+ shell::ToplevelWindow::CreateParams params;
+ params.can_resize = true;
+ params.can_maximize = true;
+ views::Widget* widget =
+ shell::ToplevelWindow::CreateToplevelWindow(params);
+ gfx::Rect bounds = widget->GetWindowBoundsInScreen();
+ // The window should be in the 2nd display with the default size.
+ EXPECT_EQ("300x300", bounds.size().ToString());
+ EXPECT_TRUE(Shell::GetScreen()->GetDisplayNearestWindow(
+ second_root_window).bounds().Contains(bounds));
+}
+
+} // namespace