Chromium Code Reviews| OLD | NEW |
|---|---|
| 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. |
|
tdanderson
2016/10/26 14:43:25
Can you please add BUG=626786 in the CL descriptio
Evan Stade
2016/10/26 14:49:01
Done.
| |
| 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/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/chromeos/network/network_icon_animation.h" | 8 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 9 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" | 9 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | |
| 11 #include "ash/resources/vector_icons/vector_icons.h" | |
| 10 #include "base/macros.h" | 12 #include "base/macros.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chromeos/network/device_state.h" | 14 #include "chromeos/network/device_state.h" |
| 13 #include "chromeos/network/network_connection_handler.h" | 15 #include "chromeos/network/network_connection_handler.h" |
| 14 #include "chromeos/network/network_state.h" | 16 #include "chromeos/network/network_state.h" |
| 15 #include "chromeos/network/network_state_handler.h" | 17 #include "chromeos/network/network_state_handler.h" |
| 16 #include "chromeos/network/portal_detector/network_portal_detector.h" | 18 #include "chromeos/network/portal_detector/network_portal_detector.h" |
| 17 #include "grit/ash_resources.h" | 19 #include "grit/ash_resources.h" |
| 18 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
| 19 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 20 #include "third_party/skia/include/core/SkPaint.h" | 22 #include "third_party/skia/include/core/SkPaint.h" |
| 21 #include "third_party/skia/include/core/SkPath.h" | 23 #include "third_party/skia/include/core/SkPath.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/base/resource/resource_bundle.h" | 25 #include "ui/base/resource/resource_bundle.h" |
| 24 #include "ui/base/webui/web_ui_util.h" | 26 #include "ui/base/webui/web_ui_util.h" |
| 25 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
| 26 #include "ui/gfx/color_palette.h" | 28 #include "ui/gfx/color_palette.h" |
| 27 #include "ui/gfx/geometry/insets.h" | 29 #include "ui/gfx/geometry/insets.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
| 29 #include "ui/gfx/geometry/size_conversions.h" | 31 #include "ui/gfx/geometry/size_conversions.h" |
| 30 #include "ui/gfx/image/canvas_image_source.h" | 32 #include "ui/gfx/image/canvas_image_source.h" |
| 31 #include "ui/gfx/image/image_skia_operations.h" | 33 #include "ui/gfx/image/image_skia_operations.h" |
| 32 #include "ui/gfx/image/image_skia_source.h" | 34 #include "ui/gfx/image/image_skia_source.h" |
| 33 #include "ui/gfx/paint_vector_icon.h" | 35 #include "ui/gfx/paint_vector_icon.h" |
| 34 #include "ui/gfx/skia_util.h" | 36 #include "ui/gfx/skia_util.h" |
| 35 #include "ui/gfx/vector_icons_public.h" | 37 #include "ui/gfx/vector_icon_types.h" |
| 36 | 38 |
| 37 using chromeos::DeviceState; | 39 using chromeos::DeviceState; |
| 38 using chromeos::NetworkConnectionHandler; | 40 using chromeos::NetworkConnectionHandler; |
| 39 using chromeos::NetworkHandler; | 41 using chromeos::NetworkHandler; |
| 40 using chromeos::NetworkPortalDetector; | 42 using chromeos::NetworkPortalDetector; |
| 41 using chromeos::NetworkState; | 43 using chromeos::NetworkState; |
| 42 using chromeos::NetworkStateHandler; | 44 using chromeos::NetworkStateHandler; |
| 43 using chromeos::NetworkTypePattern; | 45 using chromeos::NetworkTypePattern; |
| 44 | 46 |
| 45 namespace ash { | 47 namespace ash { |
| 46 namespace network_icon { | 48 namespace network_icon { |
| 47 | 49 |
| 48 namespace { | 50 namespace { |
| 49 | 51 |
| 50 // Constants for offseting the badge displayed on top of the signal strength | 52 // 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. | 53 // icon. The badge will extend outside of the base icon bounds by these amounts. |
| 52 // Only used for MD. All values are in dp. | 54 // Only used for MD. All values are in dp. |
| 53 | 55 |
| 54 // The badge offsets are different depending on whether the icon is in the tray | 56 // The badge offsets are different depending on whether the icon is in the tray |
| 55 // or menu. | 57 // or menu. |
| 56 const int kTrayIconBadgeOffset = 3; | 58 const int kTrayIconBadgeOffset = 3; |
| 57 const int kMenuIconBadgeOffset = 2; | 59 const int kMenuIconBadgeOffset = 2; |
| 58 | 60 |
| 59 // TODO(estade): use kTrayIconSize. See crbug.com/623987 | |
| 60 const int kTrayIconSide = 16; | |
| 61 | |
| 62 bool UseMd() { | 61 bool UseMd() { |
| 63 return MaterialDesignController::UseMaterialDesignSystemIcons(); | 62 return MaterialDesignController::UseMaterialDesignSystemIcons(); |
| 64 } | 63 } |
| 65 | 64 |
| 66 //------------------------------------------------------------------------------ | 65 //------------------------------------------------------------------------------ |
| 67 // Struct to pass icon badges to NetworkIconImageSource. | 66 // Struct to pass icon badges to NetworkIconImageSource. |
| 68 struct Badges { | 67 struct Badges { |
| 69 gfx::ImageSkia top_left; | 68 gfx::ImageSkia top_left; |
| 70 gfx::ImageSkia top_right; | 69 gfx::ImageSkia top_right; |
| 71 gfx::ImageSkia bottom_left; | 70 gfx::ImageSkia bottom_left; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 const double kConnectingImageAlpha = 0.5; | 185 const double kConnectingImageAlpha = 0.5; |
| 187 | 186 |
| 188 // Images for strength arcs for wireless networks or strength bars for cellular | 187 // Images for strength arcs for wireless networks or strength bars for cellular |
| 189 // networks. | 188 // networks. |
| 190 const int kNumNetworkImages = 5; | 189 const int kNumNetworkImages = 5; |
| 191 | 190 |
| 192 // Number of discrete images to use for alpha fade animation | 191 // Number of discrete images to use for alpha fade animation |
| 193 const int kNumFadeImages = 10; | 192 const int kNumFadeImages = 10; |
| 194 | 193 |
| 195 SkColor GetDefaultColorForIconType(IconType icon_type) { | 194 SkColor GetDefaultColorForIconType(IconType icon_type) { |
| 196 // TODO(estade): use kTrayIconColor and kMenuIconColor. | 195 return icon_type == ICON_TYPE_TRAY ? kTrayIconColor : kMenuIconColor; |
| 197 return icon_type == ICON_TYPE_TRAY ? SK_ColorWHITE : gfx::kChromeIconGrey; | |
| 198 } | 196 } |
| 199 | 197 |
| 200 bool IconTypeIsDark(IconType icon_type) { | 198 bool IconTypeIsDark(IconType icon_type) { |
| 201 return (icon_type != ICON_TYPE_TRAY); | 199 return (icon_type != ICON_TYPE_TRAY); |
| 202 } | 200 } |
| 203 | 201 |
| 204 bool IconTypeHasVPNBadge(IconType icon_type) { | 202 bool IconTypeHasVPNBadge(IconType icon_type) { |
| 205 return (icon_type != ICON_TYPE_LIST); | 203 return (icon_type != ICON_TYPE_LIST); |
| 206 } | 204 } |
| 207 | 205 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 | 280 |
| 283 private: | 281 private: |
| 284 NetworkIconImageSourceMd(const gfx::ImageSkia& icon, const Badges& badges) | 282 NetworkIconImageSourceMd(const gfx::ImageSkia& icon, const Badges& badges) |
| 285 : CanvasImageSource(GetSizeForBaseIconSize(icon.size()), false), | 283 : CanvasImageSource(GetSizeForBaseIconSize(icon.size()), false), |
| 286 icon_(icon), | 284 icon_(icon), |
| 287 badges_(badges) {} | 285 badges_(badges) {} |
| 288 ~NetworkIconImageSourceMd() override {} | 286 ~NetworkIconImageSourceMd() override {} |
| 289 | 287 |
| 290 static gfx::Size GetSizeForBaseIconSize(const gfx::Size& base_icon_size) { | 288 static gfx::Size GetSizeForBaseIconSize(const gfx::Size& base_icon_size) { |
| 291 gfx::Size size = base_icon_size; | 289 gfx::Size size = base_icon_size; |
| 292 const int badge_offset = base_icon_size.width() == kTrayIconSide | 290 const int badge_offset = base_icon_size.width() == kTrayIconSize |
| 293 ? kTrayIconBadgeOffset | 291 ? kTrayIconBadgeOffset |
| 294 : kMenuIconBadgeOffset; | 292 : kMenuIconBadgeOffset; |
| 295 size.Enlarge(badge_offset * 2, badge_offset * 2); | 293 size.Enlarge(badge_offset * 2, badge_offset * 2); |
| 296 return size; | 294 return size; |
| 297 } | 295 } |
| 298 | 296 |
| 299 const gfx::ImageSkia icon_; | 297 const gfx::ImageSkia icon_; |
| 300 const Badges badges_; | 298 const Badges badges_; |
| 301 | 299 |
| 302 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSourceMd); | 300 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSourceMd); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 329 if (image_type_ == ARCS) | 327 if (image_type_ == ARCS) |
| 330 DrawArcs(canvas); | 328 DrawArcs(canvas); |
| 331 else | 329 else |
| 332 DrawBars(canvas); | 330 DrawBars(canvas); |
| 333 } | 331 } |
| 334 | 332 |
| 335 bool HasRepresentationAtAllScales() const override { return true; } | 333 bool HasRepresentationAtAllScales() const override { return true; } |
| 336 | 334 |
| 337 private: | 335 private: |
| 338 static gfx::Size GetSizeForIconType(IconType icon_type) { | 336 static gfx::Size GetSizeForIconType(IconType icon_type) { |
| 339 return icon_type == ICON_TYPE_TRAY | 337 int side = icon_type == ICON_TYPE_TRAY ? kTrayIconSize : kMenuIconSize; |
| 340 ? gfx::Size(kTrayIconSide, kTrayIconSide) | 338 return gfx::Size(side, side); |
| 341 // TODO(estade): use kMenuIconSize instead of 20. | |
| 342 : gfx::Size(20, 20); | |
| 343 } | 339 } |
| 344 | 340 |
| 345 void DrawArcs(gfx::Canvas* canvas) { | 341 void DrawArcs(gfx::Canvas* canvas) { |
| 346 gfx::RectF oval_bounds((gfx::Rect(size()))); | 342 gfx::RectF oval_bounds((gfx::Rect(size()))); |
| 347 oval_bounds.Inset(gfx::Insets(kIconInset)); | 343 oval_bounds.Inset(gfx::Insets(kIconInset)); |
| 348 // Double the width and height. The new midpoint should be the former | 344 // Double the width and height. The new midpoint should be the former |
| 349 // bottom center. | 345 // bottom center. |
| 350 oval_bounds.Inset(-oval_bounds.width() / 2, 0, -oval_bounds.width() / 2, | 346 oval_bounds.Inset(-oval_bounds.width() / 2, 0, -oval_bounds.width() / 2, |
| 351 -oval_bounds.height()); | 347 -oval_bounds.height()); |
| 352 | 348 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 529 } | 525 } |
| 530 return *s_vpn_images[index]; | 526 return *s_vpn_images[index]; |
| 531 } | 527 } |
| 532 | 528 |
| 533 gfx::ImageSkia ConnectingVpnBadge(double animation, IconType icon_type) { | 529 gfx::ImageSkia ConnectingVpnBadge(double animation, IconType icon_type) { |
| 534 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); | 530 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); |
| 535 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; | 531 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; |
| 536 if (!s_vpn_badges[index]) { | 532 if (!s_vpn_badges[index]) { |
| 537 // Lazily cache images. | 533 // Lazily cache images. |
| 538 gfx::ImageSkia badge = | 534 gfx::ImageSkia badge = |
| 539 UseMd() ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_VPN, | 535 UseMd() ? gfx::CreateVectorIcon(kNetworkBadgeVpnIcon, |
| 540 GetDefaultColorForIconType(icon_type)) | 536 GetDefaultColorForIconType(icon_type)) |
| 541 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 537 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 542 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | 538 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); |
| 543 s_vpn_badges[index] = new gfx::ImageSkia( | 539 s_vpn_badges[index] = new gfx::ImageSkia( |
| 544 gfx::ImageSkiaOperations::CreateTransparentImage(badge, animation)); | 540 gfx::ImageSkiaOperations::CreateTransparentImage(badge, animation)); |
| 545 } | 541 } |
| 546 return *s_vpn_badges[index]; | 542 return *s_vpn_badges[index]; |
| 547 } | 543 } |
| 548 | 544 |
| 549 int StrengthIndex(int strength) { | 545 int StrengthIndex(int strength) { |
| 550 // Return an index in the range [1, kNumNetworkImages - 1]. | 546 // Return an index in the range [1, kNumNetworkImages - 1]. |
| 551 const float findex = (static_cast<float>(strength) / 100.0f) * | 547 const float findex = (static_cast<float>(strength) / 100.0f) * |
| 552 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); | 548 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); |
| 553 int index = 1 + static_cast<int>(findex); | 549 int index = 1 + static_cast<int>(findex); |
| 554 index = std::max(std::min(index, kNumNetworkImages - 1), 1); | 550 index = std::max(std::min(index, kNumNetworkImages - 1), 1); |
| 555 return index; | 551 return index; |
| 556 } | 552 } |
| 557 | 553 |
| 558 gfx::ImageSkia BadgeForNetworkTechnology(const NetworkState* network, | 554 gfx::ImageSkia BadgeForNetworkTechnology(const NetworkState* network, |
| 559 IconType icon_type) { | 555 IconType icon_type) { |
| 560 const std::string& technology = network->network_technology(); | 556 const std::string& technology = network->network_technology(); |
| 561 if (UseMd()) { | 557 if (UseMd()) { |
| 562 gfx::VectorIconId id = gfx::VectorIconId::VECTOR_ICON_NONE; | 558 const gfx::VectorIcon* icon = &gfx::kNoneIcon; |
| 563 if (technology == shill::kNetworkTechnologyEvdo) { | 559 if (technology == shill::kNetworkTechnologyEvdo) { |
| 564 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_EVDO; | 560 icon = &kNetworkBadgeTechnologyEvdoIcon; |
| 565 } else if (technology == shill::kNetworkTechnology1Xrtt) { | 561 } else if (technology == shill::kNetworkTechnology1Xrtt) { |
| 566 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_1X; | 562 icon = &kNetworkBadgeTechnology1xIcon; |
| 567 } else if (technology == shill::kNetworkTechnologyGprs || | 563 } else if (technology == shill::kNetworkTechnologyGprs || |
| 568 technology == shill::kNetworkTechnologyGsm) { | 564 technology == shill::kNetworkTechnologyGsm) { |
| 569 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_GPRS; | 565 icon = &kNetworkBadgeTechnologyGprsIcon; |
| 570 } else if (technology == shill::kNetworkTechnologyEdge) { | 566 } else if (technology == shill::kNetworkTechnologyEdge) { |
| 571 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_EDGE; | 567 icon = &kNetworkBadgeTechnologyEdgeIcon; |
| 572 } else if (technology == shill::kNetworkTechnologyUmts) { | 568 } else if (technology == shill::kNetworkTechnologyUmts) { |
| 573 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_3G; | 569 icon = &kNetworkBadgeTechnology3gIcon; |
| 574 } else if (technology == shill::kNetworkTechnologyHspa) { | 570 } else if (technology == shill::kNetworkTechnologyHspa) { |
| 575 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_HSPA; | 571 icon = &kNetworkBadgeTechnologyHspaIcon; |
| 576 } else if (technology == shill::kNetworkTechnologyHspaPlus) { | 572 } else if (technology == shill::kNetworkTechnologyHspaPlus) { |
| 577 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_HSPA_PLUS; | 573 icon = &kNetworkBadgeTechnologyHspaPlusIcon; |
| 578 } else if (technology == shill::kNetworkTechnologyLte) { | 574 } else if (technology == shill::kNetworkTechnologyLte) { |
| 579 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_LTE; | 575 icon = &kNetworkBadgeTechnologyLteIcon; |
| 580 } else if (technology == shill::kNetworkTechnologyLteAdvanced) { | 576 } else if (technology == shill::kNetworkTechnologyLteAdvanced) { |
| 581 id = gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_LTE_ADVANCED; | 577 icon = &kNetworkBadgeTechnologyLteAdvancedIcon; |
| 582 } else { | 578 } else { |
| 583 return gfx::ImageSkia(); | 579 return gfx::ImageSkia(); |
| 584 } | 580 } |
| 585 return gfx::CreateVectorIcon(id, GetDefaultColorForIconType(icon_type)); | 581 return gfx::CreateVectorIcon(*icon, GetDefaultColorForIconType(icon_type)); |
| 586 } | 582 } |
| 587 | 583 |
| 588 int id = -1; | 584 int id = -1; |
| 589 if (technology == shill::kNetworkTechnologyEvdo) { | 585 if (technology == shill::kNetworkTechnologyEvdo) { |
| 590 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_EVDO_DARK | 586 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_EVDO_DARK |
| 591 : IDR_AURA_UBER_TRAY_NETWORK_EVDO_LIGHT; | 587 : IDR_AURA_UBER_TRAY_NETWORK_EVDO_LIGHT; |
| 592 } else if (technology == shill::kNetworkTechnology1Xrtt) { | 588 } else if (technology == shill::kNetworkTechnology1Xrtt) { |
| 593 id = IDR_AURA_UBER_TRAY_NETWORK_1X; | 589 id = IDR_AURA_UBER_TRAY_NETWORK_1X; |
| 594 } else if (technology == shill::kNetworkTechnologyGprs) { | 590 } else if (technology == shill::kNetworkTechnologyGprs) { |
| 595 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK | 591 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 622 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | 618 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); |
| 623 } | 619 } |
| 624 | 620 |
| 625 gfx::ImageSkia GetIcon(const NetworkState* network, | 621 gfx::ImageSkia GetIcon(const NetworkState* network, |
| 626 IconType icon_type, | 622 IconType icon_type, |
| 627 int strength_index) { | 623 int strength_index) { |
| 628 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 624 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 629 if (network->Matches(NetworkTypePattern::Ethernet())) { | 625 if (network->Matches(NetworkTypePattern::Ethernet())) { |
| 630 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 626 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
| 631 return UseMd() ? gfx::CreateVectorIcon( | 627 return UseMd() ? gfx::CreateVectorIcon( |
| 632 gfx::VectorIconId::NETWORK_ETHERNET, | 628 kNetworkEthernetIcon, |
| 633 GetDefaultColorForIconType(ICON_TYPE_LIST)) | 629 GetDefaultColorForIconType(ICON_TYPE_LIST)) |
| 634 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | 630 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); |
| 635 } else if (network->Matches(NetworkTypePattern::Wireless())) { | 631 } else if (network->Matches(NetworkTypePattern::Wireless())) { |
| 636 DCHECK(strength_index > 0); | 632 DCHECK(strength_index > 0); |
| 637 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, | 633 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, |
| 638 strength_index); | 634 strength_index); |
| 639 } else if (network->Matches(NetworkTypePattern::VPN())) { | 635 } else if (network->Matches(NetworkTypePattern::VPN())) { |
| 640 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 636 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
| 641 return GetVpnImage(); | 637 return GetVpnImage(); |
| 642 } | 638 } |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 770 behind_captive_portal_ = behind_captive_portal; | 766 behind_captive_portal_ = behind_captive_portal; |
| 771 return true; | 767 return true; |
| 772 } | 768 } |
| 773 | 769 |
| 774 bool NetworkIconImpl::UpdateVPNBadge() { | 770 bool NetworkIconImpl::UpdateVPNBadge() { |
| 775 const NetworkState* vpn = | 771 const NetworkState* vpn = |
| 776 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( | 772 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( |
| 777 NetworkTypePattern::VPN()); | 773 NetworkTypePattern::VPN()); |
| 778 if (vpn && vpn_badge_.isNull()) { | 774 if (vpn && vpn_badge_.isNull()) { |
| 779 vpn_badge_ = | 775 vpn_badge_ = |
| 780 UseMd() ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_VPN, | 776 UseMd() ? gfx::CreateVectorIcon(kNetworkBadgeVpnIcon, |
| 781 GetDefaultColorForIconType(icon_type_)) | 777 GetDefaultColorForIconType(icon_type_)) |
| 782 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 778 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 783 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | 779 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); |
| 784 return true; | 780 return true; |
| 785 } | 781 } |
| 786 if (!vpn && !vpn_badge_.isNull()) { | 782 if (!vpn && !vpn_badge_.isNull()) { |
| 787 vpn_badge_ = gfx::ImageSkia(); | 783 vpn_badge_ = gfx::ImageSkia(); |
| 788 return true; | 784 return true; |
| 789 } | 785 } |
| 790 return false; | 786 return false; |
| 791 } | 787 } |
| 792 | 788 |
| 793 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { | 789 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { |
| 794 DCHECK(network); | 790 DCHECK(network); |
| 795 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 791 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 796 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 792 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 797 | 793 |
| 798 const std::string& type = network->type(); | 794 const std::string& type = network->type(); |
| 799 const SkColor icon_color = GetDefaultColorForIconType(icon_type_); | 795 const SkColor icon_color = GetDefaultColorForIconType(icon_type_); |
| 800 if (type == shill::kTypeWifi) { | 796 if (type == shill::kTypeWifi) { |
| 801 if (network->security_class() != shill::kSecurityNone && | 797 if (network->security_class() != shill::kSecurityNone && |
| 802 IconTypeIsDark(icon_type_)) { | 798 IconTypeIsDark(icon_type_)) { |
| 803 badges->bottom_right = | 799 badges->bottom_right = |
| 804 UseMd() | 800 UseMd() |
| 805 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_SECURE, | 801 ? gfx::CreateVectorIcon(kNetworkBadgeSecureIcon, icon_color) |
| 806 icon_color) | |
| 807 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK); | 802 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK); |
| 808 } | 803 } |
| 809 } else if (type == shill::kTypeWimax) { | 804 } else if (type == shill::kTypeWimax) { |
| 810 technology_badge_ = | 805 technology_badge_ = |
| 811 UseMd() | 806 UseMd() |
| 812 ? gfx::CreateVectorIcon( | 807 ? gfx::CreateVectorIcon(kNetworkBadgeTechnology4gIcon, icon_color) |
| 813 gfx::VectorIconId::NETWORK_BADGE_TECHNOLOGY_4G, icon_color) | |
| 814 : *rb.GetImageSkiaNamed(IconTypeIsDark(icon_type_) | 808 : *rb.GetImageSkiaNamed(IconTypeIsDark(icon_type_) |
| 815 ? IDR_AURA_UBER_TRAY_NETWORK_4G_DARK | 809 ? IDR_AURA_UBER_TRAY_NETWORK_4G_DARK |
| 816 : IDR_AURA_UBER_TRAY_NETWORK_4G_LIGHT); | 810 : IDR_AURA_UBER_TRAY_NETWORK_4G_LIGHT); |
| 817 } else if (type == shill::kTypeCellular) { | 811 } else if (type == shill::kTypeCellular) { |
| 818 if (network->roaming() == shill::kRoamingStateRoaming) { | 812 if (network->roaming() == shill::kRoamingStateRoaming) { |
| 819 // For networks that are always in roaming don't show roaming badge. | 813 // For networks that are always in roaming don't show roaming badge. |
| 820 const DeviceState* device = | 814 const DeviceState* device = |
| 821 handler->GetDeviceState(network->device_path()); | 815 handler->GetDeviceState(network->device_path()); |
| 822 LOG_IF(WARNING, !device) << "Could not find device state for " | 816 LOG_IF(WARNING, !device) << "Could not find device state for " |
| 823 << network->device_path(); | 817 << network->device_path(); |
| 824 if (!device || !device->provider_requires_roaming()) { | 818 if (!device || !device->provider_requires_roaming()) { |
| 825 badges->bottom_right = | 819 badges->bottom_right = |
| 826 UseMd() ? gfx::CreateVectorIcon( | 820 UseMd() |
| 827 gfx::VectorIconId::NETWORK_BADGE_ROAMING, icon_color) | 821 ? gfx::CreateVectorIcon(kNetworkBadgeRoamingIcon, icon_color) |
| 828 : *rb.GetImageSkiaNamed( | 822 : *rb.GetImageSkiaNamed( |
| 829 IconTypeIsDark(icon_type_) | 823 IconTypeIsDark(icon_type_) |
| 830 ? IDR_AURA_UBER_TRAY_NETWORK_ROAMING_DARK | 824 ? IDR_AURA_UBER_TRAY_NETWORK_ROAMING_DARK |
| 831 : IDR_AURA_UBER_TRAY_NETWORK_ROAMING_LIGHT); | 825 : IDR_AURA_UBER_TRAY_NETWORK_ROAMING_LIGHT); |
| 832 } | 826 } |
| 833 } | 827 } |
| 834 } | 828 } |
| 835 if (!network->IsConnectingState()) { | 829 if (!network->IsConnectingState()) { |
| 836 badges->top_left = technology_badge_; | 830 badges->top_left = technology_badge_; |
| 837 badges->bottom_left = vpn_badge_; | 831 badges->bottom_left = vpn_badge_; |
| 838 } | 832 } |
| 839 | 833 |
| 840 if (behind_captive_portal_) { | 834 if (behind_captive_portal_) { |
| 841 badges->bottom_right = | 835 badges->bottom_right = |
| 842 UseMd() | 836 UseMd() |
| 843 ? gfx::CreateVectorIcon( | 837 ? gfx::CreateVectorIcon(kNetworkBadgeCaptivePortalIcon, icon_color) |
| 844 gfx::VectorIconId::NETWORK_BADGE_CAPTIVE_PORTAL, icon_color) | |
| 845 : *rb.GetImageSkiaNamed( | 838 : *rb.GetImageSkiaNamed( |
| 846 IconTypeIsDark(icon_type_) | 839 IconTypeIsDark(icon_type_) |
| 847 ? IDR_AURA_UBER_TRAY_NETWORK_PORTAL_DARK | 840 ? IDR_AURA_UBER_TRAY_NETWORK_PORTAL_DARK |
| 848 : IDR_AURA_UBER_TRAY_NETWORK_PORTAL_LIGHT); | 841 : IDR_AURA_UBER_TRAY_NETWORK_PORTAL_LIGHT); |
| 849 } | 842 } |
| 850 } | 843 } |
| 851 | 844 |
| 852 void NetworkIconImpl::GenerateImage(const NetworkState* network) { | 845 void NetworkIconImpl::GenerateImage(const NetworkState* network) { |
| 853 DCHECK(network); | 846 DCHECK(network); |
| 854 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); | 847 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 909 } | 902 } |
| 910 | 903 |
| 911 gfx::ImageSkia GetImageForNewWifiNetwork(SkColor icon_color, | 904 gfx::ImageSkia GetImageForNewWifiNetwork(SkColor icon_color, |
| 912 SkColor badge_color) { | 905 SkColor badge_color) { |
| 913 SignalStrengthImageSource* source = | 906 SignalStrengthImageSource* source = |
| 914 new SignalStrengthImageSource(ImageTypeForNetworkType(shill::kTypeWifi), | 907 new SignalStrengthImageSource(ImageTypeForNetworkType(shill::kTypeWifi), |
| 915 ICON_TYPE_LIST, kNumNetworkImages - 1); | 908 ICON_TYPE_LIST, kNumNetworkImages - 1); |
| 916 source->set_color(icon_color); | 909 source->set_color(icon_color); |
| 917 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size()); | 910 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size()); |
| 918 Badges badges; | 911 Badges badges; |
| 919 badges.bottom_right = gfx::CreateVectorIcon( | 912 badges.bottom_right = |
| 920 gfx::VectorIconId::NETWORK_BADGE_ADD_OTHER, badge_color); | 913 gfx::CreateVectorIcon(kNetworkBadgeAddOtherIcon, badge_color); |
| 921 return NetworkIconImageSourceMd::CreateImage(icon, badges); | 914 return NetworkIconImageSourceMd::CreateImage(icon, badges); |
| 922 } | 915 } |
| 923 | 916 |
| 924 gfx::ImageSkia GetVpnImage() { | 917 gfx::ImageSkia GetVpnImage() { |
| 925 return UseMd() | 918 return UseMd() |
| 926 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_VPN, | 919 ? gfx::CreateVectorIcon(kNetworkVpnIcon, |
| 927 GetDefaultColorForIconType(ICON_TYPE_LIST)) | 920 GetDefaultColorForIconType(ICON_TYPE_LIST)) |
| 928 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 921 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 929 IDR_AURA_UBER_TRAY_NETWORK_VPN); | 922 IDR_AURA_UBER_TRAY_NETWORK_VPN); |
| 930 } | 923 } |
| 931 | 924 |
| 932 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, | 925 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, |
| 933 IconType icon_type) { | 926 IconType icon_type) { |
| 934 DCHECK(network); | 927 DCHECK(network); |
| 935 std::string activation_state = network->activation_state(); | 928 std::string activation_state = network->activation_state(); |
| 936 if (icon_type == ICON_TYPE_LIST) { | 929 if (icon_type == ICON_TYPE_LIST) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 iter != networks.end(); ++iter) { | 1086 iter != networks.end(); ++iter) { |
| 1094 network_paths.insert((*iter)->path()); | 1087 network_paths.insert((*iter)->path()); |
| 1095 } | 1088 } |
| 1096 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 1089 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
| 1097 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 1090 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
| 1098 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 1091 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
| 1099 } | 1092 } |
| 1100 | 1093 |
| 1101 } // namespace network_icon | 1094 } // namespace network_icon |
| 1102 } // namespace ash | 1095 } // namespace ash |
| OLD | NEW |