OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/native_theme/native_theme_win.h" | 5 #include "ui/native_theme/native_theme_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 #include <uxtheme.h> | 8 #include <uxtheme.h> |
9 #include <vsstyle.h> | 9 #include <vsstyle.h> |
10 #include <vssym32.h> | 10 #include <vssym32.h> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/memory/scoped_handle.h" | 14 #include "base/memory/scoped_handle.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/win/scoped_gdi_object.h" | 16 #include "base/win/scoped_gdi_object.h" |
17 #include "base/win/scoped_hdc.h" | 17 #include "base/win/scoped_hdc.h" |
18 #include "base/win/scoped_select_object.h" | 18 #include "base/win/scoped_select_object.h" |
19 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
20 #include "skia/ext/bitmap_platform_device.h" | 20 #include "skia/ext/bitmap_platform_device.h" |
21 #include "skia/ext/platform_canvas.h" | 21 #include "skia/ext/platform_canvas.h" |
22 #include "skia/ext/skia_utils_win.h" | 22 #include "skia/ext/skia_utils_win.h" |
23 #include "third_party/skia/include/core/SkCanvas.h" | 23 #include "third_party/skia/include/core/SkCanvas.h" |
24 #include "third_party/skia/include/core/SkColorPriv.h" | 24 #include "third_party/skia/include/core/SkColorPriv.h" |
25 #include "third_party/skia/include/core/SkShader.h" | 25 #include "third_party/skia/include/core/SkShader.h" |
26 #include "ui/gfx/color_utils.h" | 26 #include "ui/gfx/color_utils.h" |
27 #include "ui/gfx/gdi_util.h" | 27 #include "ui/gfx/gdi_util.h" |
28 #include "ui/gfx/rect.h" | 28 #include "ui/gfx/rect.h" |
29 #include "ui/gfx/rect_conversions.h" | 29 #include "ui/gfx/rect_conversions.h" |
30 #include "ui/gfx/sys_color_change_listener.h" | |
31 #include "ui/gfx/win/dpi.h" | 30 #include "ui/gfx/win/dpi.h" |
32 #include "ui/native_theme/common_theme.h" | 31 #include "ui/native_theme/common_theme.h" |
33 | 32 |
34 // This was removed from Winvers.h but is still used. | 33 // This was removed from Winvers.h but is still used. |
35 #if !defined(COLOR_MENUHIGHLIGHT) | 34 #if !defined(COLOR_MENUHIGHLIGHT) |
36 #define COLOR_MENUHIGHLIGHT 29 | 35 #define COLOR_MENUHIGHLIGHT 29 |
37 #endif | 36 #endif |
38 | 37 |
39 namespace { | 38 namespace { |
40 | 39 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 } | 204 } |
206 } | 205 } |
207 | 206 |
208 bool NativeThemeWin::IsClassicTheme(ThemeName name) const { | 207 bool NativeThemeWin::IsClassicTheme(ThemeName name) const { |
209 if (!theme_dll_) | 208 if (!theme_dll_) |
210 return true; | 209 return true; |
211 | 210 |
212 return !GetThemeHandle(name); | 211 return !GetThemeHandle(name); |
213 } | 212 } |
214 | 213 |
215 // TODO(sky): seems like we should default to NativeThemeWin, but that currently | |
216 // breaks a couple of tests (FocusTraversalTest.NormalTraversal in | |
217 // views_unittests). | |
218 #if !defined(USE_AURA) | |
219 // static | |
220 NativeTheme* NativeTheme::instance() { | |
221 return NativeThemeWin::instance(); | |
222 } | |
223 #endif | |
224 | |
225 // static | 214 // static |
226 NativeThemeWin* NativeThemeWin::instance() { | 215 NativeThemeWin* NativeThemeWin::instance() { |
227 CR_DEFINE_STATIC_LOCAL(NativeThemeWin, s_native_theme, ()); | 216 CR_DEFINE_STATIC_LOCAL(NativeThemeWin, s_native_theme, ()); |
228 return &s_native_theme; | 217 return &s_native_theme; |
229 } | 218 } |
230 | 219 |
231 gfx::Size NativeThemeWin::GetPartSize(Part part, | 220 gfx::Size NativeThemeWin::GetPartSize(Part part, |
232 State state, | 221 State state, |
233 const ExtraParams& extra) const { | 222 const ExtraParams& extra) const { |
234 gfx::Size part_size = CommonThemeGetPartSize(part, state, extra); | 223 gfx::Size part_size = CommonThemeGetPartSize(part, state, extra); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 break; | 326 break; |
338 } | 327 } |
339 } | 328 } |
340 | 329 |
341 if (needs_paint_indirect) | 330 if (needs_paint_indirect) |
342 PaintIndirect(canvas, part, state, rect, extra); | 331 PaintIndirect(canvas, part, state, rect, extra); |
343 else | 332 else |
344 PaintDirect(canvas, part, state, rect, extra); | 333 PaintDirect(canvas, part, state, rect, extra); |
345 } | 334 } |
346 | 335 |
| 336 void NativeThemeWin::OnSysColorChange() { |
| 337 UpdateSystemColors(); |
| 338 is_using_high_contrast_valid_ = false; |
| 339 NativeTheme::OnSysColorChange(); |
| 340 } |
| 341 |
347 NativeThemeWin::NativeThemeWin() | 342 NativeThemeWin::NativeThemeWin() |
348 : theme_dll_(LoadLibrary(L"uxtheme.dll")), | 343 : theme_dll_(LoadLibrary(L"uxtheme.dll")), |
349 draw_theme_(NULL), | 344 draw_theme_(NULL), |
350 draw_theme_ex_(NULL), | 345 draw_theme_ex_(NULL), |
351 get_theme_color_(NULL), | 346 get_theme_color_(NULL), |
352 get_theme_content_rect_(NULL), | 347 get_theme_content_rect_(NULL), |
353 get_theme_part_size_(NULL), | 348 get_theme_part_size_(NULL), |
354 open_theme_(NULL), | 349 open_theme_(NULL), |
355 close_theme_(NULL), | 350 close_theme_(NULL), |
356 set_theme_properties_(NULL), | 351 set_theme_properties_(NULL), |
357 is_theme_active_(NULL), | 352 is_theme_active_(NULL), |
358 get_theme_int_(NULL), | 353 get_theme_int_(NULL), |
359 color_change_listener_(this), | |
360 is_using_high_contrast_(false), | 354 is_using_high_contrast_(false), |
361 is_using_high_contrast_valid_(false) { | 355 is_using_high_contrast_valid_(false) { |
362 if (theme_dll_) { | 356 if (theme_dll_) { |
363 draw_theme_ = reinterpret_cast<DrawThemeBackgroundPtr>( | 357 draw_theme_ = reinterpret_cast<DrawThemeBackgroundPtr>( |
364 GetProcAddress(theme_dll_, "DrawThemeBackground")); | 358 GetProcAddress(theme_dll_, "DrawThemeBackground")); |
365 draw_theme_ex_ = reinterpret_cast<DrawThemeBackgroundExPtr>( | 359 draw_theme_ex_ = reinterpret_cast<DrawThemeBackgroundExPtr>( |
366 GetProcAddress(theme_dll_, "DrawThemeBackgroundEx")); | 360 GetProcAddress(theme_dll_, "DrawThemeBackgroundEx")); |
367 get_theme_color_ = reinterpret_cast<GetThemeColorPtr>( | 361 get_theme_color_ = reinterpret_cast<GetThemeColorPtr>( |
368 GetProcAddress(theme_dll_, "GetThemeColor")); | 362 GetProcAddress(theme_dll_, "GetThemeColor")); |
369 get_theme_content_rect_ = reinterpret_cast<GetThemeContentRectPtr>( | 363 get_theme_content_rect_ = reinterpret_cast<GetThemeContentRectPtr>( |
(...skipping 19 matching lines...) Expand all Loading... |
389 | 383 |
390 NativeThemeWin::~NativeThemeWin() { | 384 NativeThemeWin::~NativeThemeWin() { |
391 if (theme_dll_) { | 385 if (theme_dll_) { |
392 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks | 386 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks |
393 // certain tests and the reliability bots. | 387 // certain tests and the reliability bots. |
394 // CloseHandles(); | 388 // CloseHandles(); |
395 FreeLibrary(theme_dll_); | 389 FreeLibrary(theme_dll_); |
396 } | 390 } |
397 } | 391 } |
398 | 392 |
399 void NativeThemeWin::OnSysColorChange() { | |
400 UpdateSystemColors(); | |
401 is_using_high_contrast_valid_ = false; | |
402 } | |
403 | |
404 void NativeThemeWin::UpdateSystemColors() { | 393 void NativeThemeWin::UpdateSystemColors() { |
405 for (int i = 0; i < arraysize(kSystemColors); ++i) { | 394 for (int i = 0; i < arraysize(kSystemColors); ++i) { |
406 system_colors_[kSystemColors[i]] = | 395 system_colors_[kSystemColors[i]] = |
407 color_utils::GetSysSkColor(kSystemColors[i]); | 396 color_utils::GetSysSkColor(kSystemColors[i]); |
408 } | 397 } |
409 } | 398 } |
410 | 399 |
411 void NativeThemeWin::PaintDirect(SkCanvas* canvas, | 400 void NativeThemeWin::PaintDirect(SkCanvas* canvas, |
412 Part part, | 401 Part part, |
413 State state, | 402 State state, |
(...skipping 1736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2150 handle = open_theme_(NULL, L"Spin"); | 2139 handle = open_theme_(NULL, L"Spin"); |
2151 break; | 2140 break; |
2152 default: | 2141 default: |
2153 NOTREACHED(); | 2142 NOTREACHED(); |
2154 } | 2143 } |
2155 theme_handles_[theme_name] = handle; | 2144 theme_handles_[theme_name] = handle; |
2156 return handle; | 2145 return handle; |
2157 } | 2146 } |
2158 | 2147 |
2159 } // namespace ui | 2148 } // namespace ui |
OLD | NEW |