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

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

Issue 10909234: views: Delete painter pointer using scoped_ptr. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nits Created 8 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/border.h ('k') | 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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/memory/scoped_ptr.h"
8 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
9 #include "ui/views/painter.h" 10 #include "ui/views/painter.h"
10 11
11 namespace views { 12 namespace views {
12 13
13 namespace { 14 namespace {
14 15
15 // A simple border with different thicknesses on each side and single color. 16 // A simple border with different thicknesses on each side and single color.
16 class SidedSolidBorder : public Border { 17 class SidedSolidBorder : public Border {
17 public: 18 public:
18 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color); 19 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color);
19 20
20 // Overridden from Border: 21 // Overridden from Border:
21 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE; 22 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE;
22 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE; 23 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE;
23 24
24 private: 25 private:
25 int top_, left_, bottom_, right_; 26 const int top_;
27 const int left_;
28 const int bottom_;
29 const int right_;
26 SkColor color_; 30 SkColor color_;
27 gfx::Insets insets_; 31 gfx::Insets insets_;
28 32
29 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder); 33 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder);
30 }; 34 };
31 35
32 SidedSolidBorder::SidedSolidBorder(int top, int left, int bottom, int right, 36 SidedSolidBorder::SidedSolidBorder(int top,
33 SkColor color) 37 int left,
38 int bottom,
39 int right,
40 SkColor color)
34 : top_(top), 41 : top_(top),
35 left_(left), 42 left_(left),
36 bottom_(bottom), 43 bottom_(bottom),
37 right_(right), 44 right_(right),
38 color_(color), 45 color_(color),
39 insets_(top, left, bottom, right) { 46 insets_(top, left, bottom, right) {
40 } 47 }
41 48
42 void SidedSolidBorder::Paint(const View& view, gfx::Canvas* canvas) const { 49 void SidedSolidBorder::Paint(const View& view, gfx::Canvas* canvas) const {
43 // Top border. 50 // Top border.
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 DISALLOW_COPY_AND_ASSIGN(EmptyBorder); 97 DISALLOW_COPY_AND_ASSIGN(EmptyBorder);
91 }; 98 };
92 99
93 class BorderPainter : public Border { 100 class BorderPainter : public Border {
94 public: 101 public:
95 explicit BorderPainter(Painter* painter) 102 explicit BorderPainter(Painter* painter)
96 : painter_(painter) { 103 : painter_(painter) {
97 DCHECK(painter); 104 DCHECK(painter);
98 } 105 }
99 106
100 virtual ~BorderPainter() { 107 virtual ~BorderPainter() {}
101 delete painter_;
102 painter_ = NULL;
103 }
104 108
105 // Overridden from Border: 109 // Overridden from Border:
106 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE { 110 virtual void Paint(const View& view, gfx::Canvas* canvas) const OVERRIDE {
107 Painter::PaintPainterAt(canvas, painter_, view.GetLocalBounds()); 111 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds());
108 } 112 }
109 113
110 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE { 114 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE {
111 DCHECK(insets); 115 DCHECK(insets);
112 insets->Set(0, 0, 0, 0); 116 insets->Set(0, 0, 0, 0);
113 } 117 }
114 118
115 private: 119 private:
116 Painter* painter_; 120 scoped_ptr<Painter> painter_;
117 121
118 DISALLOW_COPY_AND_ASSIGN(BorderPainter); 122 DISALLOW_COPY_AND_ASSIGN(BorderPainter);
119 }; 123 };
120 124
121 } // namespace 125 } // namespace
122 126
123 Border::Border() { 127 Border::Border() {
124 } 128 }
125 129
126 Border::~Border() { 130 Border::~Border() {
127 } 131 }
128 132
129 // static 133 // static
130 Border* Border::CreateSolidBorder(int thickness, SkColor color) { 134 Border* Border::CreateSolidBorder(int thickness, SkColor color) {
131 return new SolidBorder(thickness, color); 135 return new SolidBorder(thickness, color);
132 } 136 }
133 137
134 // static 138 // static
135 Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) { 139 Border* Border::CreateEmptyBorder(int top, int left, int bottom, int right) {
136 return new EmptyBorder(top, left, bottom, right); 140 return new EmptyBorder(top, left, bottom, right);
137 } 141 }
138 142
139 // static 143 // static
140 Border* Border::CreateSolidSidedBorder(int top, int left, 144 Border* Border::CreateSolidSidedBorder(int top,
141 int bottom, int right, 145 int left,
142 SkColor color) { 146 int bottom,
147 int right,
148 SkColor color) {
143 return new SidedSolidBorder(top, left, bottom, right, color); 149 return new SidedSolidBorder(top, left, bottom, right, color);
144 } 150 }
145 151
146 //static 152 // static
147 Border* Border::CreateBorderPainter(Painter* painter) { 153 Border* Border::CreateBorderPainter(Painter* painter) {
148 return new BorderPainter(painter); 154 return new BorderPainter(painter);
149 } 155 }
150 156
151 } // namespace views 157 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/border.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698