| 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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 void DashedFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 114 void DashedFocusPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
| 115 gfx::Rect rect(size); | 115 gfx::Rect rect(size); |
| 116 rect.Inset(insets_); | 116 rect.Inset(insets_); |
| 117 canvas->DrawFocusRect(rect); | 117 canvas->DrawFocusRect(rect); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // SolidFocusPainter ----------------------------------------------------------- | 120 // SolidFocusPainter ----------------------------------------------------------- |
| 121 | 121 |
| 122 class SolidFocusPainter : public Painter { | 122 class SolidFocusPainter : public Painter { |
| 123 public: | 123 public: |
| 124 SolidFocusPainter(SkColor color, | 124 SolidFocusPainter(SkColor color, int thickness, const gfx::InsetsF& insets); |
| 125 SkScalar thickness, | |
| 126 const gfx::InsetsF& insets); | |
| 127 ~SolidFocusPainter() override; | 125 ~SolidFocusPainter() override; |
| 128 | 126 |
| 129 // Painter: | 127 // Painter: |
| 130 gfx::Size GetMinimumSize() const override; | 128 gfx::Size GetMinimumSize() const override; |
| 131 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override; | 129 void Paint(gfx::Canvas* canvas, const gfx::Size& size) override; |
| 132 | 130 |
| 133 private: | 131 private: |
| 134 const SkColor color_; | 132 const SkColor color_; |
| 135 const SkScalar thickness_; | 133 const int thickness_; |
| 136 const gfx::InsetsF insets_; | 134 const gfx::InsetsF insets_; |
| 137 | 135 |
| 138 DISALLOW_COPY_AND_ASSIGN(SolidFocusPainter); | 136 DISALLOW_COPY_AND_ASSIGN(SolidFocusPainter); |
| 139 }; | 137 }; |
| 140 | 138 |
| 141 SolidFocusPainter::SolidFocusPainter(SkColor color, | 139 SolidFocusPainter::SolidFocusPainter(SkColor color, |
| 142 SkScalar thickness, | 140 int thickness, |
| 143 const gfx::InsetsF& insets) | 141 const gfx::InsetsF& insets) |
| 144 : color_(color), thickness_(thickness), insets_(insets) {} | 142 : color_(color), thickness_(thickness), insets_(insets) {} |
| 145 | 143 |
| 146 SolidFocusPainter::~SolidFocusPainter() { | 144 SolidFocusPainter::~SolidFocusPainter() { |
| 147 } | 145 } |
| 148 | 146 |
| 149 gfx::Size SolidFocusPainter::GetMinimumSize() const { | 147 gfx::Size SolidFocusPainter::GetMinimumSize() const { |
| 150 return gfx::Size(); | 148 return gfx::Size(); |
| 151 } | 149 } |
| 152 | 150 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 | 347 |
| 350 // static | 348 // static |
| 351 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( | 349 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( |
| 352 SkColor color, | 350 SkColor color, |
| 353 const gfx::Insets& insets) { | 351 const gfx::Insets& insets) { |
| 354 // Before Canvas::DrawSolidFocusRect correctly inset the rect's bounds based | 352 // Before Canvas::DrawSolidFocusRect correctly inset the rect's bounds based |
| 355 // on the thickness, callers had to add 1 to the bottom and right insets. | 353 // on the thickness, callers had to add 1 to the bottom and right insets. |
| 356 // Subtract that here so it works the same way with the new | 354 // Subtract that here so it works the same way with the new |
| 357 // Canvas::DrawSolidFocusRect. | 355 // Canvas::DrawSolidFocusRect. |
| 358 const gfx::Insets corrected_insets = insets - gfx::Insets(0, 0, 1, 1); | 356 const gfx::Insets corrected_insets = insets - gfx::Insets(0, 0, 1, 1); |
| 359 return base::MakeUnique<SolidFocusPainter>(color, SkIntToScalar(1), | 357 return base::MakeUnique<SolidFocusPainter>(color, 1, corrected_insets); |
| 360 corrected_insets); | |
| 361 } | 358 } |
| 362 | 359 |
| 363 // static | 360 // static |
| 364 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( | 361 std::unique_ptr<Painter> Painter::CreateSolidFocusPainter( |
| 365 SkColor color, | 362 SkColor color, |
| 366 float thickness, | 363 int thickness, |
| 367 const gfx::InsetsF& insets) { | 364 const gfx::InsetsF& insets) { |
| 368 return base::MakeUnique<SolidFocusPainter>(color, SkFloatToScalar(thickness), | 365 return base::MakeUnique<SolidFocusPainter>(color, thickness, insets); |
| 369 insets); | |
| 370 } | 366 } |
| 371 | 367 |
| 372 // HorizontalPainter ---------------------------------------------------------- | 368 // HorizontalPainter ---------------------------------------------------------- |
| 373 | 369 |
| 374 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { | 370 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { |
| 375 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 371 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 376 for (int i = 0; i < 3; ++i) | 372 for (int i = 0; i < 3; ++i) |
| 377 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia(); | 373 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia(); |
| 378 DCHECK_EQ(images_[LEFT]->height(), images_[CENTER]->height()); | 374 DCHECK_EQ(images_[LEFT]->height(), images_[CENTER]->height()); |
| 379 DCHECK_EQ(images_[LEFT]->height(), images_[RIGHT]->height()); | 375 DCHECK_EQ(images_[LEFT]->height(), images_[RIGHT]->height()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 395 canvas->DrawImageInt(*images_[LEFT], 0, 0); | 391 canvas->DrawImageInt(*images_[LEFT], 0, 0); |
| 396 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), | 392 canvas->DrawImageInt(*images_[RIGHT], size.width() - images_[RIGHT]->width(), |
| 397 0); | 393 0); |
| 398 canvas->TileImageInt( | 394 canvas->TileImageInt( |
| 399 *images_[CENTER], images_[LEFT]->width(), 0, | 395 *images_[CENTER], images_[LEFT]->width(), 0, |
| 400 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), | 396 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), |
| 401 images_[LEFT]->height()); | 397 images_[LEFT]->height()); |
| 402 } | 398 } |
| 403 | 399 |
| 404 } // namespace views | 400 } // namespace views |
| OLD | NEW |