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_H_
6 #define UI_NATIVE_THEME_NATIVE_THEME_H_
8 #include "third_party/skia/include/core/SkColor.h"
9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/native_theme/native_theme_export.h"
21 // This class supports drawing UI controls (like buttons, text fields, lists,
22 // comboboxes, etc) that look like the native UI controls of the underlying
23 // platform, such as Windows or Linux. It also supplies default colors for
24 // dialog box backgrounds, etc., which are obtained from the system theme where
27 // The supported control types are listed in the Part enum. These parts can be
28 // in any state given by the State enum, where the actual definition of the
29 // state is part-specific. The supported colors are listed in the ColorId enum.
31 // Some parts require more information than simply the state in order to be
32 // drawn correctly, and this information is given to the Paint() method via the
33 // ExtraParams union. Each part that requires more information has its own
34 // field in the union.
36 // NativeTheme also supports getting the default size of a given part with
37 // the GetPartSize() method.
38 class NATIVE_THEME_EXPORT NativeTheme
{
40 // The part to be painted / sized.
56 // The order of the arrow enums is important, do not change without also
57 // changing the code in platform implementations.
63 kScrollbarHorizontalThumb
,
64 kScrollbarVerticalThumb
,
65 kScrollbarHorizontalTrack
,
66 kScrollbarVerticalTrack
,
67 kScrollbarHorizontalGripper
,
68 kScrollbarVerticalGripper
,
79 // The state of the part.
89 MENU_VARIATION_NORMAL
,
90 MENU_VARIATION_COMPACT_1
,
91 MENU_VARIATION_COMPACT_2
,
92 MENU_VARIATION_CONTRAST
95 // Each structure below holds extra information needed when painting a given
98 struct ButtonExtraParams
{
100 bool indeterminate
; // Whether the button state is indeterminate.
101 bool is_default
; // Whether the button is default button.
104 int classic_state
; // Used on Windows when uxtheme is not available.
105 SkColor background_color
;
108 struct InnerSpinButtonExtraParams
{
111 int classic_state
; // Used on Windows when uxtheme is not available.
114 struct MenuArrowExtraParams
{
116 // Used for the disabled state to indicate if the item is both disabled and
121 struct MenuCheckExtraParams
{
123 // Used for the disabled state to indicate if the item is both disabled and
128 struct MenuItemExtraParams
{
132 struct MenuListExtraParams
{
134 bool has_border_radius
;
137 SkColor background_color
;
138 int classic_state
; // Used on Windows when uxtheme is not available.
141 struct MenuSeparatorExtraParams
{
145 struct MenuBackgroundExtraParams
{
149 struct ProgressBarExtraParams
{
150 double animated_seconds
;
154 int value_rect_width
;
155 int value_rect_height
;
158 struct ScrollbarArrowExtraParams
{
162 struct ScrollbarTrackExtraParams
{
168 int classic_state
; // Used on Windows when uxtheme is not available.
171 struct ScrollbarThumbExtraParams
{
175 struct SliderExtraParams
{
180 struct TextFieldExtraParams
{
183 SkColor background_color
;
186 bool fill_content_area
;
188 int classic_state
; // Used on Windows when uxtheme is not available.
191 struct TrackbarExtraParams
{
193 int classic_state
; // Used on Windows when uxtheme is not available.
197 ButtonExtraParams button
;
198 InnerSpinButtonExtraParams inner_spin
;
199 MenuArrowExtraParams menu_arrow
;
200 MenuCheckExtraParams menu_check
;
201 MenuItemExtraParams menu_item
;
202 MenuListExtraParams menu_list
;
203 MenuSeparatorExtraParams menu_separator
;
204 MenuBackgroundExtraParams menu_background
;
205 ProgressBarExtraParams progress_bar
;
206 ScrollbarArrowExtraParams scrollbar_arrow
;
207 ScrollbarTrackExtraParams scrollbar_track
;
208 ScrollbarThumbExtraParams scrollbar_thumb
;
209 SliderExtraParams slider
;
210 TextFieldExtraParams text_field
;
211 TrackbarExtraParams trackbar
;
214 // Return the size of the part.
215 virtual gfx::Size
GetPartSize(Part part
,
217 const ExtraParams
& extra
) const = 0;
219 // Paint the part to the canvas.
220 virtual void Paint(SkCanvas
* canvas
,
223 const gfx::Rect
& rect
,
224 const ExtraParams
& extra
) const = 0;
226 // Supports theme specific colors.
227 void SetScrollbarColors(unsigned inactive_color
,
228 unsigned active_color
,
229 unsigned track_color
);
231 // Colors for GetSystemColor().
234 kColorId_WindowBackground
,
236 kColorId_DialogBackground
,
238 kColorId_FocusedBorderColor
,
239 kColorId_UnfocusedBorderColor
,
241 kColorId_ButtonBackgroundColor
,
242 kColorId_ButtonEnabledColor
,
243 kColorId_ButtonDisabledColor
,
244 kColorId_ButtonHighlightColor
,
245 kColorId_ButtonHoverColor
,
247 kColorId_EnabledMenuItemForegroundColor
,
248 kColorId_DisabledMenuItemForegroundColor
,
249 kColorId_SelectedMenuItemForegroundColor
,
250 kColorId_FocusedMenuItemBackgroundColor
,
251 kColorId_HoverMenuItemBackgroundColor
,
252 kColorId_MenuSeparatorColor
,
253 kColorId_MenuBackgroundColor
,
254 kColorId_MenuBorderColor
,
255 // MenuButton - buttons in wrench menu
256 kColorId_EnabledMenuButtonBorderColor
,
257 kColorId_FocusedMenuButtonBorderColor
,
258 kColorId_HoverMenuButtonBorderColor
,
260 kColorId_LabelEnabledColor
,
261 kColorId_LabelDisabledColor
,
262 kColorId_LabelBackgroundColor
,
264 kColorId_TextfieldDefaultColor
,
265 kColorId_TextfieldDefaultBackground
,
266 kColorId_TextfieldReadOnlyColor
,
267 kColorId_TextfieldReadOnlyBackground
,
268 kColorId_TextfieldSelectionColor
,
269 kColorId_TextfieldSelectionBackgroundFocused
,
270 kColorId_TextfieldSelectionBackgroundUnfocused
,
272 kColorId_TreeBackground
,
274 kColorId_TreeSelectedText
,
275 kColorId_TreeSelectedTextUnfocused
,
276 kColorId_TreeSelectionBackgroundFocused
,
277 kColorId_TreeSelectionBackgroundUnfocused
,
280 kColorId_TableBackground
,
282 kColorId_TableSelectedText
,
283 kColorId_TableSelectedTextUnfocused
,
284 kColorId_TableSelectionBackgroundFocused
,
285 kColorId_TableSelectionBackgroundUnfocused
,
286 kColorId_TableGroupingIndicatorColor
,
287 // TODO(benrg): move other hardcoded colors here.
290 // Return a color from the system theme.
291 virtual SkColor
GetSystemColor(ColorId color_id
) const = 0;
293 // Returns a shared instance of the native theme.
294 // The returned object should not be deleted by the caller. This function
295 // is not thread safe and should only be called from the UI thread.
296 // Each port of NativeTheme should provide its own implementation of this
297 // function, returning the port's subclass.
298 static NativeTheme
* instance();
300 static MenuVariation
GetMenuVariation();
304 virtual ~NativeTheme();
306 unsigned int thumb_inactive_color_
;
307 unsigned int thumb_active_color_
;
308 unsigned int track_color_
;
310 DISALLOW_COPY_AND_ASSIGN(NativeTheme
);
315 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_