Chromium Code Reviews| 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/network_menu.h" | 5 #include "chrome/browser/chromeos/status/network_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" | 13 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" |
| 14 #include "chrome/browser/chromeos/cros/cros_library.h" | 14 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 15 #include "chrome/browser/chromeos/customization_document.h" | 15 #include "chrome/browser/chromeos/customization_document.h" |
| 16 #include "chrome/browser/chromeos/sim_dialog_delegate.h" | 16 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
| 17 #include "chrome/browser/ui/browser.h" | 17 #include "chrome/browser/ui/browser.h" |
| 18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
| 19 #include "chrome/browser/ui/views/window.h" | 19 #include "chrome/browser/ui/views/window.h" |
| 20 #include "chrome/common/url_constants.h" | 20 #include "chrome/common/url_constants.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "content/browser/browser_thread.h" | |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
| 24 #include "net/base/escape.h" | 25 #include "net/base/escape.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 #include "ui/base/resource/resource_bundle.h" | 27 #include "ui/base/resource/resource_bundle.h" |
| 27 #include "ui/gfx/canvas_skia.h" | 28 #include "ui/gfx/canvas_skia.h" |
| 28 #include "ui/gfx/skbitmap_operations.h" | 29 #include "ui/gfx/skbitmap_operations.h" |
| 29 #include "views/controls/menu/menu_2.h" | 30 #include "views/controls/menu/menu_item_view.h" |
| 31 #include "views/controls/menu/submenu_view.h" | |
| 30 #include "views/window/window.h" | 32 #include "views/window/window.h" |
| 31 | 33 |
| 32 namespace { | 34 namespace { |
| 33 | 35 |
| 34 // Replace '&' in a string with "&&" to allow it to be a menu item label. | 36 // Replace '&' in a string with "&&" to allow it to be a menu item label. |
| 35 std::string EscapeAmpersands(const std::string& input) { | 37 std::string EscapeAmpersands(const std::string& input) { |
| 36 std::string str = input; | 38 std::string str = input; |
| 37 size_t found = str.find('&'); | 39 size_t found = str.find('&'); |
| 38 while (found != std::string::npos) { | 40 while (found != std::string::npos) { |
| 39 str.replace(found, 1, "&&"); | 41 str.replace(found, 1, "&&"); |
| 40 found = str.find('&', found + 2); | 42 found = str.find('&', found + 2); |
| 41 } | 43 } |
| 42 return str; | 44 return str; |
| 43 } | 45 } |
| 44 | 46 |
| 47 // Offsets for views menu ids (main menu and submenu ids use the same | |
| 48 // namespace). | |
| 49 const int kMainIndexOffset = 1000; | |
| 50 const int kVPNIndexOffset = 2000; | |
| 51 const int kMoreIndexOffset = 3000; | |
| 52 | |
| 53 // Default minimum width in pixels of the menu to prevent unnecessary | |
| 54 // resizing as networks are updated. | |
| 55 const int kDefaultMinimumWidth = 280; | |
| 56 | |
| 57 // Menu item margins. | |
| 58 const int kTopMargin = 5; | |
| 59 const int kBottomMargin = 7; | |
| 60 | |
| 45 } // namespace | 61 } // namespace |
| 46 | 62 |
| 47 namespace chromeos { | 63 namespace chromeos { |
| 48 | 64 |
| 65 class NetworkMenuModel : public views::MenuDelegate { | |
|
Nikita (slow)
2011/05/30 11:32:53
What was the reason for dropping ui::MenuModel int
| |
| 66 public: | |
| 67 struct NetworkInfo { | |
| 68 NetworkInfo(); | |
| 69 ~NetworkInfo(); | |
| 70 | |
| 71 // "ethernet" | "wifi" | "cellular" | "other". | |
| 72 std::string network_type; | |
| 73 // "connected" | "connecting" | "disconnected" | "error". | |
| 74 std::string status; | |
| 75 // status message or error message, empty if unknown status. | |
| 76 std::string message; | |
| 77 // IP address (if network is active, empty otherwise) | |
| 78 std::string ip_address; | |
| 79 // Remembered passphrase. | |
| 80 std::string passphrase; | |
| 81 // true if the network requires a passphrase. | |
| 82 bool need_passphrase; | |
| 83 // true if the network is currently remembered. | |
| 84 bool remembered; | |
| 85 // true if the network is auto connect (meaningful for Wifi only). | |
| 86 bool auto_connect; | |
| 87 }; | |
| 88 | |
| 89 explicit NetworkMenuModel(NetworkMenu* owner); | |
| 90 virtual ~NetworkMenuModel(); | |
| 91 | |
| 92 // Connect or reconnect to the network at |index|. | |
| 93 // If remember >= 0, set the favorite state of the network. | |
| 94 void ConnectToNetworkAt(int index, | |
| 95 const std::string& passphrase, | |
| 96 const std::string& ssid, | |
| 97 int remember) const; | |
| 98 | |
| 99 // Called by NetworkMenu::RunMenu to initialize list of menu items. | |
| 100 virtual void InitMenuItems(bool is_browser_mode, | |
| 101 bool should_open_button_options) = 0; | |
| 102 | |
| 103 // PopulateMenu() clears and reinstalls the menu items defined in this | |
| 104 // instance by calling PopulateMenuItem() on each one. Subclasses override | |
| 105 // PopulateMenuItem(), transform command_id into the correct range for | |
| 106 // the menu, and call the base class PopulateMenuItem(). | |
| 107 virtual void PopulateMenu(views::MenuItemView* menu); | |
| 108 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 109 int index, | |
| 110 int command_id); | |
| 111 | |
| 112 // Menu item field accessors. | |
| 113 int GetItemCount() const; | |
| 114 ui::MenuModel::ItemType GetTypeAt(int index) const; | |
| 115 string16 GetLabelAt(int index) const; | |
| 116 const gfx::Font* GetLabelFontAt(int index) const; | |
| 117 bool IsItemCheckedAt(int index) const; | |
| 118 bool GetIconAt(int index, SkBitmap* icon); | |
| 119 bool IsEnabledAt(int index) const; | |
| 120 NetworkMenuModel* GetSubmenuModelAt(int index) const; | |
| 121 void ActivatedAt(int index); | |
| 122 | |
| 123 protected: | |
| 124 enum MenuItemFlags { | |
| 125 FLAG_NONE = 0, | |
| 126 FLAG_DISABLED = 1 << 0, | |
| 127 FLAG_TOGGLE_ETHERNET = 1 << 1, | |
| 128 FLAG_TOGGLE_WIFI = 1 << 2, | |
| 129 FLAG_TOGGLE_CELLULAR = 1 << 3, | |
| 130 FLAG_TOGGLE_OFFLINE = 1 << 4, | |
| 131 FLAG_ASSOCIATED = 1 << 5, | |
| 132 FLAG_ETHERNET = 1 << 6, | |
| 133 FLAG_WIFI = 1 << 7, | |
| 134 FLAG_CELLULAR = 1 << 8, | |
| 135 FLAG_OPTIONS = 1 << 9, | |
| 136 FLAG_ADD_WIFI = 1 << 10, | |
| 137 FLAG_ADD_CELLULAR = 1 << 11, | |
| 138 FLAG_VPN = 1 << 12, | |
| 139 FLAG_ADD_VPN = 1 << 13, | |
| 140 FLAG_DISCONNECT_VPN = 1 << 14, | |
| 141 FLAG_VIEW_ACCOUNT = 1 << 15, | |
| 142 }; | |
| 143 | |
| 144 struct MenuItem { | |
| 145 MenuItem() | |
| 146 : type(ui::MenuModel::TYPE_SEPARATOR), | |
| 147 sub_menu_model(NULL), | |
| 148 flags(0) {} | |
| 149 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, | |
| 150 const std::string& service_path, int flags) | |
| 151 : type(type), | |
| 152 label(label), | |
| 153 icon(icon), | |
| 154 service_path(service_path), | |
| 155 sub_menu_model(NULL), | |
| 156 flags(flags) {} | |
| 157 MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon, | |
| 158 NetworkMenuModel* sub_menu_model, int flags) | |
| 159 : type(type), | |
| 160 label(label), | |
| 161 icon(icon), | |
| 162 sub_menu_model(sub_menu_model), | |
| 163 flags(flags) {} | |
| 164 | |
| 165 ui::MenuModel::ItemType type; | |
| 166 string16 label; | |
| 167 SkBitmap icon; | |
| 168 std::string service_path; | |
| 169 NetworkMenuModel* sub_menu_model; // Weak. | |
| 170 int flags; | |
| 171 }; | |
| 172 typedef std::vector<MenuItem> MenuItemVector; | |
| 173 | |
| 174 // Our menu items. | |
| 175 MenuItemVector menu_items_; | |
| 176 | |
| 177 NetworkMenu* owner_; // Weak pointer to NetworkMenu that owns this MenuModel. | |
| 178 | |
| 179 // Top up URL of the current carrier on empty string if there's none. | |
| 180 std::string top_up_url_; | |
| 181 | |
| 182 // Carrier ID which top up URL is initialized for. | |
| 183 // Used to update top up URL only when cellular carrier has changed. | |
| 184 std::string carrier_id_; | |
| 185 | |
| 186 private: | |
| 187 // Show a NetworkConfigView modal dialog instance. | |
| 188 void ShowNetworkConfigView(NetworkConfigView* view) const; | |
| 189 | |
| 190 void ActivateCellular(const CellularNetwork* cellular) const; | |
| 191 void ShowOther(ConnectionType type) const; | |
| 192 void ShowOtherCellular() const; | |
| 193 | |
| 194 DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel); | |
| 195 }; | |
| 196 | |
| 197 | |
| 49 class MoreMenuModel : public NetworkMenuModel { | 198 class MoreMenuModel : public NetworkMenuModel { |
| 50 public: | 199 public: |
| 51 explicit MoreMenuModel(NetworkMenu* owner); | 200 explicit MoreMenuModel(NetworkMenu* owner); |
| 52 virtual ~MoreMenuModel() {} | 201 virtual ~MoreMenuModel() {} |
| 53 | 202 |
| 54 // NetworkMenuModel implementation. | 203 // NetworkMenuModel implementation. |
| 55 virtual void InitMenuItems(bool is_browser_mode, | 204 virtual void InitMenuItems(bool is_browser_mode, |
| 56 bool should_open_button_options); | 205 bool should_open_button_options) OVERRIDE; |
| 206 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 207 int index, | |
| 208 int command_id) OVERRIDE; | |
| 57 | 209 |
| 58 private: | 210 private: |
| 59 friend class MainMenuModel; | 211 friend class MainMenuModel; |
| 60 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); | 212 DISALLOW_COPY_AND_ASSIGN(MoreMenuModel); |
| 61 }; | 213 }; |
| 62 | 214 |
| 63 class VPNMenuModel : public NetworkMenuModel { | 215 class VPNMenuModel : public NetworkMenuModel { |
| 64 public: | 216 public: |
| 65 explicit VPNMenuModel(NetworkMenu* owner); | 217 explicit VPNMenuModel(NetworkMenu* owner); |
| 66 virtual ~VPNMenuModel() {} | 218 virtual ~VPNMenuModel() {} |
| 67 | 219 |
| 68 // NetworkMenuModel implementation. | 220 // NetworkMenuModel implementation. |
| 69 virtual void InitMenuItems(bool is_browser_mode, | 221 virtual void InitMenuItems(bool is_browser_mode, |
| 70 bool should_open_button_options); | 222 bool should_open_button_options) OVERRIDE; |
| 223 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 224 int index, | |
| 225 int command_id) OVERRIDE; | |
| 71 | 226 |
| 72 static SkBitmap IconForDisplay(const Network* network); | 227 static SkBitmap IconForDisplay(const Network* network); |
| 73 | 228 |
| 74 private: | 229 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); | 230 DISALLOW_COPY_AND_ASSIGN(VPNMenuModel); |
| 76 }; | 231 }; |
| 77 | 232 |
| 78 class MainMenuModel : public NetworkMenuModel { | 233 class MainMenuModel : public NetworkMenuModel { |
| 79 public: | 234 public: |
| 80 explicit MainMenuModel(NetworkMenu* owner); | 235 explicit MainMenuModel(NetworkMenu* owner); |
| 81 virtual ~MainMenuModel() {} | 236 virtual ~MainMenuModel() {} |
| 82 | 237 |
| 83 // NetworkMenuModel implementation. | 238 // NetworkMenuModel implementation. |
| 84 virtual void InitMenuItems(bool is_browser_mode, | 239 virtual void InitMenuItems(bool is_browser_mode, |
| 85 bool should_open_button_options); | 240 bool should_open_button_options) OVERRIDE; |
| 241 virtual void PopulateMenuItem(views::MenuItemView* menu, | |
| 242 int index, | |
| 243 int command_id) OVERRIDE; | |
| 244 | |
| 245 // views::MenuDelegate implementation. | |
| 246 virtual const gfx::Font& GetLabelFont(int id) const OVERRIDE; | |
| 247 virtual bool IsItemChecked(int id) const OVERRIDE; | |
| 248 virtual bool IsCommandEnabled(int id) const OVERRIDE; | |
| 249 virtual void ExecuteCommand(int id) OVERRIDE; | |
| 86 | 250 |
| 87 private: | 251 private: |
| 88 scoped_ptr<NetworkMenuModel> vpn_menu_model_; | 252 scoped_ptr<NetworkMenuModel> vpn_menu_model_; |
| 89 scoped_ptr<MoreMenuModel> more_menu_model_; | 253 scoped_ptr<MoreMenuModel> more_menu_model_; |
| 90 | 254 |
| 91 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); | 255 DISALLOW_COPY_AND_ASSIGN(MainMenuModel); |
| 92 }; | 256 }; |
| 93 | 257 |
| 94 //////////////////////////////////////////////////////////////////////////////// | 258 //////////////////////////////////////////////////////////////////////////////// |
| 95 // NetworkMenuModel::NetworkInfo | 259 // NetworkMenuModel::NetworkInfo |
| 96 | 260 |
| 97 NetworkMenuModel::NetworkInfo::NetworkInfo() | 261 NetworkMenuModel::NetworkInfo::NetworkInfo() |
| 98 : need_passphrase(false), remembered(true), auto_connect(true) { | 262 : need_passphrase(false), remembered(true), auto_connect(true) { |
| 99 } | 263 } |
| 100 | 264 |
| 101 NetworkMenuModel::NetworkInfo::~NetworkInfo() {} | 265 NetworkMenuModel::NetworkInfo::~NetworkInfo() {} |
| 102 | 266 |
| 103 //////////////////////////////////////////////////////////////////////////////// | 267 //////////////////////////////////////////////////////////////////////////////// |
| 104 // NetworkMenuModel, public methods: | 268 // NetworkMenuModel, public methods: |
| 105 | 269 |
| 106 NetworkMenuModel::NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} | 270 NetworkMenuModel::NetworkMenuModel(NetworkMenu* owner) : owner_(owner) {} |
| 107 | 271 |
| 108 NetworkMenuModel::~NetworkMenuModel() {} | 272 NetworkMenuModel::~NetworkMenuModel() {} |
| 109 | 273 |
| 110 bool NetworkMenuModel::ConnectToNetworkAt(int index, | 274 void NetworkMenuModel::PopulateMenu(views::MenuItemView* menu) { |
| 275 if (menu->HasSubmenu()) { | |
| 276 const int old_count = menu->GetSubmenu()->child_count(); | |
| 277 for (int i = 0; i < old_count; ++i) | |
| 278 menu->RemoveMenuItemAt(0); | |
| 279 } | |
| 280 | |
| 281 const int menu_items_count = GetItemCount(); | |
| 282 for (int i = 0; i < menu_items_count; ++i) | |
| 283 PopulateMenuItem(menu, i, i); | |
| 284 } | |
| 285 | |
| 286 void NetworkMenuModel::PopulateMenuItem( | |
| 287 views::MenuItemView* menu, | |
| 288 int index, | |
| 289 int command_id) { | |
| 290 DCHECK_GT(GetItemCount(), index); | |
| 291 switch (GetTypeAt(index)) { | |
| 292 case ui::MenuModel::TYPE_SEPARATOR: | |
| 293 menu->AppendSeparator(); | |
| 294 break; | |
| 295 case ui::MenuModel::TYPE_COMMAND: { | |
| 296 views::MenuItemView* item = NULL; | |
| 297 SkBitmap icon; | |
| 298 if (GetIconAt(index, &icon)) { | |
| 299 item = menu->AppendMenuItemWithIcon(command_id, | |
| 300 UTF16ToWide(GetLabelAt(index)), | |
| 301 icon); | |
| 302 } else { | |
| 303 item = menu->AppendMenuItemWithLabel(command_id, | |
| 304 UTF16ToWide(GetLabelAt(index))); | |
| 305 } | |
| 306 item->set_margins(kTopMargin, kBottomMargin); | |
| 307 break; | |
| 308 } | |
| 309 case ui::MenuModel::TYPE_SUBMENU: { | |
| 310 views::MenuItemView* submenu = NULL; | |
| 311 SkBitmap icon; | |
| 312 if (GetIconAt(index, &icon)) { | |
| 313 submenu = menu->AppendSubMenuWithIcon(command_id, | |
| 314 UTF16ToWide(GetLabelAt(index)), | |
| 315 icon); | |
| 316 } else { | |
| 317 submenu = menu->AppendSubMenu(command_id, | |
| 318 UTF16ToWide(GetLabelAt(index))); | |
| 319 } | |
| 320 submenu->set_margins(kTopMargin, kBottomMargin); | |
| 321 GetSubmenuModelAt(index)->PopulateMenu(submenu); | |
| 322 break; | |
| 323 } | |
| 324 default: | |
| 325 NOTREACHED(); | |
| 326 } | |
| 327 } | |
| 328 | |
| 329 void NetworkMenuModel::ConnectToNetworkAt(int index, | |
| 111 const std::string& passphrase, | 330 const std::string& passphrase, |
| 112 const std::string& ssid, | 331 const std::string& ssid, |
| 113 int auto_connect) const { | 332 int auto_connect) const { |
| 114 int flags = menu_items_[index].flags; | 333 int flags = menu_items_[index].flags; |
| 115 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 334 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 116 const std::string& service_path = menu_items_[index].service_path; | 335 const std::string& service_path = menu_items_[index].service_path; |
| 117 if (flags & FLAG_WIFI) { | 336 if (flags & FLAG_WIFI) { |
| 118 WifiNetwork* wifi = cros->FindWifiNetworkByPath(service_path); | 337 WifiNetwork* wifi = cros->FindWifiNetworkByPath(service_path); |
| 119 if (wifi) { | 338 if (wifi) { |
| 120 // Connect or reconnect. | 339 // Connect or reconnect. |
| 121 if (auto_connect >= 0) | 340 if (auto_connect >= 0) |
| 122 wifi->SetAutoConnect(auto_connect ? true : false); | 341 wifi->SetAutoConnect(auto_connect ? true : false); |
| 123 if (wifi->connecting_or_connected()) { | 342 if (wifi->connecting_or_connected()) { |
| 124 // Show the config settings for the active network. | 343 // Show the config settings for the active network. |
| 125 owner_->ShowTabbedNetworkSettings(wifi); | 344 owner_->ShowTabbedNetworkSettings(wifi); |
| 126 return true; | 345 } else if (wifi->IsPassphraseRequired()) { |
| 127 } | |
| 128 if (wifi->IsPassphraseRequired()) { | |
| 129 // Show the connection UI if we require a passphrase. | 346 // Show the connection UI if we require a passphrase. |
| 130 ShowNetworkConfigView(new NetworkConfigView(wifi)); | 347 ShowNetworkConfigView(new NetworkConfigView(wifi)); |
| 131 return true; | |
| 132 } else { | 348 } else { |
| 133 cros->ConnectToWifiNetwork(wifi); | 349 cros->ConnectToWifiNetwork(wifi); |
| 134 // Connection failures are responsible for updating the UI, including | 350 // Connection failures are responsible for updating the UI, including |
| 135 // reopening dialogs. | 351 // reopening dialogs. |
| 136 return true; | |
| 137 } | 352 } |
| 138 } else { | 353 } else { |
| 139 // If we are attempting to connect to a network that no longer exists, | 354 // If we are attempting to connect to a network that no longer exists, |
| 140 // display a notification. | 355 // display a notification. |
| 141 LOG(WARNING) << "Wi-fi network does not exist to connect to: " | 356 LOG(WARNING) << "Wi-fi network does not exist to connect to: " |
| 142 << service_path; | 357 << service_path; |
| 143 // TODO(stevenjb): Show notification. | 358 // TODO(stevenjb): Show notification. |
| 144 } | 359 } |
| 145 } else if (flags & FLAG_CELLULAR) { | 360 } else if (flags & FLAG_CELLULAR) { |
| 146 CellularNetwork* cellular = cros->FindCellularNetworkByPath( | 361 CellularNetwork* cellular = cros->FindCellularNetworkByPath( |
| 147 service_path); | 362 service_path); |
| 148 if (cellular) { | 363 if (cellular) { |
| 149 if ((cellular->activation_state() != ACTIVATION_STATE_ACTIVATED && | 364 if ((cellular->activation_state() != ACTIVATION_STATE_ACTIVATED && |
| 150 cellular->activation_state() != ACTIVATION_STATE_UNKNOWN) || | 365 cellular->activation_state() != ACTIVATION_STATE_UNKNOWN) || |
| 151 cellular->needs_new_plan()) { | 366 cellular->needs_new_plan()) { |
| 152 ActivateCellular(cellular); | 367 ActivateCellular(cellular); |
| 153 return true; | |
| 154 } else if (cellular->connecting_or_connected()) { | 368 } else if (cellular->connecting_or_connected()) { |
| 155 // Cellular network is connecting or connected, | 369 // Cellular network is connecting or connected, |
| 156 // so we show the config settings for the cellular network. | 370 // so we show the config settings for the cellular network. |
| 157 owner_->ShowTabbedNetworkSettings(cellular); | 371 owner_->ShowTabbedNetworkSettings(cellular); |
| 158 return true; | 372 } else { |
| 373 // Clicked on a disconnected cellular network, so connect to it. | |
| 374 cros->ConnectToCellularNetwork(cellular); | |
| 159 } | 375 } |
| 160 // Clicked on a disconnected cellular network, so connect to it. | |
| 161 cros->ConnectToCellularNetwork(cellular); | |
| 162 } else { | 376 } else { |
| 163 // If we are attempting to connect to a network that no longer exists, | 377 // If we are attempting to connect to a network that no longer exists, |
| 164 // display a notification. | 378 // display a notification. |
| 165 LOG(WARNING) << "Cellular network does not exist to connect to: " | 379 LOG(WARNING) << "Cellular network does not exist to connect to: " |
| 166 << service_path; | 380 << service_path; |
| 167 // TODO(stevenjb): Show notification. | 381 // TODO(stevenjb): Show notification. |
| 168 } | 382 } |
| 169 } else if (flags & FLAG_ADD_WIFI) { | 383 } else if (flags & FLAG_ADD_WIFI) { |
| 170 ShowOther(TYPE_WIFI); | 384 ShowOther(TYPE_WIFI); |
| 171 } else if (flags & FLAG_ADD_CELLULAR) { | 385 } else if (flags & FLAG_ADD_CELLULAR) { |
| 172 ShowOtherCellular(); | 386 ShowOtherCellular(); |
| 173 } else if (flags & FLAG_ADD_VPN) { | 387 } else if (flags & FLAG_ADD_VPN) { |
| 174 ShowOther(TYPE_VPN); | 388 ShowOther(TYPE_VPN); |
| 175 } else if (flags & FLAG_VPN) { | 389 } else if (flags & FLAG_VPN) { |
| 176 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path); | 390 VirtualNetwork* vpn = cros->FindVirtualNetworkByPath(service_path); |
| 177 if (vpn) { | 391 if (vpn) { |
| 178 // Connect or reconnect. | 392 // Connect or reconnect. |
| 179 if (vpn->connecting_or_connected()) { | 393 if (vpn->connecting_or_connected()) { |
| 180 // Show the config settings for the connected network. | 394 // Show the config settings for the connected network. |
| 181 if (cros->connected_network()) | 395 if (cros->connected_network()) |
| 182 owner_->ShowTabbedNetworkSettings(cros->connected_network()); | 396 owner_->ShowTabbedNetworkSettings(cros->connected_network()); |
| 183 return true; | 397 } else if (vpn->NeedMoreInfoToConnect()) { |
| 398 // Show the connection UI if info for a field is missing. | |
| 399 ShowNetworkConfigView(new NetworkConfigView(vpn)); | |
| 400 } else { | |
| 401 cros->ConnectToVirtualNetwork(vpn); | |
| 402 // Connection failures are responsible for updating the UI, including | |
| 403 // reopening dialogs. | |
| 184 } | 404 } |
| 185 // Show the connection UI if info for a field is missing. | |
| 186 if (vpn->NeedMoreInfoToConnect()) { | |
| 187 ShowNetworkConfigView(new NetworkConfigView(vpn)); | |
| 188 return true; | |
| 189 } | |
| 190 cros->ConnectToVirtualNetwork(vpn); | |
| 191 // Connection failures are responsible for updating the UI, including | |
| 192 // reopening dialogs. | |
| 193 return true; | |
| 194 } else { | 405 } else { |
| 195 // If we are attempting to connect to a network that no longer exists, | 406 // If we are attempting to connect to a network that no longer exists, |
| 196 // display a notification. | 407 // display a notification. |
| 197 LOG(WARNING) << "VPN does not exist to connect to: " << service_path; | 408 LOG(WARNING) << "VPN does not exist to connect to: " << service_path; |
| 198 // TODO(stevenjb): Show notification. | 409 // TODO(stevenjb): Show notification. |
| 199 } | 410 } |
| 200 } | 411 } |
| 201 return true; | |
| 202 } | 412 } |
| 203 | 413 |
| 204 //////////////////////////////////////////////////////////////////////////////// | 414 //////////////////////////////////////////////////////////////////////////////// |
| 205 // NetworkMenuModel, ui::MenuModel implementation: | 415 // NetworkMenuModel, ui::MenuModel implementation: |
|
Nikita (slow)
2011/05/30 11:45:03
Note, comment is incorrect now.
menu_delegate.h h
| |
| 206 | 416 |
| 207 bool NetworkMenuModel::HasIcons() const { | |
| 208 return true; | |
| 209 } | |
| 210 | |
| 211 int NetworkMenuModel::GetItemCount() const { | 417 int NetworkMenuModel::GetItemCount() const { |
| 212 return static_cast<int>(menu_items_.size()); | 418 return static_cast<int>(menu_items_.size()); |
| 213 } | 419 } |
| 214 | 420 |
| 215 ui::MenuModel::ItemType NetworkMenuModel::GetTypeAt(int index) const { | 421 ui::MenuModel::ItemType NetworkMenuModel::GetTypeAt(int index) const { |
| 216 return menu_items_[index].type; | 422 return menu_items_[index].type; |
| 217 } | 423 } |
| 218 | 424 |
| 219 int NetworkMenuModel::GetCommandIdAt(int index) const { | |
| 220 return index; | |
| 221 } | |
| 222 | |
| 223 string16 NetworkMenuModel::GetLabelAt(int index) const { | 425 string16 NetworkMenuModel::GetLabelAt(int index) const { |
| 224 return menu_items_[index].label; | 426 return menu_items_[index].label; |
| 225 } | 427 } |
| 226 | 428 |
| 227 bool NetworkMenuModel::IsItemDynamicAt(int index) const { | |
| 228 return true; | |
| 229 } | |
| 230 | |
| 231 const gfx::Font* NetworkMenuModel::GetLabelFontAt(int index) const { | 429 const gfx::Font* NetworkMenuModel::GetLabelFontAt(int index) const { |
| 232 return (menu_items_[index].flags & FLAG_ASSOCIATED) ? | 430 return (menu_items_[index].flags & FLAG_ASSOCIATED) ? |
| 233 &ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BoldFont) : | 431 &ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BoldFont) : |
| 234 NULL; | 432 NULL; |
| 235 } | 433 } |
| 236 | 434 |
| 237 bool NetworkMenuModel::GetAcceleratorAt( | |
| 238 int index, ui::Accelerator* accelerator) const { | |
| 239 return false; | |
| 240 } | |
| 241 | |
| 242 bool NetworkMenuModel::IsItemCheckedAt(int index) const { | 435 bool NetworkMenuModel::IsItemCheckedAt(int index) const { |
| 243 // All ui::MenuModel::TYPE_CHECK menu items are checked. | 436 // All ui::MenuModel::TYPE_CHECK menu items are checked. |
| 244 return true; | 437 return true; |
| 245 } | 438 } |
| 246 | 439 |
| 247 int NetworkMenuModel::GetGroupIdAt(int index) const { | |
| 248 return 0; | |
| 249 } | |
| 250 | |
| 251 bool NetworkMenuModel::GetIconAt(int index, SkBitmap* icon) { | 440 bool NetworkMenuModel::GetIconAt(int index, SkBitmap* icon) { |
| 252 if (!menu_items_[index].icon.empty()) { | 441 if (!menu_items_[index].icon.empty()) { |
| 253 *icon = menu_items_[index].icon; | 442 *icon = menu_items_[index].icon; |
| 254 return true; | 443 return true; |
| 255 } | 444 } |
| 256 return false; | 445 return false; |
| 257 } | 446 } |
| 258 | 447 |
| 259 ui::ButtonMenuItemModel* NetworkMenuModel::GetButtonMenuItemAt( | |
| 260 int index) const { | |
| 261 return NULL; | |
| 262 } | |
| 263 | |
| 264 bool NetworkMenuModel::IsEnabledAt(int index) const { | 448 bool NetworkMenuModel::IsEnabledAt(int index) const { |
| 265 return !(menu_items_[index].flags & FLAG_DISABLED); | 449 return !(menu_items_[index].flags & FLAG_DISABLED); |
| 266 } | 450 } |
| 267 | 451 |
| 268 ui::MenuModel* NetworkMenuModel::GetSubmenuModelAt(int index) const { | 452 NetworkMenuModel* NetworkMenuModel::GetSubmenuModelAt(int index) const { |
| 269 return menu_items_[index].sub_menu_model; | 453 return menu_items_[index].sub_menu_model; |
| 270 } | 454 } |
| 271 | 455 |
| 272 void NetworkMenuModel::HighlightChangedTo(int index) {} | |
| 273 | |
| 274 void NetworkMenuModel::ActivatedAt(int index) { | 456 void NetworkMenuModel::ActivatedAt(int index) { |
| 275 // When we are refreshing the menu, ignore menu item activation. | 457 // When we are refreshing the menu, ignore menu item activation. |
| 276 if (owner_->refreshing_menu_) | 458 if (owner_->refreshing_menu_) |
| 277 return; | 459 return; |
| 278 | 460 |
| 279 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 461 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 280 int flags = menu_items_[index].flags; | 462 int flags = menu_items_[index].flags; |
| 281 if (flags & FLAG_OPTIONS) { | 463 if (flags & FLAG_OPTIONS) { |
| 282 owner_->OpenButtonOptions(); | 464 owner_->OpenButtonOptions(); |
| 283 } else if (flags & FLAG_TOGGLE_ETHERNET) { | 465 } else if (flags & FLAG_TOGGLE_ETHERNET) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 312 const VirtualNetwork* active_vpn = cros->virtual_network(); | 494 const VirtualNetwork* active_vpn = cros->virtual_network(); |
| 313 if (active_vpn) | 495 if (active_vpn) |
| 314 cros->DisconnectFromNetwork(active_vpn); | 496 cros->DisconnectFromNetwork(active_vpn); |
| 315 } else if (flags & FLAG_VIEW_ACCOUNT) { | 497 } else if (flags & FLAG_VIEW_ACCOUNT) { |
| 316 Browser* browser = BrowserList::GetLastActive(); | 498 Browser* browser = BrowserList::GetLastActive(); |
| 317 if (browser) | 499 if (browser) |
| 318 browser->ShowSingletonTab(GURL(top_up_url_)); | 500 browser->ShowSingletonTab(GURL(top_up_url_)); |
| 319 } | 501 } |
| 320 } | 502 } |
| 321 | 503 |
| 322 void NetworkMenuModel::MenuWillShow() {} | |
| 323 | |
| 324 void NetworkMenuModel::SetMenuModelDelegate(ui::MenuModelDelegate* delegate) {} | |
| 325 | |
| 326 //////////////////////////////////////////////////////////////////////////////// | 504 //////////////////////////////////////////////////////////////////////////////// |
| 327 // NetworkMenuModel, private methods: | 505 // NetworkMenuModel, private methods: |
| 328 | 506 |
| 329 // TODO(stevenjb): deprecate this once we've committed to tabbed settings | 507 // TODO(stevenjb): deprecate this once we've committed to tabbed settings |
| 330 // and the embedded menu UI (and fully deprecated NetworkConfigView). | 508 // and the embedded menu UI (and fully deprecated NetworkConfigView). |
| 331 // Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI, | 509 // Meanwhile, if MenuUI::IsEnabled() is true, always show the settings UI, |
| 332 // otherwise show NetworkConfigView only to get passwords when not connected. | 510 // otherwise show NetworkConfigView only to get passwords when not connected. |
| 333 void NetworkMenuModel::ShowNetworkConfigView(NetworkConfigView* view) const { | 511 void NetworkMenuModel::ShowNetworkConfigView(NetworkConfigView* view) const { |
| 334 views::Window* window = browser::CreateViewsWindow( | 512 views::Window* window = browser::CreateViewsWindow( |
| 335 owner_->GetNativeWindow(), gfx::Rect(), view); | 513 owner_->GetNativeWindow(), gfx::Rect(), view); |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 683 } else { | 861 } else { |
| 684 if (!more_menu_model_->menu_items_.empty()) { | 862 if (!more_menu_model_->menu_items_.empty()) { |
| 685 menu_items_.push_back(MenuItem( | 863 menu_items_.push_back(MenuItem( |
| 686 ui::MenuModel::TYPE_SUBMENU, | 864 ui::MenuModel::TYPE_SUBMENU, |
| 687 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), | 865 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_MORE), |
| 688 SkBitmap(), more_menu_model_.get(), FLAG_NONE)); | 866 SkBitmap(), more_menu_model_.get(), FLAG_NONE)); |
| 689 } | 867 } |
| 690 } | 868 } |
| 691 } | 869 } |
| 692 | 870 |
| 871 void MainMenuModel::PopulateMenuItem( | |
| 872 views::MenuItemView* menu, | |
| 873 int index, | |
| 874 int command_id) { | |
| 875 NetworkMenuModel::PopulateMenuItem(menu, index, | |
| 876 command_id + kMainIndexOffset); | |
| 877 } | |
| 878 | |
| 879 // views::MenuDelegate implementation. | |
| 880 | |
| 881 const gfx::Font& MainMenuModel::GetLabelFont(int id) const { | |
| 882 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 883 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 884 const gfx::Font* font = NULL; | |
| 885 if (id >= kMoreIndexOffset) | |
| 886 font = more_menu_model_->GetLabelFontAt(id - kMoreIndexOffset); | |
| 887 else if (id >= kVPNIndexOffset) | |
| 888 font = vpn_menu_model_->GetLabelFontAt(id - kVPNIndexOffset); | |
| 889 else if (id >= kMainIndexOffset) | |
| 890 font = GetLabelFontAt(id - kMainIndexOffset); | |
| 891 | |
| 892 return font ? *font : views::MenuDelegate::GetLabelFont(id); | |
| 893 } | |
| 894 | |
| 895 | |
| 896 bool MainMenuModel::IsItemChecked(int id) const { | |
| 897 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 898 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 899 if (id >= kMoreIndexOffset) | |
| 900 return more_menu_model_->IsItemCheckedAt(id - kMoreIndexOffset); | |
| 901 else if (id >= kVPNIndexOffset) | |
| 902 return vpn_menu_model_->IsItemCheckedAt(id - kVPNIndexOffset); | |
| 903 else if (id >= kMainIndexOffset) | |
| 904 return IsItemCheckedAt(id - kMainIndexOffset); | |
| 905 | |
| 906 return views::MenuDelegate::IsItemChecked(id); | |
| 907 } | |
| 908 | |
| 909 bool MainMenuModel::IsCommandEnabled(int id) const { | |
| 910 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 911 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 912 if (id >= kMoreIndexOffset) | |
| 913 return more_menu_model_->IsEnabledAt(id - kMoreIndexOffset); | |
| 914 else if (id >= kVPNIndexOffset) | |
| 915 return vpn_menu_model_->IsEnabledAt(id - kVPNIndexOffset); | |
| 916 else if (id >= kMainIndexOffset) | |
| 917 return IsEnabledAt(id - kMainIndexOffset); | |
| 918 | |
| 919 return views::MenuDelegate::IsCommandEnabled(id); | |
| 920 } | |
| 921 | |
| 922 void MainMenuModel::ExecuteCommand(int id) { | |
| 923 DCHECK_GT(kMoreIndexOffset, kVPNIndexOffset); | |
| 924 DCHECK_GT(kVPNIndexOffset, kMainIndexOffset); | |
| 925 if (id >= kMoreIndexOffset) | |
| 926 more_menu_model_->ActivatedAt(id - kMoreIndexOffset); | |
| 927 else if (id >= kVPNIndexOffset) | |
| 928 vpn_menu_model_->ActivatedAt(id - kVPNIndexOffset); | |
| 929 else if (id >= kMainIndexOffset) | |
| 930 ActivatedAt(id - kMainIndexOffset); | |
| 931 } | |
| 932 | |
| 693 //////////////////////////////////////////////////////////////////////////////// | 933 //////////////////////////////////////////////////////////////////////////////// |
| 694 // VPNMenuModel | 934 // VPNMenuModel |
| 695 | 935 |
| 696 VPNMenuModel::VPNMenuModel(NetworkMenu* owner) | 936 VPNMenuModel::VPNMenuModel(NetworkMenu* owner) |
| 697 : NetworkMenuModel(owner) { | 937 : NetworkMenuModel(owner) { |
| 698 } | 938 } |
| 699 | 939 |
| 700 void VPNMenuModel::InitMenuItems(bool is_browser_mode, | 940 void VPNMenuModel::InitMenuItems(bool is_browser_mode, |
| 701 bool should_open_button_options) { | 941 bool should_open_button_options) { |
| 702 // This gets called on initialization, so any changes should be reflected | 942 // This gets called on initialization, so any changes should be reflected |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 755 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_ADD_VPN), | 995 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_ADD_VPN), |
| 756 SkBitmap(), std::string(), FLAG_ADD_VPN)); | 996 SkBitmap(), std::string(), FLAG_ADD_VPN)); |
| 757 if (active_vpn) { | 997 if (active_vpn) { |
| 758 menu_items_.push_back(MenuItem( | 998 menu_items_.push_back(MenuItem( |
| 759 ui::MenuModel::TYPE_COMMAND, | 999 ui::MenuModel::TYPE_COMMAND, |
| 760 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), | 1000 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DISCONNECT_VPN), |
| 761 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); | 1001 SkBitmap(), std::string(), FLAG_DISCONNECT_VPN)); |
| 762 } | 1002 } |
| 763 } | 1003 } |
| 764 | 1004 |
| 1005 void VPNMenuModel::PopulateMenuItem( | |
| 1006 views::MenuItemView* menu, | |
| 1007 int index, | |
| 1008 int command_id) { | |
| 1009 NetworkMenuModel::PopulateMenuItem(menu, index, | |
| 1010 command_id + kVPNIndexOffset); | |
| 1011 } | |
| 1012 | |
| 765 // static | 1013 // static |
| 766 SkBitmap VPNMenuModel::IconForDisplay(const Network* network) { | 1014 SkBitmap VPNMenuModel::IconForDisplay(const Network* network) { |
| 767 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1015 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 768 const SkBitmap* icon = NULL; | 1016 const SkBitmap* icon = NULL; |
| 769 const SkBitmap* bottom_right_badge = NULL; | 1017 const SkBitmap* bottom_right_badge = NULL; |
| 770 const SkBitmap* top_left_badge = NULL; | 1018 const SkBitmap* top_left_badge = NULL; |
| 771 // We know for sure |network| is the active network, so no more checking | 1019 // We know for sure |network| is the active network, so no more checking |
| 772 // is needed by BadgeForPrivateNetworkStatus, hence pass in NULL. | 1020 // is needed by BadgeForPrivateNetworkStatus, hence pass in NULL. |
| 773 const SkBitmap* bottom_left_badge = | 1021 const SkBitmap* bottom_left_badge = |
| 774 NetworkMenu::BadgeForPrivateNetworkStatus(NULL); | 1022 NetworkMenu::BadgeForPrivateNetworkStatus(NULL); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 864 } | 1112 } |
| 865 } | 1113 } |
| 866 | 1114 |
| 867 menu_items_ = link_items; | 1115 menu_items_ = link_items; |
| 868 if (!menu_items_.empty() && address_items.size() > 1) | 1116 if (!menu_items_.empty() && address_items.size() > 1) |
| 869 menu_items_.push_back(MenuItem()); // Separator | 1117 menu_items_.push_back(MenuItem()); // Separator |
| 870 menu_items_.insert(menu_items_.end(), | 1118 menu_items_.insert(menu_items_.end(), |
| 871 address_items.begin(), address_items.end()); | 1119 address_items.begin(), address_items.end()); |
| 872 } | 1120 } |
| 873 | 1121 |
| 1122 void MoreMenuModel::PopulateMenuItem( | |
| 1123 views::MenuItemView* menu, | |
| 1124 int index, | |
| 1125 int command_id) { | |
| 1126 NetworkMenuModel::PopulateMenuItem(menu, index, | |
| 1127 command_id + kMoreIndexOffset); | |
| 1128 } | |
| 1129 | |
| 874 //////////////////////////////////////////////////////////////////////////////// | 1130 //////////////////////////////////////////////////////////////////////////////// |
| 875 // NetworkMenu | 1131 // NetworkMenu |
| 876 | 1132 |
| 877 // static | 1133 // static |
| 878 const int NetworkMenu::kNumBarsImages = 4; | 1134 const int NetworkMenu::kNumBarsImages = 4; |
| 879 | 1135 |
| 880 // NOTE: Use an array rather than just calculating a resource number to avoid | 1136 // NOTE: Use an array rather than just calculating a resource number to avoid |
| 881 // creating implicit ordering dependencies on the resource values. | 1137 // creating implicit ordering dependencies on the resource values. |
| 882 // static | 1138 // static |
| 883 const int NetworkMenu::kBarsImages[kNumBarsImages] = { | 1139 const int NetworkMenu::kBarsImages[kNumBarsImages] = { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 913 | 1169 |
| 914 // static | 1170 // static |
| 915 const int NetworkMenu::kNumAnimatingImages = 10; | 1171 const int NetworkMenu::kNumAnimatingImages = 10; |
| 916 | 1172 |
| 917 // static | 1173 // static |
| 918 SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages]; | 1174 SkBitmap NetworkMenu::kAnimatingImages[kNumAnimatingImages]; |
| 919 | 1175 |
| 920 // static | 1176 // static |
| 921 SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; | 1177 SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages]; |
| 922 | 1178 |
| 923 NetworkMenu::NetworkMenu() : min_width_(-1) { | 1179 NetworkMenu::NetworkMenu() : min_width_(kDefaultMinimumWidth) { |
| 924 main_menu_model_.reset(new MainMenuModel(this)); | 1180 main_menu_model_.reset(new MainMenuModel(this)); |
| 925 network_menu_.reset(new views::Menu2(main_menu_model_.get())); | 1181 network_menu_.reset(new views::MenuItemView(main_menu_model_.get())); |
| 1182 network_menu_->set_has_icons(true); | |
| 926 } | 1183 } |
| 927 | 1184 |
| 928 NetworkMenu::~NetworkMenu() { | 1185 NetworkMenu::~NetworkMenu() { |
| 929 } | 1186 } |
| 930 | 1187 |
| 931 void NetworkMenu::SetFirstLevelMenuWidth(int width) { | 1188 void NetworkMenu::SetFirstLevelMenuWidth(int width) { |
| 932 min_width_ = width; | 1189 min_width_ = width; |
| 933 // This actually has no effect since menu is rebuilt before showing. | |
| 934 network_menu_->SetMinimumWidth(width); | |
| 935 } | 1190 } |
| 936 | 1191 |
| 937 void NetworkMenu::CancelMenu() { | 1192 void NetworkMenu::CancelMenu() { |
| 938 network_menu_->CancelMenu(); | 1193 network_menu_->Cancel(); |
| 939 } | 1194 } |
| 940 | 1195 |
| 941 void NetworkMenu::UpdateMenu() { | 1196 void NetworkMenu::UpdateMenu() { |
| 1197 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 1198 | |
| 942 refreshing_menu_ = true; | 1199 refreshing_menu_ = true; |
| 943 main_menu_model_->InitMenuItems(IsBrowserMode(), ShouldOpenButtonOptions()); | 1200 main_menu_model_->InitMenuItems(IsBrowserMode(), ShouldOpenButtonOptions()); |
| 944 network_menu_->Rebuild(); | 1201 main_menu_model_->PopulateMenu(network_menu_.get()); |
| 1202 network_menu_->ChildrenChanged(); | |
| 945 refreshing_menu_ = false; | 1203 refreshing_menu_ = false; |
| 946 } | 1204 } |
| 947 | 1205 |
| 948 // static | 1206 // static |
| 949 const SkBitmap* NetworkMenu::IconForNetworkStrength(const WifiNetwork* wifi, | 1207 const SkBitmap* NetworkMenu::IconForNetworkStrength(const WifiNetwork* wifi, |
| 950 bool black) { | 1208 bool black) { |
| 951 DCHECK(wifi); | 1209 DCHECK(wifi); |
| 952 if (wifi->strength() == 0) { | 1210 if (wifi->strength() == 0) { |
| 953 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | 1211 return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 954 black ? IDR_STATUSBAR_NETWORK_BARS0_BLACK : | 1212 black ? IDR_STATUSBAR_NETWORK_BARS0_BLACK : |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1149 chrome::kInternetOptionsSubPage, | 1407 chrome::kInternetOptionsSubPage, |
| 1150 EscapeUrlEncodedData(network->service_path()).c_str(), | 1408 EscapeUrlEncodedData(network->service_path()).c_str(), |
| 1151 network->type()); | 1409 network->type()); |
| 1152 browser->ShowOptionsTab(page); | 1410 browser->ShowOptionsTab(page); |
| 1153 } | 1411 } |
| 1154 | 1412 |
| 1155 //////////////////////////////////////////////////////////////////////////////// | 1413 //////////////////////////////////////////////////////////////////////////////// |
| 1156 // NetworkMenu, views::ViewMenuDelegate implementation: | 1414 // NetworkMenu, views::ViewMenuDelegate implementation: |
| 1157 | 1415 |
| 1158 void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) { | 1416 void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) { |
| 1159 refreshing_menu_ = true; | |
| 1160 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 1417 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
| 1161 cros->RequestNetworkScan(); | 1418 cros->RequestNetworkScan(); |
| 1162 | 1419 |
| 1163 // Build initial menu items. They will be updated when UpdateMenu is | 1420 UpdateMenu(); |
| 1164 // called from NetworkChanged. | |
| 1165 main_menu_model_->InitMenuItems(IsBrowserMode(), ShouldOpenButtonOptions()); | |
| 1166 network_menu_->Rebuild(); | |
| 1167 | 1421 |
| 1168 // Restore menu width, if it was set up. | 1422 // TODO(rhashimoto): Remove this workaround when WebUI provides a |
| 1169 // NOTE: width isn't checked for correctness here since all width-related | 1423 // top-level widget on the ChromeOS login screen that is a window. |
| 1170 // logic implemented inside |network_menu_|. | 1424 // The current BackgroundView class for the ChromeOS login screen |
| 1171 if (min_width_ != -1) | 1425 // creates a owning Widget that has a native GtkWindow but is not a |
| 1172 network_menu_->SetMinimumWidth(min_width_); | 1426 // Window. This makes it impossible to get the NativeWindow via |
| 1173 refreshing_menu_ = false; | 1427 // the views API. This workaround casts the top-level NativeWidget |
| 1174 network_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT); | 1428 // to a NativeWindow that we can pass to MenuItemView::RunMenuAt(). |
| 1429 gfx::NativeWindow window = GTK_WINDOW(source->GetWidget()->GetNativeView()); | |
| 1430 | |
| 1431 gfx::Point screen_loc; | |
| 1432 views::View::ConvertPointToScreen(source, &screen_loc); | |
| 1433 gfx::Rect bounds(screen_loc, source->size()); | |
| 1434 network_menu_->GetSubmenu()->set_minimum_preferred_width(min_width_); | |
| 1435 network_menu_->RunMenuAt(window, GetMenuButton(), bounds, | |
| 1436 views::MenuItemView::TOPRIGHT, true); | |
| 1175 } | 1437 } |
| 1176 | 1438 |
| 1177 } // namespace chromeos | 1439 } // namespace chromeos |
| 1178 | |
| 1179 | |
| OLD | NEW |