Add ICU message format support
[chromium-blink-merge.git] / ui / native_theme / native_theme_win.cc
blob0ffcbd1018c40d5f56fc518d7808bea83c96e25d
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"
7 #include <windows.h>
8 #include <uxtheme.h>
9 #include <vsstyle.h>
10 #include <vssym32.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
36 #endif
38 namespace {
40 // Windows system color IDs cached and updated by the native theme.
41 const int kSystemColors[] = {
42 COLOR_3DFACE,
43 COLOR_BTNTEXT,
44 COLOR_GRAYTEXT,
45 COLOR_HIGHLIGHT,
46 COLOR_HIGHLIGHTTEXT,
47 COLOR_SCROLLBAR,
48 COLOR_WINDOW,
49 COLOR_WINDOWTEXT,
50 COLOR_BTNFACE,
51 COLOR_MENUHIGHLIGHT,
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);
66 SkBitmap temp_bitmap;
67 temp_bitmap.installPixels(info, buffer, info.minRowBytes());
68 SkBitmap bitmap;
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,
79 &local_matrix));
80 paint->setShader(shader.get());
83 // <-a->
84 // [ ***** ]
85 // ____ | |
86 // <-a-> <------b----->
87 // a: object_width
88 // b: frame_width
89 // *: animating object
91 // - the animation goes from "[" to "]" repeatedly.
92 // - the animation offset is at first "|"
94 int ComputeAnimationProgress(int frame_width,
95 int object_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();
110 } // namespace
112 namespace ui {
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_;
121 HIGHCONTRAST result;
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,
131 int part_id,
132 int state_id,
133 int prop_id,
134 SkColor* color) const {
135 HANDLE handle = GetThemeHandle(theme);
136 if (!handle || !get_theme_color_)
137 return E_NOTIMPL;
138 COLORREF color_ref;
139 if (get_theme_color_(handle, part_id, state_id, prop_id, &color_ref) != S_OK)
140 return E_NOTIMPL;
141 *color = skia::COLORREFToSkColor(color_ref);
142 return S_OK;
145 SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme,
146 int part_id,
147 int state_id,
148 int prop_id,
149 int default_sys_color) const {
150 SkColor color;
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.
158 int border;
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 {
170 if (!close_theme_)
171 return;
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);
185 // static
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,
192 State state,
193 const ExtraParams& extra) const {
194 gfx::Size part_size = CommonThemeGetPartSize(part, state, extra);
195 if (!part_size.IsEmpty())
196 return part_size;
198 // The GetThemePartSize call below returns the default size without
199 // accounting for user customization (crbug/218291).
200 switch (part) {
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);
210 if (size == 0)
211 size = 17;
212 return gfx::Size(size, size);
214 default:
215 break;
218 int part_id = GetWindowsPart(part, state, extra);
219 int state_id = GetWindowsState(part, state, extra);
221 base::win::ScopedGetDC screen_dc(NULL);
222 SIZE size;
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
229 // if/when needed.
230 return (part == kCheckbox || part == kRadio) ?
231 gfx::Size(13, 13) : gfx::Size();
234 void NativeThemeWin::Paint(SkCanvas* canvas,
235 Part part,
236 State state,
237 const gfx::Rect& rect,
238 const ExtraParams& extra) const {
239 if (rect.IsEmpty())
240 return;
242 switch (part) {
243 case kComboboxArrow:
244 CommonThemePaintComboboxArrow(canvas, rect);
245 return;
246 case kMenuPopupGutter:
247 CommonThemePaintMenuGutter(canvas, rect);
248 return;
249 case kMenuPopupSeparator:
250 CommonThemePaintMenuSeparator(canvas, rect);
251 return;
252 case kMenuPopupBackground:
253 CommonThemePaintMenuBackground(canvas, rect);
254 return;
255 case kMenuItemBackground:
256 CommonThemePaintMenuItemBackground(canvas, state, rect);
257 return;
258 default:
259 break;
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;
266 } else {
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
271 // fixed.
272 switch (part) {
273 case kScrollbarDownArrow:
274 case kScrollbarUpArrow:
275 case kScrollbarLeftArrow:
276 case kScrollbarRightArrow:
277 needs_paint_indirect = !GetThemeHandle(SCROLLBAR);
278 break;
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;
285 break;
286 default:
287 break;
291 if (needs_paint_indirect)
292 PaintIndirect(canvas, part, state, rect, extra);
293 else
294 PaintDirect(canvas, part, state, rect, extra);
297 NativeThemeWin::NativeThemeWin()
298 : draw_theme_(NULL),
299 draw_theme_ex_(NULL),
300 get_theme_color_(NULL),
301 get_theme_content_rect_(NULL),
302 get_theme_part_size_(NULL),
303 open_theme_(NULL),
304 close_theme_(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) {
312 if (theme_dll_) {
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() {
341 if (theme_dll_) {
342 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks
343 // certain tests and the reliability bots.
344 // CloseHandles();
345 FreeLibrary(theme_dll_);
349 void NativeThemeWin::OnSysColorChange() {
350 UpdateSystemColors();
351 is_using_high_contrast_valid_ = false;
352 NotifyObservers();
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,
363 Part part,
364 State state,
365 const gfx::Rect& rect,
366 const ExtraParams& extra) const {
367 skia::ScopedPlatformPaint scoped_platform_paint(canvas);
368 HDC hdc = scoped_platform_paint.GetPlatformSurface();
370 switch (part) {
371 case kCheckbox:
372 PaintCheckbox(hdc, part, state, rect, extra.button);
373 return;
374 case kInnerSpinButton:
375 PaintSpinButton(hdc, part, state, rect, extra.inner_spin);
376 return;
377 case kMenuList:
378 PaintMenuList(hdc, state, rect, extra.menu_list);
379 return;
380 case kMenuCheck:
381 PaintMenuCheck(hdc, state, rect, extra.menu_check);
382 return;
383 case kMenuCheckBackground:
384 PaintMenuCheckBackground(hdc, state, rect);
385 return;
386 case kMenuPopupArrow:
387 PaintMenuArrow(hdc, state, rect, extra.menu_arrow);
388 return;
389 case kMenuPopupBackground:
390 PaintMenuBackground(hdc, rect);
391 return;
392 case kMenuPopupGutter:
393 PaintMenuGutter(hdc, rect);
394 return;
395 case kMenuPopupSeparator:
396 PaintMenuSeparator(hdc, rect);
397 return;
398 case kMenuItemBackground:
399 PaintMenuItemBackground(hdc, state, rect, extra.menu_item);
400 return;
401 case kProgressBar:
402 PaintProgressBar(hdc, rect, extra.progress_bar);
403 return;
404 case kPushButton:
405 PaintPushButton(hdc, part, state, rect, extra.button);
406 return;
407 case kRadio:
408 PaintRadioButton(hdc, part, state, rect, extra.button);
409 return;
410 case kScrollbarDownArrow:
411 case kScrollbarUpArrow:
412 case kScrollbarLeftArrow:
413 case kScrollbarRightArrow:
414 PaintScrollbarArrow(hdc, part, state, rect, extra.scrollbar_arrow);
415 return;
416 case kScrollbarHorizontalThumb:
417 case kScrollbarVerticalThumb:
418 case kScrollbarHorizontalGripper:
419 case kScrollbarVerticalGripper:
420 PaintScrollbarThumb(hdc, part, state, rect, extra.scrollbar_thumb);
421 return;
422 case kScrollbarHorizontalTrack:
423 case kScrollbarVerticalTrack:
424 PaintScrollbarTrack(canvas, hdc, part, state, rect,
425 extra.scrollbar_track);
426 return;
427 case kScrollbarCorner:
428 canvas->drawColor(SK_ColorWHITE, SkXfermode::kSrc_Mode);
429 return;
430 case kTabPanelBackground:
431 PaintTabPanelBackground(hdc, rect);
432 return;
433 case kTextField:
434 PaintTextField(hdc, part, state, rect, extra.text_field);
435 return;
436 case kTrackbarThumb:
437 case kTrackbarTrack:
438 PaintTrackbar(canvas, hdc, part, state, rect, extra.trackbar);
439 return;
440 case kWindowResizeGripper:
441 PaintWindowResizeGripper(hdc, rect);
442 return;
443 case kComboboxArrow:
444 case kSliderTrack:
445 case kSliderThumb:
446 case kMaxPart:
447 NOTREACHED();
451 SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const {
452 SkColor color;
453 if (CommonThemeGetSystemColor(color_id, &color))
454 return 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);
459 // Dialogs:
460 const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251);
461 // FocusableBorder:
462 const SkColor kFocusedBorderColor = SkColorSetRGB(0x4d, 0x90, 0xfe);
463 const SkColor kUnfocusedBorderColor = SkColorSetRGB(0xd9, 0xd9, 0xd9);
464 // Button:
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);
469 // MenuItem:
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);
474 // Table:
475 const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43);
476 const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29);
478 switch (color_id) {
479 // Windows
480 case kColorId_WindowBackground:
481 return system_colors_[COLOR_WINDOW];
483 // Dialogs
484 case kColorId_DialogBackground:
485 return color_utils::IsInvertedColorScheme() ?
486 color_utils::InvertColor(kDialogBackgroundColor) :
487 kDialogBackgroundColor;
489 // FocusableBorder
490 case kColorId_FocusedBorderColor:
491 return kFocusedBorderColor;
492 case kColorId_UnfocusedBorderColor:
493 return kUnfocusedBorderColor;
495 // Button
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:
512 NOTREACHED();
513 return kInvalidColorIdColor;
515 // MenuItem
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:
530 NOTREACHED();
531 return kInvalidColorIdColor;
533 // MenuButton
534 case kColorId_EnabledMenuButtonBorderColor:
535 case kColorId_FocusedMenuButtonBorderColor:
536 case kColorId_HoverMenuButtonBorderColor:
537 NOTREACHED();
538 return kInvalidColorIdColor;
540 // Label
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];
548 // Textfield
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];
562 // Tooltip
563 case kColorId_TooltipBackground:
564 case kColorId_TooltipText:
565 NOTREACHED();
566 return kInvalidColorIdColor;
568 // Tree
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];
586 // Table
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];
603 // Results Tables
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(
634 kUrlTextColor,
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(
654 kPositiveTextColor,
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(
664 kNegativeTextColor,
665 GetSystemColor(kColorId_ResultsTableHoveredBackground));
666 case kColorId_ResultsTableNegativeSelectedText:
667 return color_utils::GetReadableColor(kNegativeTextColor,
668 system_colors_[COLOR_HIGHLIGHT]);
669 default:
670 NOTREACHED();
671 return kInvalidColorIdColor;
675 void NativeThemeWin::PaintIndirect(SkCanvas* canvas,
676 Part part,
677 State state,
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));
689 DCHECK(device);
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);
706 switch (part) {
707 case kProgressBar:
708 adjusted_extra.progress_bar.value_rect_x = 0;
709 adjusted_extra.progress_bar.value_rect_y = 0;
710 break;
711 case kScrollbarHorizontalTrack:
712 case kScrollbarVerticalTrack:
713 adjusted_extra.scrollbar_track.track_x = 0;
714 adjusted_extra.scrollbar_track.track_y = 0;
715 break;
716 default:
717 break;
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);
726 SkBitmap bitmap;
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,
751 HDC hdc,
752 int part_id,
753 int state_id,
754 RECT* rect,
755 int ts,
756 SIZE* size) const {
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) :
760 E_NOTIMPL;
763 HRESULT NativeThemeWin::PaintButton(HDC hdc,
764 State state,
765 const ButtonExtraParams& extra,
766 int part_id,
767 int state_id,
768 RECT* rect) const {
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;
775 switch (part_id) {
776 case BP_CHECKBOX:
777 classic_state |= DFCS_BUTTONCHECK;
778 break;
779 case BP_RADIOBUTTON:
780 classic_state |= DFCS_BUTTONRADIO;
781 break;
782 case BP_PUSHBUTTON:
783 classic_state |= DFCS_BUTTONPUSH;
784 break;
785 default:
786 NOTREACHED();
787 break;
790 switch (state) {
791 case kDisabled:
792 classic_state |= DFCS_INACTIVE;
793 break;
794 case kHovered:
795 case kNormal:
796 break;
797 case kPressed:
798 classic_state |= DFCS_PUSHED;
799 break;
800 case kNumStates:
801 NOTREACHED();
802 break;
805 if (extra.checked)
806 classic_state |= DFCS_CHECKED;
808 // Draw it manually.
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);
816 if (brush) {
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);
830 } else {
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));
848 return S_OK;
851 HRESULT NativeThemeWin::PaintMenuSeparator(
852 HDC hdc,
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.
859 --rect_win.top;
860 --rect_win.bottom;
861 return draw_theme_(handle, hdc, MENU_POPUPSEPARATOR, MPI_NORMAL, &rect_win,
862 NULL);
865 DrawEdge(hdc, &rect_win, EDGE_ETCHED, BF_TOP);
866 return S_OK;
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) :
875 E_NOTIMPL;
878 HRESULT NativeThemeWin::PaintMenuArrow(
879 HDC hdc,
880 State state,
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,
892 NULL);
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.
898 gfx::Rect r(rect);
899 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc));
900 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(),
901 r.height()));
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);
907 // Draw the arrow.
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);
914 return result;
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,
921 state);
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,
930 &rect_win, NULL);
931 FrameRect(hdc, &rect_win, GetSysColorBrush(COLOR_3DSHADOW));
932 return result;
935 FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_MENU));
936 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT);
937 return S_OK;
940 HRESULT NativeThemeWin::PaintMenuCheck(
941 HDC hdc,
942 State state,
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,
960 State state,
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,
969 &rect_win, NULL);
972 HRESULT NativeThemeWin::PaintMenuItemBackground(
973 HDC hdc,
974 State state,
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;
980 switch (state) {
981 case kDisabled:
982 state_id = extra.is_selected ? MPI_DISABLEDHOT : MPI_DISABLED;
983 break;
984 case kHovered:
985 state_id = MPI_HOT;
986 break;
987 case kNormal:
988 break;
989 case kPressed:
990 case kNumStates:
991 NOTREACHED();
992 break;
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));
1000 return S_OK;
1003 HRESULT NativeThemeWin::PaintPushButton(HDC hdc,
1004 Part part,
1005 State state,
1006 const gfx::Rect& rect,
1007 const ButtonExtraParams& extra) const {
1008 int state_id = extra.is_default ? PBS_DEFAULTED : PBS_NORMAL;
1009 switch (state) {
1010 case kDisabled:
1011 state_id = PBS_DISABLED;
1012 break;
1013 case kHovered:
1014 state_id = PBS_HOT;
1015 break;
1016 case kNormal:
1017 break;
1018 case kPressed:
1019 state_id = PBS_PRESSED;
1020 break;
1021 case kNumStates:
1022 NOTREACHED();
1023 break;
1026 RECT rect_win = rect.ToRECT();
1027 return PaintButton(hdc, state, extra, BP_PUSHBUTTON, state_id, &rect_win);
1030 HRESULT NativeThemeWin::PaintRadioButton(HDC hdc,
1031 Part part,
1032 State state,
1033 const gfx::Rect& rect,
1034 const ButtonExtraParams& extra) const {
1035 int state_id = extra.checked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL;
1036 switch (state) {
1037 case kDisabled:
1038 state_id = extra.checked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED;
1039 break;
1040 case kHovered:
1041 state_id = extra.checked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT;
1042 break;
1043 case kNormal:
1044 break;
1045 case kPressed:
1046 state_id = extra.checked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED;
1047 break;
1048 case kNumStates:
1049 NOTREACHED();
1050 break;
1053 RECT rect_win = rect.ToRECT();
1054 return PaintButton(hdc, state, extra, BP_RADIOBUTTON, state_id, &rect_win);
1057 HRESULT NativeThemeWin::PaintCheckbox(HDC hdc,
1058 Part part,
1059 State state,
1060 const gfx::Rect& rect,
1061 const ButtonExtraParams& extra) const {
1062 int state_id = extra.checked ?
1063 CBS_CHECKEDNORMAL :
1064 (extra.indeterminate ? CBS_MIXEDNORMAL : CBS_UNCHECKEDNORMAL);
1065 switch (state) {
1066 case kDisabled:
1067 state_id = extra.checked ?
1068 CBS_CHECKEDDISABLED :
1069 (extra.indeterminate ? CBS_MIXEDDISABLED : CBS_UNCHECKEDDISABLED);
1070 break;
1071 case kHovered:
1072 state_id = extra.checked ?
1073 CBS_CHECKEDHOT :
1074 (extra.indeterminate ? CBS_MIXEDHOT : CBS_UNCHECKEDHOT);
1075 break;
1076 case kNormal:
1077 break;
1078 case kPressed:
1079 state_id = extra.checked ?
1080 CBS_CHECKEDPRESSED :
1081 (extra.indeterminate ? CBS_MIXEDPRESSED : CBS_UNCHECKEDPRESSED);
1082 break;
1083 case kNumStates:
1084 NOTREACHED();
1085 break;
1088 RECT rect_win = rect.ToRECT();
1089 return PaintButton(hdc, state, extra, BP_CHECKBOX, state_id, &rect_win);
1092 HRESULT NativeThemeWin::PaintMenuList(HDC hdc,
1093 State state,
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;
1099 switch (state) {
1100 case kDisabled:
1101 state_id = CBXS_DISABLED;
1102 break;
1103 case kHovered:
1104 state_id = CBXS_HOT;
1105 break;
1106 case kNormal:
1107 break;
1108 case kPressed:
1109 state_id = CBXS_PRESSED;
1110 break;
1111 case kNumStates:
1112 NOTREACHED();
1113 break;
1116 if (handle && draw_theme_)
1117 return draw_theme_(handle, hdc, CP_DROPDOWNBUTTON, state_id, &rect_win,
1118 NULL);
1120 // Draw it manually.
1121 DrawFrameControl(hdc, &rect_win, DFC_SCROLL,
1122 DFCS_SCROLLCOMBOBOX | extra.classic_state);
1123 return S_OK;
1126 HRESULT NativeThemeWin::PaintScrollbarArrow(
1127 HDC hdc,
1128 Part part,
1129 State state,
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
1148 // in "hover" mode.
1149 if (state == kHovered && extra.is_hovering) {
1150 switch (part) {
1151 case kScrollbarDownArrow:
1152 state_id = ABS_DOWNHOVER;
1153 break;
1154 case kScrollbarLeftArrow:
1155 state_id = ABS_LEFTHOVER;
1156 break;
1157 case kScrollbarRightArrow:
1158 state_id = ABS_RIGHTHOVER;
1159 break;
1160 case kScrollbarUpArrow:
1161 state_id = ABS_UPHOVER;
1162 break;
1163 default:
1164 NOTREACHED();
1165 break;
1168 return PaintScaledTheme(handle, hdc, SBP_ARROWBTN, state_id, rect);
1171 int classic_state = DFCS_SCROLLDOWN;
1172 switch (part) {
1173 case kScrollbarDownArrow:
1174 break;
1175 case kScrollbarLeftArrow:
1176 classic_state = DFCS_SCROLLLEFT;
1177 break;
1178 case kScrollbarRightArrow:
1179 classic_state = DFCS_SCROLLRIGHT;
1180 break;
1181 case kScrollbarUpArrow:
1182 classic_state = DFCS_SCROLLUP;
1183 break;
1184 default:
1185 NOTREACHED();
1186 break;
1188 switch (state) {
1189 case kDisabled:
1190 classic_state |= DFCS_INACTIVE;
1191 break;
1192 case kHovered:
1193 classic_state |= DFCS_HOT;
1194 break;
1195 case kNormal:
1196 break;
1197 case kPressed:
1198 classic_state |= DFCS_PUSHED;
1199 break;
1200 case kNumStates:
1201 NOTREACHED();
1202 break;
1204 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, classic_state);
1205 return S_OK;
1208 HRESULT NativeThemeWin::PaintScrollbarThumb(
1209 HDC hdc,
1210 Part part,
1211 State state,
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;
1218 switch (part) {
1219 case kScrollbarHorizontalThumb:
1220 part_id = SBP_THUMBBTNHORZ;
1221 break;
1222 case kScrollbarVerticalThumb:
1223 break;
1224 case kScrollbarHorizontalGripper:
1225 part_id = SBP_GRIPPERHORZ;
1226 break;
1227 case kScrollbarVerticalGripper:
1228 part_id = SBP_GRIPPERVERT;
1229 break;
1230 default:
1231 NOTREACHED();
1232 break;
1235 int state_id = SCRBS_NORMAL;
1236 switch (state) {
1237 case kDisabled:
1238 state_id = SCRBS_DISABLED;
1239 break;
1240 case kHovered:
1241 state_id = extra.is_hovering ? SCRBS_HOVER : SCRBS_HOT;
1242 break;
1243 case kNormal:
1244 break;
1245 case kPressed:
1246 state_id = SCRBS_PRESSED;
1247 break;
1248 case kNumStates:
1249 NOTREACHED();
1250 break;
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.
1260 return S_OK;
1263 HRESULT NativeThemeWin::PaintScrollbarTrack(
1264 SkCanvas* canvas,
1265 HDC hdc,
1266 Part part,
1267 State state,
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;
1280 switch (state) {
1281 case kDisabled:
1282 state_id = SCRBS_DISABLED;
1283 break;
1284 case kHovered:
1285 state_id = SCRBS_HOVER;
1286 break;
1287 case kNormal:
1288 break;
1289 case kPressed:
1290 state_id = SCRBS_PRESSED;
1291 break;
1292 case kNumStates:
1293 NOTREACHED();
1294 break;
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));
1304 } else {
1305 SkPaint paint;
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);
1313 return S_OK;
1316 HRESULT NativeThemeWin::PaintSpinButton(
1317 HDC hdc,
1318 Part part,
1319 State state,
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;
1326 switch (state) {
1327 case kDisabled:
1328 state_id = extra.spin_up ? UPS_DISABLED : DNS_DISABLED;
1329 break;
1330 case kHovered:
1331 state_id = extra.spin_up ? UPS_HOT : DNS_HOT;
1332 break;
1333 case kNormal:
1334 break;
1335 case kPressed:
1336 state_id = extra.spin_up ? UPS_PRESSED : DNS_PRESSED;
1337 break;
1338 case kNumStates:
1339 NOTREACHED();
1340 break;
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);
1346 return S_OK;
1349 HRESULT NativeThemeWin::PaintTrackbar(
1350 SkCanvas* canvas,
1351 HDC hdc,
1352 Part part,
1353 State state,
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;
1361 switch (state) {
1362 case kDisabled:
1363 state_id = TUS_DISABLED;
1364 break;
1365 case kHovered:
1366 state_id = TUS_HOT;
1367 break;
1368 case kNormal:
1369 break;
1370 case kPressed:
1371 state_id = TUS_PRESSED;
1372 break;
1373 case kNumStates:
1374 NOTREACHED();
1375 break;
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) {
1385 channel_rect.top +=
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);
1403 } else {
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) {
1424 SkPaint paint;
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);
1452 return S_OK;
1455 HRESULT NativeThemeWin::PaintProgressBar(
1456 HDC hdc,
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,
1472 extra.value_rect_y,
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);
1481 return S_OK;
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;
1500 if (pre_vista) {
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);
1504 } else {
1505 draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, &bar_rect);
1507 return S_OK;
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 = {
1514 sizeof(DTBGOPTS),
1515 (bar_rect.right == value_rect.right && bar_rect.left != value_rect.left) ?
1516 DTBG_MIRRORDC : 0u,
1517 bar_rect
1519 if (pre_vista) {
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);
1526 } else {
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);
1539 return S_OK;
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);
1555 return S_OK;
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));
1567 return S_OK;
1570 HRESULT NativeThemeWin::PaintTextField(
1571 HDC hdc,
1572 Part part,
1573 State state,
1574 const gfx::Rect& rect,
1575 const TextFieldExtraParams& extra) const {
1576 int state_id = ETS_NORMAL;
1577 switch (state) {
1578 case kDisabled:
1579 state_id = ETS_DISABLED;
1580 break;
1581 case kHovered:
1582 state_id = ETS_HOT;
1583 break;
1584 case kNormal:
1585 if (extra.is_read_only)
1586 state_id = ETS_READONLY;
1587 else if (extra.is_focused)
1588 state_id = ETS_FOCUSED;
1589 break;
1590 case kPressed:
1591 state_id = ETS_SELECTED;
1592 break;
1593 case kNumStates:
1594 NOTREACHED();
1595 break;
1598 RECT rect_win = rect.ToRECT();
1599 return PaintTextField(hdc, EP_EDITTEXT, state_id, extra.classic_state,
1600 &rect_win,
1601 skia::SkColorToCOLORREF(extra.background_color),
1602 extra.fill_content_area, extra.draw_edges);
1605 HRESULT NativeThemeWin::PaintTextField(HDC hdc,
1606 int part_id,
1607 int state_id,
1608 int classic_state,
1609 RECT* rect,
1610 COLORREF color,
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.
1625 if (draw_edges)
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);
1632 return S_OK;
1635 static const DTBGOPTS omit_border_options = {
1636 sizeof(DTBGOPTS),
1637 DTBG_OMITBORDER,
1638 { 0, 0, 0, 0 }
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_) {
1647 RECT content_rect;
1648 hr = get_theme_content_rect_(handle, hdc, part_id, state_id, rect,
1649 &content_rect);
1650 FillRect(hdc, &content_rect, bg_brush);
1652 return hr;
1655 HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme,
1656 HDC hdc,
1657 int part_id,
1658 int state_id,
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,
1672 NULL);
1673 SetWorldTransform(hdc, &save_transform);
1674 return result;
1677 RECT bounds = rect.ToRECT();
1678 return draw_theme_(theme, hdc, part_id, state_id, &bounds, NULL);
1681 // static
1682 NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) {
1683 switch (part) {
1684 case kCheckbox:
1685 case kPushButton:
1686 case kRadio:
1687 return BUTTON;
1688 case kInnerSpinButton:
1689 return SPIN;
1690 case kMenuList:
1691 case kMenuCheck:
1692 case kMenuPopupArrow:
1693 case kMenuPopupGutter:
1694 case kMenuPopupSeparator:
1695 return MENU;
1696 case kProgressBar:
1697 return PROGRESS;
1698 case kScrollbarDownArrow:
1699 case kScrollbarLeftArrow:
1700 case kScrollbarRightArrow:
1701 case kScrollbarUpArrow:
1702 case kScrollbarHorizontalThumb:
1703 case kScrollbarVerticalThumb:
1704 case kScrollbarHorizontalTrack:
1705 case kScrollbarVerticalTrack:
1706 return SCROLLBAR;
1707 case kSliderTrack:
1708 case kSliderThumb:
1709 return TRACKBAR;
1710 case kTextField:
1711 return TEXTFIELD;
1712 case kWindowResizeGripper:
1713 return STATUS;
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:
1724 case kMaxPart:
1725 NOTREACHED();
1727 return LAST;
1730 // static
1731 int NativeThemeWin::GetWindowsPart(Part part,
1732 State state,
1733 const ExtraParams& extra) {
1734 switch (part) {
1735 case kCheckbox:
1736 return BP_CHECKBOX;
1737 case kMenuCheck:
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;
1745 case kPushButton:
1746 return BP_PUSHBUTTON;
1747 case kRadio:
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:
1759 return SP_GRIPPER;
1760 case kComboboxArrow:
1761 case kInnerSpinButton:
1762 case kMenuList:
1763 case kMenuCheckBackground:
1764 case kMenuPopupBackground:
1765 case kMenuItemBackground:
1766 case kProgressBar:
1767 case kScrollbarHorizontalTrack:
1768 case kScrollbarVerticalTrack:
1769 case kScrollbarHorizontalGripper:
1770 case kScrollbarVerticalGripper:
1771 case kScrollbarCorner:
1772 case kSliderTrack:
1773 case kSliderThumb:
1774 case kTabPanelBackground:
1775 case kTextField:
1776 case kTrackbarThumb:
1777 case kTrackbarTrack:
1778 case kMaxPart:
1779 NOTREACHED();
1781 return 0;
1784 int NativeThemeWin::GetWindowsState(Part part,
1785 State state,
1786 const ExtraParams& extra) {
1787 switch (part) {
1788 case kCheckbox:
1789 switch (state) {
1790 case kDisabled:
1791 return CBS_UNCHECKEDDISABLED;
1792 case kHovered:
1793 return CBS_UNCHECKEDHOT;
1794 case kNormal:
1795 return CBS_UNCHECKEDNORMAL;
1796 case kPressed:
1797 return CBS_UNCHECKEDPRESSED;
1798 case kNumStates:
1799 NOTREACHED();
1800 return 0;
1802 case kMenuCheck:
1803 switch (state) {
1804 case kDisabled:
1805 return extra.menu_check.is_radio ?
1806 MC_BULLETDISABLED : MC_CHECKMARKDISABLED;
1807 case kHovered:
1808 case kNormal:
1809 case kPressed:
1810 return extra.menu_check.is_radio ?
1811 MC_BULLETNORMAL : MC_CHECKMARKNORMAL;
1812 case kNumStates:
1813 NOTREACHED();
1814 return 0;
1816 case kMenuPopupArrow:
1817 case kMenuPopupGutter:
1818 case kMenuPopupSeparator:
1819 switch (state) {
1820 case kDisabled:
1821 return MBI_DISABLED;
1822 case kHovered:
1823 return MBI_HOT;
1824 case kNormal:
1825 return MBI_NORMAL;
1826 case kPressed:
1827 return MBI_PUSHED;
1828 case kNumStates:
1829 NOTREACHED();
1830 return 0;
1832 case kPushButton:
1833 switch (state) {
1834 case kDisabled:
1835 return PBS_DISABLED;
1836 case kHovered:
1837 return PBS_HOT;
1838 case kNormal:
1839 return PBS_NORMAL;
1840 case kPressed:
1841 return PBS_PRESSED;
1842 case kNumStates:
1843 NOTREACHED();
1844 return 0;
1846 case kRadio:
1847 switch (state) {
1848 case kDisabled:
1849 return RBS_UNCHECKEDDISABLED;
1850 case kHovered:
1851 return RBS_UNCHECKEDHOT;
1852 case kNormal:
1853 return RBS_UNCHECKEDNORMAL;
1854 case kPressed:
1855 return RBS_UNCHECKEDPRESSED;
1856 case kNumStates:
1857 NOTREACHED();
1858 return 0;
1860 case kScrollbarDownArrow:
1861 switch (state) {
1862 case kDisabled:
1863 return ABS_DOWNDISABLED;
1864 case kHovered:
1865 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1866 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1867 ABS_DOWNHOT : ABS_DOWNHOVER;
1868 case kNormal:
1869 return ABS_DOWNNORMAL;
1870 case kPressed:
1871 return ABS_DOWNPRESSED;
1872 case kNumStates:
1873 NOTREACHED();
1874 return 0;
1876 case kScrollbarLeftArrow:
1877 switch (state) {
1878 case kDisabled:
1879 return ABS_LEFTDISABLED;
1880 case kHovered:
1881 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1882 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1883 ABS_LEFTHOT : ABS_LEFTHOVER;
1884 case kNormal:
1885 return ABS_LEFTNORMAL;
1886 case kPressed:
1887 return ABS_LEFTPRESSED;
1888 case kNumStates:
1889 NOTREACHED();
1890 return 0;
1892 case kScrollbarRightArrow:
1893 switch (state) {
1894 case kDisabled:
1895 return ABS_RIGHTDISABLED;
1896 case kHovered:
1897 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1898 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1899 ABS_RIGHTHOT : ABS_RIGHTHOVER;
1900 case kNormal:
1901 return ABS_RIGHTNORMAL;
1902 case kPressed:
1903 return ABS_RIGHTPRESSED;
1904 case kNumStates:
1905 NOTREACHED();
1906 return 0;
1908 break;
1909 case kScrollbarUpArrow:
1910 switch (state) {
1911 case kDisabled:
1912 return ABS_UPDISABLED;
1913 case kHovered:
1914 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1915 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1916 ABS_UPHOT : ABS_UPHOVER;
1917 case kNormal:
1918 return ABS_UPNORMAL;
1919 case kPressed:
1920 return ABS_UPPRESSED;
1921 case kNumStates:
1922 NOTREACHED();
1923 return 0;
1925 break;
1926 case kScrollbarHorizontalThumb:
1927 case kScrollbarVerticalThumb:
1928 switch (state) {
1929 case kDisabled:
1930 return SCRBS_DISABLED;
1931 case kHovered:
1932 // Mimic WebKit's behaviour in ScrollbarThemeChromiumWin.cpp.
1933 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1934 SCRBS_HOT : SCRBS_HOVER;
1935 case kNormal:
1936 return SCRBS_NORMAL;
1937 case kPressed:
1938 return SCRBS_PRESSED;
1939 case kNumStates:
1940 NOTREACHED();
1941 return 0;
1943 case kWindowResizeGripper:
1944 switch (state) {
1945 case kDisabled:
1946 case kHovered:
1947 case kNormal:
1948 case kPressed:
1949 return 1; // gripper has no windows state
1950 case kNumStates:
1951 NOTREACHED();
1952 return 0;
1954 case kComboboxArrow:
1955 case kInnerSpinButton:
1956 case kMenuList:
1957 case kMenuCheckBackground:
1958 case kMenuPopupBackground:
1959 case kMenuItemBackground:
1960 case kProgressBar:
1961 case kScrollbarHorizontalTrack:
1962 case kScrollbarVerticalTrack:
1963 case kScrollbarHorizontalGripper:
1964 case kScrollbarVerticalGripper:
1965 case kScrollbarCorner:
1966 case kSliderTrack:
1967 case kSliderThumb:
1968 case kTabPanelBackground:
1969 case kTextField:
1970 case kTrackbarThumb:
1971 case kTrackbarTrack:
1972 case kMaxPart:
1973 NOTREACHED();
1975 return 0;
1978 HRESULT NativeThemeWin::GetThemeInt(ThemeName theme,
1979 int part_id,
1980 int state_id,
1981 int prop_id,
1982 int *value) const {
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,
1990 UINT type,
1991 UINT state,
1992 bool is_selected,
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) {
2015 case kDisabled:
2016 bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU;
2017 text_color_key = COLOR_GRAYTEXT;
2018 break;
2019 case kHovered:
2020 bg_color_key = COLOR_HIGHLIGHT;
2021 text_color_key = COLOR_HIGHLIGHTTEXT;
2022 break;
2023 case kNormal:
2024 break;
2025 case kPressed:
2026 case kNumStates:
2027 NOTREACHED();
2028 break;
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,
2033 SRCCOPY);
2034 SetBkColor(hdc, old_bg_color);
2035 SetTextColor(hdc, old_text_color);
2037 return S_OK;
2040 HANDLE NativeThemeWin::GetThemeHandle(ThemeName theme_name) const {
2041 if (!open_theme_ || theme_name < 0 || theme_name >= LAST)
2042 return 0;
2044 if (theme_handles_[theme_name])
2045 return theme_handles_[theme_name];
2047 // Not found, try to load it.
2048 HANDLE handle = 0;
2049 switch (theme_name) {
2050 case BUTTON:
2051 handle = open_theme_(NULL, L"Button");
2052 break;
2053 case LIST:
2054 handle = open_theme_(NULL, L"Listview");
2055 break;
2056 case MENU:
2057 handle = open_theme_(NULL, L"Menu");
2058 break;
2059 case MENULIST:
2060 handle = open_theme_(NULL, L"Combobox");
2061 break;
2062 case SCROLLBAR:
2063 handle = open_theme_(NULL, L"Scrollbar");
2064 break;
2065 case STATUS:
2066 handle = open_theme_(NULL, L"Status");
2067 break;
2068 case TAB:
2069 handle = open_theme_(NULL, L"Tab");
2070 break;
2071 case TEXTFIELD:
2072 handle = open_theme_(NULL, L"Edit");
2073 break;
2074 case TRACKBAR:
2075 handle = open_theme_(NULL, L"Trackbar");
2076 break;
2077 case WINDOW:
2078 handle = open_theme_(NULL, L"Window");
2079 break;
2080 case PROGRESS:
2081 handle = open_theme_(NULL, L"Progress");
2082 break;
2083 case SPIN:
2084 handle = open_theme_(NULL, L"Spin");
2085 break;
2086 case LAST:
2087 NOTREACHED();
2088 break;
2090 theme_handles_[theme_name] = handle;
2091 return handle;
2094 } // namespace ui