diff options
author | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-11 02:10:42 +0000 |
---|---|---|
committer | derat@chromium.org <derat@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-11 02:10:42 +0000 |
commit | 0c4011b93ad687c5087589a04220b804d086acbe (patch) | |
tree | 01c6d548aa4ef11760e72cbf0ecbcc02dd63de41 | |
parent | d24fc3a01519bb8894321a53935f127face2af28 (diff) | |
download | chromium_src-0c4011b93ad687c5087589a04220b804d086acbe.zip chromium_src-0c4011b93ad687c5087589a04220b804d086acbe.tar.gz chromium_src-0c4011b93ad687c5087589a04220b804d086acbe.tar.bz2 |
aura: Update status area position in compact mode.
This makes us adjust the position of the status area when it
compact mode depending on whether we're currently showing
the login/lock screen or not.
BUG=113001
TEST=added; also did manual testing
Review URL: http://codereview.chromium.org/9379024
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@121616 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/shell.cc | 12 | ||||
-rw-r--r-- | ash/shell.h | 14 | ||||
-rw-r--r-- | ash/wm/compact_status_area_layout_manager.cc | 18 | ||||
-rw-r--r-- | chrome/browser/ui/views/aura/status_area_host_aura.cc | 72 | ||||
-rw-r--r-- | chrome/browser/ui/views/aura/status_area_host_aura.h | 16 | ||||
-rw-r--r-- | chrome/browser/ui/views/aura/status_area_host_aura_browsertest.cc | 23 |
6 files changed, 122 insertions, 33 deletions
diff --git a/ash/shell.cc b/ash/shell.cc index 6874ca0..f5f2246 100644 --- a/ash/shell.cc +++ b/ash/shell.cc @@ -451,6 +451,18 @@ bool Shell::IsModalWindowOpen() const { return !modal_container->children().empty(); } +void Shell::SetCompactStatusAreaOffset(gfx::Size& offset) { + compact_status_area_offset_ = offset; + + // Trigger a relayout. + if (IsWindowModeCompact()) { + aura::LayoutManager* layout_manager = GetContainer( + internal::kShellWindowId_StatusContainer)->layout_manager(); + if (layout_manager) + layout_manager->OnWindowResized(); + } +} + views::NonClientFrameView* Shell::CreateDefaultNonClientFrameView( views::Widget* widget) { if (CommandLine::ForCurrentProcess()->HasSwitch( diff --git a/ash/shell.h b/ash/shell.h index 853f2e1..833cfee 100644 --- a/ash/shell.h +++ b/ash/shell.h @@ -15,6 +15,7 @@ #include "base/memory/scoped_ptr.h" #include "base/compiler_specific.h" #include "base/memory/weak_ptr.h" +#include "ui/gfx/size.h" class CommandLine; @@ -26,7 +27,6 @@ class Window; namespace gfx { class Point; class Rect; -class Size; } namespace views { class NonClientFrameView; @@ -89,6 +89,10 @@ class ASH_EXPORT Shell { static void DeleteInstance(); + const gfx::Size& compact_status_area_offset() const { + return compact_status_area_offset_; + } + aura::Window* GetContainer(int container_id); const aura::Window* GetContainer(int container_id) const; @@ -120,6 +124,10 @@ class ASH_EXPORT Shell { // See enum WindowMode for details. bool IsWindowModeCompact() const { return window_mode_ == MODE_COMPACT; } + // Sets the offset between the corner of the status area and the corner of the + // screen when we're using the compact window mode. + void SetCompactStatusAreaOffset(gfx::Size& offset); + // Creates a default views::NonClientFrameView for use by windows in the // Ash environment. views::NonClientFrameView* CreateDefaultNonClientFrameView( @@ -237,6 +245,10 @@ class ASH_EXPORT Shell { // 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_; + DISALLOW_COPY_AND_ASSIGN(Shell); }; diff --git a/ash/wm/compact_status_area_layout_manager.cc b/ash/wm/compact_status_area_layout_manager.cc index 7be8f14..5e2fcc8 100644 --- a/ash/wm/compact_status_area_layout_manager.cc +++ b/ash/wm/compact_status_area_layout_manager.cc @@ -4,22 +4,13 @@ #include "ash/wm/compact_status_area_layout_manager.h" +#include "ash/shell.h" #include "base/auto_reset.h" #include "base/i18n/rtl.h" #include "ui/gfx/rect.h" #include "ui/gfx/screen.h" #include "ui/views/widget/widget.h" -namespace { - -// Padding between the side of status area and the side of screen. -const int kSideEdgePad = 3; - -// Padding between the top of the status area and the top of the screen. -const int kTopEdgePad = 2; - -} // namespace - namespace ash { namespace internal { @@ -69,15 +60,16 @@ void CompactStatusAreaLayoutManager::LayoutStatusArea() { AutoReset<bool> auto_reset_in_layout(&in_layout_, true); gfx::Rect monitor_bounds = gfx::Screen::GetPrimaryMonitorBounds(); gfx::Rect widget_bounds = status_widget_->GetRestoredBounds(); + gfx::Size offset = ash::Shell::GetInstance()->compact_status_area_offset(); if (base::i18n::IsRTL()) { // Place the widget in the top-left corner of the screen. - widget_bounds.set_x(monitor_bounds.x() + kSideEdgePad); + widget_bounds.set_x(monitor_bounds.x() + offset.width()); } else { // Place the widget in the top-right corner of the screen. widget_bounds.set_x( - monitor_bounds.right() - widget_bounds.width() - kSideEdgePad); + monitor_bounds.right() - widget_bounds.width() - offset.width()); } - widget_bounds.set_y(kTopEdgePad); + widget_bounds.set_y(offset.height()); status_widget_->SetBounds(widget_bounds); } diff --git a/chrome/browser/ui/views/aura/status_area_host_aura.cc b/chrome/browser/ui/views/aura/status_area_host_aura.cc index 46e24d5..312e059 100644 --- a/chrome/browser/ui/views/aura/status_area_host_aura.cc +++ b/chrome/browser/ui/views/aura/status_area_host_aura.cc @@ -35,6 +35,32 @@ #include "ui/gfx/native_widget_types.h" #endif +namespace { + +// Horizontal padding between the side of the status area and the side of the +// screen in compact mode. +const int kCompactModeHorizontalOffset = 3; + +// Vertical padding between the top of the status area and the top of the screen +// when we're displaying either the login/lock screen or a browser window in +// compact mode. +const int kCompactModeLoginAndLockVerticalOffset = 4; +const int kCompactModeBrowserVerticalOffset = 2; + +} // namespace + +// static +gfx::Size StatusAreaHostAura::GetCompactModeLoginAndLockOffset() { + return gfx::Size(kCompactModeHorizontalOffset, + kCompactModeLoginAndLockVerticalOffset); +} + +// static +gfx::Size StatusAreaHostAura::GetCompactModeBrowserOffset() { + return gfx::Size(kCompactModeHorizontalOffset, + kCompactModeBrowserVerticalOffset); +} + StatusAreaHostAura::StatusAreaHostAura() : status_area_widget_(NULL), status_area_view_(NULL) { @@ -89,6 +115,8 @@ views::Widget* StatusAreaHostAura::CreateStatusArea() { status_area_widget_->Show(); status_area_widget_->GetNativeView()->SetName("StatusAreaView"); + UpdateAppearance(); + return status_area_widget_; } @@ -188,12 +216,7 @@ void StatusAreaHostAura::ExecuteStatusAreaCommand( StatusAreaButton::TextStyle StatusAreaHostAura::GetStatusAreaTextStyle() const { #if defined(OS_CHROMEOS) - if (!chromeos::UserManager::Get()->user_is_logged_in()) - return StatusAreaButton::GRAY_PLAIN_LIGHT; - - const chromeos::ScreenLocker* locker = - chromeos::ScreenLocker::default_screen_locker(); - if (locker && locker->locked()) + if (IsLoginOrLockScreenDisplayed()) return StatusAreaButton::GRAY_PLAIN_LIGHT; #endif @@ -220,16 +243,8 @@ void StatusAreaHostAura::ButtonVisibilityChanged(views::View* button_view) { status_area_view_->UpdateButtonVisibility(); } -void StatusAreaHostAura::OnBrowserAdded(const Browser* browser) { - status_area_view_->UpdateButtonTextStyle(); -} - -void StatusAreaHostAura::OnBrowserRemoved(const Browser* browser) { - status_area_view_->UpdateButtonTextStyle(); -} - void StatusAreaHostAura::OnBrowserSetLastActive(const Browser* browser) { - status_area_view_->UpdateButtonTextStyle(); + UpdateAppearance(); } void StatusAreaHostAura::Observe(int type, @@ -237,14 +252,37 @@ void StatusAreaHostAura::Observe(int type, const content::NotificationDetails& details) { switch (type) { case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: - status_area_view_->UpdateButtonTextStyle(); + UpdateAppearance(); break; #if defined(OS_CHROMEOS) case chrome::NOTIFICATION_SCREEN_LOCK_STATE_CHANGED: - status_area_view_->UpdateButtonTextStyle(); + UpdateAppearance(); break; #endif default: NOTREACHED() << "Unexpected notification " << type; } } + +bool StatusAreaHostAura::IsLoginOrLockScreenDisplayed() const { +#if defined(OS_CHROMEOS) + if (!chromeos::UserManager::Get()->user_is_logged_in()) + return true; + + const chromeos::ScreenLocker* locker = + chromeos::ScreenLocker::default_screen_locker(); + if (locker && locker->locked()) + return true; +#endif + + return false; +} + +void StatusAreaHostAura::UpdateAppearance() { + status_area_view_->UpdateButtonTextStyle(); + + gfx::Size offset = IsLoginOrLockScreenDisplayed() ? + GetCompactModeLoginAndLockOffset() : + GetCompactModeBrowserOffset(); + ash::Shell::GetInstance()->SetCompactStatusAreaOffset(offset); +} diff --git a/chrome/browser/ui/views/aura/status_area_host_aura.h b/chrome/browser/ui/views/aura/status_area_host_aura.h index c3d08d2..6321dfc 100644 --- a/chrome/browser/ui/views/aura/status_area_host_aura.h +++ b/chrome/browser/ui/views/aura/status_area_host_aura.h @@ -29,6 +29,12 @@ class StatusAreaHostAura : public StatusAreaButton::Delegate, public BrowserList::Observer, public content::NotificationObserver { public: + // Returns the padding between the corner of the status area and the corner of + // the screen when we're displaying either the login/lock screen or a browser + // window in compact mode. Exposed here for tests. + static gfx::Size GetCompactModeLoginAndLockOffset(); + static gfx::Size GetCompactModeBrowserOffset(); + StatusAreaHostAura(); virtual ~StatusAreaHostAura(); @@ -53,8 +59,8 @@ class StatusAreaHostAura : public StatusAreaButton::Delegate, virtual void ButtonVisibilityChanged(views::View* button_view) OVERRIDE; // BrowserList::Observer implementation. - virtual void OnBrowserAdded(const Browser* browser) OVERRIDE; - virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE; + virtual void OnBrowserAdded(const Browser* browser) OVERRIDE {} + virtual void OnBrowserRemoved(const Browser* browser) OVERRIDE {} virtual void OnBrowserSetLastActive(const Browser* browser) OVERRIDE; // content::NotificationObserver implementation. @@ -63,6 +69,12 @@ class StatusAreaHostAura : public StatusAreaButton::Delegate, const content::NotificationDetails& details) OVERRIDE; private: + // Is either the login or lock screen currently displayed? + bool IsLoginOrLockScreenDisplayed() const; + + // Triggers an update of the status area text style and position. + void UpdateAppearance(); + // Owned by caller of CreateStatusArea(). views::Widget* status_area_widget_; // Owned by status_area_widget_. diff --git a/chrome/browser/ui/views/aura/status_area_host_aura_browsertest.cc b/chrome/browser/ui/views/aura/status_area_host_aura_browsertest.cc index ea12c8e..78ed752 100644 --- a/chrome/browser/ui/views/aura/status_area_host_aura_browsertest.cc +++ b/chrome/browser/ui/views/aura/status_area_host_aura_browsertest.cc @@ -6,6 +6,7 @@ #include "base/command_line.h" #include "base/memory/scoped_ptr.h" #include "chrome/browser/chromeos/status/status_area_button.h" +#include "chrome/browser/profiles/profile_manager.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/views/aura/chrome_shell_delegate.h" @@ -15,6 +16,7 @@ #include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/ui_test_utils.h" #include "content/public/browser/notification_service.h" +#include "ui/gfx/size.h" #if defined(OS_CHROMEOS) #include "chrome/browser/chromeos/login/screen_locker.h" @@ -32,6 +34,8 @@ IN_PROC_BROWSER_TEST_F(StatusAreaHostAuraTest, TextStyle) { #if defined(OS_CHROMEOS) ASSERT_FALSE(chromeos::UserManager::Get()->user_is_logged_in()); EXPECT_EQ(StatusAreaButton::GRAY_PLAIN_LIGHT, host->GetStatusAreaTextStyle()); + EXPECT_EQ(StatusAreaHostAura::GetCompactModeLoginAndLockOffset().ToString(), + ash::Shell::GetInstance()->compact_status_area_offset().ToString()); // ProfileManager expects a profile dir to be set on Chrome OS. CommandLine::ForCurrentProcess()->AppendSwitchNative( @@ -40,6 +44,8 @@ IN_PROC_BROWSER_TEST_F(StatusAreaHostAuraTest, TextStyle) { ASSERT_TRUE(chromeos::UserManager::Get()->user_is_logged_in()); #endif + Browser* browser = CreateBrowser(ProfileManager::GetDefaultProfile()); + if (ash::Shell::GetInstance()->IsWindowModeCompact()) { EXPECT_EQ(StatusAreaButton::GRAY_EMBOSSED_BOLD, host->GetStatusAreaTextStyle()); @@ -56,6 +62,9 @@ IN_PROC_BROWSER_TEST_F(StatusAreaHostAuraTest, TextStyle) { host->GetStatusAreaTextStyle()); } + EXPECT_EQ(StatusAreaHostAura::GetCompactModeBrowserOffset().ToString(), + ash::Shell::GetInstance()->compact_status_area_offset().ToString()); + #if defined(OS_CHROMEOS) // Lock the screen. chromeos::ScreenLocker::Show(); @@ -69,9 +78,23 @@ IN_PROC_BROWSER_TEST_F(StatusAreaHostAuraTest, TextStyle) { lock_state_observer.Wait(); ASSERT_TRUE(tester->IsLocked()); EXPECT_EQ(StatusAreaButton::GRAY_PLAIN_LIGHT, host->GetStatusAreaTextStyle()); + EXPECT_EQ(StatusAreaHostAura::GetCompactModeLoginAndLockOffset().ToString(), + ash::Shell::GetInstance()->compact_status_area_offset().ToString()); chromeos::ScreenLocker::Hide(); ui_test_utils::RunAllPendingInMessageLoop(); ASSERT_FALSE(tester->IsLocked()); + + if (ash::Shell::GetInstance()->IsWindowModeCompact()) { + EXPECT_EQ(StatusAreaButton::GRAY_EMBOSSED_BOLD, + host->GetStatusAreaTextStyle()); + } else { + EXPECT_EQ(StatusAreaButton::WHITE_HALOED_BOLD, + host->GetStatusAreaTextStyle()); + } + EXPECT_EQ(StatusAreaHostAura::GetCompactModeBrowserOffset().ToString(), + ash::Shell::GetInstance()->compact_status_area_offset().ToString()); #endif + + browser->CloseWindow(); } |