OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/chromeos/status/network_menu_icon.h" | 5 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 | 9 |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 namespace { | 25 namespace { |
26 | 26 |
27 // Amount to fade icons while connecting. | 27 // Amount to fade icons while connecting. |
28 const double kConnectingImageAlpha = 0.5; | 28 const double kConnectingImageAlpha = 0.5; |
29 | 29 |
30 // Animation cycle length. | 30 // Animation cycle length. |
31 const int kThrobDurationMs = 750; | 31 const int kThrobDurationMs = 750; |
32 | 32 |
33 // Network strength bars images. | 33 // Network strength bars images. |
34 const int kNumBarsImages = 5; | 34 const int kNumBarsImages = 5; |
35 SkBitmap kBarsImagesAnimating[kNumBarsImages - 1]; | 35 SkBitmap* kBarsImagesAnimating[kNumBarsImages - 1]; |
36 | 36 |
37 // Network strength arcs images. | 37 // Network strength arcs images. |
38 const int kNumArcsImages = 5; | 38 const int kNumArcsImages = 5; |
39 SkBitmap kArcsImagesAnimating[kNumArcsImages - 1]; | 39 SkBitmap* kArcsImagesAnimating[kNumArcsImages - 1]; |
40 | 40 |
41 // Badge offsets. If a badge is large enough that it won't fit within the icon | 41 // Badge offsets. If a badge is large enough that it won't fit within the icon |
42 // when using the right or bottom offset, it gets shifted inwards so it will. | 42 // when using the right or bottom offset, it gets shifted inwards so it will. |
43 const int kBadgeLeftX = 0; | 43 const int kBadgeLeftX = 0; |
44 const int kBadgeRightX = 14; | 44 const int kBadgeRightX = 14; |
45 const int kBadgeTopY = 0; | 45 const int kBadgeTopY = 0; |
46 const int kBadgeBottomY = 14; | 46 const int kBadgeBottomY = 14; |
47 | 47 |
48 // ID for VPN badge. TODO(stevenjb): replace with yellow lock icon. | 48 // ID for VPN badge. TODO(stevenjb): replace with yellow lock icon. |
49 const int kVpnBadgeId = IDR_STATUSBAR_NETWORK_SECURE; | 49 const int kVpnBadgeId = IDR_STATUSBAR_NETWORK_SECURE; |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 return 0; | 519 return 0; |
520 } | 520 } |
521 return animation_connecting_.GetCurrentValue(); | 521 return animation_connecting_.GetCurrentValue(); |
522 } | 522 } |
523 | 523 |
524 // Fades the bars a bit and cycles through the different bar states. | 524 // Fades the bars a bit and cycles through the different bar states. |
525 void NetworkMenuIcon::SetConnectingIcon(const Network* network, | 525 void NetworkMenuIcon::SetConnectingIcon(const Network* network, |
526 double animation) { | 526 double animation) { |
527 int image_count; | 527 int image_count; |
528 BitmapType bitmap_type; | 528 BitmapType bitmap_type; |
529 SkBitmap* images; | 529 SkBitmap** images; |
530 | 530 |
531 if (network->type() == TYPE_WIFI) { | 531 if (network->type() == TYPE_WIFI) { |
532 image_count = kNumArcsImages - 1; | 532 image_count = kNumArcsImages - 1; |
533 bitmap_type = ARCS; | 533 bitmap_type = ARCS; |
534 images = kArcsImagesAnimating; | 534 images = kArcsImagesAnimating; |
535 } else { | 535 } else { |
536 image_count = kNumBarsImages - 1; | 536 image_count = kNumBarsImages - 1; |
537 bitmap_type = BARS; | 537 bitmap_type = BARS; |
538 images = kBarsImagesAnimating; | 538 images = kBarsImagesAnimating; |
539 } | 539 } |
540 int index = static_cast<int>( | 540 int index = static_cast<int>( |
541 animation * nextafter(static_cast<float>(image_count), 0)); | 541 animation * nextafter(static_cast<float>(image_count), 0)); |
542 index = max(min(index, image_count - 1), 0); | 542 index = max(min(index, image_count - 1), 0); |
543 | 543 |
544 // Lazily cache images. | 544 // Lazily cache images. |
545 if (images[index].empty()) { | 545 if (!images[index]) { |
546 SkBitmap source = GetBitmap(bitmap_type, index + 1); | 546 SkBitmap source = GetBitmap(bitmap_type, index + 1); |
547 images[index] = NetworkMenuIcon::GenerateConnectingBitmap(source); | 547 images[index] = |
| 548 new SkBitmap(NetworkMenuIcon::GenerateConnectingBitmap(source)); |
548 } | 549 } |
549 icon_->set_icon(images[index]); | 550 icon_->set_icon(*images[index]); |
550 } | 551 } |
551 | 552 |
552 // Sets up the icon and badges for GenerateBitmap(). | 553 // Sets up the icon and badges for GenerateBitmap(). |
553 void NetworkMenuIcon::SetIconAndText(string16* text) { | 554 void NetworkMenuIcon::SetIconAndText(string16* text) { |
554 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | 555 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); |
555 DCHECK(cros); | 556 DCHECK(cros); |
556 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 557 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
557 | 558 |
558 icon_->ClearIconAndBadges(); | 559 icon_->ClearIconAndBadges(); |
559 | 560 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
795 | 796 |
796 const SkBitmap NetworkMenuIcon::GetConnectedBitmap(BitmapType type) { | 797 const SkBitmap NetworkMenuIcon::GetConnectedBitmap(BitmapType type) { |
797 return GetBitmap(type, NumBitmaps(type) - 1); | 798 return GetBitmap(type, NumBitmaps(type) - 1); |
798 } | 799 } |
799 | 800 |
800 int NetworkMenuIcon::NumBitmaps(BitmapType type) { | 801 int NetworkMenuIcon::NumBitmaps(BitmapType type) { |
801 return (type == ARCS) ? kNumArcsImages : kNumBarsImages; | 802 return (type == ARCS) ? kNumArcsImages : kNumBarsImages; |
802 } | 803 } |
803 | 804 |
804 } // chromeos | 805 } // chromeos |
OLD | NEW |