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

Side by Side Diff: chrome/browser/chromeos/status/network_menu_button.cc

Issue 6591017: Cache network connecting bitmaps. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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_button.h" 5 #include "chrome/browser/chromeos/status/network_menu_button.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 host_->OpenButtonOptions(this); 99 host_->OpenButtonOptions(this);
100 } 100 }
101 101
102 bool NetworkMenuButton::ShouldOpenButtonOptions() const { 102 bool NetworkMenuButton::ShouldOpenButtonOptions() const {
103 return host_->ShouldOpenButtonOptions(this); 103 return host_->ShouldOpenButtonOptions(this);
104 } 104 }
105 105
106 //////////////////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////////////////
107 // NetworkMenuButton, private methods 107 // NetworkMenuButton, private methods
108 108
109 void NetworkMenuButton::SetIconAndBadge(const SkBitmap& icon, 109 void NetworkMenuButton::SetIconAndBadge(SkBitmap* icon,
110 const SkBitmap& badge) { 110 SkBitmap* badge) {
111 icon_ = icon; 111 icon_ = icon;
112 badge_ = badge; 112 badge_ = badge;
113 SetIcon(IconForDisplay(icon_, badge_)); 113 SetIcon(IconForDisplay(icon_, badge_));
114 } 114 }
115 115
116 void NetworkMenuButton::SetIconOnly(const SkBitmap& icon) { 116 void NetworkMenuButton::SetIconOnly(SkBitmap* icon) {
117 icon_ = icon; 117 icon_ = icon;
118 SetIcon(IconForDisplay(icon_, badge_)); 118 SetIcon(IconForDisplay(icon_, badge_));
119 } 119 }
120 120
121 void NetworkMenuButton::SetBadgeOnly(const SkBitmap& badge) { 121 void NetworkMenuButton::SetBadgeOnly(SkBitmap* badge) {
122 badge_ = badge; 122 badge_ = badge;
123 SetIcon(IconForDisplay(icon_, badge_)); 123 SetIcon(IconForDisplay(icon_, badge_));
124 } 124 }
125 125
126 void NetworkMenuButton::SetNetworkIcon(NetworkLibrary* cros, 126 void NetworkMenuButton::SetNetworkIcon(NetworkLibrary* cros,
127 const Network* network) { 127 const Network* network) {
128 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 128 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
129 129
130 if (!cros || !CrosLibrary::Get()->EnsureLoaded()) { 130 if (!cros || !CrosLibrary::Get()->EnsureLoaded()) {
131 SetIconAndBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0), 131 SetIconAndBadge(rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0),
132 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); 132 rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING));
133 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( 133 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16(
134 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); 134 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)));
135 return; 135 return;
136 } 136 }
137 137
138 if (!cros->Connected() && !cros->Connecting()) { 138 if (!cros->Connected() && !cros->Connecting()) {
139 animation_connecting_.Stop(); 139 animation_connecting_.Stop();
140 SetIconAndBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0), 140 SetIconAndBadge(rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0),
141 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); 141 rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED));
142 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16( 142 SetTooltipText(UTF16ToWide(l10n_util::GetStringUTF16(
143 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP))); 143 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)));
144 return; 144 return;
145 } 145 }
146 146
147 if (cros->wifi_connecting() || cros->cellular_connecting()) { 147 if (cros->wifi_connecting() || cros->cellular_connecting()) {
148 // Start the connecting animation if not running. 148 // Start the connecting animation if not running.
149 if (!animation_connecting_.is_animating()) { 149 if (!animation_connecting_.is_animating()) {
150 animation_connecting_.Reset(); 150 animation_connecting_.Reset();
151 animation_connecting_.StartThrobbing(-1); 151 animation_connecting_.StartThrobbing(-1);
152 SetIconOnly(IconForNetworkConnecting(0, false)); 152 SetIconOnly(IconForNetworkConnecting(0, false));
153 } 153 }
154 const WirelessNetwork* wireless = NULL; 154 const WirelessNetwork* wireless = NULL;
155 if (cros->wifi_connecting()) { 155 if (cros->wifi_connecting()) {
156 wireless = cros->wifi_network(); 156 wireless = cros->wifi_network();
157 SetBadgeOnly(SkBitmap()); 157 SetBadgeOnly(NULL);
158 } else { // cellular_connecting 158 } else { // cellular_connecting
159 wireless = cros->cellular_network(); 159 wireless = cros->cellular_network();
160 SetBadgeOnly(BadgeForNetworkTechnology(cros->cellular_network())); 160 SetBadgeOnly(BadgeForNetworkTechnology(cros->cellular_network()));
161 } 161 }
162 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( 162 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16(
163 wireless->configuring() ? IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP 163 wireless->configuring() ? IDS_STATUSBAR_NETWORK_CONFIGURING_TOOLTIP
164 : IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, 164 : IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP,
165 UTF8ToUTF16(wireless->name())))); 165 UTF8ToUTF16(wireless->name()))));
166 } else { 166 } else {
167 // Stop connecting animation since we are not connecting. 167 // Stop connecting animation since we are not connecting.
168 animation_connecting_.Stop(); 168 animation_connecting_.Stop();
169 // Only set the icon, if it is an active network that changed. 169 // Only set the icon, if it is an active network that changed.
170 if (network && network->is_active()) { 170 if (network && network->is_active()) {
171 if (network->type() == TYPE_ETHERNET) { 171 if (network->type() == TYPE_ETHERNET) {
172 SetIconAndBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED), SkBitmap()); 172 SetIconAndBadge(rb.GetBitmapNamed(IDR_STATUSBAR_WIRED), NULL);
173 SetTooltipText( 173 SetTooltipText(
174 UTF16ToWide(l10n_util::GetStringFUTF16( 174 UTF16ToWide(l10n_util::GetStringFUTF16(
175 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, 175 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
176 l10n_util::GetStringUTF16( 176 l10n_util::GetStringUTF16(
177 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)))); 177 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET))));
178 } else if (network->type() == TYPE_WIFI) { 178 } else if (network->type() == TYPE_WIFI) {
179 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network); 179 const WifiNetwork* wifi = static_cast<const WifiNetwork*>(network);
180 SetIconAndBadge(IconForNetworkStrength(wifi, false), SkBitmap()); 180 SetIconAndBadge(IconForNetworkStrength(wifi, false), NULL);
181 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( 181 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16(
182 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, 182 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
183 UTF8ToUTF16(wifi->name())))); 183 UTF8ToUTF16(wifi->name()))));
184 } else if (network->type() == TYPE_CELLULAR) { 184 } else if (network->type() == TYPE_CELLULAR) {
185 const CellularNetwork* cellular = 185 const CellularNetwork* cellular =
186 static_cast<const CellularNetwork*>(network); 186 static_cast<const CellularNetwork*>(network);
187 SetIconAndBadge(IconForNetworkStrength(cellular, false), 187 SetIconAndBadge(IconForNetworkStrength(cellular, false),
188 BadgeForNetworkTechnology(cellular)); 188 BadgeForNetworkTechnology(cellular));
189 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16( 189 SetTooltipText(UTF16ToWide(l10n_util::GetStringFUTF16(
190 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, 190 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
(...skipping 11 matching lines...) Expand all
202 cros->RemoveNetworkObserver(active_network_, this); 202 cros->RemoveNetworkObserver(active_network_, this);
203 } 203 }
204 if (!new_network.empty()) { 204 if (!new_network.empty()) {
205 cros->AddNetworkObserver(new_network, this); 205 cros->AddNetworkObserver(new_network, this);
206 } 206 }
207 active_network_ = new_network; 207 active_network_ = new_network;
208 } 208 }
209 } 209 }
210 210
211 } // namespace chromeos 211 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698