OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_GFX_RENDER_TEXT_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_H_ |
6 #define UI_GFX_RENDER_TEXT_H_ | 6 #define UI_GFX_RENDER_TEXT_H_ |
7 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cstring> | 9 #include <cstring> |
10 #include <string> | 10 #include <string> |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 Canvas* canvas_; | 102 Canvas* canvas_; |
103 SkCanvas* canvas_skia_; | 103 SkCanvas* canvas_skia_; |
104 SkPaint paint_; | 104 SkPaint paint_; |
105 SkScalar underline_thickness_; | 105 SkScalar underline_thickness_; |
106 SkScalar underline_position_; | 106 SkScalar underline_position_; |
107 scoped_ptr<DiagonalStrike> diagonal_; | 107 scoped_ptr<DiagonalStrike> diagonal_; |
108 | 108 |
109 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); | 109 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); |
110 }; | 110 }; |
111 | 111 |
112 // Internal helper class used by derived classes to iterate colors and styles. | 112 // Internal helper class used to iterate colors, baselines, and styles. |
113 class StyleIterator { | 113 class StyleIterator { |
114 public: | 114 public: |
115 StyleIterator(const BreakList<SkColor>& colors, | 115 StyleIterator(const BreakList<SkColor>& colors, |
116 const std::vector<BreakList<bool> >& styles); | 116 const BreakList<BaselineStyle>& baselines, |
| 117 const std::vector<BreakList<bool>>& styles); |
117 ~StyleIterator(); | 118 ~StyleIterator(); |
118 | 119 |
119 // Get the colors and styles at the current iterator position. | 120 // Get the colors and styles at the current iterator position. |
120 SkColor color() const { return color_->second; } | 121 SkColor color() const { return color_->second; } |
| 122 BaselineStyle baseline() const { return baseline_->second; } |
121 bool style(TextStyle s) const { return style_[s]->second; } | 123 bool style(TextStyle s) const { return style_[s]->second; } |
122 | 124 |
123 // Get the intersecting range of the current iterator set. | 125 // Get the intersecting range of the current iterator set. |
124 Range GetRange() const; | 126 Range GetRange() const; |
125 | 127 |
126 // Update the iterator to point to colors and styles applicable at |position|. | 128 // Update the iterator to point to colors and styles applicable at |position|. |
127 void UpdatePosition(size_t position); | 129 void UpdatePosition(size_t position); |
128 | 130 |
129 private: | 131 private: |
130 BreakList<SkColor> colors_; | 132 BreakList<SkColor> colors_; |
| 133 BreakList<BaselineStyle> baselines_; |
131 std::vector<BreakList<bool> > styles_; | 134 std::vector<BreakList<bool> > styles_; |
132 | 135 |
133 BreakList<SkColor>::const_iterator color_; | 136 BreakList<SkColor>::const_iterator color_; |
| 137 BreakList<BaselineStyle>::const_iterator baseline_; |
134 std::vector<BreakList<bool>::const_iterator> style_; | 138 std::vector<BreakList<bool>::const_iterator> style_; |
135 | 139 |
136 DISALLOW_COPY_AND_ASSIGN(StyleIterator); | 140 DISALLOW_COPY_AND_ASSIGN(StyleIterator); |
137 }; | 141 }; |
138 | 142 |
139 // Line segments are slices of the display text to be rendered on a single line. | 143 // Line segments are slices of the display text to be rendered on a single line. |
140 struct LineSegment { | 144 struct LineSegment { |
141 LineSegment(); | 145 LineSegment(); |
142 ~LineSegment(); | 146 ~LineSegment(); |
143 | 147 |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 void SelectWord(); | 329 void SelectWord(); |
326 | 330 |
327 const Range& GetCompositionRange() const; | 331 const Range& GetCompositionRange() const; |
328 void SetCompositionRange(const Range& composition_range); | 332 void SetCompositionRange(const Range& composition_range); |
329 | 333 |
330 // Set the text color over the entire text or a logical character range. | 334 // Set the text color over the entire text or a logical character range. |
331 // The |range| should be valid, non-reversed, and within [0, text().length()]. | 335 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
332 void SetColor(SkColor value); | 336 void SetColor(SkColor value); |
333 void ApplyColor(SkColor value, const Range& range); | 337 void ApplyColor(SkColor value, const Range& range); |
334 | 338 |
| 339 // Set the baseline style over the entire text or a logical character range. |
| 340 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
| 341 void SetBaselineStyle(BaselineStyle value); |
| 342 void ApplyBaselineStyle(BaselineStyle value, const Range& range); |
| 343 |
335 // Set various text styles over the entire text or a logical character range. | 344 // Set various text styles over the entire text or a logical character range. |
336 // The respective |style| is applied if |value| is true, or removed if false. | 345 // The respective |style| is applied if |value| is true, or removed if false. |
337 // The |range| should be valid, non-reversed, and within [0, text().length()]. | 346 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
338 void SetStyle(TextStyle style, bool value); | 347 void SetStyle(TextStyle style, bool value); |
339 void ApplyStyle(TextStyle style, bool value, const Range& range); | 348 void ApplyStyle(TextStyle style, bool value, const Range& range); |
340 | 349 |
341 // Returns whether this style is enabled consistently across the entire | 350 // Returns whether this style is enabled consistently across the entire |
342 // RenderText. | 351 // RenderText. |
343 bool GetStyle(TextStyle style) const; | 352 bool GetStyle(TextStyle style) const; |
344 | 353 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 protected: | 458 protected: |
450 RenderText(); | 459 RenderText(); |
451 | 460 |
452 // NOTE: The value of these accessors may be stale. Please make sure | 461 // NOTE: The value of these accessors may be stale. Please make sure |
453 // that these fields are up-to-date before accessing them. | 462 // that these fields are up-to-date before accessing them. |
454 const base::string16& layout_text() const { return layout_text_; } | 463 const base::string16& layout_text() const { return layout_text_; } |
455 const base::string16& display_text() const { return display_text_; } | 464 const base::string16& display_text() const { return display_text_; } |
456 bool text_elided() const { return text_elided_; } | 465 bool text_elided() const { return text_elided_; } |
457 | 466 |
458 const BreakList<SkColor>& colors() const { return colors_; } | 467 const BreakList<SkColor>& colors() const { return colors_; } |
| 468 const BreakList<BaselineStyle>& baselines() const { return baselines_; } |
459 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 469 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
460 | 470 |
461 const std::vector<internal::Line>& lines() const { return lines_; } | 471 const std::vector<internal::Line>& lines() const { return lines_; } |
462 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } | 472 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
463 | 473 |
464 // Returns the baseline of the current text. The return value depends on | 474 // Returns the baseline of the current text. The return value depends on |
465 // the text and its layout while the return value of GetBaseline() doesn't. | 475 // the text and its layout while the return value of GetBaseline() doesn't. |
466 // GetAlignmentOffset() takes into account the difference between them. | 476 // GetAlignmentOffset() takes into account the difference between them. |
467 // | 477 // |
468 // We'd like a RenderText to show the text always on the same baseline | 478 // We'd like a RenderText to show the text always on the same baseline |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 | 695 |
686 // The background color used for drawing the selection when focused. | 696 // The background color used for drawing the selection when focused. |
687 SkColor selection_background_focused_color_; | 697 SkColor selection_background_focused_color_; |
688 | 698 |
689 // The focus state of the text. | 699 // The focus state of the text. |
690 bool focused_; | 700 bool focused_; |
691 | 701 |
692 // Composition text range. | 702 // Composition text range. |
693 Range composition_range_; | 703 Range composition_range_; |
694 | 704 |
695 // Color and style breaks, used to color and stylize ranges of text. | 705 // Color, baseline, and style breaks, used to modify ranges of text. |
696 // BreakList positions are stored with text indices, not display indices. | 706 // BreakList positions are stored with text indices, not display indices. |
697 // TODO(msw): Expand to support cursor, selection, background, etc. colors. | 707 // TODO(msw): Expand to support cursor, selection, background, etc. colors. |
698 BreakList<SkColor> colors_; | 708 BreakList<SkColor> colors_; |
| 709 BreakList<BaselineStyle> baselines_; |
699 std::vector<BreakList<bool> > styles_; | 710 std::vector<BreakList<bool> > styles_; |
700 | 711 |
701 // Breaks saved without temporary composition and selection styling. | 712 // Breaks saved without temporary composition and selection styling. |
702 BreakList<SkColor> saved_colors_; | 713 BreakList<SkColor> saved_colors_; |
703 BreakList<bool> saved_underlines_; | 714 BreakList<bool> saved_underlines_; |
704 bool composition_and_selection_styles_applied_; | 715 bool composition_and_selection_styles_applied_; |
705 | 716 |
706 // A flag to obscure actual text with asterisks for password fields. | 717 // A flag to obscure actual text with asterisks for password fields. |
707 bool obscured_; | 718 bool obscured_; |
708 // The index at which the char should be revealed in the obscured text. | 719 // The index at which the char should be revealed in the obscured text. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
769 // Lines computed by EnsureLayout. These should be invalidated upon | 780 // Lines computed by EnsureLayout. These should be invalidated upon |
770 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 781 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
771 std::vector<internal::Line> lines_; | 782 std::vector<internal::Line> lines_; |
772 | 783 |
773 DISALLOW_COPY_AND_ASSIGN(RenderText); | 784 DISALLOW_COPY_AND_ASSIGN(RenderText); |
774 }; | 785 }; |
775 | 786 |
776 } // namespace gfx | 787 } // namespace gfx |
777 | 788 |
778 #endif // UI_GFX_RENDER_TEXT_H_ | 789 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |