From 2b4cd30636e2e17528135b3332c3536ca2da5633 Mon Sep 17 00:00:00 2001 From: "jamescook@chromium.org" Date: Fri, 24 Feb 2012 20:21:13 +0000 Subject: Aura: Remove dynamic switching into and out of compact mode Going forward we'll select compact mode based on command line flags passed by the session manager. Compact mode should go away entirely when Aura is more mature, so we don't need to maintain the ability to switch modes. This patch simplifies the Shell setup code and updates the Shell unit tests to match. BUG=115314 TEST=aura_shell_unittests, specifically Shell* Review URL: http://codereview.chromium.org/9452028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123532 0039d316-1c4b-4281-b951-d872f2087c98 --- ash/accelerators/accelerator_controller.cc | 13 -- .../accelerator_controller_unittest.cc | 3 - ash/ash_switches.cc | 6 - ash/ash_switches.h | 1 - ash/shell.cc | 111 +++--------- ash/shell.h | 50 +++--- ash/shell_unittest.cc | 196 +++++++++------------ ash/wm/root_window_layout_manager.cc | 5 - 8 files changed, 132 insertions(+), 253 deletions(-) (limited to 'ash') diff --git a/ash/accelerators/accelerator_controller.cc b/ash/accelerators/accelerator_controller.cc index 1a9e54a..9ee26a9 100644 --- a/ash/accelerators/accelerator_controller.cc +++ b/ash/accelerators/accelerator_controller.cc @@ -49,7 +49,6 @@ enum AcceleratorAction { PRINT_LAYER_HIERARCHY, PRINT_WINDOW_HIERARCHY, ROTATE_SCREEN, - TOGGLE_COMPACT_WINDOW_MODE, TOGGLE_DESKTOP_BACKGROUND_MODE, TOGGLE_ROOT_WINDOW_FULL_SCREEN, #endif @@ -123,8 +122,6 @@ const struct AcceleratorData { #if !defined(NDEBUG) { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_HOME, false, true, false, ROTATE_SCREEN }, - { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_A, false, true, true, - TOGGLE_COMPACT_WINDOW_MODE }, { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_B, false, true, true, TOGGLE_DESKTOP_BACKGROUND_MODE }, { ui::ET_TRANSLATED_KEY_PRESS, ui::VKEY_F11, false, true, false, @@ -199,14 +196,6 @@ bool HandleRotateScreen() { return true; } -bool HandleToggleCompactWindowMode() { - if (ash::Shell::GetInstance()->IsWindowModeCompact()) - ash::Shell::GetInstance()->ChangeWindowMode(ash::Shell::MODE_OVERLAPPING); - else - ash::Shell::GetInstance()->ChangeWindowMode(ash::Shell::MODE_COMPACT); - return true; -} - bool HandleToggleDesktopBackgroundMode() { ash::Shell* shell = ash::Shell::GetInstance(); if (shell->desktop_background_mode() == ash::Shell::BACKGROUND_IMAGE) @@ -393,8 +382,6 @@ bool AcceleratorController::AcceleratorPressed( #if !defined(NDEBUG) case ROTATE_SCREEN: return HandleRotateScreen(); - case TOGGLE_COMPACT_WINDOW_MODE: - return HandleToggleCompactWindowMode(); case TOGGLE_DESKTOP_BACKGROUND_MODE: return HandleToggleDesktopBackgroundMode(); case TOGGLE_ROOT_WINDOW_FULL_SCREEN: diff --git a/ash/accelerators/accelerator_controller_unittest.cc b/ash/accelerators/accelerator_controller_unittest.cc index 87b6d9b..6d3d3be 100644 --- a/ash/accelerators/accelerator_controller_unittest.cc +++ b/ash/accelerators/accelerator_controller_unittest.cc @@ -634,9 +634,6 @@ TEST_F(AcceleratorControllerTest, GlobalAccelerators) { // RotateScreen EXPECT_TRUE(GetController()->Process( PostImeAccelerator(ui::VKEY_HOME, false, true, false))); - // ToggleCompactWindowMode - EXPECT_TRUE(GetController()->Process( - PostImeAccelerator(ui::VKEY_A, false, true, true))); // ToggleDesktopBackgroundMode EXPECT_TRUE(GetController()->Process( PostImeAccelerator(ui::VKEY_B, false, true, true))); diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 99f9c1b..69067eb 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -11,12 +11,6 @@ namespace ash { namespace switches { -// Dynamically choose window mode based on screen resolution, switching to -// compact mode on small screens and overlapping mode on large screens. -// TODO(jamescook): We probably don't want this if we end up with a simple -// variant of overlapping mode on small screens. See Shell::ComputeWindowMode. -const char kAuraDynamicWindowMode[] = "aura-dynamic-window-mode"; - // Force the "compact" window mode regardless of the value of kAuraWindowMode. // This can be used to override a value set in chrome://flags. // TODO(derat): Remove this once the normal mode is usable on all platforms. diff --git a/ash/ash_switches.h b/ash/ash_switches.h index 50a69c61..251b6af 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -16,7 +16,6 @@ namespace switches { // see chromeos::LoginUtil::GetOffTheRecordCommandLine().) // Please keep alphabetized. -ASH_EXPORT extern const char kAuraDynamicWindowMode[]; ASH_EXPORT extern const char kAuraForceCompactWindowMode[]; ASH_EXPORT extern const char kAuraGoogleDialogFrames[]; ASH_EXPORT extern const char kAuraLegacyPowerButton[]; diff --git a/ash/shell.cc b/ash/shell.cc index c2998ae..22a2f38 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -69,16 +69,6 @@ namespace { using aura::Window; using views::Widget; -// Screen width above which we automatically start in overlapping window mode, -// in pixels. Should be at least 1366 pixels as we traditionally used a single -// window on Chrome OS ZGB devices with that width. -const int kOverlappingWindowModeWidthThreshold = 1366; - -// Screen height above which we automatically start in overlapping window mode, -// in pixels. Should be at least 800 pixels as we traditionally used a single -// window on Chrome OS alex devices with that height. -const int kOverlappingWindowModeHeightThreshold = 800; - // Creates a new window for use as a container. aura::Window* CreateContainer(int window_id, aura::Window* parent) { aura::Window* container = new aura::Window(NULL); @@ -182,30 +172,25 @@ void CreateSpecialContainers(aura::Window* root_window) { lock_screen_related_containers); } -// Maximizes all the windows in a |container|. -void MaximizeWindows(aura::Window* container) { - const std::vector& windows = container->children(); - for (std::vector::const_iterator it = windows.begin(); - it != windows.end(); - ++it) - window_util::MaximizeWindow(*it); -} - -// Restores all maximized windows in a |container|. -void RestoreMaximizedWindows(aura::Window* container) { - const std::vector& windows = container->children(); - for (std::vector::const_iterator it = windows.begin(); - it != windows.end(); - ++it) { - if (window_util::IsWindowMaximized(*it)) - window_util::RestoreWindow(*it); - } -} - } // namespace // static Shell* Shell::instance_ = NULL; +// static +bool Shell::compact_window_mode_for_test_ = false; + +//////////////////////////////////////////////////////////////////////////////// +// Shell::TestApi + +Shell::TestApi::TestApi(Shell* shell) : shell_(shell) {} + +Shell::WindowMode Shell::TestApi::ComputeWindowMode(CommandLine* cmd) const { + return shell_->ComputeWindowMode(cmd); +} + +internal::RootWindowLayoutManager* Shell::TestApi::root_window_layout() { + return shell_->root_window_layout_; +} //////////////////////////////////////////////////////////////////////////////// // Shell, public: @@ -218,7 +203,6 @@ Shell::Shell(ShellDelegate* delegate) #endif delegate_(delegate), shelf_(NULL), - dynamic_window_mode_(false), window_mode_(MODE_OVERLAPPING), desktop_background_mode_(BACKGROUND_IMAGE), root_window_layout_(NULL), @@ -315,14 +299,9 @@ void Shell::Init() { input_method_filter_.reset(new internal::InputMethodEventFilter); AddRootWindowEventFilter(input_method_filter_.get()); - // Dynamic window mode affects window mode computation. - CommandLine* command_line = CommandLine::ForCurrentProcess(); - dynamic_window_mode_ = command_line->HasSwitch( - switches::kAuraDynamicWindowMode); - // Window mode must be set before computing containers or layout managers. - gfx::Size monitor_size = gfx::Screen::GetPrimaryMonitorSize(); - window_mode_ = ComputeWindowMode(monitor_size, command_line); + CommandLine* command_line = CommandLine::ForCurrentProcess(); + window_mode_ = ComputeWindowMode(command_line); aura::RootWindow* root_window = GetRootWindow(); root_window->SetCursor(aura::kCursorPointer); @@ -377,8 +356,10 @@ void Shell::Init() { window_cycle_controller_.reset(new WindowCycleController); } -Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size, - CommandLine* command_line) const { +Shell::WindowMode Shell::ComputeWindowMode(CommandLine* command_line) const { + if (compact_window_mode_for_test_) + return MODE_COMPACT; + // Some devices don't perform well with overlapping windows. if (command_line->HasSwitch(switches::kAuraForceCompactWindowMode)) return MODE_COMPACT; @@ -395,16 +376,6 @@ Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size, return MODE_OVERLAPPING; } - // If we're trying to dynamically choose window mode based on screen - // resolution, use compact mode for narrow/short screens. - // TODO(jamescook): If we go with a simple variant of overlapping mode for - // small screens we should remove this and the dynamic mode switching code - // in SetupCompactWindowMode and SetupNonCompactWindowMode. - if (dynamic_window_mode_ && - monitor_size.width() <= kOverlappingWindowModeWidthThreshold && - monitor_size.height() <= kOverlappingWindowModeHeightThreshold) - return Shell::MODE_COMPACT; - // Overlapping is the default. return Shell::MODE_OVERLAPPING; } @@ -445,26 +416,6 @@ void Shell::ToggleAppList() { app_list_->SetVisible(!app_list_->IsVisible()); } -void Shell::ChangeWindowMode(WindowMode mode) { - if (mode == window_mode_) - return; - // Window mode must be set before we resize/layout the windows. - window_mode_ = mode; - if (window_mode_ == MODE_COMPACT) - SetupCompactWindowMode(); - else - SetupNonCompactWindowMode(); -} - -void Shell::SetWindowModeForMonitorSize(const gfx::Size& monitor_size) { - // If we're running on a device, a resolution change means the user plugged in - // or unplugged an external monitor. Change window mode to be appropriate for - // the new screen resolution. - CommandLine* command_line = CommandLine::ForCurrentProcess(); - WindowMode new_mode = ComputeWindowMode(monitor_size, command_line); - ChangeWindowMode(new_mode); -} - void Shell::SetDesktopBackgroundMode(BackgroundMode mode) { if (mode == BACKGROUND_SOLID_COLOR) { // Set a solid black background. @@ -535,13 +486,6 @@ void Shell::SetupCompactWindowMode() { DCHECK(root_window_layout_); DCHECK(status_widget_); - shelf_ = NULL; - - // Clean out the old layout managers before we start. - ResetLayoutManager(internal::kShellWindowId_DefaultContainer); - ResetLayoutManager(internal::kShellWindowId_LauncherContainer); - ResetLayoutManager(internal::kShellWindowId_StatusContainer); - // Don't use an event filter for the default container, as we don't support // window dragging, double-click to maximize, etc. aura::Window* default_container = @@ -562,9 +506,6 @@ void Shell::SetupCompactWindowMode() { // maximizing the windows so the work area is the right size. launcher_->widget()->Hide(); - // Maximize all the windows, using the new layout manager. - MaximizeWindows(default_container); - // Set a solid black background. SetDesktopBackgroundMode(BACKGROUND_SOLID_COLOR); } @@ -573,11 +514,6 @@ void Shell::SetupNonCompactWindowMode() { DCHECK(root_window_layout_); DCHECK(status_widget_); - // Clean out the old layout managers before we start. - ResetLayoutManager(internal::kShellWindowId_DefaultContainer); - ResetLayoutManager(internal::kShellWindowId_LauncherContainer); - ResetLayoutManager(internal::kShellWindowId_StatusContainer); - internal::ShelfLayoutManager* shelf_layout_manager = new internal::ShelfLayoutManager(launcher_->widget(), status_widget_); GetContainer(internal::kShellWindowId_LauncherContainer)-> @@ -608,11 +544,6 @@ void Shell::SetupNonCompactWindowMode() { // Ensure launcher is visible. launcher_->widget()->Show(); - // Restore all maximized windows. Don't change full screen windows, as we - // don't want to disrupt a user trying to plug in an external monitor to - // give a presentation. - RestoreMaximizedWindows(default_container); - // Create the desktop background image. SetDesktopBackgroundMode(BACKGROUND_IMAGE); } diff --git a/ash/shell.h b/ash/shell.h index 1d58180..db60bae 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -90,6 +90,20 @@ class ASH_EXPORT Shell { BACKWARD }; + // Accesses private data from a Shell for testing. + class ASH_EXPORT TestApi { + public: + explicit TestApi(Shell* shell); + + WindowMode ComputeWindowMode(CommandLine* cmd) const; + internal::RootWindowLayoutManager* root_window_layout(); + + private: + Shell* shell_; // not owned + + DISALLOW_COPY_AND_ASSIGN(TestApi); + }; + // A shell must be explicitly created so that it can call |Init()| with the // delegate set. |delegate| can be NULL (if not required for initialization). static Shell* CreateInstance(ShellDelegate* delegate); @@ -124,19 +138,6 @@ class ASH_EXPORT Shell { // Toggles app list. void ToggleAppList(); - // Dynamic window mode chooses between MODE_OVERLAPPING and MODE_COMPACT - // based on screen resolution and dynamically changes modes when the screen - // resolution changes (e.g. plugging in a monitor). - void set_dynamic_window_mode(bool value) { dynamic_window_mode_ = value; } - - // Changes the current window mode, which will cause all the open windows - // to be laid out in the new mode and layout managers and event filters to be - // installed or removed. - void ChangeWindowMode(WindowMode mode); - - // Sets an appropriate window mode for the given screen resolution. - void SetWindowModeForMonitorSize(const gfx::Size& monitor_size); - // Sets the desktop background mode. void SetDesktopBackgroundMode(BackgroundMode mode); @@ -197,10 +198,11 @@ class ASH_EXPORT Shell { return shadow_controller_.get(); } - private: - FRIEND_TEST_ALL_PREFIXES(ShellTest, ComputeWindowMode); - FRIEND_TEST_ALL_PREFIXES(ShellTest, ChangeWindowMode); + static void set_compact_window_mode_for_test(bool compact) { + compact_window_mode_for_test_ = compact; + } + private: typedef std::pair WindowAndBoundsPair; explicit Shell(ShellDelegate* delegate); @@ -208,10 +210,9 @@ class ASH_EXPORT Shell { void Init(); - // Returns the appropriate window mode to use based on the primary monitor's - // |monitor_size| and the user's |command_line|. - WindowMode ComputeWindowMode(const gfx::Size& monitor_size, - CommandLine* command_line) const; + // Returns the appropriate window mode to use based on the |command_line| + // and |compact_window_mode_for_test_|. + WindowMode ComputeWindowMode(CommandLine* command_line) const; // Initializes or re-initializes the layout managers and event filters needed // to support a given window mode and cleans up the unneeded ones. @@ -224,6 +225,10 @@ class ASH_EXPORT Shell { static Shell* instance_; + // Window mode is computed at shell initialization time, so allow it to be + // overridden without modifying the global command line. + static bool compact_window_mode_for_test_; + internal::RootWindowEventFilter* root_filter_; // not owned std::vector to_restore_; @@ -270,10 +275,7 @@ class ASH_EXPORT Shell { // the status area. internal::ShelfLayoutManager* shelf_; - // Change window mode based on screen resolution. - bool dynamic_window_mode_; - - // Can change at runtime. + // Does not change after Init(). WindowMode window_mode_; // Can change at runtime. diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc index 0da07cb..db7afd9 100644 --- a/ash/shell_unittest.cc +++ b/ash/shell_unittest.cc @@ -288,59 +288,47 @@ TEST_F(ShellTest, IsScreenLocked) { } TEST_F(ShellTest, ComputeWindowMode) { - // By default, we use overlapping mode for large screens. + // By default, we use overlapping mode. Shell* shell = Shell::GetInstance(); - gfx::Size monitor_size(1440, 900); + Shell::TestApi test_api(shell); CommandLine command_line_blank(CommandLine::NO_PROGRAM); EXPECT_EQ(Shell::MODE_OVERLAPPING, - shell->ComputeWindowMode(monitor_size, &command_line_blank)); + test_api.ComputeWindowMode(&command_line_blank)); - // By default, we use overlapping mode for small screens too. - monitor_size.SetSize(800, 600); - EXPECT_EQ(Shell::MODE_OVERLAPPING, - shell->ComputeWindowMode(monitor_size, &command_line_blank)); + // Sometimes we force compact mode. + CommandLine command_line_force(CommandLine::NO_PROGRAM); + command_line_force.AppendSwitch(switches::kAuraForceCompactWindowMode); + EXPECT_EQ(Shell::MODE_COMPACT, + test_api.ComputeWindowMode(&command_line_force)); - // Even for a large screen, the user can force compact mode. - monitor_size.SetSize(1920, 1080); + // The user can set compact mode. CommandLine command_line_compact(CommandLine::NO_PROGRAM); command_line_compact.AppendSwitchASCII(switches::kAuraWindowMode, switches::kAuraWindowModeCompact); EXPECT_EQ(Shell::MODE_COMPACT, - shell->ComputeWindowMode(monitor_size, &command_line_compact)); - - // Now test dynamic window mode computation. - Shell::GetInstance()->set_dynamic_window_mode(true); - - // Alex-sized screens need compact mode when choosing dynamically. - monitor_size.SetSize(1280, 800); - EXPECT_EQ(Shell::MODE_COMPACT, - shell->ComputeWindowMode(monitor_size, &command_line_blank)); - - // ZGB-sized screens need compact mode when choosing dynamically. - monitor_size.SetSize(1366, 768); - EXPECT_EQ(Shell::MODE_COMPACT, - shell->ComputeWindowMode(monitor_size, &command_line_blank)); - - // Even for a small screen, the user can force overlapping mode. - monitor_size.SetSize(800, 600); - CommandLine command_line_force(CommandLine::NO_PROGRAM); - command_line_force.AppendSwitchASCII(switches::kAuraWindowMode, - switches::kAuraWindowModeOverlapping); - EXPECT_EQ(Shell::MODE_OVERLAPPING, - shell->ComputeWindowMode(monitor_size, &command_line_force)); + test_api.ComputeWindowMode(&command_line_compact)); + + // The user can set managed. + CommandLine command_line_managed(CommandLine::NO_PROGRAM); + command_line_managed.AppendSwitchASCII(switches::kAuraWindowMode, + switches::kAuraWindowModeManaged); + EXPECT_EQ(Shell::MODE_MANAGED, + test_api.ComputeWindowMode(&command_line_managed)); } -// Fails on Mac only. Need to be corrected. http://crbug.com/111279. +// Fails on Mac, see http://crbug.com/115662 #if defined(OS_MACOSX) -#define MAYBE_ChangeWindowMode FAILS_ChangeWindowMode +#define MAYBE_OverlappingWindowModeBasics FAILS_OverlappingWindowModeBasics #else -#define MAYBE_ChangeWindowMode ChangeWindowMode +#define MAYBE_OverlappingWindowModeBasics OverlappingWindowModeBasics #endif -TEST_F(ShellTest, MAYBE_ChangeWindowMode) { +TEST_F(ShellTest, MAYBE_OverlappingWindowModeBasics) { + Shell* shell = Shell::GetInstance(); + Shell::TestApi test_api(shell); + // We start with the usual window containers. ExpectAllContainers(); // We're not in compact window mode by default. - Shell* shell = Shell::GetInstance(); EXPECT_FALSE(shell->IsWindowModeCompact()); // We have a default container event filter (for window drags). EXPECT_TRUE(GetDefaultContainer()->event_filter()); @@ -352,8 +340,8 @@ TEST_F(ShellTest, MAYBE_ChangeWindowMode) { EXPECT_EQ(Shell::GetRootWindow()->GetHostSize().height(), launcher_widget->GetWindowScreenBounds().bottom()); // We have a desktop background but not a bare layer. - EXPECT_TRUE(shell->root_window_layout_->background_widget()); - EXPECT_FALSE(shell->root_window_layout_->background_layer()); + EXPECT_TRUE(test_api.root_window_layout()->background_widget()); + EXPECT_FALSE(test_api.root_window_layout()->background_layer()); // Create a normal window. It is not maximized. views::Widget::InitParams widget_params( @@ -363,72 +351,12 @@ TEST_F(ShellTest, MAYBE_ChangeWindowMode) { widget->Show(); EXPECT_FALSE(widget->IsMaximized()); - // Set our new mode. - shell->ChangeWindowMode(Shell::MODE_COMPACT); - EXPECT_TRUE(shell->IsWindowModeCompact()); - // Compact mode does not use a default container event filter. - EXPECT_FALSE(GetDefaultContainer()->event_filter()); - // We still have all the usual containers. - ExpectAllContainers(); - - // In compact window mode, all windows are maximized. - EXPECT_TRUE(widget->IsMaximized()); - // Window bounds got updated to fill the work area. - EXPECT_EQ(widget->GetWorkAreaBoundsInScreen(), - widget->GetWindowScreenBounds()); - // Launcher is hidden. - EXPECT_FALSE(launcher_widget->IsVisible()); - // Desktop background widget is gone but we have a layer. - EXPECT_FALSE(shell->root_window_layout_->background_widget()); - EXPECT_TRUE(shell->root_window_layout_->background_layer()); - - // Switch back to overlapping mode. - shell->ChangeWindowMode(Shell::MODE_OVERLAPPING); - EXPECT_FALSE(shell->IsWindowModeCompact()); - // Event filter came back. - EXPECT_TRUE(GetDefaultContainer()->event_filter()); - // Launcher is visible again. - EXPECT_TRUE(launcher_widget->IsVisible()); - // Launcher is at bottom-left of screen. - EXPECT_EQ(0, launcher_widget->GetWindowScreenBounds().x()); - EXPECT_EQ(Shell::GetRootWindow()->GetHostSize().height(), - launcher_widget->GetWindowScreenBounds().bottom()); - // Desktop background is back. - EXPECT_TRUE(shell->root_window_layout_->background_widget()); - EXPECT_FALSE(shell->root_window_layout_->background_layer()); - // Clean up. widget->Close(); } -// Windows bots won't let us create large root windows, and this behavior is -// only relevant on Chrome OS devices. -#if defined(OS_CHROMEOS) -TEST_F(ShellTest, ResizeRootWindow) { - // Allow dynamic window mode switching. - Shell::GetInstance()->set_dynamic_window_mode(true); - - // Switching to a small screen enables compact window mode. - Shell::GetRootWindow()->SetHostSize(gfx::Size(1024, 768)); - EXPECT_TRUE(Shell::GetInstance()->IsWindowModeCompact()); - - // Launcher is hidden. - views::Widget* launcher_widget = Shell::GetInstance()->launcher()->widget(); - EXPECT_FALSE(launcher_widget->IsVisible()); - - // Switching to a large screen disables compact window mode. - Shell::GetRootWindow()->SetHostSize(gfx::Size(1920, 1080)); - EXPECT_FALSE(Shell::GetInstance()->IsWindowModeCompact()); - - // Launcher is in the bottom-left corner of window. - EXPECT_EQ(0, launcher_widget->GetWindowScreenBounds().x()); - EXPECT_EQ(1080, launcher_widget->GetWindowScreenBounds().bottom()); -} -#endif // defined(OS_CHROMEOS) - TEST_F(ShellTest, FullscreenWindowHidesShelf) { ExpectAllContainers(); - Shell* shell = Shell::GetInstance(); // Create a normal window. It is not maximized. views::Widget::InitParams widget_params( @@ -438,30 +366,76 @@ TEST_F(ShellTest, FullscreenWindowHidesShelf) { widget->Show(); EXPECT_FALSE(widget->IsMaximized()); - // Test in the compact mode. There should be no shelf. - shell->ChangeWindowMode(Shell::MODE_COMPACT); - EXPECT_FALSE(Shell::GetInstance()->shelf()); - - // Test in the managed mode. - shell->ChangeWindowMode(Shell::MODE_MANAGED); + // Shelf defaults to visible. EXPECT_TRUE(Shell::GetInstance()->shelf()->visible()); + // Fullscreen window hides it. widget->SetFullscreen(true); EXPECT_FALSE(Shell::GetInstance()->shelf()->visible()); + // Restoring the window restores it. widget->Restore(); EXPECT_TRUE(Shell::GetInstance()->shelf()->visible()); - // Test in the overlap mode. - shell->ChangeWindowMode(Shell::MODE_OVERLAPPING); - EXPECT_TRUE(Shell::GetInstance()->shelf()->visible()); + // Clean up. + widget->Close(); +} - widget->SetFullscreen(true); - EXPECT_FALSE(Shell::GetInstance()->shelf()->visible()); +// Window mode is computed at Shell initialization time. Rather than changing +// the global command line to select compact mode we set a switch before +// initializing the shell. +class ShellCompactWindowModeTest : public test::AshTestBase { + public: + ShellCompactWindowModeTest() {} + virtual ~ShellCompactWindowModeTest() {} - widget->Restore(); - EXPECT_TRUE(Shell::GetInstance()->shelf()->visible()); + virtual void SetUp() OVERRIDE { + // Must set this before base class initializes the shell. + Shell::set_compact_window_mode_for_test(true); + test::AshTestBase::SetUp(); + } + + virtual void TearDown() OVERRIDE { + test::AshTestBase::TearDown(); + Shell::set_compact_window_mode_for_test(false); + } + + private: + DISALLOW_COPY_AND_ASSIGN(ShellCompactWindowModeTest); +}; +TEST_F(ShellCompactWindowModeTest, CompactWindowModeBasics) { + Shell* shell = Shell::GetInstance(); + Shell::TestApi test_api(shell); + + EXPECT_TRUE(shell->IsWindowModeCompact()); + // Compact mode does not use a default container event filter. + EXPECT_FALSE(GetDefaultContainer()->event_filter()); + // We have all the usual containers. + ExpectAllContainers(); + + // Compact mode has no shelf. + EXPECT_TRUE(shell->shelf() == NULL); + + // Create a window. In compact mode, windows are created maximized. + views::Widget::InitParams widget_params( + views::Widget::InitParams::TYPE_WINDOW); + widget_params.bounds.SetRect(11, 22, 300, 400); + widget_params.show_state = ui::SHOW_STATE_MAXIMIZED; + views::Widget* widget = CreateTestWindow(widget_params); + widget->Show(); + + // Window bounds got updated to fill the work area. + EXPECT_EQ(widget->GetWorkAreaBoundsInScreen(), + widget->GetWindowScreenBounds()); + // Launcher is hidden. + views::Widget* launcher_widget = shell->launcher()->widget(); + EXPECT_FALSE(launcher_widget->IsVisible()); + // Desktop background widget is gone but we have a layer. + EXPECT_FALSE(test_api.root_window_layout()->background_widget()); + EXPECT_TRUE(test_api.root_window_layout()->background_layer()); + + // Clean up. widget->Close(); } diff --git a/ash/wm/root_window_layout_manager.cc b/ash/wm/root_window_layout_manager.cc index e237737..409247c 100644 --- a/ash/wm/root_window_layout_manager.cc +++ b/ash/wm/root_window_layout_manager.cc @@ -4,7 +4,6 @@ #include "ash/wm/root_window_layout_manager.h" -#include "ash/shell.h" #include "ui/aura/window.h" #include "ui/views/widget/widget.h" @@ -42,10 +41,6 @@ void RootWindowLayoutManager::OnWindowResized() { gfx::Rect fullscreen_bounds = gfx::Rect(owner_->bounds().width(), owner_->bounds().height()); - // Change window mode before setting bounds on children so the children will - // resize to fit the new workspace area. - Shell::GetInstance()->SetWindowModeForMonitorSize(fullscreen_bounds.size()); - // Resize both our immediate children (the containers-of-containers animated // by PowerButtonController) and their children (the actual containers). aura::Window::Windows::const_iterator i; -- cgit v1.1