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