Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: ui/native_theme/native_theme_win.h

Issue 703753005: More Windows build fixes. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: remove generated files Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/remote_window_tree_host_win.cc ('k') | ui/native_theme/native_theme_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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_WIN_H_
6 #define UI_NATIVE_THEME_NATIVE_THEME_WIN_H_
7
8 // A wrapper class for working with custom XP/Vista themes provided in
9 // uxtheme.dll. This is a singleton class that can be grabbed using
10 // NativeThemeWin::instance().
11 // For more information on visual style parts and states, see:
12 // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/plat form/commctls/userex/topics/partsandstates.asp
13
14 #include <map>
15
16 #include <windows.h>
17 #include <uxtheme.h>
18
19 #include "base/basictypes.h"
20 #include "base/compiler_specific.h"
21 #include "third_party/skia/include/core/SkColor.h"
22 #include "ui/gfx/size.h"
23 #include "ui/gfx/sys_color_change_listener.h"
24 #include "ui/native_theme/native_theme.h"
25
26 class SkCanvas;
27
28 namespace ui {
29
30 // Windows implementation of native theme class.
31 //
32 // At the moment, this class in in transition from an older API that consists
33 // of several PaintXXX methods to an API, inherited from the NativeTheme base
34 // class, that consists of a single Paint() method with a argument to indicate
35 // what kind of part to paint.
36 class NATIVE_THEME_EXPORT NativeThemeWin : public NativeTheme,
37 public gfx::SysColorChangeListener {
38 public:
39 enum ThemeName {
40 BUTTON,
41 LIST,
42 MENU,
43 MENULIST,
44 SCROLLBAR,
45 STATUS,
46 TAB,
47 TEXTFIELD,
48 TRACKBAR,
49 WINDOW,
50 PROGRESS,
51 SPIN,
52 LAST
53 };
54
55 bool IsThemingActive() const;
56
57 // Returns true if a high contrast theme is being used.
58 bool IsUsingHighContrastTheme() const;
59
60 HRESULT GetThemeColor(ThemeName theme,
61 int part_id,
62 int state_id,
63 int prop_id,
64 SkColor* color) const;
65
66 // Get the theme color if theming is enabled. If theming is unsupported
67 // for this part, use Win32's GetSysColor to find the color specified
68 // by default_sys_color.
69 SkColor GetThemeColorWithDefault(ThemeName theme,
70 int part_id,
71 int state_id,
72 int prop_id,
73 int default_sys_color) const;
74
75 // Get the thickness of the border associated with the specified theme,
76 // defaulting to GetSystemMetrics edge size if themes are disabled.
77 // In Classic Windows, borders are typically 2px; on XP+, they are 1px.
78 gfx::Size GetThemeBorderSize(ThemeName theme) const;
79
80 // Disables all theming for top-level windows in the entire process, from
81 // when this method is called until the process exits. All the other
82 // methods in this class will continue to work, but their output will ignore
83 // the user's theme. This is meant for use when running tests that require
84 // consistent visual results.
85 void DisableTheming() const;
86
87 // Closes cached theme handles so we can unload the DLL or update our UI
88 // for a theme change.
89 void CloseHandles() const;
90
91 // Returns true if classic theme is in use.
92 bool IsClassicTheme(ThemeName name) const;
93
94 // Gets our singleton instance.
95 static NativeThemeWin* instance();
96
97 HRESULT PaintTextField(HDC hdc,
98 int part_id,
99 int state_id,
100 int classic_state,
101 RECT* rect,
102 COLORREF color,
103 bool fill_content_area,
104 bool draw_edges) const;
105
106 // NativeTheme implementation:
107 virtual gfx::Size GetPartSize(Part part,
108 State state,
109 const ExtraParams& extra) const override;
110 virtual void Paint(SkCanvas* canvas,
111 Part part,
112 State state,
113 const gfx::Rect& rect,
114 const ExtraParams& extra) const override;
115 virtual SkColor GetSystemColor(ColorId color_id) const override;
116
117 private:
118 NativeThemeWin();
119 ~NativeThemeWin();
120
121 // gfx::SysColorChangeListener implementation:
122 virtual void OnSysColorChange() override;
123
124 // Update the locally cached set of system colors.
125 void UpdateSystemColors();
126
127 // Paint directly to canvas' HDC.
128 void PaintDirect(SkCanvas* canvas,
129 Part part,
130 State state,
131 const gfx::Rect& rect,
132 const ExtraParams& extra) const;
133
134 // Create a temporary HDC, paint to that, clean up the alpha values in the
135 // temporary HDC, and then blit the result to canvas. This is to work around
136 // the fact that Windows XP and some classic themes give bogus alpha values.
137 void PaintIndirect(SkCanvas* canvas,
138 Part part,
139 State state,
140 const gfx::Rect& rect,
141 const ExtraParams& extra) const;
142
143 HRESULT GetThemePartSize(ThemeName themeName,
144 HDC hdc,
145 int part_id,
146 int state_id,
147 RECT* rect,
148 int ts,
149 SIZE* size) const;
150
151 HRESULT PaintButton(HDC hdc,
152 State state,
153 const ButtonExtraParams& extra,
154 int part_id,
155 int state_id,
156 RECT* rect) const;
157
158 HRESULT PaintMenuSeparator(HDC hdc,
159 const gfx::Rect& rect) const;
160
161 HRESULT PaintMenuGutter(HDC hdc, const gfx::Rect& rect) const;
162
163 // |arrow_direction| determines whether the arrow is pointing to the left or
164 // to the right. In RTL locales, sub-menus open from right to left and
165 // therefore the menu arrow should point to the left and not to the right.
166 HRESULT PaintMenuArrow(HDC hdc,
167 State state,
168 const gfx::Rect& rect,
169 const MenuArrowExtraParams& extra) const;
170
171 HRESULT PaintMenuBackground(HDC hdc, const gfx::Rect& rect) const;
172
173 HRESULT PaintMenuCheck(HDC hdc,
174 State state,
175 const gfx::Rect& rect,
176 const MenuCheckExtraParams& extra) const;
177
178 HRESULT PaintMenuCheckBackground(HDC hdc,
179 State state,
180 const gfx::Rect& rect) const;
181
182 HRESULT PaintMenuItemBackground(HDC hdc,
183 State state,
184 const gfx::Rect& rect,
185 const MenuItemExtraParams& extra) const;
186
187 HRESULT PaintPushButton(HDC hdc,
188 Part part,
189 State state,
190 const gfx::Rect& rect,
191 const ButtonExtraParams& extra) const;
192
193 HRESULT PaintRadioButton(HDC hdc,
194 Part part,
195 State state,
196 const gfx::Rect& rect,
197 const ButtonExtraParams& extra) const;
198
199 HRESULT PaintCheckbox(HDC hdc,
200 Part part,
201 State state,
202 const gfx::Rect& rect,
203 const ButtonExtraParams& extra) const;
204
205 HRESULT PaintMenuList(HDC hdc,
206 State state,
207 const gfx::Rect& rect,
208 const MenuListExtraParams& extra) const;
209
210 // Paints a scrollbar arrow. |classic_state| should have the appropriate
211 // classic part number ORed in already.
212 HRESULT PaintScrollbarArrow(HDC hdc,
213 Part part,
214 State state,
215 const gfx::Rect& rect,
216 const ScrollbarArrowExtraParams& extra) const;
217
218 HRESULT PaintScrollbarThumb(HDC hdc,
219 Part part,
220 State state,
221 const gfx::Rect& rect,
222 const ScrollbarThumbExtraParams& extra) const;
223
224 // This method is deprecated and will be removed in the near future.
225 // Paints a scrollbar track section. |align_rect| is only used in classic
226 // mode, and makes sure the checkerboard pattern in |target_rect| is aligned
227 // with one presumed to be in |align_rect|.
228 HRESULT PaintScrollbarTrack(SkCanvas* canvas,
229 HDC hdc,
230 Part part,
231 State state,
232 const gfx::Rect& rect,
233 const ScrollbarTrackExtraParams& extra) const;
234
235 HRESULT PaintSpinButton(HDC hdc,
236 Part part,
237 State state,
238 const gfx::Rect& rect,
239 const InnerSpinButtonExtraParams& extra) const;
240
241 HRESULT PaintTrackbar(SkCanvas* canvas,
242 HDC hdc,
243 Part part,
244 State state,
245 const gfx::Rect& rect,
246 const TrackbarExtraParams& extra) const;
247
248 HRESULT PaintProgressBar(HDC hdc,
249 const gfx::Rect& rect,
250 const ProgressBarExtraParams& extra) const;
251
252 HRESULT PaintWindowResizeGripper(HDC hdc, const gfx::Rect& rect) const;
253
254 HRESULT PaintTabPanelBackground(HDC hdc, const gfx::Rect& rect) const;
255
256 HRESULT PaintTextField(HDC hdc,
257 Part part,
258 State state,
259 const gfx::Rect& rect,
260 const TextFieldExtraParams& extra) const;
261
262 // Paints a theme part, with support for scene scaling in high-DPI mode.
263 // |theme| is the theme handle. |hdc| is the handle for the device context.
264 // |part_id| is the identifier for the part (e.g. thumb gripper). |state_id|
265 // is the identifier for the rendering state of the part (e.g. hover). |rect|
266 // is the bounds for rendering, expressed in logical coordinates.
267 HRESULT PaintScaledTheme(HANDLE theme,
268 HDC hdc,
269 int part_id,
270 int state_id,
271 const gfx::Rect& rect) const;
272
273 // Get the windows theme name/part/state. These three helper functions are
274 // used only by GetPartSize(), as each of the corresponding PaintXXX()
275 // methods do further validation of the part and state that is required for
276 // getting the size.
277 static ThemeName GetThemeName(Part part);
278 static int GetWindowsPart(Part part, State state, const ExtraParams& extra);
279 static int GetWindowsState(Part part, State state, const ExtraParams& extra);
280
281 HRESULT GetThemeInt(ThemeName theme,
282 int part_id,
283 int state_id,
284 int prop_id,
285 int *result) const;
286
287 HRESULT PaintFrameControl(HDC hdc,
288 const gfx::Rect& rect,
289 UINT type,
290 UINT state,
291 bool is_selected,
292 State control_state) const;
293
294 // Returns a handle to the theme data.
295 HANDLE GetThemeHandle(ThemeName theme_name) const;
296
297 typedef HRESULT (WINAPI* DrawThemeBackgroundPtr)(HANDLE theme,
298 HDC hdc,
299 int part_id,
300 int state_id,
301 const RECT* rect,
302 const RECT* clip_rect);
303 typedef HRESULT (WINAPI* DrawThemeBackgroundExPtr)(HANDLE theme,
304 HDC hdc,
305 int part_id,
306 int state_id,
307 const RECT* rect,
308 const DTBGOPTS* opts);
309 typedef HRESULT (WINAPI* GetThemeColorPtr)(HANDLE hTheme,
310 int part_id,
311 int state_id,
312 int prop_id,
313 COLORREF* color);
314 typedef HRESULT (WINAPI* GetThemeContentRectPtr)(HANDLE hTheme,
315 HDC hdc,
316 int part_id,
317 int state_id,
318 const RECT* rect,
319 RECT* content_rect);
320 typedef HRESULT (WINAPI* GetThemePartSizePtr)(HANDLE hTheme,
321 HDC hdc,
322 int part_id,
323 int state_id,
324 RECT* rect,
325 int ts,
326 SIZE* size);
327 typedef HANDLE (WINAPI* OpenThemeDataPtr)(HWND window,
328 LPCWSTR class_list);
329 typedef HRESULT (WINAPI* CloseThemeDataPtr)(HANDLE theme);
330
331 typedef void (WINAPI* SetThemeAppPropertiesPtr) (DWORD flags);
332 typedef BOOL (WINAPI* IsThemeActivePtr)();
333 typedef HRESULT (WINAPI* GetThemeIntPtr)(HANDLE hTheme,
334 int part_id,
335 int state_id,
336 int prop_id,
337 int *value);
338
339 // Function pointers into uxtheme.dll.
340 DrawThemeBackgroundPtr draw_theme_;
341 DrawThemeBackgroundExPtr draw_theme_ex_;
342 GetThemeColorPtr get_theme_color_;
343 GetThemeContentRectPtr get_theme_content_rect_;
344 GetThemePartSizePtr get_theme_part_size_;
345 OpenThemeDataPtr open_theme_;
346 CloseThemeDataPtr close_theme_;
347 SetThemeAppPropertiesPtr set_theme_properties_;
348 IsThemeActivePtr is_theme_active_;
349 GetThemeIntPtr get_theme_int_;
350
351 // Handle to uxtheme.dll.
352 HMODULE theme_dll_;
353
354 // A cache of open theme handles.
355 mutable HANDLE theme_handles_[LAST];
356
357 // The system color change listener and the updated cache of system colors.
358 gfx::ScopedSysColorChangeListener color_change_listener_;
359 mutable std::map<int, SkColor> system_colors_;
360
361 // Is a high contrast theme active?
362 mutable bool is_using_high_contrast_;
363
364 // Is |is_using_high_contrast_| valid?
365 mutable bool is_using_high_contrast_valid_;
366
367 DISALLOW_COPY_AND_ASSIGN(NativeThemeWin);
368 };
369
370 } // namespace ui
371
372 #endif // UI_NATIVE_THEME_NATIVE_THEME_WIN_H_
OLDNEW
« no previous file with comments | « ui/aura/remote_window_tree_host_win.cc ('k') | ui/native_theme/native_theme_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698