Upstream version 5.34.104.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 "third_party/skia/include/core/SkColor.h"
9 #include "ui/gfx/native_widget_types.h"
10 #include "ui/native_theme/native_theme_export.h"
11
12 class SkCanvas;
13
14 namespace gfx {
15 class Rect;
16 class Size;
17 }
18
19 namespace ui {
20
21 // This class supports drawing UI controls (like buttons, text fields, lists,
22 // comboboxes, etc) that look like the native UI controls of the underlying
23 // platform, such as Windows or Linux. It also supplies default colors for
24 // dialog box backgrounds, etc., which are obtained from the system theme where
25 // possible.
26 //
27 // The supported control types are listed in the Part enum.  These parts can be
28 // in any state given by the State enum, where the actual definition of the
29 // state is part-specific. The supported colors are listed in the ColorId enum.
30 //
31 // Some parts require more information than simply the state in order to be
32 // drawn correctly, and this information is given to the Paint() method via the
33 // ExtraParams union.  Each part that requires more information has its own
34 // field in the union.
35 //
36 // NativeTheme also supports getting the default size of a given part with
37 // the GetPartSize() method.
38 class NATIVE_THEME_EXPORT NativeTheme {
39  public:
40   // The part to be painted / sized.
41   enum Part {
42     kCheckbox,
43     kInnerSpinButton,
44     kMenuList,
45     kMenuCheck,
46     kMenuCheckBackground,
47     kMenuPopupArrow,
48     kMenuPopupBackground,
49     kMenuPopupGutter,
50     kMenuPopupSeparator,
51     kMenuItemBackground,
52     kProgressBar,
53     kPushButton,
54     kRadio,
55
56     // The order of the arrow enums is important, do not change without also
57     // changing the code in platform implementations.
58     kScrollbarDownArrow,
59     kScrollbarLeftArrow,
60     kScrollbarRightArrow,
61     kScrollbarUpArrow,
62
63     kScrollbarHorizontalThumb,
64     kScrollbarVerticalThumb,
65     kScrollbarHorizontalTrack,
66     kScrollbarVerticalTrack,
67     kScrollbarHorizontalGripper,
68     kScrollbarVerticalGripper,
69     // The corner is drawn when there is both a horizontal and vertical
70     // scrollbar.
71     kScrollbarCorner,
72     kSliderTrack,
73     kSliderThumb,
74     kTabPanelBackground,
75     kTextField,
76     kTrackbarThumb,
77     kTrackbarTrack,
78     kWindowResizeGripper,
79     kMaxPart,
80   };
81
82   // The state of the part.
83   enum State {
84     // IDs defined as specific values for use in arrays.
85     kDisabled = 0,
86     kHovered  = 1,
87     kNormal   = 2,
88     kPressed  = 3,
89     kMaxState = 4,
90   };
91
92   // Each structure below holds extra information needed when painting a given
93   // part.
94
95   struct ButtonExtraParams {
96     bool checked;
97     bool indeterminate;  // Whether the button state is indeterminate.
98     bool is_default;  // Whether the button is default button.
99     bool is_focused;
100     bool has_border;
101     int classic_state;  // Used on Windows when uxtheme is not available.
102     SkColor background_color;
103   };
104
105   struct InnerSpinButtonExtraParams {
106     bool spin_up;
107     bool read_only;
108     int classic_state;  // Used on Windows when uxtheme is not available.
109   };
110
111   struct MenuArrowExtraParams {
112     bool pointing_right;
113     // Used for the disabled state to indicate if the item is both disabled and
114     // selected.
115     bool is_selected;
116   };
117
118   struct MenuCheckExtraParams {
119     bool is_radio;
120     // Used for the disabled state to indicate if the item is both disabled and
121     // selected.
122     bool is_selected;
123   };
124
125   struct MenuItemExtraParams {
126     bool is_selected;
127   };
128
129   struct MenuListExtraParams {
130     bool has_border;
131     bool has_border_radius;
132     int arrow_x;
133     int arrow_y;
134     SkColor background_color;
135     int classic_state;  // Used on Windows when uxtheme is not available.
136   };
137
138   struct MenuSeparatorExtraParams {
139     bool has_gutter;
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     MenuSeparatorExtraParams menu_separator;
201     MenuBackgroundExtraParams menu_background;
202     ProgressBarExtraParams progress_bar;
203     ScrollbarArrowExtraParams scrollbar_arrow;
204     ScrollbarTrackExtraParams scrollbar_track;
205     ScrollbarThumbExtraParams scrollbar_thumb;
206     SliderExtraParams slider;
207     TextFieldExtraParams text_field;
208     TrackbarExtraParams trackbar;
209   };
210
211   // Return the size of the part.
212   virtual gfx::Size GetPartSize(Part part,
213                                 State state,
214                                 const ExtraParams& extra) const = 0;
215
216   // Paint the part to the canvas.
217   virtual void Paint(SkCanvas* canvas,
218                      Part part,
219                      State state,
220                      const gfx::Rect& rect,
221                      const ExtraParams& extra) const = 0;
222
223   // Supports theme specific colors.
224   void SetScrollbarColors(unsigned inactive_color,
225                           unsigned active_color,
226                           unsigned track_color);
227
228   // Colors for GetSystemColor().
229   enum ColorId {
230     // Windows
231     kColorId_WindowBackground,
232     // Dialogs
233     kColorId_DialogBackground,
234     // FocusableBorder
235     kColorId_FocusedBorderColor,
236     kColorId_UnfocusedBorderColor,
237     // Button
238     kColorId_ButtonBackgroundColor,
239     kColorId_ButtonEnabledColor,
240     kColorId_ButtonDisabledColor,
241     kColorId_ButtonHighlightColor,
242     kColorId_ButtonHoverColor,
243     // MenuItem
244     kColorId_EnabledMenuItemForegroundColor,
245     kColorId_DisabledMenuItemForegroundColor,
246     kColorId_SelectedMenuItemForegroundColor,
247     kColorId_FocusedMenuItemBackgroundColor,
248     kColorId_HoverMenuItemBackgroundColor,
249     kColorId_MenuSeparatorColor,
250     kColorId_MenuBackgroundColor,
251     kColorId_MenuBorderColor,
252     // MenuButton - buttons in wrench menu
253     kColorId_EnabledMenuButtonBorderColor,
254     kColorId_FocusedMenuButtonBorderColor,
255     kColorId_HoverMenuButtonBorderColor,
256     // Label
257     kColorId_LabelEnabledColor,
258     kColorId_LabelDisabledColor,
259     kColorId_LabelBackgroundColor,
260     // Textfield
261     kColorId_TextfieldDefaultColor,
262     kColorId_TextfieldDefaultBackground,
263     kColorId_TextfieldReadOnlyColor,
264     kColorId_TextfieldReadOnlyBackground,
265     kColorId_TextfieldSelectionColor,
266     kColorId_TextfieldSelectionBackgroundFocused,
267     // Tree
268     kColorId_TreeBackground,
269     kColorId_TreeText,
270     kColorId_TreeSelectedText,
271     kColorId_TreeSelectedTextUnfocused,
272     kColorId_TreeSelectionBackgroundFocused,
273     kColorId_TreeSelectionBackgroundUnfocused,
274     kColorId_TreeArrow,
275     // Table
276     kColorId_TableBackground,
277     kColorId_TableText,
278     kColorId_TableSelectedText,
279     kColorId_TableSelectedTextUnfocused,
280     kColorId_TableSelectionBackgroundFocused,
281     kColorId_TableSelectionBackgroundUnfocused,
282     kColorId_TableGroupingIndicatorColor,
283     // TODO(benrg): move other hardcoded colors here.
284   };
285
286   // Return a color from the system theme.
287   virtual SkColor GetSystemColor(ColorId color_id) const = 0;
288
289   // Returns a shared instance of the native theme.
290   // The returned object should not be deleted by the caller.  This function
291   // is not thread safe and should only be called from the UI thread.
292   // Each port of NativeTheme should provide its own implementation of this
293   // function, returning the port's subclass.
294   static NativeTheme* instance();
295
296  protected:
297   NativeTheme();
298   virtual ~NativeTheme();
299
300   unsigned int thumb_inactive_color_;
301   unsigned int thumb_active_color_;
302   unsigned int track_color_;
303
304   DISALLOW_COPY_AND_ASSIGN(NativeTheme);
305 };
306
307 }  // namespace ui
308
309 #endif  // UI_NATIVE_THEME_NATIVE_THEME_H_