OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/chromeos/settings/tray_settings.h" | 5 #include "ash/system/chromeos/settings/tray_settings.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/chromeos/power/power_status.h" | 8 #include "ash/system/chromeos/power/power_status.h" |
9 #include "ash/system/chromeos/power/power_status_view.h" | 9 #include "ash/system/chromeos/power/power_status_view.h" |
10 #include "ash/system/tray/actionable_view.h" | 10 #include "ash/system/tray/actionable_view.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
24 #include "ui/views/layout/box_layout.h" | 24 #include "ui/views/layout/box_layout.h" |
25 #include "ui/views/layout/fill_layout.h" | 25 #include "ui/views/layout/fill_layout.h" |
26 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
27 | 27 |
28 namespace ash { | 28 namespace ash { |
29 namespace internal { | 29 namespace internal { |
30 | 30 |
31 namespace tray { | 31 namespace tray { |
32 | 32 |
33 class SettingsDefaultView : public ActionableView { | 33 class SettingsDefaultView : public ActionableView, |
| 34 public PowerStatus::Observer { |
34 public: | 35 public: |
35 explicit SettingsDefaultView(user::LoginStatus status) | 36 explicit SettingsDefaultView(user::LoginStatus status) |
36 : login_status_(status), | 37 : login_status_(status), |
37 label_(NULL), | 38 label_(NULL), |
38 power_status_view_(NULL) { | 39 power_status_view_(NULL) { |
| 40 PowerStatus::Get()->AddObserver(this); |
39 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 41 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
40 ash::kTrayPopupPaddingHorizontal, 0, | 42 ash::kTrayPopupPaddingHorizontal, 0, |
41 ash::kTrayPopupPaddingBetweenItems)); | 43 ash::kTrayPopupPaddingBetweenItems)); |
42 | 44 |
43 bool power_view_right_align = false; | 45 bool power_view_right_align = false; |
44 if (login_status_ != user::LOGGED_IN_NONE && | 46 if (login_status_ != user::LOGGED_IN_NONE && |
45 login_status_ != user::LOGGED_IN_LOCKED) { | 47 login_status_ != user::LOGGED_IN_LOCKED) { |
46 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 48 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
47 views::ImageView* icon = | 49 views::ImageView* icon = |
48 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); | 50 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); |
49 icon->SetImage( | 51 icon->SetImage( |
50 rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); | 52 rb.GetImageNamed(IDR_AURA_UBER_TRAY_SETTINGS).ToImageSkia()); |
51 AddChildView(icon); | 53 AddChildView(icon); |
52 | 54 |
53 base::string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS); | 55 base::string16 text = rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_SETTINGS); |
54 label_ = new views::Label(text); | 56 label_ = new views::Label(text); |
55 AddChildView(label_); | 57 AddChildView(label_); |
56 SetAccessibleName(text); | 58 SetAccessibleName(text); |
57 | 59 |
58 power_view_right_align = true; | 60 power_view_right_align = true; |
59 } | 61 } |
60 | 62 |
61 chromeos::PowerSupplyStatus power_status = | 63 if (PowerStatus::Get()->IsBatteryPresent()) { |
62 PowerStatus::Get()->GetPowerSupplyStatus(); | |
63 if (power_status.battery_is_present) { | |
64 power_status_view_ = new ash::internal::PowerStatusView( | 64 power_status_view_ = new ash::internal::PowerStatusView( |
65 ash::internal::PowerStatusView::VIEW_DEFAULT, power_view_right_align); | 65 ash::internal::PowerStatusView::VIEW_DEFAULT, power_view_right_align); |
66 AddChildView(power_status_view_); | 66 AddChildView(power_status_view_); |
67 UpdatePowerStatus(power_status); | 67 OnPowerStatusChanged(); |
68 } | 68 } |
69 } | 69 } |
70 | 70 |
71 virtual ~SettingsDefaultView() {} | 71 virtual ~SettingsDefaultView() { |
72 | 72 PowerStatus::Get()->RemoveObserver(this); |
73 void UpdatePowerStatus(const chromeos::PowerSupplyStatus& status) { | |
74 if (!power_status_view_) | |
75 return; | |
76 power_status_view_->UpdatePowerStatus(status); | |
77 base::string16 accessible_name = label_ ? | |
78 label_->text() + ASCIIToUTF16(", ") + | |
79 power_status_view_->accessible_name() : | |
80 power_status_view_->accessible_name(); | |
81 SetAccessibleName(accessible_name); | |
82 } | 73 } |
83 | 74 |
84 // Overridden from ash::internal::ActionableView. | 75 // Overridden from ash::internal::ActionableView. |
85 virtual bool PerformAction(const ui::Event& event) OVERRIDE { | 76 virtual bool PerformAction(const ui::Event& event) OVERRIDE { |
86 if (login_status_ == user::LOGGED_IN_NONE || | 77 if (login_status_ == user::LOGGED_IN_NONE || |
87 login_status_ == user::LOGGED_IN_LOCKED) | 78 login_status_ == user::LOGGED_IN_LOCKED) |
88 return false; | 79 return false; |
89 | 80 |
90 ash::Shell::GetInstance()->system_tray_delegate()->ShowSettings(); | 81 ash::Shell::GetInstance()->system_tray_delegate()->ShowSettings(); |
91 return true; | 82 return true; |
(...skipping 13 matching lines...) Expand all Loading... |
105 power_status_view_->SetBoundsRect(bounds); | 96 power_status_view_->SetBoundsRect(bounds); |
106 } | 97 } |
107 } | 98 } |
108 | 99 |
109 // Overridden from views::View. | 100 // Overridden from views::View. |
110 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { | 101 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { |
111 views::View::ChildPreferredSizeChanged(child); | 102 views::View::ChildPreferredSizeChanged(child); |
112 Layout(); | 103 Layout(); |
113 } | 104 } |
114 | 105 |
| 106 // Overridden from PowerStatus::Observer. |
| 107 virtual void OnPowerStatusChanged() OVERRIDE { |
| 108 if (!PowerStatus::Get()->IsBatteryPresent()) |
| 109 return; |
| 110 |
| 111 base::string16 accessible_name = label_ ? |
| 112 label_->text() + ASCIIToUTF16(", ") + |
| 113 PowerStatus::Get()->GetAccessibleNameString() : |
| 114 PowerStatus::Get()->GetAccessibleNameString(); |
| 115 SetAccessibleName(accessible_name); |
| 116 } |
| 117 |
115 private: | 118 private: |
116 user::LoginStatus login_status_; | 119 user::LoginStatus login_status_; |
117 views::Label* label_; | 120 views::Label* label_; |
118 ash::internal::PowerStatusView* power_status_view_; | 121 ash::internal::PowerStatusView* power_status_view_; |
119 | 122 |
120 DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView); | 123 DISALLOW_COPY_AND_ASSIGN(SettingsDefaultView); |
121 }; | 124 }; |
122 | 125 |
123 } // namespace tray | 126 } // namespace tray |
124 | 127 |
125 TraySettings::TraySettings(SystemTray* system_tray) | 128 TraySettings::TraySettings(SystemTray* system_tray) |
126 : SystemTrayItem(system_tray), | 129 : SystemTrayItem(system_tray), |
127 default_view_(NULL) { | 130 default_view_(NULL) { |
128 PowerStatus::Get()->AddObserver(this); | |
129 } | 131 } |
130 | 132 |
131 TraySettings::~TraySettings() { | 133 TraySettings::~TraySettings() { |
132 PowerStatus::Get()->RemoveObserver(this); | |
133 } | 134 } |
134 | 135 |
135 views::View* TraySettings::CreateTrayView(user::LoginStatus status) { | 136 views::View* TraySettings::CreateTrayView(user::LoginStatus status) { |
136 return NULL; | 137 return NULL; |
137 } | 138 } |
138 | 139 |
139 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) { | 140 views::View* TraySettings::CreateDefaultView(user::LoginStatus status) { |
140 if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) && | 141 if ((status == user::LOGGED_IN_NONE || status == user::LOGGED_IN_LOCKED) && |
141 !PowerStatus::Get()->GetPowerSupplyStatus().battery_is_present) | 142 !PowerStatus::Get()->IsBatteryPresent()) |
142 return NULL; | 143 return NULL; |
143 | 144 |
144 CHECK(default_view_ == NULL); | 145 CHECK(default_view_ == NULL); |
145 default_view_ = new tray::SettingsDefaultView(status); | 146 default_view_ = new tray::SettingsDefaultView(status); |
146 return default_view_; | 147 return default_view_; |
147 } | 148 } |
148 | 149 |
149 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) { | 150 views::View* TraySettings::CreateDetailedView(user::LoginStatus status) { |
150 NOTIMPLEMENTED(); | 151 NOTIMPLEMENTED(); |
151 return NULL; | 152 return NULL; |
152 } | 153 } |
153 | 154 |
154 void TraySettings::DestroyTrayView() { | 155 void TraySettings::DestroyTrayView() { |
155 } | 156 } |
156 | 157 |
157 void TraySettings::DestroyDefaultView() { | 158 void TraySettings::DestroyDefaultView() { |
158 default_view_ = NULL; | 159 default_view_ = NULL; |
159 } | 160 } |
160 | 161 |
161 void TraySettings::DestroyDetailedView() { | 162 void TraySettings::DestroyDetailedView() { |
162 } | 163 } |
163 | 164 |
164 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 165 void TraySettings::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
165 } | 166 } |
166 | 167 |
167 void TraySettings::OnPowerStatusChanged( | |
168 const chromeos::PowerSupplyStatus& status) { | |
169 if (default_view_) | |
170 default_view_->UpdatePowerStatus(status); | |
171 } | |
172 | |
173 } // namespace internal | 168 } // namespace internal |
174 } // namespace ash | 169 } // namespace ash |
OLD | NEW |