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,
69 // The corner is drawn when there is both a horizontal and vertical
82 // The state of the part.
84 // IDs defined as specific values for use in arrays.
92 // Each structure below holds extra information needed when painting a given
95 struct ButtonExtraParams {
97 bool indeterminate; // Whether the button state is indeterminate.
98 bool is_default; // Whether the button is default button.
101 int classic_state; // Used on Windows when uxtheme is not available.
102 SkColor background_color;
105 struct InnerSpinButtonExtraParams {
108 int classic_state; // Used on Windows when uxtheme is not available.
111 struct MenuArrowExtraParams {
113 // Used for the disabled state to indicate if the item is both disabled and
118 struct MenuCheckExtraParams {
120 // Used for the disabled state to indicate if the item is both disabled and
125 struct MenuItemExtraParams {
129 struct MenuListExtraParams {
131 bool has_border_radius;
134 SkColor background_color;
135 int classic_state; // Used on Windows when uxtheme is not available.
138 struct MenuSeparatorExtraParams {
142 struct MenuBackgroundExtraParams {
146 struct ProgressBarExtraParams {
147 double animated_seconds;
151 int value_rect_width;
152 int value_rect_height;
155 struct ScrollbarArrowExtraParams {
159 struct ScrollbarTrackExtraParams {
165 int classic_state; // Used on Windows when uxtheme is not available.
168 struct ScrollbarThumbExtraParams {
172 struct SliderExtraParams {
177 struct TextFieldExtraParams {
180 SkColor background_color;
183 bool fill_content_area;
185 int classic_state; // Used on Windows when uxtheme is not available.
188 struct TrackbarExtraParams {
190 int classic_state; // Used on Windows when uxtheme is not available.
194 ButtonExtraParams button;
195 InnerSpinButtonExtraParams inner_spin;
196 MenuArrowExtraParams menu_arrow;
197 MenuCheckExtraParams menu_check;
198 MenuItemExtraParams menu_item;
199 MenuListExtraParams menu_list;
200 MenuSeparatorExtraParams menu_separator;
201 MenuBackgroundExtraParams menu_background;
202 ProgressBarExtraParams progress_bar;
203 ScrollbarArrowExtraParams scrollbar_arrow;
204 ScrollbarTrackExtraParams scrollbar_track;
205 ScrollbarThumbExtraParams scrollbar_thumb;
206 SliderExtraParams slider;
207 TextFieldExtraParams text_field;
208 TrackbarExtraParams trackbar;
211 // Return the size of the part.
212 virtual gfx::Size GetPartSize(Part part,
214 const ExtraParams& extra) const = 0;
216 // Paint the part to the canvas.
217 virtual void Paint(SkCanvas* canvas,
220 const gfx::Rect& rect,
221 const ExtraParams& extra) const = 0;
223 // Supports theme specific colors.
224 void SetScrollbarColors(unsigned inactive_color,
225 unsigned active_color,
226 unsigned track_color);
228 // Colors for GetSystemColor().
231 kColorId_WindowBackground,
233 kColorId_DialogBackground,
235 kColorId_FocusedBorderColor,
236 kColorId_UnfocusedBorderColor,
238 kColorId_ButtonBackgroundColor,
239 kColorId_ButtonEnabledColor,
240 kColorId_ButtonDisabledColor,
241 kColorId_ButtonHighlightColor,
242 kColorId_ButtonHoverColor,
244 kColorId_EnabledMenuItemForegroundColor,
245 kColorId_DisabledMenuItemForegroundColor,
246 kColorId_SelectedMenuItemForegroundColor,
247 kColorId_FocusedMenuItemBackgroundColor,
248 kColorId_HoverMenuItemBackgroundColor,
249 kColorId_MenuSeparatorColor,
250 kColorId_MenuBackgroundColor,
251 kColorId_MenuBorderColor,
252 // MenuButton - buttons in wrench menu
253 kColorId_EnabledMenuButtonBorderColor,
254 kColorId_FocusedMenuButtonBorderColor,
255 kColorId_HoverMenuButtonBorderColor,
257 kColorId_LabelEnabledColor,
258 kColorId_LabelDisabledColor,
259 kColorId_LabelBackgroundColor,
261 kColorId_TextfieldDefaultColor,
262 kColorId_TextfieldDefaultBackground,
263 kColorId_TextfieldReadOnlyColor,
264 kColorId_TextfieldReadOnlyBackground,
265 kColorId_TextfieldSelectionColor,
266 kColorId_TextfieldSelectionBackgroundFocused,
268 kColorId_TreeBackground,
270 kColorId_TreeSelectedText,
271 kColorId_TreeSelectedTextUnfocused,
272 kColorId_TreeSelectionBackgroundFocused,
273 kColorId_TreeSelectionBackgroundUnfocused,
276 kColorId_TableBackground,
278 kColorId_TableSelectedText,
279 kColorId_TableSelectedTextUnfocused,
280 kColorId_TableSelectionBackgroundFocused,
281 kColorId_TableSelectionBackgroundUnfocused,
282 kColorId_TableGroupingIndicatorColor,
283 // TODO(benrg): move other hardcoded colors here.
286 // Return a color from the system theme.
287 virtual SkColor GetSystemColor(ColorId color_id) const = 0;
289 // Returns a shared instance of the native theme.
290 // The returned object should not be deleted by the caller. This function
291 // is not thread safe and should only be called from the UI thread.
292 // Each port of NativeTheme should provide its own implementation of this
293 // function, returning the port's subclass.
294 static NativeTheme* instance();
298 virtual ~NativeTheme();
300 unsigned int thumb_inactive_color_;
301 unsigned int thumb_active_color_;
302 unsigned int track_color_;
304 DISALLOW_COPY_AND_ASSIGN(NativeTheme);
309 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_