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

Side by Side Diff: ui/views/controls/styled_label.cc

Issue 342833002: [Password Generation] Update Aura UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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
OLDNEW
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/strings/string_util.h" 9 #include "base/strings/string_util.h"
10 #include "ui/gfx/font_list.h" 10 #include "ui/gfx/font_list.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 bool StyledLabel::StyleRange::operator<( 87 bool StyledLabel::StyleRange::operator<(
88 const StyledLabel::StyleRange& other) const { 88 const StyledLabel::StyleRange& other) const {
89 return range.start() < other.range.start(); 89 return range.start() < other.range.start();
90 } 90 }
91 91
92 92
93 // StyledLabel ---------------------------------------------------------------- 93 // StyledLabel ----------------------------------------------------------------
94 94
95 StyledLabel::StyledLabel(const base::string16& text, 95 StyledLabel::StyledLabel(const base::string16& text,
96 StyledLabelListener* listener) 96 StyledLabelListener* listener)
97 : listener_(listener), 97 : interline_spacing_(0),
98 listener_(listener),
98 displayed_on_background_color_set_(false), 99 displayed_on_background_color_set_(false),
99 auto_color_readability_enabled_(true) { 100 auto_color_readability_enabled_(true) {
100 base::TrimWhitespace(text, base::TRIM_TRAILING, &text_); 101 base::TrimWhitespace(text, base::TRIM_TRAILING, &text_);
101 } 102 }
102 103
103 StyledLabel::~StyledLabel() {} 104 StyledLabel::~StyledLabel() {}
104 105
105 void StyledLabel::SetText(const base::string16& text) { 106 void StyledLabel::SetText(const base::string16& text) {
106 text_ = text; 107 text_ = text;
107 style_ranges_.clear(); 108 style_ranges_.clear();
(...skipping 18 matching lines...) Expand all
126 style_ranges_.merge(new_range); 127 style_ranges_.merge(new_range);
127 128
128 PreferredSizeChanged(); 129 PreferredSizeChanged();
129 } 130 }
130 131
131 void StyledLabel::SetDefaultStyle(const RangeStyleInfo& style_info) { 132 void StyledLabel::SetDefaultStyle(const RangeStyleInfo& style_info) {
132 default_style_info_ = style_info; 133 default_style_info_ = style_info;
133 PreferredSizeChanged(); 134 PreferredSizeChanged();
134 } 135 }
135 136
137 void StyledLabel::SetInterlineSpacing(int interline_spacing) {
138 interline_spacing_ = interline_spacing;
139 PreferredSizeChanged();
140 }
141
136 void StyledLabel::SetDisplayedOnBackgroundColor(SkColor color) { 142 void StyledLabel::SetDisplayedOnBackgroundColor(SkColor color) {
137 displayed_on_background_color_ = color; 143 displayed_on_background_color_ = color;
138 displayed_on_background_color_set_ = true; 144 displayed_on_background_color_set_ = true;
139 } 145 }
140 146
141 gfx::Insets StyledLabel::GetInsets() const { 147 gfx::Insets StyledLabel::GetInsets() const {
142 gfx::Insets insets = View::GetInsets(); 148 gfx::Insets insets = View::GetInsets();
143 149
144 // We need a focus border iff we contain a link that will have a focus border. 150 // We need a focus border iff we contain a link that will have a focus border.
145 // That in turn will be true only if the link is non-empty. 151 // That in turn will be true only if the link is non-empty.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { 192 gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
187 if (!dry_run) { 193 if (!dry_run) {
188 RemoveAllChildViews(true); 194 RemoveAllChildViews(true);
189 link_targets_.clear(); 195 link_targets_.clear();
190 } 196 }
191 197
192 width -= GetInsets().width(); 198 width -= GetInsets().width();
193 if (width <= 0 || text_.empty()) 199 if (width <= 0 || text_.empty())
194 return gfx::Size(); 200 return gfx::Size();
195 201
196 const int line_height = CalculateLineHeight(font_list_); 202 const int line_height = CalculateLineHeight(font_list_) + interline_spacing_;
197 // The index of the line we're on. 203 // The index of the line we're on.
198 int line = 0; 204 int line = 0;
199 // The x position (in pixels) of the line we're on, relative to content 205 // The x position (in pixels) of the line we're on, relative to content
200 // bounds. 206 // bounds.
201 int x = 0; 207 int x = 0;
202 208
203 base::string16 remaining_string = text_; 209 base::string16 remaining_string = text_;
204 StyleRanges::const_iterator current_range = style_ranges_.begin(); 210 StyleRanges::const_iterator current_range = style_ranges_.begin();
205 211
206 // Iterate over the text, creating a bunch of labels and links and laying them 212 // Iterate over the text, creating a bunch of labels and links and laying them
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 294
289 if (displayed_on_background_color_set_) 295 if (displayed_on_background_color_set_)
290 label->SetBackgroundColor(displayed_on_background_color_); 296 label->SetBackgroundColor(displayed_on_background_color_);
291 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_); 297 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_);
292 298
293 // Calculate the size of the optional focus border, and overlap by that 299 // Calculate the size of the optional focus border, and overlap by that
294 // amount. Otherwise, "<a>link</a>," will render as "link ,". 300 // amount. Otherwise, "<a>link</a>," will render as "link ,".
295 gfx::Insets focus_border_insets(label->GetInsets()); 301 gfx::Insets focus_border_insets(label->GetInsets());
296 focus_border_insets += -label->View::GetInsets(); 302 focus_border_insets += -label->View::GetInsets();
297 const gfx::Size view_size = label->GetPreferredSize(); 303 const gfx::Size view_size = label->GetPreferredSize();
298 DCHECK_EQ(line_height, view_size.height() - focus_border_insets.height()); 304 DCHECK_EQ(line_height - interline_spacing_,
305 view_size.height() - focus_border_insets.height());
299 if (!dry_run) { 306 if (!dry_run) {
300 label->SetBoundsRect(gfx::Rect( 307 label->SetBoundsRect(gfx::Rect(
301 gfx::Point(GetInsets().left() + x - focus_border_insets.left(), 308 gfx::Point(GetInsets().left() + x - focus_border_insets.left(),
302 GetInsets().top() + line * line_height - 309 GetInsets().top() + line * line_height -
Evan Stade 2014/06/19 00:16:36 I have a feeling setting a taller line height ough
Garrett Casto 2014/06/20 23:47:01 It actually doesn't affect the position of the fir
Evan Stade 2014/06/23 18:20:40 Right, it doesn't, but it ought to. CSS line-heigh
Garrett Casto 2014/06/24 01:15:12 Ah, so you want the text to be centered in the lin
Evan Stade 2014/06/24 21:16:58 this^. It's what CSS does, and CSS is a mature lib
303 focus_border_insets.top()), 310 focus_border_insets.top()),
304 view_size)); 311 view_size));
305 AddChildView(label.release()); 312 AddChildView(label.release());
306 } 313 }
307 x += view_size.width() - focus_border_insets.width(); 314 x += view_size.width() - focus_border_insets.width();
308 315
309 remaining_string = remaining_string.substr(chunk.size()); 316 remaining_string = remaining_string.substr(chunk.size());
310 } 317 }
311 318
312 return gfx::Size(width, (line + 1) * line_height + GetInsets().height()); 319 return gfx::Size(width, (line + 1) * line_height + GetInsets().height());
313 } 320 }
314 321
315 } // namespace views 322 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698