Chromium Code Reviews| Index: ui/gfx/render_text.h |
| diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h |
| index 34277400b7369e28c41e120950e357555c8c9415..95664c812ad10df73c1a1883df12404b6767655e 100644 |
| --- a/ui/gfx/render_text.h |
| +++ b/ui/gfx/render_text.h |
| @@ -111,6 +111,40 @@ class StyleIterator { |
| DISALLOW_COPY_AND_ASSIGN(StyleIterator); |
| }; |
| +// Line segments are slices of the layout text to be rendered on a single line. |
| +// This structure holds the logical and visual position information for a line |
|
msw
2013/09/06 23:47:45
nit: remove this second sentence of the comment; i
ckocagil
2013/09/11 14:59:49
Done.
|
| +// segment. |
| +struct LineSegment { |
| + LineSegment(); |
| + |
| + // X coordinates of this line segment in text coordinate space. |
|
msw
2013/09/06 23:47:45
nit: "text space"
ckocagil
2013/09/11 14:59:49
Done.
|
| + ui::Range x_range; |
| + |
| + // The character range this segment corresponds to. |
| + ui::Range char_range; |
| + |
| + // Index of the text run that generated this segment. |
| + size_t run; |
| +}; |
| + |
| +// Holds a list of line segments and metrics for a line. |
|
msw
2013/09/06 23:47:45
nit: consider: // A line of layout text, comprised
ckocagil
2013/09/11 14:59:49
Done.
|
| +struct Line { |
| + Line(); |
| + |
| + // Segments that make up this line in visual order. |
| + std::vector<LineSegment> segments; |
| + |
| + // Total size of this line. Width is the sum of |segment| widths, height is |
|
msw
2013/09/06 23:47:45
nit: consider: // A line size is the sum of segmen
ckocagil
2013/09/11 14:59:49
Done.
|
| + // the maximum height among |segments|. |
| + Size size; |
| + |
| + // Sum of the |height| fields of preceding lines. |
|
msw
2013/09/06 23:47:45
nit: |height| doesn't exist anymore; use "Sum of t
ckocagil
2013/09/11 14:59:49
Done.
|
| + int preceding_heights; |
| + |
| + // Maximum baseline of all runs on this line. |
|
msw
2013/09/06 23:47:45
nit: s/runs/segments/
ckocagil
2013/09/11 14:59:49
Done.
|
| + int baseline; |
| +}; |
| + |
| } // namespace internal |
| // RenderText represents an abstract model of styled text and its corresponding |
| @@ -186,6 +220,11 @@ class UI_EXPORT RenderText { |
| // cleared when SetText or SetObscured is called. |
| void SetObscuredRevealIndex(int index); |
| + // TODO(ckocagil): Multiline text rendering is currently only supported on |
|
msw
2013/09/06 23:47:45
nit: try to be consistent about using either "mult
ckocagil
2013/09/11 14:59:49
Done, used "multiline".
|
| + // Windows. Support other platforms. |
| + bool multiline() const { return multiline_; } |
| + void SetMultiline(bool multiline); |
| + |
| // Set the maximum length of the displayed layout text, not the actual text. |
| // A |length| of 0 forgoes a hard limit, but does not guarantee proper |
| // functionality of very long strings. Applies to subsequent SetText calls. |
| @@ -281,13 +320,12 @@ class UI_EXPORT RenderText { |
| // |GetTextDirection()|, not the direction of a particular run. |
| VisualCursorDirection GetVisualDirectionOfLogicalEnd(); |
| - // Returns the size in pixels of the entire string. For the height, this will |
| - // return the maximum height among the different fonts in the text runs. |
| - // Note that this returns the raw size of the string, which does not include |
| - // the margin area of text shadows. |
| + // Returns the size required to display the current multi-line text. Note that |
| + // this returns the raw size of the string, which does not include the cursor |
| + // or the margin area of text shadows. |
| virtual Size GetStringSize() = 0; |
| - // Returns the width of content, which reserves room for the cursor if |
| + // Returns the width of multi-line content. Reserves room for the cursor if |
|
Alexei Svitkine (slow)
2013/08/30 18:45:25
I think "of the multi-line content" is misleading
msw
2013/09/06 23:47:45
Agreed, and ditto for the GetStringSize() comment.
ckocagil
2013/09/11 14:59:49
Done.
ckocagil
2013/09/11 14:59:49
Done.
|
| // |cursor_enabled_| is true. |
| int GetContentWidth(); |
| @@ -348,6 +386,9 @@ class UI_EXPORT RenderText { |
| const BreakList<SkColor>& colors() const { return colors_; } |
| const std::vector<BreakList<bool> >& styles() const { return styles_; } |
| + const std::vector<internal::Line>& lines() const { return lines_; } |
| + void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
| + |
| const Vector2d& GetUpdatedDisplayOffset(); |
| void set_cached_bounds_and_offset_valid(bool valid) { |
| @@ -406,7 +447,7 @@ class UI_EXPORT RenderText { |
| // Reset the layout to be invalid. |
| virtual void ResetLayout() = 0; |
| - // Ensure the text is laid out. |
| + // Ensure the text is laid out, lines are computed, and |lines_| is valid. |
| virtual void EnsureLayout() = 0; |
| // Draw the text. |
| @@ -415,22 +456,29 @@ class UI_EXPORT RenderText { |
| // Returns the text used for layout, which may be obscured or truncated. |
| const base::string16& GetLayoutText() const; |
| + // Returns layout text positions that are suitable for breaking lines at. |
|
msw
2013/09/06 23:47:45
nit: remove trailing "at".
ckocagil
2013/09/11 14:59:49
Done.
|
| + const BreakList<size_t>& GetLineBreaks(); |
| + |
| // Apply (and undo) temporary composition underlines and selection colors. |
| void ApplyCompositionAndSelectionStyles(); |
| void UndoCompositionAndSelectionStyles(); |
| - // Returns the text offset from the origin after applying text alignment and |
| + // Returns the line offset from the origin after applying text alignment and |
|
msw
2013/09/06 23:47:45
nit: please fix this to "the text alignment and th
ckocagil
2013/09/11 14:59:49
Done.
|
| // display offset. |
| - Vector2d GetTextOffset(); |
| + Vector2d GetLineOffset(size_t line_number); |
| - // Convert points from the text space to the view space and back. |
| - // Handles the display area, display offset, and the application LTR/RTL mode. |
| + // Convert points from the text space to the view space and back. Handles the |
| + // display area, display offset, application LTR/RTL mode and multi-line. |
| Point ToTextPoint(const Point& point); |
| Point ToViewPoint(const Point& point); |
| - // Returns the text offset from the origin, taking into account text alignment |
| + // Convert the range in text coordinates to rects in view coordinates that |
|
msw
2013/09/06 23:47:45
nit: s/coordinates/space/ (times two) to match the
ckocagil
2013/09/11 14:59:49
Done.
|
| + // cover the given range. |
| + std::vector<Rect> TextBoundsToViewBounds(const ui::Range& x); |
| + |
| + // Returns the line offset from the origin, taking into account text alignment |
|
msw
2013/09/06 23:47:45
nit: // Returns the line offset from the origin, a
ckocagil
2013/09/11 14:59:49
Done.
|
| // only. |
| - Vector2d GetAlignmentOffset(); |
| + Vector2d GetAlignmentOffset(size_t line_number); |
| // Applies fade effects to |renderer|. |
| void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
| @@ -457,6 +505,8 @@ class UI_EXPORT RenderText { |
| FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); |
| FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); |
| FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); |
| + FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); |
| + FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); |
| // Set the cursor to |position|, with the caret trailing the previous |
| // grapheme, or if there is no previous grapheme, leading the cursor position. |
| @@ -547,6 +597,10 @@ class UI_EXPORT RenderText { |
| // The obscured and/or truncated text that will be displayed. |
| base::string16 layout_text_; |
| + // Whether the text should be broken into multiple lines. Uses the width of |
| + // |display_rect_| as the width cap. |
| + bool multiline_; |
| + |
| // Fade text head and/or tail, if text doesn't fit into |display_rect_|. |
| bool fade_head_; |
| bool fade_tail_; |
| @@ -574,6 +628,13 @@ class UI_EXPORT RenderText { |
| // Text shadows to be drawn. |
| ShadowValues text_shadows_; |
| + // BreakList to find valid positions to break the line at. |
|
msw
2013/09/06 23:47:45
nit: consider: // A list of valid layout text line
ckocagil
2013/09/11 14:59:49
Done.
|
| + BreakList<size_t> line_breaks_; |
| + |
| + // Lines computed by EnsureLayout. These should be invalidated with |
| + // ResetLayout and on |display_rect_| changes. |
| + std::vector<internal::Line> lines_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(RenderText); |
| }; |