diff options
author | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 14:06:19 +0000 |
---|---|---|
committer | bartfab@chromium.org <bartfab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-11-08 14:06:19 +0000 |
commit | 1efd5f1835b9b93c52ae011f58fd33e4740e7a7e (patch) | |
tree | 2a281d499bf41e5bd439298a0e24561eed687b71 /ash | |
parent | 7a2a94316bb03dacdb49165023c6302cb01657ba (diff) | |
download | chromium_src-1efd5f1835b9b93c52ae011f58fd33e4740e7a7e.zip chromium_src-1efd5f1835b9b93c52ae011f58fd33e4740e7a7e.tar.gz chromium_src-1efd5f1835b9b93c52ae011f58fd33e4740e7a7e.tar.bz2 |
This CL adds a big red logout button to the aura bar. The button is
triggered by setting the kShowLogoutButtonInTray to true. This is meant
to happen automatically when logging into a public account but the code
is kept generic so that the logout button can be enabled for other
accounts as well in the future if needed.
BUG=152929
Review URL: https://chromiumcodereview.appspot.com/11345010
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@166672 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r-- | ash/ash.gyp | 3 | ||||
-rw-r--r-- | ash/system/logout_button/logout_button_observer.h | 22 | ||||
-rw-r--r-- | ash/system/logout_button/tray_logout_button.cc | 141 | ||||
-rw-r--r-- | ash/system/logout_button/tray_logout_button.h | 43 | ||||
-rw-r--r-- | ash/system/tray/system_tray.cc | 6 | ||||
-rw-r--r-- | ash/system/tray/system_tray.h | 5 |
6 files changed, 220 insertions, 0 deletions
diff --git a/ash/ash.gyp b/ash/ash.gyp index 2e11d2e..f190980 100644 --- a/ash/ash.gyp +++ b/ash/ash.gyp @@ -186,6 +186,9 @@ 'system/keyboard_brightness/keyboard_brightness_control_delegate.h', 'system/locale/tray_locale.cc', 'system/locale/tray_locale.h', + 'system/logout_button/logout_button_observer.h', + 'system/logout_button/tray_logout_button.cc', + 'system/logout_button/tray_logout_button.h', 'system/monitor/tray_monitor.cc', 'system/monitor/tray_monitor.h', 'system/power/power_status_observer.h', diff --git a/ash/system/logout_button/logout_button_observer.h b/ash/system/logout_button/logout_button_observer.h new file mode 100644 index 0000000..9234c7d --- /dev/null +++ b/ash/system/logout_button/logout_button_observer.h @@ -0,0 +1,22 @@ +// 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. + +#ifndef ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_ +#define ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_ + +namespace ash { + +// Observer for the value of the kShowLogoutButtonInTray pref that determines +// whether a logout button should be shown in the system tray during a session. +class LogoutButtonObserver { + public: + virtual ~LogoutButtonObserver() {} + + // Called when the value of the kShowLogoutButtonInTray pref changes. + virtual void OnShowLogoutButtonInTrayChanged(bool show) = 0; +}; + +} // namespace ash + +#endif // ASH_SYSTEM_LOGOUT_BUTTON_LOGOUT_BUTTON_OBSERVER_H_ diff --git a/ash/system/logout_button/tray_logout_button.cc b/ash/system/logout_button/tray_logout_button.cc new file mode 100644 index 0000000..3acc60a --- /dev/null +++ b/ash/system/logout_button/tray_logout_button.cc @@ -0,0 +1,141 @@ +// 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. + +#include "ash/system/logout_button/tray_logout_button.h" + +#include <cstddef> + +#include "ash/shell.h" +#include "ash/system/tray/system_tray_delegate.h" +#include "ash/system/user/login_status.h" +#include "base/logging.h" +#include "base/string16.h" +#include "grit/ash_resources.h" +#include "third_party/skia/include/core/SkColor.h" +#include "ui/views/controls/button/border_images.h" +#include "ui/views/controls/button/button.h" +#include "ui/views/controls/button/custom_button.h" +#include "ui/views/controls/button/label_button.h" +#include "ui/views/controls/button/label_button_border.h" + +namespace { + +const int kLogoutButtonBorderNormalImages[] = { + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_TOP_RIGHT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_CENTER, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_RIGHT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_NORMAL_BOTTOM_RIGHT +}; +const int kLogoutButtonBorderHotImages[] = { + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_TOP_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_TOP, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_TOP_RIGHT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_CENTER, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_RIGHT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_BOTTOM_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_BOTTOM, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_HOT_BOTTOM_RIGHT +}; +const int kLogoutButtonBorderPushedImages[] = { + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_TOP_RIGHT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_CENTER, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_RIGHT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_LEFT, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM, + IDR_AURA_UBER_TRAY_LOGOUT_BUTTON_PUSHED_BOTTOM_RIGHT +}; + +} // namespace + +namespace ash { +namespace internal { + +namespace tray { + +class LogoutButton : public views::LabelButton, + public views::ButtonListener { + public: + LogoutButton(user::LoginStatus status) : views::LabelButton(this, string16()), + login_status_(user::LOGGED_IN_NONE), + show_logout_button_in_tray_(false) { + for (size_t state = 0; state < views::CustomButton::BS_COUNT; ++state) { + SetTextColor(static_cast<views::CustomButton::ButtonState>(state), + SK_ColorWHITE); + } + SetFont(GetFont().DeriveFont(1)); + views::LabelButtonBorder* border = new views::LabelButtonBorder(); + border->SetImages(views::CustomButton::BS_NORMAL, + views::BorderImages(kLogoutButtonBorderNormalImages)); + border->SetImages(views::CustomButton::BS_HOT, + views::BorderImages(kLogoutButtonBorderHotImages)); + border->SetImages(views::CustomButton::BS_PUSHED, + views::BorderImages(kLogoutButtonBorderPushedImages)); + set_border(border); + OnLoginStatusChanged(status); + } + + void OnLoginStatusChanged(user::LoginStatus status) { + login_status_ = status; + SetText(GetLocalizedSignOutStringForStatus(login_status_)); + UpdateVisibility(); + } + + void OnShowLogoutButtonInTrayChanged(bool show) { + show_logout_button_in_tray_ = show; + UpdateVisibility(); + } + + // Overridden from views::ButtonListener. + void ButtonPressed(views::Button* sender, const ui::Event& event) OVERRIDE { + DCHECK_EQ(sender, this); + Shell::GetInstance()->tray_delegate()->SignOut(); + } + + private: + void UpdateVisibility() { + SetVisible(show_logout_button_in_tray_ && + login_status_ != user::LOGGED_IN_NONE && + login_status_ != user::LOGGED_IN_LOCKED); + } + + user::LoginStatus login_status_; + bool show_logout_button_in_tray_; + + DISALLOW_COPY_AND_ASSIGN(LogoutButton); +}; + +} // namespace tray + +TrayLogoutButton::TrayLogoutButton() : logout_button_(NULL) { +} + +views::View* TrayLogoutButton::CreateTrayView(user::LoginStatus status) { + CHECK(logout_button_ == NULL); + logout_button_ = new tray::LogoutButton(status); + return logout_button_; +} + +void TrayLogoutButton::DestroyTrayView() { + logout_button_ = NULL; +} + +void TrayLogoutButton::UpdateAfterLoginStatusChange(user::LoginStatus status) { + logout_button_->OnLoginStatusChanged(status); +} + +void TrayLogoutButton::OnShowLogoutButtonInTrayChanged(bool show) { + logout_button_->OnShowLogoutButtonInTrayChanged(show); +} + +} // namespace internal +} // namespace ash diff --git a/ash/system/logout_button/tray_logout_button.h b/ash/system/logout_button/tray_logout_button.h new file mode 100644 index 0000000..ca51d9d --- /dev/null +++ b/ash/system/logout_button/tray_logout_button.h @@ -0,0 +1,43 @@ +// 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. + +#ifndef ASH_SYSTEM_LOGOUT_BUTTON_TRAY_LOGOUT_BUTTON_H_ +#define ASH_SYSTEM_LOGOUT_BUTTON_TRAY_LOGOUT_BUTTON_H_ + +#include "ash/system/logout_button/logout_button_observer.h" +#include "ash/system/tray/system_tray_item.h" +#include "base/basictypes.h" +#include "base/compiler_specific.h" + +namespace ash { +namespace internal { + +namespace tray { +class LogoutButton; +} + +// Adds a logout button to the system tray if enabled by the +// kShowLogoutButtonInTray pref. +class TrayLogoutButton : public SystemTrayItem, public LogoutButtonObserver { + public: + TrayLogoutButton(); + + // Overridden from SystemTrayItem. + virtual views::View* CreateTrayView(user::LoginStatus status) OVERRIDE; + virtual void DestroyTrayView() OVERRIDE; + virtual void UpdateAfterLoginStatusChange(user::LoginStatus status) OVERRIDE; + + // Overridden from LogoutButtonObserver. + virtual void OnShowLogoutButtonInTrayChanged(bool show) OVERRIDE; + + private: + tray::LogoutButton* logout_button_; + + DISALLOW_COPY_AND_ASSIGN(TrayLogoutButton); +}; + +} // namespace internal +} // namespace ash + +#endif // ASH_SYSTEM_LOGOUT_BUTTON_TRAY_LOGOUT_BUTTON_H_ diff --git a/ash/system/tray/system_tray.cc b/ash/system/tray/system_tray.cc index 5116dc8..e7d8385 100644 --- a/ash/system/tray/system_tray.cc +++ b/ash/system/tray/system_tray.cc @@ -16,6 +16,7 @@ #include "ash/system/drive/tray_drive.h" #include "ash/system/ime/tray_ime.h" #include "ash/system/locale/tray_locale.h" +#include "ash/system/logout_button/tray_logout_button.h" #include "ash/system/monitor/tray_monitor.h" #include "ash/system/power/power_status_observer.h" #include "ash/system/power/power_supply_status.h" @@ -115,6 +116,7 @@ SystemTray::SystemTray(internal::StatusAreaWidget* status_area_widget) drive_observer_(NULL), ime_observer_(NULL), locale_observer_(NULL), + logout_button_observer_(NULL), #if defined(OS_CHROMEOS) network_observer_(NULL), vpn_observer_(NULL), @@ -151,6 +153,8 @@ void SystemTray::CreateItems() { internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock; internal::TrayDrive* tray_drive = new internal::TrayDrive; internal::TrayLocale* tray_locale = new internal::TrayLocale; + internal::TrayLogoutButton* tray_logout_button = + new internal::TrayLogoutButton(); internal::TrayUpdate* tray_update = new internal::TrayUpdate; internal::TraySettings* tray_settings = new internal::TraySettings(); @@ -163,6 +167,7 @@ void SystemTray::CreateItems() { drive_observer_ = tray_drive; ime_observer_ = tray_ime; locale_observer_ = tray_locale; + logout_button_observer_ = tray_logout_button; power_status_observers_.AddObserver(tray_power); power_status_observers_.AddObserver(tray_settings); update_observer_ = tray_update; @@ -178,6 +183,7 @@ void SystemTray::CreateItems() { sms_observer_ = tray_sms; #endif + AddTrayItem(tray_logout_button); AddTrayItem(tray_user); AddTrayItem(tray_ime); AddTrayItem(tray_power); diff --git a/ash/system/tray/system_tray.h b/ash/system/tray/system_tray.h index ae6fc04..a42632f 100644 --- a/ash/system/tray/system_tray.h +++ b/ash/system/tray/system_tray.h @@ -32,6 +32,7 @@ class ClockObserver; class DriveObserver; class IMEObserver; class LocaleObserver; +class LogoutButtonObserver; class PowerStatusObserver; class UpdateObserver; class UserObserver; @@ -144,6 +145,9 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, LocaleObserver* locale_observer() { return locale_observer_; } + LogoutButtonObserver* logout_button_observer() { + return logout_button_observer_; + } #if defined(OS_CHROMEOS) NetworkObserver* network_observer() { return network_observer_; @@ -243,6 +247,7 @@ class ASH_EXPORT SystemTray : public internal::TrayBackgroundView, DriveObserver* drive_observer_; IMEObserver* ime_observer_; LocaleObserver* locale_observer_; + LogoutButtonObserver* logout_button_observer_; #if defined(OS_CHROMEOS) NetworkObserver* network_observer_; NetworkObserver* vpn_observer_; |