Roll src/third_party/WebKit 06cb9e9:a978ee5 (svn 202558:202559)
[chromium-blink-merge.git] / ui / native_theme / native_theme_base.h
blob1c92ed8d0d9de309036b639375b7dec969f1a050
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.
5 #ifndef UI_NATIVE_THEME_NATIVE_THEME_BASE_H_
6 #define UI_NATIVE_THEME_NATIVE_THEME_BASE_H_
8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "skia/ext/platform_canvas.h"
12 #include "ui/native_theme/native_theme.h"
14 namespace gfx {
15 class Canvas;
16 class ImageSkia;
17 class Rect;
18 class Size;
21 namespace ui {
23 // Theme support for non-Windows toolkits.
24 class NATIVE_THEME_EXPORT NativeThemeBase : public NativeTheme {
25 public:
26 // NativeTheme implementation:
27 gfx::Size GetPartSize(Part part,
28 State state,
29 const ExtraParams& extra) const override;
30 void Paint(SkCanvas* canvas,
31 Part part,
32 State state,
33 const gfx::Rect& rect,
34 const ExtraParams& extra) const override;
36 void PaintStateTransition(SkCanvas* canvas,
37 Part part,
38 State startState,
39 State endState,
40 double progress,
41 const gfx::Rect& rect) const override;
43 protected:
44 NativeThemeBase();
45 ~NativeThemeBase() override;
47 // Draw the arrow. Used by scrollbar and inner spin button.
48 virtual void PaintArrowButton(
49 SkCanvas* gc,
50 const gfx::Rect& rect,
51 Part direction,
52 State state) const;
53 // Paint the scrollbar track. Done before the thumb so that it can contain
54 // alpha.
55 virtual void PaintScrollbarTrack(
56 SkCanvas* canvas,
57 Part part,
58 State state,
59 const ScrollbarTrackExtraParams& extra_params,
60 const gfx::Rect& rect) const;
61 // Draw the scrollbar thumb over the track.
62 virtual void PaintScrollbarThumb(
63 SkCanvas* canvas,
64 Part part,
65 State state,
66 const gfx::Rect& rect) const;
68 virtual void PaintScrollbarCorner(SkCanvas* canvas,
69 State state,
70 const gfx::Rect& rect) const;
72 virtual void PaintCheckbox(
73 SkCanvas* canvas,
74 State state,
75 const gfx::Rect& rect,
76 const ButtonExtraParams& button) const;
78 virtual void PaintRadio(
79 SkCanvas* canvas,
80 State state,
81 const gfx::Rect& rect,
82 const ButtonExtraParams& button) const;
84 virtual void PaintButton(
85 SkCanvas* canvas,
86 State state,
87 const gfx::Rect& rect,
88 const ButtonExtraParams& button) const;
90 virtual void PaintTextField(
91 SkCanvas* canvas,
92 State state,
93 const gfx::Rect& rect,
94 const TextFieldExtraParams& text) const;
96 virtual void PaintMenuList(
97 SkCanvas* canvas,
98 State state,
99 const gfx::Rect& rect,
100 const MenuListExtraParams& menu_list) const;
102 virtual void PaintMenuPopupBackground(
103 SkCanvas* canvas,
104 const gfx::Size& size,
105 const MenuBackgroundExtraParams& menu_background) const;
107 virtual void PaintMenuItemBackground(
108 SkCanvas* canvas,
109 State state,
110 const gfx::Rect& rect,
111 const MenuListExtraParams& menu_list) const;
113 virtual void PaintSliderTrack(
114 SkCanvas* canvas,
115 State state,
116 const gfx::Rect& rect,
117 const SliderExtraParams& slider) const;
119 virtual void PaintSliderThumb(
120 SkCanvas* canvas,
121 State state,
122 const gfx::Rect& rect,
123 const SliderExtraParams& slider) const;
125 virtual void PaintInnerSpinButton(
126 SkCanvas* canvas,
127 State state,
128 const gfx::Rect& rect,
129 const InnerSpinButtonExtraParams& spin_button) const;
131 virtual void PaintProgressBar(
132 SkCanvas* canvas,
133 State state,
134 const gfx::Rect& rect,
135 const ProgressBarExtraParams& progress_bar) const;
137 virtual void PaintScrollbarThumbStateTransition(
138 SkCanvas* canvas,
139 State startState,
140 State endState,
141 double progress,
142 const gfx::Rect& rect) const {}
144 // Shrinks checkbox/radio button rect, if necessary, to make room for padding
145 // and drop shadow.
146 // TODO(mohsen): This is needed because checkboxes/radio buttons on Android
147 // have different padding from those on desktop Chrome. Get rid of this when
148 // crbug.com/530746 is resolved.
149 virtual void AdjustCheckboxRadioRectForPadding(SkRect* rect) const;
151 void set_scrollbar_button_length(unsigned int length) {
152 scrollbar_button_length_ = length;
154 int scrollbar_button_length() const { return scrollbar_button_length_; }
156 bool IntersectsClipRectInt(SkCanvas* canvas,
157 int x, int y, int w, int h) const;
159 void DrawImageInt(SkCanvas* canvas, const gfx::ImageSkia& image,
160 int src_x, int src_y, int src_w, int src_h,
161 int dest_x, int dest_y, int dest_w, int dest_h) const;
163 void DrawTiledImage(SkCanvas* canvas,
164 const gfx::ImageSkia& image,
165 int src_x, int src_y,
166 float tile_scale_x, float tile_scale_y,
167 int dest_x, int dest_y, int w, int h) const;
169 SkColor SaturateAndBrighten(SkScalar* hsv,
170 SkScalar saturate_amount,
171 SkScalar brighten_amount) const;
173 // Paints the arrow used on the scrollbar and spinner.
174 void PaintArrow(SkCanvas* canvas,
175 const gfx::Rect& rect,
176 Part direction,
177 SkColor color) const;
179 // Returns the color used to draw the arrow.
180 SkColor GetArrowColor(State state) const;
182 private:
183 void DrawVertLine(SkCanvas* canvas,
184 int x,
185 int y1,
186 int y2,
187 const SkPaint& paint) const;
188 void DrawHorizLine(SkCanvas* canvas,
189 int x1,
190 int x2,
191 int y,
192 const SkPaint& paint) const;
193 void DrawBox(SkCanvas* canvas,
194 const gfx::Rect& rect,
195 const SkPaint& paint) const;
196 SkScalar Clamp(SkScalar value,
197 SkScalar min,
198 SkScalar max) const;
199 SkColor OutlineColor(SkScalar* hsv1, SkScalar* hsv2) const;
201 // Paint the common parts of the checkboxes and radio buttons.
202 // borderRadius specifies how rounded the corners should be.
203 SkRect PaintCheckboxRadioCommon(
204 SkCanvas* canvas,
205 State state,
206 const gfx::Rect& rect,
207 const SkScalar borderRadius) const;
209 unsigned int scrollbar_width_;
211 // The length of the arrow buttons, 0 means no buttons are drawn.
212 unsigned int scrollbar_button_length_;
214 DISALLOW_COPY_AND_ASSIGN(NativeThemeBase);
217 } // namespace ui
219 #endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_