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/views/painter.h" | 5 #include "ui/views/painter.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "cc/paint/paint_shader.h" |
12 #include "third_party/skia/include/effects/SkGradientShader.h" | 13 #include "third_party/skia/include/effects/SkGradientShader.h" |
13 #include "third_party/skia/include/pathops/SkPathOps.h" | 14 #include "third_party/skia/include/pathops/SkPathOps.h" |
14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
16 #include "ui/gfx/geometry/insets.h" | 17 #include "ui/gfx/geometry/insets.h" |
17 #include "ui/gfx/geometry/insets_f.h" | 18 #include "ui/gfx/geometry/insets_f.h" |
18 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
19 #include "ui/gfx/geometry/rect_f.h" | 20 #include "ui/gfx/geometry/rect_f.h" |
20 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
21 #include "ui/gfx/geometry/size_f.h" | 22 #include "ui/gfx/geometry/size_f.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 return gfx::Size(); | 63 return gfx::Size(); |
63 } | 64 } |
64 | 65 |
65 void SolidRoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 66 void SolidRoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
66 gfx::ScopedCanvas scoped_canvas(canvas); | 67 gfx::ScopedCanvas scoped_canvas(canvas); |
67 const float scale = canvas->UndoDeviceScaleFactor(); | 68 const float scale = canvas->UndoDeviceScaleFactor(); |
68 | 69 |
69 gfx::RectF border_rect_f(gfx::ScaleToEnclosingRect(gfx::Rect(size), scale)); | 70 gfx::RectF border_rect_f(gfx::ScaleToEnclosingRect(gfx::Rect(size), scale)); |
70 const SkScalar scaled_corner_radius = SkFloatToScalar(radius_ * scale); | 71 const SkScalar scaled_corner_radius = SkFloatToScalar(radius_ * scale); |
71 | 72 |
72 SkPaint paint; | 73 cc::PaintFlags paint; |
73 paint.setAntiAlias(true); | 74 paint.setAntiAlias(true); |
74 paint.setStyle(SkPaint::kFill_Style); | 75 paint.setStyle(cc::PaintFlags::kFill_Style); |
75 paint.setColor(bg_color_); | 76 paint.setColor(bg_color_); |
76 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, paint); | 77 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, paint); |
77 | 78 |
78 border_rect_f.Inset(gfx::InsetsF(0.5f)); | 79 border_rect_f.Inset(gfx::InsetsF(0.5f)); |
79 paint.setStyle(SkPaint::kStroke_Style); | 80 paint.setStyle(cc::PaintFlags::kStroke_Style); |
80 paint.setStrokeWidth(1); | 81 paint.setStrokeWidth(1); |
81 paint.setColor(stroke_color_); | 82 paint.setColor(stroke_color_); |
82 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, paint); | 83 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, paint); |
83 } | 84 } |
84 | 85 |
85 // DashedFocusPainter ---------------------------------------------------------- | 86 // DashedFocusPainter ---------------------------------------------------------- |
86 | 87 |
87 class DashedFocusPainter : public Painter { | 88 class DashedFocusPainter : public Painter { |
88 public: | 89 public: |
89 explicit DashedFocusPainter(const gfx::Insets& insets); | 90 explicit DashedFocusPainter(const gfx::Insets& insets); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 198 } |
198 | 199 |
199 GradientPainter::~GradientPainter() { | 200 GradientPainter::~GradientPainter() { |
200 } | 201 } |
201 | 202 |
202 gfx::Size GradientPainter::GetMinimumSize() const { | 203 gfx::Size GradientPainter::GetMinimumSize() const { |
203 return gfx::Size(); | 204 return gfx::Size(); |
204 } | 205 } |
205 | 206 |
206 void GradientPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 207 void GradientPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
207 SkPaint paint; | 208 cc::PaintFlags paint; |
208 SkPoint p[2]; | 209 SkPoint p[2]; |
209 p[0].iset(0, 0); | 210 p[0].iset(0, 0); |
210 if (horizontal_) | 211 if (horizontal_) |
211 p[1].iset(size.width(), 0); | 212 p[1].iset(size.width(), 0); |
212 else | 213 else |
213 p[1].iset(0, size.height()); | 214 p[1].iset(0, size.height()); |
214 | 215 |
215 paint.setShader(SkGradientShader::MakeLinear( | 216 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( |
216 p, colors_.get(), pos_.get(), count_, SkShader::kClamp_TileMode)); | 217 p, colors_.get(), pos_.get(), count_, SkShader::kClamp_TileMode))); |
217 paint.setStyle(SkPaint::kFill_Style); | 218 paint.setStyle(cc::PaintFlags::kFill_Style); |
218 | 219 |
219 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), | 220 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
220 SkIntToScalar(size.width()), | 221 SkIntToScalar(size.width()), |
221 SkIntToScalar(size.height()), paint); | 222 SkIntToScalar(size.height()), paint); |
222 } | 223 } |
223 | 224 |
224 // ImagePainter --------------------------------------------------------------- | 225 // ImagePainter --------------------------------------------------------------- |
225 | 226 |
226 // ImagePainter stores and paints nine images as a scalable grid. | 227 // ImagePainter stores and paints nine images as a scalable grid. |
227 class ImagePainter : public Painter { | 228 class ImagePainter : public Painter { |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 canvas->DrawImageInt(*images_[LEFT], 0, 0); | 395 canvas->DrawImageInt(*images_[LEFT], 0, 0); |
395 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), | 396 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), |
396 0); | 397 0); |
397 canvas->TileImageInt( | 398 canvas->TileImageInt( |
398 *images_[CENTER], images_[LEFT]->width(), 0, | 399 *images_[CENTER], images_[LEFT]->width(), 0, |
399 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), | 400 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), |
400 images_[LEFT]->height()); | 401 images_[LEFT]->height()); |
401 } | 402 } |
402 | 403 |
403 } // namespace views | 404 } // namespace views |
OLD | NEW |