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

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

Issue 2722503005: Add bottom border to StyledLabel. (Closed)
Patch Set: Rebase, test added 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();
Evan Stade 2017/03/06 14:28:30 nit: why is this += - and not -=
dvadym 2017/03/06 15:45:36 Done.
357 const gfx::Size view_size = label->GetPreferredSize(); 357 const gfx::Size view_size = label->GetPreferredSize();
358 label->SetBoundsRect(gfx::Rect( 358 label->SetBoundsRect(gfx::Rect(
359 gfx::Point( 359 gfx::Point(
360 GetInsets().left() + x - focus_border_insets.left(), 360 GetInsets().left() + x - focus_border_insets.left(),
Evan Stade 2017/03/06 14:28:31 GetInsets() seems non-trivial, can we pull it into
dvadym 2017/03/06 15:45:36 Done.
361 GetInsets().top() + line * line_height - focus_border_insets.top()), 361 GetInsets().top() + line * line_height - focus_border_insets.top()),
362 view_size)); 362 view_size));
363 x += view_size.width() - focus_border_insets.width(); 363 x += view_size.width() - focus_border_insets.width();
364 used_width = std::max(used_width, x); 364 used_width = std::max(used_width, x);
365 total_height = std::max(total_height, label->bounds().bottom()); 365 total_height = std::max(total_height, label->bounds().bottom());
Evan Stade 2017/03/06 14:28:31 I think it's a little bit more clear if we add it
dvadym 2017/03/06 15:45:36 Done.
366 if (!dry_run) 366 if (!dry_run)
367 AddChildView(label.release()); 367 AddChildView(label.release());
368 368
369 // If |gfx::ElideRectangleText| returned more than one substring, that 369 // If |gfx::ElideRectangleText| returned more than one substring, that
370 // means the whole text did not fit into remaining line width, with text 370 // 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]| 371 // 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 372 // 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. 373 // substring has different style), proceed to the next line.
374 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) { 374 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) {
375 x = 0; 375 x = 0;
376 ++line; 376 ++line;
377 } 377 }
378 378
379 remaining_string = remaining_string.substr(chunk.size()); 379 remaining_string = remaining_string.substr(chunk.size());
380 } 380 }
381 381
382 DCHECK_LE(used_width, width); 382 DCHECK_LE(used_width, width);
383
384 // Add bottom border. Note that StyledLabel::GetInsets() returns StyledLabel
385 // border + in some cases border of labels and borders of labels are already
386 // taken into consideration in |total_height| calculation. So GetInsect() of
387 // the parent class should be used.
388 total_height += View::GetInsets().bottom();
389
383 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); 390 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height);
384 return calculated_size_; 391 return calculated_size_;
385 } 392 }
386 393
387 } // namespace views 394 } // 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