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" |
| 11 #include "chrome/browser/chromeos/accessibility_util.h" |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | 12 #include "chrome/browser/chromeos/cros/cros_library.h" |
12 #include "grit/generated_resources.h" | 13 #include "grit/generated_resources.h" |
13 #include "grit/theme_resources.h" | 14 #include "grit/theme_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/gfx/canvas_skia.h" | 17 #include "ui/gfx/canvas_skia.h" |
17 #include "ui/gfx/skbitmap_operations.h" | 18 #include "ui/gfx/skbitmap_operations.h" |
18 | 19 |
19 using std::max; | 20 using std::max; |
20 using std::min; | 21 using std::min; |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 const Network* network = cros->FindNetworkByPath(service_path_); | 201 const Network* network = cros->FindNetworkByPath(service_path_); |
201 if (!network) { | 202 if (!network) { |
202 // If not a visible network, check for a remembered network. | 203 // If not a visible network, check for a remembered network. |
203 network = cros->FindRememberedNetworkByPath(service_path_); | 204 network = cros->FindRememberedNetworkByPath(service_path_); |
204 if (!network) { | 205 if (!network) { |
205 LOG(WARNING) << "Unable to find network:" << service_path_; | 206 LOG(WARNING) << "Unable to find network:" << service_path_; |
206 return; | 207 return; |
207 } | 208 } |
208 } | 209 } |
209 bool dirty = bitmap_.empty(); | 210 bool dirty = bitmap_.empty(); |
| 211 bool speak = false; |
| 212 if ((Network::IsConnectedState(state_) && !network->connected()) || |
| 213 (Network::IsConnectingState(state_) && !network->connecting()) || |
| 214 (Network::IsDisconnectedState(state_) && !network->disconnected())) { |
| 215 speak = true; |
| 216 } |
210 if (state_ != network->state()) { | 217 if (state_ != network->state()) { |
211 state_ = network->state(); | 218 state_ = network->state(); |
212 dirty = true; | 219 dirty = true; |
213 } | 220 } |
214 ConnectionType type = network->type(); | 221 ConnectionType type = network->type(); |
215 if (type == TYPE_WIFI || type == TYPE_CELLULAR) { | 222 if (type == TYPE_WIFI || type == TYPE_CELLULAR) { |
216 int index = 0; | 223 int index = 0; |
217 if (type == TYPE_WIFI) { | 224 if (type == TYPE_WIFI) { |
218 index = WifiStrengthIndex( | 225 index = WifiStrengthIndex( |
219 static_cast<const WifiNetwork*>(network)); | 226 static_cast<const WifiNetwork*>(network)); |
(...skipping 20 matching lines...) Expand all Loading... |
240 if (type == TYPE_VPN) { | 247 if (type == TYPE_VPN) { |
241 if (cros->connected_network() != connected_network_) { | 248 if (cros->connected_network() != connected_network_) { |
242 connected_network_ = cros->connected_network(); | 249 connected_network_ = cros->connected_network(); |
243 dirty = true; | 250 dirty = true; |
244 } | 251 } |
245 } | 252 } |
246 if (dirty) { | 253 if (dirty) { |
247 UpdateIcon(network); | 254 UpdateIcon(network); |
248 GenerateBitmap(); | 255 GenerateBitmap(); |
249 } | 256 } |
| 257 if (speak) { |
| 258 std::string connection_string; |
| 259 if (Network::IsConnectedState(state_)) { |
| 260 switch (network->type()) { |
| 261 case TYPE_ETHERNET: |
| 262 connection_string = l10n_util::GetStringFUTF8( |
| 263 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 264 l10n_util::GetStringUTF16( |
| 265 IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); |
| 266 break; |
| 267 default: |
| 268 connection_string = l10n_util::GetStringFUTF8( |
| 269 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, |
| 270 UTF8ToUTF16(network->name())); |
| 271 break; |
| 272 } |
| 273 } else if (Network::IsConnectingState(state_)) { |
| 274 const Network* connecting_network = cros->connecting_network(); |
| 275 if (connecting_network && connecting_network->type() != TYPE_ETHERNET) { |
| 276 connection_string = l10n_util::GetStringFUTF8( |
| 277 IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, |
| 278 UTF8ToUTF16(connecting_network->name())); |
| 279 } |
| 280 } else if (Network::IsDisconnectedState(state_)) { |
| 281 connection_string = l10n_util::GetStringUTF8( |
| 282 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP); |
| 283 } |
| 284 if (!connection_string.empty()) { |
| 285 accessibility::MaybeSpeak(connection_string.c_str(), true, false); |
| 286 } |
| 287 } |
250 } | 288 } |
251 | 289 |
252 // Sets up the base icon image. | 290 // Sets up the base icon image. |
253 void SetIcon(const Network* network) { | 291 void SetIcon(const Network* network) { |
254 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 292 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
255 | 293 |
256 switch (network->type()) { | 294 switch (network->type()) { |
257 case TYPE_ETHERNET: { | 295 case TYPE_ETHERNET: { |
258 icon_ = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED); | 296 icon_ = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED); |
259 break; | 297 break; |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
757 | 795 |
758 const SkBitmap NetworkMenuIcon::GetConnectedBitmap(BitmapType type) { | 796 const SkBitmap NetworkMenuIcon::GetConnectedBitmap(BitmapType type) { |
759 return GetBitmap(type, NumBitmaps(type) - 1); | 797 return GetBitmap(type, NumBitmaps(type) - 1); |
760 } | 798 } |
761 | 799 |
762 int NetworkMenuIcon::NumBitmaps(BitmapType type) { | 800 int NetworkMenuIcon::NumBitmaps(BitmapType type) { |
763 return (type == ARCS) ? kNumArcsImages : kNumBarsImages; | 801 return (type == ARCS) ? kNumArcsImages : kNumBarsImages; |
764 } | 802 } |
765 | 803 |
766 } // chromeos | 804 } // chromeos |
OLD | NEW |