| Index: ui/gfx/render_text.h
|
| diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h
|
| index c4d48fd79058f9e81fb51816ea923052d7a02165..cdf964248bbe523880522916ae7bdc2e2f99d50b 100644
|
| --- a/ui/gfx/render_text.h
|
| +++ b/ui/gfx/render_text.h
|
| @@ -13,6 +13,7 @@
|
|
|
| #include "base/gtest_prod_util.h"
|
| #include "base/i18n/rtl.h"
|
| +#include "base/memory/scoped_vector.h"
|
| #include "base/strings/string16.h"
|
| #include "skia/ext/refptr.h"
|
| #include "third_party/skia/include/core/SkColor.h"
|
| @@ -111,6 +112,33 @@ class StyleIterator {
|
| DISALLOW_COPY_AND_ASSIGN(StyleIterator);
|
| };
|
|
|
| +struct LineSegment {
|
| + ui::Range x_pos; // x coord, in text coordinates.
|
| + ui::Range char_pos;
|
| +};
|
| +
|
| +struct Line {
|
| + Line() : width(0), height(0), preceding_heights(0), baseline(0) {}
|
| + // Destructive. Empties the |segments| field of the given Line.
|
| + Line(Line& other) {
|
| + *this = other;
|
| + }
|
| + // Destructive. Empties the |segments| field of the Line on the rhs.
|
| + Line& operator=(Line& other) {
|
| + width = other.width;
|
| + height = other.height;
|
| + preceding_heights = other.preceding_heights;
|
| + baseline = other.baseline;
|
| + segments.swap(other.segments);
|
| + return *this;
|
| + }
|
| + ScopedVector<LineSegment> segments;
|
| + int width;
|
| + int height; // Maximum text height of all runs on this line.
|
| + int preceding_heights; // Sum of |height| fields of preceding lines.
|
| + int baseline; // Maximum baseline of all runs on this line.
|
| +};
|
| +
|
| } // namespace internal
|
|
|
| // RenderText represents an abstract model of styled text and its corresponding
|
| @@ -179,6 +207,9 @@ class UI_EXPORT RenderText {
|
| bool obscured() const { return obscured_; }
|
| void SetObscured(bool obscured);
|
|
|
| + bool multiline() const { return multiline_; }
|
| + void set_multiline(bool multiline) { multiline_ = multiline; }
|
| +
|
| // Makes a char in obscured text at |index| to be revealed. |index| should be
|
| // a UTF16 text index. If there is a previous revealed index, the previous one
|
| // is cleared and only the last set index will be revealed. If |index| is -1
|
| @@ -287,6 +318,11 @@ class UI_EXPORT RenderText {
|
| // the margin area of text shadows.
|
| virtual Size GetStringSize() = 0;
|
|
|
| + // Returns the size required to display the current multiline text, which is
|
| + // horizontally capped by the width of |display_rect()|.
|
| + // TODO(ckocagil): Merge with GetContentWidth.
|
| + virtual Size GetMultilineTextSize() = 0;
|
| +
|
| // Returns the width of content, which reserves room for the cursor if
|
| // |cursor_enabled_| is true.
|
| int GetContentWidth();
|
| @@ -347,6 +383,11 @@ class UI_EXPORT RenderText {
|
| const BreakList<SkColor>& colors() const { return colors_; }
|
| const std::vector<BreakList<bool> >& styles() const { return styles_; }
|
|
|
| + const BreakList<size_t>& line_breaks() const { return line_breaks_; }
|
| +
|
| + 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) {
|
| @@ -405,7 +446,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.
|
| @@ -418,18 +459,23 @@ class UI_EXPORT RenderText {
|
| 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
|
| // 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.
|
| + // 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
|
| + // cover the given range.
|
| + std::vector<Rect> TextBoundsToViewBounds(const ui::Range& x);
|
| +
|
| + // Returns the line offset from the origin, taking into account text alignment
|
| // only.
|
| - Vector2d GetAlignmentOffset();
|
| + Vector2d GetAlignmentOffset(size_t line_number);
|
|
|
| // Applies fade effects to |renderer|.
|
| void ApplyFadeEffects(internal::SkiaTextRenderer* renderer);
|
| @@ -546,6 +592,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_;
|
| @@ -573,6 +623,13 @@ class UI_EXPORT RenderText {
|
| // Text shadows to be drawn.
|
| ShadowValues text_shadows_;
|
|
|
| + // BreakList to find valid positions to break the line at.
|
| + BreakList<size_t> line_breaks_;
|
| +
|
| + // Lines computed by EnsureLayout. Should be emptied whenever the text, styles
|
| + // or |display_rect_| changes.
|
| + std::vector<internal::Line> lines_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(RenderText);
|
| };
|
|
|
|
|