Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / gfx / render_text.h
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_GFX_RENDER_TEXT_H_
6 #define UI_GFX_RENDER_TEXT_H_
7
8 #include <algorithm>
9 #include <cstring>
10 #include <string>
11 #include <utility>
12 #include <vector>
13
14 #include "base/gtest_prod_util.h"
15 #include "base/i18n/rtl.h"
16 #include "base/strings/string16.h"
17 #include "skia/ext/refptr.h"
18 #include "third_party/skia/include/core/SkColor.h"
19 #include "third_party/skia/include/core/SkPaint.h"
20 #include "third_party/skia/include/core/SkRect.h"
21 #include "ui/gfx/break_list.h"
22 #include "ui/gfx/font_list.h"
23 #include "ui/gfx/point.h"
24 #include "ui/gfx/range/range.h"
25 #include "ui/gfx/rect.h"
26 #include "ui/gfx/selection_model.h"
27 #include "ui/gfx/shadow_value.h"
28 #include "ui/gfx/size_f.h"
29 #include "ui/gfx/text_constants.h"
30 #include "ui/gfx/text_elider.h"
31 #include "ui/gfx/vector2d.h"
32
33 class SkCanvas;
34 class SkDrawLooper;
35 struct SkPoint;
36 class SkShader;
37 class SkTypeface;
38
39 namespace gfx {
40
41 class Canvas;
42 class Font;
43 class RenderTextTest;
44
45 namespace internal {
46
47 // Internal helper class used by derived classes to draw text through Skia.
48 class SkiaTextRenderer {
49  public:
50   explicit SkiaTextRenderer(Canvas* canvas);
51   ~SkiaTextRenderer();
52
53   void SetDrawLooper(SkDrawLooper* draw_looper);
54   void SetFontSmoothingSettings(bool antialiasing,
55                                 bool subpixel_rendering,
56                                 bool subpixel_positioning);
57   void SetFontHinting(SkPaint::Hinting hinting);
58   void SetTypeface(SkTypeface* typeface);
59   void SetTextSize(SkScalar size);
60   void SetFontFamilyWithStyle(const std::string& family, int font_style);
61   void SetForegroundColor(SkColor foreground);
62   void SetShader(SkShader* shader, const Rect& bounds);
63   // Sets underline metrics to use if the text will be drawn with an underline.
64   // If not set, default values based on the size of the text will be used. The
65   // two metrics must be set together.
66   void SetUnderlineMetrics(SkScalar thickness, SkScalar position);
67   void DrawSelection(const std::vector<Rect>& selection, SkColor color);
68   void DrawPosText(const SkPoint* pos,
69                    const uint16* glyphs,
70                    size_t glyph_count);
71   // Draw underline and strike-through text decorations.
72   // Based on |SkCanvas::DrawTextDecorations()| and constants from:
73   //   third_party/skia/src/core/SkTextFormatParams.h
74   void DrawDecorations(int x, int y, int width, bool underline, bool strike,
75                        bool diagonal_strike);
76   void DrawUnderline(int x, int y, int width);
77   void DrawStrike(int x, int y, int width) const;
78   void DrawDiagonalStrike(int x, int y, int width) const;
79
80  private:
81   SkCanvas* canvas_skia_;
82   bool started_drawing_;
83   SkPaint paint_;
84   SkRect bounds_;
85   skia::RefPtr<SkShader> deferred_fade_shader_;
86   SkScalar underline_thickness_;
87   SkScalar underline_position_;
88
89   DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer);
90 };
91
92 // Internal helper class used by derived classes to iterate colors and styles.
93 class StyleIterator {
94  public:
95   StyleIterator(const BreakList<SkColor>& colors,
96                 const std::vector<BreakList<bool> >& styles);
97   ~StyleIterator();
98
99   // Get the colors and styles at the current iterator position.
100   SkColor color() const { return color_->second; }
101   bool style(TextStyle s) const { return style_[s]->second; }
102
103   // Get the intersecting range of the current iterator set.
104   Range GetRange() const;
105
106   // Update the iterator to point to colors and styles applicable at |position|.
107   void UpdatePosition(size_t position);
108
109  private:
110   BreakList<SkColor> colors_;
111   std::vector<BreakList<bool> > styles_;
112
113   BreakList<SkColor>::const_iterator color_;
114   std::vector<BreakList<bool>::const_iterator> style_;
115
116   DISALLOW_COPY_AND_ASSIGN(StyleIterator);
117 };
118
119 // Line segments are slices of the layout text to be rendered on a single line.
120 struct LineSegment {
121   LineSegment();
122   ~LineSegment();
123
124   // X coordinates of this line segment in text space.
125   Range x_range;
126
127   // The character range this segment corresponds to.
128   Range char_range;
129
130   // Index of the text run that generated this segment.
131   size_t run;
132 };
133
134 // A line of layout text, comprised of a line segment list and some metrics.
135 struct Line {
136   Line();
137   ~Line();
138
139   // Segments that make up this line in visual order.
140   std::vector<LineSegment> segments;
141
142   // A line size is the sum of segment widths and the maximum of segment
143   // heights.
144   Size size;
145
146   // Sum of preceding lines' heights.
147   int preceding_heights;
148
149   // Maximum baseline of all segments on this line.
150   int baseline;
151 };
152
153 }  // namespace internal
154
155 // RenderText represents an abstract model of styled text and its corresponding
156 // visual layout. Support is built in for a cursor, a selection, simple styling,
157 // complex scripts, and bi-directional text. Implementations provide mechanisms
158 // for rendering and translation between logical and visual data.
159 class GFX_EXPORT RenderText {
160  public:
161   virtual ~RenderText();
162
163   // Creates a platform-specific RenderText instance.
164   static RenderText* CreateInstance();
165
166   const base::string16& text() const { return text_; }
167   void SetText(const base::string16& text);
168
169   HorizontalAlignment horizontal_alignment() const {
170     return horizontal_alignment_;
171   }
172   void SetHorizontalAlignment(HorizontalAlignment alignment);
173
174   const FontList& font_list() const { return font_list_; }
175   void SetFontList(const FontList& font_list);
176
177   bool cursor_enabled() const { return cursor_enabled_; }
178   void SetCursorEnabled(bool cursor_enabled);
179
180   bool cursor_visible() const { return cursor_visible_; }
181   void set_cursor_visible(bool visible) { cursor_visible_ = visible; }
182
183   bool insert_mode() const { return insert_mode_; }
184   void ToggleInsertMode();
185
186   SkColor cursor_color() const { return cursor_color_; }
187   void set_cursor_color(SkColor color) { cursor_color_ = color; }
188
189   SkColor selection_color() const { return selection_color_; }
190   void set_selection_color(SkColor color) { selection_color_ = color; }
191
192   SkColor selection_background_focused_color() const {
193     return selection_background_focused_color_;
194   }
195   void set_selection_background_focused_color(SkColor color) {
196     selection_background_focused_color_ = color;
197   }
198
199   bool focused() const { return focused_; }
200   void set_focused(bool focused) { focused_ = focused; }
201
202   bool clip_to_display_rect() const { return clip_to_display_rect_; }
203   void set_clip_to_display_rect(bool clip) { clip_to_display_rect_ = clip; }
204
205   // In an obscured (password) field, all text is drawn as asterisks or bullets.
206   bool obscured() const { return obscured_; }
207   void SetObscured(bool obscured);
208
209   // Makes a char in obscured text at |index| to be revealed. |index| should be
210   // a UTF16 text index. If there is a previous revealed index, the previous one
211   // is cleared and only the last set index will be revealed. If |index| is -1
212   // or out of range, no char will be revealed. The revealed index is also
213   // cleared when SetText or SetObscured is called.
214   void SetObscuredRevealIndex(int index);
215
216   // TODO(ckocagil): Multiline text rendering is currently only supported on
217   // Windows. Support other platforms.
218   bool multiline() const { return multiline_; }
219   void SetMultiline(bool multiline);
220
221   // Set the maximum length of the displayed layout text, not the actual text.
222   // A |length| of 0 forgoes a hard limit, but does not guarantee proper
223   // functionality of very long strings. Applies to subsequent SetText calls.
224   // WARNING: Only use this for system limits, it lacks complex text support.
225   void set_truncate_length(size_t length) { truncate_length_ = length; }
226
227   // Elides the text to fit in |display_rect| according to the specified
228   // |elide_behavior|. |ELIDE_IN_MIDDLE| is not supported.  If both truncate
229   // and elide are specified, the shorter of the two will be applicable.
230   void SetElideBehavior(ElideBehavior elide_behavior);
231
232   const Rect& display_rect() const { return display_rect_; }
233   void SetDisplayRect(const Rect& r);
234
235   void set_fade_head(bool fade_head) { fade_head_ = fade_head; }
236   bool fade_head() const { return fade_head_; }
237   void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; }
238   bool fade_tail() const { return fade_tail_; }
239
240   bool background_is_transparent() const { return background_is_transparent_; }
241   void set_background_is_transparent(bool transparent) {
242     background_is_transparent_ = transparent;
243   }
244
245   const SelectionModel& selection_model() const { return selection_model_; }
246
247   const Range& selection() const { return selection_model_.selection(); }
248
249   size_t cursor_position() const { return selection_model_.caret_pos(); }
250   void SetCursorPosition(size_t position);
251
252   // Moves the cursor left or right. Cursor movement is visual, meaning that
253   // left and right are relative to screen, not the directionality of the text.
254   // If |select| is false, the selection start is moved to the same position.
255   void MoveCursor(BreakType break_type,
256                   VisualCursorDirection direction,
257                   bool select);
258
259   // Set the selection_model_ to the value of |selection|.
260   // The selection range is clamped to text().length() if out of range.
261   // Returns true if the cursor position or selection range changed.
262   // If any index in |selection_model| is not a cursorable position (not on a
263   // grapheme boundary), it is a no-op and returns false.
264   bool MoveCursorTo(const SelectionModel& selection_model);
265
266   // Move the cursor to the position associated with the clicked point.
267   // If |select| is false, the selection start is moved to the same position.
268   // Returns true if the cursor position or selection range changed.
269   bool MoveCursorTo(const Point& point, bool select);
270
271   // Set the selection_model_ based on |range|.
272   // If the |range| start or end is greater than text length, it is modified
273   // to be the text length.
274   // If the |range| start or end is not a cursorable position (not on grapheme
275   // boundary), it is a NO-OP and returns false. Otherwise, returns true.
276   bool SelectRange(const Range& range);
277
278   // Returns true if the local point is over selected text.
279   bool IsPointInSelection(const Point& point);
280
281   // Selects no text, keeping the current cursor position and caret affinity.
282   void ClearSelection();
283
284   // Select the entire text range. If |reversed| is true, the range will end at
285   // the logical beginning of the text; this generally shows the leading portion
286   // of text that overflows its display area.
287   void SelectAll(bool reversed);
288
289   // Selects the word at the current cursor position. If there is a non-empty
290   // selection, the selection bounds are extended to their nearest word
291   // boundaries.
292   void SelectWord();
293
294   const Range& GetCompositionRange() const;
295   void SetCompositionRange(const Range& composition_range);
296
297   // Set the text color over the entire text or a logical character range.
298   // The |range| should be valid, non-reversed, and within [0, text().length()].
299   void SetColor(SkColor value);
300   void ApplyColor(SkColor value, const Range& range);
301
302   // Set various text styles over the entire text or a logical character range.
303   // The respective |style| is applied if |value| is true, or removed if false.
304   // The |range| should be valid, non-reversed, and within [0, text().length()].
305   void SetStyle(TextStyle style, bool value);
306   void ApplyStyle(TextStyle style, bool value, const Range& range);
307
308   // Returns whether this style is enabled consistently across the entire
309   // RenderText.
310   bool GetStyle(TextStyle style) const;
311
312   // Set or get the text directionality mode and get the text direction yielded.
313   void SetDirectionalityMode(DirectionalityMode mode);
314   DirectionalityMode directionality_mode() const {
315       return directionality_mode_;
316   }
317   base::i18n::TextDirection GetTextDirection();
318
319   // Returns the visual movement direction corresponding to the logical end
320   // of the text, considering only the dominant direction returned by
321   // |GetTextDirection()|, not the direction of a particular run.
322   VisualCursorDirection GetVisualDirectionOfLogicalEnd();
323
324   // Returns the size required to display the current string (which is the
325   // wrapped size in multiline mode). Note that this returns the raw size of the
326   // string, which does not include the cursor or the margin area of text
327   // shadows.
328   virtual Size GetStringSize() = 0;
329
330   // This is same as GetStringSize except that fractional size is returned.
331   // The default implementation is same as GetStringSize. Certain platforms that
332   // compute the text size as floating-point values, like Mac, will override
333   // this method.
334   // See comment in Canvas::GetStringWidthF for its usage.
335   virtual SizeF GetStringSizeF();
336
337   // Returns the width of the content (which is the wrapped width in multiline
338   // mode). Reserves room for the cursor if |cursor_enabled_| is true.
339   int GetContentWidth();
340
341   // Returns the common baseline of the text. The return value is the vertical
342   // offset from the top of |display_rect_| to the text baseline, in pixels.
343   // The baseline is determined from the font list and display rect, and does
344   // not depend on the text.
345   int GetBaseline();
346
347   void Draw(Canvas* canvas);
348
349   // Draws a cursor at |position|.
350   void DrawCursor(Canvas* canvas, const SelectionModel& position);
351
352   // Draw the selected text without a cursor or selection highlight. Subpixel
353   // antialiasing is disabled and foreground color is forced to black.
354   void DrawSelectedTextForDrag(Canvas* canvas);
355
356   // Gets the SelectionModel from a visual point in local coordinates.
357   virtual SelectionModel FindCursorPosition(const Point& point) = 0;
358
359   // Return true if cursor can appear in front of the character at |position|,
360   // which means it is a grapheme boundary or the first character in the text.
361   virtual bool IsCursorablePosition(size_t position) = 0;
362
363   // Get the visual bounds of a cursor at |caret|. These bounds typically
364   // represent a vertical line if |insert_mode| is true. Pass false for
365   // |insert_mode| to retrieve the bounds of the associated glyph. These bounds
366   // are in local coordinates, but may be outside the visible region if the text
367   // is longer than the textfield. Subsequent text, cursor, or bounds changes
368   // may invalidate returned values. Note that |caret| must be placed at
369   // grapheme boundary, that is, |IsCursorablePosition(caret.caret_pos())| must
370   // return true.
371   Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode);
372
373   // Compute the current cursor bounds, panning the text to show the cursor in
374   // the display rect if necessary. These bounds are in local coordinates.
375   // Subsequent text, cursor, or bounds changes may invalidate returned values.
376   const Rect& GetUpdatedCursorBounds();
377
378   // Given an |index| in text(), return the next or previous grapheme boundary
379   // in logical order (that is, the nearest index for which
380   // |IsCursorablePosition(index)| returns true). The return value is in the
381   // range 0 to text().length() inclusive (the input is clamped if it is out of
382   // that range). Always moves by at least one character index unless the
383   // supplied index is already at the boundary of the string.
384   size_t IndexOfAdjacentGrapheme(size_t index,
385                                  LogicalCursorDirection direction);
386
387   // Return a SelectionModel with the cursor at the current selection's start.
388   // The returned value represents a cursor/caret position without a selection.
389   SelectionModel GetSelectionModelForSelectionStart();
390
391   // Sets shadows to drawn with text.
392   void SetTextShadows(const ShadowValues& shadows);
393
394   typedef std::pair<Font, Range> FontSpan;
395   // For testing purposes, returns which fonts were chosen for which parts of
396   // the text by returning a vector of Font and Range pairs, where each range
397   // specifies the character range for which the corresponding font has been
398   // chosen.
399   virtual std::vector<FontSpan> GetFontSpansForTesting() = 0;
400
401  protected:
402   RenderText();
403
404   const BreakList<SkColor>& colors() const { return colors_; }
405   const std::vector<BreakList<bool> >& styles() const { return styles_; }
406
407   const std::vector<internal::Line>& lines() const { return lines_; }
408   void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
409
410   // Returns the baseline of the current text.  The return value depends on
411   // the text and its layout while the return value of GetBaseline() doesn't.
412   // GetAlignmentOffset() takes into account the difference between them.
413   //
414   // We'd like a RenderText to show the text always on the same baseline
415   // regardless of the text, so the text does not jump up or down depending
416   // on the text.  However, underlying layout engines return different baselines
417   // depending on the text.  In general, layout engines determine the minimum
418   // bounding box for the text and return the baseline from the top of the
419   // bounding box.  So the baseline changes depending on font metrics used to
420   // layout the text.
421   //
422   // For example, suppose there are FontA and FontB and the baseline of FontA
423   // is smaller than the one of FontB.  If the text is laid out only with FontA,
424   // then the baseline of FontA may be returned.  If the text includes some
425   // characters which are laid out with FontB, then the baseline of FontB may
426   // be returned.
427   //
428   // GetBaseline() returns the fixed baseline regardless of the text.
429   // GetLayoutTextBaseline() returns the baseline determined by the underlying
430   // layout engine, and it changes depending on the text.  GetAlignmentOffset()
431   // returns the difference between them.
432   virtual int GetLayoutTextBaseline() = 0;
433
434   const Vector2d& GetUpdatedDisplayOffset();
435
436   void set_cached_bounds_and_offset_valid(bool valid) {
437     cached_bounds_and_offset_valid_ = valid;
438   }
439
440   // Get the selection model that visually neighbors |position| by |break_type|.
441   // The returned value represents a cursor/caret position without a selection.
442   SelectionModel GetAdjacentSelectionModel(const SelectionModel& current,
443                                            BreakType break_type,
444                                            VisualCursorDirection direction);
445
446   // Get the selection model visually left/right of |selection| by one grapheme.
447   // The returned value represents a cursor/caret position without a selection.
448   virtual SelectionModel AdjacentCharSelectionModel(
449       const SelectionModel& selection,
450       VisualCursorDirection direction) = 0;
451
452   // Get the selection model visually left/right of |selection| by one word.
453   // The returned value represents a cursor/caret position without a selection.
454   virtual SelectionModel AdjacentWordSelectionModel(
455       const SelectionModel& selection,
456       VisualCursorDirection direction) = 0;
457
458   // Get the SelectionModels corresponding to visual text ends.
459   // The returned value represents a cursor/caret position without a selection.
460   SelectionModel EdgeSelectionModel(VisualCursorDirection direction);
461
462   // Sets the selection model, the argument is assumed to be valid.
463   virtual void SetSelectionModel(const SelectionModel& model);
464
465   // Get the horizontal bounds (relative to the left of the text, not the view)
466   // of the glyph starting at |index|. If the glyph is RTL then the returned
467   // Range will have is_reversed() true.  (This does not return a Rect because a
468   // Rect can't have a negative width.)
469   virtual Range GetGlyphBounds(size_t index) = 0;
470
471   // Get the visual bounds containing the logical substring within the |range|.
472   // If |range| is empty, the result is empty. These bounds could be visually
473   // discontinuous if the substring is split by a LTR/RTL level change.
474   // These bounds are in local coordinates, but may be outside the visible
475   // region if the text is longer than the textfield. Subsequent text, cursor,
476   // or bounds changes may invalidate returned values.
477   virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0;
478
479   // Convert between indices into |text_| and indices into |obscured_text_|,
480   // which differ when the text is obscured. Regardless of whether or not the
481   // text is obscured, the character (code point) offsets always match.
482   virtual size_t TextIndexToLayoutIndex(size_t index) const = 0;
483   virtual size_t LayoutIndexToTextIndex(size_t index) const = 0;
484
485   // Reset the layout to be invalid.
486   virtual void ResetLayout() = 0;
487
488   // Ensure the text is laid out, lines are computed, and |lines_| is valid.
489   virtual void EnsureLayout() = 0;
490
491   // Draw the text.
492   virtual void DrawVisualText(Canvas* canvas) = 0;
493
494   // Returns the text used for layout, which may be obscured or truncated.
495   const base::string16& GetLayoutText() const;
496
497   // Returns layout text positions that are suitable for breaking lines.
498   const BreakList<size_t>& GetLineBreaks();
499
500   // Apply (and undo) temporary composition underlines and selection colors.
501   void ApplyCompositionAndSelectionStyles();
502   void UndoCompositionAndSelectionStyles();
503
504   // Returns the line offset from the origin after applying the text alignment
505   // and the display offset.
506   Vector2d GetLineOffset(size_t line_number);
507
508   // Convert points from the text space to the view space and back. Handles the
509   // display area, display offset, application LTR/RTL mode and multiline.
510   Point ToTextPoint(const Point& point);
511   Point ToViewPoint(const Point& point);
512
513   // Convert a text space x-coordinate range to corresponding rects in view
514   // space.
515   std::vector<Rect> TextBoundsToViewBounds(const Range& x);
516
517   // Returns the line offset from the origin, accounting for text alignment
518   // only.
519   Vector2d GetAlignmentOffset(size_t line_number);
520
521   // Applies fade effects to |renderer|.
522   void ApplyFadeEffects(internal::SkiaTextRenderer* renderer);
523
524   // Applies text shadows to |renderer|.
525   void ApplyTextShadows(internal::SkiaTextRenderer* renderer);
526
527   // A convenience function to check whether the glyph attached to the caret
528   // is within the given range.
529   static bool RangeContainsCaret(const Range& range,
530                                  size_t caret_pos,
531                                  LogicalCursorDirection caret_affinity);
532
533  private:
534   friend class RenderTextTest;
535   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle);
536   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle);
537   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle);
538   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText);
539   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText);
540   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText);
541   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText);
542   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText);
543   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText);
544   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions);
545   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels);
546   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset);
547   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL);
548   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth);
549   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth);
550   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth);
551   FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline);
552
553   // Set the cursor to |position|, with the caret trailing the previous
554   // grapheme, or if there is no previous grapheme, leading the cursor position.
555   // If |select| is false, the selection start is moved to the same position.
556   // If the |position| is not a cursorable position (not on grapheme boundary),
557   // it is a NO-OP.
558   void MoveCursorTo(size_t position, bool select);
559
560   // Updates |layout_text_| if the text is obscured or truncated.
561   void UpdateLayoutText();
562
563   // Elides |text| to fit in the |display_rect_| with given |elide_behavior_|.
564   // See ElideText in ui/gfx/text_elider.cc for reference.
565   base::string16 ElideText(const base::string16& text);
566
567   // Update the cached bounds and display offset to ensure that the current
568   // cursor is within the visible display area.
569   void UpdateCachedBoundsAndOffset();
570
571   // Draw the selection.
572   void DrawSelection(Canvas* canvas);
573
574   // Logical UTF-16 string data to be drawn.
575   base::string16 text_;
576
577   // Horizontal alignment of the text with respect to |display_rect_|.  The
578   // default is to align left if the application UI is LTR and right if RTL.
579   HorizontalAlignment horizontal_alignment_;
580
581   // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT.
582   DirectionalityMode directionality_mode_;
583
584   // The cached text direction, potentially computed from the text or UI locale.
585   // Use GetTextDirection(), do not use this potentially invalid value directly!
586   base::i18n::TextDirection text_direction_;
587
588   // A list of fonts used to render |text_|.
589   FontList font_list_;
590
591   // Logical selection range and visual cursor position.
592   SelectionModel selection_model_;
593
594   // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds.
595   Rect cursor_bounds_;
596
597   // Specifies whether the cursor is enabled. If disabled, no space is reserved
598   // for the cursor when positioning text.
599   bool cursor_enabled_;
600
601   // The cursor visibility and insert mode.
602   bool cursor_visible_;
603   bool insert_mode_;
604
605   // The color used for the cursor.
606   SkColor cursor_color_;
607
608   // The color used for drawing selected text.
609   SkColor selection_color_;
610
611   // The background color used for drawing the selection when focused.
612   SkColor selection_background_focused_color_;
613
614   // The focus state of the text.
615   bool focused_;
616
617   // Composition text range.
618   Range composition_range_;
619
620   // Color and style breaks, used to color and stylize ranges of text.
621   // BreakList positions are stored with text indices, not layout indices.
622   // TODO(msw): Expand to support cursor, selection, background, etc. colors.
623   BreakList<SkColor> colors_;
624   std::vector<BreakList<bool> > styles_;
625
626   // Breaks saved without temporary composition and selection styling.
627   BreakList<SkColor> saved_colors_;
628   BreakList<bool> saved_underlines_;
629   bool composition_and_selection_styles_applied_;
630
631   // A flag to obscure actual text with asterisks for password fields.
632   bool obscured_;
633   // The index at which the char should be revealed in the obscured text.
634   int obscured_reveal_index_;
635
636   // The maximum length of text to display, 0 forgoes a hard limit.
637   size_t truncate_length_;
638
639   // The behavior for eliding or truncating.
640   ElideBehavior elide_behavior_;
641
642   // The obscured and/or truncated text that will be displayed.
643   base::string16 layout_text_;
644
645   // Whether the text should be broken into multiple lines. Uses the width of
646   // |display_rect_| as the width cap.
647   bool multiline_;
648
649   // Fade text head and/or tail, if text doesn't fit into |display_rect_|.
650   bool fade_head_;
651   bool fade_tail_;
652
653   // Is the background transparent (either partially or fully)?
654   bool background_is_transparent_;
655
656   // The local display area for rendering the text.
657   Rect display_rect_;
658
659   // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548)
660   // that results in incorrect clipping when drawing to the document margins.
661   // This field allows disabling clipping to work around the issue.
662   // TODO(asvitkine): Remove this when the underlying Skia bug is fixed.
663   bool clip_to_display_rect_;
664
665   // The offset for the text to be drawn, relative to the display area.
666   // Get this point with GetUpdatedDisplayOffset (or risk using a stale value).
667   Vector2d display_offset_;
668
669   // The baseline of the text.  This is determined from the height of the
670   // display area and the cap height of the font list so the text is vertically
671   // centered.
672   int baseline_;
673
674   // The cached bounds and offset are invalidated by changes to the cursor,
675   // selection, font, and other operations that adjust the visible text bounds.
676   bool cached_bounds_and_offset_valid_;
677
678   // Text shadows to be drawn.
679   ShadowValues text_shadows_;
680
681   // A list of valid layout text line break positions.
682   BreakList<size_t> line_breaks_;
683
684   // Lines computed by EnsureLayout. These should be invalidated with
685   // ResetLayout and on |display_rect_| changes.
686   std::vector<internal::Line> lines_;
687
688   DISALLOW_COPY_AND_ASSIGN(RenderText);
689 };
690
691 }  // namespace gfx
692
693 #endif  // UI_GFX_RENDER_TEXT_H_