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

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

Issue 2435903002: Move tray code from ui/chromeos/network/ (Closed)
Patch Set: . Created 4 years, 2 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 "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::GetMode() !=
James Cook 2016/10/20 16:05:55 I think this should be MaterialDesignController::U
stevenjb 2016/10/24 20:08:25 Done.
64 MaterialDesignController::NON_MATERIAL;
64 } 65 }
65 66
66 //------------------------------------------------------------------------------ 67 //------------------------------------------------------------------------------
67 // Struct to pass icon badges to NetworkIconImageSource. 68 // Struct to pass icon badges to NetworkIconImageSource.
68 struct Badges { 69 struct Badges {
69 gfx::ImageSkia top_left; 70 gfx::ImageSkia top_left;
70 gfx::ImageSkia top_right; 71 gfx::ImageSkia top_right;
71 gfx::ImageSkia bottom_left; 72 gfx::ImageSkia bottom_left;
72 gfx::ImageSkia bottom_right; 73 gfx::ImageSkia bottom_right;
73 }; 74 };
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 NetworkIconMap* GetIconMap(IconType icon_type) { 160 NetworkIconMap* GetIconMap(IconType icon_type) {
160 return GetIconMapInstance(icon_type, true); 161 return GetIconMapInstance(icon_type, true);
161 } 162 }
162 163
163 void PurgeIconMap(IconType icon_type, 164 void PurgeIconMap(IconType icon_type,
164 const std::set<std::string>& network_paths) { 165 const std::set<std::string>& network_paths) {
165 NetworkIconMap* icon_map = GetIconMapInstance(icon_type, false); 166 NetworkIconMap* icon_map = GetIconMapInstance(icon_type, false);
166 if (!icon_map) 167 if (!icon_map)
167 return; 168 return;
168 for (NetworkIconMap::iterator loop_iter = icon_map->begin(); 169 for (NetworkIconMap::iterator loop_iter = icon_map->begin();
169 loop_iter != icon_map->end(); ) { 170 loop_iter != icon_map->end();) {
170 NetworkIconMap::iterator cur_iter = loop_iter++; 171 NetworkIconMap::iterator cur_iter = loop_iter++;
171 if (network_paths.count(cur_iter->first) == 0) { 172 if (network_paths.count(cur_iter->first) == 0) {
172 delete cur_iter->second; 173 delete cur_iter->second;
173 icon_map->erase(cur_iter); 174 icon_map->erase(cur_iter);
174 } 175 }
175 } 176 }
176 } 177 }
177 178
178 //------------------------------------------------------------------------------ 179 //------------------------------------------------------------------------------
179 // Utilities for generating icon images. 180 // Utilities for generating icon images.
180 181
181 // 'NONE' will default to ARCS behavior where appropriate (e.g. no network or 182 // 'NONE' will default to ARCS behavior where appropriate (e.g. no network or
182 // if a new type gets added). 183 // if a new type gets added).
183 enum ImageType { 184 enum ImageType { ARCS, BARS, NONE };
184 ARCS,
185 BARS,
186 NONE
187 };
188 185
189 // Amount to fade icons while connecting. 186 // Amount to fade icons while connecting.
190 const double kConnectingImageAlpha = 0.5; 187 const double kConnectingImageAlpha = 0.5;
191 188
192 // Images for strength arcs for wireless networks or strength bars for cellular 189 // Images for strength arcs for wireless networks or strength bars for cellular
193 // networks. 190 // networks.
194 const int kNumNetworkImages = 5; 191 const int kNumNetworkImages = 5;
195 192
196 // Number of discrete images to use for alpha fade animation 193 // Number of discrete images to use for alpha fade animation
197 const int kNumFadeImages = 10; 194 const int kNumFadeImages = 10;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 void set_color(SkColor color) { color_ = color; } 326 void set_color(SkColor color) { color_ = color; }
330 327
331 // gfx::CanvasImageSource: 328 // gfx::CanvasImageSource:
332 void Draw(gfx::Canvas* canvas) override { 329 void Draw(gfx::Canvas* canvas) override {
333 if (image_type_ == ARCS) 330 if (image_type_ == ARCS)
334 DrawArcs(canvas); 331 DrawArcs(canvas);
335 else 332 else
336 DrawBars(canvas); 333 DrawBars(canvas);
337 } 334 }
338 335
339 bool HasRepresentationAtAllScales() const override { 336 bool HasRepresentationAtAllScales() const override { return true; }
340 return true;
341 }
342 337
343 private: 338 private:
344 static gfx::Size GetSizeForIconType(IconType icon_type) { 339 static gfx::Size GetSizeForIconType(IconType icon_type) {
345 return icon_type == ICON_TYPE_TRAY 340 return icon_type == ICON_TYPE_TRAY
346 ? gfx::Size(kTrayIconSide, kTrayIconSide) 341 ? gfx::Size(kTrayIconSide, kTrayIconSide)
347 // TODO(estade): use kMenuIconSize instead of 20. 342 // TODO(estade): use kMenuIconSize instead of 20.
348 : gfx::Size(20, 20); 343 : gfx::Size(20, 20);
349 } 344 }
350 345
351 void DrawArcs(gfx::Canvas* canvas) { 346 void DrawArcs(gfx::Canvas* canvas) {
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 gfx::CanvasImageSource* source = 472 gfx::CanvasImageSource* source =
478 new SignalStrengthImageSource(image_type, icon_type, index); 473 new SignalStrengthImageSource(image_type, icon_type, index);
479 return gfx::ImageSkia(source, source->size()); 474 return gfx::ImageSkia(source, source->size());
480 } 475 }
481 476
482 if (index < 0 || index >= kNumNetworkImages) 477 if (index < 0 || index >= kNumNetworkImages)
483 return gfx::ImageSkia(); 478 return gfx::ImageSkia();
484 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); 479 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type);
485 int width = images->width(); 480 int width = images->width();
486 int height = images->height() / kNumNetworkImages; 481 int height = images->height() / kNumNetworkImages;
487 return gfx::ImageSkiaOperations::ExtractSubset(*images, 482 return gfx::ImageSkiaOperations::ExtractSubset(
488 gfx::Rect(0, index * height, width, height)); 483 *images, gfx::Rect(0, index * height, width, height));
489 } 484 }
490 485
491 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, 486 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type,
492 const std::string& network_type) { 487 const std::string& network_type) {
493 DCHECK_NE(shill::kTypeVPN, network_type); 488 DCHECK_NE(shill::kTypeVPN, network_type);
494 ImageType image_type = ImageTypeForNetworkType(network_type); 489 ImageType image_type = ImageTypeForNetworkType(network_type);
495 const int disconnected_index = 0; 490 const int disconnected_index = 0;
496 return GetImageForIndex(image_type, icon_type, disconnected_index); 491 return GetImageForIndex(image_type, icon_type, disconnected_index);
497 } 492 }
498 493
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 } 672 }
678 673
679 gfx::ImageSkia GetConnectingImage(IconType icon_type, 674 gfx::ImageSkia GetConnectingImage(IconType icon_type,
680 const std::string& network_type) { 675 const std::string& network_type) {
681 if (network_type == shill::kTypeVPN) 676 if (network_type == shill::kTypeVPN)
682 return GetConnectingVpnImage(icon_type); 677 return GetConnectingVpnImage(icon_type);
683 678
684 ImageType image_type = ImageTypeForNetworkType(network_type); 679 ImageType image_type = ImageTypeForNetworkType(network_type);
685 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); 680 double animation = NetworkIconAnimation::GetInstance()->GetAnimation();
686 681
687 gfx::ImageSkia* icon = ConnectingWirelessImage( 682 gfx::ImageSkia* icon =
688 image_type, icon_type, animation); 683 ConnectingWirelessImage(image_type, icon_type, animation);
689 return UseMd() ? NetworkIconImageSourceMd::CreateImage(*icon, Badges()) 684 return UseMd() ? NetworkIconImageSourceMd::CreateImage(*icon, Badges())
690 : gfx::ImageSkia(new NetworkIconImageSource(*icon, Badges()), 685 : gfx::ImageSkia(new NetworkIconImageSource(*icon, Badges()),
691 icon->size()); 686 icon->size());
692 } 687 }
693 688
694 } // namespace 689 } // namespace
695 690
696 //------------------------------------------------------------------------------ 691 //------------------------------------------------------------------------------
697 // NetworkIconImpl 692 // NetworkIconImpl
698 693
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL; 766 state.status == NetworkPortalDetector::CAPTIVE_PORTAL_STATUS_PORTAL;
772 } 767 }
773 768
774 if (behind_captive_portal == behind_captive_portal_) 769 if (behind_captive_portal == behind_captive_portal_)
775 return false; 770 return false;
776 behind_captive_portal_ = behind_captive_portal; 771 behind_captive_portal_ = behind_captive_portal;
777 return true; 772 return true;
778 } 773 }
779 774
780 bool NetworkIconImpl::UpdateVPNBadge() { 775 bool NetworkIconImpl::UpdateVPNBadge() {
781 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> 776 const NetworkState* vpn =
782 ConnectedNetworkByType(NetworkTypePattern::VPN()); 777 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
778 NetworkTypePattern::VPN());
783 if (vpn && vpn_badge_.isNull()) { 779 if (vpn && vpn_badge_.isNull()) {
784 vpn_badge_ = 780 vpn_badge_ =
785 UseMd() ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_VPN, 781 UseMd() ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_BADGE_VPN,
786 GetDefaultColorForIconType(icon_type_)) 782 GetDefaultColorForIconType(icon_type_))
787 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 783 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
788 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); 784 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE);
789 return true; 785 return true;
790 } 786 }
791 if (!vpn && !vpn_badge_.isNull()) { 787 if (!vpn && !vpn_badge_.isNull()) {
792 vpn_badge_ = gfx::ImageSkia(); 788 vpn_badge_ = gfx::ImageSkia();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
990 } else { 986 } else {
991 return base::UTF8ToUTF16(network->name()); 987 return base::UTF8ToUTF16(network->name());
992 } 988 }
993 } 989 }
994 990
995 int GetCellularUninitializedMsg() { 991 int GetCellularUninitializedMsg() {
996 static base::Time s_uninitialized_state_time; 992 static base::Time s_uninitialized_state_time;
997 static int s_uninitialized_msg(0); 993 static int s_uninitialized_msg(0);
998 994
999 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 995 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
1000 if (handler->GetTechnologyState(NetworkTypePattern::Mobile()) 996 if (handler->GetTechnologyState(NetworkTypePattern::Mobile()) ==
1001 == NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) { 997 NetworkStateHandler::TECHNOLOGY_UNINITIALIZED) {
1002 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; 998 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR;
1003 s_uninitialized_state_time = base::Time::Now(); 999 s_uninitialized_state_time = base::Time::Now();
1004 return s_uninitialized_msg; 1000 return s_uninitialized_msg;
1005 } else if (handler->GetScanningByType(NetworkTypePattern::Mobile())) { 1001 } else if (handler->GetScanningByType(NetworkTypePattern::Mobile())) {
1006 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; 1002 s_uninitialized_msg = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING;
1007 s_uninitialized_state_time = base::Time::Now(); 1003 s_uninitialized_state_time = base::Time::Now();
1008 return s_uninitialized_msg; 1004 return s_uninitialized_msg;
1009 } 1005 }
1010 // There can be a delay between leaving the Initializing state and when 1006 // There can be a delay between leaving the Initializing state and when
1011 // a Cellular device shows up, so keep showing the initializing 1007 // a Cellular device shows up, so keep showing the initializing
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin(); 1093 for (NetworkStateHandler::NetworkStateList::iterator iter = networks.begin();
1098 iter != networks.end(); ++iter) { 1094 iter != networks.end(); ++iter) {
1099 network_paths.insert((*iter)->path()); 1095 network_paths.insert((*iter)->path());
1100 } 1096 }
1101 PurgeIconMap(ICON_TYPE_TRAY, network_paths); 1097 PurgeIconMap(ICON_TYPE_TRAY, network_paths);
1102 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); 1098 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths);
1103 PurgeIconMap(ICON_TYPE_LIST, network_paths); 1099 PurgeIconMap(ICON_TYPE_LIST, network_paths);
1104 } 1100 }
1105 1101
1106 } // namespace network_icon 1102 } // namespace network_icon
1107 } // namespace ui 1103 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698