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_; } | |
Alexei Svitkine (slow)
2014/05/12 15:58:31
Is this used somewhere?
ckocagil
2014/05/13 15:03:48
Not anymore, removed.
| |
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 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
562 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); | 569 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); |
563 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); | 570 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
564 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); | 571 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); |
565 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); | 572 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); |
566 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); | 573 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); |
567 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); | 574 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); |
568 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); | 575 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); |
569 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); | 576 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); |
570 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); | 577 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); |
571 | 578 |
579 // Creates a platform-specific RenderText instance. | |
580 static RenderText* CreateNativeInstance(); | |
581 | |
572 // Set the cursor to |position|, with the caret trailing the previous | 582 // Set the cursor to |position|, with the caret trailing the previous |
573 // grapheme, or if there is no previous grapheme, leading the cursor position. | 583 // 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. | 584 // 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), | 585 // If the |position| is not a cursorable position (not on grapheme boundary), |
576 // it is a NO-OP. | 586 // it is a NO-OP. |
577 void MoveCursorTo(size_t position, bool select); | 587 void MoveCursorTo(size_t position, bool select); |
578 | 588 |
579 // Updates |layout_text_| if the text is obscured or truncated. | 589 // Updates |layout_text_| if the text is obscured or truncated. |
580 void UpdateLayoutText(); | 590 void UpdateLayoutText(); |
581 | 591 |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
703 // Lines computed by EnsureLayout. These should be invalidated with | 713 // Lines computed by EnsureLayout. These should be invalidated with |
704 // ResetLayout and on |display_rect_| changes. | 714 // ResetLayout and on |display_rect_| changes. |
705 std::vector<internal::Line> lines_; | 715 std::vector<internal::Line> lines_; |
706 | 716 |
707 DISALLOW_COPY_AND_ASSIGN(RenderText); | 717 DISALLOW_COPY_AND_ASSIGN(RenderText); |
708 }; | 718 }; |
709 | 719 |
710 } // namespace gfx | 720 } // namespace gfx |
711 | 721 |
712 #endif // UI_GFX_RENDER_TEXT_H_ | 722 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |