blob: a0530ef38d2c0ead1033a8a3601ca796ef380e03 [file] [log] [blame]
[email protected]990e6222012-11-16 13:31:181// 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
3// found in the LICENSE file.
4
5#ifndef UI_NATIVE_THEME_NATIVE_THEME_BASE_H_
6#define UI_NATIVE_THEME_NATIVE_THEME_BASE_H_
7
danakj25c52c32016-04-12 21:51:088#include <memory>
9
[email protected]990e6222012-11-16 13:31:1810#include "base/compiler_specific.h"
bsep6e7c3082016-05-19 23:04:2611#include "base/gtest_prod_util.h"
avi9c81217b2015-12-24 23:40:0512#include "base/macros.h"
enne34f6084c2017-02-02 22:39:0813#include "cc/paint/paint_flags.h"
[email protected]990e6222012-11-16 13:31:1814#include "ui/native_theme/native_theme.h"
15
16namespace gfx {
[email protected]990e6222012-11-16 13:31:1817class Rect;
18class Size;
19}
20
21namespace ui {
22
23// Theme support for non-Windows toolkits.
24class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
25 public:
26 // NativeTheme implementation:
dcheng08038792014-10-21 10:53:2627 gfx::Size GetPartSize(Part part,
28 State state,
29 const ExtraParams& extra) const override;
enne34f6084c2017-02-02 22:39:0830 void Paint(cc::PaintCanvas* canvas,
dcheng08038792014-10-21 10:53:2631 Part part,
32 State state,
33 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5234 const ExtraParams& extra,
35 ColorScheme color_scheme) const override;
[email protected]990e6222012-11-16 13:31:1836
bokane7a058a2017-03-02 22:42:5137 bool SupportsNinePatch(Part part) const override;
38 gfx::Size GetNinePatchCanvasSize(Part part) const override;
39 gfx::Rect GetNinePatchAperture(Part part) const override;
40
[email protected]990e6222012-11-16 13:31:1841 protected:
Joey Arhar3a2f2672019-11-14 16:51:1042 // Colors for form controls refresh.
43 enum ControlColorId {
44 kBorder,
45 kDisabledBorder,
46 kHoveredBorder,
47 kAccent,
48 kDisabledAccent,
49 kHoveredAccent,
50 kBackground,
51 kDisabledBackground,
52 kFill,
53 kDisabledFill,
54 kHoveredFill,
55 kLightenLayer,
56 kProgressValue,
57 kSlider,
58 kDisabledSlider,
59 kHoveredSlider
60 };
61
[email protected]990e6222012-11-16 13:31:1862 NativeThemeBase();
dcheng08038792014-10-21 10:53:2663 ~NativeThemeBase() override;
[email protected]990e6222012-11-16 13:31:1864
65 // Draw the arrow. Used by scrollbar and inner spin button.
enne34f6084c2017-02-02 22:39:0866 virtual void PaintArrowButton(cc::PaintCanvas* gc,
67 const gfx::Rect& rect,
68 Part direction,
Rune Lillesveene9ef0d602019-07-31 00:02:5269 State state,
Bo Cupp2e9e0962019-08-12 21:19:2670 ColorScheme color_scheme,
71 const ScrollbarArrowExtraParams& arrow) const;
[email protected]990e6222012-11-16 13:31:1872 // Paint the scrollbar track. Done before the thumb so that it can contain
73 // alpha.
74 virtual void PaintScrollbarTrack(
enne34f6084c2017-02-02 22:39:0875 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:1876 Part part,
77 State state,
78 const ScrollbarTrackExtraParams& extra_params,
Rune Lillesveene9ef0d602019-07-31 00:02:5279 const gfx::Rect& rect,
80 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1881 // Draw the scrollbar thumb over the track.
82 virtual void PaintScrollbarThumb(
enne34f6084c2017-02-02 22:39:0883 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:1884 Part part,
85 State state,
chaopeng3386732f2016-10-28 14:49:4986 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5287 NativeTheme::ScrollbarOverlayColorTheme theme,
88 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1889
enne34f6084c2017-02-02 22:39:0890 virtual void PaintScrollbarCorner(cc::PaintCanvas* canvas,
[email protected]99df47e2014-01-29 07:01:5391 State state,
Rune Lillesveene9ef0d602019-07-31 00:02:5292 const gfx::Rect& rect,
93 ColorScheme color_scheme) const;
[email protected]99df47e2014-01-29 07:01:5394
Joey Arhar3a2f2672019-11-14 16:51:1095 void PaintCheckbox(cc::PaintCanvas* canvas,
96 State state,
97 const gfx::Rect& rect,
98 const ButtonExtraParams& button,
99 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18100
Joey Arhar3a2f2672019-11-14 16:51:10101 void PaintRadio(cc::PaintCanvas* canvas,
102 State state,
103 const gfx::Rect& rect,
104 const ButtonExtraParams& button,
105 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18106
Joey Arhar3a2f2672019-11-14 16:51:10107 void PaintButton(cc::PaintCanvas* canvas,
108 State state,
109 const gfx::Rect& rect,
110 const ButtonExtraParams& button,
111 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18112
Joey Arhar3a2f2672019-11-14 16:51:10113 void PaintTextField(cc::PaintCanvas* canvas,
114 State state,
115 const gfx::Rect& rect,
116 const TextFieldExtraParams& text,
117 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18118
Joey Arhar3a2f2672019-11-14 16:51:10119 void PaintMenuList(cc::PaintCanvas* canvas,
120 State state,
121 const gfx::Rect& rect,
122 const MenuListExtraParams& menu_list,
123 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18124
[email protected]e95cacb2013-01-29 02:31:12125 virtual void PaintMenuPopupBackground(
enne34f6084c2017-02-02 22:39:08126 cc::PaintCanvas* canvas,
[email protected]e95cacb2013-01-29 02:31:12127 const gfx::Size& size,
Rune Lillesveene9ef0d602019-07-31 00:02:52128 const MenuBackgroundExtraParams& menu_background,
129 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18130
Rune Lillesveene9ef0d602019-07-31 00:02:52131 virtual void PaintMenuItemBackground(cc::PaintCanvas* canvas,
132 State state,
133 const gfx::Rect& rect,
134 const MenuItemExtraParams& menu_item,
135 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18136
thomasandersone3bc84e32017-01-28 06:41:57137 virtual void PaintMenuSeparator(
enne34f6084c2017-02-02 22:39:08138 cc::PaintCanvas* canvas,
thomasandersone3bc84e32017-01-28 06:41:57139 State state,
140 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52141 const MenuSeparatorExtraParams& menu_separator,
142 ColorScheme color_scheme) const;
thomasandersone3bc84e32017-01-28 06:41:57143
Joey Arhar3a2f2672019-11-14 16:51:10144 void PaintSliderTrack(cc::PaintCanvas* canvas,
145 State state,
146 const gfx::Rect& rect,
147 const SliderExtraParams& slider,
148 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18149
Joey Arhar3a2f2672019-11-14 16:51:10150 void PaintSliderThumb(cc::PaintCanvas* canvas,
151 State state,
152 const gfx::Rect& rect,
153 const SliderExtraParams& slider,
154 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18155
156 virtual void PaintInnerSpinButton(
enne34f6084c2017-02-02 22:39:08157 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18158 State state,
159 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52160 const InnerSpinButtonExtraParams& spin_button,
161 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18162
Joey Arhar3a2f2672019-11-14 16:51:10163 void PaintProgressBar(cc::PaintCanvas* canvas,
164 State state,
165 const gfx::Rect& rect,
166 const ProgressBarExtraParams& progress_bar,
167 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18168
Rune Lillesveene9ef0d602019-07-31 00:02:52169 virtual void PaintFrameTopArea(cc::PaintCanvas* canvas,
170 State state,
171 const gfx::Rect& rect,
172 const FrameTopAreaExtraParams& frame_top_area,
173 ColorScheme color_scheme) const;
thomasanderson2bbf4302017-01-24 21:24:42174
Joey Arhar3a2f2672019-11-14 16:51:10175 virtual void PaintLightenLayer(cc::PaintCanvas* canvas,
176 SkRect skrect,
177 State state,
178 SkScalar border_radius,
179 ColorScheme color_scheme) const;
180
mohsen94189532015-09-14 04:33:46181 // Shrinks checkbox/radio button rect, if necessary, to make room for padding
182 // and drop shadow.
183 // TODO(mohsen): This is needed because checkboxes/radio buttons on Android
184 // have different padding from those on desktop Chrome. Get rid of this when
185 // crbug.com/530746 is resolved.
186 virtual void AdjustCheckboxRadioRectForPadding(SkRect* rect) const;
187
bokan3d914bd2016-10-19 15:07:58188 void set_scrollbar_button_length(int length) {
[email protected]990e6222012-11-16 13:31:18189 scrollbar_button_length_ = length;
190 }
[email protected]8eaacd42014-02-10 15:58:48191 int scrollbar_button_length() const { return scrollbar_button_length_; }
[email protected]990e6222012-11-16 13:31:18192
[email protected]990e6222012-11-16 13:31:18193 SkColor SaturateAndBrighten(SkScalar* hsv,
194 SkScalar saturate_amount,
195 SkScalar brighten_amount) const;
[email protected]e2169902014-01-22 20:23:41196
197 // Paints the arrow used on the scrollbar and spinner.
enne34f6084c2017-02-02 22:39:08198 void PaintArrow(cc::PaintCanvas* canvas,
[email protected]e2169902014-01-22 20:23:41199 const gfx::Rect& rect,
200 Part direction,
201 SkColor color) const;
202
203 // Returns the color used to draw the arrow.
Rune Lillesveene9ef0d602019-07-31 00:02:52204 SkColor GetArrowColor(State state, ColorScheme color_scheme) const;
[email protected]e2169902014-01-22 20:23:41205
bokan3d914bd2016-10-19 15:07:58206 int scrollbar_width_;
207
[email protected]990e6222012-11-16 13:31:18208 private:
bsep91cbc6d2016-06-14 00:51:51209 friend class NativeThemeAuraTest;
bsep6e7c3082016-05-19 23:04:26210
211 SkPath PathForArrow(const gfx::Rect& rect, Part direction) const;
bsep91cbc6d2016-06-14 00:51:51212 gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const;
bsep6e7c3082016-05-19 23:04:26213
enne34f6084c2017-02-02 22:39:08214 void DrawVertLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18215 int x,
216 int y1,
217 int y2,
enne9873ffb2017-02-07 23:20:17218 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08219 void DrawHorizLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18220 int x1,
221 int x2,
222 int y,
enne9873ffb2017-02-07 23:20:17223 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08224 void DrawBox(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18225 const gfx::Rect& rect,
enne9873ffb2017-02-07 23:20:17226 const cc::PaintFlags& flags) const;
[email protected]990e6222012-11-16 13:31:18227 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;
228
[email protected]a244f2582013-03-08 07:31:23229 // Paint the common parts of the checkboxes and radio buttons.
Rune Lillesveenc04c99842019-10-01 20:26:35230 // border_radius specifies how rounded the corners should be.
enne34f6084c2017-02-02 22:39:08231 SkRect PaintCheckboxRadioCommon(cc::PaintCanvas* canvas,
232 State state,
233 const gfx::Rect& rect,
Alex Kengadc4f6102019-09-18 03:07:03234 const ButtonExtraParams& button,
235 bool is_checkbox,
Rune Lillesveenc04c99842019-10-01 20:26:35236 const SkScalar border_radius,
Rune Lillesveene9ef0d602019-07-31 00:02:52237 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18238
Joey Arhar3a2f2672019-11-14 16:51:10239 SkColor ControlsAccentColorForState(State state,
240 ColorScheme color_scheme) const;
241 SkColor ControlsBorderColorForState(State state,
242 ColorScheme color_scheme) const;
243 SkColor ControlsFillColorForState(State state,
244 ColorScheme color_scheme) const;
245 SkColor ControlsBackgroundColorForState(State state,
246 ColorScheme color_scheme) const;
247 SkColor ControlsSliderColorForState(State state,
248 ColorScheme color_scheme) const;
249 SkColor GetHighContrastControlColor(ControlColorId color_id,
250 ColorScheme color_scheme) const;
251 SkColor GetControlColor(ControlColorId color_id,
252 ColorScheme color_scheme) const;
253 SkRect AlignSliderTrack(const gfx::Rect& slider_rect,
254 const NativeTheme::SliderExtraParams& slider,
255 bool is_value,
256 float track_height) const;
257
[email protected]ae9a3412014-08-14 08:01:29258 // The length of the arrow buttons, 0 means no buttons are drawn.
bokan3d914bd2016-10-19 15:07:58259 int scrollbar_button_length_;
[email protected]990e6222012-11-16 13:31:18260
261 DISALLOW_COPY_AND_ASSIGN(NativeThemeBase);
262};
263
264} // namespace ui
265
266#endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_