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

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

Issue 2969623004: RenderText: Allow strike-through line thickness to be customized. (Closed)
Patch Set: Reincorporate URL bar unittest improvements. Created 3 years, 5 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
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 <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 explicit SkiaTextRenderer(Canvas* canvas); 56 explicit SkiaTextRenderer(Canvas* canvas);
57 virtual ~SkiaTextRenderer(); 57 virtual ~SkiaTextRenderer();
58 58
59 void SetDrawLooper(sk_sp<SkDrawLooper> draw_looper); 59 void SetDrawLooper(sk_sp<SkDrawLooper> draw_looper);
60 void SetFontRenderParams(const FontRenderParams& params, 60 void SetFontRenderParams(const FontRenderParams& params,
61 bool subpixel_rendering_suppressed); 61 bool subpixel_rendering_suppressed);
62 void SetTypeface(sk_sp<SkTypeface> typeface); 62 void SetTypeface(sk_sp<SkTypeface> typeface);
63 void SetTextSize(SkScalar size); 63 void SetTextSize(SkScalar size);
64 void SetForegroundColor(SkColor foreground); 64 void SetForegroundColor(SkColor foreground);
65 void SetShader(std::unique_ptr<cc::PaintShader> shader); 65 void SetShader(std::unique_ptr<cc::PaintShader> shader);
66 // Sets underline metrics to use if the text will be drawn with an underline.
67 // If not set, default values based on the size of the text will be used. The
68 // two metrics must be set together.
69 void SetUnderlineMetrics(SkScalar thickness, SkScalar position);
70 void DrawSelection(const std::vector<Rect>& selection, SkColor color); 66 void DrawSelection(const std::vector<Rect>& selection, SkColor color);
71 virtual void DrawPosText(const SkPoint* pos, 67 virtual void DrawPosText(const SkPoint* pos,
72 const uint16_t* glyphs, 68 const uint16_t* glyphs,
73 size_t glyph_count); 69 size_t glyph_count);
74 // Draw underline and strike-through text decorations.
75 // Based on |SkCanvas::DrawTextDecorations()| and constants from:
76 // third_party/skia/src/core/SkTextFormatParams.h
77 virtual void DrawDecorations(int x,
78 int y,
79 int width,
80 bool underline,
81 bool strike);
82 void DrawUnderline(int x, int y, int width); 70 void DrawUnderline(int x, int y, int width);
83 void DrawStrike(int x, int y, int width) const; 71 void DrawStrike(int x, int y, int width, SkScalar thickness_factor);
84 72
85 private: 73 private:
86 friend class test::RenderTextTestApi; 74 friend class test::RenderTextTestApi;
87 75
88 Canvas* canvas_; 76 Canvas* canvas_;
89 cc::PaintCanvas* canvas_skia_; 77 cc::PaintCanvas* canvas_skia_;
90 cc::PaintFlags flags_; 78 cc::PaintFlags flags_;
91 SkScalar underline_thickness_;
92 SkScalar underline_position_;
93 79
94 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer); 80 DISALLOW_COPY_AND_ASSIGN(SkiaTextRenderer);
95 }; 81 };
96 82
97 // Internal helper class used to iterate colors, baselines, and styles. 83 // Internal helper class used to iterate colors, baselines, and styles.
98 class StyleIterator { 84 class StyleIterator {
99 public: 85 public:
100 StyleIterator(const BreakList<SkColor>& colors, 86 StyleIterator(const BreakList<SkColor>& colors,
101 const BreakList<BaselineStyle>& baselines, 87 const BreakList<BaselineStyle>& baselines,
102 const BreakList<Font::Weight>& weights, 88 const BreakList<Font::Weight>& weights,
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
493 // at the point, returns a nearby word. |baseline_point| should correspond to 479 // at the point, returns a nearby word. |baseline_point| should correspond to
494 // the baseline point of the leftmost glyph of the |word| in the view's 480 // the baseline point of the leftmost glyph of the |word| in the view's
495 // coordinates. Returns false, if no word can be retrieved. 481 // coordinates. Returns false, if no word can be retrieved.
496 bool GetDecoratedWordAtPoint(const Point& point, 482 bool GetDecoratedWordAtPoint(const Point& point,
497 DecoratedText* decorated_word, 483 DecoratedText* decorated_word,
498 Point* baseline_point); 484 Point* baseline_point);
499 485
500 // Retrieves the text in the given |range|. 486 // Retrieves the text in the given |range|.
501 base::string16 GetTextFromRange(const Range& range) const; 487 base::string16 GetTextFromRange(const Range& range) const;
502 488
489 // Sets the ratio of strike-through line thickness to text height.
msw 2017/07/05 19:55:00 optional nit: comment not needed on simple setter.
cjgrant 2017/07/05 20:44:43 Done. I was concerned about explaining what the ra
490 void set_strike_thickness_factor(SkScalar f) {
491 strike_thickness_factor_ = f;
msw 2017/07/05 19:55:00 nit: fits on line above with semi removed: void
cjgrant 2017/07/05 20:44:43 Done.
492 };
msw 2017/07/05 19:55:00 nit: no semi after function body
cjgrant 2017/07/05 20:44:43 Done. Oops!
493
503 protected: 494 protected:
504 RenderText(); 495 RenderText();
505 496
506 // NOTE: The value of these accessors may be stale. Please make sure 497 // NOTE: The value of these accessors may be stale. Please make sure
507 // that these fields are up to date before accessing them. 498 // that these fields are up to date before accessing them.
508 const base::string16& layout_text() const { return layout_text_; } 499 const base::string16& layout_text() const { return layout_text_; }
509 const base::string16& display_text() const { return display_text_; } 500 const base::string16& display_text() const { return display_text_; }
510 bool text_elided() const { return text_elided_; } 501 bool text_elided() const { return text_elided_; }
511 502
512 const BreakList<SkColor>& colors() const { return colors_; } 503 const BreakList<SkColor>& colors() const { return colors_; }
513 const BreakList<BaselineStyle>& baselines() const { return baselines_; } 504 const BreakList<BaselineStyle>& baselines() const { return baselines_; }
514 const BreakList<Font::Weight>& weights() const { return weights_; } 505 const BreakList<Font::Weight>& weights() const { return weights_; }
515 const std::vector<BreakList<bool> >& styles() const { return styles_; } 506 const std::vector<BreakList<bool> >& styles() const { return styles_; }
507 SkScalar strike_thickness_factor() const { return strike_thickness_factor_; }
516 508
517 const std::vector<internal::Line>& lines() const { return lines_; } 509 const std::vector<internal::Line>& lines() const { return lines_; }
518 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 510 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
519 511
520 // Returns the baseline of the current text. The return value depends on 512 // Returns the baseline of the current text. The return value depends on
521 // the text and its layout while the return value of GetBaseline() doesn't. 513 // the text and its layout while the return value of GetBaseline() doesn't.
522 // GetAlignmentOffset() takes into account the difference between them. 514 // GetAlignmentOffset() takes into account the difference between them.
523 // 515 //
524 // We'd like a RenderText to show the text always on the same baseline 516 // We'd like a RenderText to show the text always on the same baseline
525 // regardless of the text, so the text does not jump up or down depending 517 // regardless of the text, so the text does not jump up or down depending
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 // Text shadows to be drawn. 820 // Text shadows to be drawn.
829 ShadowValues shadows_; 821 ShadowValues shadows_;
830 822
831 // A list of valid display text line break positions. 823 // A list of valid display text line break positions.
832 BreakList<size_t> line_breaks_; 824 BreakList<size_t> line_breaks_;
833 825
834 // Lines computed by EnsureLayout. These should be invalidated upon 826 // Lines computed by EnsureLayout. These should be invalidated upon
835 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. 827 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls.
836 std::vector<internal::Line> lines_; 828 std::vector<internal::Line> lines_;
837 829
830 // The ratio of strike-through line thickness to text height.
831 SkScalar strike_thickness_factor_;
832
838 DISALLOW_COPY_AND_ASSIGN(RenderText); 833 DISALLOW_COPY_AND_ASSIGN(RenderText);
839 }; 834 };
840 835
841 } // namespace gfx 836 } // namespace gfx
842 837
843 #endif // UI_GFX_RENDER_TEXT_H_ 838 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698