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

Side by Side Diff: ash/common/system/chromeos/network/network_icon.cc

Issue 2784133002: Cros system menu - Use WiFi strike-through image for "No networks" row (Closed)
Patch Set: docs Created 3 years, 8 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
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 "ash/common/system/chromeos/network/network_icon.h" 5 #include "ash/common/system/chromeos/network/network_icon.h"
6 6
7 #include "ash/common/system/chromeos/network/network_icon_animation.h" 7 #include "ash/common/system/chromeos/network/network_icon_animation.h"
8 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" 8 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h"
9 #include "ash/common/system/tray/tray_constants.h" 9 #include "ash/common/system/tray/tray_constants.h"
10 #include "ash/resources/grit/ash_resources.h" 10 #include "ash/resources/grit/ash_resources.h"
(...skipping 13 matching lines...) Expand all
24 #include "ui/base/resource/resource_bundle.h" 24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/color_palette.h" 26 #include "ui/gfx/color_palette.h"
27 #include "ui/gfx/geometry/insets.h" 27 #include "ui/gfx/geometry/insets.h"
28 #include "ui/gfx/geometry/rect.h" 28 #include "ui/gfx/geometry/rect.h"
29 #include "ui/gfx/geometry/size_conversions.h" 29 #include "ui/gfx/geometry/size_conversions.h"
30 #include "ui/gfx/image/canvas_image_source.h" 30 #include "ui/gfx/image/canvas_image_source.h"
31 #include "ui/gfx/image/image_skia_operations.h" 31 #include "ui/gfx/image/image_skia_operations.h"
32 #include "ui/gfx/image/image_skia_source.h" 32 #include "ui/gfx/image/image_skia_source.h"
33 #include "ui/gfx/paint_vector_icon.h" 33 #include "ui/gfx/paint_vector_icon.h"
34 #include "ui/gfx/scoped_canvas.h"
34 #include "ui/gfx/skia_util.h" 35 #include "ui/gfx/skia_util.h"
35 #include "ui/gfx/vector_icon_types.h" 36 #include "ui/gfx/vector_icon_types.h"
36 37
37 using chromeos::DeviceState; 38 using chromeos::DeviceState;
38 using chromeos::NetworkConnectionHandler; 39 using chromeos::NetworkConnectionHandler;
39 using chromeos::NetworkHandler; 40 using chromeos::NetworkHandler;
40 using chromeos::NetworkPortalDetector; 41 using chromeos::NetworkPortalDetector;
41 using chromeos::NetworkState; 42 using chromeos::NetworkState;
42 using chromeos::NetworkStateHandler; 43 using chromeos::NetworkStateHandler;
43 using chromeos::NetworkTypePattern; 44 using chromeos::NetworkTypePattern;
44 45
45 namespace ash { 46 namespace ash {
46 namespace network_icon { 47 namespace network_icon {
47 48
48 namespace { 49 namespace {
49 50
50 // Constants for offseting the badge displayed on top of the signal strength 51 // Constants for offseting the badge displayed on top of the signal strength
51 // icon. The badge will extend outside of the base icon bounds by these amounts. 52 // icon. The badge will extend outside of the base icon bounds by these amounts.
52 // All values are in dp. 53 // All values are in dp.
53 54
54 // The badge offsets are different depending on whether the icon is in the tray 55 // The badge offsets are different depending on whether the icon is in the tray
55 // or menu. 56 // or menu.
56 const int kTrayIconBadgeOffset = 3; 57 const int kTrayIconBadgeOffset = 3;
57 const int kMenuIconBadgeOffset = 2; 58 const int kMenuIconBadgeOffset = 2;
58 59
59 //------------------------------------------------------------------------------ 60 // Describes a single badge which is defined by a vector icon.
60 // Struct to pass icon badges to NetworkIconImageSource. 61 struct Badge {
61 struct Badges { 62 bool operator==(const Badge& other) const {
62 gfx::ImageSkia top_left; 63 return other.icon == icon && other.color == color;
63 gfx::ImageSkia top_right; 64 }
64 gfx::ImageSkia center; 65 bool operator!=(const Badge& other) const { return !(other == *this); }
65 gfx::ImageSkia bottom_left; 66
66 gfx::ImageSkia bottom_right; 67 const gfx::VectorIcon* icon;
68 SkColor color;
67 }; 69 };
68 70
69 //------------------------------------------------------------------------------ 71 //------------------------------------------------------------------------------
72 // Struct to pass a collection of badges to NetworkIconImageSource.
73 struct Badges {
74 Badge top_left = {};
75 Badge center = {};
76 Badge bottom_left = {};
77 Badge bottom_right = {};
78 };
79
80 //------------------------------------------------------------------------------
70 // class used for maintaining a map of network state and images. 81 // class used for maintaining a map of network state and images.
71 class NetworkIconImpl { 82 class NetworkIconImpl {
72 public: 83 public:
73 NetworkIconImpl(const std::string& path, IconType icon_type); 84 NetworkIconImpl(const std::string& path, IconType icon_type);
74 85
75 // Determines whether or not the associated network might be dirty and if so 86 // Determines whether or not the associated network might be dirty and if so
76 // updates and generates the icon. Does nothing if network no longer exists. 87 // updates and generates the icon. Does nothing if network no longer exists.
77 void Update(const chromeos::NetworkState* network); 88 void Update(const chromeos::NetworkState* network);
78 89
79 const gfx::ImageSkia& image() const { return image_; } 90 const gfx::ImageSkia& image() const { return image_; }
(...skipping 23 matching lines...) Expand all
103 // Defines color theme and VPN badging 114 // Defines color theme and VPN badging
104 const IconType icon_type_; 115 const IconType icon_type_;
105 116
106 // Cached state of the network when the icon was last generated. 117 // Cached state of the network when the icon was last generated.
107 std::string state_; 118 std::string state_;
108 119
109 // Cached strength index of the network when the icon was last generated. 120 // Cached strength index of the network when the icon was last generated.
110 int strength_index_; 121 int strength_index_;
111 122
112 // Cached technology badge for the network when the icon was last generated. 123 // Cached technology badge for the network when the icon was last generated.
113 gfx::ImageSkia technology_badge_; 124 Badge technology_badge_ = {};
114 125
115 // Cached vpn badge for the network when the icon was last generated. 126 // Cached vpn badge for the network when the icon was last generated.
116 gfx::ImageSkia vpn_badge_; 127 Badge vpn_badge_ = {};
117 128
118 // Cached roaming state of the network when the icon was last generated. 129 // Cached roaming state of the network when the icon was last generated.
119 std::string roaming_state_; 130 std::string roaming_state_;
120 131
121 // Cached portal state of the network when the icon was last generated. 132 // Cached portal state of the network when the icon was last generated.
122 bool behind_captive_portal_; 133 bool behind_captive_portal_;
123 134
124 // Generated icon image. 135 // Generated icon image.
125 gfx::ImageSkia image_; 136 gfx::ImageSkia image_;
126 137
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 auto* source = new NetworkIconImageSource(icon, badges); 217 auto* source = new NetworkIconImageSource(icon, badges);
207 return gfx::ImageSkia(source, source->size()); 218 return gfx::ImageSkia(source, source->size());
208 } 219 }
209 220
210 // gfx::CanvasImageSource: 221 // gfx::CanvasImageSource:
211 void Draw(gfx::Canvas* canvas) override { 222 void Draw(gfx::Canvas* canvas) override {
212 const int width = size().width(); 223 const int width = size().width();
213 const int height = size().height(); 224 const int height = size().height();
214 225
215 // The base icon is centered in both dimensions. 226 // The base icon is centered in both dimensions.
227 const int icon_x = (width - icon_.width()) / 2;
216 const int icon_y = (height - icon_.height()) / 2; 228 const int icon_y = (height - icon_.height()) / 2;
217 canvas->DrawImageInt(icon_, (width - icon_.width()) / 2, icon_y); 229 canvas->DrawImageInt(icon_, icon_x, icon_y);
218 230
219 // The badges are flush against the edges of the canvas, except at the top, 231 auto paint_badge = [&canvas](const Badge& badge, int x, int y,
220 // where the badge is only 1dp higher than the base image. 232 int badge_size = 0) {
233 gfx::ScopedCanvas scoped(canvas);
234 canvas->Translate(gfx::Vector2d(x, y));
235 if (badge_size)
236 gfx::PaintVectorIcon(canvas, *badge.icon, badge_size, badge.color);
237 else
238 gfx::PaintVectorIcon(canvas, *badge.icon, badge.color);
239 };
240
241 // The center badge is scaled and centered over the icon.
242 if (badges_.center.icon)
243 paint_badge(badges_.center, icon_x, icon_y, icon_.width());
244
245 // The other badges are flush against the edges of the canvas, except at the
246 // top, where the badge is only 1dp higher than the base image.
221 const int top_badge_y = icon_y - 1; 247 const int top_badge_y = icon_y - 1;
222 if (!badges_.top_left.isNull()) 248 if (badges_.top_left.icon)
223 canvas->DrawImageInt(badges_.top_left, 0, top_badge_y); 249 paint_badge(badges_.top_left, 0, top_badge_y);
224 if (!badges_.top_right.isNull()) { 250 if (badges_.bottom_left.icon) {
225 canvas->DrawImageInt(badges_.top_right, width - badges_.top_right.width(), 251 paint_badge(
226 top_badge_y); 252 badges_.bottom_left, 0,
253 height - gfx::GetDefaultSizeOfVectorIcon(*badges_.bottom_left.icon));
227 } 254 }
228 if (!badges_.center.isNull()) { 255 if (badges_.bottom_right.icon) {
229 canvas->DrawImageInt(badges_.center, (width - badges_.center.width()) / 2, 256 const int badge_size =
230 (height - badges_.center.height()) / 2); 257 gfx::GetDefaultSizeOfVectorIcon(*badges_.bottom_right.icon);
231 } 258 paint_badge(badges_.bottom_right, width - badge_size,
232 if (!badges_.bottom_left.isNull()) { 259 height - badge_size);
233 canvas->DrawImageInt(badges_.bottom_left, 0,
234 height - badges_.bottom_left.height());
235 }
236 if (!badges_.bottom_right.isNull()) {
237 canvas->DrawImageInt(badges_.bottom_right,
238 width - badges_.bottom_right.width(),
239 height - badges_.bottom_right.height());
240 } 260 }
241 } 261 }
242 262
243 bool HasRepresentationAtAllScales() const override { return true; } 263 bool HasRepresentationAtAllScales() const override { return true; }
244 264
245 private: 265 private:
246 NetworkIconImageSource(const gfx::ImageSkia& icon, const Badges& badges) 266 NetworkIconImageSource(const gfx::ImageSkia& icon, const Badges& badges)
247 : CanvasImageSource(GetSizeForBaseIconSize(icon.size()), false), 267 : CanvasImageSource(GetSizeForBaseIconSize(icon.size()), false),
248 icon_(icon), 268 icon_(icon),
249 badges_(badges) {} 269 badges_(badges) {}
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 } 431 }
412 432
413 gfx::ImageSkia GetImageForIndex(ImageType image_type, 433 gfx::ImageSkia GetImageForIndex(ImageType image_type,
414 IconType icon_type, 434 IconType icon_type,
415 int index) { 435 int index) {
416 gfx::CanvasImageSource* source = 436 gfx::CanvasImageSource* source =
417 new SignalStrengthImageSource(image_type, icon_type, index); 437 new SignalStrengthImageSource(image_type, icon_type, index);
418 return gfx::ImageSkia(source, source->size()); 438 return gfx::ImageSkia(source, source->size());
419 } 439 }
420 440
421 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, 441 // Returns an image to represent either a fully connected/enabled network or a
422 const std::string& network_type) { 442 // disconnected/disabled network.
443 const gfx::ImageSkia GetBasicImage(bool connected,
444 IconType icon_type,
445 const std::string& network_type) {
423 DCHECK_NE(shill::kTypeVPN, network_type); 446 DCHECK_NE(shill::kTypeVPN, network_type);
424 ImageType image_type = ImageTypeForNetworkType(network_type); 447 SignalStrengthImageSource* source = new SignalStrengthImageSource(
425 const int disconnected_index = 0; 448 ImageTypeForNetworkType(network_type), icon_type, kNumNetworkImages - 1);
426 return GetImageForIndex(image_type, icon_type, disconnected_index); 449 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size());
450 Badges badges;
451 if (!connected) {
452 badges.center = {&kNetworkBadgeOffIcon,
453 GetDefaultColorForIconType(icon_type)};
454 }
455 return NetworkIconImageSource::CreateImage(icon, badges);
427 } 456 }
428 457
429 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, 458 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type,
430 IconType icon_type, 459 IconType icon_type,
431 double animation) { 460 double animation) {
432 static const int kImageCount = kNumNetworkImages - 1; 461 static const int kImageCount = kNumNetworkImages - 1;
433 static gfx::ImageSkia* s_bars_images_dark[kImageCount]; 462 static gfx::ImageSkia* s_bars_images_dark[kImageCount];
434 static gfx::ImageSkia* s_bars_images_light[kImageCount]; 463 static gfx::ImageSkia* s_bars_images_light[kImageCount];
435 static gfx::ImageSkia* s_arcs_images_dark[kImageCount]; 464 static gfx::ImageSkia* s_arcs_images_dark[kImageCount];
436 static gfx::ImageSkia* s_arcs_images_light[kImageCount]; 465 static gfx::ImageSkia* s_arcs_images_light[kImageCount];
(...skipping 23 matching lines...) Expand all
460 // Lazily cache images. 489 // Lazily cache images.
461 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 490 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
462 // TODO(estade): update this icon to MD. See crbug.com/690176 491 // TODO(estade): update this icon to MD. See crbug.com/690176
463 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); 492 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN);
464 s_vpn_images[index] = new gfx::ImageSkia( 493 s_vpn_images[index] = new gfx::ImageSkia(
465 gfx::ImageSkiaOperations::CreateTransparentImage(*icon, animation)); 494 gfx::ImageSkiaOperations::CreateTransparentImage(*icon, animation));
466 } 495 }
467 return *s_vpn_images[index]; 496 return *s_vpn_images[index];
468 } 497 }
469 498
470 gfx::ImageSkia ConnectingVpnBadge(double animation, IconType icon_type) { 499 Badge ConnectingVpnBadge(double animation, IconType icon_type) {
471 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); 500 return {&kNetworkBadgeVpnIcon,
472 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; 501 SkColorSetA(GetDefaultColorForIconType(icon_type), 0xFF * animation)};
473 if (!s_vpn_badges[index]) {
474 // Lazily cache images.
475 gfx::ImageSkia badge = gfx::CreateVectorIcon(
476 kNetworkBadgeVpnIcon, GetDefaultColorForIconType(icon_type));
477 s_vpn_badges[index] = new gfx::ImageSkia(
478 gfx::ImageSkiaOperations::CreateTransparentImage(badge, animation));
479 }
480 return *s_vpn_badges[index];
481 } 502 }
482 503
483 int StrengthIndex(int strength) { 504 int StrengthIndex(int strength) {
484 // Return an index in the range [1, kNumNetworkImages - 1]. 505 // Return an index in the range [1, kNumNetworkImages - 1].
485 const float findex = (static_cast<float>(strength) / 100.0f) * 506 const float findex = (static_cast<float>(strength) / 100.0f) *
486 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); 507 nextafter(static_cast<float>(kNumNetworkImages - 1), 0);
487 int index = 1 + static_cast<int>(findex); 508 int index = 1 + static_cast<int>(findex);
488 index = std::max(std::min(index, kNumNetworkImages - 1), 1); 509 index = std::max(std::min(index, kNumNetworkImages - 1), 1);
489 return index; 510 return index;
490 } 511 }
491 512
492 gfx::ImageSkia BadgeForNetworkTechnology(const NetworkState* network, 513 Badge BadgeForNetworkTechnology(const NetworkState* network,
493 IconType icon_type) { 514 IconType icon_type) {
515 Badge badge = {nullptr, GetDefaultColorForIconType(icon_type)};
494 const std::string& technology = network->network_technology(); 516 const std::string& technology = network->network_technology();
495 const gfx::VectorIcon* icon = &gfx::kNoneIcon;
496 if (technology == shill::kNetworkTechnologyEvdo) { 517 if (technology == shill::kNetworkTechnologyEvdo) {
497 icon = &kNetworkBadgeTechnologyEvdoIcon; 518 badge.icon = &kNetworkBadgeTechnologyEvdoIcon;
498 } else if (technology == shill::kNetworkTechnology1Xrtt) { 519 } else if (technology == shill::kNetworkTechnology1Xrtt) {
499 icon = &kNetworkBadgeTechnology1xIcon; 520 badge.icon = &kNetworkBadgeTechnology1xIcon;
500 } else if (technology == shill::kNetworkTechnologyGprs || 521 } else if (technology == shill::kNetworkTechnologyGprs ||
501 technology == shill::kNetworkTechnologyGsm) { 522 technology == shill::kNetworkTechnologyGsm) {
502 icon = &kNetworkBadgeTechnologyGprsIcon; 523 badge.icon = &kNetworkBadgeTechnologyGprsIcon;
503 } else if (technology == shill::kNetworkTechnologyEdge) { 524 } else if (technology == shill::kNetworkTechnologyEdge) {
504 icon = &kNetworkBadgeTechnologyEdgeIcon; 525 badge.icon = &kNetworkBadgeTechnologyEdgeIcon;
505 } else if (technology == shill::kNetworkTechnologyUmts) { 526 } else if (technology == shill::kNetworkTechnologyUmts) {
506 icon = &kNetworkBadgeTechnology3gIcon; 527 badge.icon = &kNetworkBadgeTechnology3gIcon;
507 } else if (technology == shill::kNetworkTechnologyHspa) { 528 } else if (technology == shill::kNetworkTechnologyHspa) {
508 icon = &kNetworkBadgeTechnologyHspaIcon; 529 badge.icon = &kNetworkBadgeTechnologyHspaIcon;
509 } else if (technology == shill::kNetworkTechnologyHspaPlus) { 530 } else if (technology == shill::kNetworkTechnologyHspaPlus) {
510 icon = &kNetworkBadgeTechnologyHspaPlusIcon; 531 badge.icon = &kNetworkBadgeTechnologyHspaPlusIcon;
511 } else if (technology == shill::kNetworkTechnologyLte) { 532 } else if (technology == shill::kNetworkTechnologyLte) {
512 icon = &kNetworkBadgeTechnologyLteIcon; 533 badge.icon = &kNetworkBadgeTechnologyLteIcon;
513 } else if (technology == shill::kNetworkTechnologyLteAdvanced) { 534 } else if (technology == shill::kNetworkTechnologyLteAdvanced) {
514 icon = &kNetworkBadgeTechnologyLteAdvancedIcon; 535 badge.icon = &kNetworkBadgeTechnologyLteAdvancedIcon;
515 } else { 536 } else {
516 return gfx::ImageSkia(); 537 return {};
517 } 538 }
518 return gfx::CreateVectorIcon(*icon, GetDefaultColorForIconType(icon_type)); 539 return badge;
519 } 540 }
520 541
521 gfx::ImageSkia GetIcon(const NetworkState* network, 542 gfx::ImageSkia GetIcon(const NetworkState* network,
522 IconType icon_type, 543 IconType icon_type,
523 int strength_index) { 544 int strength_index) {
524 if (network->Matches(NetworkTypePattern::Ethernet())) { 545 if (network->Matches(NetworkTypePattern::Ethernet())) {
525 DCHECK_NE(ICON_TYPE_TRAY, icon_type); 546 DCHECK_NE(ICON_TYPE_TRAY, icon_type);
526 return gfx::CreateVectorIcon(kNetworkEthernetIcon, 547 return gfx::CreateVectorIcon(kNetworkEthernetIcon,
527 GetDefaultColorForIconType(ICON_TYPE_LIST)); 548 GetDefaultColorForIconType(ICON_TYPE_LIST));
528 } else if (network->Matches(NetworkTypePattern::Wireless())) { 549 } else if (network->Matches(NetworkTypePattern::Wireless())) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 599
579 //------------------------------------------------------------------------------ 600 //------------------------------------------------------------------------------
580 // NetworkIconImpl 601 // NetworkIconImpl
581 602
582 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) 603 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type)
583 : network_path_(path), 604 : network_path_(path),
584 icon_type_(icon_type), 605 icon_type_(icon_type),
585 strength_index_(-1), 606 strength_index_(-1),
586 behind_captive_portal_(false) { 607 behind_captive_portal_(false) {
587 // Default image 608 // Default image
588 image_ = GetDisconnectedImage(icon_type, shill::kTypeWifi); 609 image_ = GetBasicImage(false, icon_type, shill::kTypeWifi);
589 } 610 }
590 611
591 void NetworkIconImpl::Update(const NetworkState* network) { 612 void NetworkIconImpl::Update(const NetworkState* network) {
592 DCHECK(network); 613 DCHECK(network);
593 // Determine whether or not we need to update the icon. 614 // Determine whether or not we need to update the icon.
594 bool dirty = image_.isNull(); 615 bool dirty = image_.isNull();
595 616
596 // If the network state has changed, the icon needs updating. 617 // If the network state has changed, the icon needs updating.
597 if (state_ != network->connection_state()) { 618 if (state_ != network->connection_state()) {
598 state_ = network->connection_state(); 619 state_ = network->connection_state();
(...skipping 24 matching lines...) Expand all
623 int index = StrengthIndex(network->signal_strength()); 644 int index = StrengthIndex(network->signal_strength());
624 if (index != strength_index_) { 645 if (index != strength_index_) {
625 strength_index_ = index; 646 strength_index_ = index;
626 return true; 647 return true;
627 } 648 }
628 return false; 649 return false;
629 } 650 }
630 651
631 bool NetworkIconImpl::UpdateCellularState(const NetworkState* network) { 652 bool NetworkIconImpl::UpdateCellularState(const NetworkState* network) {
632 bool dirty = false; 653 bool dirty = false;
633 const gfx::ImageSkia technology_badge = 654 const Badge technology_badge = BadgeForNetworkTechnology(network, icon_type_);
634 BadgeForNetworkTechnology(network, icon_type_); 655 if (technology_badge == technology_badge_) {
635 if (!technology_badge.BackedBySameObjectAs(technology_badge_)) {
636 technology_badge_ = technology_badge; 656 technology_badge_ = technology_badge;
637 dirty = true; 657 dirty = true;
638 } 658 }
639 std::string roaming_state = network->roaming(); 659 std::string roaming_state = network->roaming();
640 if (roaming_state != roaming_state_) { 660 if (roaming_state != roaming_state_) {
641 roaming_state_ = roaming_state; 661 roaming_state_ = roaming_state;
642 dirty = true; 662 dirty = true;
643 } 663 }
644 return dirty; 664 return dirty;
645 } 665 }
(...skipping 11 matching lines...) Expand all
657 if (behind_captive_portal == behind_captive_portal_) 677 if (behind_captive_portal == behind_captive_portal_)
658 return false; 678 return false;
659 behind_captive_portal_ = behind_captive_portal; 679 behind_captive_portal_ = behind_captive_portal;
660 return true; 680 return true;
661 } 681 }
662 682
663 bool NetworkIconImpl::UpdateVPNBadge() { 683 bool NetworkIconImpl::UpdateVPNBadge() {
664 const NetworkState* vpn = 684 const NetworkState* vpn =
665 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( 685 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
666 NetworkTypePattern::VPN()); 686 NetworkTypePattern::VPN());
667 if (vpn && vpn_badge_.isNull()) { 687 Badge vpn_badge = {};
668 vpn_badge_ = gfx::CreateVectorIcon(kNetworkBadgeVpnIcon, 688 if (vpn)
669 GetDefaultColorForIconType(icon_type_)); 689 vpn_badge = {&kNetworkBadgeVpnIcon, GetDefaultColorForIconType(icon_type_)};
670 return true; 690 if (vpn_badge != vpn_badge_) {
671 } 691 vpn_badge_ = vpn_badge;
672 if (!vpn && !vpn_badge_.isNull()) {
673 vpn_badge_ = gfx::ImageSkia();
674 return true; 692 return true;
675 } 693 }
676 return false; 694 return false;
677 } 695 }
678 696
679 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { 697 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) {
680 DCHECK(network); 698 DCHECK(network);
681 699
682 const std::string& type = network->type(); 700 const std::string& type = network->type();
683 const SkColor icon_color = GetDefaultColorForIconType(icon_type_); 701 const SkColor icon_color = GetDefaultColorForIconType(icon_type_);
684 if (type == shill::kTypeWifi) { 702 if (type == shill::kTypeWifi) {
685 if (network->security_class() != shill::kSecurityNone && 703 if (network->security_class() != shill::kSecurityNone &&
686 IconTypeIsDark(icon_type_)) { 704 IconTypeIsDark(icon_type_)) {
687 badges->bottom_right = 705 badges->bottom_right = {&kNetworkBadgeSecureIcon, icon_color};
688 gfx::CreateVectorIcon(kNetworkBadgeSecureIcon, icon_color);
689 } 706 }
690 } else if (type == shill::kTypeWimax) { 707 } else if (type == shill::kTypeWimax) {
691 technology_badge_ = 708 technology_badge_ = {&kNetworkBadgeTechnology4gIcon, icon_color};
692 gfx::CreateVectorIcon(kNetworkBadgeTechnology4gIcon, icon_color);
693 } else if (type == shill::kTypeCellular) { 709 } else if (type == shill::kTypeCellular) {
694 if (network->roaming() == shill::kRoamingStateRoaming) { 710 if (network->roaming() == shill::kRoamingStateRoaming) {
695 // For networks that are always in roaming don't show roaming badge. 711 // For networks that are always in roaming don't show roaming badge.
696 const DeviceState* device = 712 const DeviceState* device =
697 NetworkHandler::Get()->network_state_handler()->GetDeviceState( 713 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
698 network->device_path()); 714 network->device_path());
699 LOG_IF(WARNING, !device) << "Could not find device state for " 715 LOG_IF(WARNING, !device) << "Could not find device state for "
700 << network->device_path(); 716 << network->device_path();
701 if (!device || !device->provider_requires_roaming()) { 717 if (!device || !device->provider_requires_roaming()) {
702 badges->bottom_right = 718 badges->bottom_right = {&kNetworkBadgeRoamingIcon, icon_color};
703 gfx::CreateVectorIcon(kNetworkBadgeRoamingIcon, icon_color);
704 } 719 }
705 } 720 }
706 } 721 }
707 if (!network->IsConnectingState()) { 722 if (!network->IsConnectingState()) {
708 badges->top_left = technology_badge_; 723 badges->top_left = technology_badge_;
709 badges->bottom_left = vpn_badge_; 724 badges->bottom_left = vpn_badge_;
710 } 725 }
711 726
712 if (behind_captive_portal_) { 727 if (behind_captive_portal_) {
713 badges->bottom_right = 728 badges->bottom_right = {&kNetworkBadgeCaptivePortalIcon, icon_color};
714 gfx::CreateVectorIcon(kNetworkBadgeCaptivePortalIcon, icon_color);
715 } 729 }
716 } 730 }
717 731
718 void NetworkIconImpl::GenerateImage(const NetworkState* network) { 732 void NetworkIconImpl::GenerateImage(const NetworkState* network) {
719 DCHECK(network); 733 DCHECK(network);
720 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); 734 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_);
721 Badges badges; 735 Badges badges;
722 GetBadges(network, &badges); 736 GetBadges(network, &badges);
723 image_ = NetworkIconImageSource::CreateImage(icon, badges); 737 image_ = NetworkIconImageSource::CreateImage(icon, badges);
724 } 738 }
(...skipping 20 matching lines...) Expand all
745 759
746 } // namespace 760 } // namespace
747 761
748 //------------------------------------------------------------------------------ 762 //------------------------------------------------------------------------------
749 // Public interface 763 // Public interface
750 764
751 gfx::ImageSkia GetImageForNetwork(const NetworkState* network, 765 gfx::ImageSkia GetImageForNetwork(const NetworkState* network,
752 IconType icon_type) { 766 IconType icon_type) {
753 DCHECK(network); 767 DCHECK(network);
754 if (!network->visible()) 768 if (!network->visible())
755 return GetDisconnectedImage(icon_type, network->type()); 769 return GetBasicImage(false, icon_type, network->type());
756 770
757 if (network->IsConnectingState()) 771 if (network->IsConnectingState())
758 return GetConnectingImage(icon_type, network->type()); 772 return GetConnectingImage(icon_type, network->type());
759 773
760 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); 774 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type);
761 return icon->image(); 775 return icon->image();
762 } 776 }
763 777
764 gfx::ImageSkia GetImageForConnectedMobileNetwork() { 778 gfx::ImageSkia GetBasicImageForWiFiNetwork(bool connected) {
765 ImageType image_type = ImageTypeForNetworkType(shill::kTypeWifi); 779 return GetBasicImage(connected, ICON_TYPE_LIST, shill::kTypeWifi);
766 const IconType icon_type = ICON_TYPE_LIST;
767 const int connected_index = kNumNetworkImages - 1;
768 return GetImageForIndex(image_type, icon_type, connected_index);
769 } 780 }
770 781
771 gfx::ImageSkia GetImageForDisconnectedCellNetwork() { 782 gfx::ImageSkia GetImageForDisconnectedCellNetwork() {
772 return GetDisconnectedImage(ICON_TYPE_LIST, shill::kTypeCellular); 783 return GetBasicImage(false, ICON_TYPE_LIST, shill::kTypeCellular);
773 } 784 }
774 785
775 gfx::ImageSkia GetImageForNewWifiNetwork(SkColor icon_color, 786 gfx::ImageSkia GetImageForNewWifiNetwork(SkColor icon_color,
776 SkColor badge_color) { 787 SkColor badge_color) {
777 SignalStrengthImageSource* source = 788 SignalStrengthImageSource* source =
778 new SignalStrengthImageSource(ImageTypeForNetworkType(shill::kTypeWifi), 789 new SignalStrengthImageSource(ImageTypeForNetworkType(shill::kTypeWifi),
779 ICON_TYPE_LIST, kNumNetworkImages - 1); 790 ICON_TYPE_LIST, kNumNetworkImages - 1);
780 source->set_color(icon_color); 791 source->set_color(icon_color);
781 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size()); 792 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size());
782 Badges badges; 793 Badges badges;
783 badges.bottom_right = 794 badges.bottom_right = {&kNetworkBadgeAddOtherIcon, badge_color};
784 gfx::CreateVectorIcon(kNetworkBadgeAddOtherIcon, badge_color);
785 return NetworkIconImageSource::CreateImage(icon, badges); 795 return NetworkIconImageSource::CreateImage(icon, badges);
786 } 796 }
787 797
788 gfx::ImageSkia GetImageForWifiChipState(bool enabled) {
789 SignalStrengthImageSource* source =
790 new SignalStrengthImageSource(ImageTypeForNetworkType(shill::kTypeWifi),
791 ICON_TYPE_LIST, kNumNetworkImages - 1);
792 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size());
793 Badges badges;
794 if (!enabled)
795 badges.center = gfx::CreateVectorIcon(kNetworkBadgeOffIcon, kMenuIconColor);
796 return NetworkIconImageSource::CreateImage(icon, badges);
797 }
798
799 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, 798 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network,
800 IconType icon_type) { 799 IconType icon_type) {
801 DCHECK(network); 800 DCHECK(network);
802 std::string activation_state = network->activation_state(); 801 std::string activation_state = network->activation_state();
803 if (icon_type == ICON_TYPE_LIST || icon_type == ICON_TYPE_MENU_LIST) { 802 if (icon_type == ICON_TYPE_LIST || icon_type == ICON_TYPE_MENU_LIST) {
804 // Show "<network>: [Connecting|Activating|Reconnecting]..." 803 // Show "<network>: [Connecting|Activating|Reconnecting]..."
805 // TODO(varkha): Remaining states should migrate to secondary status in the 804 // TODO(varkha): Remaining states should migrate to secondary status in the
806 // network item and no longer be part of the label. 805 // network item and no longer be part of the label.
807 // See http://crbug.com/676181 . 806 // See http://crbug.com/676181 .
808 if (network->IsReconnecting()) { 807 if (network->IsReconnecting()) {
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 if (!network) { 930 if (!network) {
932 // If no connecting network, check for cellular initializing. 931 // If no connecting network, check for cellular initializing.
933 int uninitialized_msg = GetCellularUninitializedMsg(); 932 int uninitialized_msg = GetCellularUninitializedMsg();
934 if (uninitialized_msg != 0) { 933 if (uninitialized_msg != 0) {
935 *image = GetConnectingImage(icon_type, shill::kTypeCellular); 934 *image = GetConnectingImage(icon_type, shill::kTypeCellular);
936 if (label) 935 if (label)
937 *label = l10n_util::GetStringUTF16(uninitialized_msg); 936 *label = l10n_util::GetStringUTF16(uninitialized_msg);
938 *animating = true; 937 *animating = true;
939 } else { 938 } else {
940 // Otherwise show the disconnected wifi icon. 939 // Otherwise show the disconnected wifi icon.
941 *image = GetDisconnectedImage(icon_type, shill::kTypeWifi); 940 *image = GetBasicImage(false, icon_type, shill::kTypeWifi);
942 if (label) { 941 if (label) {
943 *label = l10n_util::GetStringUTF16( 942 *label = l10n_util::GetStringUTF16(
944 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); 943 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED);
945 } 944 }
946 *animating = false; 945 *animating = false;
947 } 946 }
948 return; 947 return;
949 } 948 }
950 *animating = network->IsConnectingState(); 949 *animating = network->IsConnectingState();
951 // Get icon and label for connected or connecting network. 950 // Get icon and label for connected or connecting network.
(...skipping 12 matching lines...) Expand all
964 network_paths.insert((*iter)->path()); 963 network_paths.insert((*iter)->path());
965 } 964 }
966 PurgeIconMap(ICON_TYPE_TRAY, network_paths); 965 PurgeIconMap(ICON_TYPE_TRAY, network_paths);
967 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); 966 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths);
968 PurgeIconMap(ICON_TYPE_LIST, network_paths); 967 PurgeIconMap(ICON_TYPE_LIST, network_paths);
969 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths); 968 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths);
970 } 969 }
971 970
972 } // namespace network_icon 971 } // namespace network_icon
973 } // namespace ash 972 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/network/network_icon.h ('k') | ash/common/system/chromeos/network/tray_network.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698