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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
309 // Depicts a given signal strength using arcs (e.g. for WiFi connections) or | 309 // Depicts a given signal strength using arcs (e.g. for WiFi connections) or |
310 // bars (e.g. for cell connections). | 310 // bars (e.g. for cell connections). |
311 class SignalStrengthImageSource : public gfx::CanvasImageSource { | 311 class SignalStrengthImageSource : public gfx::CanvasImageSource { |
312 public: | 312 public: |
313 SignalStrengthImageSource(ImageType image_type, | 313 SignalStrengthImageSource(ImageType image_type, |
314 IconType icon_type, | 314 IconType icon_type, |
315 int signal_strength) | 315 int signal_strength) |
316 : CanvasImageSource(GetSizeForIconType(icon_type), false), | 316 : CanvasImageSource(GetSizeForIconType(icon_type), false), |
317 image_type_(image_type), | 317 image_type_(image_type), |
318 icon_type_(icon_type), | 318 icon_type_(icon_type), |
319 color_(GetBaseColorForIconType(icon_type_)), | |
Evan Stade
2016/09/23 01:22:34
nit: maybe GetDefaultColorForIconType makes more s
varkha
2016/09/23 04:50:35
Done.
| |
319 signal_strength_(signal_strength) { | 320 signal_strength_(signal_strength) { |
320 if (image_type_ == NONE) | 321 if (image_type_ == NONE) |
321 image_type_ = ARCS; | 322 image_type_ = ARCS; |
322 | 323 |
323 DCHECK_GE(signal_strength, 0); | 324 DCHECK_GE(signal_strength, 0); |
324 DCHECK_LT(signal_strength, kNumNetworkImages); | 325 DCHECK_LT(signal_strength, kNumNetworkImages); |
325 } | 326 } |
326 ~SignalStrengthImageSource() override {} | 327 ~SignalStrengthImageSource() override {} |
327 | 328 |
329 void set_color(SkColor color) { color_ = color; } | |
330 | |
328 // gfx::CanvasImageSource: | 331 // gfx::CanvasImageSource: |
329 void Draw(gfx::Canvas* canvas) override { | 332 void Draw(gfx::Canvas* canvas) override { |
330 if (image_type_ == ARCS) | 333 if (image_type_ == ARCS) |
331 DrawArcs(canvas); | 334 DrawArcs(canvas); |
332 else | 335 else |
333 DrawBars(canvas); | 336 DrawBars(canvas); |
334 } | 337 } |
335 | 338 |
336 bool HasRepresentationAtAllScales() const override { | 339 bool HasRepresentationAtAllScales() const override { |
337 return true; | 340 return true; |
(...skipping 15 matching lines...) Expand all Loading... | |
353 oval_bounds.Inset(-oval_bounds.width() / 2, 0, -oval_bounds.width() / 2, | 356 oval_bounds.Inset(-oval_bounds.width() / 2, 0, -oval_bounds.width() / 2, |
354 -oval_bounds.height()); | 357 -oval_bounds.height()); |
355 | 358 |
356 const SkScalar kAngleAboveHorizontal = 51.f; | 359 const SkScalar kAngleAboveHorizontal = 51.f; |
357 const SkScalar kStartAngle = 180.f + kAngleAboveHorizontal; | 360 const SkScalar kStartAngle = 180.f + kAngleAboveHorizontal; |
358 const SkScalar kSweepAngle = 180.f - 2 * kAngleAboveHorizontal; | 361 const SkScalar kSweepAngle = 180.f - 2 * kAngleAboveHorizontal; |
359 | 362 |
360 SkPaint paint; | 363 SkPaint paint; |
361 paint.setAntiAlias(true); | 364 paint.setAntiAlias(true); |
362 paint.setStyle(SkPaint::kFill_Style); | 365 paint.setStyle(SkPaint::kFill_Style); |
363 const SkColor base_color = GetBaseColorForIconType(icon_type_); | |
364 // Background. Skip drawing for full signal. | 366 // Background. Skip drawing for full signal. |
365 if (signal_strength_ != kNumNetworkImages - 1) { | 367 if (signal_strength_ != kNumNetworkImages - 1) { |
366 paint.setColor(SkColorSetA(base_color, kBgAlpha)); | 368 paint.setColor(SkColorSetA(color_, kBgAlpha)); |
367 canvas->sk_canvas()->drawArc(gfx::RectFToSkRect(oval_bounds), kStartAngle, | 369 canvas->sk_canvas()->drawArc(gfx::RectFToSkRect(oval_bounds), kStartAngle, |
368 kSweepAngle, true, paint); | 370 kSweepAngle, true, paint); |
369 } | 371 } |
370 // Foreground (signal strength). | 372 // Foreground (signal strength). |
371 if (signal_strength_ != 0) { | 373 if (signal_strength_ != 0) { |
372 paint.setColor(base_color); | 374 paint.setColor(color_); |
373 // Percent of the height of the background wedge that we draw the | 375 // Percent of the height of the background wedge that we draw the |
374 // foreground wedge, indexed by signal strength. | 376 // foreground wedge, indexed by signal strength. |
375 static const float kWedgeHeightPercentages[] = {0.f, 0.375f, 0.5833f, | 377 static const float kWedgeHeightPercentages[] = {0.f, 0.375f, 0.5833f, |
376 0.75f, 1.f}; | 378 0.75f, 1.f}; |
377 const float wedge_percent = kWedgeHeightPercentages[signal_strength_]; | 379 const float wedge_percent = kWedgeHeightPercentages[signal_strength_]; |
378 oval_bounds.Inset( | 380 oval_bounds.Inset( |
379 gfx::InsetsF((oval_bounds.height() / 2) * (1.f - wedge_percent))); | 381 gfx::InsetsF((oval_bounds.height() / 2) * (1.f - wedge_percent))); |
380 canvas->sk_canvas()->drawArc(gfx::RectFToSkRect(oval_bounds), kStartAngle, | 382 canvas->sk_canvas()->drawArc(gfx::RectFToSkRect(oval_bounds), kStartAngle, |
381 kSweepAngle, true, paint); | 383 kSweepAngle, true, paint); |
382 } | 384 } |
(...skipping 16 matching lines...) Expand all Loading... | |
399 triangle.moveTo(scale(kIconInset), scale(kIconInset + kFullTriangleSide)); | 401 triangle.moveTo(scale(kIconInset), scale(kIconInset + kFullTriangleSide)); |
400 triangle.rLineTo(scale(side), 0); | 402 triangle.rLineTo(scale(side), 0); |
401 triangle.rLineTo(0, -scale(side)); | 403 triangle.rLineTo(0, -scale(side)); |
402 triangle.close(); | 404 triangle.close(); |
403 return triangle; | 405 return triangle; |
404 }; | 406 }; |
405 | 407 |
406 SkPaint paint; | 408 SkPaint paint; |
407 paint.setAntiAlias(true); | 409 paint.setAntiAlias(true); |
408 paint.setStyle(SkPaint::kFill_Style); | 410 paint.setStyle(SkPaint::kFill_Style); |
409 const SkColor base_color = GetBaseColorForIconType(icon_type_); | |
410 // Background. Skip drawing for full signal. | 411 // Background. Skip drawing for full signal. |
411 if (signal_strength_ != kNumNetworkImages - 1) { | 412 if (signal_strength_ != kNumNetworkImages - 1) { |
412 paint.setColor(SkColorSetA(base_color, kBgAlpha)); | 413 paint.setColor(SkColorSetA(color_, kBgAlpha)); |
413 canvas->DrawPath(make_triangle(kFullTriangleSide), paint); | 414 canvas->DrawPath(make_triangle(kFullTriangleSide), paint); |
414 } | 415 } |
415 // Foreground (signal strength). | 416 // Foreground (signal strength). |
416 if (signal_strength_ != 0) { | 417 if (signal_strength_ != 0) { |
417 paint.setColor(base_color); | 418 paint.setColor(color_); |
418 // As a percentage of the bg triangle, the length of one of the short | 419 // As a percentage of the bg triangle, the length of one of the short |
419 // sides of the fg triangle, indexed by signal strength. | 420 // sides of the fg triangle, indexed by signal strength. |
420 static const float kTriangleSidePercents[] = {0.f, 0.5f, 0.625f, 0.75f, | 421 static const float kTriangleSidePercents[] = {0.f, 0.5f, 0.625f, 0.75f, |
421 1.f}; | 422 1.f}; |
422 canvas->DrawPath(make_triangle(kTriangleSidePercents[signal_strength_] * | 423 canvas->DrawPath(make_triangle(kTriangleSidePercents[signal_strength_] * |
423 kFullTriangleSide), | 424 kFullTriangleSide), |
424 paint); | 425 paint); |
425 } | 426 } |
426 } | 427 } |
427 | 428 |
428 ImageType image_type_; | 429 ImageType image_type_; |
429 IconType icon_type_; | 430 IconType icon_type_; |
431 SkColor color_; | |
430 | 432 |
431 // On a scale of 0 to kNum{Arcs,Bars}Images - 1, how connected we are. | 433 // On a scale of 0 to kNum{Arcs,Bars}Images - 1, how connected we are. |
432 int signal_strength_; | 434 int signal_strength_; |
433 | 435 |
434 // Padding between outside of icon and edge of the canvas, in dp. This value | 436 // Padding between outside of icon and edge of the canvas, in dp. This value |
435 // stays the same regardless of the canvas size (which depends on | 437 // stays the same regardless of the canvas size (which depends on |
436 // |icon_type_|). | 438 // |icon_type_|). |
437 static constexpr int kIconInset = 2; | 439 static constexpr int kIconInset = 2; |
438 | 440 |
439 // TODO(estade): share this alpha with other things in ash (battery, etc.). | 441 // TODO(estade): share this alpha with other things in ash (battery, etc.). |
(...skipping 23 matching lines...) Expand all Loading... | |
463 ImageType ImageTypeForNetworkType(const std::string& type) { | 465 ImageType ImageTypeForNetworkType(const std::string& type) { |
464 if (type == shill::kTypeWifi) | 466 if (type == shill::kTypeWifi) |
465 return ARCS; | 467 return ARCS; |
466 else if (type == shill::kTypeCellular || type == shill::kTypeWimax) | 468 else if (type == shill::kTypeCellular || type == shill::kTypeWimax) |
467 return BARS; | 469 return BARS; |
468 return NONE; | 470 return NONE; |
469 } | 471 } |
470 | 472 |
471 gfx::ImageSkia GetImageForIndex(ImageType image_type, | 473 gfx::ImageSkia GetImageForIndex(ImageType image_type, |
472 IconType icon_type, | 474 IconType icon_type, |
475 SkColor color, | |
473 int index) { | 476 int index) { |
474 if (UseMd()) { | 477 if (UseMd()) { |
475 gfx::CanvasImageSource* source = | 478 SignalStrengthImageSource* source = |
476 new SignalStrengthImageSource(image_type, icon_type, index); | 479 new SignalStrengthImageSource(image_type, icon_type, index); |
480 if (color != SK_ColorTRANSPARENT) | |
481 source->set_color(color); | |
477 return gfx::ImageSkia(source, source->size()); | 482 return gfx::ImageSkia(source, source->size()); |
478 } | 483 } |
479 | 484 |
480 if (index < 0 || index >= kNumNetworkImages) | 485 if (index < 0 || index >= kNumNetworkImages) |
481 return gfx::ImageSkia(); | 486 return gfx::ImageSkia(); |
482 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); | 487 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); |
483 int width = images->width(); | 488 int width = images->width(); |
484 int height = images->height() / kNumNetworkImages; | 489 int height = images->height() / kNumNetworkImages; |
485 return gfx::ImageSkiaOperations::ExtractSubset(*images, | 490 return gfx::ImageSkiaOperations::ExtractSubset(*images, |
486 gfx::Rect(0, index * height, width, height)); | 491 gfx::Rect(0, index * height, width, height)); |
487 } | 492 } |
488 | 493 |
489 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, | 494 const gfx::ImageSkia GetDisconnectedImage(IconType icon_type, |
490 const std::string& network_type) { | 495 const std::string& network_type) { |
491 DCHECK_NE(shill::kTypeVPN, network_type); | 496 DCHECK_NE(shill::kTypeVPN, network_type); |
492 ImageType image_type = ImageTypeForNetworkType(network_type); | 497 ImageType image_type = ImageTypeForNetworkType(network_type); |
493 const int disconnected_index = 0; | 498 const int disconnected_index = 0; |
494 return GetImageForIndex(image_type, icon_type, disconnected_index); | 499 return GetImageForIndex(image_type, icon_type, SK_ColorTRANSPARENT, |
500 disconnected_index); | |
495 } | 501 } |
496 | 502 |
497 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, | 503 gfx::ImageSkia* ConnectingWirelessImage(ImageType image_type, |
498 IconType icon_type, | 504 IconType icon_type, |
499 double animation) { | 505 double animation) { |
500 static const int kImageCount = kNumNetworkImages - 1; | 506 static const int kImageCount = kNumNetworkImages - 1; |
501 static gfx::ImageSkia* s_bars_images_dark[kImageCount]; | 507 static gfx::ImageSkia* s_bars_images_dark[kImageCount]; |
502 static gfx::ImageSkia* s_bars_images_light[kImageCount]; | 508 static gfx::ImageSkia* s_bars_images_light[kImageCount]; |
503 static gfx::ImageSkia* s_arcs_images_dark[kImageCount]; | 509 static gfx::ImageSkia* s_arcs_images_dark[kImageCount]; |
504 static gfx::ImageSkia* s_arcs_images_light[kImageCount]; | 510 static gfx::ImageSkia* s_arcs_images_light[kImageCount]; |
505 int index = animation * nextafter(static_cast<float>(kImageCount), 0); | 511 int index = animation * nextafter(static_cast<float>(kImageCount), 0); |
506 index = std::max(std::min(index, kImageCount - 1), 0); | 512 index = std::max(std::min(index, kImageCount - 1), 0); |
507 gfx::ImageSkia** images; | 513 gfx::ImageSkia** images; |
508 bool dark = IconTypeIsDark(icon_type); | 514 bool dark = IconTypeIsDark(icon_type); |
509 if (image_type == BARS) | 515 if (image_type == BARS) |
510 images = dark ? s_bars_images_dark : s_bars_images_light; | 516 images = dark ? s_bars_images_dark : s_bars_images_light; |
511 else | 517 else |
512 images = dark ? s_arcs_images_dark : s_arcs_images_light; | 518 images = dark ? s_arcs_images_dark : s_arcs_images_light; |
513 if (!images[index]) { | 519 if (!images[index]) { |
514 // Lazily cache images. | 520 // Lazily cache images. |
515 // TODO(estade): should the alpha be applied in SignalStrengthImageSource? | 521 // TODO(estade): should the alpha be applied in SignalStrengthImageSource? |
516 gfx::ImageSkia source = GetImageForIndex(image_type, icon_type, index + 1); | 522 gfx::ImageSkia source = |
523 GetImageForIndex(image_type, icon_type, SK_ColorTRANSPARENT, index + 1); | |
517 images[index] = | 524 images[index] = |
518 new gfx::ImageSkia(gfx::ImageSkiaOperations::CreateTransparentImage( | 525 new gfx::ImageSkia(gfx::ImageSkiaOperations::CreateTransparentImage( |
519 source, kConnectingImageAlpha)); | 526 source, kConnectingImageAlpha)); |
520 } | 527 } |
521 return images[index]; | 528 return images[index]; |
522 } | 529 } |
523 | 530 |
524 gfx::ImageSkia ConnectingVpnImage(double animation) { | 531 gfx::ImageSkia ConnectingVpnImage(double animation) { |
525 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); | 532 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); |
526 static gfx::ImageSkia* s_vpn_images[kNumFadeImages]; | 533 static gfx::ImageSkia* s_vpn_images[kNumFadeImages]; |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
632 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 639 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
633 if (network->Matches(NetworkTypePattern::Ethernet())) { | 640 if (network->Matches(NetworkTypePattern::Ethernet())) { |
634 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 641 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
635 return UseMd() | 642 return UseMd() |
636 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_ETHERNET, | 643 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_ETHERNET, |
637 GetBaseColorForIconType(ICON_TYPE_LIST)) | 644 GetBaseColorForIconType(ICON_TYPE_LIST)) |
638 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | 645 : *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); |
639 } else if (network->Matches(NetworkTypePattern::Wireless())) { | 646 } else if (network->Matches(NetworkTypePattern::Wireless())) { |
640 DCHECK(strength_index > 0); | 647 DCHECK(strength_index > 0); |
641 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, | 648 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, |
642 strength_index); | 649 SK_ColorTRANSPARENT, strength_index); |
643 } else if (network->Matches(NetworkTypePattern::VPN())) { | 650 } else if (network->Matches(NetworkTypePattern::VPN())) { |
644 DCHECK_NE(ICON_TYPE_TRAY, icon_type); | 651 DCHECK_NE(ICON_TYPE_TRAY, icon_type); |
645 return GetVpnImage(); | 652 return GetVpnImage(); |
646 } | 653 } |
647 | 654 |
648 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); | 655 NOTREACHED() << "Request for icon for unsupported type: " << network->type(); |
649 return gfx::ImageSkia(); | 656 return gfx::ImageSkia(); |
650 } | 657 } |
651 | 658 |
652 //------------------------------------------------------------------------------ | 659 //------------------------------------------------------------------------------ |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
897 return GetConnectingImage(icon_type, network->type()); | 904 return GetConnectingImage(icon_type, network->type()); |
898 | 905 |
899 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); | 906 NetworkIconImpl* icon = FindAndUpdateImageImpl(network, icon_type); |
900 return icon->image(); | 907 return icon->image(); |
901 } | 908 } |
902 | 909 |
903 gfx::ImageSkia GetImageForConnectedMobileNetwork() { | 910 gfx::ImageSkia GetImageForConnectedMobileNetwork() { |
904 ImageType image_type = ImageTypeForNetworkType(shill::kTypeWifi); | 911 ImageType image_type = ImageTypeForNetworkType(shill::kTypeWifi); |
905 const IconType icon_type = ICON_TYPE_LIST; | 912 const IconType icon_type = ICON_TYPE_LIST; |
906 const int connected_index = kNumNetworkImages - 1; | 913 const int connected_index = kNumNetworkImages - 1; |
907 return GetImageForIndex(image_type, icon_type, connected_index); | 914 return GetImageForIndex(image_type, icon_type, SK_ColorTRANSPARENT, |
915 connected_index); | |
908 } | 916 } |
909 | 917 |
910 gfx::ImageSkia GetImageForDisconnectedCellNetwork() { | 918 gfx::ImageSkia GetImageForDisconnectedCellNetwork() { |
911 return GetDisconnectedImage(ICON_TYPE_LIST, shill::kTypeCellular); | 919 return GetDisconnectedImage(ICON_TYPE_LIST, shill::kTypeCellular); |
912 } | 920 } |
913 | 921 |
922 gfx::ImageSkia GetImageForHeaderWifiNetwork(SkColor icon_color, | |
Evan Stade
2016/09/23 01:22:34
nit: name suggestion - GetImageForNewWifiNetwork
varkha
2016/09/23 04:50:35
Done.
| |
923 SkColor badge_color) { | |
924 ImageType image_type = ImageTypeForNetworkType(shill::kTypeWifi); | |
925 const int connected_index = kNumNetworkImages - 1; | |
926 gfx::ImageSkia icon = | |
927 GetImageForIndex(image_type, ICON_TYPE_LIST, icon_color, connected_index); | |
Evan Stade
2016/09/23 01:22:34
I think we should just use SignalStrengthImageSour
varkha
2016/09/23 04:50:35
Done.
| |
928 Badges badges; | |
929 badges.bottom_right = gfx::CreateVectorIcon( | |
930 gfx::VectorIconId::NETWORK_BADGE_ADD_OTHER, badge_color); | |
931 return NetworkIconImageSourceMd::CreateImage(icon, badges); | |
932 } | |
933 | |
914 gfx::ImageSkia GetVpnImage() { | 934 gfx::ImageSkia GetVpnImage() { |
915 return UseMd() | 935 return UseMd() |
916 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_VPN, | 936 ? gfx::CreateVectorIcon(gfx::VectorIconId::NETWORK_VPN, |
917 GetBaseColorForIconType(ICON_TYPE_LIST)) | 937 GetBaseColorForIconType(ICON_TYPE_LIST)) |
918 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 938 : *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
919 IDR_AURA_UBER_TRAY_NETWORK_VPN); | 939 IDR_AURA_UBER_TRAY_NETWORK_VPN); |
920 } | 940 } |
921 | 941 |
922 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, | 942 base::string16 GetLabelForNetwork(const chromeos::NetworkState* network, |
923 IconType icon_type) { | 943 IconType icon_type) { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1083 iter != networks.end(); ++iter) { | 1103 iter != networks.end(); ++iter) { |
1084 network_paths.insert((*iter)->path()); | 1104 network_paths.insert((*iter)->path()); |
1085 } | 1105 } |
1086 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 1106 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
1087 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 1107 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
1088 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 1108 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
1089 } | 1109 } |
1090 | 1110 |
1091 } // namespace network_icon | 1111 } // namespace network_icon |
1092 } // namespace ui | 1112 } // namespace ui |
OLD | NEW |