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
119
120
121
122
123
124
125
126
127
128
129
130
ash / style / style_util.h [blame]
// Copyright 2021 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_STYLE_STYLE_UTIL_H_
#define ASH_STYLE_STYLE_UTIL_H_
#include <optional>
#include "ash/ash_export.h"
#include "ui/color/color_id.h"
#include "ui/compositor_extra/shadow.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/insets.h"
namespace ui {
class ColorProvider;
} // namespace ui
namespace views {
class Background;
class Button;
class FocusRing;
class InkDrop;
class InkDropHighlight;
class InkDropRipple;
class View;
namespace corewm {
class TooltipViewAura;
} // namespace corewm
} // namespace views
namespace ash {
class ASH_EXPORT StyleUtil {
public:
// InkDrop attributes that can be configured through
// ConfigureInkDropAttributes. Including the base color, inkdrop and highlight
// opacity.
enum InkDropAttributes {
kBaseColor = 1,
kInkDropOpacity = 1 << 1,
kHighlightOpacity = 1 << 2
};
static constexpr float kLightInkDropOpacity = 0.08f;
static constexpr float kDarkInkDropOpacity = 0.06f;
static float GetInkDropOpacity();
// Creates an InkDrop instance for `host`. All styles are configured to show
// the highlight when the ripple is visible.
static std::unique_ptr<views::InkDrop> CreateInkDrop(
views::Button* host,
bool highlight_on_hover = false,
bool highlight_on_focus = false);
// Crates an InkDropRipple instance for `host` with `insets`.
static std::unique_ptr<views::InkDropRipple> CreateInkDropRipple(
const gfx::Insets& insets,
const views::View* host,
SkColor background_color = gfx::kPlaceholderColor);
// Creates an InkDropHighlight instance for `host`.
static std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight(
const views::View* host,
SkColor background_color);
// Sets attributes(e.g, insets) for creating the inkdrop ripple. Note, A
// FloodFillInkDropRipple will be created for the given `host`.
static void SetRippleParams(
views::View* host,
const gfx::Insets& insets,
SkColor background_color = gfx::kPlaceholderColor);
// Sets up the inkdrop for the given `button`. Including setting the callback
// for InkDrop, Ripple, Highlight. Inside the callback functions, they will
// setup whether to show the highlight on hover or focus, inkdrop color,
// opacity etc.
static void SetUpInkDropForButton(
views::Button* button,
const gfx::Insets& ripple_insets = gfx::Insets(),
bool highlight_on_hover = false,
bool highlight_on_focus = false,
SkColor background_color = gfx::kPlaceholderColor);
// Configures the InkDropAttributes for the given `view` based on
// `attributes`. Note, `attributes` is a bitmask from InkDropAttributes.
static void ConfigureInkDropAttributes(
views::View* view,
uint32_t attributes,
SkColor background_color = gfx::kPlaceholderColor);
// Sets up the focus ring and its color for `view`. `halo_inset` is the
// adjustment from the visible border of the host view to render the focus
// ring. If it is not given, then the default (-0.5 * thickness) will be used.
static views::FocusRing* SetUpFocusRingForView(
views::View* view,
std::optional<int> halo_inset = std::nullopt);
static void InstallRoundedCornerHighlightPathGenerator(
views::View* view,
const gfx::RoundedCornersF& corners);
// Creates a background that fills the canvas with a fully rounded rect whose
// rounded corner radius is set to the half of the minimum dimension of view's
// local bounds. The background is painted in the color specified by the
// view's ColorProvider and the given color identifier.
static std::unique_ptr<views::Background>
CreateThemedFullyRoundedRectBackground(ui::ColorId color_id);
static std::unique_ptr<views::corewm::TooltipViewAura>
CreateAshStyleTooltipView();
// Creates a shadow colors map with given color provider.
static ui::Shadow::ElevationToColorsMap CreateShadowElevationToColorsMap(
const ui::ColorProvider* color_provider);
private:
StyleUtil() = default;
StyleUtil(const StyleUtil&) = delete;
StyleUtil& operator=(const StyleUtil&) = delete;
~StyleUtil() = default;
};
} // namespace ash
#endif // ASH_STYLE_STYLE_UTIL_H_