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 "base/observer_list.h"
9 #include "third_party/skia/include/core/SkColor.h"
10 #include "ui/gfx/native_widget_types.h"
11 #include "ui/native_theme/native_theme_export.h"
22 class NativeThemeObserver
;
24 // This class supports drawing UI controls (like buttons, text fields, lists,
25 // comboboxes, etc) that look like the native UI controls of the underlying
26 // platform, such as Windows or Linux. It also supplies default colors for
27 // dialog box backgrounds, etc., which are obtained from the system theme where
30 // The supported control types are listed in the Part enum. These parts can be
31 // in any state given by the State enum, where the actual definition of the
32 // state is part-specific. The supported colors are listed in the ColorId enum.
34 // Some parts require more information than simply the state in order to be
35 // drawn correctly, and this information is given to the Paint() method via the
36 // ExtraParams union. Each part that requires more information has its own
37 // field in the union.
39 // NativeTheme also supports getting the default size of a given part with
40 // the GetPartSize() method.
41 class NATIVE_THEME_EXPORT NativeTheme
{
43 // The part to be painted / sized.
60 // The order of the arrow enums is important, do not change without also
61 // changing the code in platform implementations.
67 kScrollbarHorizontalThumb
,
68 kScrollbarVerticalThumb
,
69 kScrollbarHorizontalTrack
,
70 kScrollbarVerticalTrack
,
71 kScrollbarHorizontalGripper
,
72 kScrollbarVerticalGripper
,
73 // The corner is drawn when there is both a horizontal and vertical
86 // The state of the part.
88 // IDs defined as specific values for use in arrays.
93 kNumStates
= kPressed
+ 1,
96 // Each structure below holds extra information needed when painting a given
99 struct ButtonExtraParams
{
101 bool indeterminate
; // Whether the button state is indeterminate.
102 bool is_default
; // Whether the button is default button.
105 int classic_state
; // Used on Windows when uxtheme is not available.
106 SkColor background_color
;
109 struct InnerSpinButtonExtraParams
{
112 int classic_state
; // Used on Windows when uxtheme is not available.
115 struct MenuArrowExtraParams
{
117 // Used for the disabled state to indicate if the item is both disabled and
122 struct MenuCheckExtraParams
{
124 // Used for the disabled state to indicate if the item is both disabled and
129 struct MenuItemExtraParams
{
133 struct MenuListExtraParams
{
135 bool has_border_radius
;
138 SkColor background_color
;
139 int classic_state
; // Used on Windows when uxtheme is not available.
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 MenuBackgroundExtraParams menu_background
;
201 ProgressBarExtraParams progress_bar
;
202 ScrollbarArrowExtraParams scrollbar_arrow
;
203 ScrollbarTrackExtraParams scrollbar_track
;
204 ScrollbarThumbExtraParams scrollbar_thumb
;
205 SliderExtraParams slider
;
206 TextFieldExtraParams text_field
;
207 TrackbarExtraParams trackbar
;
210 // Return the size of the part.
211 virtual gfx::Size
GetPartSize(Part part
,
213 const ExtraParams
& extra
) const = 0;
215 // Paint the part to the canvas.
216 virtual void Paint(SkCanvas
* canvas
,
219 const gfx::Rect
& rect
,
220 const ExtraParams
& extra
) const = 0;
222 // Paint part during state transition, used for overlay scrollbar state
223 // transition animation.
224 virtual void PaintStateTransition(SkCanvas
* canvas
,
229 const gfx::Rect
& rect
) const { }
231 // Supports theme specific colors.
232 void SetScrollbarColors(unsigned inactive_color
,
233 unsigned active_color
,
234 unsigned track_color
);
236 // Colors for GetSystemColor().
239 kColorId_WindowBackground
,
241 kColorId_DialogBackground
,
243 kColorId_FocusedBorderColor
,
244 kColorId_UnfocusedBorderColor
,
246 kColorId_ButtonBackgroundColor
,
247 kColorId_ButtonEnabledColor
,
248 kColorId_ButtonDisabledColor
,
249 kColorId_ButtonHighlightColor
,
250 kColorId_ButtonHoverColor
,
251 kColorId_ButtonHoverBackgroundColor
,
252 kColorId_BlueButtonEnabledColor
,
253 kColorId_BlueButtonDisabledColor
,
254 kColorId_BlueButtonPressedColor
,
255 kColorId_BlueButtonHoverColor
,
256 kColorId_BlueButtonShadowColor
,
258 kColorId_EnabledMenuItemForegroundColor
,
259 kColorId_DisabledMenuItemForegroundColor
,
260 kColorId_DisabledEmphasizedMenuItemForegroundColor
,
261 kColorId_SelectedMenuItemForegroundColor
,
262 kColorId_FocusedMenuItemBackgroundColor
,
263 kColorId_HoverMenuItemBackgroundColor
,
264 kColorId_MenuSeparatorColor
,
265 kColorId_MenuBackgroundColor
,
266 kColorId_MenuBorderColor
,
267 // MenuButton - buttons in wrench menu
268 kColorId_EnabledMenuButtonBorderColor
,
269 kColorId_FocusedMenuButtonBorderColor
,
270 kColorId_HoverMenuButtonBorderColor
,
272 kColorId_LabelEnabledColor
,
273 kColorId_LabelDisabledColor
,
274 kColorId_LabelBackgroundColor
,
276 kColorId_TextfieldDefaultColor
,
277 kColorId_TextfieldDefaultBackground
,
278 kColorId_TextfieldReadOnlyColor
,
279 kColorId_TextfieldReadOnlyBackground
,
280 kColorId_TextfieldSelectionColor
,
281 kColorId_TextfieldSelectionBackgroundFocused
,
283 kColorId_TooltipBackground
,
284 kColorId_TooltipText
,
286 kColorId_TreeBackground
,
288 kColorId_TreeSelectedText
,
289 kColorId_TreeSelectedTextUnfocused
,
290 kColorId_TreeSelectionBackgroundFocused
,
291 kColorId_TreeSelectionBackgroundUnfocused
,
294 kColorId_TableBackground
,
296 kColorId_TableSelectedText
,
297 kColorId_TableSelectedTextUnfocused
,
298 kColorId_TableSelectionBackgroundFocused
,
299 kColorId_TableSelectionBackgroundUnfocused
,
300 kColorId_TableGroupingIndicatorColor
,
301 // Results Tables, such as the omnibox.
302 kColorId_ResultsTableNormalBackground
,
303 kColorId_ResultsTableHoveredBackground
,
304 kColorId_ResultsTableSelectedBackground
,
305 kColorId_ResultsTableNormalText
,
306 kColorId_ResultsTableHoveredText
,
307 kColorId_ResultsTableSelectedText
,
308 kColorId_ResultsTableNormalDimmedText
,
309 kColorId_ResultsTableHoveredDimmedText
,
310 kColorId_ResultsTableSelectedDimmedText
,
311 kColorId_ResultsTableNormalUrl
,
312 kColorId_ResultsTableHoveredUrl
,
313 kColorId_ResultsTableSelectedUrl
,
314 kColorId_ResultsTableNormalDivider
,
315 kColorId_ResultsTableHoveredDivider
,
316 kColorId_ResultsTableSelectedDivider
,
317 // Positive text refers to good (often rendered in green) text, such as the
318 // stock value went up.
319 kColorId_ResultsTablePositiveText
,
320 kColorId_ResultsTablePositiveHoveredText
,
321 kColorId_ResultsTablePositiveSelectedText
,
322 // Negative text refers to something alarming (often rendered in red), such
323 // as the stock value went down.
324 kColorId_ResultsTableNegativeText
,
325 kColorId_ResultsTableNegativeHoveredText
,
326 kColorId_ResultsTableNegativeSelectedText
,
328 kColorId_ChromeIconGrey
,
329 // Colors for the material spinner (aka throbber).
330 kColorId_ThrobberSpinningColor
,
331 kColorId_ThrobberWaitingColor
,
332 kColorId_ThrobberLightColor
,
333 // TODO(benrg): move other hardcoded colors here.
338 // Return a color from the system theme.
339 virtual SkColor
GetSystemColor(ColorId color_id
) const = 0;
341 // Returns a shared instance of the native theme.
342 // The returned object should not be deleted by the caller. This function
343 // is not thread safe and should only be called from the UI thread.
344 // Each port of NativeTheme should provide its own implementation of this
345 // function, returning the port's subclass.
346 static NativeTheme
* instance();
348 // Add or remove observers to be notified when the native theme changes.
349 void AddObserver(NativeThemeObserver
* observer
);
350 void RemoveObserver(NativeThemeObserver
* observer
);
352 // Notify observers of native theme changes.
353 void NotifyObservers();
357 virtual ~NativeTheme();
359 unsigned int thumb_inactive_color_
;
360 unsigned int thumb_active_color_
;
361 unsigned int track_color_
;
364 // Observers to notify when the native theme changes.
365 base::ObserverList
<NativeThemeObserver
> native_theme_observers_
;
367 DISALLOW_COPY_AND_ASSIGN(NativeTheme
);
372 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_