| 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" |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 return gfx::Size(); | 63 return gfx::Size(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 void SolidRoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 66 void SolidRoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
| 67 gfx::ScopedCanvas scoped_canvas(canvas); | 67 gfx::ScopedCanvas scoped_canvas(canvas); |
| 68 const float scale = canvas->UndoDeviceScaleFactor(); | 68 const float scale = canvas->UndoDeviceScaleFactor(); |
| 69 | 69 |
| 70 gfx::RectF border_rect_f(gfx::ScaleToEnclosingRect(gfx::Rect(size), scale)); | 70 gfx::RectF border_rect_f(gfx::ScaleToEnclosingRect(gfx::Rect(size), scale)); |
| 71 const SkScalar scaled_corner_radius = SkFloatToScalar(radius_ * scale); | 71 const SkScalar scaled_corner_radius = SkFloatToScalar(radius_ * scale); |
| 72 | 72 |
| 73 cc::PaintFlags paint; | 73 cc::PaintFlags flags; |
| 74 paint.setAntiAlias(true); | 74 flags.setAntiAlias(true); |
| 75 paint.setStyle(cc::PaintFlags::kFill_Style); | 75 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 76 paint.setColor(bg_color_); | 76 flags.setColor(bg_color_); |
| 77 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, paint); | 77 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, flags); |
| 78 | 78 |
| 79 border_rect_f.Inset(gfx::InsetsF(0.5f)); | 79 border_rect_f.Inset(gfx::InsetsF(0.5f)); |
| 80 paint.setStyle(cc::PaintFlags::kStroke_Style); | 80 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 81 paint.setStrokeWidth(1); | 81 flags.setStrokeWidth(1); |
| 82 paint.setColor(stroke_color_); | 82 flags.setColor(stroke_color_); |
| 83 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, paint); | 83 canvas->DrawRoundRect(border_rect_f, scaled_corner_radius, flags); |
| 84 } | 84 } |
| 85 | 85 |
| 86 // DashedFocusPainter ---------------------------------------------------------- | 86 // DashedFocusPainter ---------------------------------------------------------- |
| 87 | 87 |
| 88 class DashedFocusPainter : public Painter { | 88 class DashedFocusPainter : public Painter { |
| 89 public: | 89 public: |
| 90 explicit DashedFocusPainter(const gfx::Insets& insets); | 90 explicit DashedFocusPainter(const gfx::Insets& insets); |
| 91 ~DashedFocusPainter() override; | 91 ~DashedFocusPainter() override; |
| 92 | 92 |
| 93 // Painter: | 93 // Painter: |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 } | 198 } |
| 199 | 199 |
| 200 GradientPainter::~GradientPainter() { | 200 GradientPainter::~GradientPainter() { |
| 201 } | 201 } |
| 202 | 202 |
| 203 gfx::Size GradientPainter::GetMinimumSize() const { | 203 gfx::Size GradientPainter::GetMinimumSize() const { |
| 204 return gfx::Size(); | 204 return gfx::Size(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void GradientPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 207 void GradientPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
| 208 cc::PaintFlags paint; | 208 cc::PaintFlags flags; |
| 209 SkPoint p[2]; | 209 SkPoint p[2]; |
| 210 p[0].iset(0, 0); | 210 p[0].iset(0, 0); |
| 211 if (horizontal_) | 211 if (horizontal_) |
| 212 p[1].iset(size.width(), 0); | 212 p[1].iset(size.width(), 0); |
| 213 else | 213 else |
| 214 p[1].iset(0, size.height()); | 214 p[1].iset(0, size.height()); |
| 215 | 215 |
| 216 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( | 216 flags.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( |
| 217 p, colors_.get(), pos_.get(), count_, SkShader::kClamp_TileMode))); | 217 p, colors_.get(), pos_.get(), count_, SkShader::kClamp_TileMode))); |
| 218 paint.setStyle(cc::PaintFlags::kFill_Style); | 218 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 219 | 219 |
| 220 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), | 220 canvas->sk_canvas()->drawRectCoords(SkIntToScalar(0), SkIntToScalar(0), |
| 221 SkIntToScalar(size.width()), | 221 SkIntToScalar(size.width()), |
| 222 SkIntToScalar(size.height()), paint); | 222 SkIntToScalar(size.height()), flags); |
| 223 } | 223 } |
| 224 | 224 |
| 225 // ImagePainter --------------------------------------------------------------- | 225 // ImagePainter --------------------------------------------------------------- |
| 226 | 226 |
| 227 // ImagePainter stores and paints nine images as a scalable grid. | 227 // ImagePainter stores and paints nine images as a scalable grid. |
| 228 class ImagePainter : public Painter { | 228 class ImagePainter : public Painter { |
| 229 public: | 229 public: |
| 230 // Constructs an ImagePainter with the specified image resource ids. | 230 // Constructs an ImagePainter with the specified image resource ids. |
| 231 // See CreateImageGridPainter()'s comment regarding image ID count and order. | 231 // See CreateImageGridPainter()'s comment regarding image ID count and order. |
| 232 explicit ImagePainter(const int image_ids[]); | 232 explicit ImagePainter(const int image_ids[]); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 canvas->DrawImageInt(*images_[LEFT], 0, 0); | 395 canvas->DrawImageInt(*images_[LEFT], 0, 0); |
| 396 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), | 396 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), |
| 397 0); | 397 0); |
| 398 canvas->TileImageInt( | 398 canvas->TileImageInt( |
| 399 *images_[CENTER], images_[LEFT]->width(), 0, | 399 *images_[CENTER], images_[LEFT]->width(), 0, |
| 400 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), | 400 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), |
| 401 images_[LEFT]->height()); | 401 images_[LEFT]->height()); |
| 402 } | 402 } |
| 403 | 403 |
| 404 } // namespace views | 404 } // namespace views |
| OLD | NEW |