diff options
author | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-07 13:19:57 +0000 |
---|---|---|
committer | skuhne@chromium.org <skuhne@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-07 13:19:57 +0000 |
commit | 20d16bd682839a45a8d7f05f6e2c5a501f435726 (patch) | |
tree | 6378bf6eddfb5eeed6d68ba507ff4bf376102efc /ash | |
parent | 4aa2426cd1368ec9e3dfdac988895d4ada61ea62 (diff) | |
download | chromium_src-20d16bd682839a45a8d7f05f6e2c5a501f435726.zip chromium_src-20d16bd682839a45a8d7f05f6e2c5a501f435726.tar.gz chromium_src-20d16bd682839a45a8d7f05f6e2c5a501f435726.tar.bz2 |
Don't save the touch view mode window state in the session restore set
BUG=354637
TEST=unit test & visual test
Committed: https://src.chromium.org/viewvc/chrome?view=rev&revision=268353
Review URL: https://codereview.chromium.org/252383007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@268721 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc | 79 | ||||
-rw-r--r-- | ash/wm/maximize_mode/maximize_mode_window_state.cc | 20 | ||||
-rw-r--r-- | ash/wm/window_properties.cc | 10 | ||||
-rw-r--r-- | ash/wm/window_properties.h | 13 |
4 files changed, 121 insertions, 1 deletions
diff --git a/ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc b/ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc index 56c6c53..b95aef6 100644 --- a/ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc +++ b/ash/wm/maximize_mode/maximize_mode_window_manager_unittest.cc @@ -13,8 +13,10 @@ #include "ash/test/shell_test_api.h" #include "ash/wm/mru_window_tracker.h" #include "ash/wm/overview/window_selector_controller.h" +#include "ash/wm/window_properties.h" #include "ash/wm/window_state.h" #include "ash/wm/wm_event.h" +#include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" #include "base/values.h" #include "ui/aura/client/aura_constants.h" @@ -58,6 +60,21 @@ class MaximizeModeWindowManagerTest : public test::AshTestBase { type, bounds, gfx::Size(), true, true); } + // Creates a window which also has a widget. + aura::Window* CreateWindowWithWidget(const gfx::Rect& bounds) { + views::Widget* widget = new views::Widget(); + views::Widget::InitParams params; + params.context = CurrentContext(); + // Note: The widget will get deleted with the window. + widget->Init(params); + widget->Show(); + aura::Window* window = widget->GetNativeWindow(); + window->SetBounds(bounds); + window->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_NORMAL); + + return window; + } + // Create the Maximized mode window manager. ash::MaximizeModeWindowManager* CreateMaximizeModeWindowManager() { EXPECT_FALSE(maximize_mode_window_manager()); @@ -392,6 +409,68 @@ TEST_F(MaximizeModeWindowManagerTest, EXPECT_EQ(rect.ToString(), fixed_window->bounds().ToString()); } +// Create a string which consists of the bounds and the state for comparison. +std::string GetPlacementString(const gfx::Rect& bounds, + ui::WindowShowState state) { + return bounds.ToString() + base::StringPrintf(" %d", state); +} + +// Retrieves the window's restore state override - if any - and returns it as a +// string. +std::string GetPlacementOverride(aura::Window* window) { + gfx::Rect* bounds = window->GetProperty(ash::kRestoreBoundsOverrideKey); + if (bounds) { + gfx::Rect restore_bounds = *bounds; + ui::WindowShowState restore_state = + window->GetProperty(ash::kRestoreShowStateOverrideKey); + return GetPlacementString(restore_bounds, restore_state); + } + return std::string(); +} + +// Test that the restore state will be kept at its original value for +// session restauration purposes. +TEST_F(MaximizeModeWindowManagerTest, TestRestoreIntegrety) { + gfx::Rect bounds(10, 10, 200, 50); + gfx::Size empty_size; + gfx::Rect empty_bounds; + scoped_ptr<aura::Window> normal_window( + CreateWindowWithWidget(bounds)); + scoped_ptr<aura::Window> maximized_window( + CreateWindowWithWidget(bounds)); + wm::GetWindowState(maximized_window.get())->Maximize(); + + EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get())); + EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get())); + + ash::MaximizeModeWindowManager* manager = CreateMaximizeModeWindowManager(); + ASSERT_TRUE(manager); + + // With the maximization the override states should be returned in its + // pre-maximized state. + EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_NORMAL), + GetPlacementOverride(normal_window.get())); + EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED), + GetPlacementOverride(maximized_window.get())); + + // Changing a window's state now does not change the returned result. + wm::GetWindowState(maximized_window.get())->Minimize(); + EXPECT_EQ(GetPlacementString(bounds, ui::SHOW_STATE_MAXIMIZED), + GetPlacementOverride(maximized_window.get())); + + // Destroy the manager again and check that the overrides get reset. + DestroyMaximizeModeWindowManager(); + EXPECT_EQ(std::string(), GetPlacementOverride(normal_window.get())); + EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get())); + + // Changing a window's state now does not bring the overrides back. + wm::GetWindowState(maximized_window.get())->Restore(); + gfx::Rect new_bounds(10, 10, 200, 50); + maximized_window->SetBounds(new_bounds); + + EXPECT_EQ(std::string(), GetPlacementOverride(maximized_window.get())); +} + // Test that windows which got created before the maximizer was created can be // destroyed while the maximizer is still running. TEST_F(MaximizeModeWindowManagerTest, PreCreateWindowsDeleteWhileActive) { diff --git a/ash/wm/maximize_mode/maximize_mode_window_state.cc b/ash/wm/maximize_mode/maximize_mode_window_state.cc index e150fea2..57505ee 100644 --- a/ash/wm/maximize_mode/maximize_mode_window_state.cc +++ b/ash/wm/maximize_mode/maximize_mode_window_state.cc @@ -11,7 +11,7 @@ #include "ash/wm/coordinate_conversion.h" #include "ash/wm/maximize_mode/maximize_mode_window_manager.h" #include "ash/wm/window_animations.h" -#include "ash/wm/window_state.h" +#include "ash/wm/window_properties.h" #include "ash/wm/window_state_delegate.h" #include "ash/wm/window_state_util.h" #include "ash/wm/window_util.h" @@ -22,6 +22,8 @@ #include "ui/aura/window_delegate.h" #include "ui/gfx/display.h" #include "ui/gfx/rect.h" +#include "ui/views/view_constants_aura.h" +#include "ui/views/widget/widget.h" namespace ash { namespace { @@ -186,6 +188,20 @@ void MaximizeModeWindowState::AttachState( wm::WindowState::State* previous_state) { current_state_type_ = previous_state->GetType(); + views::Widget* widget = + views::Widget::GetWidgetForNativeWindow(window_state->window()); + if (widget) { + gfx::Rect bounds = widget->GetRestoredBounds(); + if (!bounds.IsEmpty()) { + // We do not want to do a session restore to our window states. Therefore + // we tell the window to use the current default states instead. + window_state->window()->SetProperty(ash::kRestoreShowStateOverrideKey, + window_state->GetShowState()); + window_state->window()->SetProperty(ash::kRestoreBoundsOverrideKey, + new gfx::Rect(widget->GetRestoredBounds())); + } + } + // Initialize the state to a good preset. if (current_state_type_ != wm::WINDOW_STATE_TYPE_MAXIMIZED && current_state_type_ != wm::WINDOW_STATE_TYPE_MINIMIZED && @@ -199,6 +215,8 @@ void MaximizeModeWindowState::AttachState( } void MaximizeModeWindowState::DetachState(wm::WindowState* window_state) { + // From now on, we can use the default session restore mechanism again. + window_state->window()->ClearProperty(ash::kRestoreBoundsOverrideKey); window_state->set_can_be_dragged(true); } diff --git a/ash/wm/window_properties.cc b/ash/wm/window_properties.cc index 1689c90..2657e3a 100644 --- a/ash/wm/window_properties.cc +++ b/ash/wm/window_properties.cc @@ -8,9 +8,19 @@ #include "ui/aura/window_property.h" DECLARE_WINDOW_PROPERTY_TYPE(ash::wm::WindowState*); +DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ASH_EXPORT, gfx::Rect*) +DECLARE_EXPORTED_WINDOW_PROPERTY_TYPE(ASH_EXPORT, ui::WindowShowState) namespace ash { +DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, + kRestoreBoundsOverrideKey, + NULL); + +DEFINE_WINDOW_PROPERTY_KEY(ui::WindowShowState, + kRestoreShowStateOverrideKey, + ui::SHOW_STATE_DEFAULT); + DEFINE_WINDOW_PROPERTY_KEY(bool, kStayInSameRootWindowKey, false); DEFINE_WINDOW_PROPERTY_KEY(bool, kUsesScreenCoordinatesKey, false); DEFINE_OWNED_WINDOW_PROPERTY_KEY(wm::WindowState, diff --git a/ash/wm/window_properties.h b/ash/wm/window_properties.h index c99d21d..c79b694 100644 --- a/ash/wm/window_properties.h +++ b/ash/wm/window_properties.h @@ -7,6 +7,7 @@ #include "ash/ash_export.h" #include "ui/base/ui_base_types.h" +#include "ui/gfx/rect.h" namespace aura { class Window; @@ -24,6 +25,18 @@ class WindowState; // Alphabetical sort. +// A property key which stores the bounds to restore a window to. These take +// preference over the current bounds/state. This is used by e.g. the always +// maximized mode window manager. +ASH_EXPORT extern const aura::WindowProperty<gfx::Rect*>* const + kRestoreBoundsOverrideKey; + +// A property key which stores the bounds to restore a window to. These take +// preference over the current bounds/state if |kRestoreBoundsOverrideKey| is +// set. This is used by e.g. the always maximized mode window manager. +ASH_EXPORT extern const aura::WindowProperty<ui::WindowShowState>* const + kRestoreShowStateOverrideKey; + // If this is set to true, the window stays in the same root window // even if the bounds outside of its root window is set. // This is exported as it's used in the tests. |