[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 1 | // 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 | |
danakj | 25c52c3 | 2016-04-12 21:51:08 | [diff] [blame] | 8 | #include <memory> |
| 9 | |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 10 | #include "base/compiler_specific.h" |
bsep | 6e7c308 | 2016-05-19 23:04:26 | [diff] [blame] | 11 | #include "base/gtest_prod_util.h" |
avi | 9c81217b | 2015-12-24 23:40:05 | [diff] [blame] | 12 | #include "base/macros.h" |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 13 | #include "cc/paint/paint_flags.h" |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 14 | #include "ui/native_theme/native_theme.h" |
| 15 | |
| 16 | namespace gfx { |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 17 | class Rect; |
| 18 | class Size; |
| 19 | } |
| 20 | |
| 21 | namespace ui { |
| 22 | |
| 23 | // Theme support for non-Windows toolkits. |
| 24 | class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme { |
| 25 | public: |
| 26 | // NativeTheme implementation: |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 27 | gfx::Size GetPartSize(Part part, |
| 28 | State state, |
| 29 | const ExtraParams& extra) const override; |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 30 | void Paint(cc::PaintCanvas* canvas, |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 31 | Part part, |
| 32 | State state, |
| 33 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 34 | const ExtraParams& extra, |
| 35 | ColorScheme color_scheme) const override; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 36 | |
bokan | e7a058a | 2017-03-02 22:42:51 | [diff] [blame] | 37 | 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] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 41 | protected: |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 42 | // 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] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 62 | NativeThemeBase(); |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 63 | ~NativeThemeBase() override; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 64 | |
| 65 | // Draw the arrow. Used by scrollbar and inner spin button. |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 66 | virtual void PaintArrowButton(cc::PaintCanvas* gc, |
| 67 | const gfx::Rect& rect, |
| 68 | Part direction, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 69 | State state, |
Bo Cupp | 2e9e096 | 2019-08-12 21:19:26 | [diff] [blame] | 70 | ColorScheme color_scheme, |
| 71 | const ScrollbarArrowExtraParams& arrow) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 72 | // Paint the scrollbar track. Done before the thumb so that it can contain |
| 73 | // alpha. |
| 74 | virtual void PaintScrollbarTrack( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 75 | cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 76 | Part part, |
| 77 | State state, |
| 78 | const ScrollbarTrackExtraParams& extra_params, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 79 | const gfx::Rect& rect, |
| 80 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 81 | // Draw the scrollbar thumb over the track. |
| 82 | virtual void PaintScrollbarThumb( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 83 | cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 84 | Part part, |
| 85 | State state, |
chaopeng | 3386732f | 2016-10-28 14:49:49 | [diff] [blame] | 86 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 87 | NativeTheme::ScrollbarOverlayColorTheme theme, |
| 88 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 89 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 90 | virtual void PaintScrollbarCorner(cc::PaintCanvas* canvas, |
[email protected] | 99df47e | 2014-01-29 07:01:53 | [diff] [blame] | 91 | State state, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 92 | const gfx::Rect& rect, |
| 93 | ColorScheme color_scheme) const; |
[email protected] | 99df47e | 2014-01-29 07:01:53 | [diff] [blame] | 94 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 95 | void PaintCheckbox(cc::PaintCanvas* canvas, |
| 96 | State state, |
| 97 | const gfx::Rect& rect, |
| 98 | const ButtonExtraParams& button, |
| 99 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 100 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 101 | void PaintRadio(cc::PaintCanvas* canvas, |
| 102 | State state, |
| 103 | const gfx::Rect& rect, |
| 104 | const ButtonExtraParams& button, |
| 105 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 106 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 107 | void PaintButton(cc::PaintCanvas* canvas, |
| 108 | State state, |
| 109 | const gfx::Rect& rect, |
| 110 | const ButtonExtraParams& button, |
| 111 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 112 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 113 | void PaintTextField(cc::PaintCanvas* canvas, |
| 114 | State state, |
| 115 | const gfx::Rect& rect, |
| 116 | const TextFieldExtraParams& text, |
| 117 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 118 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 119 | 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] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 124 | |
[email protected] | e95cacb | 2013-01-29 02:31:12 | [diff] [blame] | 125 | virtual void PaintMenuPopupBackground( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 126 | cc::PaintCanvas* canvas, |
[email protected] | e95cacb | 2013-01-29 02:31:12 | [diff] [blame] | 127 | const gfx::Size& size, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 128 | const MenuBackgroundExtraParams& menu_background, |
| 129 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 130 | |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 131 | 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] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 136 | |
thomasanderson | e3bc84e3 | 2017-01-28 06:41:57 | [diff] [blame] | 137 | virtual void PaintMenuSeparator( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 138 | cc::PaintCanvas* canvas, |
thomasanderson | e3bc84e3 | 2017-01-28 06:41:57 | [diff] [blame] | 139 | State state, |
| 140 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 141 | const MenuSeparatorExtraParams& menu_separator, |
| 142 | ColorScheme color_scheme) const; |
thomasanderson | e3bc84e3 | 2017-01-28 06:41:57 | [diff] [blame] | 143 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 144 | void PaintSliderTrack(cc::PaintCanvas* canvas, |
| 145 | State state, |
| 146 | const gfx::Rect& rect, |
| 147 | const SliderExtraParams& slider, |
| 148 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 149 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 150 | void PaintSliderThumb(cc::PaintCanvas* canvas, |
| 151 | State state, |
| 152 | const gfx::Rect& rect, |
| 153 | const SliderExtraParams& slider, |
| 154 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 155 | |
| 156 | virtual void PaintInnerSpinButton( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 157 | cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 158 | State state, |
| 159 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 160 | const InnerSpinButtonExtraParams& spin_button, |
| 161 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 162 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 163 | 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] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 168 | |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 169 | 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; |
thomasanderson | 2bbf430 | 2017-01-24 21:24:42 | [diff] [blame] | 174 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 175 | virtual void PaintLightenLayer(cc::PaintCanvas* canvas, |
| 176 | SkRect skrect, |
| 177 | State state, |
| 178 | SkScalar border_radius, |
| 179 | ColorScheme color_scheme) const; |
| 180 | |
mohsen | 9418953 | 2015-09-14 04:33:46 | [diff] [blame] | 181 | // 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 | |
bokan | 3d914bd | 2016-10-19 15:07:58 | [diff] [blame] | 188 | void set_scrollbar_button_length(int length) { |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 189 | scrollbar_button_length_ = length; |
| 190 | } |
[email protected] | 8eaacd4 | 2014-02-10 15:58:48 | [diff] [blame] | 191 | int scrollbar_button_length() const { return scrollbar_button_length_; } |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 192 | |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 193 | SkColor SaturateAndBrighten(SkScalar* hsv, |
| 194 | SkScalar saturate_amount, |
| 195 | SkScalar brighten_amount) const; |
[email protected] | e216990 | 2014-01-22 20:23:41 | [diff] [blame] | 196 | |
| 197 | // Paints the arrow used on the scrollbar and spinner. |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 198 | void PaintArrow(cc::PaintCanvas* canvas, |
[email protected] | e216990 | 2014-01-22 20:23:41 | [diff] [blame] | 199 | const gfx::Rect& rect, |
| 200 | Part direction, |
| 201 | SkColor color) const; |
| 202 | |
| 203 | // Returns the color used to draw the arrow. |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 204 | SkColor GetArrowColor(State state, ColorScheme color_scheme) const; |
[email protected] | e216990 | 2014-01-22 20:23:41 | [diff] [blame] | 205 | |
bokan | 3d914bd | 2016-10-19 15:07:58 | [diff] [blame] | 206 | int scrollbar_width_; |
| 207 | |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 208 | private: |
bsep | 91cbc6d | 2016-06-14 00:51:51 | [diff] [blame] | 209 | friend class NativeThemeAuraTest; |
bsep | 6e7c308 | 2016-05-19 23:04:26 | [diff] [blame] | 210 | |
| 211 | SkPath PathForArrow(const gfx::Rect& rect, Part direction) const; |
bsep | 91cbc6d | 2016-06-14 00:51:51 | [diff] [blame] | 212 | gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const; |
bsep | 6e7c308 | 2016-05-19 23:04:26 | [diff] [blame] | 213 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 214 | void DrawVertLine(cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 215 | int x, |
| 216 | int y1, |
| 217 | int y2, |
enne | 9873ffb | 2017-02-07 23:20:17 | [diff] [blame] | 218 | const cc::PaintFlags& flags) const; |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 219 | void DrawHorizLine(cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 220 | int x1, |
| 221 | int x2, |
| 222 | int y, |
enne | 9873ffb | 2017-02-07 23:20:17 | [diff] [blame] | 223 | const cc::PaintFlags& flags) const; |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 224 | void DrawBox(cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 225 | const gfx::Rect& rect, |
enne | 9873ffb | 2017-02-07 23:20:17 | [diff] [blame] | 226 | const cc::PaintFlags& flags) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 227 | SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; |
| 228 | |
[email protected] | a244f258 | 2013-03-08 07:31:23 | [diff] [blame] | 229 | // Paint the common parts of the checkboxes and radio buttons. |
Rune Lillesveen | c04c9984 | 2019-10-01 20:26:35 | [diff] [blame] | 230 | // border_radius specifies how rounded the corners should be. |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 231 | SkRect PaintCheckboxRadioCommon(cc::PaintCanvas* canvas, |
| 232 | State state, |
| 233 | const gfx::Rect& rect, |
Alex Keng | adc4f610 | 2019-09-18 03:07:03 | [diff] [blame] | 234 | const ButtonExtraParams& button, |
| 235 | bool is_checkbox, |
Rune Lillesveen | c04c9984 | 2019-10-01 20:26:35 | [diff] [blame] | 236 | const SkScalar border_radius, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 237 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 238 | |
Joey Arhar | 3a2f267 | 2019-11-14 16:51:10 | [diff] [blame^] | 239 | 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] | ae9a341 | 2014-08-14 08:01:29 | [diff] [blame] | 258 | // The length of the arrow buttons, 0 means no buttons are drawn. |
bokan | 3d914bd | 2016-10-19 15:07:58 | [diff] [blame] | 259 | int scrollbar_button_length_; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 260 | |
| 261 | DISALLOW_COPY_AND_ASSIGN(NativeThemeBase); |
| 262 | }; |
| 263 | |
| 264 | } // namespace ui |
| 265 | |
| 266 | #endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_ |