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 needs_paint_indirect = false; |
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 needs_paint_indirect = 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)) |
| 307 needs_paint_indirect = true; |
| 308 break; |
| 309 default: |
| 310 break; |
| 311 } |
294 } | 312 } |
295 | 313 |
| 314 if (needs_paint_indirect) |
| 315 PaintIndirect(canvas, part, state, rect, extra); |
| 316 else |
| 317 PaintDirect(canvas, part, state, rect, extra); |
| 318 } |
| 319 |
| 320 void NativeThemeWin::PaintDirect(SkCanvas* canvas, |
| 321 Part part, |
| 322 State state, |
| 323 const gfx::Rect& rect, |
| 324 const ExtraParams& extra) const { |
296 skia::ScopedPlatformPaint scoped_platform_paint(canvas); | 325 skia::ScopedPlatformPaint scoped_platform_paint(canvas); |
297 HDC hdc = scoped_platform_paint.GetPlatformSurface(); | 326 HDC hdc = scoped_platform_paint.GetPlatformSurface(); |
298 | 327 |
299 switch (part) { | 328 switch (part) { |
300 case kCheckbox: | 329 case kCheckbox: |
301 PaintCheckbox(hdc, part, state, rect, extra.button); | 330 PaintCheckbox(hdc, part, state, rect, extra.button); |
302 break; | 331 break; |
303 case kRadio: | 332 case kRadio: |
304 PaintRadioButton(hdc, part, state, rect, extra.button); | 333 PaintRadioButton(hdc, part, state, rect, extra.button); |
305 break; | 334 break; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 case kColorId_TextfieldSelectionBackgroundUnfocused: | 462 case kColorId_TextfieldSelectionBackgroundUnfocused: |
434 return kTextfieldSelectionBackgroundUnfocused; | 463 return kTextfieldSelectionBackgroundUnfocused; |
435 | 464 |
436 default: | 465 default: |
437 NOTREACHED() << "Invalid color_id: " << color_id; | 466 NOTREACHED() << "Invalid color_id: " << color_id; |
438 break; | 467 break; |
439 } | 468 } |
440 return kInvalidColorIdColor; | 469 return kInvalidColorIdColor; |
441 } | 470 } |
442 | 471 |
443 void NativeThemeWin::PaintToNonPlatformCanvas(SkCanvas* canvas, | 472 void NativeThemeWin::PaintIndirect(SkCanvas* canvas, |
444 Part part, | 473 Part part, |
445 State state, | 474 State state, |
446 const gfx::Rect& rect, | 475 const gfx::Rect& rect, |
447 const ExtraParams& extra) const { | 476 const ExtraParams& extra) const { |
448 // TODO(asvitkine): This path is pretty inefficient - for each paint operation | 477 // TODO(asvitkine): This path is pretty inefficient - for each paint operation |
449 // it creates a new offscreen bitmap Skia canvas. This can | 478 // it creates a new offscreen bitmap Skia canvas. This can |
450 // be sped up by doing it only once per part/state and | 479 // be sped up by doing it only once per part/state and |
451 // keeping a cache of the resulting bitmaps. | 480 // keeping a cache of the resulting bitmaps. |
452 | 481 |
453 // Create an offscreen canvas that is backed by an HDC. | 482 // Create an offscreen canvas that is backed by an HDC. |
454 scoped_ptr<SkCanvas> offscreen_canvas( | 483 scoped_ptr<SkCanvas> offscreen_canvas( |
455 skia::CreateBitmapCanvas(rect.width(), rect.height(), false)); | 484 skia::CreateBitmapCanvas(rect.width(), rect.height(), false)); |
456 DCHECK(offscreen_canvas.get()); | 485 DCHECK(offscreen_canvas.get()); |
457 DCHECK(skia::SupportsPlatformPaint(offscreen_canvas.get())); | 486 DCHECK(skia::SupportsPlatformPaint(offscreen_canvas.get())); |
(...skipping 17 matching lines...) Expand all Loading... |
475 adjusted_extra.progress_bar.value_rect_y = 0; | 504 adjusted_extra.progress_bar.value_rect_y = 0; |
476 break; | 505 break; |
477 case kScrollbarHorizontalTrack: | 506 case kScrollbarHorizontalTrack: |
478 case kScrollbarVerticalTrack: | 507 case kScrollbarVerticalTrack: |
479 adjusted_extra.scrollbar_track.track_x = 0; | 508 adjusted_extra.scrollbar_track.track_x = 0; |
480 adjusted_extra.scrollbar_track.track_y = 0; | 509 adjusted_extra.scrollbar_track.track_y = 0; |
481 break; | 510 break; |
482 default: break; | 511 default: break; |
483 } | 512 } |
484 // Draw the theme controls using existing HDC-drawing code. | 513 // Draw the theme controls using existing HDC-drawing code. |
485 Paint(offscreen_canvas.get(), part, state, adjusted_rect, adjusted_extra); | 514 PaintDirect(offscreen_canvas.get(), |
| 515 part, |
| 516 state, |
| 517 adjusted_rect, |
| 518 adjusted_extra); |
486 | 519 |
487 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is | 520 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is |
488 // necessary to have when drawing to a SkPicture. | 521 // necessary to have when drawing to a SkPicture. |
489 const SkBitmap& hdc_bitmap = | 522 const SkBitmap& hdc_bitmap = |
490 offscreen_canvas->getDevice()->accessBitmap(false); | 523 offscreen_canvas->getDevice()->accessBitmap(false); |
491 SkBitmap bitmap; | 524 SkBitmap bitmap; |
492 hdc_bitmap.copyTo(&bitmap, SkBitmap::kARGB_8888_Config); | 525 hdc_bitmap.copyTo(&bitmap, SkBitmap::kARGB_8888_Config); |
493 | 526 |
494 // Post-process the pixels to fix up the alpha values (see big comment above). | 527 // Post-process the pixels to fix up the alpha values (see big comment above). |
495 const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder); | 528 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"); | 1809 handle = open_theme_(NULL, L"Spin"); |
1777 break; | 1810 break; |
1778 default: | 1811 default: |
1779 NOTREACHED(); | 1812 NOTREACHED(); |
1780 } | 1813 } |
1781 theme_handles_[theme_name] = handle; | 1814 theme_handles_[theme_name] = handle; |
1782 return handle; | 1815 return handle; |
1783 } | 1816 } |
1784 | 1817 |
1785 } // namespace ui | 1818 } // namespace ui |
OLD | NEW |