Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / native_theme / native_theme.h
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.
4
5 #ifndef UI_NATIVE_THEME_NATIVE_THEME_H_
6 #define UI_NATIVE_THEME_NATIVE_THEME_H_
7
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"
12
13 class SkCanvas;
14
15 namespace gfx {
16 class Rect;
17 class Size;
18 }
19
20 namespace ui {
21
22 class NativeThemeObserver;
23
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
28 // possible.
29 //
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.
33 //
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.
38 //
39 // NativeTheme also supports getting the default size of a given part with
40 // the GetPartSize() method.
41 class NATIVE_THEME_EXPORT NativeTheme {
42  public:
43   // The part to be painted / sized.
44   enum Part {
45     kCheckbox,
46     kInnerSpinButton,
47     kMenuList,
48     kMenuCheck,
49     kMenuCheckBackground,
50     kMenuPopupArrow,
51     kMenuPopupBackground,
52     kMenuPopupGutter,
53     kMenuPopupSeparator,
54     kMenuItemBackground,
55     kProgressBar,
56     kPushButton,
57     kRadio,
58
59     // The order of the arrow enums is important, do not change without also
60     // changing the code in platform implementations.
61     kScrollbarDownArrow,
62     kScrollbarLeftArrow,
63     kScrollbarRightArrow,
64     kScrollbarUpArrow,
65
66     kScrollbarHorizontalThumb,
67     kScrollbarVerticalThumb,
68     kScrollbarHorizontalTrack,
69     kScrollbarVerticalTrack,
70     kScrollbarHorizontalGripper,
71     kScrollbarVerticalGripper,
72     // The corner is drawn when there is both a horizontal and vertical
73     // scrollbar.
74     kScrollbarCorner,
75     kSliderTrack,
76     kSliderThumb,
77     kTabPanelBackground,
78     kTextField,
79     kTrackbarThumb,
80     kTrackbarTrack,
81     kWindowResizeGripper,
82     kMaxPart,
83   };
84
85   // The state of the part.
86   enum State {
87     // IDs defined as specific values for use in arrays.
88     kDisabled = 0,
89     kHovered  = 1,
90     kNormal   = 2,
91     kPressed  = 3,
92     kMaxState = 4,
93   };
94
95   // Each structure below holds extra information needed when painting a given
96   // part.
97
98   struct ButtonExtraParams {
99     bool checked;
100     bool indeterminate;  // Whether the button state is indeterminate.
101     bool is_default;  // Whether the button is default button.
102     bool is_focused;
103     bool has_border;
104     int classic_state;  // Used on Windows when uxtheme is not available.
105     SkColor background_color;
106   };
107
108   struct InnerSpinButtonExtraParams {
109     bool spin_up;
110     bool read_only;
111     int classic_state;  // Used on Windows when uxtheme is not available.
112   };
113
114   struct MenuArrowExtraParams {
115     bool pointing_right;
116     // Used for the disabled state to indicate if the item is both disabled and
117     // selected.
118     bool is_selected;
119   };
120
121   struct MenuCheckExtraParams {
122     bool is_radio;
123     // Used for the disabled state to indicate if the item is both disabled and
124     // selected.
125     bool is_selected;
126   };
127
128   struct MenuItemExtraParams {
129     bool is_selected;
130   };
131
132   struct MenuListExtraParams {
133     bool has_border;
134     bool has_border_radius;
135     int arrow_x;
136     int arrow_y;
137     SkColor background_color;
138     int classic_state;  // Used on Windows when uxtheme is not available.
139   };
140
141   struct MenuSeparatorExtraParams {
142     bool has_gutter;
143   };
144
145   struct MenuBackgroundExtraParams {
146     int corner_radius;
147   };
148
149   struct ProgressBarExtraParams {
150     double animated_seconds;
151     bool determinate;
152     int value_rect_x;
153     int value_rect_y;
154     int value_rect_width;
155     int value_rect_height;
156   };
157
158   struct ScrollbarArrowExtraParams {
159     bool is_hovering;
160   };
161
162   struct ScrollbarTrackExtraParams {
163     bool is_upper;
164     int track_x;
165     int track_y;
166     int track_width;
167     int track_height;
168     int classic_state;  // Used on Windows when uxtheme is not available.
169   };
170
171   struct ScrollbarThumbExtraParams {
172     bool is_hovering;
173   };
174
175   struct SliderExtraParams {
176     bool vertical;
177     bool in_drag;
178   };
179
180   struct TextFieldExtraParams {
181     bool is_text_area;
182     bool is_listbox;
183     SkColor background_color;
184     bool is_read_only;
185     bool is_focused;
186     bool fill_content_area;
187     bool draw_edges;
188     int classic_state;  // Used on Windows when uxtheme is not available.
189   };
190
191   struct TrackbarExtraParams {
192     bool vertical;
193     int classic_state;  // Used on Windows when uxtheme is not available.
194   };
195
196   union ExtraParams {
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;
212   };
213
214   // Return the size of the part.
215   virtual gfx::Size GetPartSize(Part part,
216                                 State state,
217                                 const ExtraParams& extra) const = 0;
218
219   // Paint the part to the canvas.
220   virtual void Paint(SkCanvas* canvas,
221                      Part part,
222                      State state,
223                      const gfx::Rect& rect,
224                      const ExtraParams& extra) const = 0;
225
226   // Supports theme specific colors.
227   void SetScrollbarColors(unsigned inactive_color,
228                           unsigned active_color,
229                           unsigned track_color);
230
231   // Colors for GetSystemColor().
232   enum ColorId {
233     // Windows
234     kColorId_WindowBackground,
235     // Dialogs
236     kColorId_DialogBackground,
237     // FocusableBorder
238     kColorId_FocusedBorderColor,
239     kColorId_UnfocusedBorderColor,
240     // Button
241     kColorId_ButtonBackgroundColor,
242     kColorId_ButtonEnabledColor,
243     kColorId_ButtonDisabledColor,
244     kColorId_ButtonHighlightColor,
245     kColorId_ButtonHoverColor,
246     kColorId_ButtonHoverBackgroundColor,
247     // MenuItem
248     kColorId_EnabledMenuItemForegroundColor,
249     kColorId_DisabledMenuItemForegroundColor,
250     kColorId_DisabledEmphasizedMenuItemForegroundColor,
251     kColorId_SelectedMenuItemForegroundColor,
252     kColorId_FocusedMenuItemBackgroundColor,
253     kColorId_HoverMenuItemBackgroundColor,
254     kColorId_MenuSeparatorColor,
255     kColorId_MenuBackgroundColor,
256     kColorId_MenuBorderColor,
257     // MenuButton - buttons in wrench menu
258     kColorId_EnabledMenuButtonBorderColor,
259     kColorId_FocusedMenuButtonBorderColor,
260     kColorId_HoverMenuButtonBorderColor,
261     // Label
262     kColorId_LabelEnabledColor,
263     kColorId_LabelDisabledColor,
264     kColorId_LabelBackgroundColor,
265     // Textfield
266     kColorId_TextfieldDefaultColor,
267     kColorId_TextfieldDefaultBackground,
268     kColorId_TextfieldReadOnlyColor,
269     kColorId_TextfieldReadOnlyBackground,
270     kColorId_TextfieldSelectionColor,
271     kColorId_TextfieldSelectionBackgroundFocused,
272     // Tooltip
273     kColorId_TooltipBackground,
274     // Tree
275     kColorId_TreeBackground,
276     kColorId_TreeText,
277     kColorId_TreeSelectedText,
278     kColorId_TreeSelectedTextUnfocused,
279     kColorId_TreeSelectionBackgroundFocused,
280     kColorId_TreeSelectionBackgroundUnfocused,
281     kColorId_TreeArrow,
282     // Table
283     kColorId_TableBackground,
284     kColorId_TableText,
285     kColorId_TableSelectedText,
286     kColorId_TableSelectedTextUnfocused,
287     kColorId_TableSelectionBackgroundFocused,
288     kColorId_TableSelectionBackgroundUnfocused,
289     kColorId_TableGroupingIndicatorColor,
290     // Results Tables, such as the chrome omnibox.
291     kColorId_ResultsTableNormalBackground,
292     kColorId_ResultsTableHoveredBackground,
293     kColorId_ResultsTableSelectedBackground,
294     kColorId_ResultsTableNormalText,
295     kColorId_ResultsTableHoveredText,
296     kColorId_ResultsTableSelectedText,
297     kColorId_ResultsTableNormalDimmedText,
298     kColorId_ResultsTableHoveredDimmedText,
299     kColorId_ResultsTableSelectedDimmedText,
300     kColorId_ResultsTableNormalUrl,
301     kColorId_ResultsTableHoveredUrl,
302     kColorId_ResultsTableSelectedUrl,
303     kColorId_ResultsTableNormalDivider,
304     kColorId_ResultsTableHoveredDivider,
305     kColorId_ResultsTableSelectedDivider,
306     // TODO(benrg): move other hardcoded colors here.
307   };
308
309   // Return a color from the system theme.
310   virtual SkColor GetSystemColor(ColorId color_id) const = 0;
311
312   // Returns a shared instance of the native theme.
313   // The returned object should not be deleted by the caller.  This function
314   // is not thread safe and should only be called from the UI thread.
315   // Each port of NativeTheme should provide its own implementation of this
316   // function, returning the port's subclass.
317   static NativeTheme* instance();
318
319   // Add or remove observers to be notified when the native theme changes.
320   void AddObserver(NativeThemeObserver* observer);
321   void RemoveObserver(NativeThemeObserver* observer);
322
323   // Notify observers of native theme changes.
324   void NotifyObservers();
325
326  protected:
327   NativeTheme();
328   virtual ~NativeTheme();
329
330   unsigned int thumb_inactive_color_;
331   unsigned int thumb_active_color_;
332   unsigned int track_color_;
333
334  private:
335   // Observers to notify when the native theme changes.
336   ObserverList<NativeThemeObserver> native_theme_observers_;
337
338   DISALLOW_COPY_AND_ASSIGN(NativeTheme);
339 };
340
341 }  // namespace ui
342
343 #endif  // UI_NATIVE_THEME_NATIVE_THEME_H_