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> |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 const SkColor kTextButtonBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); | 42 const SkColor kTextButtonBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); |
43 const SkColor kTextButtonEnabledColor = SkColorSetRGB(6, 45, 117); | 43 const SkColor kTextButtonEnabledColor = SkColorSetRGB(6, 45, 117); |
44 const SkColor kTextButtonDisabledColor = SkColorSetRGB(161, 161, 146); | 44 const SkColor kTextButtonDisabledColor = SkColorSetRGB(161, 161, 146); |
45 const SkColor kTextButtonHighlightColor = SkColorSetARGB(200, 255, 255, 255); | 45 const SkColor kTextButtonHighlightColor = SkColorSetARGB(200, 255, 255, 255); |
46 const SkColor kTextButtonHoverColor = kTextButtonEnabledColor; | 46 const SkColor kTextButtonHoverColor = kTextButtonEnabledColor; |
47 // MenuItem: | 47 // MenuItem: |
48 const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor; | 48 const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor; |
49 const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor; | 49 const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor; |
50 const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(246, 249, 253); | 50 const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(246, 249, 253); |
51 const SkColor kMenuSeparatorColor = SkColorSetARGB(50, 0, 0, 0); | 51 const SkColor kMenuSeparatorColor = SkColorSetARGB(50, 0, 0, 0); |
52 // Label: | |
53 const SkColor kLabelEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); | |
54 const SkColor kLabelDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); | |
55 const SkColor kLabelBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); | |
56 // Textfield: | 52 // Textfield: |
57 const SkColor kTextfieldDefaultColor = SK_ColorBLACK; | |
58 const SkColor kTextfieldDefaultBackground = SK_ColorWHITE; | |
59 const SkColor kTextfieldSelectionColor = SK_ColorWHITE; | |
60 const SkColor kTextfieldSelectionBackgroundFocused = | |
61 SkColorSetRGB(0x1D, 0x90, 0xFF); | |
62 const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; | 53 const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; |
63 | 54 |
64 SkColor WinColorToSkColor(COLORREF color) { | 55 // Windows system color IDs cached and updated by the native theme. |
65 return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); | 56 const int kSystemColors[] = { |
66 } | 57 COLOR_3DFACE, |
| 58 COLOR_GRAYTEXT, |
| 59 COLOR_HIGHLIGHT, |
| 60 COLOR_HIGHLIGHTTEXT, |
| 61 COLOR_SCROLLBAR, |
| 62 COLOR_WINDOW, |
| 63 COLOR_WINDOWTEXT, |
| 64 }; |
67 | 65 |
68 void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { | 66 void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { |
69 // Create a 2x2 checkerboard pattern using the 3D face and highlight colors. | 67 // Create a 2x2 checkerboard pattern using the 3D face and highlight colors. |
70 SkColor face = skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)); | 68 const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE); |
71 SkColor highlight = skia::COLORREFToSkColor(GetSysColor(COLOR_3DHILIGHT)); | 69 const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT); |
72 SkColor buffer[] = { face, highlight, highlight, face }; | 70 SkColor buffer[] = { face, highlight, highlight, face }; |
73 // Confusing bit: we first create a temporary bitmap with our desired pattern, | 71 // Confusing bit: we first create a temporary bitmap with our desired pattern, |
74 // then copy it to another bitmap. The temporary bitmap doesn't take | 72 // then copy it to another bitmap. The temporary bitmap doesn't take |
75 // ownership of the pixel data, and so will point to garbage when this | 73 // ownership of the pixel data, and so will point to garbage when this |
76 // function returns. The copy will copy the pixel data into a place owned by | 74 // function returns. The copy will copy the pixel data into a place owned by |
77 // the bitmap, which is in turn owned by the shader, etc., so it will live | 75 // the bitmap, which is in turn owned by the shader, etc., so it will live |
78 // until we're done using it. | 76 // until we're done using it. |
79 SkBitmap temp_bitmap; | 77 SkBitmap temp_bitmap; |
80 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); | 78 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); |
81 temp_bitmap.setPixels(buffer); | 79 temp_bitmap.setPixels(buffer); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 return E_NOTIMPL; | 145 return E_NOTIMPL; |
148 } | 146 } |
149 | 147 |
150 SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme, | 148 SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme, |
151 int part_id, | 149 int part_id, |
152 int state_id, | 150 int state_id, |
153 int prop_id, | 151 int prop_id, |
154 int default_sys_color) const { | 152 int default_sys_color) const { |
155 SkColor color; | 153 SkColor color; |
156 if (GetThemeColor(theme, part_id, state_id, prop_id, &color) != S_OK) | 154 if (GetThemeColor(theme, part_id, state_id, prop_id, &color) != S_OK) |
157 color = skia::COLORREFToSkColor(GetSysColor(default_sys_color)); | 155 color = color_utils::GetSysSkColor(default_sys_color); |
158 return color; | 156 return color; |
159 } | 157 } |
160 | 158 |
161 gfx::Size NativeThemeWin::GetThemeBorderSize(ThemeName theme) const { | 159 gfx::Size NativeThemeWin::GetThemeBorderSize(ThemeName theme) const { |
162 // For simplicity use the wildcard state==0, part==0, since it works | 160 // For simplicity use the wildcard state==0, part==0, since it works |
163 // for the cases we currently depend on. | 161 // for the cases we currently depend on. |
164 int border; | 162 int border; |
165 if (GetThemeInt(theme, 0, 0, TMT_BORDERSIZE, &border) == S_OK) | 163 if (GetThemeInt(theme, 0, 0, TMT_BORDERSIZE, &border) == S_OK) |
166 return gfx::Size(border, border); | 164 return gfx::Size(border, border); |
167 else | 165 else |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 : theme_dll_(LoadLibrary(L"uxtheme.dll")), | 297 : theme_dll_(LoadLibrary(L"uxtheme.dll")), |
300 draw_theme_(NULL), | 298 draw_theme_(NULL), |
301 draw_theme_ex_(NULL), | 299 draw_theme_ex_(NULL), |
302 get_theme_color_(NULL), | 300 get_theme_color_(NULL), |
303 get_theme_content_rect_(NULL), | 301 get_theme_content_rect_(NULL), |
304 get_theme_part_size_(NULL), | 302 get_theme_part_size_(NULL), |
305 open_theme_(NULL), | 303 open_theme_(NULL), |
306 close_theme_(NULL), | 304 close_theme_(NULL), |
307 set_theme_properties_(NULL), | 305 set_theme_properties_(NULL), |
308 is_theme_active_(NULL), | 306 is_theme_active_(NULL), |
309 get_theme_int_(NULL) { | 307 get_theme_int_(NULL), |
| 308 ALLOW_THIS_IN_INITIALIZER_LIST(color_change_listener_(this)) { |
310 if (theme_dll_) { | 309 if (theme_dll_) { |
311 draw_theme_ = reinterpret_cast<DrawThemeBackgroundPtr>( | 310 draw_theme_ = reinterpret_cast<DrawThemeBackgroundPtr>( |
312 GetProcAddress(theme_dll_, "DrawThemeBackground")); | 311 GetProcAddress(theme_dll_, "DrawThemeBackground")); |
313 draw_theme_ex_ = reinterpret_cast<DrawThemeBackgroundExPtr>( | 312 draw_theme_ex_ = reinterpret_cast<DrawThemeBackgroundExPtr>( |
314 GetProcAddress(theme_dll_, "DrawThemeBackgroundEx")); | 313 GetProcAddress(theme_dll_, "DrawThemeBackgroundEx")); |
315 get_theme_color_ = reinterpret_cast<GetThemeColorPtr>( | 314 get_theme_color_ = reinterpret_cast<GetThemeColorPtr>( |
316 GetProcAddress(theme_dll_, "GetThemeColor")); | 315 GetProcAddress(theme_dll_, "GetThemeColor")); |
317 get_theme_content_rect_ = reinterpret_cast<GetThemeContentRectPtr>( | 316 get_theme_content_rect_ = reinterpret_cast<GetThemeContentRectPtr>( |
318 GetProcAddress(theme_dll_, "GetThemeBackgroundContentRect")); | 317 GetProcAddress(theme_dll_, "GetThemeBackgroundContentRect")); |
319 get_theme_part_size_ = reinterpret_cast<GetThemePartSizePtr>( | 318 get_theme_part_size_ = reinterpret_cast<GetThemePartSizePtr>( |
320 GetProcAddress(theme_dll_, "GetThemePartSize")); | 319 GetProcAddress(theme_dll_, "GetThemePartSize")); |
321 open_theme_ = reinterpret_cast<OpenThemeDataPtr>( | 320 open_theme_ = reinterpret_cast<OpenThemeDataPtr>( |
322 GetProcAddress(theme_dll_, "OpenThemeData")); | 321 GetProcAddress(theme_dll_, "OpenThemeData")); |
323 close_theme_ = reinterpret_cast<CloseThemeDataPtr>( | 322 close_theme_ = reinterpret_cast<CloseThemeDataPtr>( |
324 GetProcAddress(theme_dll_, "CloseThemeData")); | 323 GetProcAddress(theme_dll_, "CloseThemeData")); |
325 set_theme_properties_ = reinterpret_cast<SetThemeAppPropertiesPtr>( | 324 set_theme_properties_ = reinterpret_cast<SetThemeAppPropertiesPtr>( |
326 GetProcAddress(theme_dll_, "SetThemeAppProperties")); | 325 GetProcAddress(theme_dll_, "SetThemeAppProperties")); |
327 is_theme_active_ = reinterpret_cast<IsThemeActivePtr>( | 326 is_theme_active_ = reinterpret_cast<IsThemeActivePtr>( |
328 GetProcAddress(theme_dll_, "IsThemeActive")); | 327 GetProcAddress(theme_dll_, "IsThemeActive")); |
329 get_theme_int_ = reinterpret_cast<GetThemeIntPtr>( | 328 get_theme_int_ = reinterpret_cast<GetThemeIntPtr>( |
330 GetProcAddress(theme_dll_, "GetThemeInt")); | 329 GetProcAddress(theme_dll_, "GetThemeInt")); |
331 } | 330 } |
332 memset(theme_handles_, 0, sizeof(theme_handles_)); | 331 memset(theme_handles_, 0, sizeof(theme_handles_)); |
| 332 |
| 333 // Initialize the cached system colors. |
| 334 UpdateSystemColors(); |
333 } | 335 } |
334 | 336 |
335 NativeThemeWin::~NativeThemeWin() { | 337 NativeThemeWin::~NativeThemeWin() { |
336 if (theme_dll_) { | 338 if (theme_dll_) { |
337 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks | 339 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks |
338 // certain tests and the reliability bots. | 340 // certain tests and the reliability bots. |
339 // CloseHandles(); | 341 // CloseHandles(); |
340 FreeLibrary(theme_dll_); | 342 FreeLibrary(theme_dll_); |
341 } | 343 } |
342 } | 344 } |
343 | 345 |
| 346 void NativeThemeWin::OnSysColorChange() { |
| 347 UpdateSystemColors(); |
| 348 } |
| 349 |
| 350 void NativeThemeWin::UpdateSystemColors() { |
| 351 for (int i = 0; i < arraysize(kSystemColors); ++i) { |
| 352 system_colors_[kSystemColors[i]] = |
| 353 color_utils::GetSysSkColor(kSystemColors[i]); |
| 354 } |
| 355 } |
| 356 |
344 void NativeThemeWin::PaintDirect(SkCanvas* canvas, | 357 void NativeThemeWin::PaintDirect(SkCanvas* canvas, |
345 Part part, | 358 Part part, |
346 State state, | 359 State state, |
347 const gfx::Rect& rect, | 360 const gfx::Rect& rect, |
348 const ExtraParams& extra) const { | 361 const ExtraParams& extra) const { |
349 skia::ScopedPlatformPaint scoped_platform_paint(canvas); | 362 skia::ScopedPlatformPaint scoped_platform_paint(canvas); |
350 HDC hdc = scoped_platform_paint.GetPlatformSurface(); | 363 HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
351 | 364 |
352 switch (part) { | 365 switch (part) { |
353 case kCheckbox: | 366 case kCheckbox: |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 if (IsNewMenuStyleEnabled() && | 447 if (IsNewMenuStyleEnabled() && |
435 CommonThemeGetSystemColor(color_id, &color)) { | 448 CommonThemeGetSystemColor(color_id, &color)) { |
436 return color; | 449 return color; |
437 } | 450 } |
438 | 451 |
439 switch (color_id) { | 452 switch (color_id) { |
440 // Dialogs | 453 // Dialogs |
441 case kColorId_DialogBackground: | 454 case kColorId_DialogBackground: |
442 // TODO(benrg): Should this use the new Windows theme functions? The old | 455 // TODO(benrg): Should this use the new Windows theme functions? The old |
443 // code in DialogClientView::OnPaint used GetSysColor(COLOR_3DFACE). | 456 // code in DialogClientView::OnPaint used GetSysColor(COLOR_3DFACE). |
444 return WinColorToSkColor(GetSysColor(COLOR_3DFACE)); | 457 return system_colors_[COLOR_3DFACE]; |
445 | 458 |
446 // FocusableBorder | 459 // FocusableBorder |
447 case kColorId_FocusedBorderColor: | 460 case kColorId_FocusedBorderColor: |
448 return kFocusedBorderColor; | 461 return kFocusedBorderColor; |
449 case kColorId_UnfocusedBorderColor: | 462 case kColorId_UnfocusedBorderColor: |
450 return kUnfocusedBorderColor; | 463 return kUnfocusedBorderColor; |
451 | 464 |
452 // TextButton | 465 // TextButton |
453 case kColorId_TextButtonBackgroundColor: | 466 case kColorId_TextButtonBackgroundColor: |
454 return kTextButtonBackgroundColor; | 467 return kTextButtonBackgroundColor; |
(...skipping 11 matching lines...) Expand all Loading... |
466 return kEnabledMenuItemForegroundColor; | 479 return kEnabledMenuItemForegroundColor; |
467 case kColorId_DisabledMenuItemForegroundColor: | 480 case kColorId_DisabledMenuItemForegroundColor: |
468 return kDisabledMenuItemForegroundColor; | 481 return kDisabledMenuItemForegroundColor; |
469 case kColorId_FocusedMenuItemBackgroundColor: | 482 case kColorId_FocusedMenuItemBackgroundColor: |
470 return kFocusedMenuItemBackgroundColor; | 483 return kFocusedMenuItemBackgroundColor; |
471 case kColorId_MenuSeparatorColor: | 484 case kColorId_MenuSeparatorColor: |
472 return kMenuSeparatorColor; | 485 return kMenuSeparatorColor; |
473 | 486 |
474 // Label | 487 // Label |
475 case kColorId_LabelEnabledColor: | 488 case kColorId_LabelEnabledColor: |
476 return kLabelEnabledColor; | 489 return system_colors_[COLOR_WINDOWTEXT]; |
477 case kColorId_LabelDisabledColor: | 490 case kColorId_LabelDisabledColor: |
478 return kLabelDisabledColor; | 491 return system_colors_[COLOR_GRAYTEXT]; |
479 case kColorId_LabelBackgroundColor: | 492 case kColorId_LabelBackgroundColor: |
480 return kLabelBackgroundColor; | 493 return system_colors_[COLOR_WINDOW]; |
481 | 494 |
482 // Textfield | 495 // Textfield |
483 case kColorId_TextfieldDefaultColor: | 496 case kColorId_TextfieldDefaultColor: |
484 return kTextfieldDefaultColor; | 497 return system_colors_[COLOR_WINDOWTEXT]; |
485 case kColorId_TextfieldDefaultBackground: | 498 case kColorId_TextfieldDefaultBackground: |
486 return kTextfieldDefaultBackground; | 499 return system_colors_[COLOR_WINDOW]; |
| 500 case kColorId_TextfieldReadOnlyColor: |
| 501 return system_colors_[COLOR_GRAYTEXT]; |
| 502 case kColorId_TextfieldReadOnlyBackground: |
| 503 return system_colors_[COLOR_3DFACE]; |
487 case kColorId_TextfieldSelectionColor: | 504 case kColorId_TextfieldSelectionColor: |
488 return kTextfieldSelectionColor; | 505 return system_colors_[COLOR_HIGHLIGHTTEXT]; |
489 case kColorId_TextfieldSelectionBackgroundFocused: | 506 case kColorId_TextfieldSelectionBackgroundFocused: |
490 return kTextfieldSelectionBackgroundFocused; | 507 return system_colors_[COLOR_HIGHLIGHT]; |
491 case kColorId_TextfieldSelectionBackgroundUnfocused: | 508 case kColorId_TextfieldSelectionBackgroundUnfocused: |
492 return kTextfieldSelectionBackgroundUnfocused; | 509 return kTextfieldSelectionBackgroundUnfocused; |
493 | 510 |
494 default: | 511 default: |
495 NOTREACHED() << "Invalid color_id: " << color_id; | 512 NOTREACHED() << "Invalid color_id: " << color_id; |
496 break; | 513 break; |
497 } | 514 } |
498 return kInvalidColorIdColor; | 515 return kInvalidColorIdColor; |
499 } | 516 } |
500 | 517 |
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 break; | 1153 break; |
1137 default: | 1154 default: |
1138 NOTREACHED() << "Invalid state: " << state; | 1155 NOTREACHED() << "Invalid state: " << state; |
1139 break; | 1156 break; |
1140 } | 1157 } |
1141 | 1158 |
1142 if (handle && draw_theme_) | 1159 if (handle && draw_theme_) |
1143 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); | 1160 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); |
1144 | 1161 |
1145 // Draw it manually. | 1162 // Draw it manually. |
1146 const DWORD colorScrollbar = GetSysColor(COLOR_SCROLLBAR); | 1163 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && |
1147 const DWORD color3DFace = GetSysColor(COLOR_3DFACE); | 1164 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { |
1148 if ((colorScrollbar != color3DFace) && | |
1149 (colorScrollbar != GetSysColor(COLOR_WINDOW))) { | |
1150 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); | 1165 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); |
1151 } else { | 1166 } else { |
1152 SkPaint paint; | 1167 SkPaint paint; |
1153 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, | 1168 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, |
1154 extra.track_height).ToRECT(); | 1169 extra.track_height).ToRECT(); |
1155 SetCheckerboardShader(&paint, align_rect); | 1170 SetCheckerboardShader(&paint, align_rect); |
1156 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); | 1171 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); |
1157 } | 1172 } |
1158 if (extra.classic_state & DFCS_PUSHED) | 1173 if (extra.classic_state & DFCS_PUSHED) |
1159 InvertRect(hdc, &rect_win); | 1174 InvertRect(hdc, &rect_win); |
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1958 handle = open_theme_(NULL, L"Spin"); | 1973 handle = open_theme_(NULL, L"Spin"); |
1959 break; | 1974 break; |
1960 default: | 1975 default: |
1961 NOTREACHED(); | 1976 NOTREACHED(); |
1962 } | 1977 } |
1963 theme_handles_[theme_name] = handle; | 1978 theme_handles_[theme_name] = handle; |
1964 return handle; | 1979 return handle; |
1965 } | 1980 } |
1966 | 1981 |
1967 } // namespace ui | 1982 } // namespace ui |
OLD | NEW |