1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_NATIVE_THEME_NATIVE_THEME_H_
#define UI_NATIVE_THEME_NATIVE_THEME_H_
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/native_theme/native_theme_export.h"
class SkCanvas;
namespace gfx {
class Rect;
class Size;
}
namespace ui {
// This class supports drawing UI controls (like buttons, text fields, lists,
// comboboxes, etc) that look like the native UI controls of the underlying
// platform, such as Windows or Linux. It also supplies default colors for
// dialog box backgrounds, etc., which are obtained from the system theme where
// possible.
//
// The supported control types are listed in the Part enum. These parts can be
// in any state given by the State enum, where the actual definition of the
// state is part-specific. The supported colors are listed in the ColorId enum.
//
// Some parts require more information than simply the state in order to be
// drawn correctly, and this information is given to the Paint() method via the
// ExtraParams union. Each part that requires more information has its own
// field in the union.
//
// NativeTheme also supports getting the default size of a given part with
// the GetPartSize() method.
class NATIVE_THEME_EXPORT NativeTheme {
public:
// The part to be painted / sized.
enum Part {
kCheckbox,
kInnerSpinButton,
kMenuList,
kMenuCheck,
kMenuCheckBackground,
kMenuPopupArrow,
kMenuPopupBackground,
kMenuPopupGutter,
kMenuPopupSeparator,
kMenuItemBackground,
kProgressBar,
kPushButton,
kRadio,
// The order of the arrow enums is important, do not change without also
// changing the code in platform implementations.
kScrollbarDownArrow,
kScrollbarLeftArrow,
kScrollbarRightArrow,
kScrollbarUpArrow,
kScrollbarHorizontalThumb,
kScrollbarVerticalThumb,
kScrollbarHorizontalTrack,
kScrollbarVerticalTrack,
kScrollbarHorizontalGripper,
kScrollbarVerticalGripper,
kSliderTrack,
kSliderThumb,
kTabPanelBackground,
kTextField,
kTrackbarThumb,
kTrackbarTrack,
kWindowResizeGripper,
kMaxPart,
};
// The state of the part.
enum State {
kDisabled,
kHovered,
kNormal,
kPressed,
kMaxState,
};
// Each structure below holds extra information needed when painting a given
// part.
struct ButtonExtraParams {
bool checked;
bool indeterminate; // Whether the button state is indeterminate.
bool is_default; // Whether the button is default button.
bool is_focused;
bool has_border;
int classic_state; // Used on Windows when uxtheme is not available.
SkColor background_color;
};
struct InnerSpinButtonExtraParams {
bool spin_up;
bool read_only;
int classic_state; // Used on Windows when uxtheme is not available.
};
struct MenuArrowExtraParams {
bool pointing_right;
// Used for the disabled state to indicate if the item is both disabled and
// selected.
bool is_selected;
};
struct MenuCheckExtraParams {
bool is_radio;
// Used for the disabled state to indicate if the item is both disabled and
// selected.
bool is_selected;
};
struct MenuItemExtraParams {
bool is_selected;
};
struct MenuListExtraParams {
bool has_border;
bool has_border_radius;
int arrow_x;
int arrow_y;
SkColor background_color;
int classic_state; // Used on Windows when uxtheme is not available.
};
struct MenuSeparatorExtraParams {
bool has_gutter;
};
struct ProgressBarExtraParams {
double animated_seconds;
bool determinate;
int value_rect_x;
int value_rect_y;
int value_rect_width;
int value_rect_height;
};
struct ScrollbarArrowExtraParams {
bool is_hovering;
};
struct ScrollbarTrackExtraParams {
bool is_upper;
int track_x;
int track_y;
int track_width;
int track_height;
int classic_state; // Used on Windows when uxtheme is not available.
};
struct ScrollbarThumbExtraParams {
bool is_hovering;
};
struct SliderExtraParams {
bool vertical;
bool in_drag;
};
struct TextFieldExtraParams {
bool is_text_area;
bool is_listbox;
SkColor background_color;
bool is_read_only;
bool is_focused;
bool fill_content_area;
bool draw_edges;
int classic_state; // Used on Windows when uxtheme is not available.
};
struct TrackbarExtraParams {
bool vertical;
int classic_state; // Used on Windows when uxtheme is not available.
};
union ExtraParams {
ButtonExtraParams button;
InnerSpinButtonExtraParams inner_spin;
MenuArrowExtraParams menu_arrow;
MenuCheckExtraParams menu_check;
MenuItemExtraParams menu_item;
MenuListExtraParams menu_list;
MenuSeparatorExtraParams menu_separator;
ProgressBarExtraParams progress_bar;
ScrollbarArrowExtraParams scrollbar_arrow;
ScrollbarTrackExtraParams scrollbar_track;
ScrollbarThumbExtraParams scrollbar_thumb;
SliderExtraParams slider;
TextFieldExtraParams text_field;
TrackbarExtraParams trackbar;
};
// Return the size of the part.
virtual gfx::Size GetPartSize(Part part,
State state,
const ExtraParams& extra) const = 0;
// Paint the part to the canvas.
virtual void Paint(SkCanvas* canvas,
Part part,
State state,
const gfx::Rect& rect,
const ExtraParams& extra) const = 0;
// Supports theme specific colors.
void SetScrollbarColors(unsigned inactive_color,
unsigned active_color,
unsigned track_color);
// Colors for GetSystemColor().
enum ColorId {
// Windows
kColorId_WindowBackground,
// Dialogs
kColorId_DialogBackground,
// FocusableBorder
kColorId_FocusedBorderColor,
kColorId_UnfocusedBorderColor,
// TextButton
kColorId_TextButtonBackgroundColor,
kColorId_TextButtonEnabledColor,
kColorId_TextButtonDisabledColor,
kColorId_TextButtonHighlightColor,
kColorId_TextButtonHoverColor,
// MenuItem
kColorId_EnabledMenuItemForegroundColor,
kColorId_DisabledMenuItemForegroundColor,
kColorId_FocusedMenuItemBackgroundColor,
kColorId_MenuSeparatorColor,
kColorId_MenuBackgroundColor,
kColorId_MenuBorderColor,
// Label
kColorId_LabelEnabledColor,
kColorId_LabelDisabledColor,
kColorId_LabelBackgroundColor,
// Textfield
kColorId_TextfieldDefaultColor,
kColorId_TextfieldDefaultBackground,
kColorId_TextfieldReadOnlyColor,
kColorId_TextfieldReadOnlyBackground,
kColorId_TextfieldSelectionColor,
kColorId_TextfieldSelectionBackgroundFocused,
kColorId_TextfieldSelectionBackgroundUnfocused,
// Tree
kColorId_TreeBackground,
kColorId_TreeText,
kColorId_TreeSelectedText,
kColorId_TreeSelectedTextUnfocused,
kColorId_TreeSelectionBackgroundFocused,
kColorId_TreeSelectionBackgroundUnfocused,
kColorId_TreeArrow,
// Table
kColorId_TableBackground,
kColorId_TableText,
kColorId_TableSelectedText,
kColorId_TableSelectedTextUnfocused,
kColorId_TableSelectionBackgroundFocused,
kColorId_TableSelectionBackgroundUnfocused,
kColorId_TableGroupingIndicatorColor,
// TODO(benrg): move other hardcoded colors here.
};
// Return a color from the system theme.
virtual SkColor GetSystemColor(ColorId color_id) const = 0;
// Returns a shared instance of the native theme.
// The returned object should not be deleted by the caller. This function
// is not thread safe and should only be called from the UI thread.
// Each port of NativeTheme should provide its own implementation of this
// function, returning the port's subclass.
static NativeTheme* instance();
static bool IsNewMenuStyleEnabled();
protected:
NativeTheme();
virtual ~NativeTheme();
unsigned int thumb_inactive_color_;
unsigned int thumb_active_color_;
unsigned int track_color_;
DISALLOW_COPY_AND_ASSIGN(NativeTheme);
};
} // namespace ui
#endif // UI_NATIVE_THEME_NATIVE_THEME_H_
|