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

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

Issue 924543004: adding baseline options for super/sub scripting (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Changing baseline styles from bool list to breaklist Created 5 years, 10 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.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 by derived classes to iterate colors and styles. 112 // Internal helper class used by derived classes to iterate colors and styles.
msw 2015/02/18 17:07:23 nit: // Internal helper class used to iterate colo
dschuyler 2015/02/18 22:36:02 Done.
113 class StyleIterator { 113 class StyleIterator {
114 public: 114 public:
115 StyleIterator(const BreakList<SkColor>& colors, 115 StyleIterator(const BreakList<SkColor>& colors,
116 const BreakList<BaselineStyle>& baselines,
116 const std::vector<BreakList<bool> >& styles); 117 const std::vector<BreakList<bool> >& styles);
117 ~StyleIterator(); 118 ~StyleIterator();
118 119
119 // Get the colors and styles at the current iterator position. 120 // Get the colors and styles at the current iterator position.
120 SkColor color() const { return color_->second; } 121 SkColor color() const { return color_->second; }
122 BaselineStyle baseline() const { return (BaselineStyle)baseline_->second; }
msw 2015/02/18 17:07:23 nit: is the cast needed? if so, use static_cast in
dschuyler 2015/02/18 22:36:02 Done.
121 bool style(TextStyle s) const { return style_[s]->second; } 123 bool style(TextStyle s) const { return style_[s]->second; }
122 124
123 // Get the intersecting range of the current iterator set. 125 // Get the intersecting range of the current iterator set.
124 Range GetRange() const; 126 Range GetRange() const;
125 127
126 // Update the iterator to point to colors and styles applicable at |position|. 128 // Update the iterator to point to colors and styles applicable at |position|.
127 void UpdatePosition(size_t position); 129 void UpdatePosition(size_t position);
128 130
129 private: 131 private:
130 BreakList<SkColor> colors_; 132 BreakList<SkColor> colors_;
133 BreakList<BaselineStyle> baselines_;
131 std::vector<BreakList<bool> > styles_; 134 std::vector<BreakList<bool> > styles_;
132 135
133 BreakList<SkColor>::const_iterator color_; 136 BreakList<SkColor>::const_iterator color_;
137 BreakList<BaselineStyle>::const_iterator baseline_;
134 std::vector<BreakList<bool>::const_iterator> style_; 138 std::vector<BreakList<bool>::const_iterator> style_;
135 139
136 DISALLOW_COPY_AND_ASSIGN(StyleIterator); 140 DISALLOW_COPY_AND_ASSIGN(StyleIterator);
137 }; 141 };
138 142
139 // Line segments are slices of the layout text to be rendered on a single line. 143 // Line segments are slices of the layout text to be rendered on a single line.
140 struct LineSegment { 144 struct LineSegment {
141 LineSegment(); 145 LineSegment();
142 ~LineSegment(); 146 ~LineSegment();
143 147
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 void SelectWord(); 333 void SelectWord();
330 334
331 const Range& GetCompositionRange() const; 335 const Range& GetCompositionRange() const;
332 void SetCompositionRange(const Range& composition_range); 336 void SetCompositionRange(const Range& composition_range);
333 337
334 // Set the text color over the entire text or a logical character range. 338 // Set the text color over the entire text or a logical character range.
335 // The |range| should be valid, non-reversed, and within [0, text().length()]. 339 // The |range| should be valid, non-reversed, and within [0, text().length()].
336 void SetColor(SkColor value); 340 void SetColor(SkColor value);
337 void ApplyColor(SkColor value, const Range& range); 341 void ApplyColor(SkColor value, const Range& range);
338 342
343 // Set the text baseline style over the entire text or a logical character
msw 2015/02/18 17:07:23 nit: remove "text" for cleaner comment wrapping.
dschuyler 2015/02/18 22:36:02 Done.
344 // range. The |range| should be valid, non-reversed, and within
345 // [0, text().length()].
346 void SetBaselineStyle(BaselineStyle value);
347 void ApplyBaselineStyle(BaselineStyle value, const Range& range);
348
339 // Set various text styles over the entire text or a logical character range. 349 // Set various text styles over the entire text or a logical character range.
340 // The respective |style| is applied if |value| is true, or removed if false. 350 // The respective |style| is applied if |value| is true, or removed if false.
341 // The |range| should be valid, non-reversed, and within [0, text().length()]. 351 // The |range| should be valid, non-reversed, and within [0, text().length()].
342 void SetStyle(TextStyle style, bool value); 352 void SetStyle(TextStyle style, bool value);
343 void ApplyStyle(TextStyle style, bool value, const Range& range); 353 void ApplyStyle(TextStyle style, bool value, const Range& range);
344 354
345 // Returns whether this style is enabled consistently across the entire 355 // Returns whether this style is enabled consistently across the entire
346 // RenderText. 356 // RenderText.
347 bool GetStyle(TextStyle style) const; 357 bool GetStyle(TextStyle style) const;
348 358
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
442 // Rect can't have a negative width.) 452 // Rect can't have a negative width.)
443 virtual Range GetGlyphBounds(size_t index) = 0; 453 virtual Range GetGlyphBounds(size_t index) = 0;
444 454
445 const Vector2d& GetUpdatedDisplayOffset(); 455 const Vector2d& GetUpdatedDisplayOffset();
446 void SetDisplayOffset(int horizontal_offset); 456 void SetDisplayOffset(int horizontal_offset);
447 457
448 protected: 458 protected:
449 RenderText(); 459 RenderText();
450 460
451 const BreakList<SkColor>& colors() const { return colors_; } 461 const BreakList<SkColor>& colors() const { return colors_; }
462 const BreakList<BaselineStyle>& baselines() const { return baselines_; }
452 const std::vector<BreakList<bool> >& styles() const { return styles_; } 463 const std::vector<BreakList<bool> >& styles() const { return styles_; }
453 464
454 const std::vector<internal::Line>& lines() const { return lines_; } 465 const std::vector<internal::Line>& lines() const { return lines_; }
455 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 466 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
456 467
457 // Returns the baseline of the current text. The return value depends on 468 // Returns the baseline of the current text. The return value depends on
458 // the text and its layout while the return value of GetBaseline() doesn't. 469 // the text and its layout while the return value of GetBaseline() doesn't.
459 // GetAlignmentOffset() takes into account the difference between them. 470 // GetAlignmentOffset() takes into account the difference between them.
460 // 471 //
461 // We'd like a RenderText to show the text always on the same baseline 472 // We'd like a RenderText to show the text always on the same baseline
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 676
666 // The background color used for drawing the selection when focused. 677 // The background color used for drawing the selection when focused.
667 SkColor selection_background_focused_color_; 678 SkColor selection_background_focused_color_;
668 679
669 // The focus state of the text. 680 // The focus state of the text.
670 bool focused_; 681 bool focused_;
671 682
672 // Composition text range. 683 // Composition text range.
673 Range composition_range_; 684 Range composition_range_;
674 685
675 // Color and style breaks, used to color and stylize ranges of text. 686 // Color and style breaks, used to color and stylize ranges of text.
msw 2015/02/18 17:07:23 nit: "// Color, baseline, and style breaks, used t
dschuyler 2015/02/18 22:36:02 Done.
676 // BreakList positions are stored with text indices, not layout indices. 687 // BreakList positions are stored with text indices, not layout indices.
677 // TODO(msw): Expand to support cursor, selection, background, etc. colors. 688 // TODO(msw): Expand to support cursor, selection, background, etc. colors.
678 BreakList<SkColor> colors_; 689 BreakList<SkColor> colors_;
690 BreakList<BaselineStyle> baselines_;
679 std::vector<BreakList<bool> > styles_; 691 std::vector<BreakList<bool> > styles_;
680 692
681 // Breaks saved without temporary composition and selection styling. 693 // Breaks saved without temporary composition and selection styling.
682 BreakList<SkColor> saved_colors_; 694 BreakList<SkColor> saved_colors_;
683 BreakList<bool> saved_underlines_; 695 BreakList<bool> saved_underlines_;
684 bool composition_and_selection_styles_applied_; 696 bool composition_and_selection_styles_applied_;
685 697
686 // A flag to obscure actual text with asterisks for password fields. 698 // A flag to obscure actual text with asterisks for password fields.
687 bool obscured_; 699 bool obscured_;
688 // The index at which the char should be revealed in the obscured text. 700 // The index at which the char should be revealed in the obscured text.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 // Lines computed by EnsureLayout. These should be invalidated with 753 // Lines computed by EnsureLayout. These should be invalidated with
742 // ResetLayout and on |display_rect_| changes. 754 // ResetLayout and on |display_rect_| changes.
743 std::vector<internal::Line> lines_; 755 std::vector<internal::Line> lines_;
744 756
745 DISALLOW_COPY_AND_ASSIGN(RenderText); 757 DISALLOW_COPY_AND_ASSIGN(RenderText);
746 }; 758 };
747 759
748 } // namespace gfx 760 } // namespace gfx
749 761
750 #endif // UI_GFX_RENDER_TEXT_H_ 762 #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.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698