Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: ui/gfx/render_text.h

Issue 1020853018: DNCI [RenderText] Added font size options in RenderText. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added font sizes to mac font style iterator Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 to iterate colors, baselines, 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<uint32_t>& font_sizes,
116 const BreakList<SkColor>& colors,
116 const BreakList<BaselineStyle>& baselines, 117 const BreakList<BaselineStyle>& baselines,
117 const std::vector<BreakList<bool>>& styles); 118 const std::vector<BreakList<bool>>& styles);
118 ~StyleIterator(); 119 ~StyleIterator();
119 120
120 // Get the colors and styles at the current iterator position. 121 // Get the colors and styles at the current iterator position.
122 uint32_t font_size() const { return font_size_->second; }
121 SkColor color() const { return color_->second; } 123 SkColor color() const { return color_->second; }
122 BaselineStyle baseline() const { return baseline_->second; } 124 BaselineStyle baseline() const { return baseline_->second; }
123 bool style(TextStyle s) const { return style_[s]->second; } 125 bool style(TextStyle s) const { return style_[s]->second; }
124 126
125 // Get the intersecting range of the current iterator set. 127 // Get the intersecting range of the current iterator set.
126 Range GetRange() const; 128 Range GetRange() const;
127 129
128 // Update the iterator to point to colors and styles applicable at |position|. 130 // Update the iterator to point to colors and styles applicable at |position|.
129 void UpdatePosition(size_t position); 131 void UpdatePosition(size_t position);
130 132
131 private: 133 private:
134 BreakList<uint32_t> font_sizes_;
132 BreakList<SkColor> colors_; 135 BreakList<SkColor> colors_;
133 BreakList<BaselineStyle> baselines_; 136 BreakList<BaselineStyle> baselines_;
134 std::vector<BreakList<bool> > styles_; 137 std::vector<BreakList<bool> > styles_;
135 138
139 BreakList<uint32_t>::const_iterator font_size_;
136 BreakList<SkColor>::const_iterator color_; 140 BreakList<SkColor>::const_iterator color_;
137 BreakList<BaselineStyle>::const_iterator baseline_; 141 BreakList<BaselineStyle>::const_iterator baseline_;
138 std::vector<BreakList<bool>::const_iterator> style_; 142 std::vector<BreakList<bool>::const_iterator> style_;
139 143
140 DISALLOW_COPY_AND_ASSIGN(StyleIterator); 144 DISALLOW_COPY_AND_ASSIGN(StyleIterator);
141 }; 145 };
142 146
143 // Line segments are slices of the display text to be rendered on a single line. 147 // Line segments are slices of the display text to be rendered on a single line.
144 struct LineSegment { 148 struct LineSegment {
145 LineSegment(); 149 LineSegment();
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 211
208 const base::string16& text() const { return text_; } 212 const base::string16& text() const { return text_; }
209 void SetText(const base::string16& text); 213 void SetText(const base::string16& text);
210 void AppendText(const base::string16& text); 214 void AppendText(const base::string16& text);
211 215
212 HorizontalAlignment horizontal_alignment() const { 216 HorizontalAlignment horizontal_alignment() const {
213 return horizontal_alignment_; 217 return horizontal_alignment_;
214 } 218 }
215 void SetHorizontalAlignment(HorizontalAlignment alignment); 219 void SetHorizontalAlignment(HorizontalAlignment alignment);
216 220
221 VerticalAlignment vertical_alignment() const { return vertical_alignment_; }
msw 2015/03/26 23:07:28 You should upload CLs that are rebased on your loc
dschuyler 2015/03/27 21:32:13 Done.
222 void SetVerticalAlignment(VerticalAlignment alignment);
223
217 const FontList& font_list() const { return font_list_; } 224 const FontList& font_list() const { return font_list_; }
218 void SetFontList(const FontList& font_list); 225 void SetFontList(const FontList& font_list);
219 226
220 bool cursor_enabled() const { return cursor_enabled_; } 227 bool cursor_enabled() const { return cursor_enabled_; }
221 void SetCursorEnabled(bool cursor_enabled); 228 void SetCursorEnabled(bool cursor_enabled);
222 229
223 bool cursor_visible() const { return cursor_visible_; } 230 bool cursor_visible() const { return cursor_visible_; }
224 void set_cursor_visible(bool visible) { cursor_visible_ = visible; } 231 void set_cursor_visible(bool visible) { cursor_visible_ = visible; }
225 232
226 bool insert_mode() const { return insert_mode_; } 233 bool insert_mode() const { return insert_mode_; }
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 void SelectAll(bool reversed); 338 void SelectAll(bool reversed);
332 339
333 // Selects the word at the current cursor position. If there is a non-empty 340 // Selects the word at the current cursor position. If there is a non-empty
334 // selection, the selection bounds are extended to their nearest word 341 // selection, the selection bounds are extended to their nearest word
335 // boundaries. 342 // boundaries.
336 void SelectWord(); 343 void SelectWord();
337 344
338 const Range& GetCompositionRange() const; 345 const Range& GetCompositionRange() const;
339 void SetCompositionRange(const Range& composition_range); 346 void SetCompositionRange(const Range& composition_range);
340 347
348 // Set the font size over the entire text or a logical character range.
349 // The |range| should be valid, non-reversed, and within [0, text().length()].
350 // A |value| of zero will expand to the default font size.
351 void SetFontSize(uint32_t value);
352 void ApplyFontSize(uint32_t value, const Range& range);
353
341 // Set the text color over the entire text or a logical character range. 354 // Set the text color over the entire text or a logical character range.
342 // The |range| should be valid, non-reversed, and within [0, text().length()]. 355 // The |range| should be valid, non-reversed, and within [0, text().length()].
343 void SetColor(SkColor value); 356 void SetColor(SkColor value);
344 void ApplyColor(SkColor value, const Range& range); 357 void ApplyColor(SkColor value, const Range& range);
345 358
346 // Set the baseline style over the entire text or a logical character range. 359 // Set the baseline style over the entire text or a logical character range.
347 // The |range| should be valid, non-reversed, and within [0, text().length()]. 360 // The |range| should be valid, non-reversed, and within [0, text().length()].
348 void SetBaselineStyle(BaselineStyle value); 361 void SetBaselineStyle(BaselineStyle value);
349 void ApplyBaselineStyle(BaselineStyle value, const Range& range); 362 void ApplyBaselineStyle(BaselineStyle value, const Range& range);
350 363
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 481
469 protected: 482 protected:
470 RenderText(); 483 RenderText();
471 484
472 // NOTE: The value of these accessors may be stale. Please make sure 485 // NOTE: The value of these accessors may be stale. Please make sure
473 // that these fields are up-to-date before accessing them. 486 // that these fields are up-to-date before accessing them.
474 const base::string16& layout_text() const { return layout_text_; } 487 const base::string16& layout_text() const { return layout_text_; }
475 const base::string16& display_text() const { return display_text_; } 488 const base::string16& display_text() const { return display_text_; }
476 bool text_elided() const { return text_elided_; } 489 bool text_elided() const { return text_elided_; }
477 490
491 const BreakList<uint32_t>& font_sizes() const { return font_sizes_; }
478 const BreakList<SkColor>& colors() const { return colors_; } 492 const BreakList<SkColor>& colors() const { return colors_; }
479 const BreakList<BaselineStyle>& baselines() const { return baselines_; } 493 const BreakList<BaselineStyle>& baselines() const { return baselines_; }
480 const std::vector<BreakList<bool> >& styles() const { return styles_; } 494 const std::vector<BreakList<bool> >& styles() const { return styles_; }
481 495
482 const std::vector<internal::Line>& lines() const { return lines_; } 496 const std::vector<internal::Line>& lines() const { return lines_; }
483 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 497 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
484 498
485 // Returns the baseline of the current text. The return value depends on 499 // Returns the baseline of the current text. The return value depends on
486 // the text and its layout while the return value of GetBaseline() doesn't. 500 // the text and its layout while the return value of GetBaseline() doesn't.
487 // GetAlignmentOffset() takes into account the difference between them. 501 // GetAlignmentOffset() takes into account the difference between them.
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
615 629
616 private: 630 private:
617 friend class RenderTextTest; 631 friend class RenderTextTest;
618 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyles); 632 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyles);
619 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetStyles); 633 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetStyles);
620 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyles); 634 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyles);
621 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); 635 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText);
622 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); 636 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText);
623 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText); 637 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText);
624 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText); 638 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText);
639 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, FontSize);
625 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText); 640 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText);
626 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); 641 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText);
627 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); 642 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions);
628 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, MinLineHeight); 643 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, MinLineHeight);
629 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); 644 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels);
630 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); 645 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset);
631 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); 646 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL);
632 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); 647 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth);
633 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); 648 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth);
634 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); 649 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth);
635 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); 650 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline);
636 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, NewlineWithoutMultilineFlag); 651 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, NewlineWithoutMultilineFlag);
637 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GlyphBounds); 652 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GlyphBounds);
638 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_GlyphBounds); 653 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, HarfBuzz_GlyphBounds);
639 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, 654 FRIEND_TEST_ALL_PREFIXES(RenderTextTest,
640 MoveCursorLeftRight_MeiryoUILigatures); 655 MoveCursorLeftRight_MeiryoUILigatures);
641 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Win_LogicalClusters); 656 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Win_LogicalClusters);
642 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SameFontForParentheses); 657 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SameFontForParentheses);
643 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, BreakRunsByUnicodeBlocks); 658 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, BreakRunsByUnicodeBlocks);
644 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes); 659 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes);
645 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StringFitsOwnWidth); 660 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StringFitsOwnWidth);
661 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, VerticalAlignement);
646 662
647 // Set the cursor to |position|, with the caret trailing the previous 663 // Set the cursor to |position|, with the caret trailing the previous
648 // grapheme, or if there is no previous grapheme, leading the cursor position. 664 // grapheme, or if there is no previous grapheme, leading the cursor position.
649 // If |select| is false, the selection start is moved to the same position. 665 // If |select| is false, the selection start is moved to the same position.
650 // If the |position| is not a cursorable position (not on grapheme boundary), 666 // If the |position| is not a cursorable position (not on grapheme boundary),
651 // it is a NO-OP. 667 // it is a NO-OP.
652 void MoveCursorTo(size_t position, bool select); 668 void MoveCursorTo(size_t position, bool select);
653 669
654 // Updates |layout_text_| and |display_text_| as needed (or marks them dirty). 670 // Updates |layout_text_| and |display_text_| as needed (or marks them dirty).
655 void OnTextAttributeChanged(); 671 void OnTextAttributeChanged();
(...skipping 16 matching lines...) Expand all
672 // Draw the selection. 688 // Draw the selection.
673 void DrawSelection(Canvas* canvas); 689 void DrawSelection(Canvas* canvas);
674 690
675 // Logical UTF-16 string data to be drawn. 691 // Logical UTF-16 string data to be drawn.
676 base::string16 text_; 692 base::string16 text_;
677 693
678 // Horizontal alignment of the text with respect to |display_rect_|. The 694 // Horizontal alignment of the text with respect to |display_rect_|. The
679 // default is to align left if the application UI is LTR and right if RTL. 695 // default is to align left if the application UI is LTR and right if RTL.
680 HorizontalAlignment horizontal_alignment_; 696 HorizontalAlignment horizontal_alignment_;
681 697
698 // Vertical alignment of the text with respect to |display_rect_|. The
699 // default is to vertically align middle.
700 VerticalAlignment vertical_alignment_;
701
682 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. 702 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT.
683 DirectionalityMode directionality_mode_; 703 DirectionalityMode directionality_mode_;
684 704
685 // The cached text direction, potentially computed from the text or UI locale. 705 // The cached text direction, potentially computed from the text or UI locale.
686 // Use GetTextDirection(), do not use this potentially invalid value directly! 706 // Use GetTextDirection(), do not use this potentially invalid value directly!
687 base::i18n::TextDirection text_direction_; 707 base::i18n::TextDirection text_direction_;
688 708
689 // A list of fonts used to render |text_|. 709 // A list of fonts used to render |text_|.
690 FontList font_list_; 710 FontList font_list_;
691 711
(...skipping 21 matching lines...) Expand all
713 SkColor selection_background_focused_color_; 733 SkColor selection_background_focused_color_;
714 734
715 // The focus state of the text. 735 // The focus state of the text.
716 bool focused_; 736 bool focused_;
717 737
718 // Composition text range. 738 // Composition text range.
719 Range composition_range_; 739 Range composition_range_;
720 740
721 // Color, baseline, and style breaks, used to modify ranges of text. 741 // Color, baseline, and style breaks, used to modify ranges of text.
722 // BreakList positions are stored with text indices, not display indices. 742 // BreakList positions are stored with text indices, not display indices.
743 BreakList<uint32_t> font_sizes_;
723 // TODO(msw): Expand to support cursor, selection, background, etc. colors. 744 // TODO(msw): Expand to support cursor, selection, background, etc. colors.
724 BreakList<SkColor> colors_; 745 BreakList<SkColor> colors_;
725 BreakList<BaselineStyle> baselines_; 746 BreakList<BaselineStyle> baselines_;
726 std::vector<BreakList<bool> > styles_; 747 std::vector<BreakList<bool> > styles_;
727 748
728 // Breaks saved without temporary composition and selection styling. 749 // Breaks saved without temporary composition and selection styling.
729 BreakList<SkColor> saved_colors_; 750 BreakList<SkColor> saved_colors_;
730 BreakList<bool> saved_underlines_; 751 BreakList<bool> saved_underlines_;
731 bool composition_and_selection_styles_applied_; 752 bool composition_and_selection_styles_applied_;
732 753
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 // Lines computed by EnsureLayout. These should be invalidated upon 820 // Lines computed by EnsureLayout. These should be invalidated upon
800 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. 821 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls.
801 std::vector<internal::Line> lines_; 822 std::vector<internal::Line> lines_;
802 823
803 DISALLOW_COPY_AND_ASSIGN(RenderText); 824 DISALLOW_COPY_AND_ASSIGN(RenderText);
804 }; 825 };
805 826
806 } // namespace gfx 827 } // namespace gfx
807 828
808 #endif // UI_GFX_RENDER_TEXT_H_ 829 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698