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

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

Issue 2072513003: Fix StyledLabel so it doesn't clip the bottom of Hindi text. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move GetClassName Created 4 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
« no previous file with comments | « chrome/browser/ui/views/sync/bubble_sync_promo_view.cc ('k') | no next file » | 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 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
242 if (width <= 0 || text_.empty()) 242 if (width <= 0 || text_.empty())
243 return gfx::Size(); 243 return gfx::Size();
244 244
245 const int line_height = specified_line_height_ > 0 ? specified_line_height_ 245 const int line_height = specified_line_height_ > 0 ? specified_line_height_
246 : CalculateLineHeight(font_list_); 246 : CalculateLineHeight(font_list_);
247 // The index of the line we're on. 247 // The index of the line we're on.
248 int line = 0; 248 int line = 0;
249 // The x position (in pixels) of the line we're on, relative to content 249 // The x position (in pixels) of the line we're on, relative to content
250 // bounds. 250 // bounds.
251 int x = 0; 251 int x = 0;
252 int total_height = 0;
252 // The width that was actually used. Guaranteed to be no larger than |width|. 253 // The width that was actually used. Guaranteed to be no larger than |width|.
253 int used_width = 0; 254 int used_width = 0;
254 255
255 base::string16 remaining_string = text_; 256 base::string16 remaining_string = text_;
256 StyleRanges::const_iterator current_range = style_ranges_.begin(); 257 StyleRanges::const_iterator current_range = style_ranges_.begin();
257 258
258 // Iterate over the text, creating a bunch of labels and links and laying them 259 // Iterate over the text, creating a bunch of labels and links and laying them
259 // out in the appropriate positions. 260 // out in the appropriate positions.
260 while (!remaining_string.empty()) { 261 while (!remaining_string.empty()) {
261 // Don't put whitespace at beginning of a line with an exception for the 262 // Don't put whitespace at beginning of a line with an exception for the
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 343
343 if (displayed_on_background_color_set_) 344 if (displayed_on_background_color_set_)
344 label->SetBackgroundColor(displayed_on_background_color_); 345 label->SetBackgroundColor(displayed_on_background_color_);
345 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_); 346 label->SetAutoColorReadabilityEnabled(auto_color_readability_enabled_);
346 347
347 // Calculate the size of the optional focus border, and overlap by that 348 // Calculate the size of the optional focus border, and overlap by that
348 // amount. Otherwise, "<a>link</a>," will render as "link ,". 349 // amount. Otherwise, "<a>link</a>," will render as "link ,".
349 gfx::Insets focus_border_insets(label->GetInsets()); 350 gfx::Insets focus_border_insets(label->GetInsets());
350 focus_border_insets += -label->View::GetInsets(); 351 focus_border_insets += -label->View::GetInsets();
351 const gfx::Size view_size = label->GetPreferredSize(); 352 const gfx::Size view_size = label->GetPreferredSize();
352 if (!dry_run) { 353 label->SetBoundsRect(gfx::Rect(
353 label->SetBoundsRect(gfx::Rect( 354 gfx::Point(
354 gfx::Point(GetInsets().left() + x - focus_border_insets.left(), 355 GetInsets().left() + x - focus_border_insets.left(),
355 GetInsets().top() + line * line_height - 356 GetInsets().top() + line * line_height - focus_border_insets.top()),
356 focus_border_insets.top()), 357 view_size));
357 view_size));
358 AddChildView(label.release());
359 }
360 x += view_size.width() - focus_border_insets.width(); 358 x += view_size.width() - focus_border_insets.width();
361 used_width = std::max(used_width, x); 359 used_width = std::max(used_width, x);
360 total_height = std::max(total_height, label->bounds().bottom());
361 if (!dry_run)
362 AddChildView(label.release());
362 363
363 // If |gfx::ElideRectangleText| returned more than one substring, that 364 // If |gfx::ElideRectangleText| returned more than one substring, that
364 // means the whole text did not fit into remaining line width, with text 365 // means the whole text did not fit into remaining line width, with text
365 // after |susbtring[0]| spilling into next line. If whole |substring[0]| 366 // after |susbtring[0]| spilling into next line. If whole |substring[0]|
366 // was added to the current line (this may not be the case if part of the 367 // was added to the current line (this may not be the case if part of the
367 // substring has different style), proceed to the next line. 368 // substring has different style), proceed to the next line.
368 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) { 369 if (substrings.size() > 1 && chunk.size() == substrings[0].size()) {
369 x = 0; 370 x = 0;
370 ++line; 371 ++line;
371 } 372 }
372 373
373 remaining_string = remaining_string.substr(chunk.size()); 374 remaining_string = remaining_string.substr(chunk.size());
374 } 375 }
375 376
376 DCHECK_LE(used_width, width); 377 DCHECK_LE(used_width, width);
377 // The user-specified line height only applies to interline spacing, so the
378 // final line's height is unaffected.
379 int total_height = line * line_height +
380 CalculateLineHeight(font_list_) + GetInsets().height();
381 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height); 378 calculated_size_ = gfx::Size(used_width + GetInsets().width(), total_height);
382 return calculated_size_; 379 return calculated_size_;
383 } 380 }
384 381
385 } // namespace views 382 } // namespace views
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/sync/bubble_sync_promo_view.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698