| 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 BreakList<BaselineStyle>& baselines, |
| 116 const std::vector<BreakList<bool> >& styles); | 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 void SelectWord(); | 327 void SelectWord(); |
| 324 | 328 |
| 325 const Range& GetCompositionRange() const; | 329 const Range& GetCompositionRange() const; |
| 326 void SetCompositionRange(const Range& composition_range); | 330 void SetCompositionRange(const Range& composition_range); |
| 327 | 331 |
| 328 // Set the text color over the entire text or a logical character range. | 332 // 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()]. | 333 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
| 330 void SetColor(SkColor value); | 334 void SetColor(SkColor value); |
| 331 void ApplyColor(SkColor value, const Range& range); | 335 void ApplyColor(SkColor value, const Range& range); |
| 332 | 336 |
| 337 // Set the baseline style over the entire text or a logical character range. |
| 338 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
| 339 void SetBaselineStyle(BaselineStyle value); |
| 340 void ApplyBaselineStyle(BaselineStyle value, const Range& range); |
| 341 |
| 333 // Set various text styles over the entire text or a logical character range. | 342 // 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. | 343 // 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()]. | 344 // The |range| should be valid, non-reversed, and within [0, text().length()]. |
| 336 void SetStyle(TextStyle style, bool value); | 345 void SetStyle(TextStyle style, bool value); |
| 337 void ApplyStyle(TextStyle style, bool value, const Range& range); | 346 void ApplyStyle(TextStyle style, bool value, const Range& range); |
| 338 | 347 |
| 339 // Returns whether this style is enabled consistently across the entire | 348 // Returns whether this style is enabled consistently across the entire |
| 340 // RenderText. | 349 // RenderText. |
| 341 bool GetStyle(TextStyle style) const; | 350 bool GetStyle(TextStyle style) const; |
| 342 | 351 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 protected: | 456 protected: |
| 448 RenderText(); | 457 RenderText(); |
| 449 | 458 |
| 450 // NOTE: The value of these accessors may be stale. Please make sure | 459 // NOTE: The value of these accessors may be stale. Please make sure |
| 451 // that these fields are up-to-date before accessing them. | 460 // that these fields are up-to-date before accessing them. |
| 452 const base::string16& layout_text() const { return layout_text_; } | 461 const base::string16& layout_text() const { return layout_text_; } |
| 453 const base::string16& display_text() const { return display_text_; } | 462 const base::string16& display_text() const { return display_text_; } |
| 454 bool text_elided() const { return text_elided_; } | 463 bool text_elided() const { return text_elided_; } |
| 455 | 464 |
| 456 const BreakList<SkColor>& colors() const { return colors_; } | 465 const BreakList<SkColor>& colors() const { return colors_; } |
| 466 const BreakList<BaselineStyle>& baselines() const { return baselines_; } |
| 457 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 467 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
| 458 | 468 |
| 459 const std::vector<internal::Line>& lines() const { return lines_; } | 469 const std::vector<internal::Line>& lines() const { return lines_; } |
| 460 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } | 470 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
| 461 | 471 |
| 462 // Returns the baseline of the current text. The return value depends on | 472 // 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. | 473 // the text and its layout while the return value of GetBaseline() doesn't. |
| 464 // GetAlignmentOffset() takes into account the difference between them. | 474 // GetAlignmentOffset() takes into account the difference between them. |
| 465 // | 475 // |
| 466 // We'd like a RenderText to show the text always on the same baseline | 476 // 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... |
| 683 | 693 |
| 684 // The background color used for drawing the selection when focused. | 694 // The background color used for drawing the selection when focused. |
| 685 SkColor selection_background_focused_color_; | 695 SkColor selection_background_focused_color_; |
| 686 | 696 |
| 687 // The focus state of the text. | 697 // The focus state of the text. |
| 688 bool focused_; | 698 bool focused_; |
| 689 | 699 |
| 690 // Composition text range. | 700 // Composition text range. |
| 691 Range composition_range_; | 701 Range composition_range_; |
| 692 | 702 |
| 693 // Color and style breaks, used to color and stylize ranges of text. | 703 // Color, baseline, and style breaks, used to modify ranges of text. |
| 694 // BreakList positions are stored with text indices, not display indices. | 704 // BreakList positions are stored with text indices, not display indices. |
| 695 // TODO(msw): Expand to support cursor, selection, background, etc. colors. | 705 // TODO(msw): Expand to support cursor, selection, background, etc. colors. |
| 696 BreakList<SkColor> colors_; | 706 BreakList<SkColor> colors_; |
| 707 BreakList<BaselineStyle> baselines_; |
| 697 std::vector<BreakList<bool> > styles_; | 708 std::vector<BreakList<bool> > styles_; |
| 698 | 709 |
| 699 // Breaks saved without temporary composition and selection styling. | 710 // Breaks saved without temporary composition and selection styling. |
| 700 BreakList<SkColor> saved_colors_; | 711 BreakList<SkColor> saved_colors_; |
| 701 BreakList<bool> saved_underlines_; | 712 BreakList<bool> saved_underlines_; |
| 702 bool composition_and_selection_styles_applied_; | 713 bool composition_and_selection_styles_applied_; |
| 703 | 714 |
| 704 // A flag to obscure actual text with asterisks for password fields. | 715 // A flag to obscure actual text with asterisks for password fields. |
| 705 bool obscured_; | 716 bool obscured_; |
| 706 // The index at which the char should be revealed in the obscured text. | 717 // 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 | 777 // Lines computed by EnsureLayout. These should be invalidated upon |
| 767 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 778 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
| 768 std::vector<internal::Line> lines_; | 779 std::vector<internal::Line> lines_; |
| 769 | 780 |
| 770 DISALLOW_COPY_AND_ASSIGN(RenderText); | 781 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 771 }; | 782 }; |
| 772 | 783 |
| 773 } // namespace gfx | 784 } // namespace gfx |
| 774 | 785 |
| 775 #endif // UI_GFX_RENDER_TEXT_H_ | 786 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |