Update To 11.40.268.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     kComboboxArrow,
46     kCheckbox,
47     kInnerSpinButton,
48     kMenuList,
49     kMenuCheck,
50     kMenuCheckBackground,
51     kMenuPopupArrow,
52     kMenuPopupBackground,
53     kMenuPopupGutter,
54     kMenuPopupSeparator,
55     kMenuItemBackground,
56     kProgressBar,
57     kPushButton,
58     kRadio,
59
60     // The order of the arrow enums is important, do not change without also
61     // changing the code in platform implementations.
62     kScrollbarDownArrow,
63     kScrollbarLeftArrow,
64     kScrollbarRightArrow,
65     kScrollbarUpArrow,
66
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
74     // scrollbar.
75     kScrollbarCorner,
76     kSliderTrack,
77     kSliderThumb,
78     kTabPanelBackground,
79     kTextField,
80     kTrackbarThumb,
81     kTrackbarTrack,
82     kWindowResizeGripper,
83     kMaxPart,
84   };
85
86   // The state of the part.
87   enum State {
88     // IDs defined as specific values for use in arrays.
89     kDisabled = 0,
90     kHovered  = 1,
91     kNormal   = 2,
92     kPressed  = 3,
93     kNumStates = kPressed + 1,
94   };
95
96   // Each structure below holds extra information needed when painting a given
97   // part.
98
99   struct ButtonExtraParams {
100     bool checked;
101     bool indeterminate;  // Whether the button state is indeterminate.
102     bool is_default;  // Whether the button is default button.
103     bool is_focused;
104     bool has_border;
105     int classic_state;  // Used on Windows when uxtheme is not available.
106     SkColor background_color;
107   };
108
109   struct InnerSpinButtonExtraParams {
110     bool spin_up;
111     bool read_only;
112     int classic_state;  // Used on Windows when uxtheme is not available.
113   };
114
115   struct MenuArrowExtraParams {
116     bool pointing_right;
117     // Used for the disabled state to indicate if the item is both disabled and
118     // selected.
119     bool is_selected;
120   };
121
122   struct MenuCheckExtraParams {
123     bool is_radio;
124     // Used for the disabled state to indicate if the item is both disabled and
125     // selected.
126     bool is_selected;
127   };
128
129   struct MenuItemExtraParams {
130     bool is_selected;
131   };
132
133   struct MenuListExtraParams {
134     bool has_border;
135     bool has_border_radius;
136     int arrow_x;
137     int arrow_y;
138     SkColor background_color;
139     int classic_state;  // Used on Windows when uxtheme is not available.
140   };
141
142   struct MenuBackgroundExtraParams {
143     int corner_radius;
144   };
145
146   struct ProgressBarExtraParams {
147     double animated_seconds;
148     bool determinate;
149     int value_rect_x;
150     int value_rect_y;
151     int value_rect_width;
152     int value_rect_height;
153   };
154
155   struct ScrollbarArrowExtraParams {
156     bool is_hovering;
157   };
158
159   struct ScrollbarTrackExtraParams {
160     bool is_upper;
161     int track_x;
162     int track_y;
163     int track_width;
164     int track_height;
165     int classic_state;  // Used on Windows when uxtheme is not available.
166   };
167
168   struct ScrollbarThumbExtraParams {
169     bool is_hovering;
170   };
171
172   struct SliderExtraParams {
173     bool vertical;
174     bool in_drag;
175   };
176
177   struct TextFieldExtraParams {
178     bool is_text_area;
179     bool is_listbox;
180     SkColor background_color;
181     bool is_read_only;
182     bool is_focused;
183     bool fill_content_area;
184     bool draw_edges;
185     int classic_state;  // Used on Windows when uxtheme is not available.
186   };
187
188   struct TrackbarExtraParams {
189     bool vertical;
190     int classic_state;  // Used on Windows when uxtheme is not available.
191   };
192
193   union ExtraParams {
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;
208   };
209
210   // Return the size of the part.
211   virtual gfx::Size GetPartSize(Part part,
212                                 State state,
213                                 const ExtraParams& extra) const = 0;
214
215   // Paint the part to the canvas.
216   virtual void Paint(SkCanvas* canvas,
217                      Part part,
218                      State state,
219                      const gfx::Rect& rect,
220                      const ExtraParams& extra) const = 0;
221
222   // Paint part during state transition, used for overlay scrollbar state
223   // transition animation.
224   virtual void PaintStateTransition(SkCanvas* canvas,
225                                     Part part,
226                                     State startState,
227                                     State endState,
228                                     double progress,
229                                     const gfx::Rect& rect) const { }
230
231   // Supports theme specific colors.
232   void SetScrollbarColors(unsigned inactive_color,
233                           unsigned active_color,
234                           unsigned track_color);
235
236   // Colors for GetSystemColor().
237   enum ColorId {
238     // Windows
239     kColorId_WindowBackground,
240     // Dialogs
241     kColorId_DialogBackground,
242     // FocusableBorder
243     kColorId_FocusedBorderColor,
244     kColorId_UnfocusedBorderColor,
245     // Button
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,
257     // MenuItem
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,
271     // Label
272     kColorId_LabelEnabledColor,
273     kColorId_LabelDisabledColor,
274     kColorId_LabelBackgroundColor,
275     // Textfield
276     kColorId_TextfieldDefaultColor,
277     kColorId_TextfieldDefaultBackground,
278     kColorId_TextfieldReadOnlyColor,
279     kColorId_TextfieldReadOnlyBackground,
280     kColorId_TextfieldSelectionColor,
281     kColorId_TextfieldSelectionBackgroundFocused,
282     // Tooltip
283     kColorId_TooltipBackground,
284     kColorId_TooltipText,
285     // Tree
286     kColorId_TreeBackground,
287     kColorId_TreeText,
288     kColorId_TreeSelectedText,
289     kColorId_TreeSelectedTextUnfocused,
290     kColorId_TreeSelectionBackgroundFocused,
291     kColorId_TreeSelectionBackgroundUnfocused,
292     kColorId_TreeArrow,
293     // Table
294     kColorId_TableBackground,
295     kColorId_TableText,
296     kColorId_TableSelectedText,
297     kColorId_TableSelectedTextUnfocused,
298     kColorId_TableSelectionBackgroundFocused,
299     kColorId_TableSelectionBackgroundUnfocused,
300     kColorId_TableGroupingIndicatorColor,
301     // Results Tables, such as the chrome 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     // TODO(benrg): move other hardcoded colors here.
318
319     kColorId_NumColors,
320   };
321
322   // Return a color from the system theme.
323   virtual SkColor GetSystemColor(ColorId color_id) const = 0;
324
325   // Returns a shared instance of the native theme.
326   // The returned object should not be deleted by the caller.  This function
327   // is not thread safe and should only be called from the UI thread.
328   // Each port of NativeTheme should provide its own implementation of this
329   // function, returning the port's subclass.
330   static NativeTheme* instance();
331
332   // Add or remove observers to be notified when the native theme changes.
333   void AddObserver(NativeThemeObserver* observer);
334   void RemoveObserver(NativeThemeObserver* observer);
335
336   // Notify observers of native theme changes.
337   void NotifyObservers();
338
339  protected:
340   NativeTheme();
341   virtual ~NativeTheme();
342
343   unsigned int thumb_inactive_color_;
344   unsigned int thumb_active_color_;
345   unsigned int track_color_;
346
347  private:
348   // Observers to notify when the native theme changes.
349   ObserverList<NativeThemeObserver> native_theme_observers_;
350
351   DISALLOW_COPY_AND_ASSIGN(NativeTheme);
352 };
353
354 }  // namespace ui
355
356 #endif  // UI_NATIVE_THEME_NATIVE_THEME_H_