| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/chromeos/login/rounded_rect_painter.h" | 5 #include "chrome/browser/chromeos/login/rounded_rect_painter.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/browser/chromeos/login/helper.h" | 8 #include "chrome/browser/chromeos/login/helper.h" |
| 9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| 10 #include "third_party/skia/include/effects/SkGradientShader.h" | 10 #include "third_party/skia/include/effects/SkGradientShader.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 SkColor colors[2] = { top_color, bottom_color }; | 46 SkColor colors[2] = { top_color, bottom_color }; |
| 47 SkShader* s = | 47 SkShader* s = |
| 48 SkGradientShader::CreateLinear(p, colors, NULL, 2, | 48 SkGradientShader::CreateLinear(p, colors, NULL, 2, |
| 49 SkShader::kClamp_TileMode, NULL); | 49 SkShader::kClamp_TileMode, NULL); |
| 50 paint.setShader(s); | 50 paint.setShader(s); |
| 51 // Need to unref shader, otherwise never deleted. | 51 // Need to unref shader, otherwise never deleted. |
| 52 s->unref(); | 52 s->unref(); |
| 53 } else { | 53 } else { |
| 54 paint.setColor(top_color); | 54 paint.setColor(top_color); |
| 55 } | 55 } |
| 56 canvas->AsCanvasSkia()->drawPath(path, paint); | 56 canvas->GetSkCanvas()->drawPath(path, paint); |
| 57 | 57 |
| 58 if (stroke_color != 0) { | 58 if (stroke_color != 0) { |
| 59 // Expand rect by 0.5px so resulting stroke will take the whole pixel. | 59 // Expand rect by 0.5px so resulting stroke will take the whole pixel. |
| 60 rect.set( | 60 rect.set( |
| 61 SkIntToScalar(x) - SK_ScalarHalf, | 61 SkIntToScalar(x) - SK_ScalarHalf, |
| 62 SkIntToScalar(y) - SK_ScalarHalf, | 62 SkIntToScalar(y) - SK_ScalarHalf, |
| 63 SkIntToScalar(x + w) + SK_ScalarHalf, | 63 SkIntToScalar(x + w) + SK_ScalarHalf, |
| 64 SkIntToScalar(y + h) + SK_ScalarHalf); | 64 SkIntToScalar(y + h) + SK_ScalarHalf); |
| 65 paint.setShader(NULL); | 65 paint.setShader(NULL); |
| 66 paint.setStyle(SkPaint::kStroke_Style); | 66 paint.setStyle(SkPaint::kStroke_Style); |
| 67 paint.setStrokeWidth(SkIntToScalar(SK_Scalar1)); | 67 paint.setStrokeWidth(SkIntToScalar(SK_Scalar1)); |
| 68 paint.setColor(stroke_color); | 68 paint.setColor(stroke_color); |
| 69 canvas->AsCanvasSkia()->drawRoundRect( | 69 canvas->GetSkCanvas()->drawRoundRect( |
| 70 rect, | 70 rect, |
| 71 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), | 71 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), |
| 72 paint); | 72 paint); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 static void DrawRoundedRectShadow( | 76 static void DrawRoundedRectShadow( |
| 77 gfx::Canvas* canvas, | 77 gfx::Canvas* canvas, |
| 78 int x, int y, | 78 int x, int y, |
| 79 int w, int h, | 79 int w, int h, |
| 80 int corner_radius, | 80 int corner_radius, |
| 81 int shadow, | 81 int shadow, |
| 82 SkColor color) { | 82 SkColor color) { |
| 83 SkPaint paint; | 83 SkPaint paint; |
| 84 paint.setFlags(SkPaint::kAntiAlias_Flag); | 84 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 85 paint.setStyle(SkPaint::kFill_Style); | 85 paint.setStyle(SkPaint::kFill_Style); |
| 86 paint.setColor(color); | 86 paint.setColor(color); |
| 87 SkMaskFilter* filter = SkBlurMaskFilter::Create( | 87 SkMaskFilter* filter = SkBlurMaskFilter::Create( |
| 88 shadow / 2, SkBlurMaskFilter::kNormal_BlurStyle); | 88 shadow / 2, SkBlurMaskFilter::kNormal_BlurStyle); |
| 89 paint.setMaskFilter(filter)->unref(); | 89 paint.setMaskFilter(filter)->unref(); |
| 90 SkRect rect; | 90 SkRect rect; |
| 91 rect.set( | 91 rect.set( |
| 92 SkIntToScalar(x + shadow / 2), SkIntToScalar(y + shadow / 2), | 92 SkIntToScalar(x + shadow / 2), SkIntToScalar(y + shadow / 2), |
| 93 SkIntToScalar(x + w - shadow / 2), SkIntToScalar(y + h - shadow / 2)); | 93 SkIntToScalar(x + w - shadow / 2), SkIntToScalar(y + h - shadow / 2)); |
| 94 canvas->AsCanvasSkia()->drawRoundRect( | 94 canvas->GetSkCanvas()->drawRoundRect( |
| 95 rect, | 95 rect, |
| 96 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), | 96 SkIntToScalar(corner_radius), SkIntToScalar(corner_radius), |
| 97 paint); | 97 paint); |
| 98 paint.setMaskFilter(NULL); | 98 paint.setMaskFilter(NULL); |
| 99 } | 99 } |
| 100 | 100 |
| 101 static void DrawRectWithBorder(int w, | 101 static void DrawRectWithBorder(int w, |
| 102 int h, | 102 int h, |
| 103 const BorderDefinition* const border, | 103 const BorderDefinition* const border, |
| 104 gfx::Canvas* canvas) { | 104 gfx::Canvas* canvas) { |
| 105 int padding = border->padding; | 105 int padding = border->padding; |
| 106 SkColor padding_color = border->padding_color; | 106 SkColor padding_color = border->padding_color; |
| 107 int shadow = border->shadow; | 107 int shadow = border->shadow; |
| 108 SkColor shadow_color = border->shadow_color; | 108 SkColor shadow_color = border->shadow_color; |
| 109 int corner_radius = border->corner_radius; | 109 int corner_radius = border->corner_radius; |
| 110 SkColor top_color = border->top_color; | 110 SkColor top_color = border->top_color; |
| 111 SkColor bottom_color = border->bottom_color; | 111 SkColor bottom_color = border->bottom_color; |
| 112 if (padding > 0) { | 112 if (padding > 0) { |
| 113 SkPaint paint; | 113 SkPaint paint; |
| 114 paint.setColor(padding_color); | 114 paint.setColor(padding_color); |
| 115 canvas->AsCanvasSkia()->drawRectCoords( | 115 canvas->GetSkCanvas()->drawRectCoords( |
| 116 SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(w), SkIntToScalar(h), | 116 SkIntToScalar(0), SkIntToScalar(0), SkIntToScalar(w), SkIntToScalar(h), |
| 117 paint); | 117 paint); |
| 118 } | 118 } |
| 119 if (border->shadow > 0) { | 119 if (border->shadow > 0) { |
| 120 DrawRoundedRectShadow( | 120 DrawRoundedRectShadow( |
| 121 canvas, | 121 canvas, |
| 122 padding, padding, | 122 padding, padding, |
| 123 w - 2 * padding, h - 2 * padding, | 123 w - 2 * padding, h - 2 * padding, |
| 124 corner_radius, | 124 corner_radius, |
| 125 shadow, shadow_color); | 125 shadow, shadow_color); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 rect.iset(0, 0, view->width(), view->height()); | 200 rect.iset(0, 0, view->width(), view->height()); |
| 201 SkPath path; | 201 SkPath path; |
| 202 path.addRoundRect(rect, | 202 path.addRoundRect(rect, |
| 203 SkIntToScalar(corner_radius_), | 203 SkIntToScalar(corner_radius_), |
| 204 SkIntToScalar(corner_radius_)); | 204 SkIntToScalar(corner_radius_)); |
| 205 // Draw interior. | 205 // Draw interior. |
| 206 SkPaint paint; | 206 SkPaint paint; |
| 207 paint.setStyle(SkPaint::kFill_Style); | 207 paint.setStyle(SkPaint::kFill_Style); |
| 208 paint.setFlags(SkPaint::kAntiAlias_Flag); | 208 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 209 paint.setColor(get_color()); | 209 paint.setColor(get_color()); |
| 210 canvas->AsCanvasSkia()->drawPath(path, paint); | 210 canvas->GetSkCanvas()->drawPath(path, paint); |
| 211 // Redraw boundary region with correspoinding color. | 211 // Redraw boundary region with correspoinding color. |
| 212 paint.setStyle(SkPaint::kStroke_Style); | 212 paint.setStyle(SkPaint::kStroke_Style); |
| 213 paint.setStrokeWidth(SkIntToScalar(stroke_width_)); | 213 paint.setStrokeWidth(SkIntToScalar(stroke_width_)); |
| 214 paint.setColor(stroke_color_); | 214 paint.setColor(stroke_color_); |
| 215 canvas->AsCanvasSkia()->drawPath(path, paint); | 215 canvas->GetSkCanvas()->drawPath(path, paint); |
| 216 } | 216 } |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 int corner_radius_; | 219 int corner_radius_; |
| 220 int stroke_width_; | 220 int stroke_width_; |
| 221 SkColor stroke_color_; | 221 SkColor stroke_color_; |
| 222 | 222 |
| 223 DISALLOW_COPY_AND_ASSIGN(RoundedBackground); | 223 DISALLOW_COPY_AND_ASSIGN(RoundedBackground); |
| 224 }; | 224 }; |
| 225 | 225 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 256 | 256 |
| 257 views::Background* CreateRoundedBackground(int corner_radius, | 257 views::Background* CreateRoundedBackground(int corner_radius, |
| 258 int stroke_width, | 258 int stroke_width, |
| 259 SkColor background_color, | 259 SkColor background_color, |
| 260 SkColor stroke_color) { | 260 SkColor stroke_color) { |
| 261 return new RoundedBackground( | 261 return new RoundedBackground( |
| 262 corner_radius, stroke_width, background_color, stroke_color); | 262 corner_radius, stroke_width, background_color, stroke_color); |
| 263 } | 263 } |
| 264 | 264 |
| 265 } // namespace chromeos | 265 } // namespace chromeos |
| OLD | NEW |