Chromium Code Reviews| 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/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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <uxtheme.h> | 9 #include <uxtheme.h> |
| 10 #include <vsstyle.h> | 10 #include <vsstyle.h> |
| 11 #include <vssym32.h> | 11 #include <vssym32.h> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "base/win/scoped_gdi_object.h" | 16 #include "base/win/scoped_gdi_object.h" |
| 17 #include "base/win/scoped_hdc.h" | 17 #include "base/win/scoped_hdc.h" |
| 18 #include "base/win/scoped_select_object.h" | 18 #include "base/win/scoped_select_object.h" |
| 19 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 20 #include "skia/ext/bitmap_platform_device.h" | |
| 21 #include "skia/ext/platform_canvas.h" | 20 #include "skia/ext/platform_canvas.h" |
| 22 #include "skia/ext/skia_utils_win.h" | 21 #include "skia/ext/skia_utils_win.h" |
| 23 #include "third_party/skia/include/core/SkCanvas.h" | 22 #include "third_party/skia/include/core/SkCanvas.h" |
| 24 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
| 25 #include "third_party/skia/include/core/SkColorPriv.h" | 24 #include "third_party/skia/include/core/SkColorPriv.h" |
| 26 #include "third_party/skia/include/core/SkShader.h" | 25 #include "third_party/skia/include/core/SkShader.h" |
| 26 #include "third_party/skia/include/core/SkSurface.h" | |
| 27 #include "ui/base/material_design/material_design_controller.h" | 27 #include "ui/base/material_design/material_design_controller.h" |
| 28 #include "ui/gfx/color_palette.h" | 28 #include "ui/gfx/color_palette.h" |
| 29 #include "ui/gfx/color_utils.h" | 29 #include "ui/gfx/color_utils.h" |
| 30 #include "ui/gfx/gdi_util.h" | 30 #include "ui/gfx/gdi_util.h" |
| 31 #include "ui/gfx/geometry/rect.h" | 31 #include "ui/gfx/geometry/rect.h" |
| 32 #include "ui/gfx/geometry/rect_conversions.h" | 32 #include "ui/gfx/geometry/rect_conversions.h" |
| 33 #include "ui/gfx/win/dpi.h" | 33 #include "ui/gfx/win/dpi.h" |
| 34 #include "ui/native_theme/common_theme.h" | 34 #include "ui/native_theme/common_theme.h" |
| 35 | 35 |
| 36 // This was removed from Winvers.h but is still used. | 36 // This was removed from Winvers.h but is still used. |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 case kScrollbarHorizontalGripper: | 285 case kScrollbarHorizontalGripper: |
| 286 case kScrollbarVerticalGripper: | 286 case kScrollbarVerticalGripper: |
| 287 needs_paint_indirect = !GetThemeHandle(SCROLLBAR) || | 287 needs_paint_indirect = !GetThemeHandle(SCROLLBAR) || |
| 288 base::win::GetVersion() == base::win::VERSION_XP; | 288 base::win::GetVersion() == base::win::VERSION_XP; |
| 289 break; | 289 break; |
| 290 default: | 290 default: |
| 291 break; | 291 break; |
| 292 } | 292 } |
| 293 } | 293 } |
| 294 | 294 |
| 295 skia::ScopedPlatformPaint paint(canvas); | |
| 296 HDC surface = paint.GetPlatformSurface(); | |
| 295 if (needs_paint_indirect) | 297 if (needs_paint_indirect) |
| 296 PaintIndirect(canvas, part, state, rect, extra); | 298 PaintIndirect(surface, part, state, rect, extra); |
| 297 else | 299 else |
| 298 PaintDirect(canvas, part, state, rect, extra); | 300 PaintDirect(surface, part, state, rect, extra); |
| 299 } | 301 } |
| 300 | 302 |
| 301 NativeThemeWin::NativeThemeWin() | 303 NativeThemeWin::NativeThemeWin() |
| 302 : draw_theme_(NULL), | 304 : draw_theme_(NULL), |
| 303 draw_theme_ex_(NULL), | 305 draw_theme_ex_(NULL), |
| 304 get_theme_color_(NULL), | 306 get_theme_color_(NULL), |
| 305 get_theme_content_rect_(NULL), | 307 get_theme_content_rect_(NULL), |
| 306 get_theme_part_size_(NULL), | 308 get_theme_part_size_(NULL), |
| 307 open_theme_(NULL), | 309 open_theme_(NULL), |
| 308 close_theme_(NULL), | 310 close_theme_(NULL), |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 354 UpdateSystemColors(); | 356 UpdateSystemColors(); |
| 355 is_using_high_contrast_valid_ = false; | 357 is_using_high_contrast_valid_ = false; |
| 356 NotifyObservers(); | 358 NotifyObservers(); |
| 357 } | 359 } |
| 358 | 360 |
| 359 void NativeThemeWin::UpdateSystemColors() { | 361 void NativeThemeWin::UpdateSystemColors() { |
| 360 for (int kSystemColor : kSystemColors) | 362 for (int kSystemColor : kSystemColors) |
| 361 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); | 363 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); |
| 362 } | 364 } |
| 363 | 365 |
| 364 void NativeThemeWin::PaintDirect(SkCanvas* canvas, | 366 void NativeThemeWin::PaintDirect(HDC hdc, |
| 365 Part part, | 367 Part part, |
| 366 State state, | 368 State state, |
| 367 const gfx::Rect& rect, | 369 const gfx::Rect& rect, |
| 368 const ExtraParams& extra) const { | 370 const ExtraParams& extra) const { |
| 369 skia::ScopedPlatformPaint scoped_platform_paint(canvas); | 371 SkSurface* surface = nullptr; |
|
Evan Stade
2016/02/10 21:41:04
why is this declared out here
tomhudson
2016/02/16 17:47:54
Acknowledged.
| |
| 370 HDC hdc = scoped_platform_paint.GetPlatformSurface(); | 372 SkCanvas* canvas = nullptr; |
| 371 | |
| 372 switch (part) { | 373 switch (part) { |
| 373 case kCheckbox: | 374 case kCheckbox: |
| 374 PaintCheckbox(hdc, part, state, rect, extra.button); | 375 PaintCheckbox(hdc, part, state, rect, extra.button); |
| 375 return; | 376 return; |
| 376 case kInnerSpinButton: | 377 case kInnerSpinButton: |
| 377 PaintSpinButton(hdc, part, state, rect, extra.inner_spin); | 378 PaintSpinButton(hdc, part, state, rect, extra.inner_spin); |
| 378 return; | 379 return; |
| 379 case kMenuList: | 380 case kMenuList: |
| 380 PaintMenuList(hdc, state, rect, extra.menu_list); | 381 PaintMenuList(hdc, state, rect, extra.menu_list); |
| 381 return; | 382 return; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 416 PaintScrollbarArrow(hdc, part, state, rect, extra.scrollbar_arrow); | 417 PaintScrollbarArrow(hdc, part, state, rect, extra.scrollbar_arrow); |
| 417 return; | 418 return; |
| 418 case kScrollbarHorizontalThumb: | 419 case kScrollbarHorizontalThumb: |
| 419 case kScrollbarVerticalThumb: | 420 case kScrollbarVerticalThumb: |
| 420 case kScrollbarHorizontalGripper: | 421 case kScrollbarHorizontalGripper: |
| 421 case kScrollbarVerticalGripper: | 422 case kScrollbarVerticalGripper: |
| 422 PaintScrollbarThumb(hdc, part, state, rect, extra.scrollbar_thumb); | 423 PaintScrollbarThumb(hdc, part, state, rect, extra.scrollbar_thumb); |
| 423 return; | 424 return; |
| 424 case kScrollbarHorizontalTrack: | 425 case kScrollbarHorizontalTrack: |
| 425 case kScrollbarVerticalTrack: | 426 case kScrollbarVerticalTrack: |
| 426 PaintScrollbarTrack(canvas, hdc, part, state, rect, | 427 PaintScrollbarTrack(hdc, part, state, rect, extra.scrollbar_track); |
| 427 extra.scrollbar_track); | |
| 428 return; | 428 return; |
| 429 case kScrollbarCorner: | 429 case kScrollbarCorner: { |
| 430 canvas->drawColor(SK_ColorWHITE, SkXfermode::kSrc_Mode); | 430 surface = skia::MapPlatformSurface(hdc); |
| 431 canvas = surface ? surface->getCanvas() : nullptr; | |
| 432 if (canvas) | |
| 433 canvas->drawColor(SK_ColorWHITE, SkXfermode::kSrc_Mode); | |
|
Evan Stade
2016/02/10 21:41:04
use a utility fn?
Peter Kasting
2016/02/11 00:19:26
Not necessary; just this would solve your other co
tomhudson
2016/02/16 17:47:54
Done.
| |
| 434 } | |
|
Evan Stade
2016/02/10 21:41:04
this can't be the right formatting
tomhudson
2016/02/16 17:47:54
Ooh, that's completely broken. Good catch.
Reinfor
| |
| 431 return; | 435 return; |
| 432 case kTabPanelBackground: | 436 case kTabPanelBackground: |
| 433 PaintTabPanelBackground(hdc, rect); | 437 PaintTabPanelBackground(hdc, rect); |
| 434 return; | 438 return; |
| 435 case kTextField: | 439 case kTextField: |
| 436 PaintTextField(hdc, part, state, rect, extra.text_field); | 440 PaintTextField(hdc, part, state, rect, extra.text_field); |
| 437 return; | 441 return; |
| 438 case kTrackbarThumb: | 442 case kTrackbarThumb: |
| 439 case kTrackbarTrack: | 443 case kTrackbarTrack: |
| 440 PaintTrackbar(canvas, hdc, part, state, rect, extra.trackbar); | 444 PaintTrackbar(hdc, part, state, rect, extra.trackbar); |
| 441 return; | 445 return; |
| 442 case kWindowResizeGripper: | 446 case kWindowResizeGripper: |
| 443 PaintWindowResizeGripper(hdc, rect); | 447 PaintWindowResizeGripper(hdc, rect); |
| 444 return; | 448 return; |
| 445 case kComboboxArrow: | 449 case kComboboxArrow: |
| 446 case kSliderTrack: | 450 case kSliderTrack: |
| 447 case kSliderThumb: | 451 case kSliderThumb: |
| 448 case kMaxPart: | 452 case kMaxPart: |
| 449 NOTREACHED(); | 453 NOTREACHED(); |
| 450 } | 454 } |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 case NativeTheme::kColorId_CallToActionColor: | 648 case NativeTheme::kColorId_CallToActionColor: |
| 645 return kCallToActionColorInvert; | 649 return kCallToActionColorInvert; |
| 646 default: | 650 default: |
| 647 return color_utils::InvertColor(GetAuraColor(color_id, this)); | 651 return color_utils::InvertColor(GetAuraColor(color_id, this)); |
| 648 } | 652 } |
| 649 } | 653 } |
| 650 | 654 |
| 651 return GetAuraColor(color_id, this); | 655 return GetAuraColor(color_id, this); |
| 652 } | 656 } |
| 653 | 657 |
| 654 void NativeThemeWin::PaintIndirect(SkCanvas* canvas, | 658 void NativeThemeWin::PaintIndirect(HDC hdc, |
| 655 Part part, | 659 Part part, |
| 656 State state, | 660 State state, |
| 657 const gfx::Rect& rect, | 661 const gfx::Rect& rect, |
| 658 const ExtraParams& extra) const { | 662 const ExtraParams& extra) const { |
| 659 // TODO(asvitkine): This path is pretty inefficient - for each paint operation | 663 // TODO(asvitkine): This path is pretty inefficient - for each paint operation |
| 660 // it creates a new offscreen bitmap Skia canvas. This can | 664 // it creates a new offscreen bitmap Skia canvas. This can |
| 661 // be sped up by doing it only once per part/state and | 665 // be sped up by doing it only once per part/state and |
| 662 // keeping a cache of the resulting bitmaps. | 666 // keeping a cache of the resulting bitmaps. |
| 663 | 667 |
| 664 // Create an offscreen canvas that is backed by an HDC. | 668 // Create an offscreen canvas that is backed by an HDC. |
| 665 skia::RefPtr<skia::BitmapPlatformDevice> device = skia::AdoptRef( | 669 |
| 666 skia::BitmapPlatformDevice::Create( | 670 HDC offscreen_hdc = skia::CreateOffscreenSurface(rect.width(), rect.height()); |
| 667 rect.width(), rect.height(), false, NULL)); | 671 SkSurface* offscreen_surface = skia::MapPlatformSurface(offscreen_hdc); |
| 668 DCHECK(device); | 672 DCHECK(offscreen_surface); |
| 669 SkCanvas offscreen_canvas(device.get()); | 673 SkCanvas* offscreen_canvas = offscreen_surface->getCanvas(); |
| 670 DCHECK(skia::SupportsPlatformPaint(&offscreen_canvas)); | 674 DCHECK(offscreen_canvas); |
| 671 | 675 |
| 672 // Some of the Windows theme drawing operations do not write correct alpha | 676 // 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 | 677 // 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. | 678 // especially a problem on Windows XP or when using the Classic theme. |
| 675 // | 679 // |
| 676 // To work-around this, mark all pixels with a placeholder value, to detect | 680 // 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 | 681 // 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. | 682 // pixels that have alpha 0 to opaque and placeholders to fully-transparent. |
| 679 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0); | 683 const SkColor placeholder = SkColorSetARGB(1, 0, 0, 0); |
| 680 offscreen_canvas.clear(placeholder); | 684 offscreen_canvas->clear(placeholder); |
| 681 | 685 |
| 682 // Offset destination rects to have origin (0,0). | 686 // Offset destination rects to have origin (0,0). |
| 683 gfx::Rect adjusted_rect(rect.size()); | 687 gfx::Rect adjusted_rect(rect.size()); |
| 684 ExtraParams adjusted_extra(extra); | 688 ExtraParams adjusted_extra(extra); |
| 685 switch (part) { | 689 switch (part) { |
| 686 case kProgressBar: | 690 case kProgressBar: |
| 687 adjusted_extra.progress_bar.value_rect_x = 0; | 691 adjusted_extra.progress_bar.value_rect_x = 0; |
| 688 adjusted_extra.progress_bar.value_rect_y = 0; | 692 adjusted_extra.progress_bar.value_rect_y = 0; |
| 689 break; | 693 break; |
| 690 case kScrollbarHorizontalTrack: | 694 case kScrollbarHorizontalTrack: |
| 691 case kScrollbarVerticalTrack: | 695 case kScrollbarVerticalTrack: |
| 692 adjusted_extra.scrollbar_track.track_x = 0; | 696 adjusted_extra.scrollbar_track.track_x = 0; |
| 693 adjusted_extra.scrollbar_track.track_y = 0; | 697 adjusted_extra.scrollbar_track.track_y = 0; |
| 694 break; | 698 break; |
| 695 default: | 699 default: |
| 696 break; | 700 break; |
| 697 } | 701 } |
| 702 | |
| 698 // Draw the theme controls using existing HDC-drawing code. | 703 // Draw the theme controls using existing HDC-drawing code. |
| 699 PaintDirect(&offscreen_canvas, part, state, adjusted_rect, adjusted_extra); | 704 PaintDirect(offscreen_hdc, part, state, adjusted_rect, adjusted_extra); |
| 700 | |
| 701 // Copy the pixels to a bitmap that has ref-counted pixel storage, which is | |
| 702 // necessary to have when drawing to a SkPicture. | |
| 703 const SkBitmap& hdc_bitmap = | |
| 704 offscreen_canvas.getDevice()->accessBitmap(false); | |
| 705 SkBitmap bitmap; | |
| 706 hdc_bitmap.copyTo(&bitmap, kN32_SkColorType); | |
| 707 | 705 |
| 708 // Post-process the pixels to fix up the alpha values (see big comment above). | 706 // Post-process the pixels to fix up the alpha values (see big comment above). |
| 707 SkBitmap offscreen_bitmap = skia::MapPlatformBitmap(offscreen_hdc); | |
| 709 const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder); | 708 const SkPMColor placeholder_value = SkPreMultiplyColor(placeholder); |
| 710 const int pixel_count = rect.width() * rect.height(); | 709 const int pixel_count = rect.width() * rect.height(); |
| 711 SkPMColor* pixels = bitmap.getAddr32(0, 0); | 710 SkPMColor* pixels = offscreen_bitmap.getAddr32(0, 0); |
| 712 for (int i = 0; i < pixel_count; i++) { | 711 for (int i = 0; i < pixel_count; i++) { |
| 713 if (pixels[i] == placeholder_value) { | 712 if (pixels[i] == placeholder_value) { |
| 714 // Pixel wasn't touched - make it fully transparent. | 713 // Pixel wasn't touched - make it fully transparent. |
| 715 pixels[i] = SkPackARGB32(0, 0, 0, 0); | 714 pixels[i] = SkPackARGB32(0, 0, 0, 0); |
| 716 } else if (SkGetPackedA32(pixels[i]) == 0) { | 715 } else if (SkGetPackedA32(pixels[i]) == 0) { |
| 717 // Pixel was touched but has incorrect alpha of 0, make it fully opaque. | 716 // Pixel was touched but has incorrect alpha of 0, make it fully opaque. |
| 718 pixels[i] = SkPackARGB32(0xFF, | 717 pixels[i] = SkPackARGB32(0xFF, |
| 719 SkGetPackedR32(pixels[i]), | 718 SkGetPackedR32(pixels[i]), |
| 720 SkGetPackedG32(pixels[i]), | 719 SkGetPackedG32(pixels[i]), |
| 721 SkGetPackedB32(pixels[i])); | 720 SkGetPackedB32(pixels[i])); |
| 722 } | 721 } |
| 723 } | 722 } |
| 724 | 723 |
| 725 // Draw the offscreen bitmap to the destination canvas. | 724 SkSurface* destination_surface = skia::MapPlatformSurface(hdc); |
| 726 canvas->drawBitmap(bitmap, rect.x(), rect.y()); | 725 DCHECK(destination_surface); |
| 726 SkCanvas* destination_canvas = destination_surface->getCanvas(); | |
| 727 DCHECK(destination_canvas); | |
| 728 destination_canvas->drawBitmap(offscreen_bitmap, rect.x(), rect.y()); | |
| 729 | |
| 730 DeleteDC(offscreen_hdc); | |
| 727 } | 731 } |
| 728 | 732 |
| 729 HRESULT NativeThemeWin::GetThemePartSize(ThemeName theme_name, | 733 HRESULT NativeThemeWin::GetThemePartSize(ThemeName theme_name, |
| 730 HDC hdc, | 734 HDC hdc, |
| 731 int part_id, | 735 int part_id, |
| 732 int state_id, | 736 int state_id, |
| 733 RECT* rect, | 737 RECT* rect, |
| 734 int ts, | 738 int ts, |
| 735 SIZE* size) const { | 739 SIZE* size) const { |
| 736 HANDLE handle = GetThemeHandle(theme_name); | 740 HANDLE handle = GetThemeHandle(theme_name); |
| (...skipping 496 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1233 return PaintScaledTheme(handle, hdc, part_id, state_id, rect); | 1237 return PaintScaledTheme(handle, hdc, part_id, state_id, rect); |
| 1234 | 1238 |
| 1235 // Draw it manually. | 1239 // Draw it manually. |
| 1236 if ((part_id == SBP_THUMBBTNHORZ) || (part_id == SBP_THUMBBTNVERT)) | 1240 if ((part_id == SBP_THUMBBTNHORZ) || (part_id == SBP_THUMBBTNVERT)) |
| 1237 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT | BF_MIDDLE); | 1241 DrawEdge(hdc, &rect_win, EDGE_RAISED, BF_RECT | BF_MIDDLE); |
| 1238 // Classic mode doesn't have a gripper. | 1242 // Classic mode doesn't have a gripper. |
| 1239 return S_OK; | 1243 return S_OK; |
| 1240 } | 1244 } |
| 1241 | 1245 |
| 1242 HRESULT NativeThemeWin::PaintScrollbarTrack( | 1246 HRESULT NativeThemeWin::PaintScrollbarTrack( |
| 1243 SkCanvas* canvas, | |
| 1244 HDC hdc, | 1247 HDC hdc, |
| 1245 Part part, | 1248 Part part, |
| 1246 State state, | 1249 State state, |
| 1247 const gfx::Rect& rect, | 1250 const gfx::Rect& rect, |
| 1248 const ScrollbarTrackExtraParams& extra) const { | 1251 const ScrollbarTrackExtraParams& extra) const { |
| 1249 HANDLE handle = GetThemeHandle(SCROLLBAR); | 1252 HANDLE handle = GetThemeHandle(SCROLLBAR); |
| 1250 RECT rect_win = rect.ToRECT(); | 1253 RECT rect_win = rect.ToRECT(); |
| 1251 | 1254 |
| 1252 const int part_id = extra.is_upper ? | 1255 const int part_id = extra.is_upper ? |
| 1253 ((part == kScrollbarHorizontalTrack) ? | 1256 ((part == kScrollbarHorizontalTrack) ? |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 1274 } | 1277 } |
| 1275 | 1278 |
| 1276 if (handle && draw_theme_) | 1279 if (handle && draw_theme_) |
| 1277 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); | 1280 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); |
| 1278 | 1281 |
| 1279 // Draw it manually. | 1282 // Draw it manually. |
| 1280 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && | 1283 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && |
| 1281 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { | 1284 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { |
| 1282 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); | 1285 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); |
| 1283 } else { | 1286 } else { |
| 1287 SkSurface* surface = skia::MapPlatformSurface(hdc); | |
| 1288 SkCanvas* canvas = surface ? surface->getCanvas() : nullptr; | |
| 1289 if (!surface || !canvas) | |
|
Peter Kasting
2016/02/11 00:19:26
Nit: "if (!canvas)" suffices
tomhudson
2016/02/16 17:47:54
Done.
| |
| 1290 return E_FAIL; | |
| 1284 SkPaint paint; | 1291 SkPaint paint; |
| 1285 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, | 1292 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, |
| 1286 extra.track_height).ToRECT(); | 1293 extra.track_height).ToRECT(); |
| 1287 SetCheckerboardShader(&paint, align_rect); | 1294 SetCheckerboardShader(&paint, align_rect); |
| 1288 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); | 1295 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); |
| 1289 } | 1296 } |
| 1290 if (extra.classic_state & DFCS_PUSHED) | 1297 if (extra.classic_state & DFCS_PUSHED) |
| 1291 InvertRect(hdc, &rect_win); | 1298 InvertRect(hdc, &rect_win); |
| 1292 return S_OK; | 1299 return S_OK; |
| 1293 } | 1300 } |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1319 break; | 1326 break; |
| 1320 } | 1327 } |
| 1321 | 1328 |
| 1322 if (handle && draw_theme_) | 1329 if (handle && draw_theme_) |
| 1323 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); | 1330 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); |
| 1324 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state); | 1331 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state); |
| 1325 return S_OK; | 1332 return S_OK; |
| 1326 } | 1333 } |
| 1327 | 1334 |
| 1328 HRESULT NativeThemeWin::PaintTrackbar( | 1335 HRESULT NativeThemeWin::PaintTrackbar( |
| 1329 SkCanvas* canvas, | |
| 1330 HDC hdc, | 1336 HDC hdc, |
| 1331 Part part, | 1337 Part part, |
| 1332 State state, | 1338 State state, |
| 1333 const gfx::Rect& rect, | 1339 const gfx::Rect& rect, |
| 1334 const TrackbarExtraParams& extra) const { | 1340 const TrackbarExtraParams& extra) const { |
| 1335 const int part_id = extra.vertical ? | 1341 const int part_id = extra.vertical ? |
| 1336 ((part == kTrackbarTrack) ? TKP_TRACKVERT : TKP_THUMBVERT) : | 1342 ((part == kTrackbarTrack) ? TKP_TRACKVERT : TKP_THUMBVERT) : |
| 1337 ((part == kTrackbarTrack) ? TKP_TRACK : TKP_THUMBBOTTOM); | 1343 ((part == kTrackbarTrack) ? TKP_TRACK : TKP_THUMBBOTTOM); |
| 1338 | 1344 |
| 1339 int state_id = TUS_NORMAL; | 1345 int state_id = TUS_NORMAL; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1393 RECT right_half = bottom_section; | 1399 RECT right_half = bottom_section; |
| 1394 right_half.left += ((bottom_section.right - bottom_section.left) / 2); | 1400 right_half.left += ((bottom_section.right - bottom_section.left) / 2); |
| 1395 left_half.right = right_half.left; | 1401 left_half.right = right_half.left; |
| 1396 DrawEdge(hdc, &left_half, EDGE_RAISED, | 1402 DrawEdge(hdc, &left_half, EDGE_RAISED, |
| 1397 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); | 1403 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); |
| 1398 DrawEdge(hdc, &right_half, EDGE_RAISED, | 1404 DrawEdge(hdc, &right_half, EDGE_RAISED, |
| 1399 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); | 1405 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); |
| 1400 | 1406 |
| 1401 // If the button is pressed, draw hatching. | 1407 // If the button is pressed, draw hatching. |
| 1402 if (extra.classic_state & DFCS_PUSHED) { | 1408 if (extra.classic_state & DFCS_PUSHED) { |
| 1409 SkSurface* surface = skia::MapPlatformSurface(hdc); | |
| 1410 SkCanvas* canvas = surface ? surface->getCanvas() : nullptr; | |
| 1411 if (!surface || !canvas) | |
|
Peter Kasting
2016/02/11 00:19:26
Nit: "if (!canvas)" suffices
tomhudson
2016/02/16 17:47:54
Done.
| |
| 1412 return E_FAIL; | |
| 1403 SkPaint paint; | 1413 SkPaint paint; |
| 1404 SetCheckerboardShader(&paint, rect_win); | 1414 SetCheckerboardShader(&paint, rect_win); |
| 1405 | 1415 |
| 1406 // Fill all three pieces with the pattern. | 1416 // Fill all three pieces with the pattern. |
| 1407 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint); | 1417 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint); |
| 1408 | 1418 |
| 1409 SkScalar left_triangle_top = SkIntToScalar(left_half.top); | 1419 SkScalar left_triangle_top = SkIntToScalar(left_half.top); |
| 1410 SkScalar left_triangle_right = SkIntToScalar(left_half.right); | 1420 SkScalar left_triangle_right = SkIntToScalar(left_half.right); |
| 1411 SkPath left_triangle; | 1421 SkPath left_triangle; |
| 1412 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); | 1422 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); |
| (...skipping 653 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2066 break; | 2076 break; |
| 2067 case LAST: | 2077 case LAST: |
| 2068 NOTREACHED(); | 2078 NOTREACHED(); |
| 2069 break; | 2079 break; |
| 2070 } | 2080 } |
| 2071 theme_handles_[theme_name] = handle; | 2081 theme_handles_[theme_name] = handle; |
| 2072 return handle; | 2082 return handle; |
| 2073 } | 2083 } |
| 2074 | 2084 |
| 2075 } // namespace ui | 2085 } // namespace ui |
| OLD | NEW |