123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- // Copyright 2018 The Chromium Authors. All rights reserved.
- // 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 "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); }
- const gfx::VectorIcon* icon = nullptr;
- SkColor color = gfx::kPlaceholderColor;
- };
- // Struct to pass a collection of badges to NetworkIconImageSource.
- struct 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_
|