diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-13 22:57:36 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-13 22:57:36 +0000 |
commit | d18357abad439f887cf3507b009146d1593008cf (patch) | |
tree | 01ec1166f64dd8b024b7cdcb79dc95aa73de19b7 /ash | |
parent | 42304ce243714c404622600abfb61a71db02f3d8 (diff) | |
download | chromium_src-d18357abad439f887cf3507b009146d1593008cf.zip chromium_src-d18357abad439f887cf3507b009146d1593008cf.tar.gz chromium_src-d18357abad439f887cf3507b009146d1593008cf.tar.bz2 |
Aura: Put resolution-based window mode switching behind a flag.
Putting this behind --aura-dynamic-window-mode until we're sure we need it. Reverted default window mode to overlapping, unless --aura-force-window-mode-compact is specified. This simplifies unit test setup, as the tests assume overlapping mode. I made the new flag set a bool so I can write unit tests without modifying CommandLine::ForCurrentProcess().
BUG=114018
TEST=aura_shell_unittests updated
Review URL: https://chromiumcodereview.appspot.com/9388013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121752 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash_switches.cc | 6 | ||||
-rw-r--r-- | ash/ash_switches.h | 1 | ||||
-rw-r--r-- | ash/shell.cc | 40 | ||||
-rw-r--r-- | ash/shell.h | 16 | ||||
-rw-r--r-- | ash/shell_unittest.cc | 52 | ||||
-rw-r--r-- | ash/test/aura_shell_test_base.cc | 3 |
6 files changed, 63 insertions, 55 deletions
diff --git a/ash/ash_switches.cc b/ash/ash_switches.cc index 69067eb..99f9c1b 100644 --- a/ash/ash_switches.cc +++ b/ash/ash_switches.cc @@ -11,6 +11,12 @@ 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 5af50965..1a64e4d 100644 --- a/ash/ash_switches.h +++ b/ash/ash_switches.h @@ -12,6 +12,7 @@ namespace ash { namespace switches { // 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 2916c7d..4cd6ed9 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -193,8 +193,6 @@ void RestoreMaximizedWindows(aura::Window* container) { // static Shell* Shell::instance_ = NULL; -// static -bool Shell::window_mode_overlapping_for_test_ = false; //////////////////////////////////////////////////////////////////////////////// // Shell, public: @@ -207,6 +205,7 @@ Shell::Shell(ShellDelegate* delegate) #endif delegate_(delegate), shelf_(NULL), + dynamic_window_mode_(false), window_mode_(MODE_OVERLAPPING), root_window_layout_(NULL), status_widget_(NULL) { @@ -277,11 +276,13 @@ void Shell::Init() { input_method_filter_.reset(new internal::InputMethodEventFilter); AddRootWindowEventFilter(input_method_filter_.get()); - // On small screens we automatically enable --aura-window-mode=compact if the - // user has not explicitly set a window mode flag. This must happen before - // we create containers or layout managers. - gfx::Size monitor_size = gfx::Screen::GetPrimaryMonitorSize(); + // 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); aura::RootWindow* root_window = aura::RootWindow::GetInstance(); @@ -351,9 +352,6 @@ void Shell::Init() { Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size, CommandLine* command_line) const { - if (window_mode_overlapping_for_test_) - return MODE_OVERLAPPING; - // Some devices don't perform well with overlapping windows. if (command_line->HasSwitch(switches::kAuraForceCompactWindowMode)) return MODE_COMPACT; @@ -370,18 +368,18 @@ Shell::WindowMode Shell::ComputeWindowMode(const gfx::Size& monitor_size, return MODE_OVERLAPPING; } - // If the screen is wide we prefer overlapping windows so you can arrange - // them side by side. - if (monitor_size.width() > kOverlappingWindowModeWidthThreshold) - return Shell::MODE_OVERLAPPING; - - // If the screen is tall we prefer overlapping windows so you have access - // to the launcher for easier switching. - if (monitor_size.height() > kOverlappingWindowModeHeightThreshold) - return Shell::MODE_OVERLAPPING; - - // If the screen is small we prefer compact. - return Shell::MODE_COMPACT; + // 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; } aura::Window* Shell::GetContainer(int container_id) { diff --git a/ash/shell.h b/ash/shell.h index dcc7552..67c4fc6 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -108,6 +108,11 @@ 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. @@ -167,11 +172,6 @@ class ASH_EXPORT Shell { return shadow_controller_.get(); } - // Force shell to start in overlapping window mode despite host window size. - static void set_window_mode_overlapping_for_test(bool overlapping) { - window_mode_overlapping_for_test_ = overlapping; - } - private: FRIEND_TEST_ALL_PREFIXES(ShellTest, ComputeWindowMode); FRIEND_TEST_ALL_PREFIXES(ShellTest, ChangeWindowMode); @@ -241,6 +241,9 @@ 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. WindowMode window_mode_; @@ -250,9 +253,6 @@ class ASH_EXPORT Shell { // Status area with clock, Wi-Fi signal, etc. views::Widget* status_widget_; - // Locks shell to overlapping window mode despite host window size. - static bool window_mode_overlapping_for_test_; - // Offset between the corner of the status area and the corner of the screen // when in the compact window mode. gfx::Size compact_status_area_offset_; diff --git a/ash/shell_unittest.cc b/ash/shell_unittest.cc index 87a3edf..a49f27dd 100644 --- a/ash/shell_unittest.cc +++ b/ash/shell_unittest.cc @@ -286,40 +286,46 @@ TEST_F(ShellTest, IsScreenLocked) { } TEST_F(ShellTest, ComputeWindowMode) { - // Since we're testing window mode computations, don't force overlapping. - ash::Shell::set_window_mode_overlapping_for_test(false); - - // Wide screens use normal window mode. + // By default, we use overlapping mode for large screens. Shell* shell = Shell::GetInstance(); gfx::Size monitor_size(1440, 900); - CommandLine command_line(CommandLine::NO_PROGRAM); + CommandLine command_line_blank(CommandLine::NO_PROGRAM); + EXPECT_EQ(Shell::MODE_OVERLAPPING, + shell->ComputeWindowMode(monitor_size, &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)); + shell->ComputeWindowMode(monitor_size, &command_line_blank)); - // Alex-sized screens need compact mode. + // Even for a large screen, the user can force compact mode. + monitor_size.SetSize(1920, 1080); + 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)); + shell->ComputeWindowMode(monitor_size, &command_line_blank)); - // ZGB-sized screens need compact mode. + // 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)); + shell->ComputeWindowMode(monitor_size, &command_line_blank)); // Even for a small screen, the user can force overlapping mode. monitor_size.SetSize(800, 600); - command_line.AppendSwitchASCII(ash::switches::kAuraWindowMode, - ash::switches::kAuraWindowModeOverlapping); + 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)); - - // 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::MODE_COMPACT, - shell->ComputeWindowMode(monitor_size, &command_line2)); + shell->ComputeWindowMode(monitor_size, &command_line_force)); } // Fails on Mac only. Need to be corrected. http://crbug.com/111279. @@ -397,8 +403,8 @@ TEST_F(ShellTest, MAYBE_ChangeWindowMode) { // only relevant on Chrome OS devices. #if defined(OS_CHROMEOS) TEST_F(ShellTest, ResizeRootWindow) { - // Since we're testing window mode computations, don't force overlapping. - ash::Shell::set_window_mode_overlapping_for_test(false); + // Allow dynamic window mode switching. + Shell::GetInstance()->set_dynamic_window_mode(true); // Switching to a small screen enables compact window mode. RootWindow::GetInstance()->SetHostSize(gfx::Size(1024, 768)); diff --git a/ash/test/aura_shell_test_base.cc b/ash/test/aura_shell_test_base.cc index 19959e0..1486f1c 100644 --- a/ash/test/aura_shell_test_base.cc +++ b/ash/test/aura_shell_test_base.cc @@ -20,9 +20,6 @@ AuraShellTestBase::~AuraShellTestBase() { void AuraShellTestBase::SetUp() { aura::test::AuraTestBase::SetUp(); - // Tests require Shell to come up in overlapping mode, despite small window. - ash::Shell::set_window_mode_overlapping_for_test(true); - // Creates Shell and hook with Desktop. ash::Shell::CreateInstance(new TestShellDelegate); |