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

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

Issue 377423003: Lots of random cleanups, mostly for native_theme_win.cc: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Tweak switches Created 6 years, 5 months 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
« no previous file with comments | « ui/native_theme/native_theme_aura.cc ('k') | ui/views/controls/button/button.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 gfx::Rect result(*rect); 125 gfx::Rect result(*rect);
126 result.Inset(size, size); 126 result.Inset(size, size);
127 return result.ToRECT(); 127 return result.ToRECT();
128 } 128 }
129 129
130 } // namespace 130 } // namespace
131 131
132 namespace ui { 132 namespace ui {
133 133
134 bool NativeThemeWin::IsThemingActive() const { 134 bool NativeThemeWin::IsThemingActive() const {
135 if (is_theme_active_) 135 return is_theme_active_ && is_theme_active_();
136 return !!is_theme_active_();
137 return false;
138 } 136 }
139 137
140 bool NativeThemeWin::IsUsingHighContrastTheme() const { 138 bool NativeThemeWin::IsUsingHighContrastTheme() const {
141 if (is_using_high_contrast_valid_) 139 if (is_using_high_contrast_valid_)
142 return is_using_high_contrast_; 140 return is_using_high_contrast_;
143 HIGHCONTRAST result; 141 HIGHCONTRAST result;
144 result.cbSize = sizeof(HIGHCONTRAST); 142 result.cbSize = sizeof(HIGHCONTRAST);
145 is_using_high_contrast_ = 143 is_using_high_contrast_ =
146 SystemParametersInfo(SPI_GETHIGHCONTRAST, result.cbSize, &result, 0) && 144 SystemParametersInfo(SPI_GETHIGHCONTRAST, result.cbSize, &result, 0) &&
147 (result.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON; 145 (result.dwFlags & HCF_HIGHCONTRASTON) == HCF_HIGHCONTRASTON;
148 is_using_high_contrast_valid_ = true; 146 is_using_high_contrast_valid_ = true;
149 return is_using_high_contrast_; 147 return is_using_high_contrast_;
150 } 148 }
151 149
152 HRESULT NativeThemeWin::GetThemeColor(ThemeName theme, 150 HRESULT NativeThemeWin::GetThemeColor(ThemeName theme,
153 int part_id, 151 int part_id,
154 int state_id, 152 int state_id,
155 int prop_id, 153 int prop_id,
156 SkColor* color) const { 154 SkColor* color) const {
157 HANDLE handle = GetThemeHandle(theme); 155 HANDLE handle = GetThemeHandle(theme);
158 if (handle && get_theme_color_) { 156 if (!handle || !get_theme_color_)
159 COLORREF color_ref; 157 return E_NOTIMPL;
160 if (get_theme_color_(handle, part_id, state_id, prop_id, &color_ref) == 158 COLORREF color_ref;
161 S_OK) { 159 if (get_theme_color_(handle, part_id, state_id, prop_id, &color_ref) != S_OK)
162 *color = skia::COLORREFToSkColor(color_ref); 160 return E_NOTIMPL;
163 return S_OK; 161 *color = skia::COLORREFToSkColor(color_ref);
164 } 162 return S_OK;
165 }
166 return E_NOTIMPL;
167 } 163 }
168 164
169 SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme, 165 SkColor NativeThemeWin::GetThemeColorWithDefault(ThemeName theme,
170 int part_id, 166 int part_id,
171 int state_id, 167 int state_id,
172 int prop_id, 168 int prop_id,
173 int default_sys_color) const { 169 int default_sys_color) const {
174 SkColor color; 170 SkColor color;
175 if (GetThemeColor(theme, part_id, state_id, prop_id, &color) != S_OK) 171 return (GetThemeColor(theme, part_id, state_id, prop_id, &color) == S_OK) ?
176 color = color_utils::GetSysSkColor(default_sys_color); 172 color : color_utils::GetSysSkColor(default_sys_color);
177 return color;
178 } 173 }
179 174
180 gfx::Size NativeThemeWin::GetThemeBorderSize(ThemeName theme) const { 175 gfx::Size NativeThemeWin::GetThemeBorderSize(ThemeName theme) const {
181 // For simplicity use the wildcard state==0, part==0, since it works 176 // For simplicity use the wildcard state==0, part==0, since it works
182 // for the cases we currently depend on. 177 // for the cases we currently depend on.
183 int border; 178 int border;
184 if (GetThemeInt(theme, 0, 0, TMT_BORDERSIZE, &border) == S_OK) 179 return (GetThemeInt(theme, 0, 0, TMT_BORDERSIZE, &border) == S_OK) ?
185 return gfx::Size(border, border); 180 gfx::Size(border, border) :
186 else 181 gfx::Size(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
187 return gfx::Size(GetSystemMetrics(SM_CXEDGE), GetSystemMetrics(SM_CYEDGE));
188 } 182 }
189 183
190 void NativeThemeWin::DisableTheming() const { 184 void NativeThemeWin::DisableTheming() const {
191 if (!set_theme_properties_) 185 if (set_theme_properties_)
192 return; 186 set_theme_properties_(0);
193 set_theme_properties_(0);
194 } 187 }
195 188
196 void NativeThemeWin::CloseHandles() const { 189 void NativeThemeWin::CloseHandles() const {
197 if (!close_theme_) 190 if (!close_theme_)
198 return; 191 return;
199 192
200 for (int i = 0; i < LAST; ++i) { 193 for (int i = 0; i < LAST; ++i) {
201 if (theme_handles_[i]) { 194 if (theme_handles_[i]) {
202 close_theme_(theme_handles_[i]); 195 close_theme_(theme_handles_[i]);
203 theme_handles_[i] = NULL; 196 theme_handles_[i] = NULL;
204 } 197 }
205 } 198 }
206 } 199 }
207 200
208 bool NativeThemeWin::IsClassicTheme(ThemeName name) const { 201 bool NativeThemeWin::IsClassicTheme(ThemeName name) const {
209 if (!theme_dll_) 202 return !theme_dll_ || !GetThemeHandle(name);
210 return true;
211
212 return !GetThemeHandle(name);
213 } 203 }
214 204
215 // static 205 // static
216 NativeThemeWin* NativeThemeWin::instance() { 206 NativeThemeWin* NativeThemeWin::instance() {
217 CR_DEFINE_STATIC_LOCAL(NativeThemeWin, s_native_theme, ()); 207 CR_DEFINE_STATIC_LOCAL(NativeThemeWin, s_native_theme, ());
218 return &s_native_theme; 208 return &s_native_theme;
219 } 209 }
220 210
221 gfx::Size NativeThemeWin::GetPartSize(Part part, 211 gfx::Size NativeThemeWin::GetPartSize(Part part,
222 State state, 212 State state,
(...skipping 11 matching lines...) Expand all
234 case kScrollbarUpArrow: 224 case kScrollbarUpArrow:
235 case kScrollbarHorizontalThumb: 225 case kScrollbarHorizontalThumb:
236 case kScrollbarVerticalThumb: 226 case kScrollbarVerticalThumb:
237 case kScrollbarHorizontalTrack: 227 case kScrollbarHorizontalTrack:
238 case kScrollbarVerticalTrack: { 228 case kScrollbarVerticalTrack: {
239 int size = gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL); 229 int size = gfx::win::GetSystemMetricsInDIP(SM_CXVSCROLL);
240 if (size == 0) 230 if (size == 0)
241 size = 17; 231 size = 17;
242 return gfx::Size(size, size); 232 return gfx::Size(size, size);
243 } 233 }
234 default:
235 break;
244 } 236 }
245 237
246 int part_id = GetWindowsPart(part, state, extra); 238 int part_id = GetWindowsPart(part, state, extra);
247 int state_id = GetWindowsState(part, state, extra); 239 int state_id = GetWindowsState(part, state, extra);
248 240
241 base::win::ScopedGetDC screen_dc(NULL);
249 SIZE size; 242 SIZE size;
250 HDC hdc = GetDC(NULL); 243 if (SUCCEEDED(GetThemePartSize(GetThemeName(part), screen_dc, part_id,
251 HRESULT hr = GetThemePartSize(GetThemeName(part), hdc, part_id, state_id, 244 state_id, NULL, TS_TRUE, &size)))
252 NULL, TS_TRUE, &size); 245 return gfx::Size(size.cx, size.cy);
253 ReleaseDC(NULL, hdc);
254 246
255 if (FAILED(hr)) { 247 // TODO(rogerta): For now, we need to support radio buttons and checkboxes
256 // TODO(rogerta): For now, we need to support radio buttons and checkboxes 248 // when theming is not enabled. Support for other parts can be added
257 // when theming is not enabled. Support for other parts can be added 249 // if/when needed.
258 // if/when needed. 250 return (part == kCheckbox || part == kRadio) ?
259 switch (part) { 251 gfx::Size(13, 13) : gfx::Size();
260 case kCheckbox:
261 case kRadio:
262 // TODO(rogerta): I was not able to find any API to get the default
263 // size of these controls, so determined these values empirically.
264 size.cx = 13;
265 size.cy = 13;
266 break;
267 default:
268 size.cx = 0;
269 size.cy = 0;
270 break;
271 }
272 }
273
274 return gfx::Size(size.cx, size.cy);
275 } 252 }
276 253
277 void NativeThemeWin::Paint(SkCanvas* canvas, 254 void NativeThemeWin::Paint(SkCanvas* canvas,
278 Part part, 255 Part part,
279 State state, 256 State state,
280 const gfx::Rect& rect, 257 const gfx::Rect& rect,
281 const ExtraParams& extra) const { 258 const ExtraParams& extra) const {
282 if (rect.IsEmpty()) 259 if (rect.IsEmpty())
283 return; 260 return;
284 261
285 switch (part) { 262 switch (part) {
286 case kComboboxArrow: 263 case kComboboxArrow:
287 CommonThemePaintComboboxArrow(canvas, rect); 264 CommonThemePaintComboboxArrow(canvas, rect);
288 return; 265 return;
289 case kMenuPopupGutter: 266 case kMenuPopupGutter:
290 CommonThemePaintMenuGutter(canvas, rect); 267 CommonThemePaintMenuGutter(canvas, rect);
291 return; 268 return;
292 case kMenuPopupSeparator: 269 case kMenuPopupSeparator:
293 CommonThemePaintMenuSeparator(canvas, rect, extra.menu_separator); 270 CommonThemePaintMenuSeparator(canvas, rect, extra.menu_separator);
294 return; 271 return;
295 case kMenuPopupBackground: 272 case kMenuPopupBackground:
296 CommonThemePaintMenuBackground(canvas, rect); 273 CommonThemePaintMenuBackground(canvas, rect);
297 return; 274 return;
298 case kMenuItemBackground: 275 case kMenuItemBackground:
299 CommonThemePaintMenuItemBackground(canvas, state, rect); 276 CommonThemePaintMenuItemBackground(canvas, state, rect);
300 return; 277 return;
278 default:
279 break;
301 } 280 }
302 281
303 bool needs_paint_indirect = false; 282 bool needs_paint_indirect = false;
304 if (!skia::SupportsPlatformPaint(canvas)) { 283 if (!skia::SupportsPlatformPaint(canvas)) {
305 // This block will only get hit with --enable-accelerated-drawing flag. 284 // This block will only get hit with --enable-accelerated-drawing flag.
306 needs_paint_indirect = true; 285 needs_paint_indirect = true;
307 } else { 286 } else {
308 // Scrollbar components on Windows Classic theme (on all Windows versions) 287 // Scrollbar components on Windows Classic theme (on all Windows versions)
309 // have particularly problematic alpha values, so always draw them 288 // have particularly problematic alpha values, so always draw them
310 // indirectly. In addition, scrollbar thumbs and grippers for the Windows XP 289 // indirectly. In addition, scrollbar thumbs and grippers for the Windows XP
311 // theme (available only on Windows XP) also need their alpha values 290 // theme (available only on Windows XP) also need their alpha values
312 // fixed. 291 // fixed.
313 switch (part) { 292 switch (part) {
314 case kScrollbarDownArrow: 293 case kScrollbarDownArrow:
315 case kScrollbarUpArrow: 294 case kScrollbarUpArrow:
316 case kScrollbarLeftArrow: 295 case kScrollbarLeftArrow:
317 case kScrollbarRightArrow: 296 case kScrollbarRightArrow:
318 if (!GetThemeHandle(SCROLLBAR)) 297 needs_paint_indirect = !GetThemeHandle(SCROLLBAR);
319 needs_paint_indirect = true;
320 break; 298 break;
321 case kScrollbarHorizontalThumb: 299 case kScrollbarHorizontalThumb:
322 case kScrollbarVerticalThumb: 300 case kScrollbarVerticalThumb:
323 case kScrollbarHorizontalGripper: 301 case kScrollbarHorizontalGripper:
324 case kScrollbarVerticalGripper: 302 case kScrollbarVerticalGripper:
325 if (!GetThemeHandle(SCROLLBAR) || 303 needs_paint_indirect = !GetThemeHandle(SCROLLBAR) ||
326 base::win::GetVersion() == base::win::VERSION_XP) 304 base::win::GetVersion() == base::win::VERSION_XP;
327 needs_paint_indirect = true;
328 break; 305 break;
329 default: 306 default:
330 break; 307 break;
331 } 308 }
332 } 309 }
333 310
334 if (needs_paint_indirect) 311 if (needs_paint_indirect)
335 PaintIndirect(canvas, part, state, rect, extra); 312 PaintIndirect(canvas, part, state, rect, extra);
336 else 313 else
337 PaintDirect(canvas, part, state, rect, extra); 314 PaintDirect(canvas, part, state, rect, extra);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 Part part, 383 Part part,
407 State state, 384 State state,
408 const gfx::Rect& rect, 385 const gfx::Rect& rect,
409 const ExtraParams& extra) const { 386 const ExtraParams& extra) const {
410 skia::ScopedPlatformPaint scoped_platform_paint(canvas); 387 skia::ScopedPlatformPaint scoped_platform_paint(canvas);
411 HDC hdc = scoped_platform_paint.GetPlatformSurface(); 388 HDC hdc = scoped_platform_paint.GetPlatformSurface();
412 389
413 switch (part) { 390 switch (part) {
414 case kCheckbox: 391 case kCheckbox:
415 PaintCheckbox(hdc, part, state, rect, extra.button); 392 PaintCheckbox(hdc, part, state, rect, extra.button);
416 break; 393 return;
394 case kInnerSpinButton:
395 PaintSpinButton(hdc, part, state, rect, extra.inner_spin);
396 return;
397 case kMenuList:
398 PaintMenuList(hdc, state, rect, extra.menu_list);
399 return;
400 case kMenuCheck:
401 PaintMenuCheck(hdc, state, rect, extra.menu_check);
402 return;
403 case kMenuCheckBackground:
404 PaintMenuCheckBackground(hdc, state, rect);
405 return;
406 case kMenuPopupArrow:
407 PaintMenuArrow(hdc, state, rect, extra.menu_arrow);
408 return;
409 case kMenuPopupBackground:
410 PaintMenuBackground(hdc, rect);
411 return;
412 case kMenuPopupGutter:
413 PaintMenuGutter(hdc, rect);
414 return;
415 case kMenuPopupSeparator:
416 PaintMenuSeparator(hdc, rect, extra.menu_separator);
417 return;
418 case kMenuItemBackground:
419 PaintMenuItemBackground(hdc, state, rect, extra.menu_item);
420 return;
421 case kProgressBar:
422 PaintProgressBar(hdc, rect, extra.progress_bar);
423 return;
424 case kPushButton:
425 PaintPushButton(hdc, part, state, rect, extra.button);
426 return;
417 case kRadio: 427 case kRadio:
418 PaintRadioButton(hdc, part, state, rect, extra.button); 428 PaintRadioButton(hdc, part, state, rect, extra.button);
419 break; 429 return;
420 case kPushButton:
421 PaintPushButton(hdc, part, state, rect, extra.button);
422 break;
423 case kMenuPopupArrow:
424 PaintMenuArrow(hdc, state, rect, extra.menu_arrow);
425 break;
426 case kMenuPopupGutter:
427 PaintMenuGutter(hdc, rect);
428 break;
429 case kMenuPopupSeparator:
430 PaintMenuSeparator(hdc, rect, extra.menu_separator);
431 break;
432 case kMenuPopupBackground:
433 PaintMenuBackground(hdc, rect);
434 break;
435 case kMenuCheck:
436 PaintMenuCheck(hdc, state, rect, extra.menu_check);
437 break;
438 case kMenuCheckBackground:
439 PaintMenuCheckBackground(hdc, state, rect);
440 break;
441 case kMenuItemBackground:
442 PaintMenuItemBackground(hdc, state, rect, extra.menu_item);
443 break;
444 case kMenuList:
445 PaintMenuList(hdc, state, rect, extra.menu_list);
446 break;
447 case kScrollbarDownArrow: 430 case kScrollbarDownArrow:
448 case kScrollbarUpArrow: 431 case kScrollbarUpArrow:
449 case kScrollbarLeftArrow: 432 case kScrollbarLeftArrow:
450 case kScrollbarRightArrow: 433 case kScrollbarRightArrow:
451 PaintScrollbarArrow(hdc, part, state, rect, extra.scrollbar_arrow); 434 PaintScrollbarArrow(hdc, part, state, rect, extra.scrollbar_arrow);
452 break; 435 return;
453 case kScrollbarHorizontalTrack:
454 case kScrollbarVerticalTrack:
455 PaintScrollbarTrack(canvas, hdc, part, state, rect,
456 extra.scrollbar_track);
457 break;
458 case kScrollbarCorner:
459 canvas->drawColor(SK_ColorWHITE, SkXfermode::kSrc_Mode);
460 break;
461 case kScrollbarHorizontalThumb: 436 case kScrollbarHorizontalThumb:
462 case kScrollbarVerticalThumb: 437 case kScrollbarVerticalThumb:
463 case kScrollbarHorizontalGripper: 438 case kScrollbarHorizontalGripper:
464 case kScrollbarVerticalGripper: 439 case kScrollbarVerticalGripper:
465 PaintScrollbarThumb(hdc, part, state, rect, extra.scrollbar_thumb); 440 PaintScrollbarThumb(hdc, part, state, rect, extra.scrollbar_thumb);
466 break; 441 return;
467 case kInnerSpinButton: 442 case kScrollbarHorizontalTrack:
468 PaintSpinButton(hdc, part, state, rect, extra.inner_spin); 443 case kScrollbarVerticalTrack:
469 break; 444 PaintScrollbarTrack(canvas, hdc, part, state, rect,
445 extra.scrollbar_track);
446 return;
447 case kScrollbarCorner:
448 canvas->drawColor(SK_ColorWHITE, SkXfermode::kSrc_Mode);
449 return;
450 case kTabPanelBackground:
451 PaintTabPanelBackground(hdc, rect);
452 return;
453 case kTextField:
454 PaintTextField(hdc, part, state, rect, extra.text_field);
455 return;
470 case kTrackbarThumb: 456 case kTrackbarThumb:
471 case kTrackbarTrack: 457 case kTrackbarTrack:
472 PaintTrackbar(canvas, hdc, part, state, rect, extra.trackbar); 458 PaintTrackbar(canvas, hdc, part, state, rect, extra.trackbar);
473 break; 459 return;
474 case kProgressBar:
475 PaintProgressBar(hdc, rect, extra.progress_bar);
476 break;
477 case kWindowResizeGripper: 460 case kWindowResizeGripper:
478 PaintWindowResizeGripper(hdc, rect); 461 PaintWindowResizeGripper(hdc, rect);
479 break; 462 return;
480 case kTabPanelBackground: 463 case kComboboxArrow:
481 PaintTabPanelBackground(hdc, rect);
482 break;
483 case kTextField:
484 PaintTextField(hdc, part, state, rect, extra.text_field);
485 break;
486
487 case kSliderTrack: 464 case kSliderTrack:
488 case kSliderThumb: 465 case kSliderThumb:
489 default: 466 case kMaxPart:
490 // While transitioning NativeThemeWin to the single Paint() entry point,
491 // unsupported parts will DCHECK here.
492 NOTREACHED(); 467 NOTREACHED();
493 } 468 }
494 } 469 }
495 470
496 SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const { 471 SkColor NativeThemeWin::GetSystemColor(ColorId color_id) const {
497 SkColor color; 472 SkColor color;
498 if (CommonThemeGetSystemColor(color_id, &color)) 473 if (CommonThemeGetSystemColor(color_id, &color))
499 return color; 474 return color;
500 475
501 switch (color_id) { 476 switch (color_id) {
502 // Windows 477 // Windows
503 case kColorId_WindowBackground: 478 case kColorId_WindowBackground:
504 return system_colors_[COLOR_WINDOW]; 479 return system_colors_[COLOR_WINDOW];
505 480
506 // Dialogs 481 // Dialogs
507 case kColorId_DialogBackground: 482 case kColorId_DialogBackground:
508 if (gfx::IsInvertedColorScheme()) 483 return gfx::IsInvertedColorScheme() ?
509 return color_utils::InvertColor(kDialogBackgroundColor); 484 color_utils::InvertColor(kDialogBackgroundColor) :
510 return kDialogBackgroundColor; 485 kDialogBackgroundColor;
511 486
512 // FocusableBorder 487 // FocusableBorder
513 case kColorId_FocusedBorderColor: 488 case kColorId_FocusedBorderColor:
514 return kFocusedBorderColor; 489 return kFocusedBorderColor;
515 case kColorId_UnfocusedBorderColor: 490 case kColorId_UnfocusedBorderColor:
516 return kUnfocusedBorderColor; 491 return kUnfocusedBorderColor;
517 492
518 // Button 493 // Button
519 case kColorId_ButtonBackgroundColor: 494 case kColorId_ButtonBackgroundColor:
520 return kButtonBackgroundColor; 495 return kButtonBackgroundColor;
521 case kColorId_ButtonEnabledColor: 496 case kColorId_ButtonEnabledColor:
522 return system_colors_[COLOR_BTNTEXT]; 497 return system_colors_[COLOR_BTNTEXT];
523 case kColorId_ButtonDisabledColor: 498 case kColorId_ButtonDisabledColor:
524 return system_colors_[COLOR_GRAYTEXT]; 499 return system_colors_[COLOR_GRAYTEXT];
525 case kColorId_ButtonHighlightColor: 500 case kColorId_ButtonHighlightColor:
526 return kButtonHighlightColor; 501 return kButtonHighlightColor;
527 case kColorId_ButtonHoverColor: 502 case kColorId_ButtonHoverColor:
528 return kButtonHoverColor; 503 return kButtonHoverColor;
529 case kColorId_ButtonHoverBackgroundColor: 504 case kColorId_ButtonHoverBackgroundColor:
530 return kButtonHoverBackgroundColor; 505 return kButtonHoverBackgroundColor;
506 case kColorId_BlueButtonEnabledColor:
507 case kColorId_BlueButtonDisabledColor:
508 case kColorId_BlueButtonPressedColor:
509 case kColorId_BlueButtonHoverColor:
510 NOTREACHED();
511 return kInvalidColorIdColor;
531 512
532 // MenuItem 513 // MenuItem
533 case kColorId_EnabledMenuItemForegroundColor: 514 case kColorId_EnabledMenuItemForegroundColor:
534 return kEnabledMenuItemForegroundColor; 515 return kEnabledMenuItemForegroundColor;
535 case kColorId_DisabledMenuItemForegroundColor: 516 case kColorId_DisabledMenuItemForegroundColor:
536 return kDisabledMenuItemForegroundColor; 517 return kDisabledMenuItemForegroundColor;
537 case kColorId_DisabledEmphasizedMenuItemForegroundColor: 518 case kColorId_DisabledEmphasizedMenuItemForegroundColor:
538 return SK_ColorBLACK; 519 return SK_ColorBLACK;
539 case kColorId_FocusedMenuItemBackgroundColor: 520 case kColorId_FocusedMenuItemBackgroundColor:
540 return kFocusedMenuItemBackgroundColor; 521 return kFocusedMenuItemBackgroundColor;
541 case kColorId_MenuSeparatorColor: 522 case kColorId_MenuSeparatorColor:
542 return kMenuSeparatorColor; 523 return kMenuSeparatorColor;
524 case kColorId_SelectedMenuItemForegroundColor:
525 case kColorId_HoverMenuItemBackgroundColor:
526 case kColorId_MenuBackgroundColor:
527 case kColorId_MenuBorderColor:
528 NOTREACHED();
529 return kInvalidColorIdColor;
530
531 // MenuButton
532 case kColorId_EnabledMenuButtonBorderColor:
533 case kColorId_FocusedMenuButtonBorderColor:
534 case kColorId_HoverMenuButtonBorderColor:
535 NOTREACHED();
536 return kInvalidColorIdColor;
543 537
544 // Label 538 // Label
545 case kColorId_LabelEnabledColor: 539 case kColorId_LabelEnabledColor:
546 return system_colors_[COLOR_BTNTEXT]; 540 return system_colors_[COLOR_BTNTEXT];
547 case kColorId_LabelDisabledColor: 541 case kColorId_LabelDisabledColor:
548 return system_colors_[COLOR_GRAYTEXT]; 542 return system_colors_[COLOR_GRAYTEXT];
549 case kColorId_LabelBackgroundColor: 543 case kColorId_LabelBackgroundColor:
550 return system_colors_[COLOR_WINDOW]; 544 return system_colors_[COLOR_WINDOW];
551 545
552 // Textfield 546 // Textfield
553 case kColorId_TextfieldDefaultColor: 547 case kColorId_TextfieldDefaultColor:
554 return system_colors_[COLOR_WINDOWTEXT]; 548 return system_colors_[COLOR_WINDOWTEXT];
555 case kColorId_TextfieldDefaultBackground: 549 case kColorId_TextfieldDefaultBackground:
556 return system_colors_[COLOR_WINDOW]; 550 return system_colors_[COLOR_WINDOW];
557 case kColorId_TextfieldReadOnlyColor: 551 case kColorId_TextfieldReadOnlyColor:
558 return system_colors_[COLOR_GRAYTEXT]; 552 return system_colors_[COLOR_GRAYTEXT];
559 case kColorId_TextfieldReadOnlyBackground: 553 case kColorId_TextfieldReadOnlyBackground:
560 return system_colors_[COLOR_3DFACE]; 554 return system_colors_[COLOR_3DFACE];
561 case kColorId_TextfieldSelectionColor: 555 case kColorId_TextfieldSelectionColor:
562 return system_colors_[COLOR_HIGHLIGHTTEXT]; 556 return system_colors_[COLOR_HIGHLIGHTTEXT];
563 case kColorId_TextfieldSelectionBackgroundFocused: 557 case kColorId_TextfieldSelectionBackgroundFocused:
564 return system_colors_[COLOR_HIGHLIGHT]; 558 return system_colors_[COLOR_HIGHLIGHT];
565 559
560 // Tooltip
561 case kColorId_TooltipBackground:
562 case kColorId_TooltipText:
563 NOTREACHED();
564 return kInvalidColorIdColor;
565
566 // Tree 566 // Tree
567 // NOTE: these aren't right for all themes, but as close as I could get. 567 // NOTE: these aren't right for all themes, but as close as I could get.
568 case kColorId_TreeBackground: 568 case kColorId_TreeBackground:
569 return system_colors_[COLOR_WINDOW]; 569 return system_colors_[COLOR_WINDOW];
570 case kColorId_TreeText: 570 case kColorId_TreeText:
571 return system_colors_[COLOR_WINDOWTEXT]; 571 return system_colors_[COLOR_WINDOWTEXT];
572 case kColorId_TreeSelectedText: 572 case kColorId_TreeSelectedText:
573 return system_colors_[COLOR_HIGHLIGHTTEXT]; 573 return system_colors_[COLOR_HIGHLIGHTTEXT];
574 case kColorId_TreeSelectedTextUnfocused: 574 case kColorId_TreeSelectedTextUnfocused:
575 return system_colors_[COLOR_BTNTEXT]; 575 return system_colors_[COLOR_BTNTEXT];
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 case kColorId_ResultsTableNormalDivider: 634 case kColorId_ResultsTableNormalDivider:
635 return color_utils::AlphaBlend(system_colors_[COLOR_WINDOWTEXT], 635 return color_utils::AlphaBlend(system_colors_[COLOR_WINDOWTEXT],
636 system_colors_[COLOR_WINDOW], 0x34); 636 system_colors_[COLOR_WINDOW], 0x34);
637 case kColorId_ResultsTableHoveredDivider: 637 case kColorId_ResultsTableHoveredDivider:
638 return color_utils::AlphaBlend( 638 return color_utils::AlphaBlend(
639 system_colors_[COLOR_WINDOWTEXT], 639 system_colors_[COLOR_WINDOWTEXT],
640 GetSystemColor(kColorId_ResultsTableHoveredBackground), 0x34); 640 GetSystemColor(kColorId_ResultsTableHoveredBackground), 0x34);
641 case kColorId_ResultsTableSelectedDivider: 641 case kColorId_ResultsTableSelectedDivider:
642 return color_utils::AlphaBlend(system_colors_[COLOR_HIGHLIGHTTEXT], 642 return color_utils::AlphaBlend(system_colors_[COLOR_HIGHLIGHTTEXT],
643 system_colors_[COLOR_HIGHLIGHT], 0x34); 643 system_colors_[COLOR_HIGHLIGHT], 0x34);
644
645 default:
646 NOTREACHED();
647 break;
648 } 644 }
645 NOTREACHED();
649 return kInvalidColorIdColor; 646 return kInvalidColorIdColor;
650 } 647 }
651 648
652 void NativeThemeWin::PaintIndirect(SkCanvas* canvas, 649 void NativeThemeWin::PaintIndirect(SkCanvas* canvas,
653 Part part, 650 Part part,
654 State state, 651 State state,
655 const gfx::Rect& rect, 652 const gfx::Rect& rect,
656 const ExtraParams& extra) const { 653 const ExtraParams& extra) const {
657 // TODO(asvitkine): This path is pretty inefficient - for each paint operation 654 // TODO(asvitkine): This path is pretty inefficient - for each paint operation
658 // it creates a new offscreen bitmap Skia canvas. This can 655 // it creates a new offscreen bitmap Skia canvas. This can
659 // be sped up by doing it only once per part/state and 656 // be sped up by doing it only once per part/state and
660 // keeping a cache of the resulting bitmaps. 657 // keeping a cache of the resulting bitmaps.
661 658
662 // Create an offscreen canvas that is backed by an HDC. 659 // Create an offscreen canvas that is backed by an HDC.
663 skia::RefPtr<skia::BitmapPlatformDevice> device = skia::AdoptRef( 660 skia::RefPtr<skia::BitmapPlatformDevice> device = skia::AdoptRef(
664 skia::BitmapPlatformDevice::Create( 661 skia::BitmapPlatformDevice::Create(
665 rect.width(), rect.height(), false, NULL)); 662 rect.width(), rect.height(), false, NULL));
666 DCHECK(device); 663 DCHECK(device);
667 if (!device)
668 return;
669 SkCanvas offscreen_canvas(device.get()); 664 SkCanvas offscreen_canvas(device.get());
670 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas)); 665 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas));
671 666
672 // Some of the Windows theme drawing operations do not write correct alpha 667 // Some of the Windows theme drawing operations do not write correct alpha
673 // values for fully-opaque pixels; instead the pixels get alpha 0. This is 668 // values for fully-opaque pixels; instead the pixels get alpha 0. This is
674 // especially a problem on Windows XP or when using the Classic theme. 669 // especially a problem on Windows XP or when using the Classic theme.
675 // 670 //
676 // To work-around this, mark all pixels with a placeholder value, to detect 671 // To work-around this, mark all pixels with a placeholder value, to detect
677 // which pixels get touched by the paint operation. After paint, set any 672 // which pixels get touched by the paint operation. After paint, set any
678 // pixels that have alpha 0 to opaque and placeholders to fully-transparent. 673 // pixels that have alpha 0 to opaque and placeholders to fully-transparent.
679 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0); 674 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0);
680 offscreen_canvas.clear(placeholder); 675 offscreen_canvas.clear(placeholder);
681 676
682 // Offset destination rects to have origin (0,0). 677 // Offset destination rects to have origin (0,0).
683 gfx::Rect adjusted_rect(rect.size()); 678 gfx::Rect adjusted_rect(rect.size());
684 ExtraParams adjusted_extra(extra); 679 ExtraParams adjusted_extra(extra);
685 switch (part) { 680 switch (part) {
686 case kProgressBar: 681 case kProgressBar:
687 adjusted_extra.progress_bar.value_rect_x = 0; 682 adjusted_extra.progress_bar.value_rect_x = 0;
688 adjusted_extra.progress_bar.value_rect_y = 0; 683 adjusted_extra.progress_bar.value_rect_y = 0;
689 break; 684 break;
690 case kScrollbarHorizontalTrack: 685 case kScrollbarHorizontalTrack:
691 case kScrollbarVerticalTrack: 686 case kScrollbarVerticalTrack:
692 adjusted_extra.scrollbar_track.track_x = 0; 687 adjusted_extra.scrollbar_track.track_x = 0;
693 adjusted_extra.scrollbar_track.track_y = 0; 688 adjusted_extra.scrollbar_track.track_y = 0;
694 break; 689 break;
695 default: break; 690 default:
691 break;
696 } 692 }
697 // Draw the theme controls using existing HDC-drawing code. 693 // Draw the theme controls using existing HDC-drawing code.
698 PaintDirect(&offscreen_canvas, 694 PaintDirect(&offscreen_canvas, part, state, adjusted_rect, adjusted_extra);
699 part,
700 state,
701 adjusted_rect,
702 adjusted_extra);
703 695
704 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is 696 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is
705 // necessary to have when drawing to a SkPicture. 697 // necessary to have when drawing to a SkPicture.
706 const SkBitmap& hdc_bitmap = 698 const SkBitmap& hdc_bitmap =
707 offscreen_canvas.getDevice()->accessBitmap(false); 699 offscreen_canvas.getDevice()->accessBitmap(false);
708 SkBitmap bitmap; 700 SkBitmap bitmap;
709 hdc_bitmap.copyTo(&bitmap, kN32_SkColorType); 701 hdc_bitmap.copyTo(&bitmap, kN32_SkColorType);
710 702
711 // Post-process the pixels to fix up the alpha values (see big comment above). 703 // Post-process the pixels to fix up the alpha values (see big comment above).
712 const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder); 704 const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder);
(...skipping 17 matching lines...) Expand all
730 } 722 }
731 723
732 HRESULT NativeThemeWin::GetThemePartSize(ThemeName theme_name, 724 HRESULT NativeThemeWin::GetThemePartSize(ThemeName theme_name,
733 HDC hdc, 725 HDC hdc,
734 int part_id, 726 int part_id,
735 int state_id, 727 int state_id,
736 RECT* rect, 728 RECT* rect,
737 int ts, 729 int ts,
738 SIZE* size) const { 730 SIZE* size) const {
739 HANDLE handle = GetThemeHandle(theme_name); 731 HANDLE handle = GetThemeHandle(theme_name);
740 if (handle && get_theme_part_size_) 732 return (handle && get_theme_part_size_) ?
741 return get_theme_part_size_(handle, hdc, part_id, state_id, rect, ts, size); 733 get_theme_part_size_(handle, hdc, part_id, state_id, rect, ts, size) :
742 734 E_NOTIMPL;
743 return E_NOTIMPL;
744 } 735 }
745 736
746 HRESULT NativeThemeWin::PaintButton(HDC hdc, 737 HRESULT NativeThemeWin::PaintButton(HDC hdc,
747 State state, 738 State state,
748 const ButtonExtraParams& extra, 739 const ButtonExtraParams& extra,
749 int part_id, 740 int part_id,
750 int state_id, 741 int state_id,
751 RECT* rect) const { 742 RECT* rect) const {
752 HANDLE handle = GetThemeHandle(BUTTON); 743 HANDLE handle = GetThemeHandle(BUTTON);
753 if (handle && draw_theme_) 744 if (handle && draw_theme_)
754 return draw_theme_(handle, hdc, part_id, state_id, rect, NULL); 745 return draw_theme_(handle, hdc, part_id, state_id, rect, NULL);
755 746
756 // Adjust classic_state based on part, state, and extras. 747 // Adjust classic_state based on part, state, and extras.
757 int classic_state = extra.classic_state; 748 int classic_state = extra.classic_state;
758 switch (part_id) { 749 switch (part_id) {
759 case BP_CHECKBOX: 750 case BP_CHECKBOX:
760 classic_state |= DFCS_BUTTONCHECK; 751 classic_state |= DFCS_BUTTONCHECK;
761 break; 752 break;
762 case BP_RADIOBUTTON: 753 case BP_RADIOBUTTON:
763 classic_state |= DFCS_BUTTONRADIO; 754 classic_state |= DFCS_BUTTONRADIO;
764 break; 755 break;
765 case BP_PUSHBUTTON: 756 case BP_PUSHBUTTON:
766 classic_state |= DFCS_BUTTONPUSH; 757 classic_state |= DFCS_BUTTONPUSH;
767 break; 758 break;
768 default: 759 default:
769 NOTREACHED() << "Unknown part_id: " << part_id; 760 NOTREACHED();
770 break; 761 break;
771 } 762 }
772 763
773 switch (state) { 764 switch (state) {
774 case kDisabled: 765 case kDisabled:
775 classic_state |= DFCS_INACTIVE; 766 classic_state |= DFCS_INACTIVE;
776 break; 767 break;
768 case kHovered:
769 case kNormal:
770 break;
777 case kPressed: 771 case kPressed:
778 classic_state |= DFCS_PUSHED; 772 classic_state |= DFCS_PUSHED;
779 break; 773 break;
780 case kNormal: 774 case kNumStates:
781 case kHovered: 775 NOTREACHED();
782 break;
783 default:
784 NOTREACHED() << "Unknown state: " << state;
785 break; 776 break;
786 } 777 }
787 778
788 if (extra.checked) 779 if (extra.checked)
789 classic_state |= DFCS_CHECKED; 780 classic_state |= DFCS_CHECKED;
790 781
791 // Draw it manually. 782 // Draw it manually.
792 // All pressed states have both low bits set, and no other states do. 783 // All pressed states have both low bits set, and no other states do.
793 const bool focused = ((state_id & ETS_FOCUSED) == ETS_FOCUSED); 784 const bool focused = ((state_id & ETS_FOCUSED) == ETS_FOCUSED);
794 const bool pressed = ((state_id & PBS_PRESSED) == PBS_PRESSED); 785 const bool pressed = ((state_id & PBS_PRESSED) == PBS_PRESSED);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
847 } 838 }
848 839
849 DrawEdge(hdc, &rect_win, EDGE_ETCHED, BF_TOP); 840 DrawEdge(hdc, &rect_win, EDGE_ETCHED, BF_TOP);
850 return S_OK; 841 return S_OK;
851 } 842 }
852 843
853 HRESULT NativeThemeWin::PaintMenuGutter(HDC hdc, 844 HRESULT NativeThemeWin::PaintMenuGutter(HDC hdc,
854 const gfx::Rect& rect) const { 845 const gfx::Rect& rect) const {
855 RECT rect_win = rect.ToRECT(); 846 RECT rect_win = rect.ToRECT();
856 HANDLE handle = GetThemeHandle(MENU); 847 HANDLE handle = GetThemeHandle(MENU);
857 if (handle && draw_theme_) 848 return (handle && draw_theme_) ?
858 return draw_theme_(handle, hdc, MENU_POPUPGUTTER, MPI_NORMAL, &rect_win, 849 draw_theme_(handle, hdc, MENU_POPUPGUTTER, MPI_NORMAL, &rect_win, NULL) :
859 NULL); 850 E_NOTIMPL;
860 return E_NOTIMPL;
861 } 851 }
862 852
863 HRESULT NativeThemeWin::PaintMenuArrow(HDC hdc, 853 HRESULT NativeThemeWin::PaintMenuArrow(
864 State state, 854 HDC hdc,
865 const gfx::Rect& rect, 855 State state,
866 const MenuArrowExtraParams& extra) 856 const gfx::Rect& rect,
867 const { 857 const MenuArrowExtraParams& extra) const {
868 int state_id = MSM_NORMAL; 858 int state_id = MSM_NORMAL;
869 if (state == kDisabled) 859 if (state == kDisabled)
870 state_id = MSM_DISABLED; 860 state_id = MSM_DISABLED;
871 861
872 HANDLE handle = GetThemeHandle(MENU); 862 HANDLE handle = GetThemeHandle(MENU);
873 RECT rect_win = rect.ToRECT(); 863 RECT rect_win = rect.ToRECT();
874 if (handle && draw_theme_) { 864 if (handle && draw_theme_) {
875 if (extra.pointing_right) { 865 if (extra.pointing_right) {
876 return draw_theme_(handle, hdc, MENU_POPUPSUBMENU, state_id, &rect_win, 866 return draw_theme_(handle, hdc, MENU_POPUPSUBMENU, state_id, &rect_win,
877 NULL); 867 NULL);
878 } else {
879 // There is no way to tell the uxtheme API to draw a left pointing arrow;
880 // it doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they
881 // are needed for RTL locales on Vista. So use a memory DC and mirror
882 // the region with GDI's StretchBlt.
883 gfx::Rect r(rect);
884 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc));
885 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(),
886 r.height()));
887 base::win::ScopedSelectObject select_bitmap(mem_dc, mem_bitmap);
888 // Copy and horizontally mirror the background from hdc into mem_dc. Use
889 // a negative-width source rect, starting at the rightmost pixel.
890 StretchBlt(mem_dc, 0, 0, r.width(), r.height(),
891 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY);
892 // Draw the arrow.
893 RECT theme_rect = {0, 0, r.width(), r.height()};
894 HRESULT result = draw_theme_(handle, mem_dc, MENU_POPUPSUBMENU,
895 state_id, &theme_rect, NULL);
896 // Copy and mirror the result back into mem_dc.
897 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(),
898 mem_dc, r.width()-1, 0, -r.width(), r.height(), SRCCOPY);
899 return result;
900 } 868 }
869 // There is no way to tell the uxtheme API to draw a left pointing arrow; it
870 // doesn't have a flag equivalent to DFCS_MENUARROWRIGHT. But they are
871 // needed for RTL locales on Vista. So use a memory DC and mirror the
872 // region with GDI's StretchBlt.
873 gfx::Rect r(rect);
874 base::win::ScopedCreateDC mem_dc(CreateCompatibleDC(hdc));
875 base::win::ScopedBitmap mem_bitmap(CreateCompatibleBitmap(hdc, r.width(),
876 r.height()));
877 base::win::ScopedSelectObject select_bitmap(mem_dc, mem_bitmap);
878 // Copy and horizontally mirror the background from hdc into mem_dc. Use
879 // a negative-width source rect, starting at the rightmost pixel.
880 StretchBlt(mem_dc, 0, 0, r.width(), r.height(),
881 hdc, r.right()-1, r.y(), -r.width(), r.height(), SRCCOPY);
882 // Draw the arrow.
883 RECT theme_rect = {0, 0, r.width(), r.height()};
884 HRESULT result = draw_theme_(handle, mem_dc, MENU_POPUPSUBMENU,
885 state_id, &theme_rect, NULL);
886 // Copy and mirror the result back into mem_dc.
887 StretchBlt(hdc, r.x(), r.y(), r.width(), r.height(),
888 mem_dc, r.width()-1, 0, -r.width(), r.height(), SRCCOPY);
889 return result;
901 } 890 }
902 891
903 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a 892 // For some reason, Windows uses the name DFCS_MENUARROWRIGHT to indicate a
904 // left pointing arrow. This makes the following 'if' statement slightly 893 // left pointing arrow. This makes the following statement counterintuitive.
905 // counterintuitive. 894 UINT pfc_state = extra.pointing_right ? DFCS_MENUARROW : DFCS_MENUARROWRIGHT;
906 UINT pfc_state;
907 if (extra.pointing_right)
908 pfc_state = DFCS_MENUARROW;
909 else
910 pfc_state = DFCS_MENUARROWRIGHT;
911 return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, extra.is_selected, 895 return PaintFrameControl(hdc, rect, DFC_MENU, pfc_state, extra.is_selected,
912 state); 896 state);
913 } 897 }
914 898
915 HRESULT NativeThemeWin::PaintMenuBackground(HDC hdc, 899 HRESULT NativeThemeWin::PaintMenuBackground(HDC hdc,
916 const gfx::Rect& rect) const { 900 const gfx::Rect& rect) const {
917 HANDLE handle = GetThemeHandle(MENU); 901 HANDLE handle = GetThemeHandle(MENU);
918 RECT rect_win = rect.ToRECT(); 902 RECT rect_win = rect.ToRECT();
919 if (handle && draw_theme_) { 903 if (handle && draw_theme_) {
920 HRESULT result = draw_theme_(handle, hdc, MENU_POPUPBACKGROUND, 0, 904 HRESULT result = draw_theme_(handle, hdc, MENU_POPUPBACKGROUND, 0,
921 &rect_win, NULL); 905 &rect_win, NULL);
922 FrameRect(hdc, &rect_win, GetSysColorBrush(COLOR_3DSHADOW)); 906 FrameRect(hdc, &rect_win, GetSysColorBrush(COLOR_3DSHADOW));
923 return result; 907 return result;
924 } 908 }
925 909
926 FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_MENU)); 910 FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_MENU));
927 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT); 911 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT);
928 return S_OK; 912 return S_OK;
929 } 913 }
930 914
931 HRESULT NativeThemeWin::PaintMenuCheck( 915 HRESULT NativeThemeWin::PaintMenuCheck(
932 HDC hdc, 916 HDC hdc,
933 State state, 917 State state,
934 const gfx::Rect& rect, 918 const gfx::Rect& rect,
935 const MenuCheckExtraParams& extra) const { 919 const MenuCheckExtraParams& extra) const {
936 HANDLE handle = GetThemeHandle(MENU); 920 HANDLE handle = GetThemeHandle(MENU);
937 int state_id; 921 if (handle && draw_theme_) {
938 if (extra.is_radio) { 922 const int state_id = extra.is_radio ?
939 state_id = state == kDisabled ? MC_BULLETDISABLED : MC_BULLETNORMAL; 923 ((state == kDisabled) ? MC_BULLETDISABLED : MC_BULLETNORMAL) :
940 } else { 924 ((state == kDisabled) ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL);
941 state_id = state == kDisabled ? MC_CHECKMARKDISABLED : MC_CHECKMARKNORMAL; 925 RECT rect_win = rect.ToRECT();
926 return draw_theme_(handle, hdc, MENU_POPUPCHECK, state_id, &rect_win, NULL);
942 } 927 }
943 928
944 RECT rect_win = rect.ToRECT();
945 if (handle && draw_theme_)
946 return draw_theme_(handle, hdc, MENU_POPUPCHECK, state_id, &rect_win, NULL);
947
948 return PaintFrameControl(hdc, rect, DFC_MENU, 929 return PaintFrameControl(hdc, rect, DFC_MENU,
949 extra.is_radio ? DFCS_MENUBULLET : DFCS_MENUCHECK, 930 extra.is_radio ? DFCS_MENUBULLET : DFCS_MENUCHECK,
950 extra.is_selected, state); 931 extra.is_selected, state);
951 } 932 }
952 933
953 HRESULT NativeThemeWin::PaintMenuCheckBackground(HDC hdc, 934 HRESULT NativeThemeWin::PaintMenuCheckBackground(HDC hdc,
954 State state, 935 State state,
955 const gfx::Rect& rect) const { 936 const gfx::Rect& rect) const {
956 HANDLE handle = GetThemeHandle(MENU); 937 HANDLE handle = GetThemeHandle(MENU);
938 if (!handle || !draw_theme_)
939 return S_OK; // Nothing to do for background.
940
957 int state_id = state == kDisabled ? MCB_DISABLED : MCB_NORMAL; 941 int state_id = state == kDisabled ? MCB_DISABLED : MCB_NORMAL;
958 RECT rect_win = rect.ToRECT(); 942 RECT rect_win = rect.ToRECT();
959 if (handle && draw_theme_) 943 return draw_theme_(handle, hdc, MENU_POPUPCHECKBACKGROUND, state_id,
960 return draw_theme_(handle, hdc, MENU_POPUPCHECKBACKGROUND, state_id, 944 &rect_win, NULL);
961 &rect_win, NULL);
962 // Nothing to do for background.
963 return S_OK;
964 } 945 }
965 946
966 HRESULT NativeThemeWin::PaintMenuItemBackground( 947 HRESULT NativeThemeWin::PaintMenuItemBackground(
967 HDC hdc, 948 HDC hdc,
968 State state, 949 State state,
969 const gfx::Rect& rect, 950 const gfx::Rect& rect,
970 const MenuItemExtraParams& extra) const { 951 const MenuItemExtraParams& extra) const {
971 HANDLE handle = GetThemeHandle(MENU); 952 HANDLE handle = GetThemeHandle(MENU);
972 RECT rect_win = rect.ToRECT(); 953 RECT rect_win = rect.ToRECT();
973 int state_id; 954 int state_id;
974 switch (state) { 955 switch (state) {
975 case kNormal:
976 state_id = MPI_NORMAL;
977 break;
978 case kDisabled: 956 case kDisabled:
979 state_id = extra.is_selected ? MPI_DISABLEDHOT : MPI_DISABLED; 957 state_id = extra.is_selected ? MPI_DISABLEDHOT : MPI_DISABLED;
980 break; 958 break;
981 case kHovered: 959 case kHovered:
982 state_id = MPI_HOT; 960 state_id = MPI_HOT;
983 break; 961 break;
984 default: 962 case kNormal:
985 NOTREACHED() << "Invalid state " << state; 963 state_id = MPI_NORMAL;
964 break;
965 case kPressed:
966 case kNumStates:
967 NOTREACHED();
986 break; 968 break;
987 } 969 }
988 970
989 if (handle && draw_theme_) 971 if (handle && draw_theme_)
990 return draw_theme_(handle, hdc, MENU_POPUPITEM, state_id, &rect_win, NULL); 972 return draw_theme_(handle, hdc, MENU_POPUPITEM, state_id, &rect_win, NULL);
991 973
992 if (extra.is_selected) 974 if (extra.is_selected)
993 FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_HIGHLIGHT)); 975 FillRect(hdc, &rect_win, GetSysColorBrush(COLOR_HIGHLIGHT));
994 return S_OK; 976 return S_OK;
995 } 977 }
(...skipping 10 matching lines...) Expand all
1006 break; 988 break;
1007 case kHovered: 989 case kHovered:
1008 state_id = PBS_HOT; 990 state_id = PBS_HOT;
1009 break; 991 break;
1010 case kNormal: 992 case kNormal:
1011 state_id = extra.is_default ? PBS_DEFAULTED : PBS_NORMAL; 993 state_id = extra.is_default ? PBS_DEFAULTED : PBS_NORMAL;
1012 break; 994 break;
1013 case kPressed: 995 case kPressed:
1014 state_id = PBS_PRESSED; 996 state_id = PBS_PRESSED;
1015 break; 997 break;
1016 default: 998 case kNumStates:
1017 NOTREACHED() << "Invalid state: " << state; 999 NOTREACHED();
1018 break; 1000 break;
1019 } 1001 }
1020 1002
1021 RECT rect_win = rect.ToRECT(); 1003 RECT rect_win = rect.ToRECT();
1022 return PaintButton(hdc, state, extra, BP_PUSHBUTTON, state_id, &rect_win); 1004 return PaintButton(hdc, state, extra, BP_PUSHBUTTON, state_id, &rect_win);
1023 } 1005 }
1024 1006
1025 HRESULT NativeThemeWin::PaintRadioButton(HDC hdc, 1007 HRESULT NativeThemeWin::PaintRadioButton(HDC hdc,
1026 Part part, 1008 Part part,
1027 State state, 1009 State state,
1028 const gfx::Rect& rect, 1010 const gfx::Rect& rect,
1029 const ButtonExtraParams& extra) const { 1011 const ButtonExtraParams& extra) const {
1030 int state_id; 1012 int state_id;
1031 switch (state) { 1013 switch (state) {
1032 case kDisabled: 1014 case kDisabled:
1033 state_id = extra.checked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED; 1015 state_id = extra.checked ? RBS_CHECKEDDISABLED : RBS_UNCHECKEDDISABLED;
1034 break; 1016 break;
1035 case kHovered: 1017 case kHovered:
1036 state_id = extra.checked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT; 1018 state_id = extra.checked ? RBS_CHECKEDHOT : RBS_UNCHECKEDHOT;
1037 break; 1019 break;
1038 case kNormal: 1020 case kNormal:
1039 state_id = extra.checked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL; 1021 state_id = extra.checked ? RBS_CHECKEDNORMAL : RBS_UNCHECKEDNORMAL;
1040 break; 1022 break;
1041 case kPressed: 1023 case kPressed:
1042 state_id = extra.checked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED; 1024 state_id = extra.checked ? RBS_CHECKEDPRESSED : RBS_UNCHECKEDPRESSED;
1043 break; 1025 break;
1044 default: 1026 case kNumStates:
1045 NOTREACHED() << "Invalid state: " << state; 1027 NOTREACHED();
1046 break; 1028 break;
1047 } 1029 }
1048 1030
1049 RECT rect_win = rect.ToRECT(); 1031 RECT rect_win = rect.ToRECT();
1050 return PaintButton(hdc, state, extra, BP_RADIOBUTTON, state_id, &rect_win); 1032 return PaintButton(hdc, state, extra, BP_RADIOBUTTON, state_id, &rect_win);
1051 } 1033 }
1052 1034
1053 HRESULT NativeThemeWin::PaintCheckbox(HDC hdc, 1035 HRESULT NativeThemeWin::PaintCheckbox(HDC hdc,
1054 Part part, 1036 Part part,
1055 State state, 1037 State state,
1056 const gfx::Rect& rect, 1038 const gfx::Rect& rect,
1057 const ButtonExtraParams& extra) const { 1039 const ButtonExtraParams& extra) const {
1058 int state_id; 1040 int state_id;
1059 switch (state) { 1041 switch (state) {
1060 case kDisabled: 1042 case kDisabled:
1061 state_id = extra.checked ? CBS_CHECKEDDISABLED : 1043 state_id = extra.checked ?
1062 extra.indeterminate ? CBS_MIXEDDISABLED : 1044 CBS_CHECKEDDISABLED :
1063 CBS_UNCHECKEDDISABLED; 1045 (extra.indeterminate ? CBS_MIXEDDISABLED : CBS_UNCHECKEDDISABLED);
1064 break; 1046 break;
1065 case kHovered: 1047 case kHovered:
1066 state_id = extra.checked ? CBS_CHECKEDHOT : 1048 state_id = extra.checked ?
1067 extra.indeterminate ? CBS_MIXEDHOT : 1049 CBS_CHECKEDHOT :
1068 CBS_UNCHECKEDHOT; 1050 (extra.indeterminate ? CBS_MIXEDHOT : CBS_UNCHECKEDHOT);
1069 break; 1051 break;
1070 case kNormal: 1052 case kNormal:
1071 state_id = extra.checked ? CBS_CHECKEDNORMAL : 1053 state_id = extra.checked ?
1072 extra.indeterminate ? CBS_MIXEDNORMAL : 1054 CBS_CHECKEDNORMAL :
1073 CBS_UNCHECKEDNORMAL; 1055 (extra.indeterminate ? CBS_MIXEDNORMAL : CBS_UNCHECKEDNORMAL);
1074 break; 1056 break;
1075 case kPressed: 1057 case kPressed:
1076 state_id = extra.checked ? CBS_CHECKEDPRESSED : 1058 state_id = extra.checked ?
1077 extra.indeterminate ? CBS_MIXEDPRESSED : 1059 CBS_CHECKEDPRESSED :
1078 CBS_UNCHECKEDPRESSED; 1060 (extra.indeterminate ? CBS_MIXEDPRESSED : CBS_UNCHECKEDPRESSED);
1079 break; 1061 break;
1080 default: 1062 case kNumStates:
1081 NOTREACHED() << "Invalid state: " << state; 1063 NOTREACHED();
1082 break; 1064 break;
1083 } 1065 }
1084 1066
1085 RECT rect_win = rect.ToRECT(); 1067 RECT rect_win = rect.ToRECT();
1086 return PaintButton(hdc, state, extra, BP_CHECKBOX, state_id, &rect_win); 1068 return PaintButton(hdc, state, extra, BP_CHECKBOX, state_id, &rect_win);
1087 } 1069 }
1088 1070
1089 HRESULT NativeThemeWin::PaintMenuList(HDC hdc, 1071 HRESULT NativeThemeWin::PaintMenuList(HDC hdc,
1090 State state, 1072 State state,
1091 const gfx::Rect& rect, 1073 const gfx::Rect& rect,
1092 const MenuListExtraParams& extra) const { 1074 const MenuListExtraParams& extra) const {
1093 HANDLE handle = GetThemeHandle(MENULIST); 1075 HANDLE handle = GetThemeHandle(MENULIST);
1094 RECT rect_win = rect.ToRECT(); 1076 RECT rect_win = rect.ToRECT();
1095 int state_id; 1077 int state_id;
1096 switch (state) { 1078 switch (state) {
1097 case kNormal:
1098 state_id = CBXS_NORMAL;
1099 break;
1100 case kDisabled: 1079 case kDisabled:
1101 state_id = CBXS_DISABLED; 1080 state_id = CBXS_DISABLED;
1102 break; 1081 break;
1103 case kHovered: 1082 case kHovered:
1104 state_id = CBXS_HOT; 1083 state_id = CBXS_HOT;
1105 break; 1084 break;
1085 case kNormal:
1086 state_id = CBXS_NORMAL;
1087 break;
1106 case kPressed: 1088 case kPressed:
1107 state_id = CBXS_PRESSED; 1089 state_id = CBXS_PRESSED;
1108 break; 1090 break;
1109 default: 1091 case kNumStates:
1110 NOTREACHED() << "Invalid state " << state; 1092 NOTREACHED();
1111 break; 1093 break;
1112 } 1094 }
1113 1095
1114 if (handle && draw_theme_) 1096 if (handle && draw_theme_)
1115 return draw_theme_(handle, hdc, CP_DROPDOWNBUTTON, state_id, &rect_win, 1097 return draw_theme_(handle, hdc, CP_DROPDOWNBUTTON, state_id, &rect_win,
1116 NULL); 1098 NULL);
1117 1099
1118 // Draw it manually. 1100 // Draw it manually.
1119 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, 1101 DrawFrameControl(hdc, &rect_win, DFC_SCROLL,
1120 DFCS_SCROLLCOMBOBOX | extra.classic_state); 1102 DFCS_SCROLLCOMBOBOX | extra.classic_state);
1121 return S_OK; 1103 return S_OK;
1122 } 1104 }
1123 1105
1124 HRESULT NativeThemeWin::PaintScrollbarArrow( 1106 HRESULT NativeThemeWin::PaintScrollbarArrow(
1125 HDC hdc, 1107 HDC hdc,
1126 Part part, 1108 Part part,
1127 State state, 1109 State state,
1128 const gfx::Rect& rect, 1110 const gfx::Rect& rect,
1129 const ScrollbarArrowExtraParams& extra) const { 1111 const ScrollbarArrowExtraParams& extra) const {
1130 static const int state_id_matrix[4][kMaxState] = { 1112 static const int state_id_matrix[4][kNumStates] = {
1131 ABS_DOWNDISABLED, ABS_DOWNHOT, ABS_DOWNNORMAL, ABS_DOWNPRESSED, 1113 ABS_DOWNDISABLED, ABS_DOWNHOT, ABS_DOWNNORMAL, ABS_DOWNPRESSED,
1132 ABS_LEFTDISABLED, ABS_LEFTHOT, ABS_LEFTNORMAL, ABS_LEFTPRESSED, 1114 ABS_LEFTDISABLED, ABS_LEFTHOT, ABS_LEFTNORMAL, ABS_LEFTPRESSED,
1133 ABS_RIGHTDISABLED, ABS_RIGHTHOT, ABS_RIGHTNORMAL, ABS_RIGHTPRESSED, 1115 ABS_RIGHTDISABLED, ABS_RIGHTHOT, ABS_RIGHTNORMAL, ABS_RIGHTPRESSED,
1134 ABS_UPDISABLED, ABS_UPHOT, ABS_UPNORMAL, ABS_UPPRESSED 1116 ABS_UPDISABLED, ABS_UPHOT, ABS_UPNORMAL, ABS_UPPRESSED
1135 }; 1117 };
1136 HANDLE handle = GetThemeHandle(SCROLLBAR); 1118 HANDLE handle = GetThemeHandle(SCROLLBAR);
1137 RECT rect_win = rect.ToRECT(); 1119 RECT rect_win = rect.ToRECT();
1138 if (handle && draw_theme_) { 1120 if (handle && draw_theme_) {
1139 int index = part - kScrollbarDownArrow; 1121 int index = part - kScrollbarDownArrow;
1140 DCHECK(index >=0 && index < 4); 1122 DCHECK_GE(index, 0);
1123 DCHECK_LT(static_cast<size_t>(index), arraysize(state_id_matrix));
1141 int state_id = state_id_matrix[index][state]; 1124 int state_id = state_id_matrix[index][state];
1142 1125
1143 // Hovering means that the cursor is over the scroolbar, but not over the 1126 // Hovering means that the cursor is over the scroolbar, but not over the
1144 // specific arrow itself. We don't want to show it "hot" mode, but only 1127 // specific arrow itself. We don't want to show it "hot" mode, but only
1145 // in "hover" mode. 1128 // in "hover" mode.
1146 if (state == kHovered && extra.is_hovering) { 1129 if (state == kHovered && extra.is_hovering) {
1147 switch (part) { 1130 switch (part) {
1148 case kScrollbarDownArrow: 1131 case kScrollbarDownArrow:
1149 state_id = ABS_DOWNHOVER; 1132 state_id = ABS_DOWNHOVER;
1150 break; 1133 break;
1151 case kScrollbarLeftArrow: 1134 case kScrollbarLeftArrow:
1152 state_id = ABS_LEFTHOVER; 1135 state_id = ABS_LEFTHOVER;
1153 break; 1136 break;
1154 case kScrollbarRightArrow: 1137 case kScrollbarRightArrow:
1155 state_id = ABS_RIGHTHOVER; 1138 state_id = ABS_RIGHTHOVER;
1156 break; 1139 break;
1157 case kScrollbarUpArrow: 1140 case kScrollbarUpArrow:
1158 state_id = ABS_UPHOVER; 1141 state_id = ABS_UPHOVER;
1159 break; 1142 break;
1160 default: 1143 default:
1161 NOTREACHED() << "Invalid part: " << part; 1144 NOTREACHED();
1162 break; 1145 break;
1163 } 1146 }
1164 } 1147 }
1165 return PaintScaledTheme(handle, hdc, SBP_ARROWBTN, state_id, rect); 1148 return PaintScaledTheme(handle, hdc, SBP_ARROWBTN, state_id, rect);
1166 } 1149 }
1167 1150
1168 int classic_state = DFCS_SCROLLDOWN; 1151 int classic_state = DFCS_SCROLLDOWN;
1169 switch (part) { 1152 switch (part) {
1170 case kScrollbarDownArrow: 1153 case kScrollbarDownArrow:
1171 classic_state = DFCS_SCROLLDOWN; 1154 classic_state = DFCS_SCROLLDOWN;
1172 break; 1155 break;
1173 case kScrollbarLeftArrow: 1156 case kScrollbarLeftArrow:
1174 classic_state = DFCS_SCROLLLEFT; 1157 classic_state = DFCS_SCROLLLEFT;
1175 break; 1158 break;
1176 case kScrollbarRightArrow: 1159 case kScrollbarRightArrow:
1177 classic_state = DFCS_SCROLLRIGHT; 1160 classic_state = DFCS_SCROLLRIGHT;
1178 break; 1161 break;
1179 case kScrollbarUpArrow: 1162 case kScrollbarUpArrow:
1180 classic_state = DFCS_SCROLLUP; 1163 classic_state = DFCS_SCROLLUP;
1181 break; 1164 break;
1182 default: 1165 default:
1183 NOTREACHED() << "Invalid part: " << part; 1166 NOTREACHED();
1184 break; 1167 break;
1185 } 1168 }
1186 switch (state) { 1169 switch (state) {
1187 case kDisabled: 1170 case kDisabled:
1188 classic_state |= DFCS_INACTIVE; 1171 classic_state |= DFCS_INACTIVE;
1189 break; 1172 break;
1190 case kHovered: 1173 case kHovered:
1191 classic_state |= DFCS_HOT; 1174 classic_state |= DFCS_HOT;
1192 break; 1175 break;
1193 case kNormal: 1176 case kNormal:
1194 break; 1177 break;
1195 case kPressed: 1178 case kPressed:
1196 classic_state |= DFCS_PUSHED; 1179 classic_state |= DFCS_PUSHED;
1197 break; 1180 break;
1198 default: 1181 case kNumStates:
1199 NOTREACHED() << "Invalid state: " << state; 1182 NOTREACHED();
1200 break; 1183 break;
1201 } 1184 }
1202 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, classic_state); 1185 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, classic_state);
1203 return S_OK; 1186 return S_OK;
1204 } 1187 }
1205 1188
1206 HRESULT NativeThemeWin::PaintScrollbarThumb( 1189 HRESULT NativeThemeWin::PaintScrollbarThumb(
1207 HDC hdc, 1190 HDC hdc,
1208 Part part, 1191 Part part,
1209 State state, 1192 State state,
1210 const gfx::Rect& rect, 1193 const gfx::Rect& rect,
1211 const ScrollbarThumbExtraParams& extra) const { 1194 const ScrollbarThumbExtraParams& extra) const {
1212 HANDLE handle = GetThemeHandle(SCROLLBAR); 1195 HANDLE handle = GetThemeHandle(SCROLLBAR);
1213 RECT rect_win = rect.ToRECT(); 1196 RECT rect_win = rect.ToRECT();
1197
1214 int part_id; 1198 int part_id;
1215 int state_id;
1216
1217 switch (part) { 1199 switch (part) {
1218 case NativeTheme::kScrollbarHorizontalThumb: 1200 case NativeTheme::kScrollbarHorizontalThumb:
1219 part_id = SBP_THUMBBTNHORZ; 1201 part_id = SBP_THUMBBTNHORZ;
1220 break; 1202 break;
1221 case NativeTheme::kScrollbarVerticalThumb: 1203 case NativeTheme::kScrollbarVerticalThumb:
1222 part_id = SBP_THUMBBTNVERT; 1204 part_id = SBP_THUMBBTNVERT;
1223 break; 1205 break;
1224 case NativeTheme::kScrollbarHorizontalGripper: 1206 case NativeTheme::kScrollbarHorizontalGripper:
1225 part_id = SBP_GRIPPERHORZ; 1207 part_id = SBP_GRIPPERHORZ;
1226 break; 1208 break;
1227 case NativeTheme::kScrollbarVerticalGripper: 1209 case NativeTheme::kScrollbarVerticalGripper:
1228 part_id = SBP_GRIPPERVERT; 1210 part_id = SBP_GRIPPERVERT;
1229 break; 1211 break;
1230 default: 1212 default:
1231 NOTREACHED() << "Invalid part: " << part; 1213 NOTREACHED();
1232 break; 1214 break;
1233 } 1215 }
1234 1216
1217 int state_id;
1235 switch (state) { 1218 switch (state) {
1236 case kDisabled: 1219 case kDisabled:
1237 state_id = SCRBS_DISABLED; 1220 state_id = SCRBS_DISABLED;
1238 break; 1221 break;
1239 case kHovered: 1222 case kHovered:
1240 state_id = extra.is_hovering ? SCRBS_HOVER : SCRBS_HOT; 1223 state_id = extra.is_hovering ? SCRBS_HOVER : SCRBS_HOT;
1241 break; 1224 break;
1242 case kNormal: 1225 case kNormal:
1243 state_id = SCRBS_NORMAL; 1226 state_id = SCRBS_NORMAL;
1244 break; 1227 break;
1245 case kPressed: 1228 case kPressed:
1246 state_id = SCRBS_PRESSED; 1229 state_id = SCRBS_PRESSED;
1247 break; 1230 break;
1248 default: 1231 case kNumStates:
1249 NOTREACHED() << "Invalid state: " << state; 1232 NOTREACHED();
1250 break; 1233 break;
1251 } 1234 }
1252 1235
1253 if (handle && draw_theme_) 1236 if (handle && draw_theme_)
1254 return PaintScaledTheme(handle, hdc, part_id, state_id, rect); 1237 return PaintScaledTheme(handle, hdc, part_id, state_id, rect);
1255 1238
1256 // Draw it manually. 1239 // Draw it manually.
1257 if ((part_id == SBP_THUMBBTNHORZ) || (part_id == SBP_THUMBBTNVERT)) 1240 if ((part_id == SBP_THUMBBTNHORZ) || (part_id == SBP_THUMBBTNVERT))
1258 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT | BF_MIDDLE); 1241 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT | BF_MIDDLE);
1259 // Classic mode doesn't have a gripper. 1242 // Classic mode doesn't have a gripper.
1260 return S_OK; 1243 return S_OK;
1261 } 1244 }
1262 1245
1263 HRESULT NativeThemeWin::PaintScrollbarTrack( 1246 HRESULT NativeThemeWin::PaintScrollbarTrack(
1264 SkCanvas* canvas, 1247 SkCanvas* canvas,
1265 HDC hdc, 1248 HDC hdc,
1266 Part part, 1249 Part part,
1267 State state, 1250 State state,
1268 const gfx::Rect& rect, 1251 const gfx::Rect& rect,
1269 const ScrollbarTrackExtraParams& extra) const { 1252 const ScrollbarTrackExtraParams& extra) const {
1270 HANDLE handle = GetThemeHandle(SCROLLBAR); 1253 HANDLE handle = GetThemeHandle(SCROLLBAR);
1271 RECT rect_win = rect.ToRECT(); 1254 RECT rect_win = rect.ToRECT();
1255
1272 int part_id; 1256 int part_id;
1273 int state_id;
1274
1275 switch (part) { 1257 switch (part) {
1276 case NativeTheme::kScrollbarHorizontalTrack: 1258 case NativeTheme::kScrollbarHorizontalTrack:
1277 part_id = extra.is_upper ? SBP_UPPERTRACKHORZ : SBP_LOWERTRACKHORZ; 1259 part_id = extra.is_upper ? SBP_UPPERTRACKHORZ : SBP_LOWERTRACKHORZ;
1278 break; 1260 break;
1279 case NativeTheme::kScrollbarVerticalTrack: 1261 case NativeTheme::kScrollbarVerticalTrack:
1280 part_id = extra.is_upper ? SBP_UPPERTRACKVERT : SBP_LOWERTRACKVERT; 1262 part_id = extra.is_upper ? SBP_UPPERTRACKVERT : SBP_LOWERTRACKVERT;
1281 break; 1263 break;
1282 default: 1264 default:
1283 NOTREACHED() << "Invalid part: " << part; 1265 NOTREACHED();
1284 break; 1266 break;
1285 } 1267 }
1286 1268
1269 int state_id;
1287 switch (state) { 1270 switch (state) {
1288 case kDisabled: 1271 case kDisabled:
1289 state_id = SCRBS_DISABLED; 1272 state_id = SCRBS_DISABLED;
1290 break; 1273 break;
1291 case kHovered: 1274 case kHovered:
1292 state_id = SCRBS_HOVER; 1275 state_id = SCRBS_HOVER;
1293 break; 1276 break;
1294 case kNormal: 1277 case kNormal:
1295 state_id = SCRBS_NORMAL; 1278 state_id = SCRBS_NORMAL;
1296 break; 1279 break;
1297 case kPressed: 1280 case kPressed:
1298 state_id = SCRBS_PRESSED; 1281 state_id = SCRBS_PRESSED;
1299 break; 1282 break;
1300 default: 1283 case kNumStates:
1301 NOTREACHED() << "Invalid state: " << state; 1284 NOTREACHED();
1302 break; 1285 break;
1303 } 1286 }
1304 1287
1305 if (handle && draw_theme_) 1288 if (handle && draw_theme_)
1306 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); 1289 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL);
1307 1290
1308 // Draw it manually. 1291 // Draw it manually.
1309 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && 1292 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) &&
1310 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { 1293 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) {
1311 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); 1294 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1));
(...skipping 25 matching lines...) Expand all
1337 break; 1320 break;
1338 case kHovered: 1321 case kHovered:
1339 state_id = extra.spin_up ? UPS_HOT : DNS_HOT; 1322 state_id = extra.spin_up ? UPS_HOT : DNS_HOT;
1340 break; 1323 break;
1341 case kNormal: 1324 case kNormal:
1342 state_id = extra.spin_up ? UPS_NORMAL : DNS_NORMAL; 1325 state_id = extra.spin_up ? UPS_NORMAL : DNS_NORMAL;
1343 break; 1326 break;
1344 case kPressed: 1327 case kPressed:
1345 state_id = extra.spin_up ? UPS_PRESSED : DNS_PRESSED; 1328 state_id = extra.spin_up ? UPS_PRESSED : DNS_PRESSED;
1346 break; 1329 break;
1347 default: 1330 case kNumStates:
1348 NOTREACHED() << "Invalid state " << state; 1331 NOTREACHED();
1349 break; 1332 break;
1350 } 1333 }
1351 1334
1352 if (handle && draw_theme_) 1335 if (handle && draw_theme_)
1353 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); 1336 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL);
1354 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state); 1337 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state);
1355 return S_OK; 1338 return S_OK;
1356 } 1339 }
1357 1340
1358 HRESULT NativeThemeWin::PaintTrackbar( 1341 HRESULT NativeThemeWin::PaintTrackbar(
1359 SkCanvas* canvas, 1342 SkCanvas* canvas,
1360 HDC hdc, 1343 HDC hdc,
1361 Part part, 1344 Part part,
1362 State state, 1345 State state,
1363 const gfx::Rect& rect, 1346 const gfx::Rect& rect,
1364 const TrackbarExtraParams& extra) const { 1347 const TrackbarExtraParams& extra) const {
1365 int part_id = part == kTrackbarTrack ? TKP_TRACK : TKP_THUMBBOTTOM; 1348 const int part_id = extra.vertical ?
1366 if (extra.vertical) 1349 ((part == kTrackbarTrack) ? TKP_TRACKVERT : TKP_THUMBVERT) :
1367 part_id = part == kTrackbarTrack ? TKP_TRACKVERT : TKP_THUMBVERT; 1350 ((part == kTrackbarTrack) ? TKP_TRACK : TKP_THUMBBOTTOM);
1368 1351
1369 int state_id = 0; 1352 int state_id = 0;
1370 switch (state) { 1353 switch (state) {
1371 case kDisabled: 1354 case kDisabled:
1372 state_id = TUS_DISABLED; 1355 state_id = TUS_DISABLED;
1373 break; 1356 break;
1374 case kHovered: 1357 case kHovered:
1375 state_id = TUS_HOT; 1358 state_id = TUS_HOT;
1376 break; 1359 break;
1377 case kNormal: 1360 case kNormal:
1378 state_id = TUS_NORMAL; 1361 state_id = TUS_NORMAL;
1379 break; 1362 break;
1380 case kPressed: 1363 case kPressed:
1381 state_id = TUS_PRESSED; 1364 state_id = TUS_PRESSED;
1382 break; 1365 break;
1383 default: 1366 case kNumStates:
1384 NOTREACHED() << "Invalid state " << state; 1367 NOTREACHED();
1385 break; 1368 break;
1386 } 1369 }
1387 1370
1388 // Make the channel be 4 px thick in the center of the supplied rect. (4 px 1371 // Make the channel be 4 px thick in the center of the supplied rect. (4 px
1389 // matches what XP does in various menus; GetThemePartSize() doesn't seem to 1372 // matches what XP does in various menus; GetThemePartSize() doesn't seem to
1390 // return good values here.) 1373 // return good values here.)
1391 RECT rect_win = rect.ToRECT(); 1374 RECT rect_win = rect.ToRECT();
1392 RECT channel_rect = rect.ToRECT(); 1375 RECT channel_rect = rect.ToRECT();
1393 const int channel_thickness = 4; 1376 const int channel_thickness = 4;
1394 if (part_id == TKP_TRACK) { 1377 if (part_id == TKP_TRACK) {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 return S_OK; 1445 return S_OK;
1463 } 1446 }
1464 1447
1465 HRESULT NativeThemeWin::PaintProgressBar( 1448 HRESULT NativeThemeWin::PaintProgressBar(
1466 HDC hdc, 1449 HDC hdc,
1467 const gfx::Rect& rect, 1450 const gfx::Rect& rect,
1468 const ProgressBarExtraParams& extra) const { 1451 const ProgressBarExtraParams& extra) const {
1469 // There is no documentation about the animation speed, frame-rate, nor 1452 // There is no documentation about the animation speed, frame-rate, nor
1470 // size of moving overlay of the indeterminate progress bar. 1453 // size of moving overlay of the indeterminate progress bar.
1471 // So we just observed real-world programs and guessed following parameters. 1454 // So we just observed real-world programs and guessed following parameters.
1472 const int kDeteminateOverlayPixelsPerSecond = 300; 1455 const int kDeterminateOverlayPixelsPerSecond = 300;
1473 const int kDeteminateOverlayWidth = 120; 1456 const int kDeterminateOverlayWidth = 120;
1474 const int kIndeterminateOverlayPixelsPerSecond = 175; 1457 const int kIndeterminateOverlayPixelsPerSecond = 175;
1475 const int kVistaIndeterminateOverlayWidth = 120; 1458 const int kVistaIndeterminateOverlayWidth = 120;
1476 const int kXPIndeterminateOverlayWidth = 55; 1459 const int kXPIndeterminateOverlayWidth = 55;
1477 // The thickness of the bar frame inside |value_rect| 1460 // The thickness of the bar frame inside |value_rect|
1478 const int kXPBarPadding = 3; 1461 const int kXPBarPadding = 3;
1479 1462
1480 RECT bar_rect = rect.ToRECT(); 1463 RECT bar_rect = rect.ToRECT();
1481 RECT value_rect = gfx::Rect(extra.value_rect_x, 1464 RECT value_rect = gfx::Rect(extra.value_rect_x,
1482 extra.value_rect_y, 1465 extra.value_rect_y,
1483 extra.value_rect_width, 1466 extra.value_rect_width,
1484 extra.value_rect_height).ToRECT(); 1467 extra.value_rect_height).ToRECT();
1485 1468
1486 bool pre_vista = base::win::GetVersion() < base::win::VERSION_VISTA;
1487 HANDLE handle = GetThemeHandle(PROGRESS); 1469 HANDLE handle = GetThemeHandle(PROGRESS);
1488 if (handle && draw_theme_ && draw_theme_ex_) { 1470 if (!handle || !draw_theme_ || !draw_theme_ex_) {
1489 draw_theme_(handle, hdc, PP_BAR, 0, &bar_rect, NULL); 1471 FillRect(hdc, &bar_rect, GetSysColorBrush(COLOR_BTNFACE));
1490 1472 FillRect(hdc, &value_rect, GetSysColorBrush(COLOR_BTNSHADOW));
1491 int bar_width = bar_rect.right - bar_rect.left; 1473 DrawEdge(hdc, &bar_rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1492 if (extra.determinate) {
1493 // TODO(morrita): this RTL guess can be wrong.
1494 // We should pass the direction from WebKit side.
1495 bool is_rtl = (bar_rect.right == value_rect.right &&
1496 bar_rect.left != value_rect.left);
1497 // We should care the direction here because PP_CNUNK painting
1498 // is asymmetric.
1499 DTBGOPTS value_draw_options;
1500 value_draw_options.dwSize = sizeof(DTBGOPTS);
1501 value_draw_options.dwFlags = is_rtl ? DTBG_MIRRORDC : 0;
1502 value_draw_options.rcClip = bar_rect;
1503
1504 if (pre_vista) {
1505 // On XP, progress bar is chunk-style and has no glossy effect.
1506 // We need to shrink destination rect to fit the part inside the bar
1507 // with an appropriate margin.
1508 RECT shrunk_value_rect = InsetRect(&value_rect, kXPBarPadding);
1509 draw_theme_ex_(handle, hdc, PP_CHUNK, 0,
1510 &shrunk_value_rect, &value_draw_options);
1511 } else {
1512 // On Vista or later, the progress bar part has a
1513 // single-block value part. It also has glossy effect.
1514 // And the value part has exactly same height as the bar part
1515 // so we don't need to shrink the rect.
1516 draw_theme_ex_(handle, hdc, PP_FILL, 0,
1517 &value_rect, &value_draw_options);
1518
1519 int dx = ComputeAnimationProgress(bar_width,
1520 kDeteminateOverlayWidth,
1521 kDeteminateOverlayPixelsPerSecond,
1522 extra.animated_seconds);
1523 RECT overlay_rect = value_rect;
1524 overlay_rect.left += dx;
1525 overlay_rect.right = overlay_rect.left + kDeteminateOverlayWidth;
1526 draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, &value_rect);
1527 }
1528 } else {
1529 // A glossy overlay for indeterminate progress bar has small pause
1530 // after each animation. We emulate this by adding an invisible margin
1531 // the animation has to traverse.
1532 int width_with_margin = bar_width + kIndeterminateOverlayPixelsPerSecond;
1533 int overlay_width = pre_vista ?
1534 kXPIndeterminateOverlayWidth : kVistaIndeterminateOverlayWidth;
1535 int dx = ComputeAnimationProgress(width_with_margin,
1536 overlay_width,
1537 kIndeterminateOverlayPixelsPerSecond,
1538 extra.animated_seconds);
1539 RECT overlay_rect = bar_rect;
1540 overlay_rect.left += dx;
1541 overlay_rect.right = overlay_rect.left + overlay_width;
1542 if (pre_vista) {
1543 RECT shrunk_rect = InsetRect(&overlay_rect, kXPBarPadding);
1544 RECT shrunk_bar_rect = InsetRect(&bar_rect, kXPBarPadding);
1545 draw_theme_(handle, hdc, PP_CHUNK, 0, &shrunk_rect, &shrunk_bar_rect);
1546 } else {
1547 draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, &bar_rect);
1548 }
1549 }
1550
1551 return S_OK; 1474 return S_OK;
1552 } 1475 }
1553 1476
1554 HBRUSH bg_brush = GetSysColorBrush(COLOR_BTNFACE); 1477 draw_theme_(handle, hdc, PP_BAR, 0, &bar_rect, NULL);
1555 HBRUSH fg_brush = GetSysColorBrush(COLOR_BTNSHADOW); 1478
1556 FillRect(hdc, &bar_rect, bg_brush); 1479 bool pre_vista = base::win::GetVersion() < base::win::VERSION_VISTA;
1557 FillRect(hdc, &value_rect, fg_brush); 1480 int bar_width = bar_rect.right - bar_rect.left;
1558 DrawEdge(hdc, &bar_rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); 1481 if (!extra.determinate) {
1482 // The glossy overlay for the indeterminate progress bar has a small pause
1483 // after each animation. We emulate this by adding an invisible margin the
1484 // animation has to traverse.
1485 int width_with_margin = bar_width + kIndeterminateOverlayPixelsPerSecond;
1486 int overlay_width = pre_vista ?
1487 kXPIndeterminateOverlayWidth : kVistaIndeterminateOverlayWidth;
1488 RECT overlay_rect = bar_rect;
1489 overlay_rect.left += ComputeAnimationProgress(
1490 width_with_margin, overlay_width, kIndeterminateOverlayPixelsPerSecond,
1491 extra.animated_seconds);
1492 overlay_rect.right = overlay_rect.left + overlay_width;
1493 if (pre_vista) {
1494 RECT shrunk_rect = InsetRect(&overlay_rect, kXPBarPadding);
1495 RECT shrunk_bar_rect = InsetRect(&bar_rect, kXPBarPadding);
1496 draw_theme_(handle, hdc, PP_CHUNK, 0, &shrunk_rect, &shrunk_bar_rect);
1497 } else {
1498 draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, &bar_rect);
1499 }
1500 return S_OK;
1501 }
1502
1503 // We care about the direction here because PP_CHUNK painting is asymmetric.
1504 // TODO(morrita): This RTL guess can be wrong. We should pass in the
1505 // direction from WebKit.
1506 const DTBGOPTS value_draw_options = {
1507 sizeof(DTBGOPTS),
1508 (bar_rect.right == value_rect.right && bar_rect.left != value_rect.left) ?
1509 DTBG_MIRRORDC : 0,
1510 bar_rect
1511 };
1512 if (pre_vista) {
1513 // On XP, the progress bar is chunk-style and has no glossy effect. We need
1514 // to shrink the destination rect to fit the part inside the bar with an
1515 // appropriate margin.
1516 RECT shrunk_value_rect = InsetRect(&value_rect, kXPBarPadding);
1517 draw_theme_ex_(handle, hdc, PP_CHUNK, 0, &shrunk_value_rect,
1518 &value_draw_options);
1519 } else {
1520 // On Vista or later, the progress bar part has a single-block value part
1521 // and a glossy effect. The value part has exactly same height as the bar
1522 // part, so we don't need to shrink the rect.
1523 draw_theme_ex_(handle, hdc, PP_FILL, 0, &value_rect, &value_draw_options);
1524
1525 RECT overlay_rect = value_rect;
1526 overlay_rect.left += ComputeAnimationProgress(
1527 bar_width, kDeterminateOverlayWidth, kDeterminateOverlayPixelsPerSecond,
1528 extra.animated_seconds);
1529 overlay_rect.right = overlay_rect.left + kDeterminateOverlayWidth;
1530 draw_theme_(handle, hdc, PP_MOVEOVERLAY, 0, &overlay_rect, &value_rect);
1531 }
1559 return S_OK; 1532 return S_OK;
1560 } 1533 }
1561 1534
1562 HRESULT NativeThemeWin::PaintWindowResizeGripper(HDC hdc, 1535 HRESULT NativeThemeWin::PaintWindowResizeGripper(HDC hdc,
1563 const gfx::Rect& rect) const { 1536 const gfx::Rect& rect) const {
1564 HANDLE handle = GetThemeHandle(STATUS); 1537 HANDLE handle = GetThemeHandle(STATUS);
1565 RECT rect_win = rect.ToRECT(); 1538 RECT rect_win = rect.ToRECT();
1566 if (handle && draw_theme_) { 1539 if (handle && draw_theme_) {
1567 // Paint the status bar gripper. There doesn't seem to be a 1540 // Paint the status bar gripper. There doesn't seem to be a standard
1568 // standard gripper in Windows for the space between 1541 // gripper in Windows for the space between scrollbars. This is pretty
1569 // scrollbars. This is pretty close, but it's supposed to be 1542 // close, but it's supposed to be painted over a status bar.
1570 // painted over a status bar.
1571 return draw_theme_(handle, hdc, SP_GRIPPER, 0, &rect_win, NULL); 1543 return draw_theme_(handle, hdc, SP_GRIPPER, 0, &rect_win, NULL);
1572 } 1544 }
1573 1545
1574 // Draw a windows classic scrollbar gripper. 1546 // Draw a windows classic scrollbar gripper.
1575 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, DFCS_SCROLLSIZEGRIP); 1547 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
1576 return S_OK; 1548 return S_OK;
1577 } 1549 }
1578 1550
1579 HRESULT NativeThemeWin::PaintTabPanelBackground(HDC hdc, 1551 HRESULT NativeThemeWin::PaintTabPanelBackground(HDC hdc,
1580 const gfx::Rect& rect) const { 1552 const gfx::Rect& rect) const {
1581 HANDLE handle = GetThemeHandle(TAB); 1553 HANDLE handle = GetThemeHandle(TAB);
1582 RECT rect_win = rect.ToRECT(); 1554 RECT rect_win = rect.ToRECT();
1583 if (handle && draw_theme_) 1555 if (handle && draw_theme_)
1584 return draw_theme_(handle, hdc, TABP_BODY, 0, &rect_win, NULL); 1556 return draw_theme_(handle, hdc, TABP_BODY, 0, &rect_win, NULL);
1585 1557
1586 // Classic just renders a flat color background. 1558 // Classic just renders a flat color background.
1587 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1)); 1559 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1));
1588 return S_OK; 1560 return S_OK;
1589 } 1561 }
1590 1562
1591 HRESULT NativeThemeWin::PaintTextField( 1563 HRESULT NativeThemeWin::PaintTextField(
1592 HDC hdc, 1564 HDC hdc,
1593 Part part, 1565 Part part,
1594 State state, 1566 State state,
1595 const gfx::Rect& rect, 1567 const gfx::Rect& rect,
1596 const TextFieldExtraParams& extra) const { 1568 const TextFieldExtraParams& extra) const {
1597 int part_id = EP_EDITTEXT;
1598 int state_id = ETS_NORMAL; 1569 int state_id = ETS_NORMAL;
1599 switch (state) { 1570 switch (state) {
1600 case kNormal: 1571 case kDisabled:
1601 if (extra.is_read_only) { 1572 state_id = ETS_DISABLED;
1602 state_id = ETS_READONLY;
1603 } else if (extra.is_focused) {
1604 state_id = ETS_FOCUSED;
1605 } else {
1606 state_id = ETS_NORMAL;
1607 }
1608 break; 1573 break;
1609 case kHovered: 1574 case kHovered:
1610 state_id = ETS_HOT; 1575 state_id = ETS_HOT;
1611 break; 1576 break;
1577 case kNormal:
1578 if (extra.is_read_only)
1579 state_id = ETS_READONLY;
1580 else if (extra.is_focused)
1581 state_id = ETS_FOCUSED;
1582 else
1583 state_id = ETS_NORMAL;
1584 break;
1612 case kPressed: 1585 case kPressed:
1613 state_id = ETS_SELECTED; 1586 state_id = ETS_SELECTED;
1614 break; 1587 break;
1615 case kDisabled: 1588 case kNumStates:
1616 state_id = ETS_DISABLED; 1589 NOTREACHED();
1617 break;
1618 default:
1619 NOTREACHED() << "Invalid state: " << state;
1620 break; 1590 break;
1621 } 1591 }
1622 1592
1623 RECT rect_win = rect.ToRECT(); 1593 RECT rect_win = rect.ToRECT();
1624 return PaintTextField(hdc, part_id, state_id, extra.classic_state, 1594 return PaintTextField(hdc, EP_EDITTEXT, state_id, extra.classic_state,
1625 &rect_win, 1595 &rect_win,
1626 skia::SkColorToCOLORREF(extra.background_color), 1596 skia::SkColorToCOLORREF(extra.background_color),
1627 extra.fill_content_area, extra.draw_edges); 1597 extra.fill_content_area, extra.draw_edges);
1628 } 1598 }
1629 1599
1630 HRESULT NativeThemeWin::PaintTextField(HDC hdc, 1600 HRESULT NativeThemeWin::PaintTextField(HDC hdc,
1631 int part_id, 1601 int part_id,
1632 int state_id, 1602 int state_id,
1633 int classic_state, 1603 int classic_state,
1634 RECT* rect, 1604 RECT* rect,
1635 COLORREF color, 1605 COLORREF color,
1636 bool fill_content_area, 1606 bool fill_content_area,
1637 bool draw_edges) const { 1607 bool draw_edges) const {
1638 // TODO(ojan): http://b/1210017 Figure out how to give the ability to 1608 // TODO(ojan): http://b/1210017 Figure out how to give the ability to
1639 // exclude individual edges from being drawn. 1609 // exclude individual edges from being drawn.
1640 1610
1641 HANDLE handle = GetThemeHandle(TEXTFIELD); 1611 HANDLE handle = GetThemeHandle(TEXTFIELD);
1642 // TODO(mpcomplete): can we detect if the color is specified by the user, 1612 // TODO(mpcomplete): can we detect if the color is specified by the user,
1643 // and if not, just use the system color? 1613 // and if not, just use the system color?
1644 // CreateSolidBrush() accepts a RGB value but alpha must be 0. 1614 // CreateSolidBrush() accepts a RGB value but alpha must be 0.
1645 HBRUSH bg_brush = CreateSolidBrush(color); 1615 base::win::ScopedGDIObject<HBRUSH> bg_brush(CreateSolidBrush(color));
1646 HRESULT hr;
1647 // DrawThemeBackgroundEx was introduced in XP SP2, so that it's possible 1616 // DrawThemeBackgroundEx was introduced in XP SP2, so that it's possible
1648 // draw_theme_ex_ is NULL and draw_theme_ is non-null. 1617 // draw_theme_ex_ is NULL and draw_theme_ is non-null.
1649 if (handle && (draw_theme_ex_ || (draw_theme_ && draw_edges))) { 1618 if (!handle || (!draw_theme_ex_ && (!draw_theme_ || !draw_edges))) {
1650 if (draw_theme_ex_) {
1651 static const DTBGOPTS omit_border_options = {
1652 sizeof(DTBGOPTS),
1653 DTBG_OMITBORDER,
1654 { 0, 0, 0, 0 }
1655 };
1656 const DTBGOPTS* draw_opts = draw_edges ? NULL : &omit_border_options;
1657 hr = draw_theme_ex_(handle, hdc, part_id, state_id, rect, draw_opts);
1658 } else {
1659 hr = draw_theme_(handle, hdc, part_id, state_id, rect, NULL);
1660 }
1661
1662 // TODO(maruel): Need to be fixed if get_theme_content_rect_ is NULL.
1663 if (fill_content_area && get_theme_content_rect_) {
1664 RECT content_rect;
1665 hr = get_theme_content_rect_(handle, hdc, part_id, state_id, rect,
1666 &content_rect);
1667 FillRect(hdc, &content_rect, bg_brush);
1668 }
1669 } else {
1670 // Draw it manually. 1619 // Draw it manually.
1671 if (draw_edges) 1620 if (draw_edges)
1672 DrawEdge(hdc, rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST); 1621 DrawEdge(hdc, rect, EDGE_SUNKEN, BF_RECT | BF_ADJUST);
1673 1622
1674 if (fill_content_area) { 1623 if (fill_content_area) {
1675 FillRect(hdc, rect, (classic_state & DFCS_INACTIVE) ? 1624 FillRect(hdc, rect, (classic_state & DFCS_INACTIVE) ?
1676 reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1) : bg_brush); 1625 reinterpret_cast<HBRUSH>(COLOR_BTNFACE + 1) : bg_brush);
1677 } 1626 }
1678 hr = S_OK; 1627 return S_OK;
1679 } 1628 }
1680 DeleteObject(bg_brush); 1629
1630 static const DTBGOPTS omit_border_options = {
1631 sizeof(DTBGOPTS),
1632 DTBG_OMITBORDER,
1633 { 0, 0, 0, 0 }
1634 };
1635 HRESULT hr = draw_theme_ex_ ?
1636 draw_theme_ex_(handle, hdc, part_id, state_id, rect,
1637 draw_edges ? NULL : &omit_border_options) :
1638 draw_theme_(handle, hdc, part_id, state_id, rect, NULL);
1639
1640 // TODO(maruel): Need to be fixed if get_theme_content_rect_ is NULL.
1641 if (fill_content_area && get_theme_content_rect_) {
1642 RECT content_rect;
1643 hr = get_theme_content_rect_(handle, hdc, part_id, state_id, rect,
1644 &content_rect);
1645 FillRect(hdc, &content_rect, bg_brush);
1646 }
1681 return hr; 1647 return hr;
1682 } 1648 }
1683 1649
1684 HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme, 1650 HRESULT NativeThemeWin::PaintScaledTheme(HANDLE theme,
1685 HDC hdc, 1651 HDC hdc,
1686 int part_id, 1652 int part_id,
1687 int state_id, 1653 int state_id,
1688 const gfx::Rect& rect) const { 1654 const gfx::Rect& rect) const {
1689 // Correct the scaling and positioning of sub-components such as scrollbar 1655 // Correct the scaling and positioning of sub-components such as scrollbar
1690 // arrows and thumb grippers in the event that the world transform applies 1656 // arrows and thumb grippers in the event that the world transform applies
1691 // scaling (e.g. in high-DPI mode). 1657 // scaling (e.g. in high-DPI mode).
1692 XFORM save_transform; 1658 XFORM save_transform;
1693 if (GetWorldTransform(hdc, &save_transform)) { 1659 if (GetWorldTransform(hdc, &save_transform)) {
1694 float scale = save_transform.eM11; 1660 float scale = save_transform.eM11;
1695 if (scale != 1 && save_transform.eM12 == 0) { 1661 if (scale != 1 && save_transform.eM12 == 0) {
1696 ModifyWorldTransform(hdc, NULL, MWT_IDENTITY); 1662 ModifyWorldTransform(hdc, NULL, MWT_IDENTITY);
1697 gfx::Rect scaled_rect = gfx::ToEnclosedRect( 1663 gfx::Rect scaled_rect(gfx::ToEnclosedRect(gfx::ScaleRect(rect, scale)));
1698 gfx::ScaleRect(rect, scale)); 1664 scaled_rect.Offset(save_transform.eDx, save_transform.eDy);
1699 RECT bounds = gfx::Rect(scaled_rect.x() + save_transform.eDx, 1665 RECT bounds = scaled_rect.ToRECT();
1700 scaled_rect.y() + save_transform.eDy,
1701 scaled_rect.width(),
1702 scaled_rect.height()).ToRECT();
1703 HRESULT result = draw_theme_(theme, hdc, part_id, state_id, &bounds, 1666 HRESULT result = draw_theme_(theme, hdc, part_id, state_id, &bounds,
1704 NULL); 1667 NULL);
1705 SetWorldTransform(hdc, &save_transform); 1668 SetWorldTransform(hdc, &save_transform);
1706 return result; 1669 return result;
1707 } 1670 }
1708 } 1671 }
1709 RECT bounds = rect.ToRECT(); 1672 RECT bounds = rect.ToRECT();
1710 return draw_theme_(theme, hdc, part_id, state_id, &bounds, NULL); 1673 return draw_theme_(theme, hdc, part_id, state_id, &bounds, NULL);
1711 } 1674 }
1712 1675
1713 // static 1676 // static
1714 NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) { 1677 NativeThemeWin::ThemeName NativeThemeWin::GetThemeName(Part part) {
1715 ThemeName name;
1716 switch (part) { 1678 switch (part) {
1717 case kCheckbox: 1679 case kCheckbox:
1680 case kPushButton:
1718 case kRadio: 1681 case kRadio:
1719 case kPushButton: 1682 return BUTTON;
1720 name = BUTTON;
1721 break;
1722 case kInnerSpinButton: 1683 case kInnerSpinButton:
1723 name = SPIN; 1684 return SPIN;
1724 break; 1685 case kMenuList:
1725 case kMenuCheck: 1686 case kMenuCheck:
1687 case kMenuPopupArrow:
1726 case kMenuPopupGutter: 1688 case kMenuPopupGutter:
1727 case kMenuList:
1728 case kMenuPopupArrow:
1729 case kMenuPopupSeparator: 1689 case kMenuPopupSeparator:
1730 name = MENU; 1690 return MENU;
1731 break;
1732 case kProgressBar: 1691 case kProgressBar:
1733 name = PROGRESS; 1692 return PROGRESS;
1734 break;
1735 case kScrollbarDownArrow: 1693 case kScrollbarDownArrow:
1736 case kScrollbarLeftArrow: 1694 case kScrollbarLeftArrow:
1737 case kScrollbarRightArrow: 1695 case kScrollbarRightArrow:
1738 case kScrollbarUpArrow: 1696 case kScrollbarUpArrow:
1739 case kScrollbarHorizontalThumb: 1697 case kScrollbarHorizontalThumb:
1740 case kScrollbarVerticalThumb: 1698 case kScrollbarVerticalThumb:
1741 case kScrollbarHorizontalTrack: 1699 case kScrollbarHorizontalTrack:
1742 case kScrollbarVerticalTrack: 1700 case kScrollbarVerticalTrack:
1743 name = SCROLLBAR; 1701 return SCROLLBAR;
1744 break;
1745 case kSliderTrack: 1702 case kSliderTrack:
1746 case kSliderThumb: 1703 case kSliderThumb:
1747 name = TRACKBAR; 1704 return TRACKBAR;
1748 break;
1749 case kTextField: 1705 case kTextField:
1750 name = TEXTFIELD; 1706 return TEXTFIELD;
1751 break;
1752 case kWindowResizeGripper: 1707 case kWindowResizeGripper:
1753 name = STATUS; 1708 return STATUS;
1754 break; 1709 case kComboboxArrow:
1755 default: 1710 case kMenuCheckBackground:
1756 NOTREACHED() << "Invalid part: " << part; 1711 case kMenuPopupBackground:
1757 break; 1712 case kMenuItemBackground:
1713 case kScrollbarHorizontalGripper:
1714 case kScrollbarVerticalGripper:
1715 case kScrollbarCorner:
1716 case kTabPanelBackground:
1717 case kTrackbarThumb:
1718 case kTrackbarTrack:
1719 case kMaxPart:
1720 NOTREACHED();
1758 } 1721 }
1759 return name; 1722 return LAST;
1760 } 1723 }
1761 1724
1762 // static 1725 // static
1763 int NativeThemeWin::GetWindowsPart(Part part, 1726 int NativeThemeWin::GetWindowsPart(Part part,
1764 State state, 1727 State state,
1765 const ExtraParams& extra) { 1728 const ExtraParams& extra) {
1766 int part_id;
1767 switch (part) { 1729 switch (part) {
1768 case kCheckbox: 1730 case kCheckbox:
1769 part_id = BP_CHECKBOX; 1731 return BP_CHECKBOX;
1770 break;
1771 case kMenuCheck: 1732 case kMenuCheck:
1772 part_id = MENU_POPUPCHECK; 1733 return MENU_POPUPCHECK;
1773 break;
1774 case kMenuPopupArrow: 1734 case kMenuPopupArrow:
1775 part_id = MENU_POPUPSUBMENU; 1735 return MENU_POPUPSUBMENU;
1776 break;
1777 case kMenuPopupGutter: 1736 case kMenuPopupGutter:
1778 part_id = MENU_POPUPGUTTER; 1737 return MENU_POPUPGUTTER;
1779 break;
1780 case kMenuPopupSeparator: 1738 case kMenuPopupSeparator:
1781 part_id = MENU_POPUPSEPARATOR; 1739 return MENU_POPUPSEPARATOR;
1782 break;
1783 case kPushButton: 1740 case kPushButton:
1784 part_id = BP_PUSHBUTTON; 1741 return BP_PUSHBUTTON;
1785 break;
1786 case kRadio: 1742 case kRadio:
1787 part_id = BP_RADIOBUTTON; 1743 return BP_RADIOBUTTON;
1788 break;
1789 case kWindowResizeGripper:
1790 part_id = SP_GRIPPER;
1791 break;
1792 case kScrollbarDownArrow: 1744 case kScrollbarDownArrow:
1793 case kScrollbarLeftArrow: 1745 case kScrollbarLeftArrow:
1794 case kScrollbarRightArrow: 1746 case kScrollbarRightArrow:
1795 case kScrollbarUpArrow: 1747 case kScrollbarUpArrow:
1796 part_id = SBP_ARROWBTN; 1748 return SBP_ARROWBTN;
1797 break;
1798 case kScrollbarHorizontalThumb: 1749 case kScrollbarHorizontalThumb:
1799 part_id = SBP_THUMBBTNHORZ; 1750 return SBP_THUMBBTNHORZ;
1800 break;
1801 case kScrollbarVerticalThumb: 1751 case kScrollbarVerticalThumb:
1802 part_id = SBP_THUMBBTNVERT; 1752 return SBP_THUMBBTNVERT;
1803 break; 1753 case kWindowResizeGripper:
1804 default: 1754 return SP_GRIPPER;
1805 NOTREACHED() << "Invalid part: " << part; 1755 case kComboboxArrow:
1806 break; 1756 case kInnerSpinButton:
1757 case kMenuList:
1758 case kMenuCheckBackground:
1759 case kMenuPopupBackground:
1760 case kMenuItemBackground:
1761 case kProgressBar:
1762 case kScrollbarHorizontalTrack:
1763 case kScrollbarVerticalTrack:
1764 case kScrollbarHorizontalGripper:
1765 case kScrollbarVerticalGripper:
1766 case kScrollbarCorner:
1767 case kSliderTrack:
1768 case kSliderThumb:
1769 case kTabPanelBackground:
1770 case kTextField:
1771 case kTrackbarThumb:
1772 case kTrackbarTrack:
1773 case kMaxPart:
1774 NOTREACHED();
1807 } 1775 }
1808 return part_id; 1776 return 0;
1809 } 1777 }
1810 1778
1811 int NativeThemeWin::GetWindowsState(Part part, 1779 int NativeThemeWin::GetWindowsState(Part part,
1812 State state, 1780 State state,
1813 const ExtraParams& extra) { 1781 const ExtraParams& extra) {
1814 int state_id;
1815 switch (part) { 1782 switch (part) {
1816 case kCheckbox: 1783 case kCheckbox:
1817 switch (state) { 1784 switch (state) {
1818 case kNormal: 1785 case kDisabled:
1819 state_id = CBS_UNCHECKEDNORMAL; 1786 return CBS_UNCHECKEDDISABLED;
1820 break; 1787 case kHovered:
1821 case kHovered: 1788 return CBS_UNCHECKEDHOT;
1822 state_id = CBS_UNCHECKEDHOT; 1789 case kNormal:
1823 break; 1790 return CBS_UNCHECKEDNORMAL;
1824 case kPressed: 1791 case kPressed:
1825 state_id = CBS_UNCHECKEDPRESSED; 1792 return CBS_UNCHECKEDPRESSED;
1826 break; 1793 case kNumStates:
1827 case kDisabled: 1794 NOTREACHED();
1828 state_id = CBS_UNCHECKEDDISABLED; 1795 return 0;
1829 break; 1796 }
1830 default:
1831 NOTREACHED() << "Invalid state: " << state;
1832 break;
1833 }
1834 break;
1835 case kMenuCheck: 1797 case kMenuCheck:
1836 switch (state) { 1798 switch (state) {
1837 case kNormal: 1799 case kDisabled:
1838 case kHovered: 1800 return extra.menu_check.is_radio ?
1839 case kPressed: 1801 MC_BULLETDISABLED : MC_CHECKMARKDISABLED;
1840 state_id = extra.menu_check.is_radio ? MC_BULLETNORMAL 1802 case kHovered:
1841 : MC_CHECKMARKNORMAL; 1803 case kNormal:
1842 break; 1804 case kPressed:
1843 case kDisabled: 1805 return extra.menu_check.is_radio ?
1844 state_id = extra.menu_check.is_radio ? MC_BULLETDISABLED 1806 MC_BULLETNORMAL : MC_CHECKMARKNORMAL;
1845 : MC_CHECKMARKDISABLED; 1807 case kNumStates:
1846 break; 1808 NOTREACHED();
1847 default: 1809 return 0;
1848 NOTREACHED() << "Invalid state: " << state; 1810 }
1849 break;
1850 }
1851 break;
1852 case kMenuPopupArrow: 1811 case kMenuPopupArrow:
1853 case kMenuPopupGutter: 1812 case kMenuPopupGutter:
1854 case kMenuPopupSeparator: 1813 case kMenuPopupSeparator:
1855 switch (state) { 1814 switch (state) {
1856 case kNormal: 1815 case kDisabled:
1857 state_id = MBI_NORMAL; 1816 return MBI_DISABLED;
1858 break; 1817 case kHovered:
1859 case kHovered: 1818 return MBI_HOT;
1860 state_id = MBI_HOT; 1819 case kNormal:
1861 break; 1820 return MBI_NORMAL;
1862 case kPressed: 1821 case kPressed:
1863 state_id = MBI_PUSHED; 1822 return MBI_PUSHED;
1864 break; 1823 case kNumStates:
1865 case kDisabled: 1824 NOTREACHED();
1866 state_id = MBI_DISABLED; 1825 return 0;
1867 break; 1826 }
1868 default:
1869 NOTREACHED() << "Invalid state: " << state;
1870 break;
1871 }
1872 break;
1873 case kPushButton: 1827 case kPushButton:
1874 switch (state) { 1828 switch (state) {
1875 case kNormal: 1829 case kDisabled:
1876 state_id = PBS_NORMAL; 1830 return PBS_DISABLED;
1877 break; 1831 case kHovered:
1878 case kHovered: 1832 return PBS_HOT;
1879 state_id = PBS_HOT; 1833 case kNormal:
1880 break; 1834 return PBS_NORMAL;
1881 case kPressed: 1835 case kPressed:
1882 state_id = PBS_PRESSED; 1836 return PBS_PRESSED;
1883 break; 1837 case kNumStates:
1884 case kDisabled: 1838 NOTREACHED();
1885 state_id = PBS_DISABLED; 1839 return 0;
1886 break; 1840 }
1887 default:
1888 NOTREACHED() << "Invalid state: " << state;
1889 break;
1890 }
1891 break;
1892 case kRadio: 1841 case kRadio:
1893 switch (state) { 1842 switch (state) {
1894 case kNormal: 1843 case kDisabled:
1895 state_id = RBS_UNCHECKEDNORMAL; 1844 return RBS_UNCHECKEDDISABLED;
1896 break; 1845 case kHovered:
1897 case kHovered: 1846 return RBS_UNCHECKEDHOT;
1898 state_id = RBS_UNCHECKEDHOT; 1847 case kNormal:
1899 break; 1848 return RBS_UNCHECKEDNORMAL;
1900 case kPressed: 1849 case kPressed:
1901 state_id = RBS_UNCHECKEDPRESSED; 1850 return RBS_UNCHECKEDPRESSED;
1902 break; 1851 case kNumStates:
1903 case kDisabled: 1852 NOTREACHED();
1904 state_id = RBS_UNCHECKEDDISABLED; 1853 return 0;
1905 break; 1854 }
1906 default:
1907 NOTREACHED() << "Invalid state: " << state;
1908 break;
1909 }
1910 break;
1911 case kWindowResizeGripper:
1912 switch (state) {
1913 case kNormal:
1914 case kHovered:
1915 case kPressed:
1916 case kDisabled:
1917 state_id = 1; // gripper has no windows state
1918 break;
1919 default:
1920 NOTREACHED() << "Invalid state: " << state;
1921 break;
1922 }
1923 break;
1924 case kScrollbarDownArrow: 1855 case kScrollbarDownArrow:
1925 switch (state) { 1856 switch (state) {
1926 case kNormal: 1857 case kDisabled:
1927 state_id = ABS_DOWNNORMAL; 1858 return ABS_DOWNDISABLED;
1928 break; 1859 case kHovered:
1929 case kHovered: 1860 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1930 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit. 1861 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1931 state_id = base::win::GetVersion() < base::win::VERSION_VISTA ?
1932 ABS_DOWNHOT : ABS_DOWNHOVER; 1862 ABS_DOWNHOT : ABS_DOWNHOVER;
1933 break; 1863 case kNormal:
1934 case kPressed: 1864 return ABS_DOWNNORMAL;
1935 state_id = ABS_DOWNPRESSED; 1865 case kPressed:
1936 break; 1866 return ABS_DOWNPRESSED;
1937 case kDisabled: 1867 case kNumStates:
1938 state_id = ABS_DOWNDISABLED; 1868 NOTREACHED();
1939 break; 1869 return 0;
1940 default: 1870 }
1941 NOTREACHED() << "Invalid state: " << state;
1942 break;
1943 }
1944 break;
1945 case kScrollbarLeftArrow: 1871 case kScrollbarLeftArrow:
1946 switch (state) { 1872 switch (state) {
1947 case kNormal: 1873 case kDisabled:
1948 state_id = ABS_LEFTNORMAL; 1874 return ABS_LEFTDISABLED;
1949 break; 1875 case kHovered:
1950 case kHovered: 1876 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1951 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit. 1877 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1952 state_id = base::win::GetVersion() < base::win::VERSION_VISTA ?
1953 ABS_LEFTHOT : ABS_LEFTHOVER; 1878 ABS_LEFTHOT : ABS_LEFTHOVER;
1954 break; 1879 case kNormal:
1955 case kPressed: 1880 return ABS_LEFTNORMAL;
1956 state_id = ABS_LEFTPRESSED; 1881 case kPressed:
1957 break; 1882 return ABS_LEFTPRESSED;
1958 case kDisabled: 1883 case kNumStates:
1959 state_id = ABS_LEFTDISABLED; 1884 NOTREACHED();
1960 break; 1885 return 0;
1961 default: 1886 }
1962 NOTREACHED() << "Invalid state: " << state;
1963 break;
1964 }
1965 break;
1966 case kScrollbarRightArrow: 1887 case kScrollbarRightArrow:
1967 switch (state) { 1888 switch (state) {
1968 case kNormal: 1889 case kDisabled:
1969 state_id = ABS_RIGHTNORMAL; 1890 return ABS_RIGHTDISABLED;
1970 break; 1891 case kHovered:
1971 case kHovered: 1892 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1972 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit. 1893 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1973 state_id = base::win::GetVersion() < base::win::VERSION_VISTA ?
1974 ABS_RIGHTHOT : ABS_RIGHTHOVER; 1894 ABS_RIGHTHOT : ABS_RIGHTHOVER;
1975 break; 1895 case kNormal:
1976 case kPressed: 1896 return ABS_RIGHTNORMAL;
1977 state_id = ABS_RIGHTPRESSED; 1897 case kPressed:
1978 break; 1898 return ABS_RIGHTPRESSED;
1979 case kDisabled: 1899 case kNumStates:
1980 state_id = ABS_RIGHTDISABLED; 1900 NOTREACHED();
1981 break; 1901 return 0;
1982 default:
1983 NOTREACHED() << "Invalid state: " << state;
1984 break;
1985 } 1902 }
1986 break; 1903 break;
1987 case kScrollbarUpArrow: 1904 case kScrollbarUpArrow:
1988 switch (state) { 1905 switch (state) {
1989 case kNormal: 1906 case kDisabled:
1990 state_id = ABS_UPNORMAL; 1907 return ABS_UPDISABLED;
1991 break; 1908 case kHovered:
1992 case kHovered: 1909 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit.
1993 // Mimic ScrollbarThemeChromiumWin.cpp in WebKit. 1910 return base::win::GetVersion() < base::win::VERSION_VISTA ?
1994 state_id = base::win::GetVersion() < base::win::VERSION_VISTA ?
1995 ABS_UPHOT : ABS_UPHOVER; 1911 ABS_UPHOT : ABS_UPHOVER;
1996 break; 1912 case kNormal:
1997 case kPressed: 1913 return ABS_UPNORMAL;
1998 state_id = ABS_UPPRESSED; 1914 case kPressed:
1999 break; 1915 return ABS_UPPRESSED;
2000 case kDisabled: 1916 case kNumStates:
2001 state_id = ABS_UPDISABLED; 1917 NOTREACHED();
2002 break; 1918 return 0;
2003 default:
2004 NOTREACHED() << "Invalid state: " << state;
2005 break;
2006 } 1919 }
2007 break; 1920 break;
2008 case kScrollbarHorizontalThumb: 1921 case kScrollbarHorizontalThumb:
2009 case kScrollbarVerticalThumb: 1922 case kScrollbarVerticalThumb:
2010 switch (state) { 1923 switch (state) {
2011 case kNormal: 1924 case kDisabled:
2012 state_id = SCRBS_NORMAL; 1925 return SCRBS_DISABLED;
2013 break;
2014 case kHovered: 1926 case kHovered:
2015 // Mimic WebKit's behaviour in ScrollbarThemeChromiumWin.cpp. 1927 // Mimic WebKit's behaviour in ScrollbarThemeChromiumWin.cpp.
2016 state_id = base::win::GetVersion() < base::win::VERSION_VISTA ? 1928 return base::win::GetVersion() < base::win::VERSION_VISTA ?
2017 SCRBS_HOT : SCRBS_HOVER; 1929 SCRBS_HOT : SCRBS_HOVER;
2018 break; 1930 case kNormal:
2019 case kPressed: 1931 return SCRBS_NORMAL;
2020 state_id = SCRBS_PRESSED; 1932 case kPressed:
2021 break; 1933 return SCRBS_PRESSED;
2022 case kDisabled: 1934 case kNumStates:
2023 state_id = SCRBS_DISABLED; 1935 NOTREACHED();
2024 break; 1936 return 0;
2025 default: 1937 }
2026 NOTREACHED() << "Invalid state: " << state; 1938 case kWindowResizeGripper:
2027 break; 1939 switch (state) {
2028 } 1940 case kDisabled:
2029 break; 1941 case kHovered:
2030 default: 1942 case kNormal:
2031 NOTREACHED() << "Invalid part: " << part; 1943 case kPressed:
2032 break; 1944 return 1; // gripper has no windows state
1945 case kNumStates:
1946 NOTREACHED();
1947 return 0;
1948 }
1949 case kComboboxArrow:
1950 case kInnerSpinButton:
1951 case kMenuList:
1952 case kMenuCheckBackground:
1953 case kMenuPopupBackground:
1954 case kMenuItemBackground:
1955 case kProgressBar:
1956 case kScrollbarHorizontalTrack:
1957 case kScrollbarVerticalTrack:
1958 case kScrollbarHorizontalGripper:
1959 case kScrollbarVerticalGripper:
1960 case kScrollbarCorner:
1961 case kSliderTrack:
1962 case kSliderThumb:
1963 case kTabPanelBackground:
1964 case kTextField:
1965 case kTrackbarThumb:
1966 case kTrackbarTrack:
1967 case kMaxPart:
1968 NOTREACHED();
2033 } 1969 }
2034 return state_id; 1970 return 0;
2035 } 1971 }
2036 1972
2037 HRESULT NativeThemeWin::GetThemeInt(ThemeName theme, 1973 HRESULT NativeThemeWin::GetThemeInt(ThemeName theme,
2038 int part_id, 1974 int part_id,
2039 int state_id, 1975 int state_id,
2040 int prop_id, 1976 int prop_id,
2041 int *value) const { 1977 int *value) const {
2042 HANDLE handle = GetThemeHandle(theme); 1978 HANDLE handle = GetThemeHandle(theme);
2043 if (handle && get_theme_int_) 1979 return (handle && get_theme_int_) ?
2044 return get_theme_int_(handle, part_id, state_id, prop_id, value); 1980 get_theme_int_(handle, part_id, state_id, prop_id, value) : E_NOTIMPL;
2045 return E_NOTIMPL;
2046 } 1981 }
2047 1982
2048 HRESULT NativeThemeWin::PaintFrameControl(HDC hdc, 1983 HRESULT NativeThemeWin::PaintFrameControl(HDC hdc,
2049 const gfx::Rect& rect, 1984 const gfx::Rect& rect,
2050 UINT type, 1985 UINT type,
2051 UINT state, 1986 UINT state,
2052 bool is_selected, 1987 bool is_selected,
2053 State control_state) const { 1988 State control_state) const {
2054 const int width = rect.width(); 1989 const int width = rect.width();
2055 const int height = rect.height(); 1990 const int height = rect.height();
2056 1991
2057 // DrawFrameControl for menu arrow/check wants a monochrome bitmap. 1992 // DrawFrameControl for menu arrow/check wants a monochrome bitmap.
2058 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL)); 1993 base::win::ScopedBitmap mask_bitmap(CreateBitmap(width, height, 1, 1, NULL));
2059 1994
2060 if (mask_bitmap == NULL) 1995 if (mask_bitmap == NULL)
2061 return E_OUTOFMEMORY; 1996 return E_OUTOFMEMORY;
2062 1997
2063 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL)); 1998 base::win::ScopedCreateDC bitmap_dc(CreateCompatibleDC(NULL));
2064 base::win::ScopedSelectObject select_bitmap(bitmap_dc, mask_bitmap); 1999 base::win::ScopedSelectObject select_bitmap(bitmap_dc, mask_bitmap);
2065 RECT local_rect = { 0, 0, width, height }; 2000 RECT local_rect = { 0, 0, width, height };
2066 DrawFrameControl(bitmap_dc, &local_rect, type, state); 2001 DrawFrameControl(bitmap_dc, &local_rect, type, state);
2067 2002
2068 // We're going to use BitBlt with a b&w mask. This results in using the dest 2003 // We're going to use BitBlt with a b&w mask. This results in using the dest
2069 // dc's text color for the black bits in the mask, and the dest dc's 2004 // dc's text color for the black bits in the mask, and the dest dc's
2070 // background color for the white bits in the mask. DrawFrameControl draws the 2005 // background color for the white bits in the mask. DrawFrameControl draws the
2071 // check in black, and the background in white. 2006 // check in black, and the background in white.
2072 int bg_color_key; 2007 int bg_color_key;
2073 int text_color_key; 2008 int text_color_key;
2074 switch (control_state) { 2009 switch (control_state) {
2075 case NativeTheme::kHovered: 2010 case kDisabled:
2011 bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU;
2012 text_color_key = COLOR_GRAYTEXT;
2013 break;
2014 case kHovered:
2076 bg_color_key = COLOR_HIGHLIGHT; 2015 bg_color_key = COLOR_HIGHLIGHT;
2077 text_color_key = COLOR_HIGHLIGHTTEXT; 2016 text_color_key = COLOR_HIGHLIGHTTEXT;
2078 break; 2017 break;
2079 case NativeTheme::kNormal: 2018 case kNormal:
2080 bg_color_key = COLOR_MENU; 2019 bg_color_key = COLOR_MENU;
2081 text_color_key = COLOR_MENUTEXT; 2020 text_color_key = COLOR_MENUTEXT;
2082 break; 2021 break;
2083 case NativeTheme::kDisabled: 2022 case kPressed:
2084 bg_color_key = is_selected ? COLOR_HIGHLIGHT : COLOR_MENU; 2023 case kNumStates:
2085 text_color_key = COLOR_GRAYTEXT;
2086 break;
2087 default:
2088 NOTREACHED(); 2024 NOTREACHED();
2089 bg_color_key = COLOR_MENU; 2025 bg_color_key = COLOR_MENU;
2090 text_color_key = COLOR_MENUTEXT; 2026 text_color_key = COLOR_MENUTEXT;
2091 break; 2027 break;
2092 } 2028 }
2093 COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key)); 2029 COLORREF old_bg_color = SetBkColor(hdc, GetSysColor(bg_color_key));
2094 COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key)); 2030 COLORREF old_text_color = SetTextColor(hdc, GetSysColor(text_color_key));
2095 BitBlt(hdc, rect.x(), rect.y(), width, height, bitmap_dc, 0, 0, SRCCOPY); 2031 BitBlt(hdc, rect.x(), rect.y(), width, height, bitmap_dc, 0, 0, SRCCOPY);
2096 SetBkColor(hdc, old_bg_color); 2032 SetBkColor(hdc, old_bg_color);
2097 SetTextColor(hdc, old_text_color); 2033 SetTextColor(hdc, old_text_color);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2138 break; 2074 break;
2139 case WINDOW: 2075 case WINDOW:
2140 handle = open_theme_(NULL, L"Window"); 2076 handle = open_theme_(NULL, L"Window");
2141 break; 2077 break;
2142 case PROGRESS: 2078 case PROGRESS:
2143 handle = open_theme_(NULL, L"Progress"); 2079 handle = open_theme_(NULL, L"Progress");
2144 break; 2080 break;
2145 case SPIN: 2081 case SPIN:
2146 handle = open_theme_(NULL, L"Spin"); 2082 handle = open_theme_(NULL, L"Spin");
2147 break; 2083 break;
2148 default: 2084 case LAST:
2149 NOTREACHED(); 2085 NOTREACHED();
2086 break;
2150 } 2087 }
2151 theme_handles_[theme_name] = handle; 2088 theme_handles_[theme_name] = handle;
2152 return handle; 2089 return handle;
2153 } 2090 }
2154 2091
2155 } // namespace ui 2092 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_aura.cc ('k') | ui/views/controls/button/button.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698