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. |
| 4 | 4 |
| 5 #include "ui/chromeos/network/network_icon.h" | 5 #include "ui/chromeos/network/network_icon.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "chromeos/network/device_state.h" | 9 #include "chromeos/network/device_state.h" |
| 10 #include "chromeos/network/network_connection_handler.h" | 10 #include "chromeos/network/network_connection_handler.h" |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 479 | 479 |
| 480 if (index < 0 || index >= kNumNetworkImages) | 480 if (index < 0 || index >= kNumNetworkImages) |
| 481 return gfx::ImageSkia(); | 481 return gfx::ImageSkia(); |
| 482 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); | 482 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); |
| 483 int width = images->width(); | 483 int width = images->width(); |
| 484 int height = images->height() / kNumNetworkImages; | 484 int height = images->height() / kNumNetworkImages; |
| 485 return gfx::ImageSkiaOperations::ExtractSubset(*images, | 485 return gfx::ImageSkiaOperations::ExtractSubset(*images, |
| 486 gfx::Rect(0, index * height, width, height)); | 486 gfx::Rect(0, index * height, width, height)); |
| 487 } | 487 } |
| 488 | 488 |
| 489 gfx::ImageSkia GetConnectedImage(IconType icon_type, | |
| 490 const std::string& network_type) { | |
| 491 if (network_type == shill::kTypeVPN) { | |
| 492 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 493 IDR_AURA_UBER_TRAY_NETWORK_VPN); | |
| 494 } | |
| 495 ImageType image_type = ImageTypeForNetworkType(network_type); | |
| 496 const int connected_index = kNumNetworkImages - 1; | |
| 497 return GetImageForIndex(image_type, icon_type, connected_index); | |
| 498 } | |
| 499 | |
| 500 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, | 489 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, |
| 501 const std::string& network_type) { | 490 const std::string& network_type) { |
| 502 if (network_type == shill::kTypeVPN) { | 491 DCHECK_NE(shill::kTypeVPN, network_type); |
| 503 // Note: same as connected image, shouldn't normally be seen. | |
|
Evan Stade
2016/09/13 23:54:31
AFAICT this comment was wrong, and this code path
| |
| 504 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 505 IDR_AURA_UBER_TRAY_NETWORK_VPN); | |
| 506 } | |
| 507 ImageType image_type = ImageTypeForNetworkType(network_type); | 492 ImageType image_type = ImageTypeForNetworkType(network_type); |
| 508 const int disconnected_index = 0; | 493 const int disconnected_index = 0; |
| 509 return GetImageForIndex(image_type, icon_type, disconnected_index); | 494 return GetImageForIndex(image_type, icon_type, disconnected_index); |
| 510 } | 495 } |
| 511 | 496 |
| 512 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, | 497 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, |
| 513 IconType icon_type, | 498 IconType icon_type, |
| 514 double animation) { | 499 double animation) { |
| 515 static const int kImageCount = kNumNetworkImages - 1; | 500 static const int kImageCount = kNumNetworkImages - 1; |
| 516 static gfx::ImageSkia* s_bars_images_dark[kImageCount]; | 501 static gfx::ImageSkia* s_bars_images_dark[kImageCount]; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 542 if (!s_vpn_images[index]) { | 527 if (!s_vpn_images[index]) { |
| 543 // Lazily cache images. | 528 // Lazily cache images. |
| 544 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 529 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 545 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); | 530 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); |
| 546 s_vpn_images[index] = new gfx::ImageSkia( | 531 s_vpn_images[index] = new gfx::ImageSkia( |
| 547 gfx::ImageSkiaOperations::CreateTransparentImage(*icon, animation)); | 532 gfx::ImageSkiaOperations::CreateTransparentImage(*icon, animation)); |
| 548 } | 533 } |
| 549 return *s_vpn_images[index]; | 534 return *s_vpn_images[index]; |
| 550 } | 535 } |
| 551 | 536 |
| 552 gfx::ImageSkia ConnectingVpnBadge(double animation) { | 537 gfx::ImageSkia ConnectingVpnBadge(double animation, IconType icon_type) { |
| 553 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); | 538 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); |
| 554 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; | 539 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; |
| 555 if (!s_vpn_badges[index]) { | 540 if (!s_vpn_badges[index]) { |
| 556 // Lazily cache images. | 541 // Lazily cache images. |
| 557 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 542 gfx::ImageSkia badge = |
| 558 gfx::ImageSkia* badge = | 543 UseMd() ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_VPN, |
| 559 rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | 544 GetBaseColorForIconType(icon_type)) |
| 545 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 546 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | |
| 560 s_vpn_badges[index] = new gfx::ImageSkia( | 547 s_vpn_badges[index] = new gfx::ImageSkia( |
| 561 gfx::ImageSkiaOperations::CreateTransparentImage(*badge, animation)); | 548 gfx::ImageSkiaOperations::CreateTransparentImage(badge, animation)); |
| 562 } | 549 } |
| 563 return *s_vpn_badges[index]; | 550 return *s_vpn_badges[index]; |
| 564 } | 551 } |
| 565 | 552 |
| 566 int StrengthIndex(int strength) { | 553 int StrengthIndex(int strength) { |
| 567 // Return an index in the range [1, kNumNetworkImages - 1]. | 554 // Return an index in the range [1, kNumNetworkImages - 1]. |
| 568 const float findex = (static_cast<float>(strength) / 100.0f) * | 555 const float findex = (static_cast<float>(strength) / 100.0f) * |
| 569 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); | 556 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); |
| 570 int index = 1 + static_cast<int>(findex); | 557 int index = 1 + static_cast<int>(findex); |
| 571 index = std::max(std::min(index, kNumNetworkImages - 1), 1); | 558 index = std::max(std::min(index, kNumNetworkImages - 1), 1); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 637 return gfx::ImageSkia(); | 624 return gfx::ImageSkia(); |
| 638 } | 625 } |
| 639 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | 626 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); |
| 640 } | 627 } |
| 641 | 628 |
| 642 gfx::ImageSkia GetIcon(const NetworkState* network, | 629 gfx::ImageSkia GetIcon(const NetworkState* network, |
| 643 IconType icon_type, | 630 IconType icon_type, |
| 644 int strength_index) { | 631 int strength_index) { |
| 645 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 632 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 646 if (network->Matches(NetworkTypePattern::Ethernet())) { | 633 if (network->Matches(NetworkTypePattern::Ethernet())) { |
| 647 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | 634 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
| 635 return UseMd() | |
| 636 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_ETHERNET, | |
| 637 GetBaseColorForIconType(ICON_TYPE_LIST)) | |
| 638 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | |
| 648 } else if (network->Matches(NetworkTypePattern::Wireless())) { | 639 } else if (network->Matches(NetworkTypePattern::Wireless())) { |
| 649 DCHECK(strength_index > 0); | 640 DCHECK(strength_index > 0); |
| 650 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, | 641 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, |
| 651 strength_index); | 642 strength_index); |
| 652 } else if (network->Matches(NetworkTypePattern::VPN())) { | 643 } else if (network->Matches(NetworkTypePattern::VPN())) { |
| 653 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); | 644 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
| 654 } else { | 645 return GetVpnImage(); |
| 655 LOG(WARNING) << "Request for icon for unsupported type: " | |
| 656 << network->type(); | |
| 657 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | |
| 658 } | 646 } |
| 647 | |
| 648 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); | |
| 649 return gfx::ImageSkia(); | |
| 659 } | 650 } |
| 660 | 651 |
| 661 //------------------------------------------------------------------------------ | 652 //------------------------------------------------------------------------------ |
| 662 // Get connecting images | 653 // Get connecting images |
| 663 | 654 |
| 664 gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { | 655 gfx::ImageSkia GetConnectingVpnImage(IconType icon_type) { |
| 665 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 656 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 666 const NetworkState* connected_network = nullptr; | 657 const NetworkState* connected_network = nullptr; |
| 667 if (icon_type == ICON_TYPE_TRAY) { | 658 if (icon_type == ICON_TYPE_TRAY) { |
| 668 connected_network = | 659 connected_network = |
| 669 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); | 660 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); |
| 670 } | 661 } |
| 671 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 662 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
| 672 | 663 |
| 673 gfx::ImageSkia icon; | 664 gfx::ImageSkia icon; |
| 674 Badges badges; | 665 Badges badges; |
| 675 if (connected_network) { | 666 if (connected_network) { |
| 676 icon = GetImageForNetwork(connected_network, icon_type); | 667 icon = GetImageForNetwork(connected_network, icon_type); |
| 677 badges.bottom_left = ConnectingVpnBadge(animation); | 668 badges.bottom_left = ConnectingVpnBadge(animation, icon_type); |
| 678 } else { | 669 } else { |
| 679 icon = ConnectingVpnImage(animation); | 670 icon = ConnectingVpnImage(animation); |
| 680 } | 671 } |
| 681 return UseMd() ? NetworkIconImageSourceMd::CreateImage(icon, badges) | 672 return UseMd() ? NetworkIconImageSourceMd::CreateImage(icon, badges) |
| 682 : gfx::ImageSkia(new NetworkIconImageSource(icon, badges), | 673 : gfx::ImageSkia(new NetworkIconImageSource(icon, badges), |
| 683 icon.size()); | 674 icon.size()); |
| 684 } | 675 } |
| 685 | 676 |
| 686 gfx::ImageSkia GetConnectingImage(IconType icon_type, | 677 gfx::ImageSkia GetConnectingImage(IconType icon_type, |
| 687 const std::string& network_type) { | 678 const std::string& network_type) { |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 902 if (!network->visible()) | 893 if (!network->visible()) |
| 903 return GetDisconnectedImage(icon_type, network->type()); | 894 return GetDisconnectedImage(icon_type, network->type()); |
| 904 | 895 |
| 905 if (network->IsConnectingState()) | 896 if (network->IsConnectingState()) |
| 906 return GetConnectingImage(icon_type, network->type()); | 897 return GetConnectingImage(icon_type, network->type()); |
| 907 | 898 |
| 908 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); | 899 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); |
| 909 return icon->image(); | 900 return icon->image(); |
| 910 } | 901 } |
| 911 | 902 |
| 912 gfx::ImageSkia GetImageForConnectedNetwork(IconType icon_type, | 903 gfx::ImageSkia GetImageForConnectedWifiNetwork() { |
| 913 const std::string& network_type) { | 904 ImageType image_type = ImageTypeForNetworkType(shill::kTypeWifi); |
| 914 return GetConnectedImage(icon_type, network_type); | 905 const IconType icon_type = ICON_TYPE_LIST; |
| 906 const int connected_index = kNumNetworkImages - 1; | |
| 907 return GetImageForIndex(image_type, icon_type, connected_index); | |
| 915 } | 908 } |
| 916 | 909 |
| 917 gfx::ImageSkia GetImageForConnectingNetwork(IconType icon_type, | 910 gfx::ImageSkia GetImageForDisconnectedCellNetwork() { |
| 918 const std::string& network_type) { | 911 return GetDisconnectedImage(ICON_TYPE_LIST, shill::kTypeCellular); |
| 919 return GetConnectingImage(icon_type, network_type); | |
| 920 } | 912 } |
| 921 | 913 |
| 922 gfx::ImageSkia GetImageForDisconnectedNetwork(IconType icon_type, | 914 gfx::ImageSkia GetVpnImage() { |
| 923 const std::string& network_type) { | 915 return UseMd() |
| 924 return GetDisconnectedImage(icon_type, network_type); | 916 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_VPN, |
| 917 GetBaseColorForIconType(ICON_TYPE_LIST)) | |
| 918 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 919 IDR_AURA_UBER_TRAY_NETWORK_VPN); | |
| 925 } | 920 } |
| 926 | 921 |
| 927 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, | 922 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, |
| 928 IconType icon_type) { | 923 IconType icon_type) { |
| 929 DCHECK(network); | 924 DCHECK(network); |
| 930 std::string activation_state = network->activation_state(); | 925 std::string activation_state = network->activation_state(); |
| 931 if (icon_type == ICON_TYPE_LIST) { | 926 if (icon_type == ICON_TYPE_LIST) { |
| 932 // Show "<network>: [Connecting|Activating|Reconnecting]..." | 927 // Show "<network>: [Connecting|Activating|Reconnecting]..." |
| 933 if (network->IsReconnecting()) { | 928 if (network->IsReconnecting()) { |
| 934 return l10n_util::GetStringFUTF16( | 929 return l10n_util::GetStringFUTF16( |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1050 state_handler->FirstNetworkByType(NetworkTypePattern::Mobile()); | 1045 state_handler->FirstNetworkByType(NetworkTypePattern::Mobile()); |
| 1051 if (mobile_network && (mobile_network->activation_state() == | 1046 if (mobile_network && (mobile_network->activation_state() == |
| 1052 shill::kActivationStateActivating)) { | 1047 shill::kActivationStateActivating)) { |
| 1053 network = mobile_network; | 1048 network = mobile_network; |
| 1054 } | 1049 } |
| 1055 } | 1050 } |
| 1056 if (!network) { | 1051 if (!network) { |
| 1057 // If no connecting network, check for cellular initializing. | 1052 // If no connecting network, check for cellular initializing. |
| 1058 int uninitialized_msg = GetCellularUninitializedMsg(); | 1053 int uninitialized_msg = GetCellularUninitializedMsg(); |
| 1059 if (uninitialized_msg != 0) { | 1054 if (uninitialized_msg != 0) { |
| 1060 *image = GetImageForConnectingNetwork(icon_type, shill::kTypeCellular); | 1055 *image = GetConnectingImage(icon_type, shill::kTypeCellular); |
| 1061 if (label) | 1056 if (label) |
| 1062 *label = l10n_util::GetStringUTF16(uninitialized_msg); | 1057 *label = l10n_util::GetStringUTF16(uninitialized_msg); |
| 1063 *animating = true; | 1058 *animating = true; |
| 1064 } else { | 1059 } else { |
| 1065 // Otherwise show the disconnected wifi icon. | 1060 // Otherwise show the disconnected wifi icon. |
| 1066 *image = GetImageForDisconnectedNetwork(icon_type, shill::kTypeWifi); | 1061 *image = GetDisconnectedImage(icon_type, shill::kTypeWifi); |
| 1067 if (label) { | 1062 if (label) { |
| 1068 *label = l10n_util::GetStringUTF16( | 1063 *label = l10n_util::GetStringUTF16( |
| 1069 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); | 1064 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); |
| 1070 } | 1065 } |
| 1071 *animating = false; | 1066 *animating = false; |
| 1072 } | 1067 } |
| 1073 return; | 1068 return; |
| 1074 } | 1069 } |
| 1075 *animating = network->IsConnectingState(); | 1070 *animating = network->IsConnectingState(); |
| 1076 // Get icon and label for connected or connecting network. | 1071 // Get icon and label for connected or connecting network. |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 1088 iter != networks.end(); ++iter) { | 1083 iter != networks.end(); ++iter) { |
| 1089 network_paths.insert((*iter)->path()); | 1084 network_paths.insert((*iter)->path()); |
| 1090 } | 1085 } |
| 1091 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 1086 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
| 1092 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 1087 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
| 1093 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 1088 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
| 1094 } | 1089 } |
| 1095 | 1090 |
| 1096 } // namespace network_icon | 1091 } // namespace network_icon |
| 1097 } // namespace ui | 1092 } // namespace ui |
| OLD | NEW |