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 by derived classes to iterate colors, baselines, |
msw
2015/02/18 23:32:08
nit: remove "by derived classes" for a one-liner.
dschuyler
2015/02/19 00:29:14
Done.
| |
113 // and styles. | |
113 class StyleIterator { | 114 class StyleIterator { |
114 public: | 115 public: |
115 StyleIterator(const BreakList<SkColor>& colors, | 116 StyleIterator(const BreakList<SkColor>& colors, |
117 const BreakList<BaselineStyle>& baselines, | |
116 const std::vector<BreakList<bool> >& styles); | 118 const std::vector<BreakList<bool> >& styles); |
117 ~StyleIterator(); | 119 ~StyleIterator(); |
118 | 120 |
119 // Get the colors and styles at the current iterator position. | 121 // Get the colors and styles at the current iterator position. |
120 SkColor color() const { return color_->second; } | 122 SkColor color() const { return color_->second; } |
123 BaselineStyle baseline() const { return baseline_->second; } | |
121 bool style(TextStyle s) const { return style_[s]->second; } | 124 bool style(TextStyle s) const { return style_[s]->second; } |
122 | 125 |
123 // Get the intersecting range of the current iterator set. | 126 // Get the intersecting range of the current iterator set. |
124 Range GetRange() const; | 127 Range GetRange() const; |
125 | 128 |
126 // Update the iterator to point to colors and styles applicable at |position|. | 129 // Update the iterator to point to colors and styles applicable at |position|. |
127 void UpdatePosition(size_t position); | 130 void UpdatePosition(size_t position); |
128 | 131 |
129 private: | 132 private: |
130 BreakList<SkColor> colors_; | 133 BreakList<SkColor> colors_; |
134 BreakList<BaselineStyle> baselines_; | |
131 std::vector<BreakList<bool> > styles_; | 135 std::vector<BreakList<bool> > styles_; |
132 | 136 |
133 BreakList<SkColor>::const_iterator color_; | 137 BreakList<SkColor>::const_iterator color_; |
138 BreakList<BaselineStyle>::const_iterator baseline_; | |
134 std::vector<BreakList<bool>::const_iterator> style_; | 139 std::vector<BreakList<bool>::const_iterator> style_; |
135 | 140 |
136 DISALLOW_COPY_AND_ASSIGN(StyleIterator); | 141 DISALLOW_COPY_AND_ASSIGN(StyleIterator); |
137 }; | 142 }; |
138 | 143 |
139 // Line segments are slices of the display text to be rendered on a single line. | 144 // Line segments are slices of the display text to be rendered on a single line. |
140 struct LineSegment { | 145 struct LineSegment { |
141 LineSegment(); | 146 LineSegment(); |
142 ~LineSegment(); | 147 ~LineSegment(); |
143 | 148 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 void SelectWord(); | 328 void SelectWord(); |
324 | 329 |
325 const Range& GetCompositionRange() const; | 330 const Range& GetCompositionRange() const; |
326 void SetCompositionRange(const Range& composition_range); | 331 void SetCompositionRange(const Range& composition_range); |
327 | 332 |
328 // Set the text color over the entire text or a logical character range. | 333 // Set the text color over the entire text or a logical character range. |
329 // The |range| should be valid, non-reversed, and within [0, text().length()]. | 334 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
330 void SetColor(SkColor value); | 335 void SetColor(SkColor value); |
331 void ApplyColor(SkColor value, const Range& range); | 336 void ApplyColor(SkColor value, const Range& range); |
332 | 337 |
338 // Set the baseline style over the entire text or a logical character range. | |
msw
2015/02/18 23:32:08
nit: remove the extra space before "baseline"
dschuyler
2015/02/19 00:29:14
Done.
| |
339 // The |range| should be valid, non-reversed, and within [0, text().length()]. | |
340 void SetBaselineStyle(BaselineStyle value); | |
341 void ApplyBaselineStyle(BaselineStyle value, const Range& range); | |
342 | |
333 // Set various text styles over the entire text or a logical character range. | 343 // Set various text styles over the entire text or a logical character range. |
334 // The respective |style| is applied if |value| is true, or removed if false. | 344 // The respective |style| is applied if |value| is true, or removed if false. |
335 // The |range| should be valid, non-reversed, and within [0, text().length()]. | 345 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
336 void SetStyle(TextStyle style, bool value); | 346 void SetStyle(TextStyle style, bool value); |
337 void ApplyStyle(TextStyle style, bool value, const Range& range); | 347 void ApplyStyle(TextStyle style, bool value, const Range& range); |
338 | 348 |
339 // Returns whether this style is enabled consistently across the entire | 349 // Returns whether this style is enabled consistently across the entire |
340 // RenderText. | 350 // RenderText. |
341 bool GetStyle(TextStyle style) const; | 351 bool GetStyle(TextStyle style) const; |
342 | 352 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 protected: | 457 protected: |
448 RenderText(); | 458 RenderText(); |
449 | 459 |
450 // NOTE: The value of these accessors may be stale. Please make sure | 460 // NOTE: The value of these accessors may be stale. Please make sure |
451 // that these fields are up-to-date before accessing them. | 461 // that these fields are up-to-date before accessing them. |
452 const base::string16& layout_text() const { return layout_text_; } | 462 const base::string16& layout_text() const { return layout_text_; } |
453 const base::string16& display_text() const { return display_text_; } | 463 const base::string16& display_text() const { return display_text_; } |
454 bool text_elided() const { return text_elided_; } | 464 bool text_elided() const { return text_elided_; } |
455 | 465 |
456 const BreakList<SkColor>& colors() const { return colors_; } | 466 const BreakList<SkColor>& colors() const { return colors_; } |
467 const BreakList<BaselineStyle>& baselines() const { return baselines_; } | |
457 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 468 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
458 | 469 |
459 const std::vector<internal::Line>& lines() const { return lines_; } | 470 const std::vector<internal::Line>& lines() const { return lines_; } |
460 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } | 471 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
461 | 472 |
462 // Returns the baseline of the current text. The return value depends on | 473 // Returns the baseline of the current text. The return value depends on |
463 // the text and its layout while the return value of GetBaseline() doesn't. | 474 // the text and its layout while the return value of GetBaseline() doesn't. |
464 // GetAlignmentOffset() takes into account the difference between them. | 475 // GetAlignmentOffset() takes into account the difference between them. |
465 // | 476 // |
466 // We'd like a RenderText to show the text always on the same baseline | 477 // We'd like a RenderText to show the text always on the same baseline |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 // Set the cursor to |position|, with the caret trailing the previous | 630 // Set the cursor to |position|, with the caret trailing the previous |
620 // grapheme, or if there is no previous grapheme, leading the cursor position. | 631 // grapheme, or if there is no previous grapheme, leading the cursor position. |
621 // If |select| is false, the selection start is moved to the same position. | 632 // If |select| is false, the selection start is moved to the same position. |
622 // If the |position| is not a cursorable position (not on grapheme boundary), | 633 // If the |position| is not a cursorable position (not on grapheme boundary), |
623 // it is a NO-OP. | 634 // it is a NO-OP. |
624 void MoveCursorTo(size_t position, bool select); | 635 void MoveCursorTo(size_t position, bool select); |
625 | 636 |
626 // Updates |layout_text_| and |display_text_| as needed (or marks them dirty). | 637 // Updates |layout_text_| and |display_text_| as needed (or marks them dirty). |
627 void OnTextAttributeChanged(); | 638 void OnTextAttributeChanged(); |
628 | 639 |
640 // Make sure ranges don't break text graphemes. If a range in |break_list| | |
641 // does break a grapheme in |render_text|, the range will be slightly | |
msw
2015/02/18 23:32:08
nit: remove the double space before "grapheme".
dschuyler
2015/02/19 00:29:14
Done.
| |
642 // extended to encompass the grapheme. | |
643 template <typename T> | |
644 void RestoreBreakList(RenderText* render_text, | |
645 T& break_list); | |
646 | |
629 // Elides |text| as needed to fit in the |available_width| using |behavior|. | 647 // Elides |text| as needed to fit in the |available_width| using |behavior|. |
630 // |text_width| is the pre-calculated width of the text shaped by this render | 648 // |text_width| is the pre-calculated width of the text shaped by this render |
631 // text, or pass 0 if the width is unknown. | 649 // text, or pass 0 if the width is unknown. |
632 base::string16 Elide(const base::string16& text, | 650 base::string16 Elide(const base::string16& text, |
633 float text_width, | 651 float text_width, |
634 float available_width, | 652 float available_width, |
635 ElideBehavior behavior); | 653 ElideBehavior behavior); |
636 | 654 |
637 // Elides |email| as needed to fit the |available_width|. | 655 // Elides |email| as needed to fit the |available_width|. |
638 base::string16 ElideEmail(const base::string16& email, float available_width); | 656 base::string16 ElideEmail(const base::string16& email, float available_width); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
683 | 701 |
684 // The background color used for drawing the selection when focused. | 702 // The background color used for drawing the selection when focused. |
685 SkColor selection_background_focused_color_; | 703 SkColor selection_background_focused_color_; |
686 | 704 |
687 // The focus state of the text. | 705 // The focus state of the text. |
688 bool focused_; | 706 bool focused_; |
689 | 707 |
690 // Composition text range. | 708 // Composition text range. |
691 Range composition_range_; | 709 Range composition_range_; |
692 | 710 |
693 // Color and style breaks, used to color and stylize ranges of text. | 711 // Color, baseline, and style breaks, used to modify ranges of text. |
694 // BreakList positions are stored with text indices, not display indices. | 712 // BreakList positions are stored with text indices, not display indices. |
695 // TODO(msw): Expand to support cursor, selection, background, etc. colors. | 713 // TODO(msw): Expand to support cursor, selection, background, etc. colors. |
696 BreakList<SkColor> colors_; | 714 BreakList<SkColor> colors_; |
715 BreakList<BaselineStyle> baselines_; | |
697 std::vector<BreakList<bool> > styles_; | 716 std::vector<BreakList<bool> > styles_; |
698 | 717 |
699 // Breaks saved without temporary composition and selection styling. | 718 // Breaks saved without temporary composition and selection styling. |
700 BreakList<SkColor> saved_colors_; | 719 BreakList<SkColor> saved_colors_; |
701 BreakList<bool> saved_underlines_; | 720 BreakList<bool> saved_underlines_; |
702 bool composition_and_selection_styles_applied_; | 721 bool composition_and_selection_styles_applied_; |
703 | 722 |
704 // A flag to obscure actual text with asterisks for password fields. | 723 // A flag to obscure actual text with asterisks for password fields. |
705 bool obscured_; | 724 bool obscured_; |
706 // The index at which the char should be revealed in the obscured text. | 725 // The index at which the char should be revealed in the obscured text. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 // Lines computed by EnsureLayout. These should be invalidated upon | 785 // Lines computed by EnsureLayout. These should be invalidated upon |
767 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 786 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
768 std::vector<internal::Line> lines_; | 787 std::vector<internal::Line> lines_; |
769 | 788 |
770 DISALLOW_COPY_AND_ASSIGN(RenderText); | 789 DISALLOW_COPY_AND_ASSIGN(RenderText); |
771 }; | 790 }; |
772 | 791 |
773 } // namespace gfx | 792 } // namespace gfx |
774 | 793 |
775 #endif // UI_GFX_RENDER_TEXT_H_ | 794 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |