blob: c69159fe0d051cd01a65c8b66bc0da534a0dd465 [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,
32 float height,
33 float zoom) const override;
enne34f6084c2017-02-02 22:39:0834 void Paint(cc::PaintCanvas* canvas,
dcheng08038792014-10-21 10:53:2635 Part part,
36 State state,
37 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5238 const ExtraParams& extra,
39 ColorScheme color_scheme) 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,
67 kPressedSlider
Joey Arhar3a2f2672019-11-14 16:51:1068 };
69
[email protected]990e6222012-11-16 13:31:1870 NativeThemeBase();
dcheng08038792014-10-21 10:53:2671 ~NativeThemeBase() override;
[email protected]990e6222012-11-16 13:31:1872
73 // Draw the arrow. Used by scrollbar and inner spin button.
enne34f6084c2017-02-02 22:39:0874 virtual void PaintArrowButton(cc::PaintCanvas* gc,
75 const gfx::Rect& rect,
76 Part direction,
Rune Lillesveene9ef0d602019-07-31 00:02:5277 State state,
Bo Cupp2e9e0962019-08-12 21:19:2678 ColorScheme color_scheme,
79 const ScrollbarArrowExtraParams& arrow) const;
[email protected]990e6222012-11-16 13:31:1880 // Paint the scrollbar track. Done before the thumb so that it can contain
81 // alpha.
82 virtual void PaintScrollbarTrack(
enne34f6084c2017-02-02 22:39:0883 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:1884 Part part,
85 State state,
86 const ScrollbarTrackExtraParams& extra_params,
Rune Lillesveene9ef0d602019-07-31 00:02:5287 const gfx::Rect& rect,
88 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1889 // Draw the scrollbar thumb over the track.
90 virtual void PaintScrollbarThumb(
enne34f6084c2017-02-02 22:39:0891 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:1892 Part part,
93 State state,
chaopeng3386732f2016-10-28 14:49:4994 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5295 NativeTheme::ScrollbarOverlayColorTheme theme,
96 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1897
enne34f6084c2017-02-02 22:39:0898 virtual void PaintScrollbarCorner(cc::PaintCanvas* canvas,
[email protected]99df47e2014-01-29 07:01:5399 State state,
Rune Lillesveene9ef0d602019-07-31 00:02:52100 const gfx::Rect& rect,
101 ColorScheme color_scheme) const;
[email protected]99df47e2014-01-29 07:01:53102
Joey Arhar3a2f2672019-11-14 16:51:10103 void PaintCheckbox(cc::PaintCanvas* canvas,
104 State state,
105 const gfx::Rect& rect,
106 const ButtonExtraParams& button,
107 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18108
Joey Arhar3a2f2672019-11-14 16:51:10109 void PaintRadio(cc::PaintCanvas* canvas,
110 State state,
111 const gfx::Rect& rect,
112 const ButtonExtraParams& button,
113 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18114
Joey Arhar3a2f2672019-11-14 16:51:10115 void PaintButton(cc::PaintCanvas* canvas,
116 State state,
117 const gfx::Rect& rect,
118 const ButtonExtraParams& button,
119 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18120
Joey Arhar3a2f2672019-11-14 16:51:10121 void PaintTextField(cc::PaintCanvas* canvas,
122 State state,
123 const gfx::Rect& rect,
124 const TextFieldExtraParams& text,
125 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18126
Joey Arhar3a2f2672019-11-14 16:51:10127 void PaintMenuList(cc::PaintCanvas* canvas,
128 State state,
129 const gfx::Rect& rect,
130 const MenuListExtraParams& menu_list,
131 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18132
[email protected]e95cacb2013-01-29 02:31:12133 virtual void PaintMenuPopupBackground(
enne34f6084c2017-02-02 22:39:08134 cc::PaintCanvas* canvas,
[email protected]e95cacb2013-01-29 02:31:12135 const gfx::Size& size,
Rune Lillesveene9ef0d602019-07-31 00:02:52136 const MenuBackgroundExtraParams& menu_background,
137 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18138
Rune Lillesveene9ef0d602019-07-31 00:02:52139 virtual void PaintMenuItemBackground(cc::PaintCanvas* canvas,
140 State state,
141 const gfx::Rect& rect,
142 const MenuItemExtraParams& menu_item,
143 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18144
thomasandersone3bc84e32017-01-28 06:41:57145 virtual void PaintMenuSeparator(
enne34f6084c2017-02-02 22:39:08146 cc::PaintCanvas* canvas,
thomasandersone3bc84e32017-01-28 06:41:57147 State state,
148 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52149 const MenuSeparatorExtraParams& menu_separator,
150 ColorScheme color_scheme) const;
thomasandersone3bc84e32017-01-28 06:41:57151
Joey Arhar3a2f2672019-11-14 16:51:10152 void PaintSliderTrack(cc::PaintCanvas* canvas,
153 State state,
154 const gfx::Rect& rect,
155 const SliderExtraParams& slider,
156 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18157
Joey Arhar3a2f2672019-11-14 16:51:10158 void PaintSliderThumb(cc::PaintCanvas* canvas,
159 State state,
160 const gfx::Rect& rect,
161 const SliderExtraParams& slider,
162 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18163
164 virtual void PaintInnerSpinButton(
enne34f6084c2017-02-02 22:39:08165 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18166 State state,
167 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52168 const InnerSpinButtonExtraParams& spin_button,
169 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18170
Joey Arhar3a2f2672019-11-14 16:51:10171 void PaintProgressBar(cc::PaintCanvas* canvas,
172 State state,
173 const gfx::Rect& rect,
174 const ProgressBarExtraParams& progress_bar,
175 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18176
Rune Lillesveene9ef0d602019-07-31 00:02:52177 virtual void PaintFrameTopArea(cc::PaintCanvas* canvas,
178 State state,
179 const gfx::Rect& rect,
180 const FrameTopAreaExtraParams& frame_top_area,
181 ColorScheme color_scheme) const;
thomasanderson2bbf4302017-01-24 21:24:42182
Joey Arhar3a2f2672019-11-14 16:51:10183 virtual void PaintLightenLayer(cc::PaintCanvas* canvas,
184 SkRect skrect,
185 State state,
186 SkScalar border_radius,
187 ColorScheme color_scheme) const;
188
mohsen94189532015-09-14 04:33:46189 // Shrinks checkbox/radio button rect, if necessary, to make room for padding
190 // and drop shadow.
191 // TODO(mohsen): This is needed because checkboxes/radio buttons on Android
192 // have different padding from those on desktop Chrome. Get rid of this when
193 // crbug.com/530746 is resolved.
194 virtual void AdjustCheckboxRadioRectForPadding(SkRect* rect) const;
195
bokan3d914bd2016-10-19 15:07:58196 void set_scrollbar_button_length(int length) {
[email protected]990e6222012-11-16 13:31:18197 scrollbar_button_length_ = length;
198 }
[email protected]8eaacd42014-02-10 15:58:48199 int scrollbar_button_length() const { return scrollbar_button_length_; }
[email protected]990e6222012-11-16 13:31:18200
[email protected]990e6222012-11-16 13:31:18201 SkColor SaturateAndBrighten(SkScalar* hsv,
202 SkScalar saturate_amount,
203 SkScalar brighten_amount) const;
[email protected]e2169902014-01-22 20:23:41204
205 // Paints the arrow used on the scrollbar and spinner.
enne34f6084c2017-02-02 22:39:08206 void PaintArrow(cc::PaintCanvas* canvas,
[email protected]e2169902014-01-22 20:23:41207 const gfx::Rect& rect,
208 Part direction,
209 SkColor color) const;
210
211 // Returns the color used to draw the arrow.
Rune Lillesveene9ef0d602019-07-31 00:02:52212 SkColor GetArrowColor(State state, ColorScheme color_scheme) const;
[email protected]e2169902014-01-22 20:23:41213
bokan3d914bd2016-10-19 15:07:58214 int scrollbar_width_;
215
[email protected]990e6222012-11-16 13:31:18216 private:
bsep91cbc6d2016-06-14 00:51:51217 friend class NativeThemeAuraTest;
bsep6e7c3082016-05-19 23:04:26218
219 SkPath PathForArrow(const gfx::Rect& rect, Part direction) const;
bsep91cbc6d2016-06-14 00:51:51220 gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const;
bsep6e7c3082016-05-19 23:04:26221
enne34f6084c2017-02-02 22:39:08222 void DrawVertLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18223 int x,
224 int y1,
225 int y2,
enne9873ffb2017-02-07 23:20:17226 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08227 void DrawHorizLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18228 int x1,
229 int x2,
230 int y,
enne9873ffb2017-02-07 23:20:17231 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08232 void DrawBox(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18233 const gfx::Rect& rect,
enne9873ffb2017-02-07 23:20:17234 const cc::PaintFlags& flags) const;
[email protected]990e6222012-11-16 13:31:18235 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;
236
[email protected]a244f2582013-03-08 07:31:23237 // Paint the common parts of the checkboxes and radio buttons.
Rune Lillesveenc04c99842019-10-01 20:26:35238 // border_radius specifies how rounded the corners should be.
enne34f6084c2017-02-02 22:39:08239 SkRect PaintCheckboxRadioCommon(cc::PaintCanvas* canvas,
240 State state,
241 const gfx::Rect& rect,
Alex Kengadc4f6102019-09-18 03:07:03242 const ButtonExtraParams& button,
243 bool is_checkbox,
Rune Lillesveenc04c99842019-10-01 20:26:35244 const SkScalar border_radius,
Rune Lillesveene9ef0d602019-07-31 00:02:52245 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18246
Joey Arhar3a2f2672019-11-14 16:51:10247 SkColor ControlsAccentColorForState(State state,
248 ColorScheme color_scheme) const;
249 SkColor ControlsBorderColorForState(State state,
250 ColorScheme color_scheme) const;
251 SkColor ControlsFillColorForState(State state,
252 ColorScheme color_scheme) const;
253 SkColor ControlsBackgroundColorForState(State state,
254 ColorScheme color_scheme) const;
255 SkColor ControlsSliderColorForState(State state,
256 ColorScheme color_scheme) const;
257 SkColor GetHighContrastControlColor(ControlColorId color_id,
258 ColorScheme color_scheme) const;
259 SkColor GetControlColor(ControlColorId color_id,
260 ColorScheme color_scheme) const;
261 SkRect AlignSliderTrack(const gfx::Rect& slider_rect,
262 const NativeTheme::SliderExtraParams& slider,
263 bool is_value,
264 float track_height) const;
265
[email protected]ae9a3412014-08-14 08:01:29266 // The length of the arrow buttons, 0 means no buttons are drawn.
bokan3d914bd2016-10-19 15:07:58267 int scrollbar_button_length_;
[email protected]990e6222012-11-16 13:31:18268
269 DISALLOW_COPY_AND_ASSIGN(NativeThemeBase);
270};
271
272} // namespace ui
273
274#endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_