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

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

Issue 11421204: Use native theme colors for textfields; etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nix cursor color; adjust textfield functions; add read-only theme colors. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/native_theme/native_theme_win.h" 5 #include "ui/native_theme/native_theme_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <uxtheme.h> 8 #include <uxtheme.h>
9 #include <vsstyle.h> 9 #include <vsstyle.h>
10 #include <vssym32.h> 10 #include <vssym32.h>
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 const SkColor kTextButtonBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde); 42 const SkColor kTextButtonBackgroundColor = SkColorSetRGB(0xde, 0xde, 0xde);
43 const SkColor kTextButtonEnabledColor = SkColorSetRGB(6, 45, 117); 43 const SkColor kTextButtonEnabledColor = SkColorSetRGB(6, 45, 117);
44 const SkColor kTextButtonDisabledColor = SkColorSetRGB(161, 161, 146); 44 const SkColor kTextButtonDisabledColor = SkColorSetRGB(161, 161, 146);
45 const SkColor kTextButtonHighlightColor = SkColorSetARGB(200, 255, 255, 255); 45 const SkColor kTextButtonHighlightColor = SkColorSetARGB(200, 255, 255, 255);
46 const SkColor kTextButtonHoverColor = kTextButtonEnabledColor; 46 const SkColor kTextButtonHoverColor = kTextButtonEnabledColor;
47 // MenuItem: 47 // MenuItem:
48 const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor; 48 const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor;
49 const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor; 49 const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor;
50 const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(246, 249, 253); 50 const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(246, 249, 253);
51 const SkColor kMenuSeparatorColor = SkColorSetARGB(50, 0, 0, 0); 51 const SkColor kMenuSeparatorColor = SkColorSetARGB(50, 0, 0, 0);
52 // Label:
53 const SkColor kLabelEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT);
54 const SkColor kLabelDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT);
55 const SkColor kLabelBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW);
56 // Textfield: 52 // Textfield:
57 const SkColor kTextfieldDefaultColor = SK_ColorBLACK;
58 const SkColor kTextfieldDefaultBackground = SK_ColorWHITE;
59 const SkColor kTextfieldSelectionColor = SK_ColorWHITE;
60 const SkColor kTextfieldSelectionBackgroundFocused =
61 SkColorSetRGB(0x1D, 0x90, 0xFF);
62 const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; 53 const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY;
63 54
64 SkColor WinColorToSkColor(COLORREF color) { 55 // Windows system color IDs cached and updated by the native theme.
65 return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); 56 const int kSystemColors[] = {
66 } 57 COLOR_3DFACE,
58 COLOR_GRAYTEXT,
59 COLOR_HIGHLIGHT,
60 COLOR_HIGHLIGHTTEXT,
61 COLOR_SCROLLBAR,
62 COLOR_WINDOW,
63 COLOR_WINDOWTEXT,
64 };
67 65
68 void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { 66 void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) {
69 // Create a 2x2 checkerboard pattern using the 3D face and highlight colors. 67 // Create a 2x2 checkerboard pattern using the 3D face and highlight colors.
70 SkColor face = skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)); 68 const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE);
71 SkColor highlight = skia::COLORREFToSkColor(GetSysColor(COLOR_3DHILIGHT)); 69 const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT);
72 SkColor buffer[] = { face, highlight, highlight, face }; 70 SkColor buffer[] = { face, highlight, highlight, face };
73 // Confusing bit: we first create a temporary bitmap with our desired pattern, 71 // Confusing bit: we first create a temporary bitmap with our desired pattern,
74 // then copy it to another bitmap. The temporary bitmap doesn't take 72 // then copy it to another bitmap. The temporary bitmap doesn't take
75 // ownership of the pixel data, and so will point to garbage when this 73 // ownership of the pixel data, and so will point to garbage when this
76 // function returns. The copy will copy the pixel data into a place owned by 74 // function returns. The copy will copy the pixel data into a place owned by
77 // the bitmap, which is in turn owned by the shader, etc., so it will live 75 // the bitmap, which is in turn owned by the shader, etc., so it will live
78 // until we're done using it. 76 // until we're done using it.
79 SkBitmap temp_bitmap; 77 SkBitmap temp_bitmap;
80 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2); 78 temp_bitmap.setConfig(SkBitmap::kARGB_8888_Config, 2, 2);
81 temp_bitmap.setPixels(buffer); 79 temp_bitmap.setPixels(buffer);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 return E_NOTIMPL; 145 return E_NOTIMPL;
148 } 146 }
149 147
150 SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme, 148 SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme,
151 int part_id, 149 int part_id,
152 int state_id, 150 int state_id,
153 int prop_id, 151 int prop_id,
154 int default_sys_color) const { 152 int default_sys_color) const {
155 SkColor color; 153 SkColor color;
156 if (GetThemeColor(theme, part_id, state_id, prop_id, &color) != S_OK) 154 if (GetThemeColor(theme, part_id, state_id, prop_id, &color) != S_OK)
157 color = skia::COLORREFToSkColor(GetSysColor(default_sys_color)); 155 color = color_utils::GetSysSkColor(default_sys_color);
158 return color; 156 return color;
159 } 157 }
160 158
161 gfx::Size NativeThemeWin::GetThemeBorderSize(ThemeName theme) const { 159 gfx::Size NativeThemeWin::GetThemeBorderSize(ThemeName theme) const {
162 // For simplicity use the wildcard state==0, part==0, since it works 160 // For simplicity use the wildcard state==0, part==0, since it works
163 // for the cases we currently depend on. 161 // for the cases we currently depend on.
164 int border; 162 int border;
165 if (GetThemeInt(theme, 0, 0, TMT_BORDERSIZE, &border) == S_OK) 163 if (GetThemeInt(theme, 0, 0, TMT_BORDERSIZE, &border) == S_OK)
166 return gfx::Size(border, border); 164 return gfx::Size(border, border);
167 else 165 else
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 close_theme_ = reinterpret_cast<CloseThemeDataPtr>( 321 close_theme_ = reinterpret_cast<CloseThemeDataPtr>(
324 GetProcAddress(theme_dll_, "CloseThemeData")); 322 GetProcAddress(theme_dll_, "CloseThemeData"));
325 set_theme_properties_ = reinterpret_cast<SetThemeAppPropertiesPtr>( 323 set_theme_properties_ = reinterpret_cast<SetThemeAppPropertiesPtr>(
326 GetProcAddress(theme_dll_, "SetThemeAppProperties")); 324 GetProcAddress(theme_dll_, "SetThemeAppProperties"));
327 is_theme_active_ = reinterpret_cast<IsThemeActivePtr>( 325 is_theme_active_ = reinterpret_cast<IsThemeActivePtr>(
328 GetProcAddress(theme_dll_, "IsThemeActive")); 326 GetProcAddress(theme_dll_, "IsThemeActive"));
329 get_theme_int_ = reinterpret_cast<GetThemeIntPtr>( 327 get_theme_int_ = reinterpret_cast<GetThemeIntPtr>(
330 GetProcAddress(theme_dll_, "GetThemeInt")); 328 GetProcAddress(theme_dll_, "GetThemeInt"));
331 } 329 }
332 memset(theme_handles_, 0, sizeof(theme_handles_)); 330 memset(theme_handles_, 0, sizeof(theme_handles_));
331 // Initialize the cached system colors.
332 OnSysColorChange();
sky 2012/12/04 22:38:14 I don't like calling a virtual method from a const
msw 2012/12/05 02:09:56 Done.
333 } 333 }
334 334
335 NativeThemeWin::~NativeThemeWin() { 335 NativeThemeWin::~NativeThemeWin() {
336 if (theme_dll_) { 336 if (theme_dll_) {
337 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks 337 // todo (cpu): fix this soon. Making a call to CloseHandles() here breaks
338 // certain tests and the reliability bots. 338 // certain tests and the reliability bots.
339 // CloseHandles(); 339 // CloseHandles();
340 FreeLibrary(theme_dll_); 340 FreeLibrary(theme_dll_);
341 } 341 }
342 } 342 }
343 343
344 void NativeThemeWin::OnSysColorChange() {
345 for (int i = 0; i < arraysize(kSystemColors); ++i)
sky 2012/12/04 22:38:14 nit: use {} for the for loop.
msw 2012/12/05 02:09:56 Done.
346 system_colors_[kSystemColors[i]] =
347 color_utils::GetSysSkColor(kSystemColors[i]);
348 }
349
344 void NativeThemeWin::PaintDirect(SkCanvas* canvas, 350 void NativeThemeWin::PaintDirect(SkCanvas* canvas,
345 Part part, 351 Part part,
346 State state, 352 State state,
347 const gfx::Rect& rect, 353 const gfx::Rect& rect,
348 const ExtraParams& extra) const { 354 const ExtraParams& extra) const {
349 skia::ScopedPlatformPaint scoped_platform_paint(canvas); 355 skia::ScopedPlatformPaint scoped_platform_paint(canvas);
350 HDC hdc = scoped_platform_paint.GetPlatformSurface(); 356 HDC hdc = scoped_platform_paint.GetPlatformSurface();
351 357
352 switch (part) { 358 switch (part) {
353 case kCheckbox: 359 case kCheckbox:
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 if (IsNewMenuStyleEnabled() && 440 if (IsNewMenuStyleEnabled() &&
435 CommonThemeGetSystemColor(color_id, &color)) { 441 CommonThemeGetSystemColor(color_id, &color)) {
436 return color; 442 return color;
437 } 443 }
438 444
439 switch (color_id) { 445 switch (color_id) {
440 // Dialogs 446 // Dialogs
441 case kColorId_DialogBackground: 447 case kColorId_DialogBackground:
442 // TODO(benrg): Should this use the new Windows theme functions? The old 448 // TODO(benrg): Should this use the new Windows theme functions? The old
443 // code in DialogClientView::OnPaint used GetSysColor(COLOR_3DFACE). 449 // code in DialogClientView::OnPaint used GetSysColor(COLOR_3DFACE).
444 return WinColorToSkColor(GetSysColor(COLOR_3DFACE)); 450 return system_colors_[COLOR_3DFACE];
445 451
446 // FocusableBorder 452 // FocusableBorder
447 case kColorId_FocusedBorderColor: 453 case kColorId_FocusedBorderColor:
448 return kFocusedBorderColor; 454 return kFocusedBorderColor;
449 case kColorId_UnfocusedBorderColor: 455 case kColorId_UnfocusedBorderColor:
450 return kUnfocusedBorderColor; 456 return kUnfocusedBorderColor;
451 457
452 // TextButton 458 // TextButton
453 case kColorId_TextButtonBackgroundColor: 459 case kColorId_TextButtonBackgroundColor:
454 return kTextButtonBackgroundColor; 460 return kTextButtonBackgroundColor;
(...skipping 11 matching lines...) Expand all
466 return kEnabledMenuItemForegroundColor; 472 return kEnabledMenuItemForegroundColor;
467 case kColorId_DisabledMenuItemForegroundColor: 473 case kColorId_DisabledMenuItemForegroundColor:
468 return kDisabledMenuItemForegroundColor; 474 return kDisabledMenuItemForegroundColor;
469 case kColorId_FocusedMenuItemBackgroundColor: 475 case kColorId_FocusedMenuItemBackgroundColor:
470 return kFocusedMenuItemBackgroundColor; 476 return kFocusedMenuItemBackgroundColor;
471 case kColorId_MenuSeparatorColor: 477 case kColorId_MenuSeparatorColor:
472 return kMenuSeparatorColor; 478 return kMenuSeparatorColor;
473 479
474 // Label 480 // Label
475 case kColorId_LabelEnabledColor: 481 case kColorId_LabelEnabledColor:
476 return kLabelEnabledColor; 482 return system_colors_[COLOR_WINDOWTEXT];
477 case kColorId_LabelDisabledColor: 483 case kColorId_LabelDisabledColor:
478 return kLabelDisabledColor; 484 return system_colors_[COLOR_GRAYTEXT];
479 case kColorId_LabelBackgroundColor: 485 case kColorId_LabelBackgroundColor:
480 return kLabelBackgroundColor; 486 return system_colors_[COLOR_WINDOW];
481 487
482 // Textfield 488 // Textfield
483 case kColorId_TextfieldDefaultColor: 489 case kColorId_TextfieldDefaultColor:
484 return kTextfieldDefaultColor; 490 return system_colors_[COLOR_WINDOWTEXT];
485 case kColorId_TextfieldDefaultBackground: 491 case kColorId_TextfieldDefaultBackground:
486 return kTextfieldDefaultBackground; 492 return system_colors_[COLOR_WINDOW];
493 case kColorId_TextfieldReadOnlyColor:
494 return system_colors_[COLOR_GRAYTEXT];
495 case kColorId_TextfieldReadOnlyBackground:
496 return system_colors_[COLOR_3DFACE];
487 case kColorId_TextfieldSelectionColor: 497 case kColorId_TextfieldSelectionColor:
488 return kTextfieldSelectionColor; 498 return system_colors_[COLOR_HIGHLIGHTTEXT];
489 case kColorId_TextfieldSelectionBackgroundFocused: 499 case kColorId_TextfieldSelectionBackgroundFocused:
490 return kTextfieldSelectionBackgroundFocused; 500 return system_colors_[COLOR_HIGHLIGHT];
491 case kColorId_TextfieldSelectionBackgroundUnfocused: 501 case kColorId_TextfieldSelectionBackgroundUnfocused:
492 return kTextfieldSelectionBackgroundUnfocused; 502 return kTextfieldSelectionBackgroundUnfocused;
493 503
494 default: 504 default:
495 NOTREACHED() << "Invalid color_id: " << color_id; 505 NOTREACHED() << "Invalid color_id: " << color_id;
496 break; 506 break;
497 } 507 }
498 return kInvalidColorIdColor; 508 return kInvalidColorIdColor;
499 } 509 }
500 510
(...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 break; 1146 break;
1137 default: 1147 default:
1138 NOTREACHED() << "Invalid state: " << state; 1148 NOTREACHED() << "Invalid state: " << state;
1139 break; 1149 break;
1140 } 1150 }
1141 1151
1142 if (handle && draw_theme_) 1152 if (handle && draw_theme_)
1143 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); 1153 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL);
1144 1154
1145 // Draw it manually. 1155 // Draw it manually.
1146 const DWORD colorScrollbar = GetSysColor(COLOR_SCROLLBAR); 1156 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) &&
1147 const DWORD color3DFace = GetSysColor(COLOR_3DFACE); 1157 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) {
1148 if ((colorScrollbar != color3DFace) &&
1149 (colorScrollbar != GetSysColor(COLOR_WINDOW))) {
1150 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); 1158 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1));
1151 } else { 1159 } else {
1152 SkPaint paint; 1160 SkPaint paint;
1153 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, 1161 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width,
1154 extra.track_height).ToRECT(); 1162 extra.track_height).ToRECT();
1155 SetCheckerboardShader(&paint, align_rect); 1163 SetCheckerboardShader(&paint, align_rect);
1156 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); 1164 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint);
1157 } 1165 }
1158 if (extra.classic_state & DFCS_PUSHED) 1166 if (extra.classic_state & DFCS_PUSHED)
1159 InvertRect(hdc, &rect_win); 1167 InvertRect(hdc, &rect_win);
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 handle = open_theme_(NULL, L"Spin"); 1966 handle = open_theme_(NULL, L"Spin");
1959 break; 1967 break;
1960 default: 1968 default:
1961 NOTREACHED(); 1969 NOTREACHED();
1962 } 1970 }
1963 theme_handles_[theme_name] = handle; 1971 theme_handles_[theme_name] = handle;
1964 return handle; 1972 return handle;
1965 } 1973 }
1966 1974
1967 } // namespace ui 1975 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698