Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2170)

Unified Diff: ash/system/settings/tray_settings.cc

Issue 10540041: Add battery status to settings row in uber tray bubble. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/settings/tray_settings.cc
diff --git a/ash/system/settings/tray_settings.cc b/ash/system/settings/tray_settings.cc
index fee44ece1ff34383883497f91a5b4ac9a46858d0..d78634fe2ce33d0b7ebb83f0dd092dff53ae72b4 100644
--- a/ash/system/settings/tray_settings.cc
+++ b/ash/system/settings/tray_settings.cc
@@ -5,6 +5,7 @@
#include "ash/system/settings/tray_settings.h"
#include "ash/shell.h"
+#include "ash/system/power/power_status_view.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_views.h"
@@ -22,30 +23,44 @@
#include "ui/views/layout/fill_layout.h"
#include "ui/views/view.h"
-namespace {
+namespace ash {
+namespace internal {
+
+namespace tray {
-class SettingsView : public ash::internal::ActionableView {
+class SettingsDefaultView : public ash::internal::ActionableView {
public:
- SettingsView() {
+ explicit SettingsDefaultView(user::LoginStatus status)
+ : power_status_view_(NULL) {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
ash::kTrayPopupPaddingHorizontal, 0,
ash::kTrayPopupPaddingBetweenItems));
- ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
- views::ImageView* icon =
- new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight);
- icon->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia());
- AddChildView(icon);
-
- string16 text = rb.GetLocalizedString(
- IDS_ASH_STATUS_TRAY_SETTINGS);
- label_ = new views::Label(text);
- AddChildView(label_);
-
- SetAccessibleName(text);
+ if (status != user::LOGGED_IN_NONE && status != user::LOGGED_IN_LOCKED) {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ views::ImageView* icon =
+ new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight);
+ icon->SetImage(
+ rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia());
+ AddChildView(icon);
+
+ string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS);
+ label_ = new views::Label(text);
+ AddChildView(label_);
+ SetAccessibleName(text);
+ }
+
+ PowerSupplyStatus power_status =
+ ash::Shell::GetInstance()->tray_delegate()->GetPowerSupplyStatus();
+ if (power_status.battery_is_present) {
+ power_status_view_ = new ash::internal::tray::PowerStatusView(
+ ash::internal::tray::PowerStatusView::VIEW_DEFAULT);
+ AddChildView(power_status_view_);
+ power_status_view_->UpdatePowerStatus(power_status);
stevenjb 2012/06/07 01:31:18 nit: Put this into UpdatePowerStatus()? (See comme
jennyz 2012/06/07 22:06:52 Done.
+ }
}
- virtual ~SettingsView() {}
+ virtual ~SettingsDefaultView() {}
// Overridden from ash::internal::ActionableView.
virtual bool PerformAction(const views::Event& event) OVERRIDE {
@@ -53,18 +68,43 @@ class SettingsView : public ash::internal::ActionableView {
return true;
}
+ // Overridden from views::View.
+ virtual void Layout() OVERRIDE {
+ // Let the box-layout do the layout first. Then move power_status_view_
+ // to right align if it is created.
+ views::View::Layout();
+
+ if (power_status_view_) {
+ gfx::Size size = power_status_view_->GetPreferredSize();
+ gfx::Rect bounds(size);
+ bounds.set_x(width() - size.width() - ash::kTrayPopupPaddingBetweenItems);
+ bounds.set_y((height() - size.height()) / 2);
+ power_status_view_->SetBoundsRect(bounds);
+ }
+ }
+
+ // Overridden from views::View.
+ virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE {
+ views::View::ChildPreferredSizeChanged(child);
+ Layout();
+ }
+
+ ash::internal::tray::PowerStatusView* power_status_view() {
+ return power_status_view_;
+ }
+
private:
views::Label* label_;
+ ash::internal::tray::PowerStatusView* power_status_view_;
- DISALLOW_COPY_AND_ASSIGN(SettingsView);
-};
+ DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView);
+ };
-} // namespace
-
-namespace ash {
-namespace internal {
+} // namespace tray
-TraySettings::TraySettings() {}
+TraySettings::TraySettings()
+ : default_(NULL) {
+}
TraySettings::~TraySettings() {}
@@ -73,10 +113,14 @@ views::View* TraySettings::CreateTrayView(user::LoginStatus status) {
}
views::View* TraySettings::CreateDefaultView(user::LoginStatus status) {
- if (status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED)
+ if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) &&
+ (!ash::Shell::GetInstance()->tray_delegate()->
+ GetPowerSupplyStatus().battery_is_present))
return NULL;
- return new SettingsView;
+ CHECK(default_ == NULL);
+ default_ = new tray::SettingsDefaultView(status);
+ return default_;
}
views::View* TraySettings::CreateDetailedView(user::LoginStatus status) {
@@ -88,6 +132,7 @@ void TraySettings::DestroyTrayView() {
}
void TraySettings::DestroyDefaultView() {
+ default_ = NULL;
}
void TraySettings::DestroyDetailedView() {
@@ -96,5 +141,11 @@ void TraySettings::DestroyDetailedView() {
void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) {
}
+// Overridden from PowerStatusObserver.
+void TraySettings::OnPowerStatusChanged(const PowerSupplyStatus& status) {
+ if (default_ && default_->power_status_view())
+ default_->power_status_view()->UpdatePowerStatus(status);
stevenjb 2012/06/07 01:31:18 nit: Make UpdatePowerStatus() a member of PowerSta
jennyz 2012/06/07 22:06:52 Done, you mean make UpdatePowerStatus() a member o
+}
+
} // namespace internal
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698