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

Side by Side Diff: ui/views/border.cc

Issue 2694933002: Fix appearance of task manager border at fractional scale factors. (Closed)
Patch Set: inline 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/geometry/rect_f.h" 14 #include "ui/gfx/geometry/rect_f.h"
15 #include "ui/gfx/scoped_canvas.h"
15 #include "ui/views/painter.h" 16 #include "ui/views/painter.h"
16 #include "ui/views/view.h" 17 #include "ui/views/view.h"
17 18
18 namespace views { 19 namespace views {
19 20
20 namespace { 21 namespace {
21 22
22 // A simple border with different thicknesses on each side and single color. 23 // A simple border with different thicknesses on each side and single color.
23 class SolidSidedBorder : public Border { 24 class SolidSidedBorder : public Border {
24 public: 25 public:
(...skipping 10 matching lines...) Expand all
35 36
36 DISALLOW_COPY_AND_ASSIGN(SolidSidedBorder); 37 DISALLOW_COPY_AND_ASSIGN(SolidSidedBorder);
37 }; 38 };
38 39
39 SolidSidedBorder::SolidSidedBorder(const gfx::Insets& insets, SkColor color) 40 SolidSidedBorder::SolidSidedBorder(const gfx::Insets& insets, SkColor color)
40 : insets_(insets), 41 : insets_(insets),
41 color_(color) { 42 color_(color) {
42 } 43 }
43 44
44 void SolidSidedBorder::Paint(const View& view, gfx::Canvas* canvas) { 45 void SolidSidedBorder::Paint(const View& view, gfx::Canvas* canvas) {
45 // Top border. 46 // 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_); 47 // the border. Integral scale factors should be unaffected by this, but for
47 // Left border. 48 // fractional scale factors this ensures sharp lines.
48 canvas->FillRect(gfx::Rect(0, insets_.top(), insets_.left(), 49 gfx::ScopedCanvas scoped(canvas);
49 view.height() - insets_.height()), color_); 50 float dsf = canvas->UndoDeviceScaleFactor();
50 // Bottom border. 51
51 canvas->FillRect(gfx::Rect(0, view.height() - insets_.bottom(), view.width(), 52 gfx::RectF bounds(view.GetLocalBounds());
Peter Kasting 2017/02/17 02:40:15 Nit: Prefer = to () for this (see https://www.chro
Evan Stade 2017/02/17 06:19:55 For rectf from rect you have to use the constructo
Peter Kasting 2017/02/17 07:13:19 Oh, I didn't even see that you were converting int
52 insets_.bottom()), color_); 53 bounds.Scale(dsf);
53 // Right border. 54 // This scaling operation floors the inset values.
54 canvas->FillRect(gfx::Rect(view.width() - insets_.right(), insets_.top(), 55 bounds.Inset(insets_.Scale(dsf));
55 insets_.right(), view.height() - insets_.height()), 56 canvas->ClipRect(bounds, SkClipOp::kDifference);
56 color_); 57 canvas->DrawColor(color_);
57 } 58 }
58 59
59 gfx::Insets SolidSidedBorder::GetInsets() const { 60 gfx::Insets SolidSidedBorder::GetInsets() const {
60 return insets_; 61 return insets_;
61 } 62 }
62 63
63 gfx::Size SolidSidedBorder::GetMinimumSize() const { 64 gfx::Size SolidSidedBorder::GetMinimumSize() const {
64 return gfx::Size(insets_.width(), insets_.height()); 65 return gfx::Size(insets_.width(), insets_.height());
65 } 66 }
66 67
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 const gfx::Insets& insets) { 250 const gfx::Insets& insets) {
250 return base::MakeUnique<ExtraInsetsBorder>(std::move(border), insets); 251 return base::MakeUnique<ExtraInsetsBorder>(std::move(border), insets);
251 } 252 }
252 253
253 std::unique_ptr<Border> CreateBorderPainter(std::unique_ptr<Painter> painter, 254 std::unique_ptr<Border> CreateBorderPainter(std::unique_ptr<Painter> painter,
254 const gfx::Insets& insets) { 255 const gfx::Insets& insets) {
255 return base::WrapUnique(new BorderPainter(std::move(painter), insets)); 256 return base::WrapUnique(new BorderPainter(std::move(painter), insets));
256 } 257 }
257 258
258 } // namespace views 259 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698