diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 02:10:16 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-01-05 02:10:16 +0000 |
commit | 9c66adca4f62f3b85593068aea30cf1568690987 (patch) | |
tree | f20fc834b45b09babbfb19742b2c7b39b471e02f | |
parent | fdf1c47e612fb821ed0336a07929514e7d2441a2 (diff) | |
download | chromium_src-9c66adca4f62f3b85593068aea30cf1568690987.zip chromium_src-9c66adca4f62f3b85593068aea30cf1568690987.tar.gz chromium_src-9c66adca4f62f3b85593068aea30cf1568690987.tar.bz2 |
Aura: Toggling window mode in about:flags works on CrOS devices
The problem was that programmatically modifying the command line doesn't change switches visible in about:flags -- they are in a special section. Reworked the code to:
* Not modify the command line when automatically setting the mode. We now store the mode in ash::Shell.
* Add an "automatic" option for window mode, equivalent to not specifying anything on the command line.
BUG=109002
TEST=aura_shell_unittests for Shell, manual on device modifying about:flags
Review URL: http://codereview.chromium.org/9093002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@116438 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/ash_switches.cc | 8 | ||||
-rw-r--r-- | ash/ash_switches.h | 5 | ||||
-rw-r--r-- | ash/shell.cc | 49 | ||||
-rw-r--r-- | ash/shell.h | 24 | ||||
-rw-r--r-- | ash/shell_unittest.cc | 24 | ||||
-rw-r--r-- | chrome/app/generated_resources.grd | 3 | ||||
-rw-r--r-- | chrome/browser/about_flags.cc | 9 | ||||
-rw-r--r-- | chrome/browser/ui/views/frame/browser_frame.cc | 13 |
8 files changed, 81 insertions, 54 deletions
diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 21e204f..8ffd94b 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -34,11 +34,5 @@ const char kAuraWindowModeNormal[] = "normal"; // Use Aura-style workspace window dragging and sizing. const char kAuraWorkspaceManager[] = "aura-workspace-manager"; -bool IsAuraWindowModeCompact() { - std::string mode = CommandLine::ForCurrentProcess()->GetSwitchValueASCII( - switches::kAuraWindowMode); - return mode == switches::kAuraWindowModeCompact; -} - } // namespace switches } // namespace ash diff --git a/ash/ash_switches.h b/ash/ash_switches.h index a1044ae..2480bb6 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -20,9 +20,6 @@ ASH_EXPORT extern const char kAuraWindowModeCompact[]; ASH_EXPORT extern const char kAuraWindowModeNormal[]; ASH_EXPORT extern const char kAuraWorkspaceManager[]; -// Utilities for testing multi-valued switches. -ASH_EXPORT bool IsAuraWindowModeCompact(); - } // namespace switches } // namespace ash diff --git a/ash/shell.cc b/ash/shell.cc index 77e1c0c..404f0138 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -60,7 +60,8 @@ const int kCompactWindowModeWidthThreshold = 1366; // Creates each of the special window containers that holds windows of various // types in the shell UI. They are added to |containers| from back to front in // the z-index. -void CreateSpecialContainers(aura::Window::Windows* containers) { +void CreateSpecialContainers(aura::Window::Windows* containers, + bool is_window_mode_compact) { aura::Window* background_container = new aura::Window(NULL); background_container->set_id( internal::kShellWindowId_DesktopBackgroundContainer); @@ -68,7 +69,7 @@ void CreateSpecialContainers(aura::Window::Windows* containers) { aura::Window* default_container = new aura::Window(NULL); // Primary windows in compact mode don't allow drag, so don't use the filter. - if (!switches::IsAuraWindowModeCompact()) { + if (!is_window_mode_compact) { default_container->SetEventFilter( new ToplevelWindowEventFilter(default_container)); } @@ -133,7 +134,8 @@ Shell* Shell::instance_ = NULL; Shell::Shell(ShellDelegate* delegate) : ALLOW_THIS_IN_INITIALIZER_LIST(method_factory_(this)), accelerator_controller_(new AcceleratorController), - delegate_(delegate) { + delegate_(delegate), + window_mode_(NORMAL_MODE) { aura::RootWindow::GetInstance()->SetEventFilter( new internal::RootWindowEventFilter); } @@ -196,10 +198,7 @@ void Shell::Init() { // we create containers or layout managers. gfx::Size monitor_size = gfx::Screen::GetPrimaryMonitorSize(); CommandLine* command_line = CommandLine::ForCurrentProcess(); - if (DefaultToCompactWindowMode(monitor_size, command_line)) { - command_line->AppendSwitchASCII(switches::kAuraWindowMode, - switches::kAuraWindowModeCompact); - } + window_mode_ = ComputeWindowMode(monitor_size, command_line); aura::RootWindow* root_window = aura::RootWindow::GetInstance(); root_window->SetCursor(aura::kCursorPointer); @@ -207,7 +206,7 @@ void Shell::Init() { activation_controller_.reset(new internal::ActivationController); aura::Window::Windows containers; - CreateSpecialContainers(&containers); + CreateSpecialContainers(&containers, IsWindowModeCompact()); aura::Window::Windows::const_iterator i; for (i = containers.begin(); i != containers.end(); ++i) { (*i)->Init(ui::Layer::LAYER_HAS_NO_TEXTURE); @@ -242,24 +241,30 @@ void Shell::Init() { power_button_controller_.reset(new PowerButtonController); } -bool Shell::DefaultToCompactWindowMode(const gfx::Size& monitor_size, - CommandLine* command_line) const { - // Developers often run the Aura shell in a window on their desktop. - // Don't mess with their window mode. - if (!aura::RootWindow::use_fullscreen_host_window()) - return false; +Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size, + CommandLine* command_line) const { + // If user set the flag, use their desired behavior. + if (command_line->HasSwitch(switches::kAuraWindowMode)) { + std::string mode = + command_line->GetSwitchValueASCII(switches::kAuraWindowMode); + if (mode == switches::kAuraWindowModeNormal) + return NORMAL_MODE; + if (mode == switches::kAuraWindowModeCompact) + return COMPACT_MODE; + } - // If user set the flag, don't override their desired behavior. - if (command_line->HasSwitch(switches::kAuraWindowMode)) - return false; + // Developers often run the Aura shell in small windows on their desktop. + // Prefer normal mode for them. + if (!aura::RootWindow::use_fullscreen_host_window()) + return NORMAL_MODE; - // If the screen is wide enough, we prefer multiple draggable windows. + // If the screen is narrow we prefer a single compact window display. // We explicitly don't care about height, since users don't generally stack // browser windows vertically. - if (monitor_size.width() > kCompactWindowModeWidthThreshold) - return false; + if (monitor_size.width() <= kCompactWindowModeWidthThreshold) + return COMPACT_MODE; - return true; + return NORMAL_MODE; } void Shell::InitLayoutManagers(aura::RootWindow* root_window) { @@ -278,7 +283,7 @@ void Shell::InitLayoutManagers(aura::RootWindow* root_window) { // Compact mode has a simplified layout manager and doesn't use the launcher, // desktop background, shelf, etc. - if (switches::IsAuraWindowModeCompact()) { + if (IsWindowModeCompact()) { default_container->SetLayoutManager( new internal::CompactLayoutManager(status_widget)); internal::CompactStatusAreaLayoutManager* status_area_layout_manager = diff --git a/ash/shell.h b/ash/shell.h index 8fb6ffb..88951e8 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -81,6 +81,9 @@ class ASH_EXPORT Shell { // Returns true if the screen is locked. bool IsScreenLocked() const; + // See enum WindowMode for details. + bool IsWindowModeCompact() const { return window_mode_ == COMPACT_MODE; } + AcceleratorController* accelerator_controller() { return accelerator_controller_.get(); } @@ -102,19 +105,27 @@ class ASH_EXPORT Shell { } private: - FRIEND_TEST_ALL_PREFIXES(ShellTest, DefaultToCompactWindowMode); + FRIEND_TEST_ALL_PREFIXES(ShellTest, ComputeWindowMode); typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair; + // In compact window mode we fill the screen with a single maximized window, + // similar to ChromeOS R17 and earlier. In normal mode we have draggable + // windows. + enum WindowMode { + NORMAL_MODE, + COMPACT_MODE + }; + explicit Shell(ShellDelegate* delegate); virtual ~Shell(); void Init(); - // Returns true if the |monitor_size| is narrow and the user has not set - // an explicit window mode flag on the |command_line|. - bool DefaultToCompactWindowMode(const gfx::Size& monitor_size, - CommandLine* command_line) const; + // 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; void InitLayoutManagers(aura::RootWindow* root_window); @@ -148,6 +159,9 @@ class ASH_EXPORT Shell { // An event filter that pre-handles global accelerators. scoped_ptr<internal::AcceleratorFilter> accelerator_filter_; + // The |window_mode_| never changes after the shell is initialized. + // Switching modes requires a restart. + WindowMode window_mode_; DISALLOW_COPY_AND_ASSIGN(Shell); }; diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc index 0871ee8..cab9f9f 100644 --- a/ash/shell_unittest.cc +++ b/ash/shell_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -264,7 +264,7 @@ TEST_F(ShellTest, IsScreenLocked) { EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked()); } -TEST_F(ShellTest, DefaultToCompactWindowMode) { +TEST_F(ShellTest, ComputeWindowMode) { // We only change default window mode with full-screen host windows. AutoResetUseFullscreenHostWindow use_fullscreen_host_window(true); @@ -272,21 +272,33 @@ TEST_F(ShellTest, DefaultToCompactWindowMode) { Shell* shell = Shell::GetInstance(); gfx::Size monitor_size(1440, 900); CommandLine command_line(CommandLine::NO_PROGRAM); - EXPECT_FALSE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); + EXPECT_EQ(Shell::NORMAL_MODE, + shell->ComputeWindowMode(monitor_size, &command_line)); // Alex-sized screens need compact mode. monitor_size.SetSize(1280, 800); - EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); + EXPECT_EQ(Shell::COMPACT_MODE, + shell->ComputeWindowMode(monitor_size, &command_line)); // ZGB-sized screens need compact mode. monitor_size.SetSize(1366, 768); - EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); + EXPECT_EQ(Shell::COMPACT_MODE, + shell->ComputeWindowMode(monitor_size, &command_line)); // Even for a small screen, the user can force normal mode. monitor_size.SetSize(800, 600); command_line.AppendSwitchASCII(ash::switches::kAuraWindowMode, ash::switches::kAuraWindowModeNormal); - EXPECT_FALSE(shell->DefaultToCompactWindowMode(monitor_size, &command_line)); + EXPECT_EQ(Shell::NORMAL_MODE, + shell->ComputeWindowMode(monitor_size, &command_line)); + + // Even for a large screen, the user can force compact mode. + monitor_size.SetSize(1920, 1080); + CommandLine command_line2(CommandLine::NO_PROGRAM); + command_line2.AppendSwitchASCII(ash::switches::kAuraWindowMode, + ash::switches::kAuraWindowModeCompact); + EXPECT_EQ(Shell::COMPACT_MODE, + shell->ComputeWindowMode(monitor_size, &command_line2)); } } // namespace ash diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index cf7f1ad..6c929d8 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -5019,6 +5019,9 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_FLAGS_AURA_WINDOW_MODE_DESCRIPTION" desc="Description for the flag to choose how windows are displayed."> Normal mode shows draggable windows. Compact mode shows a single maximized window, useful for low-resolution devices such as laptops. </message> + <message name="IDS_FLAGS_AURA_WINDOW_MODE_AUTOMATIC" desc="Option name for automatic selection of window display mode."> + Automatic + </message> <message name="IDS_FLAGS_AURA_WINDOW_MODE_NORMAL" desc="Option name for normal window display mode."> Normal </message> diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc index c3532d1..e6c993f 100644 --- a/chrome/browser/about_flags.cc +++ b/chrome/browser/about_flags.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -77,10 +77,11 @@ const Experiment::Choice kPrerenderFromOmniboxChoices[] = { #if defined(USE_AURA) const Experiment::Choice kAuraWindowModeChoices[] = { - { IDS_FLAGS_AURA_WINDOW_MODE_NORMAL, "", "" }, + { IDS_FLAGS_AURA_WINDOW_MODE_AUTOMATIC, "", "" }, + { IDS_FLAGS_AURA_WINDOW_MODE_NORMAL, + ash::switches::kAuraWindowMode, ash::switches::kAuraWindowModeNormal }, { IDS_FLAGS_AURA_WINDOW_MODE_COMPACT, - ash::switches::kAuraWindowMode, - ash::switches::kAuraWindowModeCompact } + ash::switches::kAuraWindowMode, ash::switches::kAuraWindowModeCompact } }; #endif diff --git a/chrome/browser/ui/views/frame/browser_frame.cc b/chrome/browser/ui/views/frame/browser_frame.cc index 9463865..543f277 100644 --- a/chrome/browser/ui/views/frame/browser_frame.cc +++ b/chrome/browser/ui/views/frame/browser_frame.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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. @@ -26,6 +26,7 @@ #if defined(USE_AURA) #include "ash/ash_switches.h" +#include "ash/shell.h" #endif //////////////////////////////////////////////////////////////////////////////// @@ -68,8 +69,8 @@ void BrowserFrame::InitBrowserFrame() { CommandLine* command_line = CommandLine::ForCurrentProcess(); if (command_line->HasSwitch(ash::switches::kAuraTranslucentFrames)) params.transparent = true; - // Aura laptop mode fills the monitor with with its windows. - if (ash::switches::IsAuraWindowModeCompact() && + // Aura compact mode fills the monitor with with its windows. + if (ash::Shell::GetInstance()->IsWindowModeCompact() && browser_view_->IsBrowserTypeNormal()) { params.bounds = gfx::Screen::GetPrimaryMonitorBounds(); params.show_state = ui::SHOW_STATE_MAXIMIZED; @@ -77,11 +78,11 @@ void BrowserFrame::InitBrowserFrame() { #endif Init(params); - // On ChromeOS and Aura laptop mode we always want top-level windows + // On ChromeOS and Aura compact mode we always want top-level windows // to appear active. bool disable_inactive_rendering = false; #if defined(USE_AURA) - disable_inactive_rendering = ash::switches::IsAuraWindowModeCompact(); + disable_inactive_rendering = ash::Shell::GetInstance()->IsWindowModeCompact(); #elif defined(OS_CHROMEOS) disable_inactive_rendering = true; #endif @@ -121,7 +122,7 @@ void BrowserFrame::TabStripDisplayModeChanged() { bool BrowserFrame::IsSingleWindowMode() const { bool single_window_mode = false; #if defined(USE_AURA) - single_window_mode = ash::switches::IsAuraWindowModeCompact(); + single_window_mode = ash::Shell::GetInstance()->IsWindowModeCompact(); #elif defined(OS_CHROMEOS) single_window_mode = chromeos::system::runtime_environment::IsRunningOnChromeOS(); |