Chromium Code Reviews| Index: ui/views/controls/styled_label.h |
| diff --git a/ui/views/controls/styled_label.h b/ui/views/controls/styled_label.h |
| index adbd7a99ba27cdab3d83074ecdb1dc57b8765faf..0be1d9907caca524867c2e195c311227f8a7e353 100644 |
| --- a/ui/views/controls/styled_label.h |
| +++ b/ui/views/controls/styled_label.h |
| @@ -90,8 +90,17 @@ class VIEWS_EXPORT StyledLabel : public View, public LinkListener { |
| auto_color_readability_enabled_ = auto_color_readability; |
| } |
| + // Resizes the label so its width is set to the width of the longest line and |
| + // its height deduced accordingly. |
| + // This is only intended for multi-line labels and is useful when the label's |
| + // text contains several lines separated with \n. |
| + // |max_width| is the maximum width that will be used (longer lines will be |
| + // wrapped). If 0, no maximum width is enforced. |
| + void SizeToFit(int max_width); |
|
sky
2015/01/20 16:24:36
Isn't this the same as:
SetSize(gfx::Size(max_wid
Ilya Sherman
2015/01/22 02:26:27
Not quite. SizeToFit will never size to a width g
|
| + |
| // View implementation: |
| gfx::Insets GetInsets() const override; |
| + gfx::Size GetPreferredSize() const override; |
| int GetHeightForWidth(int w) const override; |
| void Layout() override; |
| void PreferredSizeChanged() override; |
| @@ -115,10 +124,11 @@ class VIEWS_EXPORT StyledLabel : public View, public LinkListener { |
| }; |
| typedef std::list<StyleRange> StyleRanges; |
| - // Calculates how to layout child views, creates them and sets their size |
| - // and position. |width| is the horizontal space, in pixels, that the view |
| - // has to work with. If |dry_run| is true, the view hierarchy is not touched. |
| - // The return value is the necessary size. |
| + // Calculates how to layout child views, creates them and sets their size and |
| + // position. |width| is the horizontal space, in pixels, that the view has to |
| + // work with. If |dry_run| is true, the view hierarchy is not touched. Caches |
| + // the results in |calculated_size_|, |width_at_last_layout_|, and |
| + // |width_at_last_size_calculation_|. Returns the needed size. |
| gfx::Size CalculateAndDoLayout(int width, bool dry_run); |
| // The text to display. |
| @@ -147,6 +157,7 @@ class VIEWS_EXPORT StyledLabel : public View, public LinkListener { |
| // This variable saves the result of the last GetHeightForWidth call in order |
| // to avoid repeated calculation. |
| mutable gfx::Size calculated_size_; |
| + mutable int width_at_last_size_calculation_; |
| int width_at_last_layout_; |
| // Background color on which the label is drawn, for auto color readability. |