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

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

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: Rebase Created 3 years, 10 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>
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
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
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
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 907 matching lines...) Expand 10 before | Expand all | Expand 10 after
1313 } 1315 }
1314 1316
1315 if (handle && draw_theme_) 1317 if (handle && draw_theme_)
1316 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL); 1318 return draw_theme_(handle, hdc, part_id, state_id, &rect_win, NULL);
1317 1319
1318 // Draw it manually. 1320 // Draw it manually.
1319 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) && 1321 if ((system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_3DFACE]) &&
1320 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) { 1322 (system_colors_[COLOR_SCROLLBAR] != system_colors_[COLOR_WINDOW])) {
1321 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1)); 1323 FillRect(hdc, &rect_win, reinterpret_cast<HBRUSH>(COLOR_SCROLLBAR + 1));
1322 } else { 1324 } else {
1323 SkPaint paint; 1325 cc::PaintFlags paint;
1324 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width, 1326 RECT align_rect = gfx::Rect(extra.track_x, extra.track_y, extra.track_width,
1325 extra.track_height).ToRECT(); 1327 extra.track_height).ToRECT();
1326 SetCheckerboardShader(&paint, align_rect); 1328 SetCheckerboardShader(&paint, align_rect);
1327 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint); 1329 canvas->drawIRect(skia::RECTToSkIRect(rect_win), paint);
1328 } 1330 }
1329 if (extra.classic_state & DFCS_PUSHED) 1331 if (extra.classic_state & DFCS_PUSHED)
1330 InvertRect(hdc, &rect_win); 1332 InvertRect(hdc, &rect_win);
1331 return S_OK; 1333 return S_OK;
1332 } 1334 }
1333 1335
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 RECT right_half = bottom_section; 1434 RECT right_half = bottom_section;
1433 right_half.left += ((bottom_section.right - bottom_section.left) / 2); 1435 right_half.left += ((bottom_section.right - bottom_section.left) / 2);
1434 left_half.right = right_half.left; 1436 left_half.right = right_half.left;
1435 DrawEdge(hdc, &left_half, EDGE_RAISED, 1437 DrawEdge(hdc, &left_half, EDGE_RAISED,
1436 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); 1438 BF_DIAGONAL_ENDTOPLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
1437 DrawEdge(hdc, &right_half, EDGE_RAISED, 1439 DrawEdge(hdc, &right_half, EDGE_RAISED,
1438 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST); 1440 BF_DIAGONAL_ENDBOTTOMLEFT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
1439 1441
1440 // If the button is pressed, draw hatching. 1442 // If the button is pressed, draw hatching.
1441 if (extra.classic_state & DFCS_PUSHED) { 1443 if (extra.classic_state & DFCS_PUSHED) {
1442 SkPaint paint; 1444 cc::PaintFlags paint;
1443 SetCheckerboardShader(&paint, rect_win); 1445 SetCheckerboardShader(&paint, rect_win);
1444 1446
1445 // Fill all three pieces with the pattern. 1447 // Fill all three pieces with the pattern.
1446 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint); 1448 canvas->drawIRect(skia::RECTToSkIRect(top_section), paint);
1447 1449
1448 SkScalar left_triangle_top = SkIntToScalar(left_half.top); 1450 SkScalar left_triangle_top = SkIntToScalar(left_half.top);
1449 SkScalar left_triangle_right = SkIntToScalar(left_half.right); 1451 SkScalar left_triangle_right = SkIntToScalar(left_half.right);
1450 SkPath left_triangle; 1452 SkPath left_triangle;
1451 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top); 1453 left_triangle.moveTo(SkIntToScalar(left_half.left), left_triangle_top);
1452 left_triangle.lineTo(left_triangle_right, left_triangle_top); 1454 left_triangle.lineTo(left_triangle_right, left_triangle_top);
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
2102 break; 2104 break;
2103 case LAST: 2105 case LAST:
2104 NOTREACHED(); 2106 NOTREACHED();
2105 break; 2107 break;
2106 } 2108 }
2107 theme_handles_[theme_name] = handle; 2109 theme_handles_[theme_name] = handle;
2108 return handle; 2110 return handle;
2109 } 2111 }
2110 2112
2111 } // namespace ui 2113 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698