| 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 "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 20 #include "ui/gfx/canvas_skia.h" | 20 #include "ui/gfx/canvas_skia.h" |
| 21 #include "ui/gfx/font.h" | 21 #include "ui/gfx/font.h" |
| 22 #include "views/controls/menu/menu_item_view.h" | 22 #include "views/controls/menu/menu_item_view.h" |
| 23 #include "views/controls/menu/menu_runner.h" | 23 #include "views/controls/menu/menu_runner.h" |
| 24 #include "views/controls/menu/submenu_view.h" | 24 #include "views/controls/menu/submenu_view.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 PowerMenuButton::PowerMenuButton(StatusAreaHost* host) | 247 PowerMenuButton::PowerMenuButton(StatusAreaHost* host) |
| 248 : StatusAreaButton(host, this), | 248 : StatusAreaButton(host, this), |
| 249 battery_is_present_(false), | 249 battery_is_present_(false), |
| 250 line_power_on_(false), | 250 line_power_on_(false), |
| 251 battery_percentage_(0.0), | 251 battery_percentage_(0.0), |
| 252 battery_index_(-1), | 252 battery_index_(-1), |
| 253 battery_time_to_full_(TimeDelta::FromMicroseconds(kInitialMS)), | 253 battery_time_to_full_(TimeDelta::FromMicroseconds(kInitialMS)), |
| 254 battery_time_to_empty_(TimeDelta::FromMicroseconds(kInitialMS)), | 254 battery_time_to_empty_(TimeDelta::FromMicroseconds(kInitialMS)), |
| 255 status_(NULL) { | 255 status_(NULL) { |
| 256 UpdateIconAndLabelInfo(); | 256 UpdateIconAndLabelInfo(); |
| 257 CrosLibrary::Get()->GetPowerLibrary()->AddObserver(this); | 257 DBusThreadManager::Get()->power_manager_client()->AddObserver(this); |
| 258 } | 258 } |
| 259 | 259 |
| 260 PowerMenuButton::~PowerMenuButton() { | 260 PowerMenuButton::~PowerMenuButton() { |
| 261 CrosLibrary::Get()->GetPowerLibrary()->RemoveObserver(this); | 261 DBusThreadManager::Get()->power_manager_client()->RemoveObserver(this); |
| 262 } | 262 } |
| 263 | 263 |
| 264 // PowerMenuButton, views::MenuDelegate implementation: | 264 // PowerMenuButton, views::MenuDelegate implementation: |
| 265 | 265 |
| 266 string16 PowerMenuButton::GetLabel(int id) const { | 266 string16 PowerMenuButton::GetLabel(int id) const { |
| 267 return string16(); | 267 return string16(); |
| 268 } | 268 } |
| 269 | 269 |
| 270 bool PowerMenuButton::IsCommandEnabled(int id) const { | 270 bool PowerMenuButton::IsCommandEnabled(int id) const { |
| 271 return false; | 271 return false; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 // PowerMenuButton, views::View implementation: | 312 // PowerMenuButton, views::View implementation: |
| 313 void PowerMenuButton::OnLocaleChanged() { | 313 void PowerMenuButton::OnLocaleChanged() { |
| 314 UpdateIconAndLabelInfo(); | 314 UpdateIconAndLabelInfo(); |
| 315 } | 315 } |
| 316 | 316 |
| 317 //////////////////////////////////////////////////////////////////////////////// | 317 //////////////////////////////////////////////////////////////////////////////// |
| 318 // PowerMenuButton, views::ViewMenuDelegate implementation: | 318 // PowerMenuButton, views::ViewMenuDelegate implementation: |
| 319 | 319 |
| 320 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 320 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
| 321 // Explicitly query the power status. | 321 // Explicitly query the power status. |
| 322 CrosLibrary::Get()->GetPowerLibrary()->RequestStatusUpdate(); | 322 DBusThreadManager::Get()->power_manager_client()->RequestStatusUpdate(); |
| 323 | 323 |
| 324 views::MenuItemView* menu = new views::MenuItemView(this); | 324 views::MenuItemView* menu = new views::MenuItemView(this); |
| 325 // MenuRunner takes ownership of |menu|. | 325 // MenuRunner takes ownership of |menu|. |
| 326 menu_runner_.reset(new views::MenuRunner(menu)); | 326 menu_runner_.reset(new views::MenuRunner(menu)); |
| 327 views::MenuItemView* submenu = menu->AppendMenuItem( | 327 views::MenuItemView* submenu = menu->AppendMenuItem( |
| 328 POWER_BATTERY_PERCENTAGE_ITEM, | 328 POWER_BATTERY_PERCENTAGE_ITEM, |
| 329 string16(), | 329 string16(), |
| 330 views::MenuItemView::NORMAL); | 330 views::MenuItemView::NORMAL); |
| 331 status_ = new StatusView(this); | 331 status_ = new StatusView(this); |
| 332 submenu->AddChildView(status_); | 332 submenu->AddChildView(status_); |
| 333 menu->CreateSubmenu()->set_resize_open_menu(true); | 333 menu->CreateSubmenu()->set_resize_open_menu(true); |
| 334 menu->SetMargins(0, 0); | 334 menu->SetMargins(0, 0); |
| 335 submenu->SetMargins(0, 0); | 335 submenu->SetMargins(0, 0); |
| 336 menu->ChildrenChanged(); | 336 menu->ChildrenChanged(); |
| 337 | 337 |
| 338 gfx::Point screen_location; | 338 gfx::Point screen_location; |
| 339 views::View::ConvertPointToScreen(source, &screen_location); | 339 views::View::ConvertPointToScreen(source, &screen_location); |
| 340 gfx::Rect bounds(screen_location, source->size()); | 340 gfx::Rect bounds(screen_location, source->size()); |
| 341 if (menu_runner_->RunMenuAt( | 341 if (menu_runner_->RunMenuAt( |
| 342 source->GetWidget()->GetTopLevelWidget(), this, bounds, | 342 source->GetWidget()->GetTopLevelWidget(), this, bounds, |
| 343 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == | 343 views::MenuItemView::TOPRIGHT, views::MenuRunner::HAS_MNEMONICS) == |
| 344 views::MenuRunner::MENU_DELETED) | 344 views::MenuRunner::MENU_DELETED) |
| 345 return; | 345 return; |
| 346 status_ = NULL; | 346 status_ = NULL; |
| 347 menu_runner_.reset(NULL); | 347 menu_runner_.reset(NULL); |
| 348 } | 348 } |
| 349 | 349 |
| 350 //////////////////////////////////////////////////////////////////////////////// | 350 //////////////////////////////////////////////////////////////////////////////// |
| 351 // PowerMenuButton, PowerLibrary::Observer implementation: | 351 // PowerMenuButton, PowerManagerClient::Observer implementation: |
| 352 | 352 |
| 353 void PowerMenuButton::PowerChanged(const PowerSupplyStatus& power_status) { | 353 void PowerMenuButton::PowerChanged(const PowerSupplyStatus& power_status) { |
| 354 power_status_ = power_status; | 354 power_status_ = power_status; |
| 355 UpdateIconAndLabelInfo(); | 355 UpdateIconAndLabelInfo(); |
| 356 } | 356 } |
| 357 | 357 |
| 358 //////////////////////////////////////////////////////////////////////////////// | 358 //////////////////////////////////////////////////////////////////////////////// |
| 359 // PowerMenuButton, StatusAreaButton implementation: | 359 // PowerMenuButton, StatusAreaButton implementation: |
| 360 | 360 |
| 361 void PowerMenuButton::UpdateIconAndLabelInfo() { | 361 void PowerMenuButton::UpdateIconAndLabelInfo() { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 // If previous is 0, then it either was never set (initial condition) | 415 // If previous is 0, then it either was never set (initial condition) |
| 416 // or got down to 0. | 416 // or got down to 0. |
| 417 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || | 417 if (*previous == TimeDelta::FromMicroseconds(kInitialMS) || |
| 418 diff < kMinDiff || | 418 diff < kMinDiff || |
| 419 diff > kMaxDiff) { | 419 diff > kMaxDiff) { |
| 420 *previous = current; | 420 *previous = current; |
| 421 } | 421 } |
| 422 } | 422 } |
| 423 | 423 |
| 424 } // namespace chromeos | 424 } // namespace chromeos |
| OLD | NEW |