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 MenuSeparatorExtraParams {
146 struct MenuBackgroundExtraParams {
150 struct ProgressBarExtraParams {
151 double animated_seconds;
155 int value_rect_width;
156 int value_rect_height;
159 struct ScrollbarArrowExtraParams {
163 struct ScrollbarTrackExtraParams {
169 int classic_state; // Used on Windows when uxtheme is not available.
172 struct ScrollbarThumbExtraParams {
176 struct SliderExtraParams {
181 struct TextFieldExtraParams {
184 SkColor background_color;
187 bool fill_content_area;
189 int classic_state; // Used on Windows when uxtheme is not available.
192 struct TrackbarExtraParams {
194 int classic_state; // Used on Windows when uxtheme is not available.
198 ButtonExtraParams button;
199 InnerSpinButtonExtraParams inner_spin;
200 MenuArrowExtraParams menu_arrow;
201 MenuCheckExtraParams menu_check;
202 MenuItemExtraParams menu_item;
203 MenuListExtraParams menu_list;
204 MenuSeparatorExtraParams menu_separator;
205 MenuBackgroundExtraParams menu_background;
206 ProgressBarExtraParams progress_bar;
207 ScrollbarArrowExtraParams scrollbar_arrow;
208 ScrollbarTrackExtraParams scrollbar_track;
209 ScrollbarThumbExtraParams scrollbar_thumb;
210 SliderExtraParams slider;
211 TextFieldExtraParams text_field;
212 TrackbarExtraParams trackbar;
215 // Return the size of the part.
216 virtual gfx::Size GetPartSize(Part part,
218 const ExtraParams& extra) const = 0;
220 // Paint the part to the canvas.
221 virtual void Paint(SkCanvas* canvas,
224 const gfx::Rect& rect,
225 const ExtraParams& extra) const = 0;
227 // Paint part during state transition, used for overlay scrollbar state
228 // transition animation.
229 virtual void PaintStateTransition(SkCanvas* canvas,
234 const gfx::Rect& rect) const { }
236 // Supports theme specific colors.
237 void SetScrollbarColors(unsigned inactive_color,
238 unsigned active_color,
239 unsigned track_color);
241 // Colors for GetSystemColor().
244 kColorId_WindowBackground,
246 kColorId_DialogBackground,
248 kColorId_FocusedBorderColor,
249 kColorId_UnfocusedBorderColor,
251 kColorId_ButtonBackgroundColor,
252 kColorId_ButtonEnabledColor,
253 kColorId_ButtonDisabledColor,
254 kColorId_ButtonHighlightColor,
255 kColorId_ButtonHoverColor,
256 kColorId_ButtonHoverBackgroundColor,
257 kColorId_BlueButtonEnabledColor,
258 kColorId_BlueButtonDisabledColor,
259 kColorId_BlueButtonPressedColor,
260 kColorId_BlueButtonHoverColor,
261 kColorId_BlueButtonShadowColor,
263 kColorId_EnabledMenuItemForegroundColor,
264 kColorId_DisabledMenuItemForegroundColor,
265 kColorId_DisabledEmphasizedMenuItemForegroundColor,
266 kColorId_SelectedMenuItemForegroundColor,
267 kColorId_FocusedMenuItemBackgroundColor,
268 kColorId_HoverMenuItemBackgroundColor,
269 kColorId_MenuSeparatorColor,
270 kColorId_MenuBackgroundColor,
271 kColorId_MenuBorderColor,
272 // MenuButton - buttons in wrench menu
273 kColorId_EnabledMenuButtonBorderColor,
274 kColorId_FocusedMenuButtonBorderColor,
275 kColorId_HoverMenuButtonBorderColor,
277 kColorId_LabelEnabledColor,
278 kColorId_LabelDisabledColor,
279 kColorId_LabelBackgroundColor,
281 kColorId_TextfieldDefaultColor,
282 kColorId_TextfieldDefaultBackground,
283 kColorId_TextfieldReadOnlyColor,
284 kColorId_TextfieldReadOnlyBackground,
285 kColorId_TextfieldSelectionColor,
286 kColorId_TextfieldSelectionBackgroundFocused,
288 kColorId_TooltipBackground,
289 kColorId_TooltipText,
291 kColorId_TreeBackground,
293 kColorId_TreeSelectedText,
294 kColorId_TreeSelectedTextUnfocused,
295 kColorId_TreeSelectionBackgroundFocused,
296 kColorId_TreeSelectionBackgroundUnfocused,
299 kColorId_TableBackground,
301 kColorId_TableSelectedText,
302 kColorId_TableSelectedTextUnfocused,
303 kColorId_TableSelectionBackgroundFocused,
304 kColorId_TableSelectionBackgroundUnfocused,
305 kColorId_TableGroupingIndicatorColor,
306 // Results Tables, such as the chrome omnibox.
307 kColorId_ResultsTableNormalBackground,
308 kColorId_ResultsTableHoveredBackground,
309 kColorId_ResultsTableSelectedBackground,
310 kColorId_ResultsTableNormalText,
311 kColorId_ResultsTableHoveredText,
312 kColorId_ResultsTableSelectedText,
313 kColorId_ResultsTableNormalDimmedText,
314 kColorId_ResultsTableHoveredDimmedText,
315 kColorId_ResultsTableSelectedDimmedText,
316 kColorId_ResultsTableNormalUrl,
317 kColorId_ResultsTableHoveredUrl,
318 kColorId_ResultsTableSelectedUrl,
319 kColorId_ResultsTableNormalDivider,
320 kColorId_ResultsTableHoveredDivider,
321 kColorId_ResultsTableSelectedDivider,
322 // TODO(benrg): move other hardcoded colors here.
327 // Return a color from the system theme.
328 virtual SkColor GetSystemColor(ColorId color_id) const = 0;
330 // Returns a shared instance of the native theme.
331 // The returned object should not be deleted by the caller. This function
332 // is not thread safe and should only be called from the UI thread.
333 // Each port of NativeTheme should provide its own implementation of this
334 // function, returning the port's subclass.
335 static NativeTheme* instance();
337 // Add or remove observers to be notified when the native theme changes.
338 void AddObserver(NativeThemeObserver* observer);
339 void RemoveObserver(NativeThemeObserver* observer);
341 // Notify observers of native theme changes.
342 void NotifyObservers();
346 virtual ~NativeTheme();
348 unsigned int thumb_inactive_color_;
349 unsigned int thumb_active_color_;
350 unsigned int track_color_;
353 // Observers to notify when the native theme changes.
354 ObserverList<NativeThemeObserver> native_theme_observers_;
356 DISALLOW_COPY_AND_ASSIGN(NativeTheme);
361 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_