Add ICU message format support
[chromium-blink-merge.git] / ui / native_theme / native_theme.h
blob5cc5ea816cc955983ef75934890fa07dce871898
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"
13 class SkCanvas;
15 namespace gfx {
16 class Rect;
17 class Size;
20 namespace ui {
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
28 // possible.
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 {
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,
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,
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,
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,
96 // Each structure below holds extra information needed when painting a given
97 // part.
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;
109 struct InnerSpinButtonExtraParams {
110 bool spin_up;
111 bool read_only;
112 int classic_state; // Used on Windows when uxtheme is not available.
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;
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;
129 struct MenuItemExtraParams {
130 bool is_selected;
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.
142 struct MenuBackgroundExtraParams {
143 int corner_radius;
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;
155 struct ScrollbarArrowExtraParams {
156 bool is_hovering;
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.
168 struct ScrollbarThumbExtraParams {
169 bool is_hovering;
172 struct SliderExtraParams {
173 bool vertical;
174 bool in_drag;
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.
188 struct TrackbarExtraParams {
189 bool vertical;
190 int classic_state; // Used on Windows when uxtheme is not available.
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;
210 // Return the size of the part.
211 virtual gfx::Size GetPartSize(Part part,
212 State state,
213 const ExtraParams& extra) const = 0;
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;
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 { }
231 // Supports theme specific colors.
232 void SetScrollbarColors(unsigned inactive_color,
233 unsigned active_color,
234 unsigned track_color);
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 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 // Positive text refers to good (often rendered in green) text, such as the
318 // stock value went up.
319 kColorId_ResultsTablePositiveText,
320 kColorId_ResultsTablePositiveHoveredText,
321 kColorId_ResultsTablePositiveSelectedText,
322 // Negative text refers to something alarming (often rendered in red), such
323 // as the stock value went down.
324 kColorId_ResultsTableNegativeText,
325 kColorId_ResultsTableNegativeHoveredText,
326 kColorId_ResultsTableNegativeSelectedText,
327 // For MD icons.
328 kColorId_ChromeIconGrey,
329 kColorId_GoogleBlue,
330 // Colors for the material spinner (aka throbber).
331 kColorId_ThrobberSpinningColor,
332 kColorId_ThrobberWaitingColor,
333 kColorId_ThrobberLightColor,
334 // TODO(benrg): move other hardcoded colors here.
336 kColorId_NumColors,
339 // Return a color from the system theme.
340 virtual SkColor GetSystemColor(ColorId color_id) const = 0;
342 // Returns a shared instance of the native theme.
343 // The returned object should not be deleted by the caller. This function
344 // is not thread safe and should only be called from the UI thread.
345 // Each port of NativeTheme should provide its own implementation of this
346 // function, returning the port's subclass.
347 static NativeTheme* instance();
349 // Add or remove observers to be notified when the native theme changes.
350 void AddObserver(NativeThemeObserver* observer);
351 void RemoveObserver(NativeThemeObserver* observer);
353 // Notify observers of native theme changes.
354 void NotifyObservers();
356 protected:
357 NativeTheme();
358 virtual ~NativeTheme();
360 unsigned int thumb_inactive_color_;
361 unsigned int thumb_active_color_;
362 unsigned int track_color_;
364 private:
365 // Observers to notify when the native theme changes.
366 base::ObserverList<NativeThemeObserver> native_theme_observers_;
368 DISALLOW_COPY_AND_ASSIGN(NativeTheme);
371 } // namespace ui
373 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_