Chromium Code Reviews| Index: ui/gfx/render_text.h |
| diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h |
| index 6c094dcc36d51c6e29574aeedcedb47376a3a38c..5fb3865b6f60c7e6cda8655eea7716ca9dd7dcc7 100644 |
| --- a/ui/gfx/render_text.h |
| +++ b/ui/gfx/render_text.h |
| @@ -274,8 +274,6 @@ class GFX_EXPORT RenderText { |
| void SetElideBehavior(ElideBehavior elide_behavior); |
| ElideBehavior elide_behavior() const { return elide_behavior_; } |
| - const base::string16& layout_text() const { return layout_text_; } |
| - |
| const Rect& display_rect() const { return display_rect_; } |
| void SetDisplayRect(const Rect& r); |
| @@ -358,6 +356,11 @@ class GFX_EXPORT RenderText { |
| // |GetTextDirection()|, not the direction of a particular run. |
| VisualCursorDirection GetVisualDirectionOfLogicalEnd(); |
| + // Returns the text used for layout, which may be obscured, |
| + // truncated or elided. The subclass may compute elided text on the fly, |
| + // or use precomputed the elided text. |
| + virtual const base::string16& GetLayoutText() = 0; |
| + |
| // Returns the size required to display the current string (which is the |
| // wrapped size in multiline mode). The returned size does not include space |
| // reserved for the cursor or the offset text shadows. |
| @@ -448,6 +451,10 @@ class GFX_EXPORT RenderText { |
| protected: |
| RenderText(); |
| + const base::string16& layout_text() const { return layout_text_; } |
| + const base::string16& elided_text() const { return elided_text_; } |
| + bool text_elided() const { return text_elided_; } |
| + |
| const BreakList<SkColor>& colors() const { return colors_; } |
| const std::vector<BreakList<bool> >& styles() const { return styles_; } |
| @@ -515,14 +522,20 @@ class GFX_EXPORT RenderText { |
| // or bounds changes may invalidate returned values. |
| virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; |
| - // Convert between indices into |text_| and indices into |obscured_text_|, |
| - // which differ when the text is obscured. Regardless of whether or not the |
| - // text is obscured, the character (code point) offsets always match. |
| - virtual size_t TextIndexToLayoutIndex(size_t index) const = 0; |
| - virtual size_t LayoutIndexToTextIndex(size_t index) const = 0; |
| + // Convert between indices into |text_| and indices into |
| + // GetLayoutText(), which differ when the text is obscured, |
| + // truncated or elided. Regardless of whether or not the text is |
| + // obscured, the character (code point) offsets always match. |
| + virtual size_t TextIndexToLayoutIndex(size_t index) = 0; |
| + virtual size_t LayoutIndexToTextIndex(size_t index) = 0; |
| + |
| + // Notifies that layout text, or attributes that affects layout text |
| + // shape have changed. |text_changed| is true if the content of the |
| + // |layouttext_| has changed, not just attributes. |
|
msw
2015/02/12 22:45:06
nit: |layout_text_|
oshima
2015/02/13 00:29:43
Done.
|
| + virtual void OnLayoutTextShapeChanged(bool text_changed) = 0; |
| - // Reset the layout to be invalid. |
| - virtual void ResetLayout() = 0; |
| + // Notifies that attributes that affects elided text shape has changed. |
|
msw
2015/02/12 22:45:06
nit: s/affects/affect/ and s/has/have/
oshima
2015/02/13 00:29:43
Done.
|
| + virtual void OnElidedTextShapeChanged() = 0; |
| // Ensure the text is laid out, lines are computed, and |lines_| is valid. |
| virtual void EnsureLayout() = 0; |
| @@ -530,8 +543,8 @@ class GFX_EXPORT RenderText { |
| // Draw the text. |
| virtual void DrawVisualText(Canvas* canvas) = 0; |
| - // Returns the text used for layout, which may be obscured or truncated. |
| - const base::string16& GetLayoutText() const; |
| + // Update the elided text. |
| + void UpdateElidedText(float visual_width); |
| // Returns layout text positions that are suitable for breaking lines. |
| const BreakList<size_t>& GetLineBreaks(); |
| @@ -609,10 +622,14 @@ class GFX_EXPORT RenderText { |
| void MoveCursorTo(size_t position, bool select); |
| // Updates |layout_text_| if the text is obscured or truncated. |
| + // This will triggers |elided_text_| update. |
|
msw
2015/02/12 22:45:06
nit: merge the comments to something simpler, like
oshima
2015/02/13 00:29:43
Done.
|
| void UpdateLayoutText(); |
|
msw
2015/02/12 22:45:06
I like the pattern of On*Changed, and I could see
oshima
2015/02/13 00:29:43
Changed to OnTextAttributeChanged
|
| // Elides |text| as needed to fit in the |available_width| using |behavior|. |
| + // |text_width| is the pre-calculated width of the text shaped by this render |
| + // text, or pass 0 if the width is unknown. |
| base::string16 Elide(const base::string16& text, |
| + float text_width, |
| float available_width, |
| ElideBehavior behavior); |
| @@ -694,9 +711,14 @@ class GFX_EXPORT RenderText { |
| // The behavior for eliding, fading, or truncating. |
| ElideBehavior elide_behavior_; |
| - // The obscured and/or truncated text that will be displayed. |
| + // The obscured and/or truncated text, before elided. |
|
msw
2015/02/12 22:45:06
Rename this, it doesn't match the semantics of Get
oshima
2015/02/13 00:29:43
kept layout_text_ and changed elided_text_ to disp
|
| base::string16 layout_text_; |
| + // The elided text. This is empty if the text does not have to be elided. |
| + base::string16 elided_text_; |
|
msw
2015/02/12 22:45:06
nit: reorder |elide_behavior_| to come immediately
oshima
2015/02/13 00:29:43
Done.
|
| + |
| + bool text_elided_; |
|
msw
2015/02/12 22:45:06
nit: add a comment like "True if the text is elide
oshima
2015/02/13 00:29:43
Done.
|
| + |
| // Whether newline characters should be replaced with newline symbols. |
| bool replace_newline_chars_with_symbols_; |