Index: ui/gfx/text_elider.cc |
diff --git a/ui/gfx/text_elider.cc b/ui/gfx/text_elider.cc |
index 279e5cb3be87ff3142647f3f3ab5d15fde476f97..5ec7593362851cf92cfbc18db905d975418c3b5d 100644 |
--- a/ui/gfx/text_elider.cc |
+++ b/ui/gfx/text_elider.cc |
@@ -482,7 +482,8 @@ class RectangleText { |
last_line_ended_in_lf_(false), |
lines_(lines), |
insufficient_width_(false), |
- insufficient_height_(false) {} |
+ insufficient_height_(false), |
+ max_broken_pixel_width_(0) {} |
// Perform deferred initializions following creation. Must be called |
// before any input can be added via AddString(). |
@@ -500,6 +501,10 @@ class RectangleText { |
// insufficient, leading to elision or truncation. |
int Finalize(); |
+ // Returns maximum width of those lines which were broken after some words to |
+ // fit |available_pixel_width_|. |
+ float GetMaxBrokenPixelWidth() const { return max_broken_pixel_width_; } |
Alexei Svitkine (slow)
2014/10/06 17:59:58
Nit: This should just be max_broken_pixel_width()
Roman Sorokin (ftl)
2014/10/07 09:21:53
Done.
|
+ |
private: |
// Add a line to the rectangular region at the current position, |
// either by itself or by breaking it into words. |
@@ -562,6 +567,10 @@ class RectangleText { |
// Indicates whether there were too many lines for the available height. |
bool insufficient_height_; |
+ // Maximum width of those lines which were broken after some words to |
+ // fit |available_pixel_width_|. |
+ float max_broken_pixel_width_; |
+ |
DISALLOW_COPY_AND_ASSIGN(RectangleText); |
}; |
@@ -691,6 +700,8 @@ int RectangleText::AddWord(const base::string16& word) { |
// Word can be made to fit, no need to fragment it. |
if ((current_width_ + trimmed_width > available_pixel_width_) && NewLine()) |
lines_added++; |
+ max_broken_pixel_width_ = |
+ std::max(max_broken_pixel_width_, current_width_ + trimmed_width); |
// Append the non-trimmed word, in case more words are added after. |
AddToCurrentLine(word); |
} else { |
@@ -744,7 +755,8 @@ int ElideRectangleText(const base::string16& input, |
float available_pixel_width, |
int available_pixel_height, |
WordWrapBehavior wrap_behavior, |
- std::vector<base::string16>* lines) { |
+ std::vector<base::string16>* lines, |
+ float* max_broken_pixel_width) { |
RectangleText rect(font_list, |
available_pixel_width, |
available_pixel_height, |
@@ -752,6 +764,8 @@ int ElideRectangleText(const base::string16& input, |
lines); |
rect.Init(); |
rect.AddString(input); |
+ if (max_broken_pixel_width) |
+ *max_broken_pixel_width = rect.GetMaxBrokenPixelWidth(); |
return rect.Finalize(); |
} |