Index: ui/gfx/render_text.h |
diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h |
index c4d48fd79058f9e81fb51816ea923052d7a02165..009aed1529288bc1d922e6fd600527057748fd92 100644 |
--- a/ui/gfx/render_text.h |
+++ b/ui/gfx/render_text.h |
@@ -13,6 +13,8 @@ |
#include "base/gtest_prod_util.h" |
#include "base/i18n/rtl.h" |
+#include "base/memory/scoped_vector.h" |
+#include "base/stl_util.h" |
#include "base/strings/string16.h" |
#include "skia/ext/refptr.h" |
#include "third_party/skia/include/core/SkColor.h" |
@@ -111,6 +113,35 @@ 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), |
msw
2013/07/17 06:47:18
nit: make this all one line or indent intitializer
ckocagil
2013/07/19 19:40:50
Done.
|
+ height(0), |
+ preceding_heights(0), |
+ baseline(0) { |
+ } |
+ Line(Line& other) { |
+ *this = other; |
+ } |
+ Line& operator=(Line& other) { |
+ width = other.width; |
+ height = other.height; |
+ preceding_heights = other.preceding_heights; |
+ baseline = other.baseline; |
+ segments.swap(other.segments); |
msw
2013/07/17 06:47:18
Swap makes this destructive to the right hand side
ckocagil
2013/07/19 19:40:50
Yes, these are for STL containers only. I'm adding
msw
2013/08/15 02:44:17
Use ScopedVector and avoid copy/assign if possible
|
+ return *this; |
+ } |
+ ScopedVector<LineSegment> segments; |
+ int width; |
+ int height; // Maximum text height of all runs on this line. |
msw
2013/07/17 06:47:18
See Yuki's ongoing work to find common heights and
|
+ 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 +210,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 +321,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 +386,14 @@ class UI_EXPORT RenderText { |
const BreakList<SkColor>& colors() const { return colors_; } |
const std::vector<BreakList<bool> >& styles() const { return styles_; } |
+ const std::vector<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); } |
+ |
+ bool lines_valid() const { return lines_valid_; } |
+ void set_lines_valid(bool lines_valid) { lines_valid_ = lines_valid; } |
+ |
const Vector2d& GetUpdatedDisplayOffset(); |
void set_cached_bounds_and_offset_valid(bool valid) { |
@@ -405,7 +452,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 +465,22 @@ 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(int line); |
msw
2013/07/17 06:47:18
Rename to |line_number| to clarify the arg; and us
ckocagil
2013/07/19 19:40:50
Done.
|
// Convert points from the text space to the view space and back. |
// Handles the display area, display offset, and the application LTR/RTL mode. |
msw
2013/07/17 06:47:18
Update the comment, to reflect the new multi-line
ckocagil
2013/07/19 19:40:50
Done.
|
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> RangeToViewRects(const ui::Range& x); |
msw
2013/07/17 06:47:18
I'm trying to think of a better name, maybe: TextB
ckocagil
2013/07/19 19:40:50
Changed to TextBoundsToViewBounds.
|
+ |
+ // Returns the line offset from the origin, taking into account text alignment |
// only. |
- Vector2d GetAlignmentOffset(); |
+ Vector2d GetAlignmentOffset(int line); |
msw
2013/07/17 06:47:18
Ditto: Rename to |line_number| to clarify the arg;
ckocagil
2013/07/19 19:40:50
Done.
|
// Applies fade effects to |renderer|. |
void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
@@ -546,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_; |
@@ -573,6 +628,16 @@ class UI_EXPORT RenderText { |
// Text shadows to be drawn. |
ShadowValues text_shadows_; |
+ // Positions at which we can break the line. |
+ std::vector<size_t> line_breaks_; |
+ |
+ // Lines computed by EnsureLayout. Valid when |lines_valid_| is true. |
+ std::vector<internal::Line> lines_; |
+ |
+ // Whether the current |lines_| is valid. |lines_| is invalidated whenever |
msw
2013/07/17 06:47:18
Since we reconstruct |lines_| on ComputeLines, can
ckocagil
2013/07/19 19:40:50
Done.
|
+ // the text, styles or |display_rect_| changes. |
+ bool lines_valid_; |
+ |
DISALLOW_COPY_AND_ASSIGN(RenderText); |
}; |