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

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

Issue 2716213002: ui: Fix cc/paint skia type mismatches (Closed)
Patch Set: Created 3 years, 9 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
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 <stddef.h> 8 #include <stddef.h>
9 #include <uxtheme.h> 9 #include <uxtheme.h>
10 #include <vsstyle.h> 10 #include <vsstyle.h>
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 COLOR_GRAYTEXT, 53 COLOR_GRAYTEXT,
54 COLOR_HIGHLIGHT, 54 COLOR_HIGHLIGHT,
55 COLOR_HIGHLIGHTTEXT, 55 COLOR_HIGHLIGHTTEXT,
56 COLOR_HOTLIGHT, 56 COLOR_HOTLIGHT,
57 COLOR_MENUHIGHLIGHT, 57 COLOR_MENUHIGHLIGHT,
58 COLOR_SCROLLBAR, 58 COLOR_SCROLLBAR,
59 COLOR_WINDOW, 59 COLOR_WINDOW,
60 COLOR_WINDOWTEXT, 60 COLOR_WINDOWTEXT,
61 }; 61 };
62 62
63 void SetCheckerboardShader(cc::PaintFlags* flags, const RECT& align_rect) { 63 void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) {
64 // Create a 2x2 checkerboard pattern using the 3D face and highlight colors. 64 // Create a 2x2 checkerboard pattern using the 3D face and highlight colors.
65 const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE); 65 const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE);
66 const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT); 66 const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT);
67 SkColor buffer[] = { face, highlight, highlight, face }; 67 SkColor buffer[] = { face, highlight, highlight, face };
68 // Confusing bit: we first create a temporary bitmap with our desired pattern, 68 // Confusing bit: we first create a temporary bitmap with our desired pattern,
69 // then copy it to another bitmap. The temporary bitmap doesn't take 69 // then copy it to another bitmap. The temporary bitmap doesn't take
70 // ownership of the pixel data, and so will point to garbage when this 70 // ownership of the pixel data, and so will point to garbage when this
71 // function returns. The copy will copy the pixel data into a place owned by 71 // function returns. The copy will copy the pixel data into a place owned by
72 // the bitmap, which is in turn owned by the shader, etc., so it will live 72 // the bitmap, which is in turn owned by the shader, etc., so it will live
73 // until we're done using it. 73 // until we're done using it.
74 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); 74 SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2);
75 SkBitmap temp_bitmap; 75 SkBitmap temp_bitmap;
76 temp_bitmap.installPixels(info, buffer, info.minRowBytes()); 76 temp_bitmap.installPixels(info, buffer, info.minRowBytes());
77 SkBitmap bitmap; 77 SkBitmap bitmap;
78 temp_bitmap.copyTo(&bitmap); 78 temp_bitmap.copyTo(&bitmap);
79 79
80 // Align the pattern with the upper corner of |align_rect|. 80 // Align the pattern with the upper corner of |align_rect|.
81 SkMatrix local_matrix; 81 SkMatrix local_matrix;
82 local_matrix.setTranslate(SkIntToScalar(align_rect.left), 82 local_matrix.setTranslate(SkIntToScalar(align_rect.left),
83 SkIntToScalar(align_rect.top)); 83 SkIntToScalar(align_rect.top));
84 flags->setShader( 84 paint->setShader(
85 SkShader::MakeBitmapShader(bitmap, SkShader::kRepeat_TileMode, 85 SkShader::MakeBitmapShader(bitmap, SkShader::kRepeat_TileMode,
86 SkShader::kRepeat_TileMode, &local_matrix)); 86 SkShader::kRepeat_TileMode, &local_matrix));
87 } 87 }
88 88
89 // <-a-> 89 // <-a->
90 // [ ***** ] 90 // [ ***** ]
91 // ____ | | 91 // ____ | |
92 // <-a-> <------b-----> 92 // <-a-> <------b----->
93 // a: object_width 93 // a: object_width
94 // b: frame_width 94 // b: frame_width
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 UpdateSystemColors(); 358 UpdateSystemColors();
359 is_using_high_contrast_valid_ = false; 359 is_using_high_contrast_valid_ = false;
360 NotifyObservers(); 360 NotifyObservers();
361 } 361 }
362 362
363 void NativeThemeWin::UpdateSystemColors() { 363 void NativeThemeWin::UpdateSystemColors() {
364 for (int kSystemColor : kSystemColors) 364 for (int kSystemColor : kSystemColors)
365 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); 365 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor);
366 } 366 }
367 367
368 void NativeThemeWin::PaintMenuSeparator(SkCanvas* canvas, 368 void NativeThemeWin::PaintMenuSeparator(cc::PaintCanvas* canvas,
369 const gfx::Rect& rect) const { 369 const gfx::Rect& rect) const {
370 cc::PaintFlags flags; 370 cc::PaintFlags flags;
371 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); 371 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor));
372 int position_y = rect.y() + rect.height() / 2; 372 int position_y = rect.y() + rect.height() / 2;
373 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, flags); 373 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, flags);
374 } 374 }
375 375
376 void NativeThemeWin::PaintMenuGutter(SkCanvas* canvas, 376 void NativeThemeWin::PaintMenuGutter(cc::PaintCanvas* canvas,
377 const gfx::Rect& rect) const { 377 const gfx::Rect& rect) const {
378 cc::PaintFlags flags; 378 cc::PaintFlags flags;
379 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); 379 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor));
380 int position_x = rect.x() + rect.width() / 2; 380 int position_x = rect.x() + rect.width() / 2;
381 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), flags); 381 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), flags);
382 } 382 }
383 383
384 void NativeThemeWin::PaintMenuBackground(SkCanvas* canvas, 384 void NativeThemeWin::PaintMenuBackground(cc::PaintCanvas* canvas,
385 const gfx::Rect& rect) const { 385 const gfx::Rect& rect) const {
386 cc::PaintFlags flags; 386 cc::PaintFlags flags;
387 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor)); 387 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor));
388 canvas->drawRect(gfx::RectToSkRect(rect), flags); 388 canvas->drawRect(gfx::RectToSkRect(rect), flags);
389 } 389 }
390 390
391 void NativeThemeWin::PaintDirect(SkCanvas* destination_canvas, 391 void NativeThemeWin::PaintDirect(SkCanvas* destination_canvas,
392 HDC hdc, 392 HDC hdc,
393 Part part, 393 Part part,
394 State state, 394 State state,
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
653 case NativeTheme::kColorId_ProminentButtonColor: 653 case NativeTheme::kColorId_ProminentButtonColor:
654 return kProminentButtonColorInvert; 654 return kProminentButtonColorInvert;
655 default: 655 default:
656 return color_utils::InvertColor(GetAuraColor(color_id, this)); 656 return color_utils::InvertColor(GetAuraColor(color_id, this));
657 } 657 }
658 } 658 }
659 659
660 return GetAuraColor(color_id, this); 660 return GetAuraColor(color_id, this);
661 } 661 }
662 662
663 void NativeThemeWin::PaintIndirect(SkCanvas* destination_canvas, 663 void NativeThemeWin::PaintIndirect(cc::PaintCanvas* destination_canvas,
664 Part part, 664 Part part,
665 State state, 665 State state,
666 const gfx::Rect& rect, 666 const gfx::Rect& rect,
667 const ExtraParams& extra) const { 667 const ExtraParams& extra) const {
668 // TODO(asvitkine): This path is pretty inefficient - for each paint operation 668 // TODO(asvitkine): This path is pretty inefficient - for each paint operation
669 // it creates a new offscreen bitmap Skia canvas. This can be sped up by doing 669 // it creates a new offscreen bitmap Skia canvas. This can be sped up by doing
670 // it only once per part/state and keeping a cache of the resulting bitmaps. 670 // it only once per part/state and keeping a cache of the resulting bitmaps.
671 // 671 //
672 // TODO(enne): This could also potentially be sped up for software raster 672 // TODO(enne): This could also potentially be sped up for software raster
673 // by moving these draw ops into PaintRecord itself and then moving the 673 // by moving these draw ops into PaintRecord itself and then moving the
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 } 1304 }
1305 1305
1306 if (handle && draw_theme_) 1306 if (handle && draw_theme_)
1307 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); 1307 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL);
1308 1308
1309 // Draw it manually. 1309 // Draw it manually.
1310 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && 1310 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) &&
1311 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { 1311 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) {
1312 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); 1312 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1));
1313 } else { 1313 } else {
1314 cc::PaintFlags flags; 1314 SkPaint paint;
1315 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, 1315 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width,
1316 extra.track_height).ToRECT(); 1316 extra.track_height).ToRECT();
1317 SetCheckerboardShader(&flags, align_rect); 1317 SetCheckerboardShader(&paint, align_rect);
1318 canvas->drawIRect(skia::RECTToSkIRect(rect_win), flags); 1318 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint);
1319 } 1319 }
1320 if (extra.classic_state & DFCS_PUSHED) 1320 if (extra.classic_state & DFCS_PUSHED)
1321 InvertRect(hdc, &rect_win); 1321 InvertRect(hdc, &rect_win);
1322 return S_OK; 1322 return S_OK;
1323 } 1323 }
1324 1324
1325 HRESULT NativeThemeWin::PaintSpinButton( 1325 HRESULT NativeThemeWin::PaintSpinButton(
1326 HDC hdc, 1326 HDC hdc,
1327 Part part, 1327 Part part,
1328 State state, 1328 State state,
(...skipping 19 matching lines...) Expand all
1348 NOTREACHED(); 1348 NOTREACHED();
1349 break; 1349 break;
1350 } 1350 }
1351 1351
1352 if (handle && draw_theme_) 1352 if (handle && draw_theme_)
1353 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); 1353 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL);
1354 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state); 1354 DrawFrameControl(hdc, &rect_win, DFC_SCROLL, extra.classic_state);
1355 return S_OK; 1355 return S_OK;
1356 } 1356 }
1357 1357
1358 HRESULT NativeThemeWin::PaintTrackbar( 1358 HRESULT NativeThemeWin::PaintTrackbar(SkCanvas* canvas,
1359 SkCanvas* canvas, 1359 HDC hdc,
1360 HDC hdc, 1360 Part part,
1361 Part part, 1361 State state,
1362 State state, 1362 const gfx::Rect& rect,
1363 const gfx::Rect& rect, 1363 const TrackbarExtraParams& extra) const {
1364 const TrackbarExtraParams& extra) const {
1365 const int part_id = extra.vertical ? 1364 const int part_id = extra.vertical ?
1366 ((part == kTrackbarTrack) ? TKP_TRACKVERT : TKP_THUMBVERT) : 1365 ((part == kTrackbarTrack) ? TKP_TRACKVERT : TKP_THUMBVERT) :
1367 ((part == kTrackbarTrack) ? TKP_TRACK : TKP_THUMBBOTTOM); 1366 ((part == kTrackbarTrack) ? TKP_TRACK : TKP_THUMBBOTTOM);
1368 1367
1369 int state_id = TUS_NORMAL; 1368 int state_id = TUS_NORMAL;
1370 switch (state) { 1369 switch (state) {
1371 case kDisabled: 1370 case kDisabled:
1372 state_id = TUS_DISABLED; 1371 state_id = TUS_DISABLED;
1373 break; 1372 break;
1374 case kHovered: 1373 case kHovered:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 RECT right_half = bottom_section; 1422 RECT right_half = bottom_section;
1424 right_half.left += ((bottom_section.right - bottom_section.left) / 2); 1423 right_half.left += ((bottom_section.right - bottom_section.left) / 2);
1425 left_half.right = right_half.left; 1424 left_half.right = right_half.left;
1426 DrawEdge(hdc, &left_half, EDGE_RAISED, 1425 DrawEdge(hdc, &left_half, EDGE_RAISED,
1427 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); 1426 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
1428 DrawEdge(hdc, &right_half, EDGE_RAISED, 1427 DrawEdge(hdc, &right_half, EDGE_RAISED,
1429 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); 1428 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
1430 1429
1431 // If the button is pressed, draw hatching. 1430 // If the button is pressed, draw hatching.
1432 if (extra.classic_state & DFCS_PUSHED) { 1431 if (extra.classic_state & DFCS_PUSHED) {
1433 cc::PaintFlags flags; 1432 SkPaint paint;
1434 SetCheckerboardShader(&flags, rect_win); 1433 SetCheckerboardShader(&paint, rect_win);
1435 1434
1436 // Fill all three pieces with the pattern. 1435 // Fill all three pieces with the pattern.
1437 canvas->drawIRect(skia::RECTToSkIRect(top_section), flags); 1436 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint);
1438 1437
1439 SkScalar left_triangle_top = SkIntToScalar(left_half.top); 1438 SkScalar left_triangle_top = SkIntToScalar(left_half.top);
1440 SkScalar left_triangle_right = SkIntToScalar(left_half.right); 1439 SkScalar left_triangle_right = SkIntToScalar(left_half.right);
1441 SkPath left_triangle; 1440 SkPath left_triangle;
1442 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); 1441 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top);
1443 left_triangle.lineTo(left_triangle_right, left_triangle_top); 1442 left_triangle.lineTo(left_triangle_right, left_triangle_top);
1444 left_triangle.lineTo(left_triangle_right, 1443 left_triangle.lineTo(left_triangle_right,
1445 SkIntToScalar(left_half.bottom)); 1444 SkIntToScalar(left_half.bottom));
1446 left_triangle.close(); 1445 left_triangle.close();
1447 canvas->drawPath(left_triangle, flags); 1446 canvas->drawPath(left_triangle, paint);
1448 1447
1449 SkScalar right_triangle_left = SkIntToScalar(right_half.left); 1448 SkScalar right_triangle_left = SkIntToScalar(right_half.left);
1450 SkScalar right_triangle_top = SkIntToScalar(right_half.top); 1449 SkScalar right_triangle_top = SkIntToScalar(right_half.top);
1451 SkPath right_triangle; 1450 SkPath right_triangle;
1452 right_triangle.moveTo(right_triangle_left, right_triangle_top); 1451 right_triangle.moveTo(right_triangle_left, right_triangle_top);
1453 right_triangle.lineTo(SkIntToScalar(right_half.right), 1452 right_triangle.lineTo(SkIntToScalar(right_half.right),
1454 right_triangle_top); 1453 right_triangle_top);
1455 right_triangle.lineTo(right_triangle_left, 1454 right_triangle.lineTo(right_triangle_left,
1456 SkIntToScalar(right_half.bottom)); 1455 SkIntToScalar(right_half.bottom));
1457 right_triangle.close(); 1456 right_triangle.close();
1458 canvas->drawPath(right_triangle, flags); 1457 canvas->drawPath(right_triangle, paint);
1459 } 1458 }
1460 } 1459 }
1461 return S_OK; 1460 return S_OK;
1462 } 1461 }
1463 1462
1464 HRESULT NativeThemeWin::PaintProgressBar( 1463 HRESULT NativeThemeWin::PaintProgressBar(
1465 HDC hdc, 1464 HDC hdc,
1466 const gfx::Rect& rect, 1465 const gfx::Rect& rect,
1467 const ProgressBarExtraParams& extra) const { 1466 const ProgressBarExtraParams& extra) const {
1468 // There is no documentation about the animation speed, frame-rate, nor 1467 // There is no documentation about the animation speed, frame-rate, nor
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after
2093 break; 2092 break;
2094 case LAST: 2093 case LAST:
2095 NOTREACHED(); 2094 NOTREACHED();
2096 break; 2095 break;
2097 } 2096 }
2098 theme_handles_[theme_name] = handle; 2097 theme_handles_[theme_name] = handle;
2099 return handle; 2098 return handle;
2100 } 2099 }
2101 2100
2102 } // namespace ui 2101 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698