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"
23 // Theme support for non-Windows toolkits.
24 class NATIVE_THEME_EXPORT NativeThemeBase
: public NativeTheme
{
26 // NativeTheme implementation:
27 gfx::Size
GetPartSize(Part part
,
29 const ExtraParams
& extra
) const override
;
30 void Paint(SkCanvas
* canvas
,
33 const gfx::Rect
& rect
,
34 const ExtraParams
& extra
) const override
;
36 void PaintStateTransition(SkCanvas
* canvas
,
41 const gfx::Rect
& rect
) const override
;
45 ~NativeThemeBase() override
;
47 // Draw the arrow. Used by scrollbar and inner spin button.
48 virtual void PaintArrowButton(
50 const gfx::Rect
& rect
,
53 // Paint the scrollbar track. Done before the thumb so that it can contain
55 virtual void PaintScrollbarTrack(
59 const ScrollbarTrackExtraParams
& extra_params
,
60 const gfx::Rect
& rect
) const;
61 // Draw the scrollbar thumb over the track.
62 virtual void PaintScrollbarThumb(
66 const gfx::Rect
& rect
) const;
68 virtual void PaintScrollbarCorner(SkCanvas
* canvas
,
70 const gfx::Rect
& rect
) const;
72 virtual void PaintCheckbox(
75 const gfx::Rect
& rect
,
76 const ButtonExtraParams
& button
) const;
78 virtual void PaintRadio(
81 const gfx::Rect
& rect
,
82 const ButtonExtraParams
& button
) const;
84 virtual void PaintButton(
87 const gfx::Rect
& rect
,
88 const ButtonExtraParams
& button
) const;
90 virtual void PaintTextField(
93 const gfx::Rect
& rect
,
94 const TextFieldExtraParams
& text
) const;
96 virtual void PaintMenuList(
99 const gfx::Rect
& rect
,
100 const MenuListExtraParams
& menu_list
) const;
102 virtual void PaintMenuPopupBackground(
104 const gfx::Size
& size
,
105 const MenuBackgroundExtraParams
& menu_background
) const;
107 virtual void PaintMenuItemBackground(
110 const gfx::Rect
& rect
,
111 const MenuListExtraParams
& menu_list
) const;
113 virtual void PaintSliderTrack(
116 const gfx::Rect
& rect
,
117 const SliderExtraParams
& slider
) const;
119 virtual void PaintSliderThumb(
122 const gfx::Rect
& rect
,
123 const SliderExtraParams
& slider
) const;
125 virtual void PaintInnerSpinButton(
128 const gfx::Rect
& rect
,
129 const InnerSpinButtonExtraParams
& spin_button
) const;
131 virtual void PaintProgressBar(
134 const gfx::Rect
& rect
,
135 const ProgressBarExtraParams
& progress_bar
) const;
137 virtual void PaintScrollbarThumbStateTransition(
142 const gfx::Rect
& rect
) const {}
144 // Shrinks checkbox/radio button rect, if necessary, to make room for padding
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
,
177 SkColor color
) const;
179 // Returns the color used to draw the arrow.
180 SkColor
GetArrowColor(State state
) const;
183 void DrawVertLine(SkCanvas
* canvas
,
187 const SkPaint
& paint
) const;
188 void DrawHorizLine(SkCanvas
* canvas
,
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
,
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(
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
);
219 #endif // UI_NATIVE_THEME_NATIVE_THEME_BASE_H_