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

Side by Side Diff: chrome/browser/chromeos/status/network_menu_icon.cc

Issue 10824208: Fix logic for VPN badges and network menu order (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 4 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_icon.h" 5 #include "chrome/browser/chromeos/status/network_menu_icon.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const int kNumArcsImages = 5; 42 const int kNumArcsImages = 5;
43 gfx::ImageSkia* kArcsImagesAnimatingDark[kNumArcsImages - 1]; 43 gfx::ImageSkia* kArcsImagesAnimatingDark[kNumArcsImages - 1];
44 gfx::ImageSkia* kArcsImagesAnimatingLight[kNumArcsImages - 1]; 44 gfx::ImageSkia* kArcsImagesAnimatingLight[kNumArcsImages - 1];
45 45
46 // Badge offsets. The right and bottom offsets are computed based on the size 46 // Badge offsets. The right and bottom offsets are computed based on the size
47 // of the network icon and the badge in order to accomodate multiple icon 47 // of the network icon and the badge in order to accomodate multiple icon
48 // resolutions (ie. standard and high DPI). 48 // resolutions (ie. standard and high DPI).
49 const int kBadgeLeftX = 0; 49 const int kBadgeLeftX = 0;
50 const int kBadgeTopY = 0; 50 const int kBadgeTopY = 0;
51 51
52 // ID for VPN badge.
53 const int kVpnBadgeId = IDR_STATUSBAR_VPN_BADGE;
54
55 int StrengthIndex(int strength, int count) { 52 int StrengthIndex(int strength, int count) {
56 if (strength == 0) { 53 if (strength == 0) {
57 return 0; 54 return 0;
58 } else { 55 } else {
59 // Return an index in the range [1, count]. 56 // Return an index in the range [1, count].
60 const float findex = (static_cast<float>(strength) / 100.0f) * 57 const float findex = (static_cast<float>(strength) / 100.0f) *
61 nextafter(static_cast<float>(count), 0); 58 nextafter(static_cast<float>(count), 0);
62 int index = 1 + static_cast<int>(findex); 59 int index = 1 + static_cast<int>(findex);
63 index = max(min(index, count), 1); 60 index = max(min(index, count), 1);
64 return index; 61 return index;
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 SkBitmap empty; 169 SkBitmap empty;
173 empty.setConfig(SkBitmap::kARGB_8888_Config, key.first, key.second); 170 empty.setConfig(SkBitmap::kARGB_8888_Config, key.first, key.second);
174 empty.allocPixels(); 171 empty.allocPixels();
175 empty.eraseARGB(0, 0, 0, 0); 172 empty.eraseARGB(0, 0, 0, 0);
176 (*empty_bitmaps_)[key] = empty; 173 (*empty_bitmaps_)[key] = empty;
177 return empty; 174 return empty;
178 } 175 }
179 176
180 class EmptyImageSource: public gfx::ImageSkiaSource { 177 class EmptyImageSource: public gfx::ImageSkiaSource {
181 public: 178 public:
182 EmptyImageSource(const gfx::Size& size) 179 explicit EmptyImageSource(const gfx::Size& size)
183 : size_(size) { 180 : size_(size) {
184 } 181 }
185 182
186 virtual gfx::ImageSkiaRep GetImageForScale( 183 virtual gfx::ImageSkiaRep GetImageForScale(
187 ui::ScaleFactor scale_factor) OVERRIDE { 184 ui::ScaleFactor scale_factor) OVERRIDE {
188 gfx::Size pixel_size = size_.Scale(ui::GetScaleFactorScale(scale_factor)); 185 gfx::Size pixel_size = size_.Scale(ui::GetScaleFactorScale(scale_factor));
189 SkBitmap empty_bitmap = GetEmptyBitmap(pixel_size); 186 SkBitmap empty_bitmap = GetEmptyBitmap(pixel_size);
190 return gfx::ImageSkiaRep(empty_bitmap, scale_factor); 187 return gfx::ImageSkiaRep(empty_bitmap, scale_factor);
191 } 188 }
192 private: 189 private:
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 private: 236 private:
240 const gfx::ImageSkia icon_; 237 const gfx::ImageSkia icon_;
241 const gfx::ImageSkia *top_left_badge_; 238 const gfx::ImageSkia *top_left_badge_;
242 const gfx::ImageSkia *top_right_badge_; 239 const gfx::ImageSkia *top_right_badge_;
243 const gfx::ImageSkia *bottom_left_badge_; 240 const gfx::ImageSkia *bottom_left_badge_;
244 const gfx::ImageSkia *bottom_right_badge_; 241 const gfx::ImageSkia *bottom_right_badge_;
245 242
246 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); 243 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource);
247 }; 244 };
248 245
249 gfx::ImageSkia CreateVpnImage() {
250 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
251 const gfx::ImageSkia* ethernet_icon = rb.GetImageSkiaNamed(IDR_STATUSBAR_VPN);
252 const gfx::ImageSkia* vpn_badge = rb.GetImageSkiaNamed(kVpnBadgeId);
253 return NetworkMenuIcon::GenerateImageFromComponents(
254 *ethernet_icon, NULL, NULL, vpn_badge, NULL);
255 }
256
257 gfx::ImageSkia GetEmptyImage(const gfx::Size& size) { 246 gfx::ImageSkia GetEmptyImage(const gfx::Size& size) {
258 return gfx::ImageSkia(new EmptyImageSource(size), size); 247 return gfx::ImageSkia(new EmptyImageSource(size), size);
259 } 248 }
260 249
261 } // namespace 250 } // namespace
262 251
263 //////////////////////////////////////////////////////////////////////////////// 252 ////////////////////////////////////////////////////////////////////////////////
264 // NetworkIcon 253 // NetworkIcon
265 254
266 // Sets up and generates an ImageSkia for a Network icon. 255 // Sets up and generates an ImageSkia for a Network icon.
267 class NetworkIcon { 256 class NetworkIcon {
268 public: 257 public:
269 // Default constructor is used by the status bar icon (NetworkMenuIcon). 258 // Default constructor is used by the status bar icon (NetworkMenuIcon).
270 explicit NetworkIcon(NetworkMenuIcon::ResourceColorTheme color); 259 explicit NetworkIcon(NetworkMenuIcon::ResourceColorTheme color);
271 260
272 // Service path constructor for cached network service icons. 261 // Service path constructor for cached network service icons.
273 NetworkIcon(const std::string& service_path, 262 NetworkIcon(const std::string& service_path,
274 NetworkMenuIcon::ResourceColorTheme color); 263 NetworkMenuIcon::ResourceColorTheme color);
275 264
276 ~NetworkIcon(); 265 ~NetworkIcon();
277 266
278 // Resets the icon state. 267 // Resets the icon state.
279 void ClearIconAndBadges(); 268 void ClearIconAndBadges();
280 269
281 // Resets the saved state to force an update. 270 // Resets the saved state to force an update.
282 void SetDirty(); 271 void SetDirty();
283 272
273 // Updates |vpn_connected_|, returns true if it changed.
274 bool SetOrClearVpnConnected(const Network* network);
275
284 // Determines whether or not the associated network might be dirty and if so 276 // Determines whether or not the associated network might be dirty and if so
285 // updates and generates the icon. Does nothing if network no longer exists. 277 // updates and generates the icon. Does nothing if network no longer exists.
286 void Update(); 278 void Update();
287 279
288 // Sets up the base icon image. 280 // Sets up the base icon image.
289 void SetIcon(const Network* network); 281 void SetIcon(const Network* network);
290 282
291 // Sets up the various badges: 283 // Sets up the various badges:
292 // top_left: cellular roaming 284 // top_left: cellular roaming
293 // top_right: libcros warning 285 // top_right: libcros warning
294 // bottom_left: VPN 286 // bottom_left: VPN
295 // bottom_right: disconnected / secure / technology / warning 287 // bottom_right: disconnected / secure / technology / warning
296 void SetBadges(const Network* network); 288 void SetBadges(const Network* network);
297 289
298 // Clears any previous state then sets the base icon and badges. 290 // Clears any previous state then sets the base icon and badges.
299 void UpdateIcon(const Network* network); 291 void UpdateIcon(const Network* network);
300 292
301 // Generates the image. Call after setting the icon and badges. 293 // Generates the image. Call after setting the icon and badges.
302 void GenerateImage(); 294 void GenerateImage();
303 295
304 const gfx::ImageSkia GetImage() const { return image_; } 296 const gfx::ImageSkia GetImage() const { return image_; }
305 297
298 bool ShouldShowInTray() const;
299
300 void set_type(ConnectionType type) { type_ = type; }
301 void set_state(ConnectionState state) { state_ = state; }
306 void set_icon(const gfx::ImageSkia& icon) { icon_ = icon; } 302 void set_icon(const gfx::ImageSkia& icon) { icon_ = icon; }
307 void set_top_left_badge(const gfx::ImageSkia* badge) { 303 void set_top_left_badge(const gfx::ImageSkia* badge) {
308 top_left_badge_ = badge; 304 top_left_badge_ = badge;
309 } 305 }
310 void set_top_right_badge(const gfx::ImageSkia* badge) { 306 void set_top_right_badge(const gfx::ImageSkia* badge) {
311 top_right_badge_ = badge; 307 top_right_badge_ = badge;
312 } 308 }
313 void set_bottom_left_badge(const gfx::ImageSkia* badge) { 309 void set_bottom_left_badge(const gfx::ImageSkia* badge) {
314 bottom_left_badge_ = badge; 310 bottom_left_badge_ = badge;
315 } 311 }
316 void set_bottom_right_badge(const gfx::ImageSkia* badge) { 312 void set_bottom_right_badge(const gfx::ImageSkia* badge) {
317 bottom_right_badge_ = badge; 313 bottom_right_badge_ = badge;
318 } 314 }
319 315
320 private: 316 private:
321 // Updates strength_index_ for wifi or cellular networks. 317 // Updates strength_index_ for wifi or cellular networks.
322 // Returns true if |strength_index_| changed. 318 // Returns true if |strength_index_| changed.
323 bool UpdateWirelessStrengthIndex(const Network* network); 319 bool UpdateWirelessStrengthIndex(const Network* network);
324 320
325 // Updates the local state for cellular networks. 321 // Updates the local state for cellular networks.
326 bool UpdateCellularState(const Network* network); 322 bool UpdateCellularState(const Network* network);
327 323
328 std::string service_path_; 324 std::string service_path_;
325 ConnectionType type_;
329 ConnectionState state_; 326 ConnectionState state_;
330 NetworkMenuIcon::ResourceColorTheme resource_color_theme_; 327 NetworkMenuIcon::ResourceColorTheme resource_color_theme_;
331 int strength_index_; 328 int strength_index_;
332 gfx::ImageSkia image_; 329 gfx::ImageSkia image_;
333 gfx::ImageSkia icon_; 330 gfx::ImageSkia icon_;
334 const gfx::ImageSkia* top_left_badge_; 331 const gfx::ImageSkia* top_left_badge_;
335 const gfx::ImageSkia* top_right_badge_; 332 const gfx::ImageSkia* top_right_badge_;
336 const gfx::ImageSkia* bottom_left_badge_; 333 const gfx::ImageSkia* bottom_left_badge_;
337 const gfx::ImageSkia* bottom_right_badge_; 334 const gfx::ImageSkia* bottom_right_badge_;
338 bool is_status_bar_; 335 bool is_status_bar_;
339 const Network* connected_network_; // weak pointer; used for VPN icons. 336 const Network* connected_network_; // weak pointer; used for VPN icons.
337 bool vpn_connected_;
340 NetworkRoamingState roaming_state_; 338 NetworkRoamingState roaming_state_;
341 339
342 DISALLOW_COPY_AND_ASSIGN(NetworkIcon); 340 DISALLOW_COPY_AND_ASSIGN(NetworkIcon);
343 }; 341 };
344 342
345 //////////////////////////////////////////////////////////////////////////////// 343 ////////////////////////////////////////////////////////////////////////////////
346 // NetworkIcon 344 // NetworkIcon
347 345
348 NetworkIcon::NetworkIcon(NetworkMenuIcon::ResourceColorTheme color) 346 NetworkIcon::NetworkIcon(NetworkMenuIcon::ResourceColorTheme color)
349 : state_(STATE_UNKNOWN), 347 : type_(TYPE_UNKNOWN),
348 state_(STATE_UNKNOWN),
350 resource_color_theme_(color), 349 resource_color_theme_(color),
351 strength_index_(-1), 350 strength_index_(-1),
352 top_left_badge_(NULL), 351 top_left_badge_(NULL),
353 top_right_badge_(NULL), 352 top_right_badge_(NULL),
354 bottom_left_badge_(NULL), 353 bottom_left_badge_(NULL),
355 bottom_right_badge_(NULL), 354 bottom_right_badge_(NULL),
356 is_status_bar_(true), 355 is_status_bar_(true),
357 connected_network_(NULL), 356 connected_network_(NULL),
357 vpn_connected_(false),
358 roaming_state_(ROAMING_STATE_UNKNOWN) { 358 roaming_state_(ROAMING_STATE_UNKNOWN) {
359 } 359 }
360 360
361 NetworkIcon::NetworkIcon(const std::string& service_path, 361 NetworkIcon::NetworkIcon(const std::string& service_path,
362 NetworkMenuIcon::ResourceColorTheme color) 362 NetworkMenuIcon::ResourceColorTheme color)
363 : service_path_(service_path), 363 : service_path_(service_path),
364 type_(TYPE_UNKNOWN),
364 state_(STATE_UNKNOWN), 365 state_(STATE_UNKNOWN),
365 resource_color_theme_(color), 366 resource_color_theme_(color),
366 strength_index_(-1), 367 strength_index_(-1),
367 top_left_badge_(NULL), 368 top_left_badge_(NULL),
368 top_right_badge_(NULL), 369 top_right_badge_(NULL),
369 bottom_left_badge_(NULL), 370 bottom_left_badge_(NULL),
370 bottom_right_badge_(NULL), 371 bottom_right_badge_(NULL),
371 is_status_bar_(false), 372 is_status_bar_(false),
372 connected_network_(NULL), 373 connected_network_(NULL),
374 vpn_connected_(false),
373 roaming_state_(ROAMING_STATE_UNKNOWN) { 375 roaming_state_(ROAMING_STATE_UNKNOWN) {
374 } 376 }
375 377
376 NetworkIcon::~NetworkIcon() { 378 NetworkIcon::~NetworkIcon() {
377 } 379 }
378 380
379 void NetworkIcon::ClearIconAndBadges() { 381 void NetworkIcon::ClearIconAndBadges() {
380 icon_ = gfx::ImageSkia(); 382 icon_ = gfx::ImageSkia();
381 top_left_badge_ = NULL; 383 top_left_badge_ = NULL;
382 top_right_badge_ = NULL; 384 top_right_badge_ = NULL;
383 bottom_left_badge_ = NULL; 385 bottom_left_badge_ = NULL;
384 bottom_right_badge_ = NULL; 386 bottom_right_badge_ = NULL;
385 } 387 }
386 388
387 void NetworkIcon::SetDirty() { 389 void NetworkIcon::SetDirty() {
388 state_ = STATE_UNKNOWN; 390 state_ = STATE_UNKNOWN;
389 strength_index_ = -1; 391 strength_index_ = -1;
390 } 392 }
391 393
394 bool NetworkIcon::SetOrClearVpnConnected(const Network* network) {
395 if (network->type() == TYPE_VPN)
396 return false; // Never show the VPN badge for a VPN network.
397 chromeos::NetworkLibrary* cros =
398 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
399 bool vpn_connected = (network->connected() &&
400 cros->virtual_network() &&
401 cros->virtual_network()->connected());
402 if (vpn_connected_ != vpn_connected) {
403 vpn_connected_ = vpn_connected;
404 return true;
405 }
406 return false;
407 }
408
392 void NetworkIcon::Update() { 409 void NetworkIcon::Update() {
393 chromeos::NetworkLibrary* cros = 410 chromeos::NetworkLibrary* cros =
394 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 411 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
395 // First look for a visible network. 412 // First look for a visible network.
396 const Network* network = cros->FindNetworkByPath(service_path_); 413 const Network* network = cros->FindNetworkByPath(service_path_);
397 if (!network) { 414 if (!network) {
398 // If not a visible network, check for a remembered network. 415 // If not a visible network, check for a remembered network.
399 network = cros->FindRememberedNetworkByPath(service_path_); 416 network = cros->FindRememberedNetworkByPath(service_path_);
400 if (!network) { 417 if (!network) {
401 LOG(WARNING) << "Unable to find network:" << service_path_; 418 LOG(WARNING) << "Unable to find network:" << service_path_;
402 return; 419 return;
403 } 420 }
404 } 421 }
405 422
406 // Determine whether or not we need to update the icon. 423 // Determine whether or not we need to update the icon.
407 bool dirty = image_.empty(); 424 bool dirty = image_.empty();
408 425
409 // If the network state has changed, the icon needs updating. 426 // If the network state has changed, the icon needs updating.
410 if (state_ != network->state()) { 427 if (state_ != network->state()) {
411 state_ = network->state(); 428 state_ = network->state();
412 dirty = true; 429 dirty = true;
413 } 430 }
414 431
415 ConnectionType type = network->type(); 432 type_ = network->type();
416 if (type == TYPE_WIFI || type == TYPE_WIMAX || type == TYPE_CELLULAR) { 433
434 if (type_ == TYPE_WIFI || type_ == TYPE_WIMAX || type_ == TYPE_CELLULAR) {
417 if (UpdateWirelessStrengthIndex(network)) 435 if (UpdateWirelessStrengthIndex(network))
418 dirty = true; 436 dirty = true;
419 } 437 }
420 438
421 if (type == TYPE_CELLULAR) { 439 if (type_ == TYPE_CELLULAR) {
422 if (UpdateCellularState(network)) 440 if (UpdateCellularState(network))
423 dirty = true; 441 dirty = true;
424 } 442 }
425 443
426 if (type == TYPE_VPN) { 444 if (type_ == TYPE_VPN) {
445 // For VPN, check to see if the connected network has changed.
427 if (cros->connected_network() != connected_network_) { 446 if (cros->connected_network() != connected_network_) {
428 connected_network_ = cros->connected_network(); 447 connected_network_ = cros->connected_network();
429 dirty = true; 448 dirty = true;
430 } 449 }
450 } else {
451 // For non-VPN, check to see if the VPN connection state has changed.
452 if (SetOrClearVpnConnected(network))
453 dirty = true;
431 } 454 }
432 455
433 if (dirty) { 456 if (dirty) {
434 // Set the icon and badges based on the network. 457 // Set the icon and badges based on the network.
435 UpdateIcon(network); 458 UpdateIcon(network);
436 // Generate the image from the icon. 459 // Generate the image from the icon.
437 GenerateImage(); 460 GenerateImage();
438 } 461 }
439 } 462 }
440 463
441 void NetworkIcon::SetIcon(const Network* network) { 464 void NetworkIcon::SetIcon(const Network* network) {
442 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 465 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
443 466
444 switch (network->type()) { 467 set_type(network->type());
468 set_state(network->state());
469
470 switch (type_) {
445 case TYPE_ETHERNET: { 471 case TYPE_ETHERNET: {
446 icon_ = *rb.GetImageSkiaNamed(IDR_STATUSBAR_WIRED); 472 icon_ = *rb.GetImageSkiaNamed(IDR_STATUSBAR_WIRED);
447 break; 473 break;
448 } 474 }
449 case TYPE_WIFI: { 475 case TYPE_WIFI: {
450 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network); 476 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network);
451 if (strength_index_ == -1) 477 if (strength_index_ == -1)
452 strength_index_ = WifiStrengthIndex(wifi); 478 strength_index_ = WifiStrengthIndex(wifi);
453 icon_ = NetworkMenuIcon::GetImage( 479 icon_ = NetworkMenuIcon::GetImage(
454 NetworkMenuIcon::ARCS, strength_index_, resource_color_theme_); 480 NetworkMenuIcon::ARCS, strength_index_, resource_color_theme_);
(...skipping 14 matching lines...) Expand all
469 strength_index_ = CellularStrengthIndex(cellular); 495 strength_index_ = CellularStrengthIndex(cellular);
470 icon_ = NetworkMenuIcon::GetImage( 496 icon_ = NetworkMenuIcon::GetImage(
471 NetworkMenuIcon::BARS, strength_index_, resource_color_theme_); 497 NetworkMenuIcon::BARS, strength_index_, resource_color_theme_);
472 break; 498 break;
473 } 499 }
474 case TYPE_VPN: { 500 case TYPE_VPN: {
475 icon_ = *rb.GetImageSkiaNamed(IDR_STATUSBAR_VPN); 501 icon_ = *rb.GetImageSkiaNamed(IDR_STATUSBAR_VPN);
476 break; 502 break;
477 } 503 }
478 default: { 504 default: {
479 LOG(WARNING) << "Request for icon for unsupported type: " 505 LOG(WARNING) << "Request for icon for unsupported type: " << type_;
480 << network->type();
481 icon_ = *rb.GetImageSkiaNamed(IDR_STATUSBAR_WIRED); 506 icon_ = *rb.GetImageSkiaNamed(IDR_STATUSBAR_WIRED);
482 break; 507 break;
483 } 508 }
484 } 509 }
485 } 510 }
486 511
487 void NetworkIcon::SetBadges(const Network* network) { 512 void NetworkIcon::SetBadges(const Network* network) {
488 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 513 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
489 chromeos::NetworkLibrary* cros = 514 chromeos::NetworkLibrary* cros =
490 chromeos::CrosLibrary::Get()->GetNetworkLibrary(); 515 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 548 }
524 if (!cellular->connecting()) { 549 if (!cellular->connecting()) {
525 top_left_badge_ = BadgeForNetworkTechnology(cellular, 550 top_left_badge_ = BadgeForNetworkTechnology(cellular,
526 resource_color_theme_); 551 resource_color_theme_);
527 } 552 }
528 break; 553 break;
529 } 554 }
530 default: 555 default:
531 break; 556 break;
532 } 557 }
533 // Display the VPN badge too. 558 if (vpn_connected_)
534 if (resource_color_theme_ == NetworkMenuIcon::COLOR_DARK && 559 bottom_left_badge_ = rb.GetImageSkiaNamed(IDR_STATUSBAR_VPN_BADGE);
535 cros->virtual_network() &&
536 (cros->virtual_network()->connected() ||
537 cros->virtual_network()->connecting())) {
538 bottom_left_badge_ = rb.GetImageSkiaNamed(kVpnBadgeId);
539 }
540 } 560 }
541 561
542 void NetworkIcon::UpdateIcon(const Network* network) { 562 void NetworkIcon::UpdateIcon(const Network* network) {
543 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
544 chromeos::NetworkLibrary* cros =
545 chromeos::CrosLibrary::Get()->GetNetworkLibrary();
546
547 ClearIconAndBadges(); 563 ClearIconAndBadges();
548 564 SetIcon(network);
549 if (network->type() != TYPE_VPN) { 565 SetBadges(network);
550 SetIcon(network);
551 SetBadges(network);
552 return;
553 }
554
555 // VPN should never be the primiary active network. This is used for
556 // the icon next to a connected or disconnected VPN.
557 const Network* connected_network = cros->connected_network();
558 if (connected_network && connected_network->type() != TYPE_VPN) {
559 // Set the icon and badges for the connected network.
560 SetIcon(connected_network);
561 SetBadges(connected_network);
562 } else {
563 // Use the ethernet icon for VPN when not connected.
564 icon_ = *rb.GetImageSkiaNamed(IDR_STATUSBAR_WIRED);
565 // We can be connected to a VPN, even when there is no connected
566 // underlying network. In that case, for the status bar, show the
567 // disconnected badge.
568 if (is_status_bar_) {
569 bottom_right_badge_ =
570 rb.GetImageSkiaNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED);
571 }
572 }
573 // Overlay the VPN badge.
574 bottom_left_badge_ = rb.GetImageSkiaNamed(kVpnBadgeId);
575 } 566 }
576 567
577 void NetworkIcon::GenerateImage() { 568 void NetworkIcon::GenerateImage() {
578 if (icon_.empty()) 569 if (icon_.empty())
579 return; 570 return;
580 571
581 image_ = NetworkMenuIcon::GenerateImageFromComponents(icon_, top_left_badge_, 572 image_ = NetworkMenuIcon::GenerateImageFromComponents(icon_, top_left_badge_,
582 top_right_badge_, bottom_left_badge_, bottom_right_badge_); 573 top_right_badge_, bottom_left_badge_, bottom_right_badge_);
583 } 574 }
584 575
576 bool NetworkIcon::ShouldShowInTray() const {
577 if (type_ == TYPE_UNKNOWN || type_ == TYPE_VPN)
578 return false;
579 if (type_ != TYPE_ETHERNET)
580 return true;
581 if (!Network::IsConnectedState(state_))
582 return true;
583 NetworkLibrary* crosnet = CrosLibrary::Get()->GetNetworkLibrary();
584 if (crosnet->virtual_network() && crosnet->virtual_network()->connecting())
585 return true;
586 return false;
587 }
588
585 bool NetworkIcon::UpdateWirelessStrengthIndex(const Network* network) { 589 bool NetworkIcon::UpdateWirelessStrengthIndex(const Network* network) {
586 bool dirty = false; 590 bool dirty = false;
587 ConnectionType type = network->type(); 591 ConnectionType type = network->type();
588 int index = 0; 592 int index = 0;
589 if (type == TYPE_WIFI) { 593 if (type == TYPE_WIFI) {
590 index = WifiStrengthIndex(static_cast<const WifiNetwork*>(network)); 594 index = WifiStrengthIndex(static_cast<const WifiNetwork*>(network));
591 } else if (type == TYPE_WIMAX) { 595 } else if (type == TYPE_WIMAX) {
592 index = WimaxStrengthIndex(static_cast<const WimaxNetwork*>(network)); 596 index = WimaxStrengthIndex(static_cast<const WimaxNetwork*>(network));
593 } else if (type == TYPE_CELLULAR) { 597 } else if (type == TYPE_CELLULAR) {
594 index = CellularStrengthIndex(static_cast<const CellularNetwork*>(network)); 598 index = CellularStrengthIndex(static_cast<const CellularNetwork*>(network));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 // Public methods: 646 // Public methods:
643 647
644 void NetworkMenuIcon::SetResourceColorTheme(ResourceColorTheme color) { 648 void NetworkMenuIcon::SetResourceColorTheme(ResourceColorTheme color) {
645 if (color == resource_color_theme_) 649 if (color == resource_color_theme_)
646 return; 650 return;
647 651
648 resource_color_theme_ = color; 652 resource_color_theme_ = color;
649 icon_.reset(new NetworkIcon(resource_color_theme_)); 653 icon_.reset(new NetworkIcon(resource_color_theme_));
650 } 654 }
651 655
656 bool NetworkMenuIcon::ShouldShowIconInTray() {
657 if (!icon_.get())
658 return false;
659 return icon_->ShouldShowInTray();
660 }
661
652 const gfx::ImageSkia NetworkMenuIcon::GetIconAndText(string16* text) { 662 const gfx::ImageSkia NetworkMenuIcon::GetIconAndText(string16* text) {
653 SetIconAndText(); 663 SetIconAndText();
654 if (text) 664 if (text)
655 *text = text_; 665 *text = text_;
656 icon_->GenerateImage(); 666 icon_->GenerateImage();
657 return icon_->GetImage(); 667 return icon_->GetImage();
658 } 668 }
659 669
660 void NetworkMenuIcon::AnimationProgressed(const ui::Animation* animation) { 670 void NetworkMenuIcon::AnimationProgressed(const ui::Animation* animation) {
661 if (animation == &animation_connecting_ && delegate_) { 671 if (animation == &animation_connecting_ && delegate_) {
(...skipping 28 matching lines...) Expand all
690 } 700 }
691 return animation_connecting_.GetCurrentValue(); 701 return animation_connecting_.GetCurrentValue();
692 } 702 }
693 703
694 // TODO(stevenjb): move below SetIconAndText. 704 // TODO(stevenjb): move below SetIconAndText.
695 void NetworkMenuIcon::SetConnectingIconAndText() { 705 void NetworkMenuIcon::SetConnectingIconAndText() {
696 int image_count; 706 int image_count;
697 ImageType image_type; 707 ImageType image_type;
698 gfx::ImageSkia** images; 708 gfx::ImageSkia** images;
699 709
710 icon_->set_type(connecting_network_->type());
711 icon_->set_state(connecting_network_->state());
712
700 if (connecting_network_->type() == TYPE_WIFI) { 713 if (connecting_network_->type() == TYPE_WIFI) {
701 image_count = kNumArcsImages - 1; 714 image_count = kNumArcsImages - 1;
702 image_type = ARCS; 715 image_type = ARCS;
703 images = resource_color_theme_ == COLOR_DARK ? kArcsImagesAnimatingDark : 716 images = resource_color_theme_ == COLOR_DARK ? kArcsImagesAnimatingDark :
704 kArcsImagesAnimatingLight; 717 kArcsImagesAnimatingLight;
705 } else { 718 } else {
706 image_count = kNumBarsImages - 1; 719 image_count = kNumBarsImages - 1;
707 image_type = BARS; 720 image_type = BARS;
708 images = resource_color_theme_ == COLOR_DARK ? kBarsImagesAnimatingDark : 721 images = resource_color_theme_ == COLOR_DARK ? kBarsImagesAnimatingDark :
709 kBarsImagesAnimatingLight; 722 kBarsImagesAnimatingLight;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 } 778 }
766 779
767 void NetworkMenuIcon::SetActiveNetworkIconAndText(const Network* network) { 780 void NetworkMenuIcon::SetActiveNetworkIconAndText(const Network* network) {
768 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); 781 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
769 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 782 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
770 bool animating = false; 783 bool animating = false;
771 last_network_type_ = network->type(); 784 last_network_type_ = network->type();
772 785
773 // Set icon and badges. Call SetDirty() since network may have changed. 786 // Set icon and badges. Call SetDirty() since network may have changed.
774 icon_->SetDirty(); 787 icon_->SetDirty();
788 icon_->SetOrClearVpnConnected(network);
775 icon_->UpdateIcon(network); 789 icon_->UpdateIcon(network);
776 // Overlay the VPN badge if connecting to a VPN. 790 // Overlay the VPN badge if connecting to a VPN.
777 if (network->type() != TYPE_VPN && cros->virtual_network()) { 791 if (network->type() != TYPE_VPN &&
778 if (cros->virtual_network()->connecting()) { 792 cros->virtual_network() && cros->virtual_network()->connecting()) {
779 const gfx::ImageSkia* vpn_badge = rb.GetImageSkiaNamed(kVpnBadgeId); 793 const gfx::ImageSkia* vpn_badge =
780 const double animation = GetAnimation(); 794 rb.GetImageSkiaNamed(IDR_STATUSBAR_VPN_BADGE);
781 animating = true; 795 const double animation = GetAnimation();
782 // Even though this is the only place we use vpn_connecting_badge_, 796 animating = true;
783 // it is important that this is a member variable since we set a 797 // Even though this is the only place we use vpn_connecting_badge_,
784 // pointer to it and access that pointer in icon_->GenerateImage(). 798 // it is important that this is a member variable since we set a
785 vpn_connecting_badge_ = gfx::ImageSkiaOperations::CreateBlendedImage( 799 // pointer to it and access that pointer in icon_->GenerateImage().
786 GetEmptyImage(vpn_badge->size()), *vpn_badge, animation); 800 vpn_connecting_badge_ = gfx::ImageSkiaOperations::CreateBlendedImage(
787 icon_->set_bottom_left_badge(&vpn_connecting_badge_); 801 GetEmptyImage(vpn_badge->size()), *vpn_badge, animation);
788 } 802 icon_->set_bottom_left_badge(&vpn_connecting_badge_);
789 } 803 }
790 if (!animating) 804 if (!animating)
791 animation_connecting_.Stop(); 805 animation_connecting_.Stop();
792 806
793 // Set the text to display. 807 // Set the text to display.
794 if (network->type() == TYPE_ETHERNET) { 808 if (network->type() == TYPE_ETHERNET) {
795 if (mode_ == MENU_MODE) { 809 if (mode_ == MENU_MODE) {
796 text_ = l10n_util::GetStringFUTF16( 810 text_ = l10n_util::GetStringFUTF16(
797 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, 811 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
798 l10n_util::GetStringUTF16( 812 l10n_util::GetStringUTF16(
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 icon = new NetworkIcon(network->service_path(), color); 902 icon = new NetworkIcon(network->service_path(), color);
889 icon_map->insert(std::make_pair(network->service_path(), icon)); 903 icon_map->insert(std::make_pair(network->service_path(), icon));
890 } else { 904 } else {
891 icon = iter->second; 905 icon = iter->second;
892 } 906 }
893 // Update and return the icon's image. 907 // Update and return the icon's image.
894 icon->Update(); 908 icon->Update();
895 return icon->GetImage(); 909 return icon->GetImage();
896 } 910 }
897 911
898 // Returns an icon for a disconnected VPN.
899 const gfx::ImageSkia NetworkMenuIcon::GetVpnImage() {
900 static const gfx::ImageSkia *vpn_image = new gfx::ImageSkia(CreateVpnImage());
901 return *vpn_image;
902 }
903
904 const gfx::ImageSkia NetworkMenuIcon::GetImage(ImageType type, 912 const gfx::ImageSkia NetworkMenuIcon::GetImage(ImageType type,
905 int index, 913 int index,
906 ResourceColorTheme color) { 914 ResourceColorTheme color) {
907 int width, height = 0; 915 int width, height = 0;
908 gfx::ImageSkia* images = NULL; 916 gfx::ImageSkia* images = NULL;
909 if (type == NetworkMenuIcon::ARCS) { 917 if (type == NetworkMenuIcon::ARCS) {
910 if (index >= kNumArcsImages) 918 if (index >= kNumArcsImages)
911 return gfx::ImageSkia(); 919 return gfx::ImageSkia();
912 images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 920 images = ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
913 color == NetworkMenuIcon::COLOR_DARK ? 921 color == NetworkMenuIcon::COLOR_DARK ?
(...skipping 23 matching lines...) Expand all
937 const gfx::ImageSkia NetworkMenuIcon::GetConnectedImage(ImageType type, 945 const gfx::ImageSkia NetworkMenuIcon::GetConnectedImage(ImageType type,
938 ResourceColorTheme color) { 946 ResourceColorTheme color) {
939 return GetImage(type, NumImages(type) - 1, color); 947 return GetImage(type, NumImages(type) - 1, color);
940 } 948 }
941 949
942 int NetworkMenuIcon::NumImages(ImageType type) { 950 int NetworkMenuIcon::NumImages(ImageType type) {
943 return (type == ARCS) ? kNumArcsImages : kNumBarsImages; 951 return (type == ARCS) ? kNumArcsImages : kNumBarsImages;
944 } 952 }
945 953
946 } // chromeos 954 } // chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_menu_icon.h ('k') | chrome/browser/chromeos/system/ash_system_tray_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698