| 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 "third_party/skia/include/effects/SkGradientShader.h" | 12 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 13 #include "third_party/skia/include/pathops/SkPathOps.h" | 13 #include "third_party/skia/include/pathops/SkPathOps.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/geometry/insets.h" | 16 #include "ui/gfx/geometry/insets.h" |
| 17 #include "ui/gfx/geometry/insets_f.h" |
| 17 #include "ui/gfx/geometry/point.h" | 18 #include "ui/gfx/geometry/point.h" |
| 18 #include "ui/gfx/geometry/rect_f.h" | 19 #include "ui/gfx/geometry/rect_f.h" |
| 19 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| 20 #include "ui/gfx/geometry/size_f.h" | 21 #include "ui/gfx/geometry/size_f.h" |
| 21 #include "ui/gfx/image/image.h" | 22 #include "ui/gfx/image/image.h" |
| 22 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image_skia.h" |
| 23 #include "ui/gfx/image/image_skia_operations.h" | 24 #include "ui/gfx/image/image_skia_operations.h" |
| 24 #include "ui/gfx/nine_image_painter.h" | 25 #include "ui/gfx/nine_image_painter.h" |
| 25 #include "ui/gfx/scoped_canvas.h" | 26 #include "ui/gfx/scoped_canvas.h" |
| 26 #include "ui/views/view.h" | 27 #include "ui/views/view.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 void DashedFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 113 void DashedFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
| 113 gfx::Rect rect(size); | 114 gfx::Rect rect(size); |
| 114 rect.Inset(insets_); | 115 rect.Inset(insets_); |
| 115 canvas->DrawFocusRect(rect); | 116 canvas->DrawFocusRect(rect); |
| 116 } | 117 } |
| 117 | 118 |
| 118 // SolidFocusPainter ----------------------------------------------------------- | 119 // SolidFocusPainter ----------------------------------------------------------- |
| 119 | 120 |
| 120 class SolidFocusPainter : public Painter { | 121 class SolidFocusPainter : public Painter { |
| 121 public: | 122 public: |
| 122 SolidFocusPainter(SkColor color, const gfx::Insets& insets); | 123 SolidFocusPainter(SkColor color, |
| 124 SkScalar thickness, |
| 125 const gfx::InsetsF& insets); |
| 123 ~SolidFocusPainter() override; | 126 ~SolidFocusPainter() override; |
| 124 | 127 |
| 125 // Painter: | 128 // Painter: |
| 126 gfx::Size GetMinimumSize() const override; | 129 gfx::Size GetMinimumSize() const override; |
| 127 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override; | 130 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override; |
| 128 | 131 |
| 129 private: | 132 private: |
| 130 const SkColor color_; | 133 const SkColor color_; |
| 131 const gfx::Insets insets_; | 134 const SkScalar thickness_; |
| 135 const gfx::InsetsF insets_; |
| 132 | 136 |
| 133 DISALLOW_COPY_AND_ASSIGN(SolidFocusPainter); | 137 DISALLOW_COPY_AND_ASSIGN(SolidFocusPainter); |
| 134 }; | 138 }; |
| 135 | 139 |
| 136 SolidFocusPainter::SolidFocusPainter(SkColor color, | 140 SolidFocusPainter::SolidFocusPainter(SkColor color, |
| 137 const gfx::Insets& insets) | 141 SkScalar thickness, |
| 138 : color_(color), | 142 const gfx::InsetsF& insets) |
| 139 insets_(insets) { | 143 : color_(color), thickness_(thickness), insets_(insets) {} |
| 140 } | |
| 141 | 144 |
| 142 SolidFocusPainter::~SolidFocusPainter() { | 145 SolidFocusPainter::~SolidFocusPainter() { |
| 143 } | 146 } |
| 144 | 147 |
| 145 gfx::Size SolidFocusPainter::GetMinimumSize() const { | 148 gfx::Size SolidFocusPainter::GetMinimumSize() const { |
| 146 return gfx::Size(); | 149 return gfx::Size(); |
| 147 } | 150 } |
| 148 | 151 |
| 149 void SolidFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 152 void SolidFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
| 150 gfx::Rect rect(size); | 153 gfx::RectF rect((gfx::Rect(size))); |
| 151 rect.Inset(insets_); | 154 rect.Inset(insets_); |
| 152 canvas->DrawSolidFocusRect(rect, color_); | 155 canvas->DrawSolidFocusRect(rect, color_, thickness_); |
| 153 } | 156 } |
| 154 | 157 |
| 155 // GradientPainter ------------------------------------------------------------ | 158 // GradientPainter ------------------------------------------------------------ |
| 156 | 159 |
| 157 class GradientPainter : public Painter { | 160 class GradientPainter : public Painter { |
| 158 public: | 161 public: |
| 159 GradientPainter(bool horizontal, | 162 GradientPainter(bool horizontal, |
| 160 SkColor* colors, | 163 SkColor* colors, |
| 161 SkScalar* pos, | 164 SkScalar* pos, |
| 162 size_t count); | 165 size_t count); |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 // static | 352 // static |
| 350 std::unique_ptr<Painter> Painter::CreateDashedFocusPainterWithInsets( | 353 std::unique_ptr<Painter> Painter::CreateDashedFocusPainterWithInsets( |
| 351 const gfx::Insets& insets) { | 354 const gfx::Insets& insets) { |
| 352 return base::MakeUnique<DashedFocusPainter>(insets); | 355 return base::MakeUnique<DashedFocusPainter>(insets); |
| 353 } | 356 } |
| 354 | 357 |
| 355 // static | 358 // static |
| 356 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( | 359 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( |
| 357 SkColor color, | 360 SkColor color, |
| 358 const gfx::Insets& insets) { | 361 const gfx::Insets& insets) { |
| 359 return base::MakeUnique<SolidFocusPainter>(color, insets); | 362 // Before Canvas::DrawSolidFocusRect correctly inset the rect's bounds based |
| 363 // on the thickness, callers had to add 1 to the bottom and right insets. |
| 364 // Subtract that here so it works the same way with the new |
| 365 // Canvas::DrawSolidFocusRect. |
| 366 const gfx::Insets corrected_insets = insets - gfx::Insets(0, 0, 1, 1); |
| 367 return base::MakeUnique<SolidFocusPainter>(color, SkIntToScalar(1), |
| 368 corrected_insets); |
| 369 } |
| 370 |
| 371 // static |
| 372 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( |
| 373 SkColor color, |
| 374 float thickness, |
| 375 const gfx::InsetsF& insets) { |
| 376 return base::MakeUnique<SolidFocusPainter>(color, SkFloatToScalar(thickness), |
| 377 insets); |
| 360 } | 378 } |
| 361 | 379 |
| 362 // HorizontalPainter ---------------------------------------------------------- | 380 // HorizontalPainter ---------------------------------------------------------- |
| 363 | 381 |
| 364 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { | 382 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { |
| 365 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 383 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 366 for (int i = 0; i < 3; ++i) | 384 for (int i = 0; i < 3; ++i) |
| 367 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia(); | 385 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia(); |
| 368 DCHECK_EQ(images_[LEFT]->height(), images_[CENTER]->height()); | 386 DCHECK_EQ(images_[LEFT]->height(), images_[CENTER]->height()); |
| 369 DCHECK_EQ(images_[LEFT]->height(), images_[RIGHT]->height()); | 387 DCHECK_EQ(images_[LEFT]->height(), images_[RIGHT]->height()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 385 canvas->DrawImageInt(*images_[LEFT], 0, 0); | 403 canvas->DrawImageInt(*images_[LEFT], 0, 0); |
| 386 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), | 404 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), |
| 387 0); | 405 0); |
| 388 canvas->TileImageInt( | 406 canvas->TileImageInt( |
| 389 *images_[CENTER], images_[LEFT]->width(), 0, | 407 *images_[CENTER], images_[LEFT]->width(), 0, |
| 390 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), | 408 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), |
| 391 images_[LEFT]->height()); | 409 images_[LEFT]->height()); |
| 392 } | 410 } |
| 393 | 411 |
| 394 } // namespace views | 412 } // namespace views |
| OLD | NEW |