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 "base/debug/trace_event.h" | |
7 #include "base/string_number_conversions.h" | 8 #include "base/string_number_conversions.h" |
8 #include "base/time.h" | 9 #include "base/time.h" |
9 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 11 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
12 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
14 #include "ui/base/animation/slide_animation.h" | |
13 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
14 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
18 #include "ui/gfx/transform.h" | |
19 #include "ui/gfx/compositor/compositor.h" | |
16 #include "views/controls/menu/menu_item_view.h" | 20 #include "views/controls/menu/menu_item_view.h" |
17 #include "views/controls/menu/submenu_view.h" | 21 #include "views/controls/menu/submenu_view.h" |
18 #include "views/widget/widget.h" | 22 #include "views/widget/widget.h" |
19 | 23 |
20 namespace { | 24 namespace { |
21 | 25 |
22 // Menu item ids. | 26 // Menu item ids. |
23 enum { | 27 enum { |
24 POWER_BATTERY_PERCENTAGE_ITEM = 1000, | 28 POWER_BATTERY_PERCENTAGE_ITEM = 1000, |
25 POWER_BATTERY_IS_CHARGED_ITEM, | 29 POWER_BATTERY_IS_CHARGED_ITEM, |
26 POWER_NO_BATTERY, | 30 POWER_NO_BATTERY, |
27 }; | 31 }; |
28 | 32 |
29 } // namespace | 33 } // namespace |
sadrul
2011/06/29 20:35:10
two spaces between } and //
| |
30 | 34 |
31 namespace chromeos { | 35 namespace chromeos { |
32 | 36 |
33 //////////////////////////////////////////////////////////////////////////////// | 37 //////////////////////////////////////////////////////////////////////////////// |
34 // PowerMenuButton | 38 // PowerMenuButton |
35 | 39 |
36 // static | 40 // static |
37 const int PowerMenuButton::kNumPowerImages = 19; | 41 const int PowerMenuButton::kNumPowerImages = 19; |
38 | 42 |
39 PowerMenuButton::PowerMenuButton(StatusAreaHost* host) | 43 PowerMenuButton::PowerMenuButton(StatusAreaHost* host) |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
119 //////////////////////////////////////////////////////////////////////////////// | 123 //////////////////////////////////////////////////////////////////////////////// |
120 // PowerMenuButton, views::View implementation: | 124 // PowerMenuButton, views::View implementation: |
121 void PowerMenuButton::OnLocaleChanged() { | 125 void PowerMenuButton::OnLocaleChanged() { |
122 UpdateIconAndLabelInfo(); | 126 UpdateIconAndLabelInfo(); |
123 } | 127 } |
124 | 128 |
125 //////////////////////////////////////////////////////////////////////////////// | 129 //////////////////////////////////////////////////////////////////////////////// |
126 // PowerMenuButton, views::ViewMenuDelegate implementation: | 130 // PowerMenuButton, views::ViewMenuDelegate implementation: |
127 | 131 |
128 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { | 132 void PowerMenuButton::RunMenu(views::View* source, const gfx::Point& pt) { |
129 UpdateMenu(); | 133 //UpdateMenu(); |
134 // | |
135 //// TODO(rhashimoto): Remove this workaround when WebUI provides a | |
136 //// top-level widget on the ChromeOS login screen that is a window. | |
137 //// The current BackgroundView class for the ChromeOS login screen | |
138 //// creates a owning Widget that has a native GtkWindow but is not a | |
139 //// Window. This makes it impossible to get the NativeWindow via | |
140 //// the views API. This workaround casts the top-level NativeWidget | |
141 //// to a NativeWindow that we can pass to MenuItemView::RunMenuAt(). | |
142 //gfx::NativeWindow window = GTK_WINDOW(source->GetWidget()->GetNativeView()); | |
143 // | |
144 //gfx::Point screen_loc; | |
145 //views::View::ConvertPointToScreen(source, &screen_loc); | |
146 //gfx::Rect bounds(screen_loc, source->size()); | |
147 //menu_->RunMenuAt( | |
148 // window, | |
149 // this, | |
150 // bounds, | |
151 // views::MenuItemView::TOPRIGHT, | |
152 // true); | |
130 | 153 |
131 // TODO(rhashimoto): Remove this workaround when WebUI provides a | 154 static int i = 0; |
132 // top-level widget on the ChromeOS login screen that is a window. | |
133 // The current BackgroundView class for the ChromeOS login screen | |
134 // creates a owning Widget that has a native GtkWindow but is not a | |
135 // Window. This makes it impossible to get the NativeWindow via | |
136 // the views API. This workaround casts the top-level NativeWidget | |
137 // to a NativeWindow that we can pass to MenuItemView::RunMenuAt(). | |
138 gfx::NativeWindow window = GTK_WINDOW(source->GetWidget()->GetNativeView()); | |
139 | 155 |
140 gfx::Point screen_loc; | 156 sensors::ScreenOrientationChange change; |
141 views::View::ConvertPointToScreen(source, &screen_loc); | 157 switch (i) { |
142 gfx::Rect bounds(screen_loc, source->size()); | 158 case 0: change.upward = sensors::ScreenOrientationChange::LEFT; break; |
143 menu_->RunMenuAt( | 159 case 1: change.upward = sensors::ScreenOrientationChange::BOTTOM; break; |
144 window, | 160 case 2: change.upward = sensors::ScreenOrientationChange::RIGHT; break; |
145 this, | 161 case 3: change.upward = sensors::ScreenOrientationChange::TOP; break; |
146 bounds, | 162 case 4: change.upward = sensors::ScreenOrientationChange::BOTTOM; break; |
147 views::MenuItemView::TOPRIGHT, | 163 case 5: change.upward = sensors::ScreenOrientationChange::TOP; break; |
148 true); | 164 case 6: change.upward = sensors::ScreenOrientationChange::LEFT; break; |
165 case 7: change.upward = sensors::ScreenOrientationChange::RIGHT; break; | |
166 case 8: change.upward = sensors::ScreenOrientationChange::LEFT; break; | |
167 case 9: change.upward = sensors::ScreenOrientationChange::TOP; break; | |
168 case 10: change.upward = sensors::ScreenOrientationChange::RIGHT; break; | |
169 case 11: change.upward = sensors::ScreenOrientationChange::BOTTOM; break; | |
170 case 12: change.upward = sensors::ScreenOrientationChange::LEFT; break; | |
171 case 13: change.upward = sensors::ScreenOrientationChange::TOP; break; | |
172 } | |
173 i = (i + 1) % 14; | |
174 std::string data(reinterpret_cast<const char*>(&change), sizeof(change)); | |
175 | |
176 sensors::Provider::GetInstance()->FireSensorChanged( | |
177 sensors::kScreenOrientationChannel, data); | |
sadrul
2011/06/29 20:35:10
Since we are upstreaming this change, I think it'd
| |
149 } | 178 } |
150 | 179 |
151 //////////////////////////////////////////////////////////////////////////////// | 180 //////////////////////////////////////////////////////////////////////////////// |
152 // PowerMenuButton, PowerLibrary::Observer implementation: | 181 // PowerMenuButton, PowerLibrary::Observer implementation: |
153 | 182 |
154 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { | 183 void PowerMenuButton::PowerChanged(PowerLibrary* obj) { |
155 UpdateIconAndLabelInfo(); | 184 UpdateIconAndLabelInfo(); |
156 } | 185 } |
157 | 186 |
158 //////////////////////////////////////////////////////////////////////////////// | 187 //////////////////////////////////////////////////////////////////////////////// |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 menu_->AppendDelegateMenuItem(POWER_BATTERY_IS_CHARGED_ITEM); | 289 menu_->AppendDelegateMenuItem(POWER_BATTERY_IS_CHARGED_ITEM); |
261 } else { | 290 } else { |
262 menu_->AppendMenuItemWithLabel( | 291 menu_->AppendMenuItemWithLabel( |
263 POWER_NO_BATTERY, | 292 POWER_NO_BATTERY, |
264 UTF16ToWide(l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_BATTERY))); | 293 UTF16ToWide(l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_BATTERY))); |
265 } | 294 } |
266 menu_->ChildrenChanged(); | 295 menu_->ChildrenChanged(); |
267 } | 296 } |
268 | 297 |
269 } // namespace chromeos | 298 } // namespace chromeos |
OLD | NEW |