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

Side by Side Diff: chrome/browser/ui/views/theme_helpers.cc

Issue 8122013: Allow CanvasSkia to bind to an existing SkCanvas. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: 1 more fix Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/theme_helpers.h" 5 #include "chrome/browser/ui/views/theme_helpers.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlapp.h> 8 #include <atlapp.h>
9 #include <atltheme.h> 9 #include <atltheme.h>
10 10
(...skipping 13 matching lines...) Expand all
24 24
25 gfx::CanvasSkia canvas(width, 1, true); 25 gfx::CanvasSkia canvas(width, 1, true);
26 26
27 // Render the Rebar gradient into the DIB 27 // Render the Rebar gradient into the DIB
28 CTheme theme; 28 CTheme theme;
29 if (theme.IsThemingSupported()) 29 if (theme.IsThemingSupported())
30 theme.OpenThemeData(NULL, L"REBAR"); 30 theme.OpenThemeData(NULL, L"REBAR");
31 // On Windows XP+, if using a Theme, we can ask the theme to render the 31 // On Windows XP+, if using a Theme, we can ask the theme to render the
32 // gradient for us. 32 // gradient for us.
33 if (!theme.IsThemeNull()) { 33 if (!theme.IsThemeNull()) {
34 skia::ScopedPlatformPaint scoped_platform_paint(&canvas); 34 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas());
35 HDC dc = scoped_platform_paint.GetPlatformSurface(); 35 HDC dc = scoped_platform_paint.GetPlatformSurface();
36 RECT rect = { 0, 0, width, 1 }; 36 RECT rect = { 0, 0, width, 1 };
37 theme.DrawThemeBackground(dc, 0, 0, &rect, NULL); 37 theme.DrawThemeBackground(dc, 0, 0, &rect, NULL);
38 } else { 38 } else {
39 // On Windows 2000 or Windows XP+ with the Classic theme selected, we need 39 // On Windows 2000 or Windows XP+ with the Classic theme selected, we need
40 // to build our own gradient using system colors. 40 // to build our own gradient using system colors.
41 SkColor grad_colors[2]; 41 SkColor grad_colors[2];
42 COLORREF hl_ref = ::GetSysColor(COLOR_3DHILIGHT); 42 COLORREF hl_ref = ::GetSysColor(COLOR_3DHILIGHT);
43 grad_colors[0] = SkColorSetRGB(GetRValue(hl_ref), GetGValue(hl_ref), 43 grad_colors[0] = SkColorSetRGB(GetRValue(hl_ref), GetGValue(hl_ref),
44 GetBValue(hl_ref)); 44 GetBValue(hl_ref));
45 COLORREF face_ref = ::GetSysColor(COLOR_3DFACE); 45 COLORREF face_ref = ::GetSysColor(COLOR_3DFACE);
46 grad_colors[1] = SkColorSetRGB(GetRValue(face_ref), GetGValue(face_ref), 46 grad_colors[1] = SkColorSetRGB(GetRValue(face_ref), GetGValue(face_ref),
47 GetBValue(face_ref)); 47 GetBValue(face_ref));
48 SkPoint grad_points[2]; 48 SkPoint grad_points[2];
49 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(0)); 49 grad_points[0].set(SkIntToScalar(0), SkIntToScalar(0));
50 grad_points[1].set(SkIntToScalar(width), SkIntToScalar(0)); 50 grad_points[1].set(SkIntToScalar(width), SkIntToScalar(0));
51 SkShader* gradient_shader = SkGradientShader::CreateLinear( 51 SkShader* gradient_shader = SkGradientShader::CreateLinear(
52 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode); 52 grad_points, grad_colors, NULL, 2, SkShader::kRepeat_TileMode);
53 SkPaint paint; 53 SkPaint paint;
54 paint.setShader(gradient_shader); 54 paint.setShader(gradient_shader);
55 // Shader created with a ref count of 1, release as the paint now owns 55 // Shader created with a ref count of 1, release as the paint now owns
56 // the gradient. 56 // the gradient.
57 gradient_shader->unref(); 57 gradient_shader->unref();
58 paint.setStyle(SkPaint::kFill_Style); 58 paint.setStyle(SkPaint::kFill_Style);
59 canvas.drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), 59 canvas.sk_canvas()->drawRectCoords(
60 SkIntToScalar(width), SkIntToScalar(1), paint); 60 SkIntToScalar(0), SkIntToScalar(0),
61 SkIntToScalar(width), SkIntToScalar(1), paint);
61 } 62 }
62 63
63 // Extract the color values from the selected pixels 64 // Extract the color values from the selected pixels
64 // The | in the following operations forces the alpha to 0xFF. This is 65 // The | in the following operations forces the alpha to 0xFF. This is
65 // needed as windows sets the alpha to 0 when it renders. 66 // needed as windows sets the alpha to 0 when it renders.
66 SkDevice* device = skia::GetTopDevice(canvas); 67 SkDevice* device = skia::GetTopDevice(*canvas.sk_canvas());
67 const SkBitmap& bitmap = device->accessBitmap(false); 68 const SkBitmap& bitmap = device->accessBitmap(false);
68 SkAutoLockPixels lock(bitmap); 69 SkAutoLockPixels lock(bitmap);
69 70
70 *c1 = 0xFF000000 | bitmap.getColor(x1, 0); 71 *c1 = 0xFF000000 | bitmap.getColor(x1, 0);
71 *c2 = 0xFF000000 | bitmap.getColor(x2, 0); 72 *c2 = 0xFF000000 | bitmap.getColor(x2, 0);
72 } 73 }
73 74
74 void GetDarkLineColor(SkColor* dark_color) { 75 void GetDarkLineColor(SkColor* dark_color) {
75 DCHECK(dark_color) << "ThemeHelpers::DarkColor - dark_color is NULL!"; 76 DCHECK(dark_color) << "ThemeHelpers::DarkColor - dark_color is NULL!";
76 77
77 CTheme theme; 78 CTheme theme;
78 if (theme.IsThemingSupported()) 79 if (theme.IsThemingSupported())
79 theme.OpenThemeData(NULL, L"REBAR"); 80 theme.OpenThemeData(NULL, L"REBAR");
80 81
81 // Note: the alpha values were chosen scientifically according to what looked 82 // Note: the alpha values were chosen scientifically according to what looked
82 // best to me at the time! --beng 83 // best to me at the time! --beng
83 if (!theme.IsThemeNull()) { 84 if (!theme.IsThemeNull()) {
84 *dark_color = SkColorSetARGB(60, 0, 0, 0); 85 *dark_color = SkColorSetARGB(60, 0, 0, 0);
85 } else { 86 } else {
86 COLORREF shadow_ref = ::GetSysColor(COLOR_3DSHADOW); 87 COLORREF shadow_ref = ::GetSysColor(COLOR_3DSHADOW);
87 *dark_color = SkColorSetARGB(175, 88 *dark_color = SkColorSetARGB(175,
88 GetRValue(shadow_ref), 89 GetRValue(shadow_ref),
89 GetGValue(shadow_ref), 90 GetGValue(shadow_ref),
90 GetBValue(shadow_ref)); 91 GetBValue(shadow_ref));
91 } 92 }
92 } 93 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698