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

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: Removed some debug code 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') | ui/gfx/render_text_unittest.cc » ('J')
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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 to iterate colors, baselines, and styles. 112 // Internal helper class used to iterate colors, baselines, and styles.
msw 2015/03/30 21:14:35 nit: "used to iterate ranged style values."
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.
msw 2015/03/30 21:14:35 nit: "Get the ranged style values at the"
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|.
msw 2015/03/30 21:14:35 nit: "point to ranged values applicable"
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 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 void SelectAll(bool reversed); 338 void SelectAll(bool reversed);
335 339
336 // 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
337 // selection, the selection bounds are extended to their nearest word 341 // selection, the selection bounds are extended to their nearest word
338 // boundaries. 342 // boundaries.
339 void SelectWord(); 343 void SelectWord();
340 344
341 const Range& GetCompositionRange() const; 345 const Range& GetCompositionRange() const;
342 void SetCompositionRange(const Range& composition_range); 346 void SetCompositionRange(const Range& composition_range);
343 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.
msw 2015/03/30 21:14:35 I believe that font size literal values (15pt, 17p
351 void SetFontSize(uint32_t value);
352 void ApplyFontSize(uint32_t value, const Range& range);
353
344 // 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.
345 // 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()].
346 void SetColor(SkColor value); 356 void SetColor(SkColor value);
347 void ApplyColor(SkColor value, const Range& range); 357 void ApplyColor(SkColor value, const Range& range);
348 358
349 // 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.
350 // 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()].
351 void SetBaselineStyle(BaselineStyle value); 361 void SetBaselineStyle(BaselineStyle value);
352 void ApplyBaselineStyle(BaselineStyle value, const Range& range); 362 void ApplyBaselineStyle(BaselineStyle value, const Range& range);
353 363
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
471 481
472 protected: 482 protected:
473 RenderText(); 483 RenderText();
474 484
475 // 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
476 // that these fields are up-to-date before accessing them. 486 // that these fields are up-to-date before accessing them.
477 const base::string16& layout_text() const { return layout_text_; } 487 const base::string16& layout_text() const { return layout_text_; }
478 const base::string16& display_text() const { return display_text_; } 488 const base::string16& display_text() const { return display_text_; }
479 bool text_elided() const { return text_elided_; } 489 bool text_elided() const { return text_elided_; }
480 490
491 const BreakList<uint32_t>& font_sizes() const { return font_sizes_; }
481 const BreakList<SkColor>& colors() const { return colors_; } 492 const BreakList<SkColor>& colors() const { return colors_; }
482 const BreakList<BaselineStyle>& baselines() const { return baselines_; } 493 const BreakList<BaselineStyle>& baselines() const { return baselines_; }
483 const std::vector<BreakList<bool> >& styles() const { return styles_; } 494 const std::vector<BreakList<bool> >& styles() const { return styles_; }
484 495
485 const std::vector<internal::Line>& lines() const { return lines_; } 496 const std::vector<internal::Line>& lines() const { return lines_; }
486 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 497 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
487 498
488 // 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
489 // 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.
490 // GetAlignmentOffset() takes into account the difference between them. 501 // GetAlignmentOffset() takes into account the difference between them.
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 private: 630 private:
620 friend class RenderTextTest; 631 friend class RenderTextTest;
621 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyles); 632 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyles);
622 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetStyles); 633 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetStyles);
623 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyles); 634 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyles);
624 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, AppendTextKeepsStyles); 635 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, AppendTextKeepsStyles);
625 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); 636 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText);
626 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); 637 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText);
627 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText); 638 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText);
628 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText); 639 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText);
640 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, FontSize);
629 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText); 641 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText);
630 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); 642 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText);
631 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); 643 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions);
632 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, MinLineHeight); 644 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, MinLineHeight);
633 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); 645 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels);
634 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); 646 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset);
635 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); 647 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL);
636 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); 648 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth);
637 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); 649 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth);
638 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); 650 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth);
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 732
721 // The background color used for drawing the selection when focused. 733 // The background color used for drawing the selection when focused.
722 SkColor selection_background_focused_color_; 734 SkColor selection_background_focused_color_;
723 735
724 // The focus state of the text. 736 // The focus state of the text.
725 bool focused_; 737 bool focused_;
726 738
727 // Composition text range. 739 // Composition text range.
728 Range composition_range_; 740 Range composition_range_;
729 741
730 // Color, baseline, and style breaks, used to modify ranges of text. 742 // Color, baseline, and style breaks, used to modify ranges of text.
msw 2015/03/30 21:14:35 "Text styling breaks"
731 // BreakList positions are stored with text indices, not display indices. 743 // BreakList positions are stored with text indices, not display indices.
744 BreakList<uint32_t> font_sizes_;
msw 2015/03/30 21:14:35 nit: sizes_ or size_deltas_ might be cleaner.
732 // TODO(msw): Expand to support cursor, selection, background, etc. colors. 745 // TODO(msw): Expand to support cursor, selection, background, etc. colors.
733 BreakList<SkColor> colors_; 746 BreakList<SkColor> colors_;
734 BreakList<BaselineStyle> baselines_; 747 BreakList<BaselineStyle> baselines_;
735 std::vector<BreakList<bool> > styles_; 748 std::vector<BreakList<bool> > styles_;
736 749
737 // Breaks saved without temporary composition and selection styling. 750 // Breaks saved without temporary composition and selection styling.
738 BreakList<SkColor> saved_colors_; 751 BreakList<SkColor> saved_colors_;
739 BreakList<bool> saved_underlines_; 752 BreakList<bool> saved_underlines_;
740 bool composition_and_selection_styles_applied_; 753 bool composition_and_selection_styles_applied_;
741 754
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
808 // Lines computed by EnsureLayout. These should be invalidated upon 821 // Lines computed by EnsureLayout. These should be invalidated upon
809 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. 822 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls.
810 std::vector<internal::Line> lines_; 823 std::vector<internal::Line> lines_;
811 824
812 DISALLOW_COPY_AND_ASSIGN(RenderText); 825 DISALLOW_COPY_AND_ASSIGN(RenderText);
813 }; 826 };
814 827
815 } // namespace gfx 828 } // namespace gfx
816 829
817 #endif // UI_GFX_RENDER_TEXT_H_ 830 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | ui/gfx/render_text_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698