OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/status/power_menu_button.h" | 5 #include "chrome/browser/chromeos/status/power_menu_button.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/dbus/dbus_thread_manager.h" |
15 #include "chrome/browser/chromeos/status/status_area_bubble.h" | 15 #include "chrome/browser/chromeos/status/status_area_bubble.h" |
16 #include "chrome/browser/chromeos/view_ids.h" | 16 #include "chrome/browser/chromeos/view_ids.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
22 #include "ui/gfx/canvas_skia.h" | 22 #include "ui/gfx/canvas_skia.h" |
23 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
24 #include "ui/gfx/image/image.h" | 24 #include "ui/gfx/image/image.h" |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 PowerMenuButton::PowerMenuButton(StatusAreaButton::Delegate* delegate) | 209 PowerMenuButton::PowerMenuButton(StatusAreaButton::Delegate* delegate) |
210 : StatusAreaButton(delegate, this), | 210 : StatusAreaButton(delegate, this), |
211 battery_is_present_(false), | 211 battery_is_present_(false), |
212 line_power_on_(false), | 212 line_power_on_(false), |
213 battery_percentage_(0.0), | 213 battery_percentage_(0.0), |
214 battery_time_to_full_(TimeDelta::FromMicroseconds(kInitialMS)), | 214 battery_time_to_full_(TimeDelta::FromMicroseconds(kInitialMS)), |
215 battery_time_to_empty_(TimeDelta::FromMicroseconds(kInitialMS)), | 215 battery_time_to_empty_(TimeDelta::FromMicroseconds(kInitialMS)), |
216 status_(NULL) { | 216 status_(NULL) { |
217 set_id(VIEW_ID_STATUS_BUTTON_POWER); | 217 set_id(VIEW_ID_STATUS_BUTTON_POWER); |
218 UpdateIconAndLabelInfo(); | 218 UpdateIconAndLabelInfo(); |
219 CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this); | 219 DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(this); |
220 } | 220 } |
221 | 221 |
222 PowerMenuButton::~PowerMenuButton() { | 222 PowerMenuButton::~PowerMenuButton() { |
223 CrosLibrary::Get()->GetPowerLibrary()->RemoveObserver(this); | 223 DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(this); |
224 } | 224 } |
225 | 225 |
226 // PowerMenuButton, views::MenuDelegate implementation: | 226 // PowerMenuButton, views::MenuDelegate implementation: |
227 | 227 |
228 string16 PowerMenuButton::GetLabel(int id) const { | 228 string16 PowerMenuButton::GetLabel(int id) const { |
229 return string16(); | 229 return string16(); |
230 } | 230 } |
231 | 231 |
232 string16 PowerMenuButton::GetBatteryIsChargedText() const { | 232 string16 PowerMenuButton::GetBatteryIsChargedText() const { |
233 // The second item shows the battery is charged if it is. | 233 // The second item shows the battery is charged if it is. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 // PowerMenuButton, views::View implementation: | 270 // PowerMenuButton, views::View implementation: |
271 void PowerMenuButton::OnLocaleChanged() { | 271 void PowerMenuButton::OnLocaleChanged() { |
272 UpdateIconAndLabelInfo(); | 272 UpdateIconAndLabelInfo(); |
273 } | 273 } |
274 | 274 |
275 //////////////////////////////////////////////////////////////////////////////// | 275 //////////////////////////////////////////////////////////////////////////////// |
276 // PowerMenuButton, views::ViewMenuDelegate implementation: | 276 // PowerMenuButton, views::ViewMenuDelegate implementation: |
277 | 277 |
278 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 278 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
279 // Explicitly query the power status. | 279 // Explicitly query the power status. |
280 CrosLibrary::Get()->GetPowerLibrary()->RequestStatusUpdate(); | 280 DBusThreadManager::Get()->GetPowerManagerClient()->RequestStatusUpdate(); |
281 | 281 |
282 views::MenuItemView* menu = new views::MenuItemView(this); | 282 views::MenuItemView* menu = new views::MenuItemView(this); |
283 // MenuRunner takes ownership of |menu|. | 283 // MenuRunner takes ownership of |menu|. |
284 menu_runner_.reset(new views::MenuRunner(menu)); | 284 menu_runner_.reset(new views::MenuRunner(menu)); |
285 views::MenuItemView* submenu = menu->AppendMenuItem( | 285 views::MenuItemView* submenu = menu->AppendMenuItem( |
286 POWER_BATTERY_PERCENTAGE_ITEM, | 286 POWER_BATTERY_PERCENTAGE_ITEM, |
287 string16(), | 287 string16(), |
288 views::MenuItemView::NORMAL); | 288 views::MenuItemView::NORMAL); |
289 status_ = new StatusAreaBubbleContentView(new BatteryIconView, string16()); | 289 status_ = new StatusAreaBubbleContentView(new BatteryIconView, string16()); |
290 UpdateStatusView(); | 290 UpdateStatusView(); |
291 submenu->AddChildView(status_); | 291 submenu->AddChildView(status_); |
292 menu->CreateSubmenu()->set_resize_open_menu(true); | 292 menu->CreateSubmenu()->set_resize_open_menu(true); |
293 menu->SetMargins(0, 0); | 293 menu->SetMargins(0, 0); |
294 submenu->SetMargins(0, 0); | 294 submenu->SetMargins(0, 0); |
295 menu->ChildrenChanged(); | 295 menu->ChildrenChanged(); |
296 | 296 |
297 gfx::Point screen_location; | 297 gfx::Point screen_location; |
298 views::View::ConvertPointToScreen(source, &screen_location); | 298 views::View::ConvertPointToScreen(source, &screen_location); |
299 gfx::Rect bounds(screen_location, source->size()); | 299 gfx::Rect bounds(screen_location, source->size()); |
300 if (menu_runner_->RunMenuAt( | 300 if (menu_runner_->RunMenuAt( |
301 source->GetWidget()->GetTopLevelWidget(), this, bounds, | 301 source->GetWidget()->GetTopLevelWidget(), this, bounds, |
302 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | 302 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
303 views::MenuRunner::MENU_DELETED) | 303 views::MenuRunner::MENU_DELETED) |
304 return; | 304 return; |
305 status_ = NULL; | 305 status_ = NULL; |
306 menu_runner_.reset(NULL); | 306 menu_runner_.reset(NULL); |
307 } | 307 } |
308 | 308 |
309 //////////////////////////////////////////////////////////////////////////////// | 309 //////////////////////////////////////////////////////////////////////////////// |
310 // PowerMenuButton, PowerLibrary::Observer implementation: | 310 // PowerMenuButton, PowerManagerClient::Observer implementation: |
311 | 311 |
312 void PowerMenuButton::PowerChanged(const PowerSupplyStatus& power_status) { | 312 void PowerMenuButton::PowerChanged(const PowerSupplyStatus& power_status) { |
313 power_status_ = power_status; | 313 power_status_ = power_status; |
314 UpdateIconAndLabelInfo(); | 314 UpdateIconAndLabelInfo(); |
315 } | 315 } |
316 | 316 |
317 //////////////////////////////////////////////////////////////////////////////// | 317 //////////////////////////////////////////////////////////////////////////////// |
318 // PowerMenuButton, StatusAreaButton implementation: | 318 // PowerMenuButton, StatusAreaButton implementation: |
319 | 319 |
320 void PowerMenuButton::UpdateIconAndLabelInfo() { | 320 void PowerMenuButton::UpdateIconAndLabelInfo() { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 // If previous is 0, then it either was never set (initial condition) | 379 // If previous is 0, then it either was never set (initial condition) |
380 // or got down to 0. | 380 // or got down to 0. |
381 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || | 381 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || |
382 diff < kMinDiff || | 382 diff < kMinDiff || |
383 diff > kMaxDiff) { | 383 diff > kMaxDiff) { |
384 *previous = current; | 384 *previous = current; |
385 } | 385 } |
386 } | 386 } |
387 | 387 |
388 } // namespace chromeos | 388 } // namespace chromeos |
OLD | NEW |