Chromium Code Reviews| Index: ui/native_theme/native_theme_win.cc |
| diff --git a/ui/native_theme/native_theme_win.cc b/ui/native_theme/native_theme_win.cc |
| index 27a00a510c00e2a5355756b12b37a14e0d559b60..d59a86087978ca3e84d616b9a4c5b795b09ec585 100644 |
| --- a/ui/native_theme/native_theme_win.cc |
| +++ b/ui/native_theme/native_theme_win.cc |
| @@ -49,26 +49,24 @@ const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor; |
| const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor; |
| const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(246, 249, 253); |
| const SkColor kMenuSeparatorColor = SkColorSetARGB(50, 0, 0, 0); |
| -// Label: |
| -const SkColor kLabelEnabledColor = color_utils::GetSysSkColor(COLOR_WINDOWTEXT); |
| -const SkColor kLabelDisabledColor = color_utils::GetSysSkColor(COLOR_GRAYTEXT); |
| -const SkColor kLabelBackgroundColor = color_utils::GetSysSkColor(COLOR_WINDOW); |
| // Textfield: |
| -const SkColor kTextfieldDefaultColor = SK_ColorBLACK; |
| -const SkColor kTextfieldDefaultBackground = SK_ColorWHITE; |
| -const SkColor kTextfieldSelectionColor = SK_ColorWHITE; |
| -const SkColor kTextfieldSelectionBackgroundFocused = |
| - SkColorSetRGB(0x1D, 0x90, 0xFF); |
| const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY; |
| -SkColor WinColorToSkColor(COLORREF color) { |
| - return SkColorSetRGB(GetRValue(color), GetGValue(color), GetBValue(color)); |
| -} |
| +// Windows system color IDs cached and updated by the native theme. |
| +const int kSystemColors[] = { |
| + COLOR_3DFACE, |
| + COLOR_GRAYTEXT, |
| + COLOR_HIGHLIGHT, |
| + COLOR_HIGHLIGHTTEXT, |
| + COLOR_SCROLLBAR, |
| + COLOR_WINDOW, |
| + COLOR_WINDOWTEXT, |
| +}; |
| void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { |
| // Create a 2x2 checkerboard pattern using the 3D face and highlight colors. |
| - SkColor face = skia::COLORREFToSkColor(GetSysColor(COLOR_3DFACE)); |
| - SkColor highlight = skia::COLORREFToSkColor(GetSysColor(COLOR_3DHILIGHT)); |
| + const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE); |
| + const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT); |
| SkColor buffer[] = { face, highlight, highlight, face }; |
| // Confusing bit: we first create a temporary bitmap with our desired pattern, |
| // then copy it to another bitmap. The temporary bitmap doesn't take |
| @@ -154,7 +152,7 @@ SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme, |
| int default_sys_color) const { |
| SkColor color; |
| if (GetThemeColor(theme, part_id, state_id, prop_id, &color) != S_OK) |
| - color = skia::COLORREFToSkColor(GetSysColor(default_sys_color)); |
| + color = color_utils::GetSysSkColor(default_sys_color); |
| return color; |
| } |
| @@ -330,6 +328,8 @@ NativeThemeWin::NativeThemeWin() |
| GetProcAddress(theme_dll_, "GetThemeInt")); |
| } |
| memset(theme_handles_, 0, sizeof(theme_handles_)); |
| + // Initialize the cached system colors. |
| + 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.
|
| } |
| NativeThemeWin::~NativeThemeWin() { |
| @@ -341,6 +341,12 @@ NativeThemeWin::~NativeThemeWin() { |
| } |
| } |
| +void NativeThemeWin::OnSysColorChange() { |
| + 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.
|
| + system_colors_[kSystemColors[i]] = |
| + color_utils::GetSysSkColor(kSystemColors[i]); |
| +} |
| + |
| void NativeThemeWin::PaintDirect(SkCanvas* canvas, |
| Part part, |
| State state, |
| @@ -441,7 +447,7 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { |
| case kColorId_DialogBackground: |
| // TODO(benrg): Should this use the new Windows theme functions? The old |
| // code in DialogClientView::OnPaint used GetSysColor(COLOR_3DFACE). |
| - return WinColorToSkColor(GetSysColor(COLOR_3DFACE)); |
| + return system_colors_[COLOR_3DFACE]; |
| // FocusableBorder |
| case kColorId_FocusedBorderColor: |
| @@ -473,21 +479,25 @@ SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { |
| // Label |
| case kColorId_LabelEnabledColor: |
| - return kLabelEnabledColor; |
| + return system_colors_[COLOR_WINDOWTEXT]; |
| case kColorId_LabelDisabledColor: |
| - return kLabelDisabledColor; |
| + return system_colors_[COLOR_GRAYTEXT]; |
| case kColorId_LabelBackgroundColor: |
| - return kLabelBackgroundColor; |
| + return system_colors_[COLOR_WINDOW]; |
| // Textfield |
| case kColorId_TextfieldDefaultColor: |
| - return kTextfieldDefaultColor; |
| + return system_colors_[COLOR_WINDOWTEXT]; |
| case kColorId_TextfieldDefaultBackground: |
| - return kTextfieldDefaultBackground; |
| + return system_colors_[COLOR_WINDOW]; |
| + case kColorId_TextfieldReadOnlyColor: |
| + return system_colors_[COLOR_GRAYTEXT]; |
| + case kColorId_TextfieldReadOnlyBackground: |
| + return system_colors_[COLOR_3DFACE]; |
| case kColorId_TextfieldSelectionColor: |
| - return kTextfieldSelectionColor; |
| + return system_colors_[COLOR_HIGHLIGHTTEXT]; |
| case kColorId_TextfieldSelectionBackgroundFocused: |
| - return kTextfieldSelectionBackgroundFocused; |
| + return system_colors_[COLOR_HIGHLIGHT]; |
| case kColorId_TextfieldSelectionBackgroundUnfocused: |
| return kTextfieldSelectionBackgroundUnfocused; |
| @@ -1143,10 +1153,8 @@ HRESULT NativeThemeWin::PaintScrollbarTrack( |
| return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); |
| // Draw it manually. |
| - const DWORD colorScrollbar = GetSysColor(COLOR_SCROLLBAR); |
| - const DWORD color3DFace = GetSysColor(COLOR_3DFACE); |
| - if ((colorScrollbar != color3DFace) && |
| - (colorScrollbar != GetSysColor(COLOR_WINDOW))) { |
| + if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && |
| + (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { |
| FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); |
| } else { |
| SkPaint paint; |