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 "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" | |
| 8 #include "ash/common/system/chromeos/network/network_icon_animation.h" | 7 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 9 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" | 8 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 11 #include "ash/resources/vector_icons/vector_icons.h" | 10 #include "ash/resources/vector_icons/vector_icons.h" |
| 12 #include "base/macros.h" | 11 #include "base/macros.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 14 #include "chromeos/network/device_state.h" | 13 #include "chromeos/network/device_state.h" |
| 15 #include "chromeos/network/network_connection_handler.h" | 14 #include "chromeos/network/network_connection_handler.h" |
| 16 #include "chromeos/network/network_state.h" | 15 #include "chromeos/network/network_state.h" |
| 17 #include "chromeos/network/network_state_handler.h" | 16 #include "chromeos/network/network_state_handler.h" |
| 18 #include "chromeos/network/portal_detector/network_portal_detector.h" | 17 #include "chromeos/network/portal_detector/network_portal_detector.h" |
| 19 #include "grit/ash_resources.h" | 18 #include "grit/ash_resources.h" |
| 20 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 20 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 #include "third_party/skia/include/core/SkPaint.h" | 21 #include "third_party/skia/include/core/SkPaint.h" |
| 23 #include "third_party/skia/include/core/SkPath.h" | 22 #include "third_party/skia/include/core/SkPath.h" |
| 24 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
| 25 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
| 26 #include "ui/base/webui/web_ui_util.h" | |
| 27 #include "ui/gfx/canvas.h" | 25 #include "ui/gfx/canvas.h" |
| 28 #include "ui/gfx/color_palette.h" | 26 #include "ui/gfx/color_palette.h" |
| 29 #include "ui/gfx/geometry/insets.h" | 27 #include "ui/gfx/geometry/insets.h" |
| 30 #include "ui/gfx/geometry/rect.h" | 28 #include "ui/gfx/geometry/rect.h" |
| 31 #include "ui/gfx/geometry/size_conversions.h" | 29 #include "ui/gfx/geometry/size_conversions.h" |
| 32 #include "ui/gfx/image/canvas_image_source.h" | 30 #include "ui/gfx/image/canvas_image_source.h" |
| 33 #include "ui/gfx/image/image_skia_operations.h" | 31 #include "ui/gfx/image/image_skia_operations.h" |
| 34 #include "ui/gfx/image/image_skia_source.h" | 32 #include "ui/gfx/image/image_skia_source.h" |
| 35 #include "ui/gfx/paint_vector_icon.h" | 33 #include "ui/gfx/paint_vector_icon.h" |
| 36 #include "ui/gfx/skia_util.h" | 34 #include "ui/gfx/skia_util.h" |
| 37 #include "ui/gfx/vector_icon_types.h" | 35 #include "ui/gfx/vector_icon_types.h" |
| 38 | 36 |
| 39 using chromeos::DeviceState; | 37 using chromeos::DeviceState; |
| 40 using chromeos::NetworkConnectionHandler; | 38 using chromeos::NetworkConnectionHandler; |
| 41 using chromeos::NetworkHandler; | 39 using chromeos::NetworkHandler; |
| 42 using chromeos::NetworkPortalDetector; | 40 using chromeos::NetworkPortalDetector; |
| 43 using chromeos::NetworkState; | 41 using chromeos::NetworkState; |
| 44 using chromeos::NetworkStateHandler; | 42 using chromeos::NetworkStateHandler; |
| 45 using chromeos::NetworkTypePattern; | 43 using chromeos::NetworkTypePattern; |
| 46 | 44 |
| 47 namespace ash { | 45 namespace ash { |
| 48 namespace network_icon { | 46 namespace network_icon { |
| 49 | 47 |
| 50 namespace { | 48 namespace { |
| 51 | 49 |
| 52 // 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 |
| 53 // 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. |
| 54 // Only used for MD. All values are in dp. | 52 // All values are in dp. |
| 55 | 53 |
| 56 // 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 |
| 57 // or menu. | 55 // or menu. |
| 58 const int kTrayIconBadgeOffset = 3; | 56 const int kTrayIconBadgeOffset = 3; |
| 59 const int kMenuIconBadgeOffset = 2; | 57 const int kMenuIconBadgeOffset = 2; |
| 60 | 58 |
| 61 bool UseMd() { | |
| 62 return MaterialDesignController::UseMaterialDesignSystemIcons(); | |
| 63 } | |
| 64 | |
| 65 //------------------------------------------------------------------------------ | 59 //------------------------------------------------------------------------------ |
| 66 // Struct to pass icon badges to NetworkIconImageSource. | 60 // Struct to pass icon badges to NetworkIconImageSource. |
| 67 struct Badges { | 61 struct Badges { |
| 68 gfx::ImageSkia top_left; | 62 gfx::ImageSkia top_left; |
| 69 gfx::ImageSkia top_right; | 63 gfx::ImageSkia top_right; |
| 70 gfx::ImageSkia bottom_left; | 64 gfx::ImageSkia bottom_left; |
| 71 gfx::ImageSkia bottom_right; | 65 gfx::ImageSkia bottom_right; |
| 72 }; | 66 }; |
| 73 | 67 |
| 74 //------------------------------------------------------------------------------ | 68 //------------------------------------------------------------------------------ |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 return (icon_type != ICON_TYPE_TRAY); | 193 return (icon_type != ICON_TYPE_TRAY); |
| 200 } | 194 } |
| 201 | 195 |
| 202 bool IconTypeHasVPNBadge(IconType icon_type) { | 196 bool IconTypeHasVPNBadge(IconType icon_type) { |
| 203 return (icon_type != ICON_TYPE_LIST && icon_type != ICON_TYPE_MENU_LIST); | 197 return (icon_type != ICON_TYPE_LIST && icon_type != ICON_TYPE_MENU_LIST); |
| 204 } | 198 } |
| 205 | 199 |
| 206 // This defines how we assemble a network icon. | 200 // This defines how we assemble a network icon. |
| 207 class NetworkIconImageSource : public gfx::CanvasImageSource { | 201 class NetworkIconImageSource : public gfx::CanvasImageSource { |
| 208 public: | 202 public: |
| 209 NetworkIconImageSource(const gfx::ImageSkia& icon, const Badges& badges) | |
| 210 : CanvasImageSource(icon.size(), false), icon_(icon), badges_(badges) {} | |
| 211 ~NetworkIconImageSource() override {} | |
| 212 | |
| 213 // TODO(pkotwicz): Figure out what to do when a new image resolution becomes | |
| 214 // available. | |
| 215 void Draw(gfx::Canvas* canvas) override { | |
| 216 canvas->DrawImageInt(icon_, 0, 0); | |
| 217 | |
| 218 if (!badges_.top_left.isNull()) | |
| 219 canvas->DrawImageInt(badges_.top_left, 0, 0); | |
| 220 if (!badges_.top_right.isNull()) | |
| 221 canvas->DrawImageInt(badges_.top_right, | |
| 222 icon_.width() - badges_.top_right.width(), 0); | |
| 223 if (!badges_.bottom_left.isNull()) { | |
| 224 canvas->DrawImageInt(badges_.bottom_left, 0, | |
| 225 icon_.height() - badges_.bottom_left.height()); | |
| 226 } | |
| 227 if (!badges_.bottom_right.isNull()) { | |
| 228 canvas->DrawImageInt(badges_.bottom_right, | |
| 229 icon_.width() - badges_.bottom_right.width(), | |
| 230 icon_.height() - badges_.bottom_right.height()); | |
| 231 } | |
| 232 } | |
| 233 | |
| 234 private: | |
| 235 const gfx::ImageSkia icon_; | |
| 236 const Badges badges_; | |
| 237 | |
| 238 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); | |
| 239 }; | |
| 240 | |
| 241 // This defines how we assemble a network icon. | |
| 242 class NetworkIconImageSourceMd : public gfx::CanvasImageSource { | |
| 243 public: | |
| 244 static gfx::ImageSkia CreateImage(const gfx::ImageSkia& icon, | 203 static gfx::ImageSkia CreateImage(const gfx::ImageSkia& icon, |
| 245 const Badges& badges) { | 204 const Badges& badges) { |
| 246 auto source = new NetworkIconImageSourceMd(icon, badges); | 205 auto source = new NetworkIconImageSource(icon, badges); |
| 247 return gfx::ImageSkia(source, source->size()); | 206 return gfx::ImageSkia(source, source->size()); |
| 248 } | 207 } |
| 249 | 208 |
| 250 // gfx::CanvasImageSource: | 209 // gfx::CanvasImageSource: |
| 251 void Draw(gfx::Canvas* canvas) override { | 210 void Draw(gfx::Canvas* canvas) override { |
| 252 const int width = size().width(); | 211 const int width = size().width(); |
| 253 const int height = size().height(); | 212 const int height = size().height(); |
| 254 | 213 |
| 255 // The base icon is centered in both dimensions. | 214 // The base icon is centered in both dimensions. |
| 256 const int icon_y = (height - icon_.height()) / 2; | 215 const int icon_y = (height - icon_.height()) / 2; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 272 if (!badges_.bottom_right.isNull()) { | 231 if (!badges_.bottom_right.isNull()) { |
| 273 canvas->DrawImageInt(badges_.bottom_right, | 232 canvas->DrawImageInt(badges_.bottom_right, |
| 274 width - badges_.bottom_right.width(), | 233 width - badges_.bottom_right.width(), |
| 275 height - badges_.bottom_right.height()); | 234 height - badges_.bottom_right.height()); |
| 276 } | 235 } |
| 277 } | 236 } |
| 278 | 237 |
| 279 bool HasRepresentationAtAllScales() const override { return true; } | 238 bool HasRepresentationAtAllScales() const override { return true; } |
| 280 | 239 |
| 281 private: | 240 private: |
| 282 NetworkIconImageSourceMd(const gfx::ImageSkia& icon, const Badges& badges) | 241 NetworkIconImageSource(const gfx::ImageSkia& icon, const Badges& badges) |
| 283 : CanvasImageSource(GetSizeForBaseIconSize(icon.size()), false), | 242 : CanvasImageSource(GetSizeForBaseIconSize(icon.size()), false), |
| 284 icon_(icon), | 243 icon_(icon), |
| 285 badges_(badges) {} | 244 badges_(badges) {} |
| 286 ~NetworkIconImageSourceMd() override {} | 245 ~NetworkIconImageSource() override {} |
| 287 | 246 |
| 288 static gfx::Size GetSizeForBaseIconSize(const gfx::Size& base_icon_size) { | 247 static gfx::Size GetSizeForBaseIconSize(const gfx::Size& base_icon_size) { |
| 289 gfx::Size size = base_icon_size; | 248 gfx::Size size = base_icon_size; |
| 290 const int badge_offset = base_icon_size.width() == kTrayIconSize | 249 const int badge_offset = base_icon_size.width() == kTrayIconSize |
| 291 ? kTrayIconBadgeOffset | 250 ? kTrayIconBadgeOffset |
| 292 : kMenuIconBadgeOffset; | 251 : kMenuIconBadgeOffset; |
| 293 size.Enlarge(badge_offset * 2, badge_offset * 2); | 252 size.Enlarge(badge_offset * 2, badge_offset * 2); |
| 294 return size; | 253 return size; |
| 295 } | 254 } |
| 296 | 255 |
| 297 const gfx::ImageSkia icon_; | 256 const gfx::ImageSkia icon_; |
| 298 const Badges badges_; | 257 const Badges badges_; |
| 299 | 258 |
| 300 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSourceMd); | 259 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); |
| 301 }; | 260 }; |
| 302 | 261 |
| 303 // Depicts a given signal strength using arcs (e.g. for WiFi connections) or | 262 // Depicts a given signal strength using arcs (e.g. for WiFi connections) or |
| 304 // bars (e.g. for cell connections). | 263 // bars (e.g. for cell connections). |
| 305 class SignalStrengthImageSource : public gfx::CanvasImageSource { | 264 class SignalStrengthImageSource : public gfx::CanvasImageSource { |
| 306 public: | 265 public: |
| 307 SignalStrengthImageSource(ImageType image_type, | 266 SignalStrengthImageSource(ImageType image_type, |
| 308 IconType icon_type, | 267 IconType icon_type, |
| 309 int signal_strength) | 268 int signal_strength) |
| 310 : CanvasImageSource(GetSizeForIconType(icon_type), false), | 269 : CanvasImageSource(GetSizeForIconType(icon_type), false), |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 431 // TODO(estade): share this alpha with other things in ash (battery, etc.). | 390 // TODO(estade): share this alpha with other things in ash (battery, etc.). |
| 432 // See crbug.com/623987 and crbug.com/632827 | 391 // See crbug.com/623987 and crbug.com/632827 |
| 433 static constexpr int kBgAlpha = 0x4D; | 392 static constexpr int kBgAlpha = 0x4D; |
| 434 | 393 |
| 435 DISALLOW_COPY_AND_ASSIGN(SignalStrengthImageSource); | 394 DISALLOW_COPY_AND_ASSIGN(SignalStrengthImageSource); |
| 436 }; | 395 }; |
| 437 | 396 |
| 438 //------------------------------------------------------------------------------ | 397 //------------------------------------------------------------------------------ |
| 439 // Utilities for extracting icon images. | 398 // Utilities for extracting icon images. |
| 440 | 399 |
| 441 gfx::ImageSkia* BaseImageForType(ImageType image_type, IconType icon_type) { | |
| 442 gfx::ImageSkia* image; | |
| 443 if (image_type == BARS) { | |
| 444 image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 445 IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK | |
| 446 : IDR_AURA_UBER_TRAY_NETWORK_BARS_LIGHT); | |
| 447 } else { | |
| 448 image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 449 IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_ARCS_DARK | |
| 450 : IDR_AURA_UBER_TRAY_NETWORK_ARCS_LIGHT); | |
| 451 } | |
| 452 return image; | |
| 453 } | |
| 454 | |
| 455 ImageType ImageTypeForNetworkType(const std::string& type) { | 400 ImageType ImageTypeForNetworkType(const std::string& type) { |
| 456 if (type == shill::kTypeWifi) | 401 if (type == shill::kTypeWifi) |
| 457 return ARCS; | 402 return ARCS; |
| 458 else if (type == shill::kTypeCellular || type == shill::kTypeWimax) | 403 else if (type == shill::kTypeCellular || type == shill::kTypeWimax) |
| 459 return BARS; | 404 return BARS; |
| 460 return NONE; | 405 return NONE; |
| 461 } | 406 } |
| 462 | 407 |
| 463 gfx::ImageSkia GetImageForIndex(ImageType image_type, | 408 gfx::ImageSkia GetImageForIndex(ImageType image_type, |
| 464 IconType icon_type, | 409 IconType icon_type, |
| 465 int index) { | 410 int index) { |
| 466 if (UseMd()) { | 411 gfx::CanvasImageSource* source = |
| 467 gfx::CanvasImageSource* source = | 412 new SignalStrengthImageSource(image_type, icon_type, index); |
| 468 new SignalStrengthImageSource(image_type, icon_type, index); | 413 return gfx::ImageSkia(source, source->size()); |
| 469 return gfx::ImageSkia(source, source->size()); | |
| 470 } | |
| 471 | |
| 472 if (index < 0 || index >= kNumNetworkImages) | |
| 473 return gfx::ImageSkia(); | |
| 474 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); | |
| 475 int width = images->width(); | |
| 476 int height = images->height() / kNumNetworkImages; | |
| 477 return gfx::ImageSkiaOperations::ExtractSubset( | |
| 478 *images, gfx::Rect(0, index * height, width, height)); | |
| 479 } | 414 } |
| 480 | 415 |
| 481 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, | 416 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, |
| 482 const std::string& network_type) { | 417 const std::string& network_type) { |
| 483 DCHECK_NE(shill::kTypeVPN, network_type); | 418 DCHECK_NE(shill::kTypeVPN, network_type); |
| 484 ImageType image_type = ImageTypeForNetworkType(network_type); | 419 ImageType image_type = ImageTypeForNetworkType(network_type); |
| 485 const int disconnected_index = 0; | 420 const int disconnected_index = 0; |
| 486 return GetImageForIndex(image_type, icon_type, disconnected_index); | 421 return GetImageForIndex(image_type, icon_type, disconnected_index); |
| 487 } | 422 } |
| 488 | 423 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 512 } | 447 } |
| 513 return images[index]; | 448 return images[index]; |
| 514 } | 449 } |
| 515 | 450 |
| 516 gfx::ImageSkia ConnectingVpnImage(double animation) { | 451 gfx::ImageSkia ConnectingVpnImage(double animation) { |
| 517 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); | 452 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); |
| 518 static gfx::ImageSkia* s_vpn_images[kNumFadeImages]; | 453 static gfx::ImageSkia* s_vpn_images[kNumFadeImages]; |
| 519 if (!s_vpn_images[index]) { | 454 if (!s_vpn_images[index]) { |
| 520 // Lazily cache images. | 455 // Lazily cache images. |
| 521 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 456 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 457 // TODO(estade): update this icon to MD. See crbug.com/690176 | |
|
tdanderson
2017/02/09 18:23:47
Thanks for catching + filing
| |
| 522 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); | 458 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); |
| 523 s_vpn_images[index] = new gfx::ImageSkia( | 459 s_vpn_images[index] = new gfx::ImageSkia( |
| 524 gfx::ImageSkiaOperations::CreateTransparentImage(*icon, animation)); | 460 gfx::ImageSkiaOperations::CreateTransparentImage(*icon, animation)); |
| 525 } | 461 } |
| 526 return *s_vpn_images[index]; | 462 return *s_vpn_images[index]; |
| 527 } | 463 } |
| 528 | 464 |
| 529 gfx::ImageSkia ConnectingVpnBadge(double animation, IconType icon_type) { | 465 gfx::ImageSkia ConnectingVpnBadge(double animation, IconType icon_type) { |
| 530 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); | 466 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); |
| 531 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; | 467 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; |
| 532 if (!s_vpn_badges[index]) { | 468 if (!s_vpn_badges[index]) { |
| 533 // Lazily cache images. | 469 // Lazily cache images. |
| 534 gfx::ImageSkia badge = | 470 gfx::ImageSkia badge = gfx::CreateVectorIcon( |
| 535 UseMd() ? gfx::CreateVectorIcon(kNetworkBadgeVpnIcon, | 471 kNetworkBadgeVpnIcon, GetDefaultColorForIconType(icon_type)); |
| 536 GetDefaultColorForIconType(icon_type)) | |
| 537 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 538 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | |
| 539 s_vpn_badges[index] = new gfx::ImageSkia( | 472 s_vpn_badges[index] = new gfx::ImageSkia( |
| 540 gfx::ImageSkiaOperations::CreateTransparentImage(badge, animation)); | 473 gfx::ImageSkiaOperations::CreateTransparentImage(badge, animation)); |
| 541 } | 474 } |
| 542 return *s_vpn_badges[index]; | 475 return *s_vpn_badges[index]; |
| 543 } | 476 } |
| 544 | 477 |
| 545 int StrengthIndex(int strength) { | 478 int StrengthIndex(int strength) { |
| 546 // Return an index in the range [1, kNumNetworkImages - 1]. | 479 // Return an index in the range [1, kNumNetworkImages - 1]. |
| 547 const float findex = (static_cast<float>(strength) / 100.0f) * | 480 const float findex = (static_cast<float>(strength) / 100.0f) * |
| 548 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); | 481 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); |
| 549 int index = 1 + static_cast<int>(findex); | 482 int index = 1 + static_cast<int>(findex); |
| 550 index = std::max(std::min(index, kNumNetworkImages - 1), 1); | 483 index = std::max(std::min(index, kNumNetworkImages - 1), 1); |
| 551 return index; | 484 return index; |
| 552 } | 485 } |
| 553 | 486 |
| 554 gfx::ImageSkia BadgeForNetworkTechnology(const NetworkState* network, | 487 gfx::ImageSkia BadgeForNetworkTechnology(const NetworkState* network, |
| 555 IconType icon_type) { | 488 IconType icon_type) { |
| 556 const std::string& technology = network->network_technology(); | 489 const std::string& technology = network->network_technology(); |
| 557 if (UseMd()) { | 490 const gfx::VectorIcon* icon = &gfx::kNoneIcon; |
| 558 const gfx::VectorIcon* icon = &gfx::kNoneIcon; | |
| 559 if (technology == shill::kNetworkTechnologyEvdo) { | |
| 560 icon = &kNetworkBadgeTechnologyEvdoIcon; | |
| 561 } else if (technology == shill::kNetworkTechnology1Xrtt) { | |
| 562 icon = &kNetworkBadgeTechnology1xIcon; | |
| 563 } else if (technology == shill::kNetworkTechnologyGprs || | |
| 564 technology == shill::kNetworkTechnologyGsm) { | |
| 565 icon = &kNetworkBadgeTechnologyGprsIcon; | |
| 566 } else if (technology == shill::kNetworkTechnologyEdge) { | |
| 567 icon = &kNetworkBadgeTechnologyEdgeIcon; | |
| 568 } else if (technology == shill::kNetworkTechnologyUmts) { | |
| 569 icon = &kNetworkBadgeTechnology3gIcon; | |
| 570 } else if (technology == shill::kNetworkTechnologyHspa) { | |
| 571 icon = &kNetworkBadgeTechnologyHspaIcon; | |
| 572 } else if (technology == shill::kNetworkTechnologyHspaPlus) { | |
| 573 icon = &kNetworkBadgeTechnologyHspaPlusIcon; | |
| 574 } else if (technology == shill::kNetworkTechnologyLte) { | |
| 575 icon = &kNetworkBadgeTechnologyLteIcon; | |
| 576 } else if (technology == shill::kNetworkTechnologyLteAdvanced) { | |
| 577 icon = &kNetworkBadgeTechnologyLteAdvancedIcon; | |
| 578 } else { | |
| 579 return gfx::ImageSkia(); | |
| 580 } | |
| 581 return gfx::CreateVectorIcon(*icon, GetDefaultColorForIconType(icon_type)); | |
| 582 } | |
| 583 | |
| 584 int id = -1; | |
| 585 if (technology == shill::kNetworkTechnologyEvdo) { | 491 if (technology == shill::kNetworkTechnologyEvdo) { |
| 586 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_EVDO_DARK | 492 icon = &kNetworkBadgeTechnologyEvdoIcon; |
| 587 : IDR_AURA_UBER_TRAY_NETWORK_EVDO_LIGHT; | |
| 588 } else if (technology == shill::kNetworkTechnology1Xrtt) { | 493 } else if (technology == shill::kNetworkTechnology1Xrtt) { |
| 589 id = IDR_AURA_UBER_TRAY_NETWORK_1X; | 494 icon = &kNetworkBadgeTechnology1xIcon; |
| 590 } else if (technology == shill::kNetworkTechnologyGprs) { | 495 } else if (technology == shill::kNetworkTechnologyGprs || |
| 591 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK | 496 technology == shill::kNetworkTechnologyGsm) { |
| 592 : IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT; | 497 icon = &kNetworkBadgeTechnologyGprsIcon; |
| 593 } else if (technology == shill::kNetworkTechnologyEdge) { | 498 } else if (technology == shill::kNetworkTechnologyEdge) { |
| 594 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_EDGE_DARK | 499 icon = &kNetworkBadgeTechnologyEdgeIcon; |
| 595 : IDR_AURA_UBER_TRAY_NETWORK_EDGE_LIGHT; | |
| 596 } else if (technology == shill::kNetworkTechnologyUmts) { | 500 } else if (technology == shill::kNetworkTechnologyUmts) { |
| 597 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_3G_DARK | 501 icon = &kNetworkBadgeTechnology3gIcon; |
| 598 : IDR_AURA_UBER_TRAY_NETWORK_3G_LIGHT; | |
| 599 } else if (technology == shill::kNetworkTechnologyHspa) { | 502 } else if (technology == shill::kNetworkTechnologyHspa) { |
| 600 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_HSPA_DARK | 503 icon = &kNetworkBadgeTechnologyHspaIcon; |
| 601 : IDR_AURA_UBER_TRAY_NETWORK_HSPA_LIGHT; | |
| 602 } else if (technology == shill::kNetworkTechnologyHspaPlus) { | 504 } else if (technology == shill::kNetworkTechnologyHspaPlus) { |
| 603 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_HSPA_PLUS_DARK | 505 icon = &kNetworkBadgeTechnologyHspaPlusIcon; |
| 604 : IDR_AURA_UBER_TRAY_NETWORK_HSPA_PLUS_LIGHT; | |
| 605 } else if (technology == shill::kNetworkTechnologyLte) { | 506 } else if (technology == shill::kNetworkTechnologyLte) { |
| 606 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_LTE_DARK | 507 icon = &kNetworkBadgeTechnologyLteIcon; |
| 607 : IDR_AURA_UBER_TRAY_NETWORK_LTE_LIGHT; | |
| 608 } else if (technology == shill::kNetworkTechnologyLteAdvanced) { | 508 } else if (technology == shill::kNetworkTechnologyLteAdvanced) { |
| 609 id = IconTypeIsDark(icon_type) | 509 icon = &kNetworkBadgeTechnologyLteAdvancedIcon; |
| 610 ? IDR_AURA_UBER_TRAY_NETWORK_LTE_ADVANCED_DARK | |
| 611 : IDR_AURA_UBER_TRAY_NETWORK_LTE_ADVANCED_LIGHT; | |
| 612 } else if (technology == shill::kNetworkTechnologyGsm) { | |
| 613 id = IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK | |
| 614 : IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT; | |
| 615 } else { | 510 } else { |
| 616 return gfx::ImageSkia(); | 511 return gfx::ImageSkia(); |
| 617 } | 512 } |
| 618 return *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | 513 return gfx::CreateVectorIcon(*icon, GetDefaultColorForIconType(icon_type)); |
| 619 } | 514 } |
| 620 | 515 |
| 621 gfx::ImageSkia GetIcon(const NetworkState* network, | 516 gfx::ImageSkia GetIcon(const NetworkState* network, |
| 622 IconType icon_type, | 517 IconType icon_type, |
| 623 int strength_index) { | 518 int strength_index) { |
| 624 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 625 if (network->Matches(NetworkTypePattern::Ethernet())) { | 519 if (network->Matches(NetworkTypePattern::Ethernet())) { |
| 626 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 520 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
| 627 return UseMd() ? gfx::CreateVectorIcon( | 521 return gfx::CreateVectorIcon(kNetworkEthernetIcon, |
| 628 kNetworkEthernetIcon, | 522 GetDefaultColorForIconType(ICON_TYPE_LIST)); |
| 629 GetDefaultColorForIconType(ICON_TYPE_LIST)) | |
| 630 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | |
| 631 } else if (network->Matches(NetworkTypePattern::Wireless())) { | 523 } else if (network->Matches(NetworkTypePattern::Wireless())) { |
| 632 DCHECK(strength_index > 0); | 524 DCHECK(strength_index > 0); |
| 633 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, | 525 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, |
| 634 strength_index); | 526 strength_index); |
| 635 } else if (network->Matches(NetworkTypePattern::VPN())) { | 527 } else if (network->Matches(NetworkTypePattern::VPN())) { |
| 636 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 528 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
| 637 return GetVpnImage(); | 529 return GetVpnImage(); |
| 638 } | 530 } |
| 639 | 531 |
| 640 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); | 532 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 654 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 546 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
| 655 | 547 |
| 656 gfx::ImageSkia icon; | 548 gfx::ImageSkia icon; |
| 657 Badges badges; | 549 Badges badges; |
| 658 if (connected_network) { | 550 if (connected_network) { |
| 659 icon = GetImageForNetwork(connected_network, icon_type); | 551 icon = GetImageForNetwork(connected_network, icon_type); |
| 660 badges.bottom_left = ConnectingVpnBadge(animation, icon_type); | 552 badges.bottom_left = ConnectingVpnBadge(animation, icon_type); |
| 661 } else { | 553 } else { |
| 662 icon = ConnectingVpnImage(animation); | 554 icon = ConnectingVpnImage(animation); |
| 663 } | 555 } |
| 664 return UseMd() ? NetworkIconImageSourceMd::CreateImage(icon, badges) | 556 return NetworkIconImageSource::CreateImage(icon, badges); |
| 665 : gfx::ImageSkia(new NetworkIconImageSource(icon, badges), | |
| 666 icon.size()); | |
| 667 } | 557 } |
| 668 | 558 |
| 669 gfx::ImageSkia GetConnectingImage(IconType icon_type, | 559 gfx::ImageSkia GetConnectingImage(IconType icon_type, |
| 670 const std::string& network_type) { | 560 const std::string& network_type) { |
| 671 if (network_type == shill::kTypeVPN) | 561 if (network_type == shill::kTypeVPN) |
| 672 return GetConnectingVpnImage(icon_type); | 562 return GetConnectingVpnImage(icon_type); |
| 673 | 563 |
| 674 ImageType image_type = ImageTypeForNetworkType(network_type); | 564 ImageType image_type = ImageTypeForNetworkType(network_type); |
| 675 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 565 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
| 676 | 566 |
| 677 gfx::ImageSkia* icon = | 567 return NetworkIconImageSource::CreateImage( |
| 678 ConnectingWirelessImage(image_type, icon_type, animation); | 568 *ConnectingWirelessImage(image_type, icon_type, animation), Badges()); |
| 679 return UseMd() ? NetworkIconImageSourceMd::CreateImage(*icon, Badges()) | |
| 680 : gfx::ImageSkia(new NetworkIconImageSource(*icon, Badges()), | |
| 681 icon->size()); | |
| 682 } | 569 } |
| 683 | 570 |
| 684 } // namespace | 571 } // namespace |
| 685 | 572 |
| 686 //------------------------------------------------------------------------------ | 573 //------------------------------------------------------------------------------ |
| 687 // NetworkIconImpl | 574 // NetworkIconImpl |
| 688 | 575 |
| 689 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) | 576 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) |
| 690 : network_path_(path), | 577 : network_path_(path), |
| 691 icon_type_(icon_type), | 578 icon_type_(icon_type), |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 765 return false; | 652 return false; |
| 766 behind_captive_portal_ = behind_captive_portal; | 653 behind_captive_portal_ = behind_captive_portal; |
| 767 return true; | 654 return true; |
| 768 } | 655 } |
| 769 | 656 |
| 770 bool NetworkIconImpl::UpdateVPNBadge() { | 657 bool NetworkIconImpl::UpdateVPNBadge() { |
| 771 const NetworkState* vpn = | 658 const NetworkState* vpn = |
| 772 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( | 659 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( |
| 773 NetworkTypePattern::VPN()); | 660 NetworkTypePattern::VPN()); |
| 774 if (vpn && vpn_badge_.isNull()) { | 661 if (vpn && vpn_badge_.isNull()) { |
| 775 vpn_badge_ = | 662 vpn_badge_ = gfx::CreateVectorIcon(kNetworkBadgeVpnIcon, |
| 776 UseMd() ? gfx::CreateVectorIcon(kNetworkBadgeVpnIcon, | 663 GetDefaultColorForIconType(icon_type_)); |
| 777 GetDefaultColorForIconType(icon_type_)) | |
| 778 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 779 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | |
| 780 return true; | 664 return true; |
| 781 } | 665 } |
| 782 if (!vpn && !vpn_badge_.isNull()) { | 666 if (!vpn && !vpn_badge_.isNull()) { |
| 783 vpn_badge_ = gfx::ImageSkia(); | 667 vpn_badge_ = gfx::ImageSkia(); |
| 784 return true; | 668 return true; |
| 785 } | 669 } |
| 786 return false; | 670 return false; |
| 787 } | 671 } |
| 788 | 672 |
| 789 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { | 673 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { |
| 790 DCHECK(network); | 674 DCHECK(network); |
| 791 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 792 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | |
| 793 | 675 |
| 794 const std::string& type = network->type(); | 676 const std::string& type = network->type(); |
| 795 const SkColor icon_color = GetDefaultColorForIconType(icon_type_); | 677 const SkColor icon_color = GetDefaultColorForIconType(icon_type_); |
| 796 if (type == shill::kTypeWifi) { | 678 if (type == shill::kTypeWifi) { |
| 797 if (network->security_class() != shill::kSecurityNone && | 679 if (network->security_class() != shill::kSecurityNone && |
| 798 IconTypeIsDark(icon_type_)) { | 680 IconTypeIsDark(icon_type_)) { |
| 799 badges->bottom_right = | 681 badges->bottom_right = |
| 800 UseMd() | 682 gfx::CreateVectorIcon(kNetworkBadgeSecureIcon, icon_color); |
| 801 ? gfx::CreateVectorIcon(kNetworkBadgeSecureIcon, icon_color) | |
| 802 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_SECURE_DARK); | |
| 803 } | 683 } |
| 804 } else if (type == shill::kTypeWimax) { | 684 } else if (type == shill::kTypeWimax) { |
| 805 technology_badge_ = | 685 technology_badge_ = |
| 806 UseMd() | 686 gfx::CreateVectorIcon(kNetworkBadgeTechnology4gIcon, icon_color); |
| 807 ? gfx::CreateVectorIcon(kNetworkBadgeTechnology4gIcon, icon_color) | |
| 808 : *rb.GetImageSkiaNamed(IconTypeIsDark(icon_type_) | |
| 809 ? IDR_AURA_UBER_TRAY_NETWORK_4G_DARK | |
| 810 : IDR_AURA_UBER_TRAY_NETWORK_4G_LIGHT); | |
| 811 } else if (type == shill::kTypeCellular) { | 687 } else if (type == shill::kTypeCellular) { |
| 812 if (network->roaming() == shill::kRoamingStateRoaming) { | 688 if (network->roaming() == shill::kRoamingStateRoaming) { |
| 813 // For networks that are always in roaming don't show roaming badge. | 689 // For networks that are always in roaming don't show roaming badge. |
| 814 const DeviceState* device = | 690 const DeviceState* device = |
| 815 handler->GetDeviceState(network->device_path()); | 691 NetworkHandler::Get()->network_state_handler()->GetDeviceState( |
| 692 network->device_path()); | |
| 816 LOG_IF(WARNING, !device) << "Could not find device state for " | 693 LOG_IF(WARNING, !device) << "Could not find device state for " |
| 817 << network->device_path(); | 694 << network->device_path(); |
| 818 if (!device || !device->provider_requires_roaming()) { | 695 if (!device || !device->provider_requires_roaming()) { |
| 819 badges->bottom_right = | 696 badges->bottom_right = |
| 820 UseMd() | 697 gfx::CreateVectorIcon(kNetworkBadgeRoamingIcon, icon_color); |
| 821 ? gfx::CreateVectorIcon(kNetworkBadgeRoamingIcon, icon_color) | |
| 822 : *rb.GetImageSkiaNamed( | |
| 823 IconTypeIsDark(icon_type_) | |
| 824 ? IDR_AURA_UBER_TRAY_NETWORK_ROAMING_DARK | |
| 825 : IDR_AURA_UBER_TRAY_NETWORK_ROAMING_LIGHT); | |
| 826 } | 698 } |
| 827 } | 699 } |
| 828 } | 700 } |
| 829 if (!network->IsConnectingState()) { | 701 if (!network->IsConnectingState()) { |
| 830 badges->top_left = technology_badge_; | 702 badges->top_left = technology_badge_; |
| 831 badges->bottom_left = vpn_badge_; | 703 badges->bottom_left = vpn_badge_; |
| 832 } | 704 } |
| 833 | 705 |
| 834 if (behind_captive_portal_) { | 706 if (behind_captive_portal_) { |
| 835 badges->bottom_right = | 707 badges->bottom_right = |
| 836 UseMd() | 708 gfx::CreateVectorIcon(kNetworkBadgeCaptivePortalIcon, icon_color); |
| 837 ? gfx::CreateVectorIcon(kNetworkBadgeCaptivePortalIcon, icon_color) | |
| 838 : *rb.GetImageSkiaNamed( | |
| 839 IconTypeIsDark(icon_type_) | |
| 840 ? IDR_AURA_UBER_TRAY_NETWORK_PORTAL_DARK | |
| 841 : IDR_AURA_UBER_TRAY_NETWORK_PORTAL_LIGHT); | |
| 842 } | 709 } |
| 843 } | 710 } |
| 844 | 711 |
| 845 void NetworkIconImpl::GenerateImage(const NetworkState* network) { | 712 void NetworkIconImpl::GenerateImage(const NetworkState* network) { |
| 846 DCHECK(network); | 713 DCHECK(network); |
| 847 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); | 714 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); |
| 848 Badges badges; | 715 Badges badges; |
| 849 GetBadges(network, &badges); | 716 GetBadges(network, &badges); |
| 850 image_ = UseMd() ? NetworkIconImageSourceMd::CreateImage(icon, badges) | 717 image_ = NetworkIconImageSource::CreateImage(icon, badges); |
| 851 : gfx::ImageSkia(new NetworkIconImageSource(icon, badges), | |
| 852 icon.size()); | |
| 853 } | 718 } |
| 854 | 719 |
| 855 namespace { | 720 namespace { |
| 856 | 721 |
| 857 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, | 722 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, |
| 858 IconType icon_type) { | 723 IconType icon_type) { |
| 859 // Find or add the icon. | 724 // Find or add the icon. |
| 860 NetworkIconMap* icon_map = GetIconMap(icon_type); | 725 NetworkIconMap* icon_map = GetIconMap(icon_type); |
| 861 NetworkIconImpl* icon; | 726 NetworkIconImpl* icon; |
| 862 NetworkIconMap::iterator iter = icon_map->find(network->path()); | 727 NetworkIconMap::iterator iter = icon_map->find(network->path()); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 gfx::ImageSkia GetImageForNewWifiNetwork(SkColor icon_color, | 769 gfx::ImageSkia GetImageForNewWifiNetwork(SkColor icon_color, |
| 905 SkColor badge_color) { | 770 SkColor badge_color) { |
| 906 SignalStrengthImageSource* source = | 771 SignalStrengthImageSource* source = |
| 907 new SignalStrengthImageSource(ImageTypeForNetworkType(shill::kTypeWifi), | 772 new SignalStrengthImageSource(ImageTypeForNetworkType(shill::kTypeWifi), |
| 908 ICON_TYPE_LIST, kNumNetworkImages - 1); | 773 ICON_TYPE_LIST, kNumNetworkImages - 1); |
| 909 source->set_color(icon_color); | 774 source->set_color(icon_color); |
| 910 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size()); | 775 gfx::ImageSkia icon = gfx::ImageSkia(source, source->size()); |
| 911 Badges badges; | 776 Badges badges; |
| 912 badges.bottom_right = | 777 badges.bottom_right = |
| 913 gfx::CreateVectorIcon(kNetworkBadgeAddOtherIcon, badge_color); | 778 gfx::CreateVectorIcon(kNetworkBadgeAddOtherIcon, badge_color); |
| 914 return NetworkIconImageSourceMd::CreateImage(icon, badges); | 779 return NetworkIconImageSource::CreateImage(icon, badges); |
| 915 } | 780 } |
| 916 | 781 |
| 917 gfx::ImageSkia GetVpnImage() { | 782 gfx::ImageSkia GetVpnImage() { |
| 918 return UseMd() | 783 return gfx::CreateVectorIcon(kNetworkVpnIcon, |
| 919 ? gfx::CreateVectorIcon(kNetworkVpnIcon, | 784 GetDefaultColorForIconType(ICON_TYPE_LIST)); |
| 920 GetDefaultColorForIconType(ICON_TYPE_LIST)) | |
| 921 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 922 IDR_AURA_UBER_TRAY_NETWORK_VPN); | |
| 923 } | 785 } |
| 924 | 786 |
| 925 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, | 787 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, |
| 926 IconType icon_type) { | 788 IconType icon_type) { |
| 927 DCHECK(network); | 789 DCHECK(network); |
| 928 std::string activation_state = network->activation_state(); | 790 std::string activation_state = network->activation_state(); |
| 929 if (icon_type == ICON_TYPE_LIST || icon_type == ICON_TYPE_MENU_LIST) { | 791 if (icon_type == ICON_TYPE_LIST || icon_type == ICON_TYPE_MENU_LIST) { |
| 930 // Show "<network>: [Connecting|Activating|Reconnecting]..." | 792 // Show "<network>: [Connecting|Activating|Reconnecting]..." |
| 931 // TODO(varkha): Remaining states should migrate to secondary status in the | 793 // TODO(varkha): Remaining states should migrate to secondary status in the |
| 932 // network item and no longer be part of the label. | 794 // network item and no longer be part of the label. |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1090 network_paths.insert((*iter)->path()); | 952 network_paths.insert((*iter)->path()); |
| 1091 } | 953 } |
| 1092 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 954 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
| 1093 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 955 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
| 1094 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 956 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
| 1095 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths); | 957 PurgeIconMap(ICON_TYPE_MENU_LIST, network_paths); |
| 1096 } | 958 } |
| 1097 | 959 |
| 1098 } // namespace network_icon | 960 } // namespace network_icon |
| 1099 } // namespace ash | 961 } // namespace ash |
| OLD | NEW |