OLD | NEW |
---|---|
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/base/native_theme/native_theme_win.h" | 5 #include "ui/base/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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
280 } | 280 } |
281 | 281 |
282 return gfx::Size(size.cx, size.cy); | 282 return gfx::Size(size.cx, size.cy); |
283 } | 283 } |
284 | 284 |
285 void NativeThemeWin::Paint(SkCanvas* canvas, | 285 void NativeThemeWin::Paint(SkCanvas* canvas, |
286 Part part, | 286 Part part, |
287 State state, | 287 State state, |
288 const gfx::Rect& rect, | 288 const gfx::Rect& rect, |
289 const ExtraParams& extra) const { | 289 const ExtraParams& extra) const { |
290 bool needsPaintIndirect = false; | |
brettw
2012/07/23 21:27:07
Style: "needs_paint_indirect"
ccameron
2012/07/23 23:20:36
Done.
| |
290 if (!skia::SupportsPlatformPaint(canvas)) { | 291 if (!skia::SupportsPlatformPaint(canvas)) { |
291 // This block will only get hit with --enable-accelerated-drawing flag. | 292 // This block will only get hit with --enable-accelerated-drawing flag. |
292 PaintToNonPlatformCanvas(canvas, part, state, rect, extra); | 293 needsPaintIndirect = true; |
293 return; | 294 } else { |
295 // Scrollbars on Windows XP and the Windows Classic theme have particularly | |
296 // problematic alpha values, so always draw them indirectly. | |
297 switch (part) { | |
298 case kScrollbarDownArrow: | |
299 case kScrollbarUpArrow: | |
300 case kScrollbarLeftArrow: | |
301 case kScrollbarRightArrow: | |
302 case kScrollbarHorizontalThumb: | |
303 case kScrollbarVerticalThumb: | |
304 case kScrollbarHorizontalGripper: | |
305 case kScrollbarVerticalGripper: | |
306 if (!GetThemeHandle(SCROLLBAR)) { | |
brettw
2012/07/23 21:27:07
No {} for single-line conditionals (to match surro
ccameron
2012/07/23 23:20:36
Done (and made this change to the "if (needs_paint
| |
307 needsPaintIndirect = true; | |
308 } | |
309 break; | |
310 default: | |
311 break; | |
312 } | |
294 } | 313 } |
295 | 314 |
315 if (needsPaintIndirect) { | |
316 PaintIndirect(canvas, part, state, rect, extra); | |
317 } else { | |
318 PaintDirect(canvas, part, state, rect, extra); | |
319 } | |
320 } | |
321 | |
322 void NativeThemeWin::PaintDirect(SkCanvas* canvas, | |
323 Part part, | |
324 State state, | |
325 const gfx::Rect& rect, | |
326 const ExtraParams& extra) const { | |
296 skia::ScopedPlatformPaint scoped_platform_paint(canvas); | 327 skia::ScopedPlatformPaint scoped_platform_paint(canvas); |
297 HDC hdc = scoped_platform_paint.GetPlatformSurface(); | 328 HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
298 | 329 |
299 switch (part) { | 330 switch (part) { |
300 case kCheckbox: | 331 case kCheckbox: |
301 PaintCheckbox(hdc, part, state, rect, extra.button); | 332 PaintCheckbox(hdc, part, state, rect, extra.button); |
302 break; | 333 break; |
303 case kRadio: | 334 case kRadio: |
304 PaintRadioButton(hdc, part, state, rect, extra.button); | 335 PaintRadioButton(hdc, part, state, rect, extra.button); |
305 break; | 336 break; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
433 case kColorId_TextfieldSelectionBackgroundUnfocused: | 464 case kColorId_TextfieldSelectionBackgroundUnfocused: |
434 return kTextfieldSelectionBackgroundUnfocused; | 465 return kTextfieldSelectionBackgroundUnfocused; |
435 | 466 |
436 default: | 467 default: |
437 NOTREACHED() << "Invalid color_id: " << color_id; | 468 NOTREACHED() << "Invalid color_id: " << color_id; |
438 break; | 469 break; |
439 } | 470 } |
440 return kInvalidColorIdColor; | 471 return kInvalidColorIdColor; |
441 } | 472 } |
442 | 473 |
443 void NativeThemeWin::PaintToNonPlatformCanvas(SkCanvas* canvas, | 474 void NativeThemeWin::PaintIndirect(SkCanvas* canvas, |
444 Part part, | 475 Part part, |
445 State state, | 476 State state, |
446 const gfx::Rect& rect, | 477 const gfx::Rect& rect, |
447 const ExtraParams& extra) const { | 478 const ExtraParams& extra) const { |
448 // TODO(asvitkine): This path is pretty inefficient - for each paint operation | 479 // TODO(asvitkine): This path is pretty inefficient - for each paint operation |
449 // it creates a new offscreen bitmap Skia canvas. This can | 480 // it creates a new offscreen bitmap Skia canvas. This can |
450 // be sped up by doing it only once per part/state and | 481 // be sped up by doing it only once per part/state and |
451 // keeping a cache of the resulting bitmaps. | 482 // keeping a cache of the resulting bitmaps. |
452 | 483 |
453 // Create an offscreen canvas that is backed by an HDC. | 484 // Create an offscreen canvas that is backed by an HDC. |
454 scoped_ptr<SkCanvas> offscreen_canvas( | 485 scoped_ptr<SkCanvas> offscreen_canvas( |
455 skia::CreateBitmapCanvas(rect.width(), rect.height(), false)); | 486 skia::CreateBitmapCanvas(rect.width(), rect.height(), false)); |
456 DCHECK(offscreen_canvas.get()); | 487 DCHECK(offscreen_canvas.get()); |
457 DCHECK(skia::SupportsPlatformPaint(offscreen_canvas.get())); | 488 DCHECK(skia::SupportsPlatformPaint(offscreen_canvas.get())); |
(...skipping 17 matching lines...) Expand all Loading... | |
475 adjusted_extra.progress_bar.value_rect_y = 0; | 506 adjusted_extra.progress_bar.value_rect_y = 0; |
476 break; | 507 break; |
477 case kScrollbarHorizontalTrack: | 508 case kScrollbarHorizontalTrack: |
478 case kScrollbarVerticalTrack: | 509 case kScrollbarVerticalTrack: |
479 adjusted_extra.scrollbar_track.track_x = 0; | 510 adjusted_extra.scrollbar_track.track_x = 0; |
480 adjusted_extra.scrollbar_track.track_y = 0; | 511 adjusted_extra.scrollbar_track.track_y = 0; |
481 break; | 512 break; |
482 default: break; | 513 default: break; |
483 } | 514 } |
484 // Draw the theme controls using existing HDC-drawing code. | 515 // Draw the theme controls using existing HDC-drawing code. |
485 Paint(offscreen_canvas.get(), part, state, adjusted_rect, adjusted_extra); | 516 PaintDirect(offscreen_canvas.get(), |
517 part, | |
518 state, | |
519 adjusted_rect, | |
520 adjusted_extra); | |
486 | 521 |
487 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is | 522 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is |
488 // necessary to have when drawing to a SkPicture. | 523 // necessary to have when drawing to a SkPicture. |
489 const SkBitmap& hdc_bitmap = | 524 const SkBitmap& hdc_bitmap = |
490 offscreen_canvas->getDevice()->accessBitmap(false); | 525 offscreen_canvas->getDevice()->accessBitmap(false); |
491 SkBitmap bitmap; | 526 SkBitmap bitmap; |
492 hdc_bitmap.copyTo(&bitmap, SkBitmap::kARGB_8888_Config); | 527 hdc_bitmap.copyTo(&bitmap, SkBitmap::kARGB_8888_Config); |
493 | 528 |
494 // Post-process the pixels to fix up the alpha values (see big comment above). | 529 // Post-process the pixels to fix up the alpha values (see big comment above). |
495 const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder); | 530 const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder); |
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1776 handle = open_theme_(NULL, L"Spin"); | 1811 handle = open_theme_(NULL, L"Spin"); |
1777 break; | 1812 break; |
1778 default: | 1813 default: |
1779 NOTREACHED(); | 1814 NOTREACHED(); |
1780 } | 1815 } |
1781 theme_handles_[theme_name] = handle; | 1816 theme_handles_[theme_name] = handle; |
1782 return handle; | 1817 return handle; |
1783 } | 1818 } |
1784 | 1819 |
1785 } // namespace ui | 1820 } // namespace ui |
OLD | NEW |