blob: a29df63b8a4655bfa638b78073221acf53ce7078 [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;
Ionel Popescu2649f2f2020-01-10 10:06:5930 float GetBorderRadiusForPart(Part part,
31 float width,
Yu Han87d8dc82021-02-11 08:15:4432 float height) const override;
enne34f6084c2017-02-02 22:39:0833 void Paint(cc::PaintCanvas* canvas,
dcheng08038792014-10-21 10:53:2634 Part part,
35 State state,
36 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5237 const ExtraParams& extra,
Joey Arhar8c9f1382021-03-12 21:40:2438 ColorScheme color_scheme,
39 const base::Optional<SkColor>& accent_color) const override;
[email protected]990e6222012-11-16 13:31:1840
bokane7a058a2017-03-02 22:42:5141 bool SupportsNinePatch(Part part) const override;
42 gfx::Size GetNinePatchCanvasSize(Part part) const override;
43 gfx::Rect GetNinePatchAperture(Part part) const override;
44
[email protected]990e6222012-11-16 13:31:1845 protected:
Joey Arhar3a2f2672019-11-14 16:51:1046 // Colors for form controls refresh.
47 enum ControlColorId {
48 kBorder,
49 kDisabledBorder,
50 kHoveredBorder,
Ionel Popescu5ce28592020-01-14 07:16:5251 kPressedBorder,
Joey Arhar3a2f2672019-11-14 16:51:1052 kAccent,
53 kDisabledAccent,
54 kHoveredAccent,
Ionel Popescu5ce28592020-01-14 07:16:5255 kPressedAccent,
Joey Arhar3a2f2672019-11-14 16:51:1056 kBackground,
57 kDisabledBackground,
58 kFill,
59 kDisabledFill,
60 kHoveredFill,
Ionel Popescu5ce28592020-01-14 07:16:5261 kPressedFill,
Joey Arhar3a2f2672019-11-14 16:51:1062 kLightenLayer,
63 kProgressValue,
64 kSlider,
65 kDisabledSlider,
Ionel Popescu5ce28592020-01-14 07:16:5266 kHoveredSlider,
Sam Sebree6bf32582020-01-15 16:23:5567 kPressedSlider,
Sam Sebree8dffabf2020-05-27 21:43:0368 kAutoCompleteBackground,
69 kScrollbarArrowBackground,
70 kScrollbarArrowBackgroundHovered,
71 kScrollbarArrowBackgroundPressed,
72 kScrollbarArrow,
73 kScrollbarArrowHovered,
74 kScrollbarArrowPressed,
75 kScrollbarTrack,
76 kScrollbarThumb,
77 kScrollbarThumbHovered,
78 kScrollbarThumbPressed,
Yu Han428cc3d2020-10-21 22:42:1379 kScrollbarThumbInactive,
80 kButtonBorder,
81 kButtonDisabledBorder,
82 kButtonHoveredBorder,
83 kButtonPressedBorder,
84 kButtonFill,
85 kButtonDisabledFill,
86 kButtonHoveredFill,
87 kButtonPressedFill
Joey Arhar3a2f2672019-11-14 16:51:1088 };
89
John Smith6176b1d2020-03-06 21:56:5390 using NativeTheme::NativeTheme;
[email protected]990e6222012-11-16 13:31:1891 NativeThemeBase();
John Smith6176b1d2020-03-06 21:56:5392 explicit NativeThemeBase(bool should_only_use_dark_colors);
dcheng08038792014-10-21 10:53:2693 ~NativeThemeBase() override;
[email protected]990e6222012-11-16 13:31:1894
95 // Draw the arrow. Used by scrollbar and inner spin button.
enne34f6084c2017-02-02 22:39:0896 virtual void PaintArrowButton(cc::PaintCanvas* gc,
97 const gfx::Rect& rect,
98 Part direction,
Rune Lillesveene9ef0d602019-07-31 00:02:5299 State state,
Bo Cupp2e9e0962019-08-12 21:19:26100 ColorScheme color_scheme,
101 const ScrollbarArrowExtraParams& arrow) const;
[email protected]990e6222012-11-16 13:31:18102 // Paint the scrollbar track. Done before the thumb so that it can contain
103 // alpha.
104 virtual void PaintScrollbarTrack(
enne34f6084c2017-02-02 22:39:08105 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18106 Part part,
107 State state,
108 const ScrollbarTrackExtraParams& extra_params,
Rune Lillesveene9ef0d602019-07-31 00:02:52109 const gfx::Rect& rect,
110 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18111 // Draw the scrollbar thumb over the track.
112 virtual void PaintScrollbarThumb(
enne34f6084c2017-02-02 22:39:08113 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18114 Part part,
115 State state,
chaopeng3386732f2016-10-28 14:49:49116 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52117 NativeTheme::ScrollbarOverlayColorTheme theme,
118 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18119
enne34f6084c2017-02-02 22:39:08120 virtual void PaintScrollbarCorner(cc::PaintCanvas* canvas,
[email protected]99df47e2014-01-29 07:01:53121 State state,
Rune Lillesveene9ef0d602019-07-31 00:02:52122 const gfx::Rect& rect,
123 ColorScheme color_scheme) const;
[email protected]99df47e2014-01-29 07:01:53124
Joey Arhar3a2f2672019-11-14 16:51:10125 void PaintCheckbox(cc::PaintCanvas* canvas,
126 State state,
127 const gfx::Rect& rect,
128 const ButtonExtraParams& button,
Joey Arhar8c9f1382021-03-12 21:40:24129 ColorScheme color_scheme,
130 const base::Optional<SkColor>& accent_color) const;
[email protected]990e6222012-11-16 13:31:18131
Joey Arhar3a2f2672019-11-14 16:51:10132 void PaintRadio(cc::PaintCanvas* canvas,
133 State state,
134 const gfx::Rect& rect,
135 const ButtonExtraParams& button,
Joey Arhar8c9f1382021-03-12 21:40:24136 ColorScheme color_scheme,
137 const base::Optional<SkColor>& accent_color) const;
[email protected]990e6222012-11-16 13:31:18138
Joey Arhar3a2f2672019-11-14 16:51:10139 void PaintButton(cc::PaintCanvas* canvas,
140 State state,
141 const gfx::Rect& rect,
142 const ButtonExtraParams& button,
143 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18144
Joey Arhar3a2f2672019-11-14 16:51:10145 void PaintTextField(cc::PaintCanvas* canvas,
146 State state,
147 const gfx::Rect& rect,
148 const TextFieldExtraParams& text,
149 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18150
Joey Arhar3a2f2672019-11-14 16:51:10151 void PaintMenuList(cc::PaintCanvas* canvas,
152 State state,
153 const gfx::Rect& rect,
154 const MenuListExtraParams& menu_list,
155 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18156
[email protected]e95cacb2013-01-29 02:31:12157 virtual void PaintMenuPopupBackground(
enne34f6084c2017-02-02 22:39:08158 cc::PaintCanvas* canvas,
[email protected]e95cacb2013-01-29 02:31:12159 const gfx::Size& size,
Rune Lillesveene9ef0d602019-07-31 00:02:52160 const MenuBackgroundExtraParams& menu_background,
161 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18162
Rune Lillesveene9ef0d602019-07-31 00:02:52163 virtual void PaintMenuItemBackground(cc::PaintCanvas* canvas,
164 State state,
165 const gfx::Rect& rect,
166 const MenuItemExtraParams& menu_item,
167 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18168
thomasandersone3bc84e32017-01-28 06:41:57169 virtual void PaintMenuSeparator(
enne34f6084c2017-02-02 22:39:08170 cc::PaintCanvas* canvas,
thomasandersone3bc84e32017-01-28 06:41:57171 State state,
172 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52173 const MenuSeparatorExtraParams& menu_separator,
174 ColorScheme color_scheme) const;
thomasandersone3bc84e32017-01-28 06:41:57175
Joey Arhar3a2f2672019-11-14 16:51:10176 void PaintSliderTrack(cc::PaintCanvas* canvas,
177 State state,
178 const gfx::Rect& rect,
179 const SliderExtraParams& slider,
Joey Arhar8c9f1382021-03-12 21:40:24180 ColorScheme color_scheme,
181 const base::Optional<SkColor>& accent_color) const;
[email protected]990e6222012-11-16 13:31:18182
Joey Arhar3a2f2672019-11-14 16:51:10183 void PaintSliderThumb(cc::PaintCanvas* canvas,
184 State state,
185 const gfx::Rect& rect,
186 const SliderExtraParams& slider,
Joey Arhar8c9f1382021-03-12 21:40:24187 ColorScheme color_scheme,
188 const base::Optional<SkColor>& accent_color) const;
[email protected]990e6222012-11-16 13:31:18189
190 virtual void PaintInnerSpinButton(
enne34f6084c2017-02-02 22:39:08191 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18192 State state,
193 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52194 const InnerSpinButtonExtraParams& spin_button,
195 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18196
Joey Arhar3a2f2672019-11-14 16:51:10197 void PaintProgressBar(cc::PaintCanvas* canvas,
198 State state,
199 const gfx::Rect& rect,
200 const ProgressBarExtraParams& progress_bar,
Joey Arhar8c9f1382021-03-12 21:40:24201 ColorScheme color_scheme,
202 const base::Optional<SkColor>& accent_color) const;
[email protected]990e6222012-11-16 13:31:18203
Rune Lillesveene9ef0d602019-07-31 00:02:52204 virtual void PaintFrameTopArea(cc::PaintCanvas* canvas,
205 State state,
206 const gfx::Rect& rect,
207 const FrameTopAreaExtraParams& frame_top_area,
208 ColorScheme color_scheme) const;
thomasanderson2bbf4302017-01-24 21:24:42209
Joey Arhar3a2f2672019-11-14 16:51:10210 virtual void PaintLightenLayer(cc::PaintCanvas* canvas,
211 SkRect skrect,
212 State state,
213 SkScalar border_radius,
214 ColorScheme color_scheme) const;
215
mohsen94189532015-09-14 04:33:46216 // Shrinks checkbox/radio button rect, if necessary, to make room for padding
217 // and drop shadow.
218 // TODO(mohsen): This is needed because checkboxes/radio buttons on Android
219 // have different padding from those on desktop Chrome. Get rid of this when
220 // crbug.com/530746 is resolved.
221 virtual void AdjustCheckboxRadioRectForPadding(SkRect* rect) const;
222
Yu Hanc107b262021-03-01 08:13:54223 virtual float AdjustBorderWidthByZoom(float border_width,
224 float zoom_level) const;
225
bokan3d914bd2016-10-19 15:07:58226 void set_scrollbar_button_length(int length) {
[email protected]990e6222012-11-16 13:31:18227 scrollbar_button_length_ = length;
228 }
[email protected]8eaacd42014-02-10 15:58:48229 int scrollbar_button_length() const { return scrollbar_button_length_; }
[email protected]990e6222012-11-16 13:31:18230
[email protected]990e6222012-11-16 13:31:18231 SkColor SaturateAndBrighten(SkScalar* hsv,
232 SkScalar saturate_amount,
233 SkScalar brighten_amount) const;
[email protected]e2169902014-01-22 20:23:41234
235 // Paints the arrow used on the scrollbar and spinner.
enne34f6084c2017-02-02 22:39:08236 void PaintArrow(cc::PaintCanvas* canvas,
[email protected]e2169902014-01-22 20:23:41237 const gfx::Rect& rect,
238 Part direction,
239 SkColor color) const;
240
241 // Returns the color used to draw the arrow.
Rune Lillesveene9ef0d602019-07-31 00:02:52242 SkColor GetArrowColor(State state, ColorScheme color_scheme) const;
Sam Sebree8dffabf2020-05-27 21:43:03243 SkColor GetControlColor(ControlColorId color_id,
244 ColorScheme color_scheme) const;
Ionel Popescued15df012021-01-12 19:59:44245 virtual SkColor ControlsAccentColorForState(State state,
246 ColorScheme color_scheme) const;
247 virtual SkColor ControlsSliderColorForState(State state,
248 ColorScheme color_scheme) const;
249 virtual SkColor ButtonBorderColorForState(State state,
250 ColorScheme color_scheme) const;
251 virtual SkColor ButtonFillColorForState(State state,
252 ColorScheme color_scheme) const;
253 virtual SkColor ControlsBorderColorForState(State state,
254 ColorScheme color_scheme) const;
255 virtual SkColor ControlsFillColorForState(State state,
256 ColorScheme color_scheme) const;
[email protected]e2169902014-01-22 20:23:41257
John Smith6176b1d2020-03-06 21:56:53258 int scrollbar_width_ = 15;
bokan3d914bd2016-10-19 15:07:58259
[email protected]990e6222012-11-16 13:31:18260 private:
bsep91cbc6d2016-06-14 00:51:51261 friend class NativeThemeAuraTest;
bsep6e7c3082016-05-19 23:04:26262
263 SkPath PathForArrow(const gfx::Rect& rect, Part direction) const;
bsep91cbc6d2016-06-14 00:51:51264 gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const;
bsep6e7c3082016-05-19 23:04:26265
enne34f6084c2017-02-02 22:39:08266 void DrawVertLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18267 int x,
268 int y1,
269 int y2,
enne9873ffb2017-02-07 23:20:17270 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08271 void DrawHorizLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18272 int x1,
273 int x2,
274 int y,
enne9873ffb2017-02-07 23:20:17275 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08276 void DrawBox(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18277 const gfx::Rect& rect,
enne9873ffb2017-02-07 23:20:17278 const cc::PaintFlags& flags) const;
[email protected]990e6222012-11-16 13:31:18279 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;
280
[email protected]a244f2582013-03-08 07:31:23281 // Paint the common parts of the checkboxes and radio buttons.
Rune Lillesveenc04c99842019-10-01 20:26:35282 // border_radius specifies how rounded the corners should be.
Joey Arhar8c9f1382021-03-12 21:40:24283 SkRect PaintCheckboxRadioCommon(
284 cc::PaintCanvas* canvas,
285 State state,
286 const gfx::Rect& rect,
287 const ButtonExtraParams& button,
288 bool is_checkbox,
289 const SkScalar border_radius,
290 ColorScheme color_scheme,
291 const base::Optional<SkColor>& accent_color) const;
[email protected]990e6222012-11-16 13:31:18292
Joey Arhar3a2f2672019-11-14 16:51:10293 SkColor ControlsBackgroundColorForState(State state,
294 ColorScheme color_scheme) const;
Joey Arhar3a2f2672019-11-14 16:51:10295 SkColor GetHighContrastControlColor(ControlColorId color_id,
296 ColorScheme color_scheme) const;
Sam Sebreec518e412020-02-28 15:08:22297 SkColor GetDarkModeControlColor(ControlColorId color_id) const;
Sam Sebree8dffabf2020-05-27 21:43:03298
Joey Arhar3a2f2672019-11-14 16:51:10299 SkRect AlignSliderTrack(const gfx::Rect& slider_rect,
300 const NativeTheme::SliderExtraParams& slider,
301 bool is_value,
302 float track_height) const;
303
[email protected]ae9a3412014-08-14 08:01:29304 // The length of the arrow buttons, 0 means no buttons are drawn.
John Smith6176b1d2020-03-06 21:56:53305 int scrollbar_button_length_ = 14;
[email protected]990e6222012-11-16 13:31:18306
307 DISALLOW_COPY_AND_ASSIGN(NativeThemeBase);
308};
309
310} // namespace ui
311
312#endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_