OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/controls/styled_label.h" | 5 #include "ui/views/controls/styled_label.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "ui/base/text/text_elider.h" | 10 #include "ui/base/text/text_elider.h" |
(...skipping 28 matching lines...) Expand all Loading... | |
39 | 39 |
40 void StyledLabel::AddLink(const ui::Range& range) { | 40 void StyledLabel::AddLink(const ui::Range& range) { |
41 DCHECK(!range.is_reversed()); | 41 DCHECK(!range.is_reversed()); |
42 DCHECK(!range.is_empty()); | 42 DCHECK(!range.is_empty()); |
43 DCHECK(ui::Range(0, text_.size()).Contains(range)); | 43 DCHECK(ui::Range(0, text_.size()).Contains(range)); |
44 link_ranges_.push(LinkRange(range)); | 44 link_ranges_.push(LinkRange(range)); |
45 calculated_size_ = gfx::Size(); | 45 calculated_size_ = gfx::Size(); |
46 InvalidateLayout(); | 46 InvalidateLayout(); |
47 } | 47 } |
48 | 48 |
49 void StyledLabel::SizeToFit(int width) { | |
sky
2013/03/18 19:32:39
I'm not a fan of this method, it's too easy to use
tbarzic
2013/03/18 20:40:03
ok, removed
| |
50 SetBounds(x(), y(), width, GetHeightForWidth(width)); | |
51 InvalidateLayout(); | |
52 } | |
53 | |
49 gfx::Insets StyledLabel::GetInsets() const { | 54 gfx::Insets StyledLabel::GetInsets() const { |
50 gfx::Insets insets = View::GetInsets(); | 55 gfx::Insets insets = View::GetInsets(); |
51 const gfx::Insets focus_border_padding(1, 1, 1, 1); | 56 const gfx::Insets focus_border_padding(1, 1, 1, 1); |
52 insets += focus_border_padding; | 57 insets += focus_border_padding; |
53 return insets; | 58 return insets; |
54 } | 59 } |
55 | 60 |
61 gfx::Size StyledLabel::GetPreferredSize() { | |
62 return gfx::Size(width(), GetHeightForWidth(width())); | |
sky
2013/03/18 19:32:39
This isn't right. If you need the preferred size f
tbarzic
2013/03/18 20:40:03
Done.
| |
63 } | |
64 | |
56 int StyledLabel::GetHeightForWidth(int w) { | 65 int StyledLabel::GetHeightForWidth(int w) { |
57 if (w != calculated_size_.width()) | 66 if (w != calculated_size_.width()) |
58 calculated_size_ = gfx::Size(w, CalculateAndDoLayout(w, true)); | 67 calculated_size_ = gfx::Size(w, CalculateAndDoLayout(w, true)); |
59 | 68 |
60 return calculated_size_.height(); | 69 return calculated_size_.height(); |
61 } | 70 } |
62 | 71 |
63 void StyledLabel::Layout() { | 72 void StyledLabel::Layout() { |
64 CalculateAndDoLayout(GetLocalBounds().width(), false); | 73 CalculateAndDoLayout(GetLocalBounds().width(), false); |
65 } | 74 } |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 } | 173 } |
165 x += view_size.width() - 2 * overlap; | 174 x += view_size.width() - 2 * overlap; |
166 | 175 |
167 remaining_string = remaining_string.substr(chunk.size()); | 176 remaining_string = remaining_string.substr(chunk.size()); |
168 } | 177 } |
169 | 178 |
170 return (line + 1) * line_height + GetInsets().height(); | 179 return (line + 1) * line_height + GetInsets().height(); |
171 } | 180 } |
172 | 181 |
173 } // namespace views | 182 } // namespace views |
OLD | NEW |