[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: |
| 42 | NativeThemeBase(); |
dcheng | 0803879 | 2014-10-21 10:53:26 | [diff] [blame] | 43 | ~NativeThemeBase() override; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 44 | |
| 45 | // Draw the arrow. Used by scrollbar and inner spin button. |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 46 | virtual void PaintArrowButton(cc::PaintCanvas* gc, |
| 47 | const gfx::Rect& rect, |
| 48 | Part direction, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 49 | State state, |
Bo Cupp | 2e9e096 | 2019-08-12 21:19:26 | [diff] [blame] | 50 | ColorScheme color_scheme, |
| 51 | const ScrollbarArrowExtraParams& arrow) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 52 | // Paint the scrollbar track. Done before the thumb so that it can contain |
| 53 | // alpha. |
| 54 | virtual void PaintScrollbarTrack( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 55 | cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 56 | Part part, |
| 57 | State state, |
| 58 | const ScrollbarTrackExtraParams& extra_params, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 59 | const gfx::Rect& rect, |
| 60 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 61 | // Draw the scrollbar thumb over the track. |
| 62 | virtual void PaintScrollbarThumb( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 63 | cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 64 | Part part, |
| 65 | State state, |
chaopeng | 3386732f | 2016-10-28 14:49:49 | [diff] [blame] | 66 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 67 | NativeTheme::ScrollbarOverlayColorTheme theme, |
| 68 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 69 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 70 | virtual void PaintScrollbarCorner(cc::PaintCanvas* canvas, |
[email protected] | 99df47e | 2014-01-29 07:01:53 | [diff] [blame] | 71 | State state, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 72 | const gfx::Rect& rect, |
| 73 | ColorScheme color_scheme) const; |
[email protected] | 99df47e | 2014-01-29 07:01:53 | [diff] [blame] | 74 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 75 | virtual void PaintCheckbox(cc::PaintCanvas* canvas, |
| 76 | State state, |
| 77 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 78 | const ButtonExtraParams& button, |
| 79 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 80 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 81 | virtual void PaintRadio(cc::PaintCanvas* canvas, |
| 82 | State state, |
| 83 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 84 | const ButtonExtraParams& button, |
| 85 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 86 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 87 | virtual void PaintButton(cc::PaintCanvas* canvas, |
| 88 | State state, |
| 89 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 90 | const ButtonExtraParams& button, |
| 91 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 92 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 93 | virtual void PaintTextField(cc::PaintCanvas* canvas, |
| 94 | State state, |
| 95 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 96 | const TextFieldExtraParams& text, |
| 97 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 98 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 99 | virtual void PaintMenuList(cc::PaintCanvas* canvas, |
| 100 | State state, |
| 101 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 102 | const MenuListExtraParams& menu_list, |
| 103 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 104 | |
[email protected] | e95cacb | 2013-01-29 02:31:12 | [diff] [blame] | 105 | virtual void PaintMenuPopupBackground( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 106 | cc::PaintCanvas* canvas, |
[email protected] | e95cacb | 2013-01-29 02:31:12 | [diff] [blame] | 107 | const gfx::Size& size, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 108 | const MenuBackgroundExtraParams& menu_background, |
| 109 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 110 | |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 111 | virtual void PaintMenuItemBackground(cc::PaintCanvas* canvas, |
| 112 | State state, |
| 113 | const gfx::Rect& rect, |
| 114 | const MenuItemExtraParams& menu_item, |
| 115 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 116 | |
thomasanderson | e3bc84e3 | 2017-01-28 06:41:57 | [diff] [blame] | 117 | virtual void PaintMenuSeparator( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 118 | cc::PaintCanvas* canvas, |
thomasanderson | e3bc84e3 | 2017-01-28 06:41:57 | [diff] [blame] | 119 | State state, |
| 120 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 121 | const MenuSeparatorExtraParams& menu_separator, |
| 122 | ColorScheme color_scheme) const; |
thomasanderson | e3bc84e3 | 2017-01-28 06:41:57 | [diff] [blame] | 123 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 124 | virtual void PaintSliderTrack(cc::PaintCanvas* canvas, |
| 125 | State state, |
| 126 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 127 | const SliderExtraParams& slider, |
| 128 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 129 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 130 | virtual void PaintSliderThumb(cc::PaintCanvas* canvas, |
| 131 | State state, |
| 132 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 133 | const SliderExtraParams& slider, |
| 134 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 135 | |
| 136 | virtual void PaintInnerSpinButton( |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 137 | cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 138 | State state, |
| 139 | const gfx::Rect& rect, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 140 | const InnerSpinButtonExtraParams& spin_button, |
| 141 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 142 | |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 143 | virtual void PaintProgressBar(cc::PaintCanvas* canvas, |
| 144 | State state, |
| 145 | const gfx::Rect& rect, |
| 146 | const ProgressBarExtraParams& progress_bar, |
| 147 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 148 | |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 149 | virtual void PaintFrameTopArea(cc::PaintCanvas* canvas, |
| 150 | State state, |
| 151 | const gfx::Rect& rect, |
| 152 | const FrameTopAreaExtraParams& frame_top_area, |
| 153 | ColorScheme color_scheme) const; |
thomasanderson | 2bbf430 | 2017-01-24 21:24:42 | [diff] [blame] | 154 | |
mohsen | 9418953 | 2015-09-14 04:33:46 | [diff] [blame] | 155 | // Shrinks checkbox/radio button rect, if necessary, to make room for padding |
| 156 | // and drop shadow. |
| 157 | // TODO(mohsen): This is needed because checkboxes/radio buttons on Android |
| 158 | // have different padding from those on desktop Chrome. Get rid of this when |
| 159 | // crbug.com/530746 is resolved. |
| 160 | virtual void AdjustCheckboxRadioRectForPadding(SkRect* rect) const; |
| 161 | |
bokan | 3d914bd | 2016-10-19 15:07:58 | [diff] [blame] | 162 | void set_scrollbar_button_length(int length) { |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 163 | scrollbar_button_length_ = length; |
| 164 | } |
[email protected] | 8eaacd4 | 2014-02-10 15:58:48 | [diff] [blame] | 165 | int scrollbar_button_length() const { return scrollbar_button_length_; } |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 166 | |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 167 | SkColor SaturateAndBrighten(SkScalar* hsv, |
| 168 | SkScalar saturate_amount, |
| 169 | SkScalar brighten_amount) const; |
[email protected] | e216990 | 2014-01-22 20:23:41 | [diff] [blame] | 170 | |
| 171 | // Paints the arrow used on the scrollbar and spinner. |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 172 | void PaintArrow(cc::PaintCanvas* canvas, |
[email protected] | e216990 | 2014-01-22 20:23:41 | [diff] [blame] | 173 | const gfx::Rect& rect, |
| 174 | Part direction, |
| 175 | SkColor color) const; |
| 176 | |
| 177 | // Returns the color used to draw the arrow. |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 178 | SkColor GetArrowColor(State state, ColorScheme color_scheme) const; |
[email protected] | e216990 | 2014-01-22 20:23:41 | [diff] [blame] | 179 | |
bokan | 3d914bd | 2016-10-19 15:07:58 | [diff] [blame] | 180 | int scrollbar_width_; |
| 181 | |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 182 | private: |
bsep | 91cbc6d | 2016-06-14 00:51:51 | [diff] [blame] | 183 | friend class NativeThemeAuraTest; |
bsep | 6e7c308 | 2016-05-19 23:04:26 | [diff] [blame] | 184 | |
| 185 | SkPath PathForArrow(const gfx::Rect& rect, Part direction) const; |
bsep | 91cbc6d | 2016-06-14 00:51:51 | [diff] [blame] | 186 | gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const; |
bsep | 6e7c308 | 2016-05-19 23:04:26 | [diff] [blame] | 187 | |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 188 | void DrawVertLine(cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 189 | int x, |
| 190 | int y1, |
| 191 | int y2, |
enne | 9873ffb | 2017-02-07 23:20:17 | [diff] [blame] | 192 | const cc::PaintFlags& flags) const; |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 193 | void DrawHorizLine(cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 194 | int x1, |
| 195 | int x2, |
| 196 | int y, |
enne | 9873ffb | 2017-02-07 23:20:17 | [diff] [blame] | 197 | const cc::PaintFlags& flags) const; |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 198 | void DrawBox(cc::PaintCanvas* canvas, |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 199 | const gfx::Rect& rect, |
enne | 9873ffb | 2017-02-07 23:20:17 | [diff] [blame] | 200 | const cc::PaintFlags& flags) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 201 | SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const; |
| 202 | |
[email protected] | a244f258 | 2013-03-08 07:31:23 | [diff] [blame] | 203 | // Paint the common parts of the checkboxes and radio buttons. |
Rune Lillesveen | c04c9984 | 2019-10-01 20:26:35 | [diff] [blame^] | 204 | // border_radius specifies how rounded the corners should be. |
enne | 34f6084c | 2017-02-02 22:39:08 | [diff] [blame] | 205 | SkRect PaintCheckboxRadioCommon(cc::PaintCanvas* canvas, |
| 206 | State state, |
| 207 | const gfx::Rect& rect, |
Alex Keng | adc4f610 | 2019-09-18 03:07:03 | [diff] [blame] | 208 | const ButtonExtraParams& button, |
| 209 | bool is_checkbox, |
Rune Lillesveen | c04c9984 | 2019-10-01 20:26:35 | [diff] [blame^] | 210 | const SkScalar border_radius, |
Rune Lillesveen | e9ef0d60 | 2019-07-31 00:02:52 | [diff] [blame] | 211 | ColorScheme color_scheme) const; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 212 | |
[email protected] | ae9a341 | 2014-08-14 08:01:29 | [diff] [blame] | 213 | // The length of the arrow buttons, 0 means no buttons are drawn. |
bokan | 3d914bd | 2016-10-19 15:07:58 | [diff] [blame] | 214 | int scrollbar_button_length_; |
[email protected] | 990e622 | 2012-11-16 13:31:18 | [diff] [blame] | 215 | |
| 216 | DISALLOW_COPY_AND_ASSIGN(NativeThemeBase); |
| 217 | }; |
| 218 | |
| 219 | } // namespace ui |
| 220 | |
| 221 | #endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_ |