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 "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 27 matching lines...) Expand all Loading... | |
| 38 using chromeos::NetworkPortalDetector; | 38 using chromeos::NetworkPortalDetector; |
| 39 using chromeos::NetworkState; | 39 using chromeos::NetworkState; |
| 40 using chromeos::NetworkStateHandler; | 40 using chromeos::NetworkStateHandler; |
| 41 using chromeos::NetworkTypePattern; | 41 using chromeos::NetworkTypePattern; |
| 42 | 42 |
| 43 namespace ui { | 43 namespace ui { |
| 44 namespace network_icon { | 44 namespace network_icon { |
| 45 | 45 |
| 46 namespace { | 46 namespace { |
| 47 | 47 |
| 48 // Constants for offseting the badge displayed on top of the signal strength | |
| 49 // icon. The badge will extend outside of the base icon bounds by these amounts. | |
| 50 // Only used for MD. All values are in dp. | |
| 51 | |
| 52 // The badge offsets are different depending on whether the icon is in the tray | |
| 53 // or menu. | |
| 54 const int kTrayIconBadgeOffset = 3; | |
| 55 const int kMenuIconBadgeOffset = 2; | |
| 56 | |
| 57 bool UseMd() { | |
| 58 return md_icon_controller::UseMaterialDesignNetworkIcons(); | |
| 59 } | |
| 60 | |
| 48 //------------------------------------------------------------------------------ | 61 //------------------------------------------------------------------------------ |
| 49 // Struct to pass icon badges to NetworkIconImageSource. | 62 // Struct to pass icon badges to NetworkIconImageSource. |
| 50 struct Badges { | 63 struct Badges { |
| 51 Badges() | 64 Badges() |
| 52 : top_left(NULL), | 65 : top_left(NULL), |
|
tdanderson
2016/09/08 19:11:57
nit: NULL -> nullptr while you're here
Evan Stade
2016/09/08 19:31:34
Done.
| |
| 53 top_right(NULL), | 66 top_right(NULL), |
| 54 bottom_left(NULL), | 67 bottom_left(NULL), |
| 55 bottom_right(NULL) { | 68 bottom_right(NULL) { |
| 56 } | 69 } |
| 57 const gfx::ImageSkia* top_left; | 70 const gfx::ImageSkia* top_left; |
| 58 const gfx::ImageSkia* top_right; | 71 const gfx::ImageSkia* top_right; |
| 59 const gfx::ImageSkia* bottom_left; | 72 const gfx::ImageSkia* bottom_left; |
| 60 const gfx::ImageSkia* bottom_right; | 73 const gfx::ImageSkia* bottom_right; |
| 61 }; | 74 }; |
| 62 | 75 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 const int kNumNetworkImages = 5; | 195 const int kNumNetworkImages = 5; |
| 183 | 196 |
| 184 // Number of discrete images to use for alpha fade animation | 197 // Number of discrete images to use for alpha fade animation |
| 185 const int kNumFadeImages = 10; | 198 const int kNumFadeImages = 10; |
| 186 | 199 |
| 187 SkColor GetBaseColorForIconType(IconType icon_type) { | 200 SkColor GetBaseColorForIconType(IconType icon_type) { |
| 188 // TODO(estade): use kTrayIconColor and kMenuIconColor. | 201 // TODO(estade): use kTrayIconColor and kMenuIconColor. |
| 189 return icon_type == ICON_TYPE_TRAY ? SK_ColorWHITE : gfx::kChromeIconGrey; | 202 return icon_type == ICON_TYPE_TRAY ? SK_ColorWHITE : gfx::kChromeIconGrey; |
| 190 } | 203 } |
| 191 | 204 |
| 192 gfx::Size GetSizeForIconType(IconType icon_type) { | |
| 193 // TODO(estade): use kTrayIconSize and kMenuIconSize. | |
| 194 return icon_type == ICON_TYPE_TRAY ? gfx::Size(16, 16) : gfx::Size(20, 20); | |
| 195 } | |
| 196 | |
| 197 bool IconTypeIsDark(IconType icon_type) { | 205 bool IconTypeIsDark(IconType icon_type) { |
| 198 return (icon_type != ICON_TYPE_TRAY); | 206 return (icon_type != ICON_TYPE_TRAY); |
| 199 } | 207 } |
| 200 | 208 |
| 201 bool IconTypeHasVPNBadge(IconType icon_type) { | 209 bool IconTypeHasVPNBadge(IconType icon_type) { |
| 202 return (icon_type != ICON_TYPE_LIST); | 210 return (icon_type != ICON_TYPE_LIST); |
| 203 } | 211 } |
| 204 | 212 |
| 205 //------------------------------------------------------------------------------ | |
| 206 // Classes for generating scaled images. | |
| 207 | |
| 208 const SkBitmap GetEmptyBitmap(const gfx::Size pixel_size) { | |
| 209 typedef std::pair<int, int> SizeKey; | |
| 210 typedef std::map<SizeKey, SkBitmap> SizeBitmapMap; | |
| 211 static SizeBitmapMap* s_empty_bitmaps = new SizeBitmapMap; | |
| 212 | |
| 213 SizeKey key(pixel_size.width(), pixel_size.height()); | |
| 214 | |
| 215 SizeBitmapMap::iterator iter = s_empty_bitmaps->find(key); | |
| 216 if (iter != s_empty_bitmaps->end()) | |
| 217 return iter->second; | |
| 218 | |
| 219 SkBitmap empty; | |
| 220 empty.allocN32Pixels(key.first, key.second); | |
| 221 empty.eraseARGB(0, 0, 0, 0); | |
| 222 (*s_empty_bitmaps)[key] = empty; | |
| 223 return empty; | |
| 224 } | |
| 225 | |
| 226 class EmptyImageSource: public gfx::ImageSkiaSource { | |
| 227 public: | |
| 228 explicit EmptyImageSource(const gfx::Size& size) | |
| 229 : size_(size) { | |
| 230 } | |
| 231 | |
| 232 gfx::ImageSkiaRep GetImageForScale(float scale) override { | |
| 233 gfx::Size pixel_size = gfx::ScaleToFlooredSize(size_, scale); | |
| 234 SkBitmap empty_bitmap = GetEmptyBitmap(pixel_size); | |
| 235 return gfx::ImageSkiaRep(empty_bitmap, scale); | |
| 236 } | |
| 237 | |
| 238 private: | |
| 239 const gfx::Size size_; | |
| 240 | |
| 241 DISALLOW_COPY_AND_ASSIGN(EmptyImageSource); | |
| 242 }; | |
| 243 | |
| 244 // This defines how we assemble a network icon. | 213 // This defines how we assemble a network icon. |
| 245 class NetworkIconImageSource : public gfx::ImageSkiaSource { | 214 class NetworkIconImageSource : public gfx::CanvasImageSource { |
|
tdanderson
2016/09/08 19:11:58
optional: add a TODO to remove this class and refe
Evan Stade
2016/09/08 19:31:34
I don't think it's necessary because it's guarded
| |
| 246 public: | 215 public: |
| 247 NetworkIconImageSource(const gfx::ImageSkia& icon, const Badges& badges) | 216 NetworkIconImageSource(const gfx::ImageSkia& icon, const Badges& badges) |
| 248 : icon_(icon), | 217 : CanvasImageSource(icon.size(), false), icon_(icon), badges_(badges) {} |
| 249 badges_(badges) { | |
| 250 } | |
| 251 ~NetworkIconImageSource() override {} | 218 ~NetworkIconImageSource() override {} |
| 252 | 219 |
| 253 // TODO(pkotwicz): Figure out what to do when a new image resolution becomes | 220 // TODO(pkotwicz): Figure out what to do when a new image resolution becomes |
| 254 // available. | 221 // available. |
| 255 gfx::ImageSkiaRep GetImageForScale(float scale) override { | 222 void Draw(gfx::Canvas* canvas) override { |
| 256 gfx::Canvas canvas(icon_.size(), scale, false); | 223 canvas->DrawImageInt(icon_, 0, 0); |
| 257 canvas.DrawImageInt(icon_, 0, 0); | |
| 258 | 224 |
| 259 if (badges_.top_left) | 225 if (badges_.top_left) |
| 260 canvas.DrawImageInt(*badges_.top_left, 0, 0); | 226 canvas->DrawImageInt(*badges_.top_left, 0, 0); |
| 261 if (badges_.top_right) | 227 if (badges_.top_right) |
| 262 canvas.DrawImageInt(*badges_.top_right, | 228 canvas->DrawImageInt(*badges_.top_right, |
| 263 icon_.width() - badges_.top_right->width(), 0); | 229 icon_.width() - badges_.top_right->width(), 0); |
| 264 if (badges_.bottom_left) { | 230 if (badges_.bottom_left) { |
| 265 canvas.DrawImageInt(*badges_.bottom_left, | 231 canvas->DrawImageInt(*badges_.bottom_left, 0, |
| 266 0, icon_.height() - badges_.bottom_left->height()); | 232 icon_.height() - badges_.bottom_left->height()); |
| 267 } | 233 } |
| 268 if (badges_.bottom_right) { | 234 if (badges_.bottom_right) { |
| 269 canvas.DrawImageInt(*badges_.bottom_right, | 235 canvas->DrawImageInt(*badges_.bottom_right, |
| 270 icon_.width() - badges_.bottom_right->width(), | 236 icon_.width() - badges_.bottom_right->width(), |
| 271 icon_.height() - badges_.bottom_right->height()); | 237 icon_.height() - badges_.bottom_right->height()); |
| 272 } | 238 } |
| 273 return canvas.ExtractImageRep(); | |
| 274 } | 239 } |
| 275 | 240 |
| 276 private: | 241 private: |
| 277 const gfx::ImageSkia icon_; | 242 const gfx::ImageSkia icon_; |
| 278 const Badges badges_; | 243 const Badges badges_; |
| 279 | 244 |
| 280 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); | 245 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); |
| 281 }; | 246 }; |
| 282 | 247 |
| 248 // This defines how we assemble a network icon. | |
|
tdanderson
2016/09/08 19:11:58
nit: "...in material design"
Evan Stade
2016/09/08 19:31:34
Do you think the class name makes that apparent?
| |
| 249 class NetworkIconImageSourceMd : public gfx::CanvasImageSource { | |
| 250 public: | |
| 251 static gfx::ImageSkia CreateImage(const gfx::ImageSkia& icon, | |
| 252 const Badges& badges) { | |
| 253 auto source = new NetworkIconImageSourceMd(icon, badges); | |
| 254 return gfx::ImageSkia(source, source->size()); | |
| 255 } | |
| 256 | |
| 257 // gfx::CanvasImageSource: | |
| 258 void Draw(gfx::Canvas* canvas) override { | |
| 259 int width = size().width(); | |
|
tdanderson
2016/09/08 19:11:58
int: const for width and height
| |
| 260 int height = size().height(); | |
| 261 | |
| 262 // The base icon is centered in both dimensions. | |
| 263 const int icon_y = (height - icon_.height()) / 2; | |
| 264 canvas->DrawImageInt(icon_, (width - icon_.width()) / 2, icon_y); | |
| 265 | |
| 266 // The badges are flush against the edges of the canvas, except at the top, | |
| 267 // where the badge is only 1dp higher than the base image. | |
| 268 const int top_badge_y = icon_y - 1; | |
| 269 if (badges_.top_left) | |
| 270 canvas->DrawImageInt(*badges_.top_left, 0, top_badge_y); | |
| 271 if (badges_.top_right) { | |
| 272 canvas->DrawImageInt(*badges_.top_right, | |
| 273 width - badges_.top_right->width(), top_badge_y); | |
| 274 } | |
| 275 if (badges_.bottom_left) { | |
| 276 canvas->DrawImageInt(*badges_.bottom_left, 0, | |
| 277 height - badges_.bottom_left->height()); | |
| 278 } | |
| 279 if (badges_.bottom_right) { | |
| 280 canvas->DrawImageInt(*badges_.bottom_right, | |
| 281 width - badges_.bottom_right->width(), | |
| 282 height - badges_.bottom_right->height()); | |
| 283 } | |
| 284 } | |
| 285 | |
| 286 bool HasRepresentationAtAllScales() const override { return true; } | |
| 287 | |
| 288 private: | |
| 289 NetworkIconImageSourceMd(const gfx::ImageSkia& icon, const Badges& badges) | |
| 290 : CanvasImageSource(GetSizeForBaseIconSize(icon.size()), false), | |
| 291 icon_(icon), | |
| 292 badges_(badges) {} | |
| 293 ~NetworkIconImageSourceMd() override {} | |
| 294 | |
| 295 static gfx::Size GetSizeForBaseIconSize(const gfx::Size& base_icon_size) { | |
| 296 gfx::Size size = base_icon_size; | |
| 297 int badge_offset = base_icon_size.width() == 16 ? kTrayIconBadgeOffset | |
|
tdanderson
2016/09/08 19:11:58
nit: const
Evan Stade
2016/09/08 19:31:34
why? there are lots of local variables where we co
| |
| 298 : kMenuIconBadgeOffset; | |
| 299 size.Enlarge(badge_offset * 2, badge_offset * 2); | |
| 300 return size; | |
| 301 } | |
| 302 | |
| 303 const gfx::ImageSkia icon_; | |
| 304 const Badges badges_; | |
| 305 | |
| 306 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSourceMd); | |
| 307 }; | |
| 308 | |
| 283 // 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 |
| 284 // bars (e.g. for cell connections). | 310 // bars (e.g. for cell connections). |
| 285 class NetworkIconImageSourceMd : public gfx::CanvasImageSource { | 311 class SignalStrengthImageSource : public gfx::CanvasImageSource { |
| 286 public: | 312 public: |
| 287 NetworkIconImageSourceMd(ImageType image_type, | 313 SignalStrengthImageSource(ImageType image_type, |
| 288 IconType icon_type, | 314 IconType icon_type, |
| 289 int signal_strength) | 315 int signal_strength) |
| 290 : CanvasImageSource(GetSizeForIconType(icon_type), false), | 316 : CanvasImageSource(GetSizeForIconType(icon_type), false), |
| 291 image_type_(image_type), | 317 image_type_(image_type), |
| 292 icon_type_(icon_type), | 318 icon_type_(icon_type), |
| 293 signal_strength_(signal_strength) { | 319 signal_strength_(signal_strength) { |
| 294 if (image_type_ == NONE) | 320 if (image_type_ == NONE) |
| 295 image_type_ = ARCS; | 321 image_type_ = ARCS; |
| 296 | 322 |
| 297 DCHECK_GE(signal_strength, 0); | 323 DCHECK_GE(signal_strength, 0); |
| 298 DCHECK_LT(signal_strength, kNumNetworkImages); | 324 DCHECK_LT(signal_strength, kNumNetworkImages); |
| 299 } | 325 } |
| 300 ~NetworkIconImageSourceMd() override {} | 326 ~SignalStrengthImageSource() override {} |
| 301 | 327 |
| 302 // gfx::CanvasImageSource: | 328 // gfx::CanvasImageSource: |
| 303 void Draw(gfx::Canvas* canvas) override { | 329 void Draw(gfx::Canvas* canvas) override { |
| 304 if (image_type_ == ARCS) | 330 if (image_type_ == ARCS) |
| 305 DrawArcs(canvas); | 331 DrawArcs(canvas); |
| 306 else | 332 else |
| 307 DrawBars(canvas); | 333 DrawBars(canvas); |
| 308 } | 334 } |
| 335 | |
| 309 bool HasRepresentationAtAllScales() const override { | 336 bool HasRepresentationAtAllScales() const override { |
| 310 // This image source can handle any scale factor. TODO(estade): investigate | |
| 311 // why this doesn't seem to be respected. (Perhaps because we compose | |
| 312 // multiple images that don't have representations at all scales?) | |
| 313 return true; | 337 return true; |
| 314 } | 338 } |
| 315 | 339 |
| 316 private: | 340 private: |
| 341 static gfx::Size GetSizeForIconType(IconType icon_type) { | |
| 342 // TODO(estade): use kTrayIconSize and kMenuIconSize. | |
|
tdanderson
2016/09/08 19:11:58
nit: can you define 16 and 20 as constants in this
Evan Stade
2016/09/08 19:31:34
done (more or less)
| |
| 343 return icon_type == ICON_TYPE_TRAY ? gfx::Size(16, 16) : gfx::Size(20, 20); | |
| 344 } | |
| 345 | |
| 317 void DrawArcs(gfx::Canvas* canvas) { | 346 void DrawArcs(gfx::Canvas* canvas) { |
| 318 gfx::RectF oval_bounds((gfx::Rect(size()))); | 347 gfx::RectF oval_bounds((gfx::Rect(size()))); |
| 319 oval_bounds.Inset(gfx::Insets(kIconInset)); | 348 oval_bounds.Inset(gfx::Insets(kIconInset)); |
| 320 // Double the width and height. The new midpoint should be the former | 349 // Double the width and height. The new midpoint should be the former |
| 321 // bottom center. | 350 // bottom center. |
| 322 oval_bounds.Inset(-oval_bounds.width() / 2, 0, -oval_bounds.width() / 2, | 351 oval_bounds.Inset(-oval_bounds.width() / 2, 0, -oval_bounds.width() / 2, |
| 323 -oval_bounds.height()); | 352 -oval_bounds.height()); |
| 324 | 353 |
| 325 const SkScalar kAngleAboveHorizontal = 51.f; | 354 const SkScalar kAngleAboveHorizontal = 51.f; |
| 326 const SkScalar kStartAngle = 180.f + kAngleAboveHorizontal; | 355 const SkScalar kStartAngle = 180.f + kAngleAboveHorizontal; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 | 431 |
| 403 // Padding between outside of icon and edge of the canvas, in dp. This value | 432 // Padding between outside of icon and edge of the canvas, in dp. This value |
| 404 // stays the same regardless of the canvas size (which depends on | 433 // stays the same regardless of the canvas size (which depends on |
| 405 // |icon_type_|). | 434 // |icon_type_|). |
| 406 static constexpr int kIconInset = 2; | 435 static constexpr int kIconInset = 2; |
| 407 | 436 |
| 408 // TODO(estade): share this alpha with other things in ash (battery, etc.). | 437 // TODO(estade): share this alpha with other things in ash (battery, etc.). |
| 409 // See crbug.com/623987 and crbug.com/632827 | 438 // See crbug.com/623987 and crbug.com/632827 |
| 410 static constexpr int kBgAlpha = 0x4D; | 439 static constexpr int kBgAlpha = 0x4D; |
| 411 | 440 |
| 412 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSourceMd); | 441 DISALLOW_COPY_AND_ASSIGN(SignalStrengthImageSource); |
| 413 }; | 442 }; |
| 414 | 443 |
| 415 //------------------------------------------------------------------------------ | 444 //------------------------------------------------------------------------------ |
| 416 // Utilities for extracting icon images. | 445 // Utilities for extracting icon images. |
| 417 | 446 |
| 418 gfx::ImageSkia* BaseImageForType(ImageType image_type, IconType icon_type) { | 447 gfx::ImageSkia* BaseImageForType(ImageType image_type, IconType icon_type) { |
| 419 gfx::ImageSkia* image; | 448 gfx::ImageSkia* image; |
| 420 if (image_type == BARS) { | 449 if (image_type == BARS) { |
| 421 image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 450 image = ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 422 IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK | 451 IconTypeIsDark(icon_type) ? IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 433 if (type == shill::kTypeWifi) | 462 if (type == shill::kTypeWifi) |
| 434 return ARCS; | 463 return ARCS; |
| 435 else if (type == shill::kTypeCellular || type == shill::kTypeWimax) | 464 else if (type == shill::kTypeCellular || type == shill::kTypeWimax) |
| 436 return BARS; | 465 return BARS; |
| 437 return NONE; | 466 return NONE; |
| 438 } | 467 } |
| 439 | 468 |
| 440 gfx::ImageSkia GetImageForIndex(ImageType image_type, | 469 gfx::ImageSkia GetImageForIndex(ImageType image_type, |
| 441 IconType icon_type, | 470 IconType icon_type, |
| 442 int index) { | 471 int index) { |
| 443 if (md_icon_controller::UseMaterialDesignNetworkIcons()) { | 472 if (UseMd()) { |
| 444 gfx::CanvasImageSource* source = | 473 gfx::CanvasImageSource* source = |
| 445 new NetworkIconImageSourceMd(image_type, icon_type, index); | 474 new SignalStrengthImageSource(image_type, icon_type, index); |
| 446 return gfx::ImageSkia(source, source->size()); | 475 return gfx::ImageSkia(source, source->size()); |
| 447 } | 476 } |
| 448 | 477 |
| 449 if (index < 0 || index >= kNumNetworkImages) | 478 if (index < 0 || index >= kNumNetworkImages) |
| 450 return gfx::ImageSkia(); | 479 return gfx::ImageSkia(); |
| 451 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); | 480 gfx::ImageSkia* images = BaseImageForType(image_type, icon_type); |
| 452 int width = images->width(); | 481 int width = images->width(); |
| 453 int height = images->height() / kNumNetworkImages; | 482 int height = images->height() / kNumNetworkImages; |
| 454 return gfx::ImageSkiaOperations::ExtractSubset(*images, | 483 return gfx::ImageSkiaOperations::ExtractSubset(*images, |
| 455 gfx::Rect(0, index * height, width, height)); | 484 gfx::Rect(0, index * height, width, height)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 int index = animation * nextafter(static_cast<float>(kImageCount), 0); | 518 int index = animation * nextafter(static_cast<float>(kImageCount), 0); |
| 490 index = std::max(std::min(index, kImageCount - 1), 0); | 519 index = std::max(std::min(index, kImageCount - 1), 0); |
| 491 gfx::ImageSkia** images; | 520 gfx::ImageSkia** images; |
| 492 bool dark = IconTypeIsDark(icon_type); | 521 bool dark = IconTypeIsDark(icon_type); |
| 493 if (image_type == BARS) | 522 if (image_type == BARS) |
| 494 images = dark ? s_bars_images_dark : s_bars_images_light; | 523 images = dark ? s_bars_images_dark : s_bars_images_light; |
| 495 else | 524 else |
| 496 images = dark ? s_arcs_images_dark : s_arcs_images_light; | 525 images = dark ? s_arcs_images_dark : s_arcs_images_light; |
| 497 if (!images[index]) { | 526 if (!images[index]) { |
| 498 // Lazily cache images. | 527 // Lazily cache images. |
| 528 // TODO(estade): should the alpha be applied in SignalStrengthImageSource? | |
| 499 gfx::ImageSkia source = GetImageForIndex(image_type, icon_type, index + 1); | 529 gfx::ImageSkia source = GetImageForIndex(image_type, icon_type, index + 1); |
| 500 images[index] = new gfx::ImageSkia( | 530 images[index] = |
| 501 gfx::ImageSkiaOperations::CreateBlendedImage( | 531 new gfx::ImageSkia(gfx::ImageSkiaOperations::CreateTransparentImage( |
| 502 gfx::ImageSkia(new EmptyImageSource(source.size()), source.size()), | 532 source, kConnectingImageAlpha)); |
| 503 source, | |
| 504 kConnectingImageAlpha)); | |
| 505 } | 533 } |
| 506 return images[index]; | 534 return images[index]; |
| 507 } | 535 } |
| 508 | 536 |
| 509 gfx::ImageSkia* ConnectingVpnImage(double animation) { | 537 gfx::ImageSkia* ConnectingVpnImage(double animation) { |
| 510 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); | 538 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); |
| 511 static gfx::ImageSkia* s_vpn_images[kNumFadeImages]; | 539 static gfx::ImageSkia* s_vpn_images[kNumFadeImages]; |
| 512 if (!s_vpn_images[index]) { | 540 if (!s_vpn_images[index]) { |
| 513 // Lazily cache images. | 541 // Lazily cache images. |
| 514 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 542 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 515 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); | 543 gfx::ImageSkia* icon = rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN); |
| 516 s_vpn_images[index] = new gfx::ImageSkia( | 544 s_vpn_images[index] = new gfx::ImageSkia( |
| 517 gfx::ImageSkiaOperations::CreateBlendedImage( | 545 gfx::ImageSkiaOperations::CreateTransparentImage(*icon, animation)); |
| 518 gfx::ImageSkia(new EmptyImageSource(icon->size()), icon->size()), | |
| 519 *icon, | |
| 520 animation)); | |
| 521 } | 546 } |
| 522 return s_vpn_images[index]; | 547 return s_vpn_images[index]; |
| 523 } | 548 } |
| 524 | 549 |
| 525 gfx::ImageSkia* ConnectingVpnBadge(double animation) { | 550 gfx::ImageSkia* ConnectingVpnBadge(double animation) { |
| 526 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); | 551 int index = animation * nextafter(static_cast<float>(kNumFadeImages), 0); |
| 527 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; | 552 static gfx::ImageSkia* s_vpn_badges[kNumFadeImages]; |
| 528 if (!s_vpn_badges[index]) { | 553 if (!s_vpn_badges[index]) { |
| 529 // Lazily cache images. | 554 // Lazily cache images. |
| 530 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 555 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 531 gfx::ImageSkia* icon = | |
| 532 rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); // For size | |
| 533 gfx::ImageSkia* badge = | 556 gfx::ImageSkia* badge = |
| 534 rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | 557 rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); |
| 535 s_vpn_badges[index] = new gfx::ImageSkia( | 558 s_vpn_badges[index] = new gfx::ImageSkia( |
| 536 gfx::ImageSkiaOperations::CreateBlendedImage( | 559 gfx::ImageSkiaOperations::CreateTransparentImage(*badge, animation)); |
| 537 gfx::ImageSkia(new EmptyImageSource(icon->size()), icon->size()), | |
| 538 *badge, | |
| 539 animation)); | |
| 540 } | 560 } |
| 541 return s_vpn_badges[index]; | 561 return s_vpn_badges[index]; |
| 542 } | 562 } |
| 543 | 563 |
| 544 int StrengthIndex(int strength) { | 564 int StrengthIndex(int strength) { |
| 545 // Return an index in the range [1, kNumNetworkImages - 1]. | 565 // Return an index in the range [1, kNumNetworkImages - 1]. |
| 546 const float findex = (static_cast<float>(strength) / 100.0f) * | 566 const float findex = (static_cast<float>(strength) / 100.0f) * |
| 547 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); | 567 nextafter(static_cast<float>(kNumNetworkImages - 1), 0); |
| 548 int index = 1 + static_cast<int>(findex); | 568 int index = 1 + static_cast<int>(findex); |
| 549 index = std::max(std::min(index, kNumNetworkImages - 1), 1); | 569 index = std::max(std::min(index, kNumNetworkImages - 1), 1); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 id = IconTypeIsDark(icon_type) ? | 613 id = IconTypeIsDark(icon_type) ? |
| 594 IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK : | 614 IDR_AURA_UBER_TRAY_NETWORK_GPRS_DARK : |
| 595 IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT; | 615 IDR_AURA_UBER_TRAY_NETWORK_GPRS_LIGHT; |
| 596 } | 616 } |
| 597 if (id == kUnknownBadgeType) | 617 if (id == kUnknownBadgeType) |
| 598 return NULL; | 618 return NULL; |
| 599 else | 619 else |
| 600 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); | 620 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(id); |
| 601 } | 621 } |
| 602 | 622 |
| 603 const gfx::ImageSkia* BadgeForVPN(IconType icon_type) { | |
| 604 return ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 605 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | |
| 606 } | |
| 607 | |
| 608 gfx::ImageSkia GetIcon(const NetworkState* network, | 623 gfx::ImageSkia GetIcon(const NetworkState* network, |
| 609 IconType icon_type, | 624 IconType icon_type, |
| 610 int strength_index) { | 625 int strength_index) { |
| 611 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 626 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 612 if (network->Matches(NetworkTypePattern::Ethernet())) { | 627 if (network->Matches(NetworkTypePattern::Ethernet())) { |
| 613 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); | 628 return *rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_NETWORK_WIRED); |
| 614 } else if (network->Matches(NetworkTypePattern::Wireless())) { | 629 } else if (network->Matches(NetworkTypePattern::Wireless())) { |
| 615 DCHECK(strength_index > 0); | 630 DCHECK(strength_index > 0); |
| 616 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, | 631 return GetImageForIndex(ImageTypeForNetworkType(network->type()), icon_type, |
| 617 strength_index); | 632 strength_index); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 633 if (icon_type == ICON_TYPE_TRAY) { | 648 if (icon_type == ICON_TYPE_TRAY) { |
| 634 connected_network = | 649 connected_network = |
| 635 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); | 650 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); |
| 636 } | 651 } |
| 637 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 652 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
| 638 | 653 |
| 639 if (connected_network) { | 654 if (connected_network) { |
| 640 gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type); | 655 gfx::ImageSkia icon = GetImageForNetwork(connected_network, icon_type); |
| 641 Badges badges; | 656 Badges badges; |
| 642 badges.bottom_left = ConnectingVpnBadge(animation); | 657 badges.bottom_left = ConnectingVpnBadge(animation); |
| 643 return gfx::ImageSkia( | 658 return UseMd() ? NetworkIconImageSourceMd::CreateImage(icon, badges) |
| 644 new NetworkIconImageSource(icon, badges), icon.size()); | 659 : gfx::ImageSkia(new NetworkIconImageSource(icon, badges), |
| 660 icon.size()); | |
| 645 } else { | 661 } else { |
| 646 gfx::ImageSkia* icon = ConnectingVpnImage(animation); | 662 gfx::ImageSkia* icon = ConnectingVpnImage(animation); |
| 647 return gfx::ImageSkia( | 663 return UseMd() ? NetworkIconImageSourceMd::CreateImage(*icon, Badges()) |
| 648 new NetworkIconImageSource(*icon, Badges()), icon->size()); | 664 : gfx::ImageSkia(new NetworkIconImageSource(*icon, Badges()), |
| 665 icon->size()); | |
| 649 } | 666 } |
| 650 } | 667 } |
| 651 | 668 |
| 652 gfx::ImageSkia GetConnectingImage(IconType icon_type, | 669 gfx::ImageSkia GetConnectingImage(IconType icon_type, |
| 653 const std::string& network_type) { | 670 const std::string& network_type) { |
| 654 if (network_type == shill::kTypeVPN) | 671 if (network_type == shill::kTypeVPN) |
| 655 return GetConnectingVpnImage(icon_type); | 672 return GetConnectingVpnImage(icon_type); |
| 656 | 673 |
| 657 ImageType image_type = ImageTypeForNetworkType(network_type); | 674 ImageType image_type = ImageTypeForNetworkType(network_type); |
| 658 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); | 675 double animation = NetworkIconAnimation::GetInstance()->GetAnimation(); |
| 659 | 676 |
| 660 gfx::ImageSkia* icon = ConnectingWirelessImage( | 677 gfx::ImageSkia* icon = ConnectingWirelessImage( |
| 661 image_type, icon_type, animation); | 678 image_type, icon_type, animation); |
| 662 return gfx::ImageSkia( | 679 return UseMd() ? NetworkIconImageSourceMd::CreateImage(*icon, Badges()) |
| 663 new NetworkIconImageSource(*icon, Badges()), icon->size()); | 680 : gfx::ImageSkia(new NetworkIconImageSource(*icon, Badges()), |
| 681 icon->size()); | |
| 664 } | 682 } |
| 665 | 683 |
| 666 } // namespace | 684 } // namespace |
| 667 | 685 |
| 668 //------------------------------------------------------------------------------ | 686 //------------------------------------------------------------------------------ |
| 669 // NetworkIconImpl | 687 // NetworkIconImpl |
| 670 | 688 |
| 671 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) | 689 NetworkIconImpl::NetworkIconImpl(const std::string& path, IconType icon_type) |
| 672 : network_path_(path), | 690 : network_path_(path), |
| 673 icon_type_(icon_type), | 691 icon_type_(icon_type), |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 748 if (behind_captive_portal == behind_captive_portal_) | 766 if (behind_captive_portal == behind_captive_portal_) |
| 749 return false; | 767 return false; |
| 750 behind_captive_portal_ = behind_captive_portal; | 768 behind_captive_portal_ = behind_captive_portal; |
| 751 return true; | 769 return true; |
| 752 } | 770 } |
| 753 | 771 |
| 754 bool NetworkIconImpl::UpdateVPNBadge() { | 772 bool NetworkIconImpl::UpdateVPNBadge() { |
| 755 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> | 773 const NetworkState* vpn = NetworkHandler::Get()->network_state_handler()-> |
| 756 ConnectedNetworkByType(NetworkTypePattern::VPN()); | 774 ConnectedNetworkByType(NetworkTypePattern::VPN()); |
| 757 if (vpn && vpn_badge_ == NULL) { | 775 if (vpn && vpn_badge_ == NULL) { |
| 758 vpn_badge_ = BadgeForVPN(icon_type_); | 776 vpn_badge_ = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 777 IDR_AURA_UBER_TRAY_NETWORK_VPN_BADGE); | |
| 759 return true; | 778 return true; |
| 760 } else if (!vpn && vpn_badge_ != NULL) { | 779 } else if (!vpn && vpn_badge_ != NULL) { |
| 761 vpn_badge_ = NULL; | 780 vpn_badge_ = NULL; |
| 762 return true; | 781 return true; |
| 763 } | 782 } |
| 764 return false; | 783 return false; |
| 765 } | 784 } |
| 766 | 785 |
| 767 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { | 786 void NetworkIconImpl::GetBadges(const NetworkState* network, Badges* badges) { |
| 768 DCHECK(network); | 787 DCHECK(network); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 808 IDR_AURA_UBER_TRAY_NETWORK_PORTAL_LIGHT); | 827 IDR_AURA_UBER_TRAY_NETWORK_PORTAL_LIGHT); |
| 809 badges->bottom_right = badge; | 828 badges->bottom_right = badge; |
| 810 } | 829 } |
| 811 } | 830 } |
| 812 | 831 |
| 813 void NetworkIconImpl::GenerateImage(const NetworkState* network) { | 832 void NetworkIconImpl::GenerateImage(const NetworkState* network) { |
| 814 DCHECK(network); | 833 DCHECK(network); |
| 815 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); | 834 gfx::ImageSkia icon = GetIcon(network, icon_type_, strength_index_); |
| 816 Badges badges; | 835 Badges badges; |
| 817 GetBadges(network, &badges); | 836 GetBadges(network, &badges); |
| 818 image_ = gfx::ImageSkia( | 837 image_ = UseMd() ? NetworkIconImageSourceMd::CreateImage(icon, badges) |
| 819 new NetworkIconImageSource(icon, badges), icon.size()); | 838 : gfx::ImageSkia(new NetworkIconImageSource(icon, badges), |
| 839 icon.size()); | |
| 820 } | 840 } |
| 821 | 841 |
| 822 namespace { | 842 namespace { |
| 823 | 843 |
| 824 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, | 844 NetworkIconImpl* FindAndUpdateImageImpl(const NetworkState* network, |
| 825 IconType icon_type) { | 845 IconType icon_type) { |
| 826 // Find or add the icon. | 846 // Find or add the icon. |
| 827 NetworkIconMap* icon_map = GetIconMap(icon_type); | 847 NetworkIconMap* icon_map = GetIconMap(icon_type); |
| 828 NetworkIconImpl* icon; | 848 NetworkIconImpl* icon; |
| 829 NetworkIconMap::iterator iter = icon_map->find(network->path()); | 849 NetworkIconMap::iterator iter = icon_map->find(network->path()); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 iter != networks.end(); ++iter) { | 1056 iter != networks.end(); ++iter) { |
| 1037 network_paths.insert((*iter)->path()); | 1057 network_paths.insert((*iter)->path()); |
| 1038 } | 1058 } |
| 1039 PurgeIconMap(ICON_TYPE_TRAY, network_paths); | 1059 PurgeIconMap(ICON_TYPE_TRAY, network_paths); |
| 1040 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); | 1060 PurgeIconMap(ICON_TYPE_DEFAULT_VIEW, network_paths); |
| 1041 PurgeIconMap(ICON_TYPE_LIST, network_paths); | 1061 PurgeIconMap(ICON_TYPE_LIST, network_paths); |
| 1042 } | 1062 } |
| 1043 | 1063 |
| 1044 } // namespace network_icon | 1064 } // namespace network_icon |
| 1045 } // namespace ui | 1065 } // namespace ui |
| OLD | NEW |