blob: a61c947114320a4c3105ccc598c67595f7596d48 [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;
enne34f6084c2017-02-02 22:39:0830 void Paint(cc::PaintCanvas* canvas,
dcheng08038792014-10-21 10:53:2631 Part part,
32 State state,
33 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5234 const ExtraParams& extra,
35 ColorScheme color_scheme) const override;
[email protected]990e6222012-11-16 13:31:1836
bokane7a058a2017-03-02 22:42:5137 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]990e6222012-11-16 13:31:1841 protected:
42 NativeThemeBase();
dcheng08038792014-10-21 10:53:2643 ~NativeThemeBase() override;
[email protected]990e6222012-11-16 13:31:1844
45 // Draw the arrow. Used by scrollbar and inner spin button.
enne34f6084c2017-02-02 22:39:0846 virtual void PaintArrowButton(cc::PaintCanvas* gc,
47 const gfx::Rect& rect,
48 Part direction,
Rune Lillesveene9ef0d602019-07-31 00:02:5249 State state,
Bo Cupp2e9e0962019-08-12 21:19:2650 ColorScheme color_scheme,
51 const ScrollbarArrowExtraParams& arrow) const;
[email protected]990e6222012-11-16 13:31:1852 // Paint the scrollbar track. Done before the thumb so that it can contain
53 // alpha.
54 virtual void PaintScrollbarTrack(
enne34f6084c2017-02-02 22:39:0855 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:1856 Part part,
57 State state,
58 const ScrollbarTrackExtraParams& extra_params,
Rune Lillesveene9ef0d602019-07-31 00:02:5259 const gfx::Rect& rect,
60 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1861 // Draw the scrollbar thumb over the track.
62 virtual void PaintScrollbarThumb(
enne34f6084c2017-02-02 22:39:0863 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:1864 Part part,
65 State state,
chaopeng3386732f2016-10-28 14:49:4966 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5267 NativeTheme::ScrollbarOverlayColorTheme theme,
68 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1869
enne34f6084c2017-02-02 22:39:0870 virtual void PaintScrollbarCorner(cc::PaintCanvas* canvas,
[email protected]99df47e2014-01-29 07:01:5371 State state,
Rune Lillesveene9ef0d602019-07-31 00:02:5272 const gfx::Rect& rect,
73 ColorScheme color_scheme) const;
[email protected]99df47e2014-01-29 07:01:5374
enne34f6084c2017-02-02 22:39:0875 virtual void PaintCheckbox(cc::PaintCanvas* canvas,
76 State state,
77 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5278 const ButtonExtraParams& button,
79 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1880
enne34f6084c2017-02-02 22:39:0881 virtual void PaintRadio(cc::PaintCanvas* canvas,
82 State state,
83 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5284 const ButtonExtraParams& button,
85 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1886
enne34f6084c2017-02-02 22:39:0887 virtual void PaintButton(cc::PaintCanvas* canvas,
88 State state,
89 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5290 const ButtonExtraParams& button,
91 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1892
enne34f6084c2017-02-02 22:39:0893 virtual void PaintTextField(cc::PaintCanvas* canvas,
94 State state,
95 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:5296 const TextFieldExtraParams& text,
97 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:1898
enne34f6084c2017-02-02 22:39:0899 virtual void PaintMenuList(cc::PaintCanvas* canvas,
100 State state,
101 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52102 const MenuListExtraParams& menu_list,
103 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18104
[email protected]e95cacb2013-01-29 02:31:12105 virtual void PaintMenuPopupBackground(
enne34f6084c2017-02-02 22:39:08106 cc::PaintCanvas* canvas,
[email protected]e95cacb2013-01-29 02:31:12107 const gfx::Size& size,
Rune Lillesveene9ef0d602019-07-31 00:02:52108 const MenuBackgroundExtraParams& menu_background,
109 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18110
Rune Lillesveene9ef0d602019-07-31 00:02:52111 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]990e6222012-11-16 13:31:18116
thomasandersone3bc84e32017-01-28 06:41:57117 virtual void PaintMenuSeparator(
enne34f6084c2017-02-02 22:39:08118 cc::PaintCanvas* canvas,
thomasandersone3bc84e32017-01-28 06:41:57119 State state,
120 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52121 const MenuSeparatorExtraParams& menu_separator,
122 ColorScheme color_scheme) const;
thomasandersone3bc84e32017-01-28 06:41:57123
enne34f6084c2017-02-02 22:39:08124 virtual void PaintSliderTrack(cc::PaintCanvas* canvas,
125 State state,
126 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52127 const SliderExtraParams& slider,
128 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18129
enne34f6084c2017-02-02 22:39:08130 virtual void PaintSliderThumb(cc::PaintCanvas* canvas,
131 State state,
132 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52133 const SliderExtraParams& slider,
134 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18135
136 virtual void PaintInnerSpinButton(
enne34f6084c2017-02-02 22:39:08137 cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18138 State state,
139 const gfx::Rect& rect,
Rune Lillesveene9ef0d602019-07-31 00:02:52140 const InnerSpinButtonExtraParams& spin_button,
141 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18142
Rune Lillesveene9ef0d602019-07-31 00:02:52143 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]990e6222012-11-16 13:31:18148
Rune Lillesveene9ef0d602019-07-31 00:02:52149 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;
thomasanderson2bbf4302017-01-24 21:24:42154
mohsen94189532015-09-14 04:33:46155 // 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
bokan3d914bd2016-10-19 15:07:58162 void set_scrollbar_button_length(int length) {
[email protected]990e6222012-11-16 13:31:18163 scrollbar_button_length_ = length;
164 }
[email protected]8eaacd42014-02-10 15:58:48165 int scrollbar_button_length() const { return scrollbar_button_length_; }
[email protected]990e6222012-11-16 13:31:18166
[email protected]990e6222012-11-16 13:31:18167 SkColor SaturateAndBrighten(SkScalar* hsv,
168 SkScalar saturate_amount,
169 SkScalar brighten_amount) const;
[email protected]e2169902014-01-22 20:23:41170
171 // Paints the arrow used on the scrollbar and spinner.
enne34f6084c2017-02-02 22:39:08172 void PaintArrow(cc::PaintCanvas* canvas,
[email protected]e2169902014-01-22 20:23:41173 const gfx::Rect& rect,
174 Part direction,
175 SkColor color) const;
176
177 // Returns the color used to draw the arrow.
Rune Lillesveene9ef0d602019-07-31 00:02:52178 SkColor GetArrowColor(State state, ColorScheme color_scheme) const;
[email protected]e2169902014-01-22 20:23:41179
bokan3d914bd2016-10-19 15:07:58180 int scrollbar_width_;
181
[email protected]990e6222012-11-16 13:31:18182 private:
bsep91cbc6d2016-06-14 00:51:51183 friend class NativeThemeAuraTest;
bsep6e7c3082016-05-19 23:04:26184
185 SkPath PathForArrow(const gfx::Rect& rect, Part direction) const;
bsep91cbc6d2016-06-14 00:51:51186 gfx::Rect BoundingRectForArrow(const gfx::Rect& rect) const;
bsep6e7c3082016-05-19 23:04:26187
enne34f6084c2017-02-02 22:39:08188 void DrawVertLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18189 int x,
190 int y1,
191 int y2,
enne9873ffb2017-02-07 23:20:17192 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08193 void DrawHorizLine(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18194 int x1,
195 int x2,
196 int y,
enne9873ffb2017-02-07 23:20:17197 const cc::PaintFlags& flags) const;
enne34f6084c2017-02-02 22:39:08198 void DrawBox(cc::PaintCanvas* canvas,
[email protected]990e6222012-11-16 13:31:18199 const gfx::Rect& rect,
enne9873ffb2017-02-07 23:20:17200 const cc::PaintFlags& flags) const;
[email protected]990e6222012-11-16 13:31:18201 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;
202
[email protected]a244f2582013-03-08 07:31:23203 // Paint the common parts of the checkboxes and radio buttons.
Rune Lillesveenc04c99842019-10-01 20:26:35204 // border_radius specifies how rounded the corners should be.
enne34f6084c2017-02-02 22:39:08205 SkRect PaintCheckboxRadioCommon(cc::PaintCanvas* canvas,
206 State state,
207 const gfx::Rect& rect,
Alex Kengadc4f6102019-09-18 03:07:03208 const ButtonExtraParams& button,
209 bool is_checkbox,
Rune Lillesveenc04c99842019-10-01 20:26:35210 const SkScalar border_radius,
Rune Lillesveene9ef0d602019-07-31 00:02:52211 ColorScheme color_scheme) const;
[email protected]990e6222012-11-16 13:31:18212
[email protected]ae9a3412014-08-14 08:01:29213 // The length of the arrow buttons, 0 means no buttons are drawn.
bokan3d914bd2016-10-19 15:07:58214 int scrollbar_button_length_;
[email protected]990e6222012-11-16 13:31:18215
216 DISALLOW_COPY_AND_ASSIGN(NativeThemeBase);
217};
218
219} // namespace ui
220
221#endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_