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 #include "ui/native_theme/native_theme_win.h"
12 #include "base/basictypes.h"
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/win/scoped_gdi_object.h"
16 #include "base/win/scoped_hdc.h"
17 #include "base/win/scoped_select_object.h"
18 #include "base/win/windows_version.h"
19 #include "skia/ext/bitmap_platform_device.h"
20 #include "skia/ext/platform_canvas.h"
21 #include "skia/ext/skia_utils_win.h"
22 #include "third_party/skia/include/core/SkCanvas.h"
23 #include "third_party/skia/include/core/SkColor.h"
24 #include "third_party/skia/include/core/SkColorPriv.h"
25 #include "third_party/skia/include/core/SkShader.h"
26 #include "ui/gfx/color_utils.h"
27 #include "ui/gfx/gdi_util.h"
28 #include "ui/gfx/geometry/rect.h"
29 #include "ui/gfx/geometry/rect_conversions.h"
30 #include "ui/gfx/win/dpi.h"
31 #include "ui/native_theme/common_theme.h"
33 // This was removed from Winvers.h but is still used.
34 #if !defined(COLOR_MENUHIGHLIGHT)
35 #define COLOR_MENUHIGHLIGHT 29
40 // Windows system color IDs cached and updated by the native theme.
41 const int kSystemColors
[] = {
54 void SetCheckerboardShader(SkPaint
* paint
, const RECT
& align_rect
) {
55 // Create a 2x2 checkerboard pattern using the 3D face and highlight colors.
56 const SkColor face
= color_utils::GetSysSkColor(COLOR_3DFACE
);
57 const SkColor highlight
= color_utils::GetSysSkColor(COLOR_3DHILIGHT
);
58 SkColor buffer
[] = { face
, highlight
, highlight
, face
};
59 // Confusing bit: we first create a temporary bitmap with our desired pattern,
60 // then copy it to another bitmap. The temporary bitmap doesn't take
61 // ownership of the pixel data, and so will point to garbage when this
62 // function returns. The copy will copy the pixel data into a place owned by
63 // the bitmap, which is in turn owned by the shader, etc., so it will live
64 // until we're done using it.
65 SkImageInfo info
= SkImageInfo::MakeN32Premul(2, 2);
67 temp_bitmap
.installPixels(info
, buffer
, info
.minRowBytes());
69 temp_bitmap
.copyTo(&bitmap
);
71 // Align the pattern with the upper corner of |align_rect|.
72 SkMatrix local_matrix
;
73 local_matrix
.setTranslate(SkIntToScalar(align_rect
.left
),
74 SkIntToScalar(align_rect
.top
));
75 skia::RefPtr
<SkShader
> shader
=
76 skia::AdoptRef(SkShader::CreateBitmapShader(bitmap
,
77 SkShader::kRepeat_TileMode
,
78 SkShader::kRepeat_TileMode
,
80 paint
->setShader(shader
.get());
86 // <-a-> <------b----->
89 // *: animating object
91 // - the animation goes from "[" to "]" repeatedly.
92 // - the animation offset is at first "|"
94 int ComputeAnimationProgress(int frame_width
,
96 int pixels_per_second
,
97 double animated_seconds
) {
98 int animation_width
= frame_width
+ object_width
;
99 double interval
= static_cast<double>(animation_width
) / pixels_per_second
;
100 double ratio
= fmod(animated_seconds
, interval
) / interval
;
101 return static_cast<int>(animation_width
* ratio
) - object_width
;
104 RECT
InsetRect(const RECT
* rect
, int size
) {
105 gfx::Rect
result(*rect
);
106 result
.Inset(size
, size
);
107 return result
.ToRECT();
114 bool NativeThemeWin::IsThemingActive() const {
115 return is_theme_active_
&& is_theme_active_();
118 bool NativeThemeWin::IsUsingHighContrastTheme() const {
119 if (is_using_high_contrast_valid_
)
120 return is_using_high_contrast_
;
122 result
.cbSize
= sizeof(HIGHCONTRAST
);
123 is_using_high_contrast_
=
124 SystemParametersInfo(SPI_GETHIGHCONTRAST
, result
.cbSize
, &result
, 0) &&
125 (result
.dwFlags
& HCF_HIGHCONTRASTON
) == HCF_HIGHCONTRASTON
;
126 is_using_high_contrast_valid_
= true;
127 return is_using_high_contrast_
;
130 HRESULT
NativeThemeWin::GetThemeColor(ThemeName theme
,
134 SkColor
* color
) const {
135 HANDLE handle
= GetThemeHandle(theme
);
136 if (!handle
|| !get_theme_color_
)
139 if (get_theme_color_(handle
, part_id
, state_id
, prop_id
, &color_ref
) != S_OK
)
141 *color
= skia::COLORREFToSkColor(color_ref
);
145 SkColor
NativeThemeWin::GetThemeColorWithDefault(ThemeName theme
,
149 int default_sys_color
) const {
151 return (GetThemeColor(theme
, part_id
, state_id
, prop_id
, &color
) == S_OK
) ?
152 color
: color_utils::GetSysSkColor(default_sys_color
);
155 gfx::Size
NativeThemeWin::GetThemeBorderSize(ThemeName theme
) const {
156 // For simplicity use the wildcard state==0, part==0, since it works
157 // for the cases we currently depend on.
159 return (GetThemeInt(theme
, 0, 0, TMT_BORDERSIZE
, &border
) == S_OK
) ?
160 gfx::Size(border
, border
) :
161 gfx::Size(GetSystemMetrics(SM_CXEDGE
), GetSystemMetrics(SM_CYEDGE
));
164 void NativeThemeWin::DisableTheming() const {
165 if (set_theme_properties_
)
166 set_theme_properties_(0);
169 void NativeThemeWin::CloseHandles() const {
173 for (int i
= 0; i
< LAST
; ++i
) {
174 if (theme_handles_
[i
]) {
175 close_theme_(theme_handles_
[i
]);
176 theme_handles_
[i
] = NULL
;
181 bool NativeThemeWin::IsClassicTheme(ThemeName name
) const {
182 return !theme_dll_
|| !GetThemeHandle(name
);
186 NativeThemeWin
* NativeThemeWin::instance() {
187 CR_DEFINE_STATIC_LOCAL(NativeThemeWin
, s_native_theme
, ());
188 return &s_native_theme
;
191 gfx::Size
NativeThemeWin::GetPartSize(Part part
,
193 const ExtraParams
& extra
) const {
194 gfx::Size part_size
= CommonThemeGetPartSize(part
, state
, extra
);
195 if (!part_size
.IsEmpty())
198 // The GetThemePartSize call below returns the default size without
199 // accounting for user customization (crbug/218291).
201 case kScrollbarDownArrow
:
202 case kScrollbarLeftArrow
:
203 case kScrollbarRightArrow
:
204 case kScrollbarUpArrow
:
205 case kScrollbarHorizontalThumb
:
206 case kScrollbarVerticalThumb
:
207 case kScrollbarHorizontalTrack
:
208 case kScrollbarVerticalTrack
: {
209 int size
= gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL
);
212 return gfx::Size(size
, size
);
218 int part_id
= GetWindowsPart(part
, state
, extra
);
219 int state_id
= GetWindowsState(part
, state
, extra
);
221 base::win::ScopedGetDC
screen_dc(NULL
);
223 if (SUCCEEDED(GetThemePartSize(GetThemeName(part
), screen_dc
, part_id
,
224 state_id
, NULL
, TS_TRUE
, &size
)))
225 return gfx::Size(size
.cx
, size
.cy
);
227 // TODO(rogerta): For now, we need to support radio buttons and checkboxes
228 // when theming is not enabled. Support for other parts can be added
230 return (part
== kCheckbox
|| part
== kRadio
) ?
231 gfx::Size(13, 13) : gfx::Size();
234 void NativeThemeWin::Paint(SkCanvas
* canvas
,
237 const gfx::Rect
& rect
,
238 const ExtraParams
& extra
) const {
244 CommonThemePaintComboboxArrow(canvas
, rect
);
246 case kMenuPopupGutter
:
247 CommonThemePaintMenuGutter(canvas
, rect
);
249 case kMenuPopupSeparator
:
250 CommonThemePaintMenuSeparator(canvas
, rect
);
252 case kMenuPopupBackground
:
253 CommonThemePaintMenuBackground(canvas
, rect
);
255 case kMenuItemBackground
:
256 CommonThemePaintMenuItemBackground(canvas
, state
, rect
);
262 bool needs_paint_indirect
= false;
263 if (!skia::SupportsPlatformPaint(canvas
)) {
264 // This block will only get hit with --enable-accelerated-drawing flag.
265 needs_paint_indirect
= true;
267 // Scrollbar components on Windows Classic theme (on all Windows versions)
268 // have particularly problematic alpha values, so always draw them
269 // indirectly. In addition, scrollbar thumbs and grippers for the Windows XP
270 // theme (available only on Windows XP) also need their alpha values
273 case kScrollbarDownArrow
:
274 case kScrollbarUpArrow
:
275 case kScrollbarLeftArrow
:
276 case kScrollbarRightArrow
:
277 needs_paint_indirect
= !GetThemeHandle(SCROLLBAR
);
279 case kScrollbarHorizontalThumb
:
280 case kScrollbarVerticalThumb
:
281 case kScrollbarHorizontalGripper
:
282 case kScrollbarVerticalGripper
:
283 needs_paint_indirect
= !GetThemeHandle(SCROLLBAR
) ||
284 base::win::GetVersion() == base::win::VERSION_XP
;
291 if (needs_paint_indirect
)
292 PaintIndirect(canvas
, part
, state
, rect
, extra
);
294 PaintDirect(canvas
, part
, state
, rect
, extra
);
297 NativeThemeWin::NativeThemeWin()
299 draw_theme_ex_(NULL
),
300 get_theme_color_(NULL
),
301 get_theme_content_rect_(NULL
),
302 get_theme_part_size_(NULL
),
305 set_theme_properties_(NULL
),
306 is_theme_active_(NULL
),
307 get_theme_int_(NULL
),
308 theme_dll_(LoadLibrary(L
"uxtheme.dll")),
309 color_change_listener_(this),
310 is_using_high_contrast_(false),
311 is_using_high_contrast_valid_(false) {
313 draw_theme_
= reinterpret_cast<DrawThemeBackgroundPtr
>(
314 GetProcAddress(theme_dll_
, "DrawThemeBackground"));
315 draw_theme_ex_
= reinterpret_cast<DrawThemeBackgroundExPtr
>(
316 GetProcAddress(theme_dll_
, "DrawThemeBackgroundEx"));
317 get_theme_color_
= reinterpret_cast<GetThemeColorPtr
>(
318 GetProcAddress(theme_dll_
, "GetThemeColor"));
319 get_theme_content_rect_
= reinterpret_cast<GetThemeContentRectPtr
>(
320 GetProcAddress(theme_dll_
, "GetThemeBackgroundContentRect"));
321 get_theme_part_size_
= reinterpret_cast<GetThemePartSizePtr
>(
322 GetProcAddress(theme_dll_
, "GetThemePartSize"));
323 open_theme_
= reinterpret_cast<OpenThemeDataPtr
>(
324 GetProcAddress(theme_dll_
, "OpenThemeData"));
325 close_theme_
= reinterpret_cast<CloseThemeDataPtr
>(
326 GetProcAddress(theme_dll_
, "CloseThemeData"));
327 set_theme_properties_
= reinterpret_cast<SetThemeAppPropertiesPtr
>(
328 GetProcAddress(theme_dll_
, "SetThemeAppProperties"));
329 is_theme_active_
= reinterpret_cast<IsThemeActivePtr
>(
330 GetProcAddress(theme_dll_
, "IsThemeActive"));
331 get_theme_int_
= reinterpret_cast<GetThemeIntPtr
>(
332 GetProcAddress(theme_dll_
, "GetThemeInt"));
334 memset(theme_handles_
, 0, sizeof(theme_handles_
));
336 // Initialize the cached system colors.
337 UpdateSystemColors();
340 NativeThemeWin::~NativeThemeWin() {
342 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks
343 // certain tests and the reliability bots.
345 FreeLibrary(theme_dll_
);
349 void NativeThemeWin::OnSysColorChange() {
350 UpdateSystemColors();
351 is_using_high_contrast_valid_
= false;
355 void NativeThemeWin::UpdateSystemColors() {
356 for (int i
= 0; i
< arraysize(kSystemColors
); ++i
) {
357 system_colors_
[kSystemColors
[i
]] =
358 color_utils::GetSysSkColor(kSystemColors
[i
]);
362 void NativeThemeWin::PaintDirect(SkCanvas
* canvas
,
365 const gfx::Rect
& rect
,
366 const ExtraParams
& extra
) const {
367 skia::ScopedPlatformPaint
scoped_platform_paint(canvas
);
368 HDC hdc
= scoped_platform_paint
.GetPlatformSurface();
372 PaintCheckbox(hdc
, part
, state
, rect
, extra
.button
);
374 case kInnerSpinButton
:
375 PaintSpinButton(hdc
, part
, state
, rect
, extra
.inner_spin
);
378 PaintMenuList(hdc
, state
, rect
, extra
.menu_list
);
381 PaintMenuCheck(hdc
, state
, rect
, extra
.menu_check
);
383 case kMenuCheckBackground
:
384 PaintMenuCheckBackground(hdc
, state
, rect
);
386 case kMenuPopupArrow
:
387 PaintMenuArrow(hdc
, state
, rect
, extra
.menu_arrow
);
389 case kMenuPopupBackground
:
390 PaintMenuBackground(hdc
, rect
);
392 case kMenuPopupGutter
:
393 PaintMenuGutter(hdc
, rect
);
395 case kMenuPopupSeparator
:
396 PaintMenuSeparator(hdc
, rect
);
398 case kMenuItemBackground
:
399 PaintMenuItemBackground(hdc
, state
, rect
, extra
.menu_item
);
402 PaintProgressBar(hdc
, rect
, extra
.progress_bar
);
405 PaintPushButton(hdc
, part
, state
, rect
, extra
.button
);
408 PaintRadioButton(hdc
, part
, state
, rect
, extra
.button
);
410 case kScrollbarDownArrow
:
411 case kScrollbarUpArrow
:
412 case kScrollbarLeftArrow
:
413 case kScrollbarRightArrow
:
414 PaintScrollbarArrow(hdc
, part
, state
, rect
, extra
.scrollbar_arrow
);
416 case kScrollbarHorizontalThumb
:
417 case kScrollbarVerticalThumb
:
418 case kScrollbarHorizontalGripper
:
419 case kScrollbarVerticalGripper
:
420 PaintScrollbarThumb(hdc
, part
, state
, rect
, extra
.scrollbar_thumb
);
422 case kScrollbarHorizontalTrack
:
423 case kScrollbarVerticalTrack
:
424 PaintScrollbarTrack(canvas
, hdc
, part
, state
, rect
,
425 extra
.scrollbar_track
);
427 case kScrollbarCorner
:
428 canvas
->drawColor(SK_ColorWHITE
, SkXfermode::kSrc_Mode
);
430 case kTabPanelBackground
:
431 PaintTabPanelBackground(hdc
, rect
);
434 PaintTextField(hdc
, part
, state
, rect
, extra
.text_field
);
438 PaintTrackbar(canvas
, hdc
, part
, state
, rect
, extra
.trackbar
);
440 case kWindowResizeGripper
:
441 PaintWindowResizeGripper(hdc
, rect
);
451 SkColor
NativeThemeWin::GetSystemColor(ColorId color_id
) const {
453 if (CommonThemeGetSystemColor(color_id
, &color
))
456 // TODO: Obtain the correct colors using GetSysColor.
457 const SkColor kInvalidColorIdColor
= SkColorSetRGB(255, 0, 128);
458 const SkColor kUrlTextColor
= SkColorSetRGB(0x0b, 0x80, 0x43);
460 const SkColor kDialogBackgroundColor
= SkColorSetRGB(251, 251, 251);
462 const SkColor kFocusedBorderColor
= SkColorSetRGB(0x4d, 0x90, 0xfe);
463 const SkColor kUnfocusedBorderColor
= SkColorSetRGB(0xd9, 0xd9, 0xd9);
465 const SkColor kButtonBackgroundColor
= SkColorSetRGB(0xde, 0xde, 0xde);
466 const SkColor kButtonHighlightColor
= SkColorSetARGB(200, 255, 255, 255);
467 const SkColor kButtonHoverColor
= SkColorSetRGB(6, 45, 117);
468 const SkColor kButtonHoverBackgroundColor
= SkColorSetRGB(0xEA, 0xEA, 0xEA);
470 const SkColor kEnabledMenuItemForegroundColor
= SkColorSetRGB(6, 45, 117);
471 const SkColor kDisabledMenuItemForegroundColor
= SkColorSetRGB(161, 161, 146);
472 const SkColor kFocusedMenuItemBackgroundColor
= SkColorSetRGB(246, 249, 253);
473 const SkColor kMenuSeparatorColor
= SkColorSetARGB(50, 0, 0, 0);
475 const SkColor kPositiveTextColor
= SkColorSetRGB(0x0b, 0x80, 0x43);
476 const SkColor kNegativeTextColor
= SkColorSetRGB(0xc5, 0x39, 0x29);
480 case kColorId_WindowBackground
:
481 return system_colors_
[COLOR_WINDOW
];
484 case kColorId_DialogBackground
:
485 return color_utils::IsInvertedColorScheme() ?
486 color_utils::InvertColor(kDialogBackgroundColor
) :
487 kDialogBackgroundColor
;
490 case kColorId_FocusedBorderColor
:
491 return kFocusedBorderColor
;
492 case kColorId_UnfocusedBorderColor
:
493 return kUnfocusedBorderColor
;
496 case kColorId_ButtonBackgroundColor
:
497 return kButtonBackgroundColor
;
498 case kColorId_ButtonEnabledColor
:
499 return system_colors_
[COLOR_BTNTEXT
];
500 case kColorId_ButtonDisabledColor
:
501 return system_colors_
[COLOR_GRAYTEXT
];
502 case kColorId_ButtonHighlightColor
:
503 return kButtonHighlightColor
;
504 case kColorId_ButtonHoverColor
:
505 return kButtonHoverColor
;
506 case kColorId_ButtonHoverBackgroundColor
:
507 return kButtonHoverBackgroundColor
;
508 case kColorId_BlueButtonEnabledColor
:
509 case kColorId_BlueButtonDisabledColor
:
510 case kColorId_BlueButtonPressedColor
:
511 case kColorId_BlueButtonHoverColor
:
513 return kInvalidColorIdColor
;
516 case kColorId_EnabledMenuItemForegroundColor
:
517 return kEnabledMenuItemForegroundColor
;
518 case kColorId_DisabledMenuItemForegroundColor
:
519 return kDisabledMenuItemForegroundColor
;
520 case kColorId_DisabledEmphasizedMenuItemForegroundColor
:
521 return SK_ColorBLACK
;
522 case kColorId_FocusedMenuItemBackgroundColor
:
523 return kFocusedMenuItemBackgroundColor
;
524 case kColorId_MenuSeparatorColor
:
525 return kMenuSeparatorColor
;
526 case kColorId_SelectedMenuItemForegroundColor
:
527 case kColorId_HoverMenuItemBackgroundColor
:
528 case kColorId_MenuBackgroundColor
:
529 case kColorId_MenuBorderColor
:
531 return kInvalidColorIdColor
;
534 case kColorId_EnabledMenuButtonBorderColor
:
535 case kColorId_FocusedMenuButtonBorderColor
:
536 case kColorId_HoverMenuButtonBorderColor
:
538 return kInvalidColorIdColor
;
541 case kColorId_LabelEnabledColor
:
542 return system_colors_
[COLOR_BTNTEXT
];
543 case kColorId_LabelDisabledColor
:
544 return system_colors_
[COLOR_GRAYTEXT
];
545 case kColorId_LabelBackgroundColor
:
546 return system_colors_
[COLOR_WINDOW
];
549 case kColorId_TextfieldDefaultColor
:
550 return system_colors_
[COLOR_WINDOWTEXT
];
551 case kColorId_TextfieldDefaultBackground
:
552 return system_colors_
[COLOR_WINDOW
];
553 case kColorId_TextfieldReadOnlyColor
:
554 return system_colors_
[COLOR_GRAYTEXT
];
555 case kColorId_TextfieldReadOnlyBackground
:
556 return system_colors_
[COLOR_3DFACE
];
557 case kColorId_TextfieldSelectionColor
:
558 return system_colors_
[COLOR_HIGHLIGHTTEXT
];
559 case kColorId_TextfieldSelectionBackgroundFocused
:
560 return system_colors_
[COLOR_HIGHLIGHT
];
563 case kColorId_TooltipBackground
:
564 case kColorId_TooltipText
:
566 return kInvalidColorIdColor
;
569 // NOTE: these aren't right for all themes, but as close as I could get.
570 case kColorId_TreeBackground
:
571 return system_colors_
[COLOR_WINDOW
];
572 case kColorId_TreeText
:
573 return system_colors_
[COLOR_WINDOWTEXT
];
574 case kColorId_TreeSelectedText
:
575 return system_colors_
[COLOR_HIGHLIGHTTEXT
];
576 case kColorId_TreeSelectedTextUnfocused
:
577 return system_colors_
[COLOR_BTNTEXT
];
578 case kColorId_TreeSelectionBackgroundFocused
:
579 return system_colors_
[COLOR_HIGHLIGHT
];
580 case kColorId_TreeSelectionBackgroundUnfocused
:
581 return system_colors_
[IsUsingHighContrastTheme() ?
582 COLOR_MENUHIGHLIGHT
: COLOR_BTNFACE
];
583 case kColorId_TreeArrow
:
584 return system_colors_
[COLOR_WINDOWTEXT
];
587 case kColorId_TableBackground
:
588 return system_colors_
[COLOR_WINDOW
];
589 case kColorId_TableText
:
590 return system_colors_
[COLOR_WINDOWTEXT
];
591 case kColorId_TableSelectedText
:
592 return system_colors_
[COLOR_HIGHLIGHTTEXT
];
593 case kColorId_TableSelectedTextUnfocused
:
594 return system_colors_
[COLOR_BTNTEXT
];
595 case kColorId_TableSelectionBackgroundFocused
:
596 return system_colors_
[COLOR_HIGHLIGHT
];
597 case kColorId_TableSelectionBackgroundUnfocused
:
598 return system_colors_
[IsUsingHighContrastTheme() ?
599 COLOR_MENUHIGHLIGHT
: COLOR_BTNFACE
];
600 case kColorId_TableGroupingIndicatorColor
:
601 return system_colors_
[COLOR_GRAYTEXT
];
604 case kColorId_ResultsTableNormalBackground
:
605 return system_colors_
[COLOR_WINDOW
];
606 case kColorId_ResultsTableHoveredBackground
:
607 return color_utils::AlphaBlend(system_colors_
[COLOR_HIGHLIGHT
],
608 system_colors_
[COLOR_WINDOW
], 0x40);
609 case kColorId_ResultsTableSelectedBackground
:
610 return system_colors_
[COLOR_HIGHLIGHT
];
611 case kColorId_ResultsTableNormalText
:
612 return system_colors_
[COLOR_WINDOWTEXT
];
613 case kColorId_ResultsTableHoveredText
:
614 return color_utils::GetReadableColor(
615 system_colors_
[COLOR_WINDOWTEXT
],
616 GetSystemColor(kColorId_ResultsTableHoveredBackground
));
617 case kColorId_ResultsTableSelectedText
:
618 return system_colors_
[COLOR_HIGHLIGHTTEXT
];
619 case kColorId_ResultsTableNormalDimmedText
:
620 return color_utils::AlphaBlend(system_colors_
[COLOR_WINDOWTEXT
],
621 system_colors_
[COLOR_WINDOW
], 0x80);
622 case kColorId_ResultsTableHoveredDimmedText
:
623 return color_utils::AlphaBlend(
624 system_colors_
[COLOR_WINDOWTEXT
],
625 GetSystemColor(kColorId_ResultsTableHoveredBackground
), 0x80);
626 case kColorId_ResultsTableSelectedDimmedText
:
627 return color_utils::AlphaBlend(system_colors_
[COLOR_HIGHLIGHTTEXT
],
628 system_colors_
[COLOR_HIGHLIGHT
], 0x80);
629 case kColorId_ResultsTableNormalUrl
:
630 return color_utils::GetReadableColor(kUrlTextColor
,
631 system_colors_
[COLOR_WINDOW
]);
632 case kColorId_ResultsTableHoveredUrl
:
633 return color_utils::GetReadableColor(
635 GetSystemColor(kColorId_ResultsTableHoveredBackground
));
636 case kColorId_ResultsTableSelectedUrl
:
637 return color_utils::GetReadableColor(kUrlTextColor
,
638 system_colors_
[COLOR_HIGHLIGHT
]);
639 case kColorId_ResultsTableNormalDivider
:
640 return color_utils::AlphaBlend(system_colors_
[COLOR_WINDOWTEXT
],
641 system_colors_
[COLOR_WINDOW
], 0x34);
642 case kColorId_ResultsTableHoveredDivider
:
643 return color_utils::AlphaBlend(
644 system_colors_
[COLOR_WINDOWTEXT
],
645 GetSystemColor(kColorId_ResultsTableHoveredBackground
), 0x34);
646 case kColorId_ResultsTableSelectedDivider
:
647 return color_utils::AlphaBlend(system_colors_
[COLOR_HIGHLIGHTTEXT
],
648 system_colors_
[COLOR_HIGHLIGHT
], 0x34);
649 case kColorId_ResultsTablePositiveText
:
650 return color_utils::GetReadableColor(kPositiveTextColor
,
651 system_colors_
[COLOR_WINDOW
]);
652 case kColorId_ResultsTablePositiveHoveredText
:
653 return color_utils::GetReadableColor(
655 GetSystemColor(kColorId_ResultsTableHoveredBackground
));
656 case kColorId_ResultsTablePositiveSelectedText
:
657 return color_utils::GetReadableColor(kPositiveTextColor
,
658 system_colors_
[COLOR_HIGHLIGHT
]);
659 case kColorId_ResultsTableNegativeText
:
660 return color_utils::GetReadableColor(kNegativeTextColor
,
661 system_colors_
[COLOR_WINDOW
]);
662 case kColorId_ResultsTableNegativeHoveredText
:
663 return color_utils::GetReadableColor(
665 GetSystemColor(kColorId_ResultsTableHoveredBackground
));
666 case kColorId_ResultsTableNegativeSelectedText
:
667 return color_utils::GetReadableColor(kNegativeTextColor
,
668 system_colors_
[COLOR_HIGHLIGHT
]);
671 return kInvalidColorIdColor
;
675 void NativeThemeWin::PaintIndirect(SkCanvas
* canvas
,
678 const gfx::Rect
& rect
,
679 const ExtraParams
& extra
) const {
680 // TODO(asvitkine): This path is pretty inefficient - for each paint operation
681 // it creates a new offscreen bitmap Skia canvas. This can
682 // be sped up by doing it only once per part/state and
683 // keeping a cache of the resulting bitmaps.
685 // Create an offscreen canvas that is backed by an HDC.
686 skia::RefPtr
<skia::BitmapPlatformDevice
> device
= skia::AdoptRef(
687 skia::BitmapPlatformDevice::Create(
688 rect
.width(), rect
.height(), false, NULL
));
690 SkCanvas
offscreen_canvas(device
.get());
691 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas
));
693 // Some of the Windows theme drawing operations do not write correct alpha
694 // values for fully-opaque pixels; instead the pixels get alpha 0. This is
695 // especially a problem on Windows XP or when using the Classic theme.
697 // To work-around this, mark all pixels with a placeholder value, to detect
698 // which pixels get touched by the paint operation. After paint, set any
699 // pixels that have alpha 0 to opaque and placeholders to fully-transparent.
700 const SkColor placeholder
= SkColorSetARGB(1, 0, 0, 0);
701 offscreen_canvas
.clear(placeholder
);
703 // Offset destination rects to have origin (0,0).
704 gfx::Rect
adjusted_rect(rect
.size());
705 ExtraParams
adjusted_extra(extra
);
708 adjusted_extra
.progress_bar
.value_rect_x
= 0;
709 adjusted_extra
.progress_bar
.value_rect_y
= 0;
711 case kScrollbarHorizontalTrack
:
712 case kScrollbarVerticalTrack
:
713 adjusted_extra
.scrollbar_track
.track_x
= 0;
714 adjusted_extra
.scrollbar_track
.track_y
= 0;
719 // Draw the theme controls using existing HDC-drawing code.
720 PaintDirect(&offscreen_canvas
, part
, state
, adjusted_rect
, adjusted_extra
);
722 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is
723 // necessary to have when drawing to a SkPicture.
724 const SkBitmap
& hdc_bitmap
=
725 offscreen_canvas
.getDevice()->accessBitmap(false);
727 hdc_bitmap
.copyTo(&bitmap
, kN32_SkColorType
);
729 // Post-process the pixels to fix up the alpha values (see big comment above).
730 const SkPMColor placeholder_value
= SkPreMultiplyColor(placeholder
);
731 const int pixel_count
= rect
.width() * rect
.height();
732 SkPMColor
* pixels
= bitmap
.getAddr32(0, 0);
733 for (int i
= 0; i
< pixel_count
; i
++) {
734 if (pixels
[i
] == placeholder_value
) {
735 // Pixel wasn't touched - make it fully transparent.
736 pixels
[i
] = SkPackARGB32(0, 0, 0, 0);
737 } else if (SkGetPackedA32(pixels
[i
]) == 0) {
738 // Pixel was touched but has incorrect alpha of 0, make it fully opaque.
739 pixels
[i
] = SkPackARGB32(0xFF,
740 SkGetPackedR32(pixels
[i
]),
741 SkGetPackedG32(pixels
[i
]),
742 SkGetPackedB32(pixels
[i
]));
746 // Draw the offscreen bitmap to the destination canvas.
747 canvas
->drawBitmap(bitmap
, rect
.x(), rect
.y());
750 HRESULT
NativeThemeWin::GetThemePartSize(ThemeName theme_name
,
757 HANDLE handle
= GetThemeHandle(theme_name
);
758 return (handle
&& get_theme_part_size_
) ?
759 get_theme_part_size_(handle
, hdc
, part_id
, state_id
, rect
, ts
, size
) :
763 HRESULT
NativeThemeWin::PaintButton(HDC hdc
,
765 const ButtonExtraParams
& extra
,
769 HANDLE handle
= GetThemeHandle(BUTTON
);
770 if (handle
&& draw_theme_
)
771 return draw_theme_(handle
, hdc
, part_id
, state_id
, rect
, NULL
);
773 // Adjust classic_state based on part, state, and extras.
774 int classic_state
= extra
.classic_state
;
777 classic_state
|= DFCS_BUTTONCHECK
;
780 classic_state
|= DFCS_BUTTONRADIO
;
783 classic_state
|= DFCS_BUTTONPUSH
;
792 classic_state
|= DFCS_INACTIVE
;
798 classic_state
|= DFCS_PUSHED
;
806 classic_state
|= DFCS_CHECKED
;
809 // All pressed states have both low bits set, and no other states do.
810 const bool focused
= ((state_id
& ETS_FOCUSED
) == ETS_FOCUSED
);
811 const bool pressed
= ((state_id
& PBS_PRESSED
) == PBS_PRESSED
);
812 if ((BP_PUSHBUTTON
== part_id
) && (pressed
|| focused
)) {
813 // BP_PUSHBUTTON has a focus rect drawn around the outer edge, and the
814 // button itself is shrunk by 1 pixel.
815 HBRUSH brush
= GetSysColorBrush(COLOR_3DDKSHADOW
);
817 FrameRect(hdc
, rect
, brush
);
818 InflateRect(rect
, -1, -1);
821 DrawFrameControl(hdc
, rect
, DFC_BUTTON
, classic_state
);
823 // Draw the focus rectangle (the dotted line box) only on buttons. For radio
824 // and checkboxes, we let webkit draw the focus rectangle (orange glow).
825 if ((BP_PUSHBUTTON
== part_id
) && focused
) {
826 // The focus rect is inside the button. The exact number of pixels depends
827 // on whether we're in classic mode or using uxtheme.
828 if (handle
&& get_theme_content_rect_
) {
829 get_theme_content_rect_(handle
, hdc
, part_id
, state_id
, rect
, rect
);
831 InflateRect(rect
, -GetSystemMetrics(SM_CXEDGE
),
832 -GetSystemMetrics(SM_CYEDGE
));
834 DrawFocusRect(hdc
, rect
);
837 // Classic theme doesn't support indeterminate checkboxes. We draw
838 // a recangle inside a checkbox like IE10 does.
839 if (part_id
== BP_CHECKBOX
&& extra
.indeterminate
) {
840 RECT inner_rect
= *rect
;
841 // "4 / 13" is same as IE10 in classic theme.
842 int padding
= (inner_rect
.right
- inner_rect
.left
) * 4 / 13;
843 InflateRect(&inner_rect
, -padding
, -padding
);
844 int color_index
= state
== kDisabled
? COLOR_GRAYTEXT
: COLOR_WINDOWTEXT
;
845 FillRect(hdc
, &inner_rect
, GetSysColorBrush(color_index
));
851 HRESULT
NativeThemeWin::PaintMenuSeparator(
853 const gfx::Rect
& rect
) const {
854 RECT rect_win
= rect
.ToRECT();
856 HANDLE handle
= GetThemeHandle(MENU
);
857 if (handle
&& draw_theme_
) {
858 // Delta is needed for non-classic to move separator up slightly.
861 return draw_theme_(handle
, hdc
, MENU_POPUPSEPARATOR
, MPI_NORMAL
, &rect_win
,
865 DrawEdge(hdc
, &rect_win
, EDGE_ETCHED
, BF_TOP
);
869 HRESULT
NativeThemeWin::PaintMenuGutter(HDC hdc
,
870 const gfx::Rect
& rect
) const {
871 RECT rect_win
= rect
.ToRECT();
872 HANDLE handle
= GetThemeHandle(MENU
);
873 return (handle
&& draw_theme_
) ?
874 draw_theme_(handle
, hdc
, MENU_POPUPGUTTER
, MPI_NORMAL
, &rect_win
, NULL
) :
878 HRESULT
NativeThemeWin::PaintMenuArrow(
881 const gfx::Rect
& rect
,
882 const MenuArrowExtraParams
& extra
) const {
883 int state_id
= MSM_NORMAL
;
884 if (state
== kDisabled
)
885 state_id
= MSM_DISABLED
;
887 HANDLE handle
= GetThemeHandle(MENU
);
888 RECT rect_win
= rect
.ToRECT();
889 if (handle
&& draw_theme_
) {
890 if (extra
.pointing_right
) {
891 return draw_theme_(handle
, hdc
, MENU_POPUPSUBMENU
, state_id
, &rect_win
,
894 // There is no way to tell the uxtheme API to draw a left pointing arrow; it
895 // doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they are
896 // needed for RTL locales on Vista. So use a memory DC and mirror the
897 // region with GDI's StretchBlt.
899 base::win::ScopedCreateDC
mem_dc(CreateCompatibleDC(hdc
));
900 base::win::ScopedBitmap
mem_bitmap(CreateCompatibleBitmap(hdc
, r
.width(),
902 base::win::ScopedSelectObject
select_bitmap(mem_dc
.Get(), mem_bitmap
);
903 // Copy and horizontally mirror the background from hdc into mem_dc. Use
904 // a negative-width source rect, starting at the rightmost pixel.
905 StretchBlt(mem_dc
.Get(), 0, 0, r
.width(), r
.height(),
906 hdc
, r
.right()-1, r
.y(), -r
.width(), r
.height(), SRCCOPY
);
908 RECT theme_rect
= {0, 0, r
.width(), r
.height()};
909 HRESULT result
= draw_theme_(handle
, mem_dc
.Get(), MENU_POPUPSUBMENU
,
910 state_id
, &theme_rect
, NULL
);
911 // Copy and mirror the result back into mem_dc.
912 StretchBlt(hdc
, r
.x(), r
.y(), r
.width(), r
.height(),
913 mem_dc
.Get(), r
.width()-1, 0, -r
.width(), r
.height(), SRCCOPY
);
917 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a
918 // left pointing arrow. This makes the following statement counterintuitive.
919 UINT pfc_state
= extra
.pointing_right
? DFCS_MENUARROW
: DFCS_MENUARROWRIGHT
;
920 return PaintFrameControl(hdc
, rect
, DFC_MENU
, pfc_state
, extra
.is_selected
,
924 HRESULT
NativeThemeWin::PaintMenuBackground(HDC hdc
,
925 const gfx::Rect
& rect
) const {
926 HANDLE handle
= GetThemeHandle(MENU
);
927 RECT rect_win
= rect
.ToRECT();
928 if (handle
&& draw_theme_
) {
929 HRESULT result
= draw_theme_(handle
, hdc
, MENU_POPUPBACKGROUND
, 0,
931 FrameRect(hdc
, &rect_win
, GetSysColorBrush(COLOR_3DSHADOW
));
935 FillRect(hdc
, &rect_win
, GetSysColorBrush(COLOR_MENU
));
936 DrawEdge(hdc
, &rect_win
, EDGE_RAISED
, BF_RECT
);
940 HRESULT
NativeThemeWin::PaintMenuCheck(
943 const gfx::Rect
& rect
,
944 const MenuCheckExtraParams
& extra
) const {
945 HANDLE handle
= GetThemeHandle(MENU
);
946 if (handle
&& draw_theme_
) {
947 const int state_id
= extra
.is_radio
?
948 ((state
== kDisabled
) ? MC_BULLETDISABLED
: MC_BULLETNORMAL
) :
949 ((state
== kDisabled
) ? MC_CHECKMARKDISABLED
: MC_CHECKMARKNORMAL
);
950 RECT rect_win
= rect
.ToRECT();
951 return draw_theme_(handle
, hdc
, MENU_POPUPCHECK
, state_id
, &rect_win
, NULL
);
954 return PaintFrameControl(hdc
, rect
, DFC_MENU
,
955 extra
.is_radio
? DFCS_MENUBULLET
: DFCS_MENUCHECK
,
956 extra
.is_selected
, state
);
959 HRESULT
NativeThemeWin::PaintMenuCheckBackground(HDC hdc
,
961 const gfx::Rect
& rect
) const {
962 HANDLE handle
= GetThemeHandle(MENU
);
963 if (!handle
|| !draw_theme_
)
964 return S_OK
; // Nothing to do for background.
966 int state_id
= state
== kDisabled
? MCB_DISABLED
: MCB_NORMAL
;
967 RECT rect_win
= rect
.ToRECT();
968 return draw_theme_(handle
, hdc
, MENU_POPUPCHECKBACKGROUND
, state_id
,
972 HRESULT
NativeThemeWin::PaintMenuItemBackground(
975 const gfx::Rect
& rect
,
976 const MenuItemExtraParams
& extra
) const {
977 HANDLE handle
= GetThemeHandle(MENU
);
978 RECT rect_win
= rect
.ToRECT();
979 int state_id
= MPI_NORMAL
;
982 state_id
= extra
.is_selected
? MPI_DISABLEDHOT
: MPI_DISABLED
;
995 if (handle
&& draw_theme_
)
996 return draw_theme_(handle
, hdc
, MENU_POPUPITEM
, state_id
, &rect_win
, NULL
);
998 if (extra
.is_selected
)
999 FillRect(hdc
, &rect_win
, GetSysColorBrush(COLOR_HIGHLIGHT
));
1003 HRESULT
NativeThemeWin::PaintPushButton(HDC hdc
,
1006 const gfx::Rect
& rect
,
1007 const ButtonExtraParams
& extra
) const {
1008 int state_id
= extra
.is_default
? PBS_DEFAULTED
: PBS_NORMAL
;
1011 state_id
= PBS_DISABLED
;
1019 state_id
= PBS_PRESSED
;
1026 RECT rect_win
= rect
.ToRECT();
1027 return PaintButton(hdc
, state
, extra
, BP_PUSHBUTTON
, state_id
, &rect_win
);
1030 HRESULT
NativeThemeWin::PaintRadioButton(HDC hdc
,
1033 const gfx::Rect
& rect
,
1034 const ButtonExtraParams
& extra
) const {
1035 int state_id
= extra
.checked
? RBS_CHECKEDNORMAL
: RBS_UNCHECKEDNORMAL
;
1038 state_id
= extra
.checked
? RBS_CHECKEDDISABLED
: RBS_UNCHECKEDDISABLED
;
1041 state_id
= extra
.checked
? RBS_CHECKEDHOT
: RBS_UNCHECKEDHOT
;
1046 state_id
= extra
.checked
? RBS_CHECKEDPRESSED
: RBS_UNCHECKEDPRESSED
;
1053 RECT rect_win
= rect
.ToRECT();
1054 return PaintButton(hdc
, state
, extra
, BP_RADIOBUTTON
, state_id
, &rect_win
);
1057 HRESULT
NativeThemeWin::PaintCheckbox(HDC hdc
,
1060 const gfx::Rect
& rect
,
1061 const ButtonExtraParams
& extra
) const {
1062 int state_id
= extra
.checked
?
1064 (extra
.indeterminate
? CBS_MIXEDNORMAL
: CBS_UNCHECKEDNORMAL
);
1067 state_id
= extra
.checked
?
1068 CBS_CHECKEDDISABLED
:
1069 (extra
.indeterminate
? CBS_MIXEDDISABLED
: CBS_UNCHECKEDDISABLED
);
1072 state_id
= extra
.checked
?
1074 (extra
.indeterminate
? CBS_MIXEDHOT
: CBS_UNCHECKEDHOT
);
1079 state_id
= extra
.checked
?
1080 CBS_CHECKEDPRESSED
:
1081 (extra
.indeterminate
? CBS_MIXEDPRESSED
: CBS_UNCHECKEDPRESSED
);
1088 RECT rect_win
= rect
.ToRECT();
1089 return PaintButton(hdc
, state
, extra
, BP_CHECKBOX
, state_id
, &rect_win
);
1092 HRESULT
NativeThemeWin::PaintMenuList(HDC hdc
,
1094 const gfx::Rect
& rect
,
1095 const MenuListExtraParams
& extra
) const {
1096 HANDLE handle
= GetThemeHandle(MENULIST
);
1097 RECT rect_win
= rect
.ToRECT();
1098 int state_id
= CBXS_NORMAL
;
1101 state_id
= CBXS_DISABLED
;
1104 state_id
= CBXS_HOT
;
1109 state_id
= CBXS_PRESSED
;
1116 if (handle
&& draw_theme_
)
1117 return draw_theme_(handle
, hdc
, CP_DROPDOWNBUTTON
, state_id
, &rect_win
,
1120 // Draw it manually.
1121 DrawFrameControl(hdc
, &rect_win
, DFC_SCROLL
,
1122 DFCS_SCROLLCOMBOBOX
| extra
.classic_state
);
1126 HRESULT
NativeThemeWin::PaintScrollbarArrow(
1130 const gfx::Rect
& rect
,
1131 const ScrollbarArrowExtraParams
& extra
) const {
1132 static const int state_id_matrix
[4][kNumStates
] = {
1133 {ABS_DOWNDISABLED
, ABS_DOWNHOT
, ABS_DOWNNORMAL
, ABS_DOWNPRESSED
},
1134 {ABS_LEFTDISABLED
, ABS_LEFTHOT
, ABS_LEFTNORMAL
, ABS_LEFTPRESSED
},
1135 {ABS_RIGHTDISABLED
, ABS_RIGHTHOT
, ABS_RIGHTNORMAL
, ABS_RIGHTPRESSED
},
1136 {ABS_UPDISABLED
, ABS_UPHOT
, ABS_UPNORMAL
, ABS_UPPRESSED
},
1138 HANDLE handle
= GetThemeHandle(SCROLLBAR
);
1139 RECT rect_win
= rect
.ToRECT();
1140 if (handle
&& draw_theme_
) {
1141 int index
= part
- kScrollbarDownArrow
;
1142 DCHECK_GE(index
, 0);
1143 DCHECK_LT(static_cast<size_t>(index
), arraysize(state_id_matrix
));
1144 int state_id
= state_id_matrix
[index
][state
];
1146 // Hovering means that the cursor is over the scroolbar, but not over the
1147 // specific arrow itself. We don't want to show it "hot" mode, but only
1149 if (state
== kHovered
&& extra
.is_hovering
) {
1151 case kScrollbarDownArrow
:
1152 state_id
= ABS_DOWNHOVER
;
1154 case kScrollbarLeftArrow
:
1155 state_id
= ABS_LEFTHOVER
;
1157 case kScrollbarRightArrow
:
1158 state_id
= ABS_RIGHTHOVER
;
1160 case kScrollbarUpArrow
:
1161 state_id
= ABS_UPHOVER
;
1168 return PaintScaledTheme(handle
, hdc
, SBP_ARROWBTN
, state_id
, rect
);
1171 int classic_state
= DFCS_SCROLLDOWN
;
1173 case kScrollbarDownArrow
:
1175 case kScrollbarLeftArrow
:
1176 classic_state
= DFCS_SCROLLLEFT
;
1178 case kScrollbarRightArrow
:
1179 classic_state
= DFCS_SCROLLRIGHT
;
1181 case kScrollbarUpArrow
:
1182 classic_state
= DFCS_SCROLLUP
;
1190 classic_state
|= DFCS_INACTIVE
;
1193 classic_state
|= DFCS_HOT
;
1198 classic_state
|= DFCS_PUSHED
;
1204 DrawFrameControl(hdc
, &rect_win
, DFC_SCROLL
, classic_state
);
1208 HRESULT
NativeThemeWin::PaintScrollbarThumb(
1212 const gfx::Rect
& rect
,
1213 const ScrollbarThumbExtraParams
& extra
) const {
1214 HANDLE handle
= GetThemeHandle(SCROLLBAR
);
1215 RECT rect_win
= rect
.ToRECT();
1217 int part_id
= SBP_THUMBBTNVERT
;
1219 case kScrollbarHorizontalThumb
:
1220 part_id
= SBP_THUMBBTNHORZ
;
1222 case kScrollbarVerticalThumb
:
1224 case kScrollbarHorizontalGripper
:
1225 part_id
= SBP_GRIPPERHORZ
;
1227 case kScrollbarVerticalGripper
:
1228 part_id
= SBP_GRIPPERVERT
;
1235 int state_id
= SCRBS_NORMAL
;
1238 state_id
= SCRBS_DISABLED
;
1241 state_id
= extra
.is_hovering
? SCRBS_HOVER
: SCRBS_HOT
;
1246 state_id
= SCRBS_PRESSED
;
1253 if (handle
&& draw_theme_
)
1254 return PaintScaledTheme(handle
, hdc
, part_id
, state_id
, rect
);
1256 // Draw it manually.
1257 if ((part_id
== SBP_THUMBBTNHORZ
) || (part_id
== SBP_THUMBBTNVERT
))
1258 DrawEdge(hdc
, &rect_win
, EDGE_RAISED
, BF_RECT
| BF_MIDDLE
);
1259 // Classic mode doesn't have a gripper.
1263 HRESULT
NativeThemeWin::PaintScrollbarTrack(
1268 const gfx::Rect
& rect
,
1269 const ScrollbarTrackExtraParams
& extra
) const {
1270 HANDLE handle
= GetThemeHandle(SCROLLBAR
);
1271 RECT rect_win
= rect
.ToRECT();
1273 const int part_id
= extra
.is_upper
?
1274 ((part
== kScrollbarHorizontalTrack
) ?
1275 SBP_UPPERTRACKHORZ
: SBP_UPPERTRACKVERT
) :
1276 ((part
== kScrollbarHorizontalTrack
) ?
1277 SBP_LOWERTRACKHORZ
: SBP_LOWERTRACKVERT
);
1279 int state_id
= SCRBS_NORMAL
;
1282 state_id
= SCRBS_DISABLED
;
1285 state_id
= SCRBS_HOVER
;
1290 state_id
= SCRBS_PRESSED
;
1297 if (handle
&& draw_theme_
)
1298 return draw_theme_(handle
, hdc
, part_id
, state_id
, &rect_win
, NULL
);
1300 // Draw it manually.
1301 if ((system_colors_
[COLOR_SCROLLBAR
] != system_colors_
[COLOR_3DFACE
]) &&
1302 (system_colors_
[COLOR_SCROLLBAR
] != system_colors_
[COLOR_WINDOW
])) {
1303 FillRect(hdc
, &rect_win
, reinterpret_cast<HBRUSH
>(COLOR_SCROLLBAR
+ 1));
1306 RECT align_rect
= gfx::Rect(extra
.track_x
, extra
.track_y
, extra
.track_width
,
1307 extra
.track_height
).ToRECT();
1308 SetCheckerboardShader(&paint
, align_rect
);
1309 canvas
->drawIRect(skia::RECTToSkIRect(rect_win
), paint
);
1311 if (extra
.classic_state
& DFCS_PUSHED
)
1312 InvertRect(hdc
, &rect_win
);
1316 HRESULT
NativeThemeWin::PaintSpinButton(
1320 const gfx::Rect
& rect
,
1321 const InnerSpinButtonExtraParams
& extra
) const {
1322 HANDLE handle
= GetThemeHandle(SPIN
);
1323 RECT rect_win
= rect
.ToRECT();
1324 int part_id
= extra
.spin_up
? SPNP_UP
: SPNP_DOWN
;
1325 int state_id
= extra
.spin_up
? UPS_NORMAL
: DNS_NORMAL
;
1328 state_id
= extra
.spin_up
? UPS_DISABLED
: DNS_DISABLED
;
1331 state_id
= extra
.spin_up
? UPS_HOT
: DNS_HOT
;
1336 state_id
= extra
.spin_up
? UPS_PRESSED
: DNS_PRESSED
;
1343 if (handle
&& draw_theme_
)
1344 return draw_theme_(handle
, hdc
, part_id
, state_id
, &rect_win
, NULL
);
1345 DrawFrameControl(hdc
, &rect_win
, DFC_SCROLL
, extra
.classic_state
);
1349 HRESULT
NativeThemeWin::PaintTrackbar(
1354 const gfx::Rect
& rect
,
1355 const TrackbarExtraParams
& extra
) const {
1356 const int part_id
= extra
.vertical
?
1357 ((part
== kTrackbarTrack
) ? TKP_TRACKVERT
: TKP_THUMBVERT
) :
1358 ((part
== kTrackbarTrack
) ? TKP_TRACK
: TKP_THUMBBOTTOM
);
1360 int state_id
= TUS_NORMAL
;
1363 state_id
= TUS_DISABLED
;
1371 state_id
= TUS_PRESSED
;
1378 // Make the channel be 4 px thick in the center of the supplied rect. (4 px
1379 // matches what XP does in various menus; GetThemePartSize() doesn't seem to
1380 // return good values here.)
1381 RECT rect_win
= rect
.ToRECT();
1382 RECT channel_rect
= rect
.ToRECT();
1383 const int channel_thickness
= 4;
1384 if (part_id
== TKP_TRACK
) {
1386 ((channel_rect
.bottom
- channel_rect
.top
- channel_thickness
) / 2);
1387 channel_rect
.bottom
= channel_rect
.top
+ channel_thickness
;
1388 } else if (part_id
== TKP_TRACKVERT
) {
1389 channel_rect
.left
+=
1390 ((channel_rect
.right
- channel_rect
.left
- channel_thickness
) / 2);
1391 channel_rect
.right
= channel_rect
.left
+ channel_thickness
;
1392 } // else this isn't actually a channel, so |channel_rect| == |rect|.
1394 HANDLE handle
= GetThemeHandle(TRACKBAR
);
1395 if (handle
&& draw_theme_
)
1396 return draw_theme_(handle
, hdc
, part_id
, state_id
, &channel_rect
, NULL
);
1398 // Classic mode, draw it manually.
1399 if ((part_id
== TKP_TRACK
) || (part_id
== TKP_TRACKVERT
)) {
1400 DrawEdge(hdc
, &channel_rect
, EDGE_SUNKEN
, BF_RECT
);
1401 } else if (part_id
== TKP_THUMBVERT
) {
1402 DrawEdge(hdc
, &rect_win
, EDGE_RAISED
, BF_RECT
| BF_SOFT
| BF_MIDDLE
);
1404 // Split rect into top and bottom pieces.
1405 RECT top_section
= rect
.ToRECT();
1406 RECT bottom_section
= rect
.ToRECT();
1407 top_section
.bottom
-= ((bottom_section
.right
- bottom_section
.left
) / 2);
1408 bottom_section
.top
= top_section
.bottom
;
1409 DrawEdge(hdc
, &top_section
, EDGE_RAISED
,
1410 BF_LEFT
| BF_TOP
| BF_RIGHT
| BF_SOFT
| BF_MIDDLE
| BF_ADJUST
);
1412 // Split triangular piece into two diagonals.
1413 RECT
& left_half
= bottom_section
;
1414 RECT right_half
= bottom_section
;
1415 right_half
.left
+= ((bottom_section
.right
- bottom_section
.left
) / 2);
1416 left_half
.right
= right_half
.left
;
1417 DrawEdge(hdc
, &left_half
, EDGE_RAISED
,
1418 BF_DIAGONAL_ENDTOPLEFT
| BF_SOFT
| BF_MIDDLE
| BF_ADJUST
);
1419 DrawEdge(hdc
, &right_half
, EDGE_RAISED
,
1420 BF_DIAGONAL_ENDBOTTOMLEFT
| BF_SOFT
| BF_MIDDLE
| BF_ADJUST
);
1422 // If the button is pressed, draw hatching.
1423 if (extra
.classic_state
& DFCS_PUSHED
) {
1425 SetCheckerboardShader(&paint
, rect_win
);
1427 // Fill all three pieces with the pattern.
1428 canvas
->drawIRect(skia::RECTToSkIRect(top_section
), paint
);
1430 SkScalar left_triangle_top
= SkIntToScalar(left_half
.top
);
1431 SkScalar left_triangle_right
= SkIntToScalar(left_half
.right
);
1432 SkPath left_triangle
;
1433 left_triangle
.moveTo(SkIntToScalar(left_half
.left
), left_triangle_top
);
1434 left_triangle
.lineTo(left_triangle_right
, left_triangle_top
);
1435 left_triangle
.lineTo(left_triangle_right
,
1436 SkIntToScalar(left_half
.bottom
));
1437 left_triangle
.close();
1438 canvas
->drawPath(left_triangle
, paint
);
1440 SkScalar right_triangle_left
= SkIntToScalar(right_half
.left
);
1441 SkScalar right_triangle_top
= SkIntToScalar(right_half
.top
);
1442 SkPath right_triangle
;
1443 right_triangle
.moveTo(right_triangle_left
, right_triangle_top
);
1444 right_triangle
.lineTo(SkIntToScalar(right_half
.right
),
1445 right_triangle_top
);
1446 right_triangle
.lineTo(right_triangle_left
,
1447 SkIntToScalar(right_half
.bottom
));
1448 right_triangle
.close();
1449 canvas
->drawPath(right_triangle
, paint
);
1455 HRESULT
NativeThemeWin::PaintProgressBar(
1457 const gfx::Rect
& rect
,
1458 const ProgressBarExtraParams
& extra
) const {
1459 // There is no documentation about the animation speed, frame-rate, nor
1460 // size of moving overlay of the indeterminate progress bar.
1461 // So we just observed real-world programs and guessed following parameters.
1462 const int kDeterminateOverlayPixelsPerSecond
= 300;
1463 const int kDeterminateOverlayWidth
= 120;
1464 const int kIndeterminateOverlayPixelsPerSecond
= 175;
1465 const int kVistaIndeterminateOverlayWidth
= 120;
1466 const int kXPIndeterminateOverlayWidth
= 55;
1467 // The thickness of the bar frame inside |value_rect|
1468 const int kXPBarPadding
= 3;
1470 RECT bar_rect
= rect
.ToRECT();
1471 RECT value_rect
= gfx::Rect(extra
.value_rect_x
,
1473 extra
.value_rect_width
,
1474 extra
.value_rect_height
).ToRECT();
1476 HANDLE handle
= GetThemeHandle(PROGRESS
);
1477 if (!handle
|| !draw_theme_
|| !draw_theme_ex_
) {
1478 FillRect(hdc
, &bar_rect
, GetSysColorBrush(COLOR_BTNFACE
));
1479 FillRect(hdc
, &value_rect
, GetSysColorBrush(COLOR_BTNSHADOW
));
1480 DrawEdge(hdc
, &bar_rect
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
1484 draw_theme_(handle
, hdc
, PP_BAR
, 0, &bar_rect
, NULL
);
1486 bool pre_vista
= base::win::GetVersion() < base::win::VERSION_VISTA
;
1487 int bar_width
= bar_rect
.right
- bar_rect
.left
;
1488 if (!extra
.determinate
) {
1489 // The glossy overlay for the indeterminate progress bar has a small pause
1490 // after each animation. We emulate this by adding an invisible margin the
1491 // animation has to traverse.
1492 int width_with_margin
= bar_width
+ kIndeterminateOverlayPixelsPerSecond
;
1493 int overlay_width
= pre_vista
?
1494 kXPIndeterminateOverlayWidth
: kVistaIndeterminateOverlayWidth
;
1495 RECT overlay_rect
= bar_rect
;
1496 overlay_rect
.left
+= ComputeAnimationProgress(
1497 width_with_margin
, overlay_width
, kIndeterminateOverlayPixelsPerSecond
,
1498 extra
.animated_seconds
);
1499 overlay_rect
.right
= overlay_rect
.left
+ overlay_width
;
1501 RECT shrunk_rect
= InsetRect(&overlay_rect
, kXPBarPadding
);
1502 RECT shrunk_bar_rect
= InsetRect(&bar_rect
, kXPBarPadding
);
1503 draw_theme_(handle
, hdc
, PP_CHUNK
, 0, &shrunk_rect
, &shrunk_bar_rect
);
1505 draw_theme_(handle
, hdc
, PP_MOVEOVERLAY
, 0, &overlay_rect
, &bar_rect
);
1510 // We care about the direction here because PP_CHUNK painting is asymmetric.
1511 // TODO(morrita): This RTL guess can be wrong. We should pass in the
1512 // direction from WebKit.
1513 const DTBGOPTS value_draw_options
= {
1515 (bar_rect
.right
== value_rect
.right
&& bar_rect
.left
!= value_rect
.left
) ?
1520 // On XP, the progress bar is chunk-style and has no glossy effect. We need
1521 // to shrink the destination rect to fit the part inside the bar with an
1522 // appropriate margin.
1523 RECT shrunk_value_rect
= InsetRect(&value_rect
, kXPBarPadding
);
1524 draw_theme_ex_(handle
, hdc
, PP_CHUNK
, 0, &shrunk_value_rect
,
1525 &value_draw_options
);
1527 // On Vista or later, the progress bar part has a single-block value part
1528 // and a glossy effect. The value part has exactly same height as the bar
1529 // part, so we don't need to shrink the rect.
1530 draw_theme_ex_(handle
, hdc
, PP_FILL
, 0, &value_rect
, &value_draw_options
);
1532 RECT overlay_rect
= value_rect
;
1533 overlay_rect
.left
+= ComputeAnimationProgress(
1534 bar_width
, kDeterminateOverlayWidth
, kDeterminateOverlayPixelsPerSecond
,
1535 extra
.animated_seconds
);
1536 overlay_rect
.right
= overlay_rect
.left
+ kDeterminateOverlayWidth
;
1537 draw_theme_(handle
, hdc
, PP_MOVEOVERLAY
, 0, &overlay_rect
, &value_rect
);
1542 HRESULT
NativeThemeWin::PaintWindowResizeGripper(HDC hdc
,
1543 const gfx::Rect
& rect
) const {
1544 HANDLE handle
= GetThemeHandle(STATUS
);
1545 RECT rect_win
= rect
.ToRECT();
1546 if (handle
&& draw_theme_
) {
1547 // Paint the status bar gripper. There doesn't seem to be a standard
1548 // gripper in Windows for the space between scrollbars. This is pretty
1549 // close, but it's supposed to be painted over a status bar.
1550 return draw_theme_(handle
, hdc
, SP_GRIPPER
, 0, &rect_win
, NULL
);
1553 // Draw a windows classic scrollbar gripper.
1554 DrawFrameControl(hdc
, &rect_win
, DFC_SCROLL
, DFCS_SCROLLSIZEGRIP
);
1558 HRESULT
NativeThemeWin::PaintTabPanelBackground(HDC hdc
,
1559 const gfx::Rect
& rect
) const {
1560 HANDLE handle
= GetThemeHandle(TAB
);
1561 RECT rect_win
= rect
.ToRECT();
1562 if (handle
&& draw_theme_
)
1563 return draw_theme_(handle
, hdc
, TABP_BODY
, 0, &rect_win
, NULL
);
1565 // Classic just renders a flat color background.
1566 FillRect(hdc
, &rect_win
, reinterpret_cast<HBRUSH
>(COLOR_3DFACE
+ 1));
1570 HRESULT
NativeThemeWin::PaintTextField(
1574 const gfx::Rect
& rect
,
1575 const TextFieldExtraParams
& extra
) const {
1576 int state_id
= ETS_NORMAL
;
1579 state_id
= ETS_DISABLED
;
1585 if (extra
.is_read_only
)
1586 state_id
= ETS_READONLY
;
1587 else if (extra
.is_focused
)
1588 state_id
= ETS_FOCUSED
;
1591 state_id
= ETS_SELECTED
;
1598 RECT rect_win
= rect
.ToRECT();
1599 return PaintTextField(hdc
, EP_EDITTEXT
, state_id
, extra
.classic_state
,
1601 skia::SkColorToCOLORREF(extra
.background_color
),
1602 extra
.fill_content_area
, extra
.draw_edges
);
1605 HRESULT
NativeThemeWin::PaintTextField(HDC hdc
,
1611 bool fill_content_area
,
1612 bool draw_edges
) const {
1613 // TODO(ojan): http://b/1210017 Figure out how to give the ability to
1614 // exclude individual edges from being drawn.
1616 HANDLE handle
= GetThemeHandle(TEXTFIELD
);
1617 // TODO(mpcomplete): can we detect if the color is specified by the user,
1618 // and if not, just use the system color?
1619 // CreateSolidBrush() accepts a RGB value but alpha must be 0.
1620 base::win::ScopedGDIObject
<HBRUSH
> bg_brush(CreateSolidBrush(color
));
1621 // DrawThemeBackgroundEx was introduced in XP SP2, so that it's possible
1622 // draw_theme_ex_ is NULL and draw_theme_ is non-null.
1623 if (!handle
|| (!draw_theme_ex_
&& (!draw_theme_
|| !draw_edges
))) {
1624 // Draw it manually.
1626 DrawEdge(hdc
, rect
, EDGE_SUNKEN
, BF_RECT
| BF_ADJUST
);
1628 if (fill_content_area
) {
1629 FillRect(hdc
, rect
, (classic_state
& DFCS_INACTIVE
) ?
1630 reinterpret_cast<HBRUSH
>(COLOR_BTNFACE
+ 1) : bg_brush
);
1635 static const DTBGOPTS omit_border_options
= {
1640 HRESULT hr
= draw_theme_ex_
?
1641 draw_theme_ex_(handle
, hdc
, part_id
, state_id
, rect
,
1642 draw_edges
? NULL
: &omit_border_options
) :
1643 draw_theme_(handle
, hdc
, part_id
, state_id
, rect
, NULL
);
1645 // TODO(maruel): Need to be fixed if get_theme_content_rect_ is NULL.
1646 if (fill_content_area
&& get_theme_content_rect_
) {
1648 hr
= get_theme_content_rect_(handle
, hdc
, part_id
, state_id
, rect
,
1650 FillRect(hdc
, &content_rect
, bg_brush
);
1655 HRESULT
NativeThemeWin::PaintScaledTheme(HANDLE theme
,
1659 const gfx::Rect
& rect
) const {
1660 // Correct the scaling and positioning of sub-components such as scrollbar
1661 // arrows and thumb grippers in the event that the world transform applies
1662 // scaling (e.g. in high-DPI mode).
1663 XFORM save_transform
;
1664 if (GetWorldTransform(hdc
, &save_transform
)) {
1665 float scale
= save_transform
.eM11
;
1666 if (scale
!= 1 && save_transform
.eM12
== 0) {
1667 ModifyWorldTransform(hdc
, NULL
, MWT_IDENTITY
);
1668 gfx::Rect
scaled_rect(gfx::ToEnclosedRect(gfx::ScaleRect(rect
, scale
)));
1669 scaled_rect
.Offset(save_transform
.eDx
, save_transform
.eDy
);
1670 RECT bounds
= scaled_rect
.ToRECT();
1671 HRESULT result
= draw_theme_(theme
, hdc
, part_id
, state_id
, &bounds
,
1673 SetWorldTransform(hdc
, &save_transform
);
1677 RECT bounds
= rect
.ToRECT();
1678 return draw_theme_(theme
, hdc
, part_id
, state_id
, &bounds
, NULL
);
1682 NativeThemeWin::ThemeName
NativeThemeWin::GetThemeName(Part part
) {
1688 case kInnerSpinButton
:
1692 case kMenuPopupArrow
:
1693 case kMenuPopupGutter
:
1694 case kMenuPopupSeparator
:
1698 case kScrollbarDownArrow
:
1699 case kScrollbarLeftArrow
:
1700 case kScrollbarRightArrow
:
1701 case kScrollbarUpArrow
:
1702 case kScrollbarHorizontalThumb
:
1703 case kScrollbarVerticalThumb
:
1704 case kScrollbarHorizontalTrack
:
1705 case kScrollbarVerticalTrack
:
1712 case kWindowResizeGripper
:
1714 case kComboboxArrow
:
1715 case kMenuCheckBackground
:
1716 case kMenuPopupBackground
:
1717 case kMenuItemBackground
:
1718 case kScrollbarHorizontalGripper
:
1719 case kScrollbarVerticalGripper
:
1720 case kScrollbarCorner
:
1721 case kTabPanelBackground
:
1722 case kTrackbarThumb
:
1723 case kTrackbarTrack
:
1731 int NativeThemeWin::GetWindowsPart(Part part
,
1733 const ExtraParams
& extra
) {
1738 return MENU_POPUPCHECK
;
1739 case kMenuPopupArrow
:
1740 return MENU_POPUPSUBMENU
;
1741 case kMenuPopupGutter
:
1742 return MENU_POPUPGUTTER
;
1743 case kMenuPopupSeparator
:
1744 return MENU_POPUPSEPARATOR
;
1746 return BP_PUSHBUTTON
;
1748 return BP_RADIOBUTTON
;
1749 case kScrollbarDownArrow
:
1750 case kScrollbarLeftArrow
:
1751 case kScrollbarRightArrow
:
1752 case kScrollbarUpArrow
:
1753 return SBP_ARROWBTN
;
1754 case kScrollbarHorizontalThumb
:
1755 return SBP_THUMBBTNHORZ
;
1756 case kScrollbarVerticalThumb
:
1757 return SBP_THUMBBTNVERT
;
1758 case kWindowResizeGripper
:
1760 case kComboboxArrow
:
1761 case kInnerSpinButton
:
1763 case kMenuCheckBackground
:
1764 case kMenuPopupBackground
:
1765 case kMenuItemBackground
:
1767 case kScrollbarHorizontalTrack
:
1768 case kScrollbarVerticalTrack
:
1769 case kScrollbarHorizontalGripper
:
1770 case kScrollbarVerticalGripper
:
1771 case kScrollbarCorner
:
1774 case kTabPanelBackground
:
1776 case kTrackbarThumb
:
1777 case kTrackbarTrack
:
1784 int NativeThemeWin::GetWindowsState(Part part
,
1786 const ExtraParams
& extra
) {
1791 return CBS_UNCHECKEDDISABLED
;
1793 return CBS_UNCHECKEDHOT
;
1795 return CBS_UNCHECKEDNORMAL
;
1797 return CBS_UNCHECKEDPRESSED
;
1805 return extra
.menu_check
.is_radio
?
1806 MC_BULLETDISABLED
: MC_CHECKMARKDISABLED
;
1810 return extra
.menu_check
.is_radio
?
1811 MC_BULLETNORMAL
: MC_CHECKMARKNORMAL
;
1816 case kMenuPopupArrow
:
1817 case kMenuPopupGutter
:
1818 case kMenuPopupSeparator
:
1821 return MBI_DISABLED
;
1835 return PBS_DISABLED
;
1849 return RBS_UNCHECKEDDISABLED
;
1851 return RBS_UNCHECKEDHOT
;
1853 return RBS_UNCHECKEDNORMAL
;
1855 return RBS_UNCHECKEDPRESSED
;
1860 case kScrollbarDownArrow
:
1863 return ABS_DOWNDISABLED
;
1865 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1866 return base::win::GetVersion() < base::win::VERSION_VISTA
?
1867 ABS_DOWNHOT
: ABS_DOWNHOVER
;
1869 return ABS_DOWNNORMAL
;
1871 return ABS_DOWNPRESSED
;
1876 case kScrollbarLeftArrow
:
1879 return ABS_LEFTDISABLED
;
1881 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1882 return base::win::GetVersion() < base::win::VERSION_VISTA
?
1883 ABS_LEFTHOT
: ABS_LEFTHOVER
;
1885 return ABS_LEFTNORMAL
;
1887 return ABS_LEFTPRESSED
;
1892 case kScrollbarRightArrow
:
1895 return ABS_RIGHTDISABLED
;
1897 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1898 return base::win::GetVersion() < base::win::VERSION_VISTA
?
1899 ABS_RIGHTHOT
: ABS_RIGHTHOVER
;
1901 return ABS_RIGHTNORMAL
;
1903 return ABS_RIGHTPRESSED
;
1909 case kScrollbarUpArrow
:
1912 return ABS_UPDISABLED
;
1914 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1915 return base::win::GetVersion() < base::win::VERSION_VISTA
?
1916 ABS_UPHOT
: ABS_UPHOVER
;
1918 return ABS_UPNORMAL
;
1920 return ABS_UPPRESSED
;
1926 case kScrollbarHorizontalThumb
:
1927 case kScrollbarVerticalThumb
:
1930 return SCRBS_DISABLED
;
1932 // Mimic WebKit's behaviour in ScrollbarThemeChromiumWin.cpp.
1933 return base::win::GetVersion() < base::win::VERSION_VISTA
?
1934 SCRBS_HOT
: SCRBS_HOVER
;
1936 return SCRBS_NORMAL
;
1938 return SCRBS_PRESSED
;
1943 case kWindowResizeGripper
:
1949 return 1; // gripper has no windows state
1954 case kComboboxArrow
:
1955 case kInnerSpinButton
:
1957 case kMenuCheckBackground
:
1958 case kMenuPopupBackground
:
1959 case kMenuItemBackground
:
1961 case kScrollbarHorizontalTrack
:
1962 case kScrollbarVerticalTrack
:
1963 case kScrollbarHorizontalGripper
:
1964 case kScrollbarVerticalGripper
:
1965 case kScrollbarCorner
:
1968 case kTabPanelBackground
:
1970 case kTrackbarThumb
:
1971 case kTrackbarTrack
:
1978 HRESULT
NativeThemeWin::GetThemeInt(ThemeName theme
,
1983 HANDLE handle
= GetThemeHandle(theme
);
1984 return (handle
&& get_theme_int_
) ?
1985 get_theme_int_(handle
, part_id
, state_id
, prop_id
, value
) : E_NOTIMPL
;
1988 HRESULT
NativeThemeWin::PaintFrameControl(HDC hdc
,
1989 const gfx::Rect
& rect
,
1993 State control_state
) const {
1994 const int width
= rect
.width();
1995 const int height
= rect
.height();
1997 // DrawFrameControl for menu arrow/check wants a monochrome bitmap.
1998 base::win::ScopedBitmap
mask_bitmap(CreateBitmap(width
, height
, 1, 1, NULL
));
2000 if (mask_bitmap
== NULL
)
2001 return E_OUTOFMEMORY
;
2003 base::win::ScopedCreateDC
bitmap_dc(CreateCompatibleDC(NULL
));
2004 base::win::ScopedSelectObject
select_bitmap(bitmap_dc
.Get(), mask_bitmap
);
2005 RECT local_rect
= { 0, 0, width
, height
};
2006 DrawFrameControl(bitmap_dc
.Get(), &local_rect
, type
, state
);
2008 // We're going to use BitBlt with a b&w mask. This results in using the dest
2009 // dc's text color for the black bits in the mask, and the dest dc's
2010 // background color for the white bits in the mask. DrawFrameControl draws the
2011 // check in black, and the background in white.
2012 int bg_color_key
= COLOR_MENU
;
2013 int text_color_key
= COLOR_MENUTEXT
;
2014 switch (control_state
) {
2016 bg_color_key
= is_selected
? COLOR_HIGHLIGHT
: COLOR_MENU
;
2017 text_color_key
= COLOR_GRAYTEXT
;
2020 bg_color_key
= COLOR_HIGHLIGHT
;
2021 text_color_key
= COLOR_HIGHLIGHTTEXT
;
2030 COLORREF old_bg_color
= SetBkColor(hdc
, GetSysColor(bg_color_key
));
2031 COLORREF old_text_color
= SetTextColor(hdc
, GetSysColor(text_color_key
));
2032 BitBlt(hdc
, rect
.x(), rect
.y(), width
, height
, bitmap_dc
.Get(), 0, 0,
2034 SetBkColor(hdc
, old_bg_color
);
2035 SetTextColor(hdc
, old_text_color
);
2040 HANDLE
NativeThemeWin::GetThemeHandle(ThemeName theme_name
) const {
2041 if (!open_theme_
|| theme_name
< 0 || theme_name
>= LAST
)
2044 if (theme_handles_
[theme_name
])
2045 return theme_handles_
[theme_name
];
2047 // Not found, try to load it.
2049 switch (theme_name
) {
2051 handle
= open_theme_(NULL
, L
"Button");
2054 handle
= open_theme_(NULL
, L
"Listview");
2057 handle
= open_theme_(NULL
, L
"Menu");
2060 handle
= open_theme_(NULL
, L
"Combobox");
2063 handle
= open_theme_(NULL
, L
"Scrollbar");
2066 handle
= open_theme_(NULL
, L
"Status");
2069 handle
= open_theme_(NULL
, L
"Tab");
2072 handle
= open_theme_(NULL
, L
"Edit");
2075 handle
= open_theme_(NULL
, L
"Trackbar");
2078 handle
= open_theme_(NULL
, L
"Window");
2081 handle
= open_theme_(NULL
, L
"Progress");
2084 handle
= open_theme_(NULL
, L
"Spin");
2090 theme_handles_
[theme_name
] = handle
;