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 "ash/common/system/chromeos/network/network_icon.h" |
6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 9 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
7 #include "base/macros.h" | 10 #include "base/macros.h" |
8 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
9 #include "chromeos/network/device_state.h" | 12 #include "chromeos/network/device_state.h" |
10 #include "chromeos/network/network_connection_handler.h" | 13 #include "chromeos/network/network_connection_handler.h" |
11 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
12 #include "chromeos/network/network_state_handler.h" | 15 #include "chromeos/network/network_state_handler.h" |
13 #include "chromeos/network/portal_detector/network_portal_detector.h" | 16 #include "chromeos/network/portal_detector/network_portal_detector.h" |
14 #include "grit/ui_chromeos_resources.h" | 17 #include "grit/ash_resources.h" |
15 #include "grit/ui_chromeos_strings.h" | 18 #include "grit/ash_strings.h" |
16 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
17 #include "third_party/skia/include/core/SkPaint.h" | 20 #include "third_party/skia/include/core/SkPaint.h" |
18 #include "third_party/skia/include/core/SkPath.h" | 21 #include "third_party/skia/include/core/SkPath.h" |
19 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/base/webui/web_ui_util.h" | 24 #include "ui/base/webui/web_ui_util.h" |
22 #include "ui/chromeos/material_design_icon_controller.h" | |
23 #include "ui/chromeos/network/network_icon_animation.h" | |
24 #include "ui/chromeos/network/network_icon_animation_observer.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/skia_util.h" | 34 #include "ui/gfx/skia_util.h" |
35 #include "ui/gfx/vector_icons_public.h" | 35 #include "ui/gfx/vector_icons_public.h" |
36 | 36 |
37 using chromeos::DeviceState; | 37 using chromeos::DeviceState; |
38 using chromeos::NetworkConnectionHandler; | 38 using chromeos::NetworkConnectionHandler; |
39 using chromeos::NetworkHandler; | 39 using chromeos::NetworkHandler; |
40 using chromeos::NetworkPortalDetector; | 40 using chromeos::NetworkPortalDetector; |
41 using chromeos::NetworkState; | 41 using chromeos::NetworkState; |
42 using chromeos::NetworkStateHandler; | 42 using chromeos::NetworkStateHandler; |
43 using chromeos::NetworkTypePattern; | 43 using chromeos::NetworkTypePattern; |
44 | 44 |
45 namespace ui { | 45 namespace ash { |
46 namespace network_icon { | 46 namespace network_icon { |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 // Constants for offseting the badge displayed on top of the signal strength | 50 // 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. | 51 // icon. The badge will extend outside of the base icon bounds by these amounts. |
52 // Only used for MD. All values are in dp. | 52 // Only used for MD. All values are in dp. |
53 | 53 |
54 // The badge offsets are different depending on whether the icon is in the tray | 54 // The badge offsets are different depending on whether the icon is in the tray |
55 // or menu. | 55 // or menu. |
56 const int kTrayIconBadgeOffset = 3; | 56 const int kTrayIconBadgeOffset = 3; |
57 const int kMenuIconBadgeOffset = 2; | 57 const int kMenuIconBadgeOffset = 2; |
58 | 58 |
59 // TODO(estade): use kTrayIconSize. See crbug.com/623987 | 59 // TODO(estade): use kTrayIconSize. See crbug.com/623987 |
60 const int kTrayIconSide = 16; | 60 const int kTrayIconSide = 16; |
61 | 61 |
62 bool UseMd() { | 62 bool UseMd() { |
63 return md_icon_controller::UseMaterialDesignNetworkIcons(); | 63 return MaterialDesignController::UseMaterialDesignSystemIcons(); |
64 } | 64 } |
65 | 65 |
66 //------------------------------------------------------------------------------ | 66 //------------------------------------------------------------------------------ |
67 // Struct to pass icon badges to NetworkIconImageSource. | 67 // Struct to pass icon badges to NetworkIconImageSource. |
68 struct Badges { | 68 struct Badges { |
69 gfx::ImageSkia top_left; | 69 gfx::ImageSkia top_left; |
70 gfx::ImageSkia top_right; | 70 gfx::ImageSkia top_right; |
71 gfx::ImageSkia bottom_left; | 71 gfx::ImageSkia bottom_left; |
72 gfx::ImageSkia bottom_right; | 72 gfx::ImageSkia bottom_right; |
73 }; | 73 }; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 NetworkIconMap* GetIconMap(IconType icon_type) { | 159 NetworkIconMap* GetIconMap(IconType icon_type) { |
160 return GetIconMapInstance(icon_type, true); | 160 return GetIconMapInstance(icon_type, true); |
161 } | 161 } |
162 | 162 |
163 void PurgeIconMap(IconType icon_type, | 163 void PurgeIconMap(IconType icon_type, |
164 const std::set<std::string>& network_paths) { | 164 const std::set<std::string>& network_paths) { |
165 NetworkIconMap* icon_map = GetIconMapInstance(icon_type, false); | 165 NetworkIconMap* icon_map = GetIconMapInstance(icon_type, false); |
166 if (!icon_map) | 166 if (!icon_map) |
167 return; | 167 return; |
168 for (NetworkIconMap::iterator loop_iter = icon_map->begin(); | 168 for (NetworkIconMap::iterator loop_iter = icon_map->begin(); |
169 loop_iter != icon_map->end(); ) { | 169 loop_iter != icon_map->end();) { |
170 NetworkIconMap::iterator cur_iter = loop_iter++; | 170 NetworkIconMap::iterator cur_iter = loop_iter++; |
171 if (network_paths.count(cur_iter->first) == 0) { | 171 if (network_paths.count(cur_iter->first) == 0) { |
172 delete cur_iter->second; | 172 delete cur_iter->second; |
173 icon_map->erase(cur_iter); | 173 icon_map->erase(cur_iter); |
174 } | 174 } |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
178 //------------------------------------------------------------------------------ | 178 //------------------------------------------------------------------------------ |
179 // Utilities for generating icon images. | 179 // Utilities for generating icon images. |
180 | 180 |
181 // 'NONE' will default to ARCS behavior where appropriate (e.g. no network or | 181 // 'NONE' will default to ARCS behavior where appropriate (e.g. no network or |
182 // if a new type gets added). | 182 // if a new type gets added). |
183 enum ImageType { | 183 enum ImageType { ARCS, BARS, NONE }; |
184 ARCS, | |
185 BARS, | |
186 NONE | |
187 }; | |
188 | 184 |
189 // Amount to fade icons while connecting. | 185 // Amount to fade icons while connecting. |
190 const double kConnectingImageAlpha = 0.5; | 186 const double kConnectingImageAlpha = 0.5; |
191 | 187 |
192 // Images for strength arcs for wireless networks or strength bars for cellular | 188 // Images for strength arcs for wireless networks or strength bars for cellular |
193 // networks. | 189 // networks. |
194 const int kNumNetworkImages = 5; | 190 const int kNumNetworkImages = 5; |
195 | 191 |
196 // Number of discrete images to use for alpha fade animation | 192 // Number of discrete images to use for alpha fade animation |
197 const int kNumFadeImages = 10; | 193 const int kNumFadeImages = 10; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 void set_color(SkColor color) { color_ = color; } | 325 void set_color(SkColor color) { color_ = color; } |
330 | 326 |
331 // gfx::CanvasImageSource: | 327 // gfx::CanvasImageSource: |
332 void Draw(gfx::Canvas* canvas) override { | 328 void Draw(gfx::Canvas* canvas) override { |
333 if (image_type_ == ARCS) | 329 if (image_type_ == ARCS) |
334 DrawArcs(canvas); | 330 DrawArcs(canvas); |
335 else | 331 else |
336 DrawBars(canvas); | 332 DrawBars(canvas); |
337 } | 333 } |
338 | 334 |
339 bool HasRepresentationAtAllScales() const override { | 335 bool HasRepresentationAtAllScales() const override { return true; } |
340 return true; | |
341 } | |
342 | 336 |
343 private: | 337 private: |
344 static gfx::Size GetSizeForIconType(IconType icon_type) { | 338 static gfx::Size GetSizeForIconType(IconType icon_type) { |
345 return icon_type == ICON_TYPE_TRAY | 339 return icon_type == ICON_TYPE_TRAY |
346 ? gfx::Size(kTrayIconSide, kTrayIconSide) | 340 ? gfx::Size(kTrayIconSide, kTrayIconSide) |
347 // TODO(estade): use kMenuIconSize instead of 20. | 341 // TODO(estade): use kMenuIconSize instead of 20. |
348 : gfx::Size(20, 20); | 342 : gfx::Size(20, 20); |
349 } | 343 } |
350 | 344 |
351 void DrawArcs(gfx::Canvas* canvas) { | 345 void DrawArcs(gfx::Canvas* canvas) { |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
477 gfx::CanvasImageSource* source = | 471 gfx::CanvasImageSource* source = |
478 new SignalStrengthImageSource(image_type, icon_type, index); | 472 new SignalStrengthImageSource(image_type, icon_type, index); |
479 return gfx::ImageSkia(source, source->size()); | 473 return gfx::ImageSkia(source, source->size()); |
480 } | 474 } |
481 | 475 |
482 if (index < 0 || index >= kNumNetworkImages) | 476 if (index < 0 || index >= kNumNetworkImages) |
483 return gfx::ImageSkia(); | 477 return gfx::ImageSkia(); |
484 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); | 478 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); |
485 int width = images->width(); | 479 int width = images->width(); |
486 int height = images->height() / kNumNetworkImages; | 480 int height = images->height() / kNumNetworkImages; |
487 return gfx::ImageSkiaOperations::ExtractSubset(*images, | 481 return gfx::ImageSkiaOperations::ExtractSubset( |
488 gfx::Rect(0, index * height, width, height)); | 482 *images, gfx::Rect(0, index * height, width, height)); |
489 } | 483 } |
490 | 484 |
491 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, | 485 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, |
492 const std::string& network_type) { | 486 const std::string& network_type) { |
493 DCHECK_NE(shill::kTypeVPN, network_type); | 487 DCHECK_NE(shill::kTypeVPN, network_type); |
494 ImageType image_type = ImageTypeForNetworkType(network_type); | 488 ImageType image_type = ImageTypeForNetworkType(network_type); |
495 const int disconnected_index = 0; | 489 const int disconnected_index = 0; |
496 return GetImageForIndex(image_type, icon_type, disconnected_index); | 490 return GetImageForIndex(image_type, icon_type, disconnected_index); |
497 } | 491 } |
498 | 492 |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
677 } | 671 } |
678 | 672 |
679 gfx::ImageSkia GetConnectingImage(IconType icon_type, | 673 gfx::ImageSkia GetConnectingImage(IconType icon_type, |
680 const std::string& network_type) { | 674 const std::string& network_type) { |
681 if (network_type == shill::kTypeVPN) | 675 if (network_type == shill::kTypeVPN) |
682 return GetConnectingVpnImage(icon_type); | 676 return GetConnectingVpnImage(icon_type); |
683 | 677 |
684 ImageType image_type = ImageTypeForNetworkType(network_type); | 678 ImageType image_type = ImageTypeForNetworkType(network_type); |
685 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 679 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
686 | 680 |
687 gfx::ImageSkia* icon = ConnectingWirelessImage( | 681 gfx::ImageSkia* icon = |
688 image_type, icon_type, animation); | 682 ConnectingWirelessImage(image_type, icon_type, animation); |
689 return UseMd() ? NetworkIconImageSourceMd::CreateImage(*icon, Badges()) | 683 return UseMd() ? NetworkIconImageSourceMd::CreateImage(*icon, Badges()) |
690 : gfx::ImageSkia(new NetworkIconImageSource(*icon, Badges()), | 684 : gfx::ImageSkia(new NetworkIconImageSource(*icon, Badges()), |
691 icon->size()); | 685 icon->size()); |
692 } | 686 } |
693 | 687 |
694 } // namespace | 688 } // namespace |
695 | 689 |
696 //------------------------------------------------------------------------------ | 690 //------------------------------------------------------------------------------ |
697 // NetworkIconImpl | 691 // NetworkIconImpl |
698 | 692 |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; | 765 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; |
772 } | 766 } |
773 | 767 |
774 if (behind_captive_portal == behind_captive_portal_) | 768 if (behind_captive_portal == behind_captive_portal_) |
775 return false; | 769 return false; |
776 behind_captive_portal_ = behind_captive_portal; | 770 behind_captive_portal_ = behind_captive_portal; |
777 return true; | 771 return true; |
778 } | 772 } |
779 | 773 |
780 bool NetworkIconImpl::UpdateVPNBadge() { | 774 bool NetworkIconImpl::UpdateVPNBadge() { |
781 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> | 775 const NetworkState* vpn = |
782 ConnectedNetworkByType(NetworkTypePattern::VPN()); | 776 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( |
| 777 NetworkTypePattern::VPN()); |
783 if (vpn && vpn_badge_.isNull()) { | 778 if (vpn && vpn_badge_.isNull()) { |
784 vpn_badge_ = | 779 vpn_badge_ = |
785 UseMd() ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_VPN, | 780 UseMd() ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_VPN, |
786 GetDefaultColorForIconType(icon_type_)) | 781 GetDefaultColorForIconType(icon_type_)) |
787 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 782 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
788 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | 783 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); |
789 return true; | 784 return true; |
790 } | 785 } |
791 if (!vpn && !vpn_badge_.isNull()) { | 786 if (!vpn && !vpn_badge_.isNull()) { |
792 vpn_badge_ = gfx::ImageSkia(); | 787 vpn_badge_ = gfx::ImageSkia(); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 } else { | 985 } else { |
991 return base::UTF8ToUTF16(network->name()); | 986 return base::UTF8ToUTF16(network->name()); |
992 } | 987 } |
993 } | 988 } |
994 | 989 |
995 int GetCellularUninitializedMsg() { | 990 int GetCellularUninitializedMsg() { |
996 static base::Time s_uninitialized_state_time; | 991 static base::Time s_uninitialized_state_time; |
997 static int s_uninitialized_msg(0); | 992 static int s_uninitialized_msg(0); |
998 | 993 |
999 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 994 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
1000 if (handler->GetTechnologyState(NetworkTypePattern::Mobile()) | 995 if (handler->GetTechnologyState(NetworkTypePattern::Mobile()) == |
1001 == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { | 996 NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { |
1002 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; | 997 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; |
1003 s_uninitialized_state_time = base::Time::Now(); | 998 s_uninitialized_state_time = base::Time::Now(); |
1004 return s_uninitialized_msg; | 999 return s_uninitialized_msg; |
1005 } else if (handler->GetScanningByType(NetworkTypePattern::Mobile())) { | 1000 } else if (handler->GetScanningByType(NetworkTypePattern::Mobile())) { |
1006 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; | 1001 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; |
1007 s_uninitialized_state_time = base::Time::Now(); | 1002 s_uninitialized_state_time = base::Time::Now(); |
1008 return s_uninitialized_msg; | 1003 return s_uninitialized_msg; |
1009 } | 1004 } |
1010 // There can be a delay between leaving the Initializing state and when | 1005 // There can be a delay between leaving the Initializing state and when |
1011 // a Cellular device shows up, so keep showing the initializing | 1006 // a Cellular device shows up, so keep showing the initializing |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1097 for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin(); | 1092 for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin(); |
1098 iter != networks.end(); ++iter) { | 1093 iter != networks.end(); ++iter) { |
1099 network_paths.insert((*iter)->path()); | 1094 network_paths.insert((*iter)->path()); |
1100 } | 1095 } |
1101 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 1096 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
1102 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 1097 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
1103 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 1098 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
1104 } | 1099 } |
1105 | 1100 |
1106 } // namespace network_icon | 1101 } // namespace network_icon |
1107 } // namespace ui | 1102 } // namespace ash |
OLD | NEW |