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