1 // Copyright 2018 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef ASH_PUBLIC_CPP_NETWORK_ICON_IMAGE_SOURCE_H_ 6 #define ASH_PUBLIC_CPP_NETWORK_ICON_IMAGE_SOURCE_H_ 7 8 #include "ash/public/cpp/ash_public_export.h" 9 #include "third_party/skia/include/core/SkColor.h" 10 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/geometry/size.h" 12 #include "ui/gfx/image/canvas_image_source.h" 13 #include "ui/gfx/image/image_skia.h" 14 15 namespace gfx { 16 struct VectorIcon; 17 } 18 19 namespace ash { 20 namespace network_icon { 21 22 // Number of images for signal strength arcs or bars for wireless networks. 23 constexpr int kNumNetworkImages = 5; 24 25 // 'NONE' will default to ARCS behavior where appropriate (e.g. no network). 26 enum ImageType { ARCS, BARS, NONE }; 27 28 // Describes a single badge which is defined by a vector icon. 29 struct Badge { 30 bool operator==(const Badge& other) const { 31 return other.icon == icon && other.color == color; 32 } 33 bool operator!=(const Badge& other) const { return !(other == *this); } 34 35 const gfx::VectorIcon* icon = nullptr; 36 SkColor color; 37 }; 38 39 // Struct to pass a collection of badges to NetworkIconImageSource. 40 struct Badges { 41 Badge top_left = {}; 42 Badge center = {}; 43 Badge bottom_left = {}; 44 Badge bottom_right = {}; 45 }; 46 47 // Provides an image source for assembling a network icons. 48 class ASH_PUBLIC_EXPORT NetworkIconImageSource : public gfx::CanvasImageSource { 49 public: 50 NetworkIconImageSource(const gfx::Size& size, 51 const gfx::ImageSkia& icon, 52 const Badges& badges); 53 ~NetworkIconImageSource() override; 54 55 // gfx::CanvasImageSource: 56 void Draw(gfx::Canvas* canvas) override; 57 bool HasRepresentationAtAllScales() const override; 58 59 private: 60 const gfx::ImageSkia icon_; 61 const Badges badges_; 62 63 DISALLOW_COPY_AND_ASSIGN(NetworkIconImageSource); 64 }; 65 66 // Provides an image source for wireless signal strength icons. 67 class ASH_PUBLIC_EXPORT SignalStrengthImageSource 68 : public gfx::CanvasImageSource { 69 public: 70 SignalStrengthImageSource(ImageType image_type, 71 SkColor color, 72 const gfx::Size& size, 73 int signal_strength, 74 int padding = 2); 75 76 ~SignalStrengthImageSource() override; 77 78 // gfx::CanvasImageSource: 79 void Draw(gfx::Canvas* canvas) override; 80 bool HasRepresentationAtAllScales() const override; 81 82 private: 83 void DrawArcs(gfx::Canvas* canvas); 84 void DrawBars(gfx::Canvas* canvas); 85 86 ImageType image_type_; 87 SkColor color_; 88 89 // On a scale of 0 to kNumNetworkImages - 1, how connected we are. 90 int signal_strength_; 91 92 // Padding between outside of icon and edge of the canvas, in dp. This value 93 // stays the same regardless of the canvas size. 94 const int padding_; 95 96 DISALLOW_COPY_AND_ASSIGN(SignalStrengthImageSource); 97 }; 98 99 // Returns the sized full strength unbadged image for a Wi-Fi network. Used 100 // for wireless network notifications. 101 ASH_PUBLIC_EXPORT gfx::ImageSkia GetImageForWifiNetwork(SkColor color, 102 gfx::Size size); 103 104 } // namespace network_icon 105 } // namespace ash 106 107 #endif // ASH_PUBLIC_CPP_NETWORK_ICON_IMAGE_SOURCE_H_ 108