| 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/border.h" | 5 #include "ui/views/border.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_flags.h" | 12 #include "cc/paint/paint_flags.h" |
| 13 #include "ui/compositor/dip_util.h" |
| 13 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/geometry/rect_f.h" | 15 #include "ui/gfx/geometry/rect_f.h" |
| 16 #include "ui/gfx/scoped_canvas.h" |
| 15 #include "ui/views/painter.h" | 17 #include "ui/views/painter.h" |
| 16 #include "ui/views/view.h" | 18 #include "ui/views/view.h" |
| 17 | 19 |
| 18 namespace views { | 20 namespace views { |
| 19 | 21 |
| 20 namespace { | 22 namespace { |
| 21 | 23 |
| 22 // A simple border with different thicknesses on each side and single color. | 24 // A simple border with different thicknesses on each side and single color. |
| 23 class SolidSidedBorder : public Border { | 25 class SolidSidedBorder : public Border { |
| 24 public: | 26 public: |
| (...skipping 10 matching lines...) Expand all Loading... |
| 35 | 37 |
| 36 DISALLOW_COPY_AND_ASSIGN(SolidSidedBorder); | 38 DISALLOW_COPY_AND_ASSIGN(SolidSidedBorder); |
| 37 }; | 39 }; |
| 38 | 40 |
| 39 SolidSidedBorder::SolidSidedBorder(const gfx::Insets& insets, SkColor color) | 41 SolidSidedBorder::SolidSidedBorder(const gfx::Insets& insets, SkColor color) |
| 40 : insets_(insets), | 42 : insets_(insets), |
| 41 color_(color) { | 43 color_(color) { |
| 42 } | 44 } |
| 43 | 45 |
| 44 void SolidSidedBorder::Paint(const View& view, gfx::Canvas* canvas) { | 46 void SolidSidedBorder::Paint(const View& view, gfx::Canvas* canvas) { |
| 45 // Top border. | 47 // Undo DSF so that we can be sure to draw an integral number of pixels for |
| 46 canvas->FillRect(gfx::Rect(0, 0, view.width(), insets_.top()), color_); | 48 // the border. Integral scale factors should be unaffected by this, but for |
| 47 // Left border. | 49 // fractional scale factors this ensures sharp lines. |
| 48 canvas->FillRect(gfx::Rect(0, insets_.top(), insets_.left(), | 50 gfx::ScopedCanvas scoped(canvas); |
| 49 view.height() - insets_.height()), color_); | 51 float dsf = canvas->UndoDeviceScaleFactor(); |
| 50 // Bottom border. | 52 |
| 51 canvas->FillRect(gfx::Rect(0, view.height() - insets_.bottom(), view.width(), | 53 gfx::RectF scaled_bounds; |
| 52 insets_.bottom()), color_); | 54 if (view.layer()) { |
| 53 // Right border. | 55 scaled_bounds = |
| 54 canvas->FillRect(gfx::Rect(view.width() - insets_.right(), insets_.top(), | 56 gfx::RectF(ui::ConvertRectToPixel(view.layer(), view.GetLocalBounds())); |
| 55 insets_.right(), view.height() - insets_.height()), | 57 } else { |
| 56 color_); | 58 scaled_bounds = gfx::RectF(view.GetLocalBounds()); |
| 59 scaled_bounds.Scale(dsf); |
| 60 } |
| 61 |
| 62 // This scaling operation floors the inset values. |
| 63 scaled_bounds.Inset(insets_.Scale(dsf)); |
| 64 canvas->sk_canvas()->clipRect(gfx::RectFToSkRect(scaled_bounds), |
| 65 SkClipOp::kDifference, true); |
| 66 canvas->DrawColor(color_); |
| 57 } | 67 } |
| 58 | 68 |
| 59 gfx::Insets SolidSidedBorder::GetInsets() const { | 69 gfx::Insets SolidSidedBorder::GetInsets() const { |
| 60 return insets_; | 70 return insets_; |
| 61 } | 71 } |
| 62 | 72 |
| 63 gfx::Size SolidSidedBorder::GetMinimumSize() const { | 73 gfx::Size SolidSidedBorder::GetMinimumSize() const { |
| 64 return gfx::Size(insets_.width(), insets_.height()); | 74 return gfx::Size(insets_.width(), insets_.height()); |
| 65 } | 75 } |
| 66 | 76 |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 const gfx::Insets& insets) { | 259 const gfx::Insets& insets) { |
| 250 return base::MakeUnique<ExtraInsetsBorder>(std::move(border), insets); | 260 return base::MakeUnique<ExtraInsetsBorder>(std::move(border), insets); |
| 251 } | 261 } |
| 252 | 262 |
| 253 std::unique_ptr<Border> CreateBorderPainter(std::unique_ptr<Painter> painter, | 263 std::unique_ptr<Border> CreateBorderPainter(std::unique_ptr<Painter> painter, |
| 254 const gfx::Insets& insets) { | 264 const gfx::Insets& insets) { |
| 255 return base::WrapUnique(new BorderPainter(std::move(painter), insets)); | 265 return base::WrapUnique(new BorderPainter(std::move(painter), insets)); |
| 256 } | 266 } |
| 257 | 267 |
| 258 } // namespace views | 268 } // namespace views |
| OLD | NEW |