Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Unified Diff: ui/views/border.cc

Issue 2694933002: Fix appearance of task manager border at fractional scale factors. (Closed)
Patch Set: tests Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | ui/views/border_unittest.cc » ('j') | ui/views/border_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/border.cc
diff --git a/ui/views/border.cc b/ui/views/border.cc
index 14e6d302e20de5e7955465510d7dfdbc2a6cccb9..61b3b4a399423e1cf52c3f433597cb8493fe33de 100644
--- a/ui/views/border.cc
+++ b/ui/views/border.cc
@@ -10,8 +10,10 @@
#include "base/macros.h"
#include "base/memory/ptr_util.h"
#include "cc/paint/paint_flags.h"
+#include "ui/compositor/dip_util.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 +44,26 @@ 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 scaled_bounds;
+ if (view.layer()) {
+ scaled_bounds =
+ gfx::RectF(ui::ConvertRectToPixel(view.layer(), view.GetLocalBounds()));
+ } else {
+ scaled_bounds = gfx::RectF(view.GetLocalBounds());
+ scaled_bounds.Scale(dsf);
+ }
+
+ // This scaling operation floors the inset values.
+ scaled_bounds.Inset(insets_.Scale(dsf));
+ canvas->sk_canvas()->clipRect(gfx::RectFToSkRect(scaled_bounds),
+ SkClipOp::kDifference, true);
+ canvas->DrawColor(color_);
}
gfx::Insets SolidSidedBorder::GetInsets() const {
« no previous file with comments | « no previous file | ui/views/border_unittest.cc » ('j') | ui/views/border_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698