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

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

Issue 82483003: Add GetMinimumSize() for Borders, and make LabelButton auto-size to at least as (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years 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
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 "base/memory/scoped_ptr.h"
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/views/painter.h" 10 #include "ui/views/painter.h"
11 11
12 namespace views { 12 namespace views {
13 13
14 namespace { 14 namespace {
15 15
16 // 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.
17 class SidedSolidBorder : public Border { 17 class SidedSolidBorder : public Border {
18 public: 18 public:
19 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color); 19 SidedSolidBorder(int top, int left, int bottom, int right, SkColor color);
20 20
21 // Overridden from Border: 21 // Overridden from Border:
22 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE; 22 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE;
23 virtual gfx::Insets GetInsets() const OVERRIDE; 23 virtual gfx::Insets GetInsets() const OVERRIDE;
24 virtual gfx::Size GetMinimumSize() const OVERRIDE;
24 25
25 private: 26 private:
26 const SkColor color_; 27 const SkColor color_;
27 const gfx::Insets insets_; 28 const gfx::Insets insets_;
28 29
29 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder); 30 DISALLOW_COPY_AND_ASSIGN(SidedSolidBorder);
30 }; 31 };
31 32
32 SidedSolidBorder::SidedSolidBorder(int top, 33 SidedSolidBorder::SidedSolidBorder(int top,
33 int left, 34 int left,
(...skipping 14 matching lines...) Expand all
48 insets_.bottom()), color_); 49 insets_.bottom()), color_);
49 // Right border. 50 // Right border.
50 canvas->FillRect(gfx::Rect(view.width() - insets_.right(), 0, insets_.right(), 51 canvas->FillRect(gfx::Rect(view.width() - insets_.right(), 0, insets_.right(),
51 view.height()), color_); 52 view.height()), color_);
52 } 53 }
53 54
54 gfx::Insets SidedSolidBorder::GetInsets() const { 55 gfx::Insets SidedSolidBorder::GetInsets() const {
55 return insets_; 56 return insets_;
56 } 57 }
57 58
59 gfx::Size SidedSolidBorder::GetMinimumSize() const {
60 return gfx::Size(insets_.width(), insets_.height());
61 }
62
58 // A variation of SidedSolidBorder, where each side has the same thickness. 63 // A variation of SidedSolidBorder, where each side has the same thickness.
59 class SolidBorder : public SidedSolidBorder { 64 class SolidBorder : public SidedSolidBorder {
60 public: 65 public:
61 SolidBorder(int thickness, SkColor color) 66 SolidBorder(int thickness, SkColor color)
62 : SidedSolidBorder(thickness, thickness, thickness, thickness, color) { 67 : SidedSolidBorder(thickness, thickness, thickness, thickness, color) {
63 } 68 }
64 69
65 private: 70 private:
66 DISALLOW_COPY_AND_ASSIGN(SolidBorder); 71 DISALLOW_COPY_AND_ASSIGN(SolidBorder);
67 }; 72 };
68 73
69 class EmptyBorder : public Border { 74 class EmptyBorder : public Border {
70 public: 75 public:
71 EmptyBorder(int top, int left, int bottom, int right) 76 EmptyBorder(int top, int left, int bottom, int right)
72 : insets_(top, left, bottom, right) {} 77 : insets_(top, left, bottom, right) {}
73 78
74 // Overridden from Border: 79 // Overridden from Border:
75 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE {} 80 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE {}
76 81
77 virtual gfx::Insets GetInsets() const OVERRIDE { 82 virtual gfx::Insets GetInsets() const OVERRIDE {
78 return insets_; 83 return insets_;
79 } 84 }
80 85
86 virtual gfx::Size GetMinimumSize() const OVERRIDE {
87 return gfx::Size();
msw 2013/11/22 18:00:25 nit: shouldn't this match the insets? Empty means
Peter Kasting 2013/11/22 22:07:55 As noted previously, GetMinimumSize() should only
88 }
89
81 private: 90 private:
82 const gfx::Insets insets_; 91 const gfx::Insets insets_;
83 92
84 DISALLOW_COPY_AND_ASSIGN(EmptyBorder); 93 DISALLOW_COPY_AND_ASSIGN(EmptyBorder);
85 }; 94 };
86 95
87 class BorderPainter : public Border { 96 class BorderPainter : public Border {
88 public: 97 public:
89 explicit BorderPainter(Painter* painter, const gfx::Insets& insets) 98 explicit BorderPainter(Painter* painter, const gfx::Insets& insets)
90 : painter_(painter), 99 : painter_(painter),
91 insets_(insets) { 100 insets_(insets) {
92 DCHECK(painter); 101 DCHECK(painter);
93 } 102 }
94 103
95 virtual ~BorderPainter() {} 104 virtual ~BorderPainter() {}
96 105
97 // Overridden from Border: 106 // Overridden from Border:
98 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE { 107 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE {
99 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds()); 108 Painter::PaintPainterAt(canvas, painter_.get(), view.GetLocalBounds());
100 } 109 }
101 110
102 virtual gfx::Insets GetInsets() const OVERRIDE { 111 virtual gfx::Insets GetInsets() const OVERRIDE {
103 return insets_; 112 return insets_;
104 } 113 }
105 114
115 virtual gfx::Size GetMinimumSize() const OVERRIDE {
116 return painter_->GetMinimumSize();
117 }
118
106 private: 119 private:
107 scoped_ptr<Painter> painter_; 120 scoped_ptr<Painter> painter_;
108 const gfx::Insets insets_; 121 const gfx::Insets insets_;
109 122
110 DISALLOW_COPY_AND_ASSIGN(BorderPainter); 123 DISALLOW_COPY_AND_ASSIGN(BorderPainter);
111 }; 124 };
112 125
113 } // namespace 126 } // namespace
114 127
115 Border::Border() { 128 Border::Border() {
(...skipping 29 matching lines...) Expand all
145 158
146 TextButtonBorder* Border::AsTextButtonBorder() { 159 TextButtonBorder* Border::AsTextButtonBorder() {
147 return NULL; 160 return NULL;
148 } 161 }
149 162
150 const TextButtonBorder* Border::AsTextButtonBorder() const { 163 const TextButtonBorder* Border::AsTextButtonBorder() const {
151 return NULL; 164 return NULL;
152 } 165 }
153 166
154 } // namespace views 167 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698