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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 // Draw underline and strike-through text decorations. | 72 // Draw underline and strike-through text decorations. |
73 // Based on |SkCanvas::DrawTextDecorations()| and constants from: | 73 // Based on |SkCanvas::DrawTextDecorations()| and constants from: |
74 // third_party/skia/src/core/SkTextFormatParams.h | 74 // third_party/skia/src/core/SkTextFormatParams.h |
75 void DrawDecorations(int x, int y, int width, bool underline, bool strike, | 75 void DrawDecorations(int x, int y, int width, bool underline, bool strike, |
76 bool diagonal_strike); | 76 bool diagonal_strike); |
77 // Finishes any ongoing diagonal strike run. | 77 // Finishes any ongoing diagonal strike run. |
78 void EndDiagonalStrike(); | 78 void EndDiagonalStrike(); |
79 void DrawUnderline(int x, int y, int width); | 79 void DrawUnderline(int x, int y, int width); |
80 void DrawStrike(int x, int y, int width) const; | 80 void DrawStrike(int x, int y, int width) const; |
81 | 81 |
| 82 SkPaint paint() const { return paint_; } |
| 83 |
82 private: | 84 private: |
83 // Helper class to draw a diagonal line with multiple pieces of different | 85 // Helper class to draw a diagonal line with multiple pieces of different |
84 // lengths and colors; to support text selection appearances. | 86 // lengths and colors; to support text selection appearances. |
85 class DiagonalStrike { | 87 class DiagonalStrike { |
86 public: | 88 public: |
87 DiagonalStrike(Canvas* canvas, Point start, const SkPaint& paint); | 89 DiagonalStrike(Canvas* canvas, Point start, const SkPaint& paint); |
88 ~DiagonalStrike(); | 90 ~DiagonalStrike(); |
89 | 91 |
90 void AddPiece(int length, SkColor color); | 92 void AddPiece(int length, SkColor color); |
91 void Draw(); | 93 void Draw(); |
92 | 94 |
93 private: | 95 private: |
94 typedef std::pair<int, SkColor> Piece; | 96 typedef std::pair<int, SkColor> Piece; |
95 | 97 |
96 Canvas* canvas_; | 98 Canvas* canvas_; |
| 99 SkMatrix matrix_; |
97 const Point start_; | 100 const Point start_; |
98 SkPaint paint_; | 101 SkPaint paint_; |
99 int total_length_; | 102 int total_length_; |
100 std::vector<Piece> pieces_; | 103 std::vector<Piece> pieces_; |
101 | 104 |
102 DISALLOW_COPY_AND_ASSIGN(DiagonalStrike); | 105 DISALLOW_COPY_AND_ASSIGN(DiagonalStrike); |
103 }; | 106 }; |
104 | 107 |
105 Canvas* canvas_; | 108 Canvas* canvas_; |
106 SkCanvas* canvas_skia_; | 109 SkCanvas* canvas_skia_; |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 // heights. | 172 // heights. |
170 Size size; | 173 Size size; |
171 | 174 |
172 // Sum of preceding lines' heights. | 175 // Sum of preceding lines' heights. |
173 int preceding_heights; | 176 int preceding_heights; |
174 | 177 |
175 // Maximum baseline of all segments on this line. | 178 // Maximum baseline of all segments on this line. |
176 int baseline; | 179 int baseline; |
177 }; | 180 }; |
178 | 181 |
| 182 // Creates an SkTypeface from a font |family| name and a |gfx::Font::FontStyle|. |
| 183 skia::RefPtr<SkTypeface> CreateSkiaTypeface(const std::string& family, |
| 184 int style); |
| 185 |
179 } // namespace internal | 186 } // namespace internal |
180 | 187 |
181 // RenderText represents an abstract model of styled text and its corresponding | 188 // RenderText represents an abstract model of styled text and its corresponding |
182 // visual layout. Support is built in for a cursor, a selection, simple styling, | 189 // visual layout. Support is built in for a cursor, a selection, simple styling, |
183 // complex scripts, and bi-directional text. Implementations provide mechanisms | 190 // complex scripts, and bi-directional text. Implementations provide mechanisms |
184 // for rendering and translation between logical and visual data. | 191 // for rendering and translation between logical and visual data. |
185 class GFX_EXPORT RenderText { | 192 class GFX_EXPORT RenderText { |
186 public: | 193 public: |
187 virtual ~RenderText(); | 194 virtual ~RenderText(); |
188 | 195 |
189 // Creates a platform-specific RenderText instance. | 196 // Creates a platform-specific or cross-platform RenderText instance. |
190 static RenderText* CreateInstance(); | 197 static RenderText* CreateInstance(); |
191 | 198 |
192 const base::string16& text() const { return text_; } | 199 const base::string16& text() const { return text_; } |
193 void SetText(const base::string16& text); | 200 void SetText(const base::string16& text); |
194 | 201 |
195 HorizontalAlignment horizontal_alignment() const { | 202 HorizontalAlignment horizontal_alignment() const { |
196 return horizontal_alignment_; | 203 return horizontal_alignment_; |
197 } | 204 } |
198 void SetHorizontalAlignment(HorizontalAlignment alignment); | 205 void SetHorizontalAlignment(HorizontalAlignment alignment); |
199 | 206 |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); | 572 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); |
566 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); | 573 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
567 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); | 574 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); |
568 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); | 575 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); |
569 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); | 576 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); |
570 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); | 577 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); |
571 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); | 578 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); |
572 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); | 579 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); |
573 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); | 580 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); |
574 | 581 |
| 582 // Creates a platform-specific RenderText instance. |
| 583 static RenderText* CreateNativeInstance(); |
| 584 |
575 // Set the cursor to |position|, with the caret trailing the previous | 585 // Set the cursor to |position|, with the caret trailing the previous |
576 // grapheme, or if there is no previous grapheme, leading the cursor position. | 586 // grapheme, or if there is no previous grapheme, leading the cursor position. |
577 // If |select| is false, the selection start is moved to the same position. | 587 // If |select| is false, the selection start is moved to the same position. |
578 // If the |position| is not a cursorable position (not on grapheme boundary), | 588 // If the |position| is not a cursorable position (not on grapheme boundary), |
579 // it is a NO-OP. | 589 // it is a NO-OP. |
580 void MoveCursorTo(size_t position, bool select); | 590 void MoveCursorTo(size_t position, bool select); |
581 | 591 |
582 // Updates |layout_text_| if the text is obscured or truncated. | 592 // Updates |layout_text_| if the text is obscured or truncated. |
583 void UpdateLayoutText(); | 593 void UpdateLayoutText(); |
584 | 594 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 // Lines computed by EnsureLayout. These should be invalidated with | 716 // Lines computed by EnsureLayout. These should be invalidated with |
707 // ResetLayout and on |display_rect_| changes. | 717 // ResetLayout and on |display_rect_| changes. |
708 std::vector<internal::Line> lines_; | 718 std::vector<internal::Line> lines_; |
709 | 719 |
710 DISALLOW_COPY_AND_ASSIGN(RenderText); | 720 DISALLOW_COPY_AND_ASSIGN(RenderText); |
711 }; | 721 }; |
712 | 722 |
713 } // namespace gfx | 723 } // namespace gfx |
714 | 724 |
715 #endif // UI_GFX_RENDER_TEXT_H_ | 725 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |