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

Side by Side Diff: ui/views/style/mac/dialog_button_border_mac.cc

Issue 1831883002: Use sk_sp-based shader creation APIs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sprinkle in some std::move and some sk_sp in the API Created 4 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/views/style/mac/dialog_button_border_mac.h" 5 #include "ui/views/style/mac/dialog_button_border_mac.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "skia/ext/refptr.h" 8 #include "skia/ext/refptr.h"
9 #include "third_party/skia/include/core/SkCanvas.h" 9 #include "third_party/skia/include/core/SkCanvas.h"
10 #include "third_party/skia/include/core/SkDrawLooper.h" 10 #include "third_party/skia/include/core/SkDrawLooper.h"
(...skipping 20 matching lines...) Expand all
31 // Vertical offset of the drop shadow and the inner highlight shadow. 31 // Vertical offset of the drop shadow and the inner highlight shadow.
32 const SkScalar kShadowOffsetY = 1; 32 const SkScalar kShadowOffsetY = 1;
33 33
34 // Shadow blur radius of the inner highlight shadow. 34 // Shadow blur radius of the inner highlight shadow.
35 const double kInnerShadowBlurRadius = 2.0; 35 const double kInnerShadowBlurRadius = 2.0;
36 36
37 // Default border insets, to provide text padding. 37 // Default border insets, to provide text padding.
38 const int kPaddingX = 14; 38 const int kPaddingX = 14;
39 const int kPaddingY = 4; 39 const int kPaddingY = 4;
40 40
41 skia::RefPtr<SkShader> GetButtonGradient(int height, 41 sk_sp<SkShader> GetButtonGradient(int height,
danakj 2016/03/25 18:18:09 mind s/Get/Create/ while you're here?
tomhudson 2016/03/25 19:27:31 Done.
42 Button::ButtonState state) { 42 Button::ButtonState state) {
43 ColorByState start = {0xFFF0F0F0, 0xFFF4F4F4, 0xFFEBEBEB, 0xFFEDEDED}; 43 ColorByState start = {0xFFF0F0F0, 0xFFF4F4F4, 0xFFEBEBEB, 0xFFEDEDED};
44 ColorByState end = {0xFFE0E0E0, 0xFFE4E4E4, 0xFFDBDBDB, 0xFFDEDEDE}; 44 ColorByState end = {0xFFE0E0E0, 0xFFE4E4E4, 0xFFDBDBDB, 0xFFDEDEDE};
45 45
46 SkPoint gradient_points[2]; 46 SkPoint gradient_points[2];
47 gradient_points[0].iset(0, 0); 47 gradient_points[0].iset(0, 0);
48 gradient_points[1].iset(0, height); 48 gradient_points[1].iset(0, height);
49 49
50 SkColor gradient_colors[] = {start[state], start[state], end[state]}; 50 SkColor gradient_colors[] = {start[state], start[state], end[state]};
51 SkScalar gradient_positions[] = {0.0, 0.38, 1.0}; 51 SkScalar gradient_positions[] = {0.0, 0.38, 1.0};
52 52
53 skia::RefPtr<SkShader> gradient_shader = 53 return SkGradientShader::MakeLinear(
54 skia::AdoptRef(SkGradientShader::CreateLinear(
55 gradient_points, gradient_colors, gradient_positions, 3, 54 gradient_points, gradient_colors, gradient_positions, 3,
56 SkShader::kClamp_TileMode)); 55 SkShader::kClamp_TileMode);
57 return gradient_shader;
58 } 56 }
59 57
60 void DrawConstrainedButtonBackground(const SkRect& button_rect, 58 void DrawConstrainedButtonBackground(const SkRect& button_rect,
61 SkCanvas* canvas, 59 SkCanvas* canvas,
62 Button::ButtonState button_state) { 60 Button::ButtonState button_state) {
63 // Extend the size of the SkRect so the border stroke is drawn over it on all 61 // Extend the size of the SkRect so the border stroke is drawn over it on all
64 // sides. 62 // sides.
65 SkRect rect(button_rect); 63 SkRect rect(button_rect);
66 rect.fRight += 1; 64 rect.fRight += 1;
67 rect.fBottom += 1; 65 rect.fBottom += 1;
68 66
69 SkPaint paint; 67 SkPaint paint;
70 68
71 // Drop Shadow. 69 // Drop Shadow.
72 ColorByState shadow = {0x14000000, 0x1F000000, 0x00000000, 0x00000000}; 70 ColorByState shadow = {0x14000000, 0x1F000000, 0x00000000, 0x00000000};
73 const double blur = 0.0; 71 const double blur = 0.0;
74 std::vector<gfx::ShadowValue> shadows( 72 std::vector<gfx::ShadowValue> shadows(
75 1, gfx::ShadowValue(gfx::Vector2d(0, kShadowOffsetY), blur, 73 1, gfx::ShadowValue(gfx::Vector2d(0, kShadowOffsetY), blur,
76 shadow[button_state])); 74 shadow[button_state]));
77 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows); 75 skia::RefPtr<SkDrawLooper> looper = gfx::CreateShadowDrawLooper(shadows);
78 paint.setLooper(looper.get()); 76 paint.setLooper(looper.get());
79 77
80 // Background. 78 // Background.
81 skia::RefPtr<SkShader> gradient_shader = 79 paint.setShader(GetButtonGradient(rect.height(), button_state));
82 GetButtonGradient(rect.height(), button_state);
83 paint.setShader(gradient_shader.get());
84 paint.setStyle(SkPaint::kFill_Style); 80 paint.setStyle(SkPaint::kFill_Style);
85 paint.setFlags(SkPaint::kAntiAlias_Flag); 81 paint.setFlags(SkPaint::kAntiAlias_Flag);
86 canvas->drawRoundRect(rect, kCornerRadius, kCornerRadius, paint); 82 canvas->drawRoundRect(rect, kCornerRadius, kCornerRadius, paint);
87 } 83 }
88 84
89 // Draws an inner box shadow inside a rounded rectangle of size |rect|. The 85 // Draws an inner box shadow inside a rounded rectangle of size |rect|. The
90 // technique: draw a black "ring" around the outside of the button cell. Then 86 // technique: draw a black "ring" around the outside of the button cell. Then
91 // clip out everything except the shadow it casts. Works similar to Blink's 87 // clip out everything except the shadow it casts. Works similar to Blink's
92 // GraphicsContext::drawInnerShadow(). 88 // GraphicsContext::drawInnerShadow().
93 void DrawRoundRectInnerShadow(const SkRect& rect, 89 void DrawRoundRectInnerShadow(const SkRect& rect,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 else 154 else
159 paint.setColor(border[button.state()]); 155 paint.setColor(border[button.state()]);
160 canvas_skia->drawRoundRect(sk_rect, kCornerRadius, kCornerRadius, paint); 156 canvas_skia->drawRoundRect(sk_rect, kCornerRadius, kCornerRadius, paint);
161 } 157 }
162 158
163 gfx::Size DialogButtonBorderMac::GetMinimumSize() const { 159 gfx::Size DialogButtonBorderMac::GetMinimumSize() const {
164 return gfx::Size(100, 30); 160 return gfx::Size(100, 30);
165 } 161 }
166 162
167 } // namespace views 163 } // namespace views
OLDNEW
« skia/config/SkUserConfig.h ('K') | « ui/views/style/mac/combobox_background_mac.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698