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_LinkDisabled
,
277 kColorId_LinkEnabled
,
278 kColorId_LinkPressed
,
280 kColorId_TextfieldDefaultColor
,
281 kColorId_TextfieldDefaultBackground
,
282 kColorId_TextfieldReadOnlyColor
,
283 kColorId_TextfieldReadOnlyBackground
,
284 kColorId_TextfieldSelectionColor
,
285 kColorId_TextfieldSelectionBackgroundFocused
,
287 kColorId_TooltipBackground
,
288 kColorId_TooltipText
,
290 kColorId_TreeBackground
,
292 kColorId_TreeSelectedText
,
293 kColorId_TreeSelectedTextUnfocused
,
294 kColorId_TreeSelectionBackgroundFocused
,
295 kColorId_TreeSelectionBackgroundUnfocused
,
298 kColorId_TableBackground
,
300 kColorId_TableSelectedText
,
301 kColorId_TableSelectedTextUnfocused
,
302 kColorId_TableSelectionBackgroundFocused
,
303 kColorId_TableSelectionBackgroundUnfocused
,
304 kColorId_TableGroupingIndicatorColor
,
305 // Results Tables, such as the omnibox.
306 kColorId_ResultsTableNormalBackground
,
307 kColorId_ResultsTableHoveredBackground
,
308 kColorId_ResultsTableSelectedBackground
,
309 kColorId_ResultsTableNormalText
,
310 kColorId_ResultsTableHoveredText
,
311 kColorId_ResultsTableSelectedText
,
312 kColorId_ResultsTableNormalDimmedText
,
313 kColorId_ResultsTableHoveredDimmedText
,
314 kColorId_ResultsTableSelectedDimmedText
,
315 kColorId_ResultsTableNormalUrl
,
316 kColorId_ResultsTableHoveredUrl
,
317 kColorId_ResultsTableSelectedUrl
,
318 kColorId_ResultsTableNormalDivider
,
319 kColorId_ResultsTableHoveredDivider
,
320 kColorId_ResultsTableSelectedDivider
,
321 // Positive text refers to good (often rendered in green) text, such as the
322 // stock value went up.
323 kColorId_ResultsTablePositiveText
,
324 kColorId_ResultsTablePositiveHoveredText
,
325 kColorId_ResultsTablePositiveSelectedText
,
326 // Negative text refers to something alarming (often rendered in red), such
327 // as the stock value went down.
328 kColorId_ResultsTableNegativeText
,
329 kColorId_ResultsTableNegativeHoveredText
,
330 kColorId_ResultsTableNegativeSelectedText
,
333 kColorId_ChromeIconGrey
,
335 // Colors for the material spinner (aka throbber).
336 kColorId_ThrobberSpinningColor
,
337 kColorId_ThrobberWaitingColor
,
338 kColorId_ThrobberLightColor
,
339 // TODO(benrg): move other hardcoded colors here.
344 // Return a color from the system theme.
345 virtual SkColor
GetSystemColor(ColorId color_id
) const = 0;
347 // Returns a shared instance of the native theme.
348 // The returned object should not be deleted by the caller. This function
349 // is not thread safe and should only be called from the UI thread.
350 // Each port of NativeTheme should provide its own implementation of this
351 // function, returning the port's subclass.
352 static NativeTheme
* instance();
354 // Add or remove observers to be notified when the native theme changes.
355 void AddObserver(NativeThemeObserver
* observer
);
356 void RemoveObserver(NativeThemeObserver
* observer
);
358 // Notify observers of native theme changes.
359 void NotifyObservers();
363 virtual ~NativeTheme();
365 unsigned int thumb_inactive_color_
;
366 unsigned int thumb_active_color_
;
367 unsigned int track_color_
;
370 // Observers to notify when the native theme changes.
371 base::ObserverList
<NativeThemeObserver
> native_theme_observers_
;
373 DISALLOW_COPY_AND_ASSIGN(NativeTheme
);
378 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_