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

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

Issue 2475033003: Add ability to specify extra insets for a view via its border. (Closed)
Patch Set: restore lost changes Created 4 years, 1 month 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 | « 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 <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"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 } 130 }
131 131
132 gfx::Insets EmptyBorder::GetInsets() const { 132 gfx::Insets EmptyBorder::GetInsets() const {
133 return insets_; 133 return insets_;
134 } 134 }
135 135
136 gfx::Size EmptyBorder::GetMinimumSize() const { 136 gfx::Size EmptyBorder::GetMinimumSize() const {
137 return gfx::Size(); 137 return gfx::Size();
138 } 138 }
139 139
140 class ExtraInsetsBorder : public Border {
141 public:
142 ExtraInsetsBorder(std::unique_ptr<Border> border, const gfx::Insets& insets);
143
144 // Overridden from Border:
145 void Paint(const View& view, gfx::Canvas* canvas) override;
146 gfx::Insets GetInsets() const override;
147 gfx::Size GetMinimumSize() const override;
148
149 private:
150 std::unique_ptr<Border> border_;
151 const gfx::Insets extra_insets_;
152
153 DISALLOW_COPY_AND_ASSIGN(ExtraInsetsBorder);
154 };
155
156 ExtraInsetsBorder::ExtraInsetsBorder(std::unique_ptr<Border> border,
157 const gfx::Insets& insets)
158 : border_(std::move(border)), extra_insets_(insets) {}
159
160 void ExtraInsetsBorder::Paint(const View& view, gfx::Canvas* canvas) {
161 border_->Paint(view, canvas);
162 }
163
164 gfx::Insets ExtraInsetsBorder::GetInsets() const {
165 return border_->GetInsets() + extra_insets_;
166 }
167
168 gfx::Size ExtraInsetsBorder::GetMinimumSize() const {
169 gfx::Size size = border_->GetMinimumSize();
170 size.Enlarge(extra_insets_.width(), extra_insets_.height());
171 return size;
172 }
173
140 class BorderPainter : public Border { 174 class BorderPainter : public Border {
141 public: 175 public:
142 BorderPainter(std::unique_ptr<Painter> painter, const gfx::Insets& insets); 176 BorderPainter(std::unique_ptr<Painter> painter, const gfx::Insets& insets);
143 177
144 // Overridden from Border: 178 // Overridden from Border:
145 void Paint(const View& view, gfx::Canvas* canvas) override; 179 void Paint(const View& view, gfx::Canvas* canvas) override;
146 gfx::Insets GetInsets() const override; 180 gfx::Insets GetInsets() const override;
147 gfx::Size GetMinimumSize() const override; 181 gfx::Size GetMinimumSize() const override;
148 182
149 private: 183 private:
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 std::unique_ptr<Border> Border::CreateSolidSidedBorder(int top, 248 std::unique_ptr<Border> Border::CreateSolidSidedBorder(int top,
215 int left, 249 int left,
216 int bottom, 250 int bottom,
217 int right, 251 int right,
218 SkColor color) { 252 SkColor color) {
219 return base::MakeUnique<SolidSidedBorder>( 253 return base::MakeUnique<SolidSidedBorder>(
220 gfx::Insets(top, left, bottom, right), color); 254 gfx::Insets(top, left, bottom, right), color);
221 } 255 }
222 256
223 // static 257 // static
258 std::unique_ptr<Border> Border::CreatePaddedBorder(
259 std::unique_ptr<Border> border,
260 const gfx::Insets& insets) {
261 return base::MakeUnique<ExtraInsetsBorder>(std::move(border), insets);
262 }
263
264 // static
224 std::unique_ptr<Border> Border::CreateBorderPainter( 265 std::unique_ptr<Border> Border::CreateBorderPainter(
225 std::unique_ptr<Painter> painter, 266 std::unique_ptr<Painter> painter,
226 const gfx::Insets& insets) { 267 const gfx::Insets& insets) {
227 return base::WrapUnique(new BorderPainter(std::move(painter), insets)); 268 return base::WrapUnique(new BorderPainter(std::move(painter), insets));
228 } 269 }
229 270
230 } // namespace views 271 } // 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