| 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> |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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* paint, const RECT& align_rect) { | 63 void SetCheckerboardShader(cc::PaintFlags* flags, 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 paint->setShader( | 84 flags->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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 NotifyObservers(); | 371 NotifyObservers(); |
| 372 } | 372 } |
| 373 | 373 |
| 374 void NativeThemeWin::UpdateSystemColors() { | 374 void NativeThemeWin::UpdateSystemColors() { |
| 375 for (int kSystemColor : kSystemColors) | 375 for (int kSystemColor : kSystemColors) |
| 376 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); | 376 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void NativeThemeWin::PaintMenuSeparator(SkCanvas* canvas, | 379 void NativeThemeWin::PaintMenuSeparator(SkCanvas* canvas, |
| 380 const gfx::Rect& rect) const { | 380 const gfx::Rect& rect) const { |
| 381 cc::PaintFlags paint; | 381 cc::PaintFlags flags; |
| 382 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); | 382 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); |
| 383 int position_y = rect.y() + rect.height() / 2; | 383 int position_y = rect.y() + rect.height() / 2; |
| 384 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, paint); | 384 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, flags); |
| 385 } | 385 } |
| 386 | 386 |
| 387 void NativeThemeWin::PaintMenuGutter(SkCanvas* canvas, | 387 void NativeThemeWin::PaintMenuGutter(SkCanvas* canvas, |
| 388 const gfx::Rect& rect) const { | 388 const gfx::Rect& rect) const { |
| 389 cc::PaintFlags paint; | 389 cc::PaintFlags flags; |
| 390 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); | 390 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); |
| 391 int position_x = rect.x() + rect.width() / 2; | 391 int position_x = rect.x() + rect.width() / 2; |
| 392 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), paint); | 392 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), flags); |
| 393 } | 393 } |
| 394 | 394 |
| 395 void NativeThemeWin::PaintMenuBackground(SkCanvas* canvas, | 395 void NativeThemeWin::PaintMenuBackground(SkCanvas* canvas, |
| 396 const gfx::Rect& rect) const { | 396 const gfx::Rect& rect) const { |
| 397 cc::PaintFlags paint; | 397 cc::PaintFlags flags; |
| 398 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor)); | 398 flags.setColor(GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor)); |
| 399 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 399 canvas->drawRect(gfx::RectToSkRect(rect), flags); |
| 400 } | 400 } |
| 401 | 401 |
| 402 void NativeThemeWin::PaintDirect(SkCanvas* destination_canvas, | 402 void NativeThemeWin::PaintDirect(SkCanvas* destination_canvas, |
| 403 HDC hdc, | 403 HDC hdc, |
| 404 Part part, | 404 Part part, |
| 405 State state, | 405 State state, |
| 406 const gfx::Rect& rect, | 406 const gfx::Rect& rect, |
| 407 const ExtraParams& extra) const { | 407 const ExtraParams& extra) const { |
| 408 switch (part) { | 408 switch (part) { |
| 409 case kCheckbox: | 409 case kCheckbox: |
| (...skipping 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 } | 1314 } |
| 1315 | 1315 |
| 1316 if (handle && draw_theme_) | 1316 if (handle && draw_theme_) |
| 1317 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); | 1317 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); |
| 1318 | 1318 |
| 1319 // Draw it manually. | 1319 // Draw it manually. |
| 1320 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && | 1320 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && |
| 1321 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { | 1321 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { |
| 1322 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); | 1322 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); |
| 1323 } else { | 1323 } else { |
| 1324 cc::PaintFlags paint; | 1324 cc::PaintFlags flags; |
| 1325 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, | 1325 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, |
| 1326 extra.track_height).ToRECT(); | 1326 extra.track_height).ToRECT(); |
| 1327 SetCheckerboardShader(&paint, align_rect); | 1327 SetCheckerboardShader(&flags, align_rect); |
| 1328 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); | 1328 canvas->drawIRect(skia::RECTToSkIRect(rect_win), flags); |
| 1329 } | 1329 } |
| 1330 if (extra.classic_state & DFCS_PUSHED) | 1330 if (extra.classic_state & DFCS_PUSHED) |
| 1331 InvertRect(hdc, &rect_win); | 1331 InvertRect(hdc, &rect_win); |
| 1332 return S_OK; | 1332 return S_OK; |
| 1333 } | 1333 } |
| 1334 | 1334 |
| 1335 HRESULT NativeThemeWin::PaintSpinButton( | 1335 HRESULT NativeThemeWin::PaintSpinButton( |
| 1336 HDC hdc, | 1336 HDC hdc, |
| 1337 Part part, | 1337 Part part, |
| 1338 State state, | 1338 State state, |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 RECT right_half = bottom_section; | 1433 RECT right_half = bottom_section; |
| 1434 right_half.left += ((bottom_section.right - bottom_section.left) / 2); | 1434 right_half.left += ((bottom_section.right - bottom_section.left) / 2); |
| 1435 left_half.right = right_half.left; | 1435 left_half.right = right_half.left; |
| 1436 DrawEdge(hdc, &left_half, EDGE_RAISED, | 1436 DrawEdge(hdc, &left_half, EDGE_RAISED, |
| 1437 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); | 1437 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); |
| 1438 DrawEdge(hdc, &right_half, EDGE_RAISED, | 1438 DrawEdge(hdc, &right_half, EDGE_RAISED, |
| 1439 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); | 1439 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); |
| 1440 | 1440 |
| 1441 // If the button is pressed, draw hatching. | 1441 // If the button is pressed, draw hatching. |
| 1442 if (extra.classic_state & DFCS_PUSHED) { | 1442 if (extra.classic_state & DFCS_PUSHED) { |
| 1443 cc::PaintFlags paint; | 1443 cc::PaintFlags flags; |
| 1444 SetCheckerboardShader(&paint, rect_win); | 1444 SetCheckerboardShader(&flags, rect_win); |
| 1445 | 1445 |
| 1446 // Fill all three pieces with the pattern. | 1446 // Fill all three pieces with the pattern. |
| 1447 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint); | 1447 canvas->drawIRect(skia::RECTToSkIRect(top_section), flags); |
| 1448 | 1448 |
| 1449 SkScalar left_triangle_top = SkIntToScalar(left_half.top); | 1449 SkScalar left_triangle_top = SkIntToScalar(left_half.top); |
| 1450 SkScalar left_triangle_right = SkIntToScalar(left_half.right); | 1450 SkScalar left_triangle_right = SkIntToScalar(left_half.right); |
| 1451 SkPath left_triangle; | 1451 SkPath left_triangle; |
| 1452 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); | 1452 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); |
| 1453 left_triangle.lineTo(left_triangle_right, left_triangle_top); | 1453 left_triangle.lineTo(left_triangle_right, left_triangle_top); |
| 1454 left_triangle.lineTo(left_triangle_right, | 1454 left_triangle.lineTo(left_triangle_right, |
| 1455 SkIntToScalar(left_half.bottom)); | 1455 SkIntToScalar(left_half.bottom)); |
| 1456 left_triangle.close(); | 1456 left_triangle.close(); |
| 1457 canvas->drawPath(left_triangle, paint); | 1457 canvas->drawPath(left_triangle, flags); |
| 1458 | 1458 |
| 1459 SkScalar right_triangle_left = SkIntToScalar(right_half.left); | 1459 SkScalar right_triangle_left = SkIntToScalar(right_half.left); |
| 1460 SkScalar right_triangle_top = SkIntToScalar(right_half.top); | 1460 SkScalar right_triangle_top = SkIntToScalar(right_half.top); |
| 1461 SkPath right_triangle; | 1461 SkPath right_triangle; |
| 1462 right_triangle.moveTo(right_triangle_left, right_triangle_top); | 1462 right_triangle.moveTo(right_triangle_left, right_triangle_top); |
| 1463 right_triangle.lineTo(SkIntToScalar(right_half.right), | 1463 right_triangle.lineTo(SkIntToScalar(right_half.right), |
| 1464 right_triangle_top); | 1464 right_triangle_top); |
| 1465 right_triangle.lineTo(right_triangle_left, | 1465 right_triangle.lineTo(right_triangle_left, |
| 1466 SkIntToScalar(right_half.bottom)); | 1466 SkIntToScalar(right_half.bottom)); |
| 1467 right_triangle.close(); | 1467 right_triangle.close(); |
| 1468 canvas->drawPath(right_triangle, paint); | 1468 canvas->drawPath(right_triangle, flags); |
| 1469 } | 1469 } |
| 1470 } | 1470 } |
| 1471 return S_OK; | 1471 return S_OK; |
| 1472 } | 1472 } |
| 1473 | 1473 |
| 1474 HRESULT NativeThemeWin::PaintProgressBar( | 1474 HRESULT NativeThemeWin::PaintProgressBar( |
| 1475 HDC hdc, | 1475 HDC hdc, |
| 1476 const gfx::Rect& rect, | 1476 const gfx::Rect& rect, |
| 1477 const ProgressBarExtraParams& extra) const { | 1477 const ProgressBarExtraParams& extra) const { |
| 1478 // There is no documentation about the animation speed, frame-rate, nor | 1478 // There is no documentation about the animation speed, frame-rate, nor |
| (...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2103 break; | 2103 break; |
| 2104 case LAST: | 2104 case LAST: |
| 2105 NOTREACHED(); | 2105 NOTREACHED(); |
| 2106 break; | 2106 break; |
| 2107 } | 2107 } |
| 2108 theme_handles_[theme_name] = handle; | 2108 theme_handles_[theme_name] = handle; |
| 2109 return handle; | 2109 return handle; |
| 2110 } | 2110 } |
| 2111 | 2111 |
| 2112 } // namespace ui | 2112 } // namespace ui |
| OLD | NEW |