Fix cert DB usage in PolicyCertVerifier test.
[chromium-blink-merge.git] / ui / native_theme / native_theme.h
blob23f8d5a95f7f33bb8c327b3cb38eb1cacfa0e549
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 MenuSeparatorExtraParams {
143 bool has_gutter;
146 struct MenuBackgroundExtraParams {
147 int corner_radius;
150 struct ProgressBarExtraParams {
151 double animated_seconds;
152 bool determinate;
153 int value_rect_x;
154 int value_rect_y;
155 int value_rect_width;
156 int value_rect_height;
159 struct ScrollbarArrowExtraParams {
160 bool is_hovering;
163 struct ScrollbarTrackExtraParams {
164 bool is_upper;
165 int track_x;
166 int track_y;
167 int track_width;
168 int track_height;
169 int classic_state; // Used on Windows when uxtheme is not available.
172 struct ScrollbarThumbExtraParams {
173 bool is_hovering;
176 struct SliderExtraParams {
177 bool vertical;
178 bool in_drag;
181 struct TextFieldExtraParams {
182 bool is_text_area;
183 bool is_listbox;
184 SkColor background_color;
185 bool is_read_only;
186 bool is_focused;
187 bool fill_content_area;
188 bool draw_edges;
189 int classic_state; // Used on Windows when uxtheme is not available.
192 struct TrackbarExtraParams {
193 bool vertical;
194 int classic_state; // Used on Windows when uxtheme is not available.
197 union ExtraParams {
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,
217 State state,
218 const ExtraParams& extra) const = 0;
220 // Paint the part to the canvas.
221 virtual void Paint(SkCanvas* canvas,
222 Part part,
223 State state,
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,
230 Part part,
231 State startState,
232 State endState,
233 double progress,
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().
242 enum ColorId {
243 // Windows
244 kColorId_WindowBackground,
245 // Dialogs
246 kColorId_DialogBackground,
247 // FocusableBorder
248 kColorId_FocusedBorderColor,
249 kColorId_UnfocusedBorderColor,
250 // Button
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,
262 // MenuItem
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,
276 // Label
277 kColorId_LabelEnabledColor,
278 kColorId_LabelDisabledColor,
279 kColorId_LabelBackgroundColor,
280 // Textfield
281 kColorId_TextfieldDefaultColor,
282 kColorId_TextfieldDefaultBackground,
283 kColorId_TextfieldReadOnlyColor,
284 kColorId_TextfieldReadOnlyBackground,
285 kColorId_TextfieldSelectionColor,
286 kColorId_TextfieldSelectionBackgroundFocused,
287 // Tooltip
288 kColorId_TooltipBackground,
289 kColorId_TooltipText,
290 // Tree
291 kColorId_TreeBackground,
292 kColorId_TreeText,
293 kColorId_TreeSelectedText,
294 kColorId_TreeSelectedTextUnfocused,
295 kColorId_TreeSelectionBackgroundFocused,
296 kColorId_TreeSelectionBackgroundUnfocused,
297 kColorId_TreeArrow,
298 // Table
299 kColorId_TableBackground,
300 kColorId_TableText,
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.
325 // Return a color from the system theme.
326 virtual SkColor GetSystemColor(ColorId color_id) const = 0;
328 // Returns a shared instance of the native theme.
329 // The returned object should not be deleted by the caller. This function
330 // is not thread safe and should only be called from the UI thread.
331 // Each port of NativeTheme should provide its own implementation of this
332 // function, returning the port's subclass.
333 static NativeTheme* instance();
335 // Add or remove observers to be notified when the native theme changes.
336 void AddObserver(NativeThemeObserver* observer);
337 void RemoveObserver(NativeThemeObserver* observer);
339 // Notify observers of native theme changes.
340 void NotifyObservers();
342 protected:
343 NativeTheme();
344 virtual ~NativeTheme();
346 unsigned int thumb_inactive_color_;
347 unsigned int thumb_active_color_;
348 unsigned int track_color_;
350 private:
351 // Observers to notify when the native theme changes.
352 ObserverList<NativeThemeObserver> native_theme_observers_;
354 DISALLOW_COPY_AND_ASSIGN(NativeTheme);
357 } // namespace ui
359 #endif // UI_NATIVE_THEME_NATIVE_THEME_H_