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