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

Side by Side Diff: chrome/browser/chromeos/power_menu_button.cc

Issue 341044: Move chromeos code to namespace chromeos. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/power_menu_button.h" 5 #include "chrome/browser/chromeos/power_menu_button.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "grit/generated_resources.h" 10 #include "grit/generated_resources.h"
11 #include "grit/theme_resources.h" 11 #include "grit/theme_resources.h"
12 12
13 namespace chromeos {
14
13 //////////////////////////////////////////////////////////////////////////////// 15 ////////////////////////////////////////////////////////////////////////////////
14 // PowerMenuButton 16 // PowerMenuButton
15 17
16 // static 18 // static
17 const int PowerMenuButton::kNumPowerImages = 16; 19 const int PowerMenuButton::kNumPowerImages = 16;
18 20
19 PowerMenuButton::PowerMenuButton() 21 PowerMenuButton::PowerMenuButton()
20 : StatusAreaButton(this), 22 : StatusAreaButton(this),
21 ALLOW_THIS_IN_INITIALIZER_LIST(power_menu_(this)) { 23 ALLOW_THIS_IN_INITIALIZER_LIST(power_menu_(this)) {
22 UpdateIcon(); 24 UpdateIcon();
23 CrosPowerLibrary::Get()->AddObserver(this); 25 PowerLibrary::Get()->AddObserver(this);
24 } 26 }
25 27
26 PowerMenuButton::~PowerMenuButton() { 28 PowerMenuButton::~PowerMenuButton() {
27 CrosPowerLibrary::Get()->RemoveObserver(this); 29 PowerLibrary::Get()->RemoveObserver(this);
28 } 30 }
29 31
30 //////////////////////////////////////////////////////////////////////////////// 32 ////////////////////////////////////////////////////////////////////////////////
31 // PowerMenuButton, views::Menu2Model implementation: 33 // PowerMenuButton, views::Menu2Model implementation:
32 34
33 int PowerMenuButton::GetItemCount() const { 35 int PowerMenuButton::GetItemCount() const {
34 return 2; 36 return 2;
35 } 37 }
36 38
37 views::Menu2Model::ItemType PowerMenuButton::GetTypeAt(int index) const { 39 views::Menu2Model::ItemType PowerMenuButton::GetTypeAt(int index) const {
38 return views::Menu2Model::TYPE_COMMAND; 40 return views::Menu2Model::TYPE_COMMAND;
39 } 41 }
40 42
41 string16 PowerMenuButton::GetLabelAt(int index) const { 43 string16 PowerMenuButton::GetLabelAt(int index) const {
42 CrosPowerLibrary* cros = CrosPowerLibrary::Get(); 44 PowerLibrary* cros = PowerLibrary::Get();
43 // The first item shows the percentage of battery left. 45 // The first item shows the percentage of battery left.
44 if (index == 0) { 46 if (index == 0) {
45 // If fully charged, always show 100% even if internal number is a bit less. 47 // If fully charged, always show 100% even if internal number is a bit less.
46 double percent = cros->battery_fully_charged() ? 100 : 48 double percent = cros->battery_fully_charged() ? 100 :
47 cros->battery_percentage(); 49 cros->battery_percentage();
48 return l10n_util::GetStringFUTF16(IDS_STATUSBAR_BATTERY_PERCENTAGE, 50 return l10n_util::GetStringFUTF16(IDS_STATUSBAR_BATTERY_PERCENTAGE,
49 IntToString16(static_cast<int>(percent))); 51 IntToString16(static_cast<int>(percent)));
50 } 52 }
51 53
52 // The second item shows the battery is charged if it is. 54 // The second item shows the battery is charged if it is.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 //////////////////////////////////////////////////////////////////////////////// 86 ////////////////////////////////////////////////////////////////////////////////
85 // PowerMenuButton, views::ViewMenuDelegate implementation: 87 // PowerMenuButton, views::ViewMenuDelegate implementation:
86 88
87 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { 89 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) {
88 power_menu_.Rebuild(); 90 power_menu_.Rebuild();
89 power_menu_.UpdateStates(); 91 power_menu_.UpdateStates();
90 power_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); 92 power_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
91 } 93 }
92 94
93 //////////////////////////////////////////////////////////////////////////////// 95 ////////////////////////////////////////////////////////////////////////////////
94 // PowerMenuButton, CrosPowerLibrary::Observer implementation: 96 // PowerMenuButton, PowerLibrary::Observer implementation:
95 97
96 void PowerMenuButton::PowerChanged(CrosPowerLibrary* obj) { 98 void PowerMenuButton::PowerChanged(PowerLibrary* obj) {
97 UpdateIcon(); 99 UpdateIcon();
98 } 100 }
99 101
100 void PowerMenuButton::UpdateIcon() { 102 void PowerMenuButton::UpdateIcon() {
101 CrosPowerLibrary* cros = CrosPowerLibrary::Get(); 103 PowerLibrary* cros = PowerLibrary::Get();
102 int id = IDR_STATUSBAR_BATTERY_UNKNOWN; 104 int id = IDR_STATUSBAR_BATTERY_UNKNOWN;
103 if (CrosPowerLibrary::loaded()) { 105 if (PowerLibrary::loaded()) {
104 if (!cros->battery_is_present()) { 106 if (!cros->battery_is_present()) {
105 id = IDR_STATUSBAR_BATTERY_MISSING; 107 id = IDR_STATUSBAR_BATTERY_MISSING;
106 } else if (cros->line_power_on() && cros->battery_fully_charged()) { 108 } else if (cros->line_power_on() && cros->battery_fully_charged()) {
107 id = IDR_STATUSBAR_BATTERY_CHARGED; 109 id = IDR_STATUSBAR_BATTERY_CHARGED;
108 } else { 110 } else {
109 // If fully charged, always show 100% even if percentage is a bit less. 111 // If fully charged, always show 100% even if percentage is a bit less.
110 double percent = cros->battery_fully_charged() ? 100 : 112 double percent = cros->battery_fully_charged() ? 100 :
111 cros->battery_percentage(); 113 cros->battery_percentage();
112 // Gets the power image depending on battery percentage. Percentage is 114 // Gets the power image depending on battery percentage. Percentage is
113 // from 0 to 100, so we need to convert that to 0 to kNumPowerImages - 1. 115 // from 0 to 100, so we need to convert that to 0 to kNumPowerImages - 1.
114 int index = static_cast<int>(percent / 100.0 * 116 int index = static_cast<int>(percent / 100.0 *
115 nextafter(static_cast<float>(kNumPowerImages), 0)); 117 nextafter(static_cast<float>(kNumPowerImages), 0));
116 // Make sure that index is between 0 and kNumWifiImages - 1 118 // Make sure that index is between 0 and kNumWifiImages - 1
117 if (index < 0) 119 if (index < 0)
118 index = 0; 120 index = 0;
119 if (index >= kNumPowerImages) 121 if (index >= kNumPowerImages)
120 index = kNumPowerImages - 1; 122 index = kNumPowerImages - 1;
121 if (cros->line_power_on()) 123 if (cros->line_power_on())
122 id = IDR_STATUSBAR_BATTERY_CHARGING_1 + index; 124 id = IDR_STATUSBAR_BATTERY_CHARGING_1 + index;
123 else 125 else
124 id = IDR_STATUSBAR_BATTERY_DISCHARGING_1 + index; 126 id = IDR_STATUSBAR_BATTERY_DISCHARGING_1 + index;
125 } 127 }
126 } 128 }
127 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(id)); 129 SetIcon(*ResourceBundle::GetSharedInstance().GetBitmapNamed(id));
128 SchedulePaint(); 130 SchedulePaint();
129 } 131 }
132
133 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698