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/win/scoped_gdi_object.h" | 15 #include "base/win/scoped_gdi_object.h" |
16 #include "base/win/scoped_hdc.h" | 16 #include "base/win/scoped_hdc.h" |
17 #include "base/win/scoped_select_object.h" | 17 #include "base/win/scoped_select_object.h" |
18 #include "base/win/win_util.h" | 18 #include "base/win/win_util.h" |
19 #include "base/win/windows_version.h" | 19 #include "base/win/windows_version.h" |
| 20 #include "cc/paint/paint_canvas.h" |
| 21 #include "cc/paint/paint_flags.h" |
20 #include "skia/ext/platform_canvas.h" | 22 #include "skia/ext/platform_canvas.h" |
21 #include "skia/ext/skia_utils_win.h" | 23 #include "skia/ext/skia_utils_win.h" |
22 #include "third_party/skia/include/core/SkCanvas.h" | 24 #include "third_party/skia/include/core/SkCanvas.h" |
23 #include "third_party/skia/include/core/SkColor.h" | 25 #include "third_party/skia/include/core/SkColor.h" |
24 #include "third_party/skia/include/core/SkColorPriv.h" | 26 #include "third_party/skia/include/core/SkColorPriv.h" |
25 #include "third_party/skia/include/core/SkPath.h" | 27 #include "third_party/skia/include/core/SkPath.h" |
26 #include "third_party/skia/include/core/SkRefCnt.h" | 28 #include "third_party/skia/include/core/SkRefCnt.h" |
27 #include "third_party/skia/include/core/SkShader.h" | 29 #include "third_party/skia/include/core/SkShader.h" |
28 #include "third_party/skia/include/core/SkSurface.h" | 30 #include "third_party/skia/include/core/SkSurface.h" |
29 #include "ui/base/material_design/material_design_controller.h" | 31 #include "ui/base/material_design/material_design_controller.h" |
(...skipping 21 matching lines...) Expand all Loading... |
51 COLOR_GRAYTEXT, | 53 COLOR_GRAYTEXT, |
52 COLOR_HIGHLIGHT, | 54 COLOR_HIGHLIGHT, |
53 COLOR_HIGHLIGHTTEXT, | 55 COLOR_HIGHLIGHTTEXT, |
54 COLOR_HOTLIGHT, | 56 COLOR_HOTLIGHT, |
55 COLOR_MENUHIGHLIGHT, | 57 COLOR_MENUHIGHLIGHT, |
56 COLOR_SCROLLBAR, | 58 COLOR_SCROLLBAR, |
57 COLOR_WINDOW, | 59 COLOR_WINDOW, |
58 COLOR_WINDOWTEXT, | 60 COLOR_WINDOWTEXT, |
59 }; | 61 }; |
60 | 62 |
61 void SetCheckerboardShader(SkPaint* paint, const RECT& align_rect) { | 63 void SetCheckerboardShader(cc::PaintFlags* paint, const RECT& align_rect) { |
62 // 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. |
63 const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE); | 65 const SkColor face = color_utils::GetSysSkColor(COLOR_3DFACE); |
64 const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT); | 66 const SkColor highlight = color_utils::GetSysSkColor(COLOR_3DHILIGHT); |
65 SkColor buffer[] = { face, highlight, highlight, face }; | 67 SkColor buffer[] = { face, highlight, highlight, face }; |
66 // 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, |
67 // 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 |
68 // 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 |
69 // 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 |
70 // 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 |
71 // until we're done using it. | 73 // until we're done using it. |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 state_id, NULL, TS_TRUE, &size))) | 246 state_id, NULL, TS_TRUE, &size))) |
245 return gfx::Size(size.cx, size.cy); | 247 return gfx::Size(size.cx, size.cy); |
246 | 248 |
247 // TODO(rogerta): For now, we need to support radio buttons and checkboxes | 249 // TODO(rogerta): For now, we need to support radio buttons and checkboxes |
248 // when theming is not enabled. Support for other parts can be added | 250 // when theming is not enabled. Support for other parts can be added |
249 // if/when needed. | 251 // if/when needed. |
250 return (part == kCheckbox || part == kRadio) ? | 252 return (part == kCheckbox || part == kRadio) ? |
251 gfx::Size(13, 13) : gfx::Size(); | 253 gfx::Size(13, 13) : gfx::Size(); |
252 } | 254 } |
253 | 255 |
254 void NativeThemeWin::Paint(SkCanvas* canvas, | 256 void NativeThemeWin::Paint(cc::PaintCanvas* canvas, |
255 Part part, | 257 Part part, |
256 State state, | 258 State state, |
257 const gfx::Rect& rect, | 259 const gfx::Rect& rect, |
258 const ExtraParams& extra) const { | 260 const ExtraParams& extra) const { |
259 if (rect.IsEmpty()) | 261 if (rect.IsEmpty()) |
260 return; | 262 return; |
261 | 263 |
262 switch (part) { | 264 switch (part) { |
263 case kMenuPopupGutter: | 265 case kMenuPopupGutter: |
264 PaintMenuGutter(canvas, rect); | 266 PaintMenuGutter(canvas, rect); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 NotifyObservers(); | 371 NotifyObservers(); |
370 } | 372 } |
371 | 373 |
372 void NativeThemeWin::UpdateSystemColors() { | 374 void NativeThemeWin::UpdateSystemColors() { |
373 for (int kSystemColor : kSystemColors) | 375 for (int kSystemColor : kSystemColors) |
374 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); | 376 system_colors_[kSystemColor] = color_utils::GetSysSkColor(kSystemColor); |
375 } | 377 } |
376 | 378 |
377 void NativeThemeWin::PaintMenuSeparator(SkCanvas* canvas, | 379 void NativeThemeWin::PaintMenuSeparator(SkCanvas* canvas, |
378 const gfx::Rect& rect) const { | 380 const gfx::Rect& rect) const { |
379 SkPaint paint; | 381 cc::PaintFlags paint; |
380 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); | 382 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); |
381 int position_y = rect.y() + rect.height() / 2; | 383 int position_y = rect.y() + rect.height() / 2; |
382 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, paint); | 384 canvas->drawLine(rect.x(), position_y, rect.right(), position_y, paint); |
383 } | 385 } |
384 | 386 |
385 void NativeThemeWin::PaintMenuGutter(SkCanvas* canvas, | 387 void NativeThemeWin::PaintMenuGutter(SkCanvas* canvas, |
386 const gfx::Rect& rect) const { | 388 const gfx::Rect& rect) const { |
387 SkPaint paint; | 389 cc::PaintFlags paint; |
388 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); | 390 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuSeparatorColor)); |
389 int position_x = rect.x() + rect.width() / 2; | 391 int position_x = rect.x() + rect.width() / 2; |
390 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), paint); | 392 canvas->drawLine(position_x, rect.y(), position_x, rect.bottom(), paint); |
391 } | 393 } |
392 | 394 |
393 void NativeThemeWin::PaintMenuBackground(SkCanvas* canvas, | 395 void NativeThemeWin::PaintMenuBackground(SkCanvas* canvas, |
394 const gfx::Rect& rect) const { | 396 const gfx::Rect& rect) const { |
395 SkPaint paint; | 397 cc::PaintFlags paint; |
396 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor)); | 398 paint.setColor(GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor)); |
397 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 399 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
398 } | 400 } |
399 | 401 |
400 void NativeThemeWin::PaintDirect(SkCanvas* destination_canvas, | 402 void NativeThemeWin::PaintDirect(SkCanvas* destination_canvas, |
401 HDC hdc, | 403 HDC hdc, |
402 Part part, | 404 Part part, |
403 State state, | 405 State state, |
404 const gfx::Rect& rect, | 406 const gfx::Rect& rect, |
405 const ExtraParams& extra) const { | 407 const ExtraParams& extra) const { |
(...skipping 906 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 } | 1314 } |
1313 | 1315 |
1314 if (handle && draw_theme_) | 1316 if (handle && draw_theme_) |
1315 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); |
1316 | 1318 |
1317 // Draw it manually. | 1319 // Draw it manually. |
1318 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && | 1320 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && |
1319 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { | 1321 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { |
1320 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); | 1322 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); |
1321 } else { | 1323 } else { |
1322 SkPaint paint; | 1324 cc::PaintFlags paint; |
1323 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, |
1324 extra.track_height).ToRECT(); | 1326 extra.track_height).ToRECT(); |
1325 SetCheckerboardShader(&paint, align_rect); | 1327 SetCheckerboardShader(&paint, align_rect); |
1326 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); | 1328 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); |
1327 } | 1329 } |
1328 if (extra.classic_state & DFCS_PUSHED) | 1330 if (extra.classic_state & DFCS_PUSHED) |
1329 InvertRect(hdc, &rect_win); | 1331 InvertRect(hdc, &rect_win); |
1330 return S_OK; | 1332 return S_OK; |
1331 } | 1333 } |
1332 | 1334 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 RECT right_half = bottom_section; | 1433 RECT right_half = bottom_section; |
1432 right_half.left += ((bottom_section.right - bottom_section.left) / 2); | 1434 right_half.left += ((bottom_section.right - bottom_section.left) / 2); |
1433 left_half.right = right_half.left; | 1435 left_half.right = right_half.left; |
1434 DrawEdge(hdc, &left_half, EDGE_RAISED, | 1436 DrawEdge(hdc, &left_half, EDGE_RAISED, |
1435 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); | 1437 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); |
1436 DrawEdge(hdc, &right_half, EDGE_RAISED, | 1438 DrawEdge(hdc, &right_half, EDGE_RAISED, |
1437 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); | 1439 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); |
1438 | 1440 |
1439 // If the button is pressed, draw hatching. | 1441 // If the button is pressed, draw hatching. |
1440 if (extra.classic_state & DFCS_PUSHED) { | 1442 if (extra.classic_state & DFCS_PUSHED) { |
1441 SkPaint paint; | 1443 cc::PaintFlags paint; |
1442 SetCheckerboardShader(&paint, rect_win); | 1444 SetCheckerboardShader(&paint, rect_win); |
1443 | 1445 |
1444 // Fill all three pieces with the pattern. | 1446 // Fill all three pieces with the pattern. |
1445 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint); | 1447 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint); |
1446 | 1448 |
1447 SkScalar left_triangle_top = SkIntToScalar(left_half.top); | 1449 SkScalar left_triangle_top = SkIntToScalar(left_half.top); |
1448 SkScalar left_triangle_right = SkIntToScalar(left_half.right); | 1450 SkScalar left_triangle_right = SkIntToScalar(left_half.right); |
1449 SkPath left_triangle; | 1451 SkPath left_triangle; |
1450 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); | 1452 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); |
1451 left_triangle.lineTo(left_triangle_right, left_triangle_top); | 1453 left_triangle.lineTo(left_triangle_right, left_triangle_top); |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2101 break; | 2103 break; |
2102 case LAST: | 2104 case LAST: |
2103 NOTREACHED(); | 2105 NOTREACHED(); |
2104 break; | 2106 break; |
2105 } | 2107 } |
2106 theme_handles_[theme_name] = handle; | 2108 theme_handles_[theme_name] = handle; |
2107 return handle; | 2109 return handle; |
2108 } | 2110 } |
2109 | 2111 |
2110 } // namespace ui | 2112 } // namespace ui |
OLD | NEW |