OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/network_menu.h" | 5 #include "chrome/browser/chromeos/status/network_menu.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/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
11 #include "gfx/canvas_skia.h" | 11 #include "gfx/canvas_skia.h" |
12 #include "gfx/skbitmap_operations.h" | 12 #include "gfx/skbitmap_operations.h" |
13 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
14 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
15 #include "views/window/window.h" | 15 #include "views/window/window.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 //////////////////////////////////////////////////////////////////////////////// | 19 //////////////////////////////////////////////////////////////////////////////// |
20 // NetworkMenu | 20 // NetworkMenu |
21 | 21 |
22 // static | 22 // static |
23 const int NetworkMenu::kNumWifiImages = 9; | 23 const int NetworkMenu::kNumWifiImages = 9; |
24 | 24 |
25 NetworkMenu::NetworkMenu() | 25 NetworkMenu::NetworkMenu() |
26 : ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)) { | 26 : ALLOW_THIS_IN_INITIALIZER_LIST(network_menu_(this)), |
| 27 min_width_(-1) { |
27 } | 28 } |
28 | 29 |
29 NetworkMenu::~NetworkMenu() { | 30 NetworkMenu::~NetworkMenu() { |
30 } | 31 } |
31 | 32 |
32 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
33 // NetworkMenu, menus::MenuModel implementation: | 34 // NetworkMenu, menus::MenuModel implementation: |
34 | 35 |
35 int NetworkMenu::GetItemCount() const { | 36 int NetworkMenu::GetItemCount() const { |
36 return static_cast<int>(menu_items_.size()); | 37 return static_cast<int>(menu_items_.size()); |
(...skipping 123 matching lines...) Loading... |
160 } else { | 161 } else { |
161 // TODO(stevenjb): Connection in progress. Show dialog? | 162 // TODO(stevenjb): Connection in progress. Show dialog? |
162 } | 163 } |
163 } else { | 164 } else { |
164 cros->ConnectToCellularNetwork(cellular); | 165 cros->ConnectToCellularNetwork(cellular); |
165 } | 166 } |
166 } | 167 } |
167 } | 168 } |
168 | 169 |
169 void NetworkMenu::SetFirstLevelMenuWidth(int width) { | 170 void NetworkMenu::SetFirstLevelMenuWidth(int width) { |
| 171 min_width_ = width; |
| 172 // This actually has no effect since menu is rebuilt before showing. |
170 network_menu_.SetMinimumWidth(width); | 173 network_menu_.SetMinimumWidth(width); |
171 } | 174 } |
172 | 175 |
173 void NetworkMenu::CancelMenu() { | 176 void NetworkMenu::CancelMenu() { |
174 network_menu_.CancelMenu(); | 177 network_menu_.CancelMenu(); |
175 } | 178 } |
176 | 179 |
177 // static | 180 // static |
178 SkBitmap NetworkMenu::IconForNetworkStrength(int strength, bool black) { | 181 SkBitmap NetworkMenu::IconForNetworkStrength(int strength, bool black) { |
179 // Compose wifi icon by superimposing various icons. | 182 // Compose wifi icon by superimposing various icons. |
(...skipping 52 matching lines...) Loading... |
232 // NetworkMenu, views::ViewMenuDelegate implementation: | 235 // NetworkMenu, views::ViewMenuDelegate implementation: |
233 | 236 |
234 void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) { | 237 void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) { |
235 refreshing_menu_ = true; | 238 refreshing_menu_ = true; |
236 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 239 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
237 cros->RequestWifiScan(); | 240 cros->RequestWifiScan(); |
238 cros->UpdateSystemInfo(); | 241 cros->UpdateSystemInfo(); |
239 InitMenuItems(); | 242 InitMenuItems(); |
240 network_menu_.Rebuild(); | 243 network_menu_.Rebuild(); |
241 network_menu_.UpdateStates(); | 244 network_menu_.UpdateStates(); |
| 245 // Restore menu width, if it was set up. |
| 246 // NOTE: width isn't checked for correctness here since all width-related |
| 247 // logic implemented inside |network_menu_|. |
| 248 if (min_width_ != -1) |
| 249 network_menu_.SetMinimumWidth(min_width_); |
242 refreshing_menu_ = false; | 250 refreshing_menu_ = false; |
243 network_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 251 network_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); |
244 } | 252 } |
245 | 253 |
246 void NetworkMenu::InitMenuItems() { | 254 void NetworkMenu::InitMenuItems() { |
247 menu_items_.clear(); | 255 menu_items_.clear(); |
248 // Populate our MenuItems with the current list of wifi networks. | 256 // Populate our MenuItems with the current list of wifi networks. |
249 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 257 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
250 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 258 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
251 | 259 |
(...skipping 99 matching lines...) Loading... |
351 if (ShouldOpenButtonOptions()) { | 359 if (ShouldOpenButtonOptions()) { |
352 label = | 360 label = |
353 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); | 361 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_OPEN_OPTIONS_DIALOG); |
354 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, | 362 menu_items_.push_back(MenuItem(menus::MenuModel::TYPE_COMMAND, label, |
355 SkBitmap(), std::string(), FLAG_OPTIONS)); | 363 SkBitmap(), std::string(), FLAG_OPTIONS)); |
356 } | 364 } |
357 } | 365 } |
358 } | 366 } |
359 | 367 |
360 } // namespace chromeos | 368 } // namespace chromeos |
OLD | NEW |