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

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

Issue 2722503005: Add bottom border to StyledLabel. (Closed)
Patch Set: Spacing fixed Created 3 years, 9 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
« no previous file with comments | « no previous file | ui/views/controls/styled_label_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <vector> 10 #include <vector>
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
346 label = CreateLabelRange(chunk, font_list_, default_style_info_, this); 346 label = CreateLabelRange(chunk, font_list_, default_style_info_, this);
347 } 347 }
348 348
349 if (displayed_on_background_color_set_) 349 if (displayed_on_background_color_set_)
350 label->SetBackgroundColor(displayed_on_background_color_); 350 label->SetBackgroundColor(displayed_on_background_color_);
351 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_); 351 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_);
352 352
353 // Calculate the size of the optional focus border, and overlap by that 353 // Calculate the size of the optional focus border, and overlap by that
354 // amount. Otherwise, "<a>link</a>," will render as "link ,". 354 // amount. Otherwise, "<a>link</a>," will render as "link ,".
355 gfx::Insets focus_border_insets(label->GetInsets()); 355 gfx::Insets focus_border_insets(label->GetInsets());
356 focus_border_insets += -label->View::GetInsets(); 356 focus_border_insets -= label->View::GetInsets();
357 const gfx::Size view_size = label->GetPreferredSize(); 357 const gfx::Size view_size = label->GetPreferredSize();
358 const gfx::Insets insets = GetInsets();
358 label->SetBoundsRect(gfx::Rect( 359 label->SetBoundsRect(gfx::Rect(
359 gfx::Point( 360 gfx::Point(
360 GetInsets().left() + x - focus_border_insets.left(), 361 insets.left() + x - focus_border_insets.left(),
361 GetInsets().top() + line * line_height - focus_border_insets.top()), 362 insets.top() + line * line_height - focus_border_insets.top()),
362 view_size)); 363 view_size));
363 x += view_size.width() - focus_border_insets.width(); 364 x += view_size.width() - focus_border_insets.width();
364 used_width = std::max(used_width, x); 365 used_width = std::max(used_width, x);
365 total_height = std::max(total_height, label->bounds().bottom()); 366 total_height =
367 std::max(total_height, label->bounds().bottom() + insets.bottom() -
368 focus_border_insets.bottom());
366 if (!dry_run) 369 if (!dry_run)
367 AddChildView(label.release()); 370 AddChildView(label.release());
368 371
369 // If |gfx::ElideRectangleText| returned more than one substring, that 372 // If |gfx::ElideRectangleText| returned more than one substring, that
370 // means the whole text did not fit into remaining line width, with text 373 // means the whole text did not fit into remaining line width, with text
371 // after |susbtring[0]| spilling into next line. If whole |substring[0]| 374 // after |susbtring[0]| spilling into next line. If whole |substring[0]|
372 // was added to the current line (this may not be the case if part of the 375 // was added to the current line (this may not be the case if part of the
373 // substring has different style), proceed to the next line. 376 // substring has different style), proceed to the next line.
374 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) { 377 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) {
375 x = 0; 378 x = 0;
376 ++line; 379 ++line;
377 } 380 }
378 381
379 remaining_string = remaining_string.substr(chunk.size()); 382 remaining_string = remaining_string.substr(chunk.size());
380 } 383 }
381 384
382 DCHECK_LE(used_width, width); 385 DCHECK_LE(used_width, width);
383 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); 386 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height);
384 return calculated_size_; 387 return calculated_size_;
385 } 388 }
386 389
387 } // namespace views 390 } // namespace views
OLDNEW
« no previous file with comments | « no previous file | ui/views/controls/styled_label_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698