| Index: ui/gfx/text_elider.cc
|
| diff --git a/ui/gfx/text_elider.cc b/ui/gfx/text_elider.cc
|
| index 279e5cb3be87ff3142647f3f3ab5d15fde476f97..1eff364ed5c6115106e6e33a33c6daaac58b9d71 100644
|
| --- a/ui/gfx/text_elider.cc
|
| +++ b/ui/gfx/text_elider.cc
|
| @@ -477,7 +477,6 @@ class RectangleText {
|
| available_pixel_width_(available_pixel_width),
|
| available_pixel_height_(available_pixel_height),
|
| wrap_behavior_(wrap_behavior),
|
| - current_width_(0),
|
| current_height_(0),
|
| last_line_ended_in_lf_(false),
|
| lines_(lines),
|
| @@ -514,11 +513,6 @@ class RectangleText {
|
| // Add a word to the rectangluar region at the current position.
|
| int AddWord(const base::string16& word);
|
|
|
| - // Append the specified |text| to the current output line, incrementing the
|
| - // running width by the specified amount. This is an optimization over
|
| - // |AddToCurrentLine()| when |text_width| is already known.
|
| - void AddToCurrentLineWithWidth(const base::string16& text, float text_width);
|
| -
|
| // Append the specified |text| to the current output line.
|
| void AddToCurrentLine(const base::string16& text);
|
|
|
| @@ -540,9 +534,6 @@ class RectangleText {
|
| // The wrap behavior for words that are too long to fit on a single line.
|
| const WordWrapBehavior wrap_behavior_;
|
|
|
| - // The current running width.
|
| - float current_width_;
|
| -
|
| // The current running height.
|
| int current_height_;
|
|
|
| @@ -601,7 +592,7 @@ int RectangleText::Finalize() {
|
| void RectangleText::AddLine(const base::string16& line) {
|
| const float line_width = GetStringWidthF(line, font_list_);
|
| if (line_width <= available_pixel_width_) {
|
| - AddToCurrentLineWithWidth(line, line_width);
|
| + AddToCurrentLine(line);
|
| } else {
|
| // Iterate over positions that are valid to break the line at. In general,
|
| // these are word boundaries but after any punctuation following the word.
|
| @@ -621,7 +612,6 @@ void RectangleText::AddLine(const base::string16& line) {
|
| }
|
| if (base::ContainsOnlyChars(word, base::kWhitespaceUTF16)) {
|
| // Skip the first space if the previous line was carried over.
|
| - current_width_ = 0;
|
| current_line_.clear();
|
| }
|
| }
|
| @@ -667,7 +657,6 @@ int RectangleText::AddWordOverflow(const base::string16& word) {
|
|
|
| if (wrap_behavior_ == IGNORE_LONG_WORDS) {
|
| current_line_ = word;
|
| - current_width_ = available_pixel_width_;
|
| } else if (wrap_behavior_ == WRAP_LONG_WORDS) {
|
| lines_added += WrapWord(word);
|
| } else {
|
| @@ -689,7 +678,13 @@ int RectangleText::AddWord(const base::string16& word) {
|
| const float trimmed_width = GetStringWidthF(trimmed, font_list_);
|
| if (trimmed_width <= available_pixel_width_) {
|
| // Word can be made to fit, no need to fragment it.
|
| - if ((current_width_ + trimmed_width > available_pixel_width_) && NewLine())
|
| + base::string16 line_with_new_word(current_line_);
|
| + line_with_new_word.append(trimmed);
|
| + float new_width = GetStringWidthF(line_with_new_word, font_list_);
|
| + // We can't just add trimmed_width to current_width and compare it to
|
| + // available_pixel_width. Sometimes sum of widths of two strings is not
|
| + // equal to width of concatenation of these strings (see crbug.com/415213).
|
| + if ((new_width > available_pixel_width_) && NewLine())
|
| lines_added++;
|
| // Append the non-trimmed word, in case more words are added after.
|
| AddToCurrentLine(word);
|
| @@ -701,17 +696,11 @@ int RectangleText::AddWord(const base::string16& word) {
|
| }
|
|
|
| void RectangleText::AddToCurrentLine(const base::string16& text) {
|
| - AddToCurrentLineWithWidth(text, GetStringWidthF(text, font_list_));
|
| -}
|
| -
|
| -void RectangleText::AddToCurrentLineWithWidth(const base::string16& text,
|
| - float text_width) {
|
| if (current_height_ >= available_pixel_height_) {
|
| insufficient_height_ = true;
|
| return;
|
| }
|
| current_line_.append(text);
|
| - current_width_ += text_width;
|
| }
|
|
|
| bool RectangleText::NewLine() {
|
| @@ -724,7 +713,6 @@ bool RectangleText::NewLine() {
|
| insufficient_height_ = true;
|
| }
|
| current_height_ += line_height_;
|
| - current_width_ = 0;
|
| return line_added;
|
| }
|
|
|
|
|