summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-22 21:12:27 +0000
committerjamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-22 21:12:27 +0000
commitb06392858ab76a6720352022f224b1144af06548 (patch)
tree13f484806c2596c0dd807df27e5458460c1abb23
parentfdfcfe325f7d00f4f729b99ed39e6f039fb01feb (diff)
downloadchromium_src-b06392858ab76a6720352022f224b1144af06548.zip
chromium_src-b06392858ab76a6720352022f224b1144af06548.tar.gz
chromium_src-b06392858ab76a6720352022f224b1144af06548.tar.bz2
Aura: Automatically use compact window mode on narrow displays
We default to compact mode on displays with a width of 1366 (ZGB) and narrower. Only do this when we're not running in a window, to avoid changing the default for Aura developers running on desktop workstations. BUG=108187 TEST=added unit test Review URL: http://codereview.chromium.org/9018022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@115606 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--ui/aura/root_window.h3
-rw-r--r--ui/aura_shell/shell.cc38
-rw-r--r--ui/aura_shell/shell.h12
-rw-r--r--ui/aura_shell/shell_unittest.cc47
4 files changed, 96 insertions, 4 deletions
diff --git a/ui/aura/root_window.h b/ui/aura/root_window.h
index 0af56b2..b3e91ec 100644
--- a/ui/aura/root_window.h
+++ b/ui/aura/root_window.h
@@ -53,6 +53,9 @@ class AURA_EXPORT RootWindow : public ui::CompositorDelegate,
static void set_use_fullscreen_host_window(bool use_fullscreen) {
use_fullscreen_host_window_ = use_fullscreen;
}
+ static bool use_fullscreen_host_window() {
+ return use_fullscreen_host_window_;
+ }
ui::Compositor* compositor() { return compositor_.get(); }
gfx::Point last_mouse_location() const { return last_mouse_location_; }
diff --git a/ui/aura_shell/shell.cc b/ui/aura_shell/shell.cc
index de891c8..87c772e 100644
--- a/ui/aura_shell/shell.cc
+++ b/ui/aura_shell/shell.cc
@@ -38,6 +38,8 @@
#include "ui/aura_shell/workspace_controller.h"
#include "ui/gfx/compositor/layer.h"
#include "ui/gfx/compositor/layer_animator.h"
+#include "ui/gfx/screen.h"
+#include "ui/gfx/size.h"
#include "ui/views/widget/native_widget_aura.h"
#include "ui/views/widget/widget.h"
@@ -47,6 +49,11 @@ namespace {
using views::Widget;
+// Screen width at or below which we automatically start in compact window mode,
+// in pixels. Should be at least 1366 pixels, the resolution of ChromeOS ZGB
+// device displays, as we traditionally used a single window on those devices.
+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.
@@ -176,6 +183,16 @@ void Shell::DeleteInstance() {
}
void Shell::Init() {
+ // 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();
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (DefaultToCompactWindowMode(monitor_size, command_line)) {
+ command_line->AppendSwitchASCII(switches::kAuraWindowMode,
+ switches::kAuraWindowModeCompact);
+ }
+
aura::RootWindow* root_window = aura::RootWindow::GetInstance();
root_window->SetCursor(aura::kCursorPointer);
@@ -194,7 +211,6 @@ void Shell::Init() {
InitLayoutManagers(root_window);
- CommandLine* command_line = CommandLine::ForCurrentProcess();
if (!command_line->HasSwitch(switches::kAuraNoShadows))
shadow_controller_.reset(new internal::ShadowController());
@@ -214,6 +230,26 @@ void Shell::Init() {
drag_drop_controller_.reset(new internal::DragDropController);
}
+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;
+
+ // If user set the flag, don't override their desired behavior.
+ if (command_line->HasSwitch(switches::kAuraWindowMode))
+ return false;
+
+ // If the screen is wide enough, we prefer multiple draggable windows.
+ // We explicitly don't care about height, since users don't generally stack
+ // browser windows vertically.
+ if (monitor_size.width() > kCompactWindowModeWidthThreshold)
+ return false;
+
+ return true;
+}
+
void Shell::InitLayoutManagers(aura::RootWindow* root_window) {
internal::RootWindowLayoutManager* root_window_layout =
new internal::RootWindowLayoutManager(root_window);
diff --git a/ui/aura_shell/shell.h b/ui/aura_shell/shell.h
index 66c88eb..fb971a8 100644
--- a/ui/aura_shell/shell.h
+++ b/ui/aura_shell/shell.h
@@ -10,12 +10,15 @@
#include <vector>
#include "base/basictypes.h"
+#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/task.h"
#include "base/compiler_specific.h"
#include "base/memory/weak_ptr.h"
#include "ui/aura_shell/aura_shell_export.h"
+class CommandLine;
+
namespace aura {
class EventFilter;
class RootWindow;
@@ -23,6 +26,7 @@ class Window;
}
namespace gfx {
class Rect;
+class Size;
}
namespace aura_shell {
@@ -93,12 +97,20 @@ class AURA_SHELL_EXPORT Shell {
}
private:
+ FRIEND_TEST_ALL_PREFIXES(ShellTest, DefaultToCompactWindowMode);
+
typedef std::pair<aura::Window*, gfx::Rect> WindowAndBoundsPair;
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;
+
void InitLayoutManagers(aura::RootWindow* root_window);
// Enables WorkspaceManager.
diff --git a/ui/aura_shell/shell_unittest.cc b/ui/aura_shell/shell_unittest.cc
index f00a3df..0afe720 100644
--- a/ui/aura_shell/shell_unittest.cc
+++ b/ui/aura_shell/shell_unittest.cc
@@ -2,17 +2,20 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "ui/aura/test/aura_test_base.h"
+#include "ui/aura/root_window.h"
#include "ui/aura/window.h"
+#include "ui/aura_shell/aura_shell_switches.h"
#include "ui/aura_shell/shell.h"
#include "ui/aura_shell/shell_window_ids.h"
#include "ui/aura_shell/test/aura_shell_test_base.h"
+#include "ui/gfx/size.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
namespace aura_shell {
-namespace test {
namespace {
@@ -70,9 +73,23 @@ class ModalWindow : public views::WidgetDelegateView {
DISALLOW_COPY_AND_ASSIGN(ModalWindow);
};
+// After base::AutoReset<> but via setter and getter.
+class AutoResetUseFullscreenHostWindow {
+ public:
+ AutoResetUseFullscreenHostWindow(bool new_value) {
+ old_value_ = aura::RootWindow::use_fullscreen_host_window();
+ aura::RootWindow::set_use_fullscreen_host_window(new_value);
+ }
+ ~AutoResetUseFullscreenHostWindow() {
+ aura::RootWindow::set_use_fullscreen_host_window(old_value_);
+ }
+ private:
+ bool old_value_;
+};
+
} // namespace
-class ShellTest : public AuraShellTestBase {
+class ShellTest : public test::AuraShellTestBase {
public:
ShellTest() {}
virtual ~ShellTest() {}
@@ -247,5 +264,29 @@ TEST_F(ShellTest, IsScreenLocked) {
EXPECT_FALSE(Shell::GetInstance()->IsScreenLocked());
}
-} // namespace test
+TEST_F(ShellTest, DefaultToCompactWindowMode) {
+ // We only change default window mode with full-screen host windows.
+ AutoResetUseFullscreenHostWindow use_fullscreen_host_window(true);
+
+ // Wide screens use normal window mode.
+ Shell* shell = Shell::GetInstance();
+ gfx::Size monitor_size(1440, 900);
+ CommandLine command_line(CommandLine::NO_PROGRAM);
+ EXPECT_FALSE(shell->DefaultToCompactWindowMode(monitor_size, &command_line));
+
+ // Alex-sized screens need compact mode.
+ monitor_size.SetSize(1280, 800);
+ EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line));
+
+ // ZGB-sized screens need compact mode.
+ monitor_size.SetSize(1366, 768);
+ EXPECT_TRUE(shell->DefaultToCompactWindowMode(monitor_size, &command_line));
+
+ // Even for a small screen, the user can force normal mode.
+ monitor_size.SetSize(800, 600);
+ command_line.AppendSwitchASCII(aura_shell::switches::kAuraWindowMode,
+ aura_shell::switches::kAuraWindowModeNormal);
+ EXPECT_FALSE(shell->DefaultToCompactWindowMode(monitor_size, &command_line));
+}
+
} // namespace aura_shell