Chromium Code Reviews| Index: ui/views/border.cc |
| diff --git a/ui/views/border.cc b/ui/views/border.cc |
| index 14e6d302e20de5e7955465510d7dfdbc2a6cccb9..8f5ddaa93fddc27057294b09a71e48895decb7f2 100644 |
| --- a/ui/views/border.cc |
| +++ b/ui/views/border.cc |
| @@ -12,6 +12,7 @@ |
| #include "cc/paint/paint_flags.h" |
| #include "ui/gfx/canvas.h" |
| #include "ui/gfx/geometry/rect_f.h" |
| +#include "ui/gfx/scoped_canvas.h" |
| #include "ui/views/painter.h" |
| #include "ui/views/view.h" |
| @@ -42,18 +43,23 @@ SolidSidedBorder::SolidSidedBorder(const gfx::Insets& insets, SkColor color) |
| } |
| void SolidSidedBorder::Paint(const View& view, gfx::Canvas* canvas) { |
| - // Top border. |
| - canvas->FillRect(gfx::Rect(0, 0, view.width(), insets_.top()), color_); |
| - // Left border. |
| - canvas->FillRect(gfx::Rect(0, insets_.top(), insets_.left(), |
| - view.height() - insets_.height()), color_); |
| - // Bottom border. |
| - canvas->FillRect(gfx::Rect(0, view.height() - insets_.bottom(), view.width(), |
| - insets_.bottom()), color_); |
| - // Right border. |
| - canvas->FillRect(gfx::Rect(view.width() - insets_.right(), insets_.top(), |
| - insets_.right(), view.height() - insets_.height()), |
| - color_); |
| + // Undo DSF so that we can be sure to draw an integral number of pixels for |
| + // the border. Integral scale factors should be unaffected by this, but for |
| + // fractional scale factors this ensures sharp lines. |
| + gfx::ScopedCanvas scoped(canvas); |
| + float dsf = canvas->UndoDeviceScaleFactor(); |
| + |
| + gfx::RectF bounds(view.GetLocalBounds()); |
| + bounds.Scale(dsf); |
| + // This scaling operation floors the inset values. |
| + bounds.Inset(insets_.Scale(dsf)); |
| + // If the view has a layer, it will be snapped to pixel bounds, giving the |
| + // canvas integral dimensions. Therefore we have to round up. Otherwise, no |
| + // rounding is necessary as the view's canvas won't be integral. |
| + if (view.layer()) |
| + bounds = gfx::RectF(gfx::ToEnclosingRect(bounds)); |
|
Peter Kasting
2017/02/18 00:08:28
Why ToEnclosingRect() and not ToEnclosedRect()? T
ericrk
2017/02/18 00:37:25
Agreed.
Interestingly, it appears that the view.l
|
| + canvas->ClipRect(bounds, SkClipOp::kDifference); |
| + canvas->DrawColor(color_); |
| } |
| gfx::Insets SolidSidedBorder::GetInsets() const { |