Revert of Reland debugging for ipc related crash. (patchset #1 id:1 of https://codere...
[chromium-blink-merge.git] / ui / gfx / render_text_mac.h
blob5d3d00db6e5e7f119ad8fcb9ca7697e4ff38445b
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
3 // found in the LICENSE file.
5 #ifndef UI_GFX_RENDER_TEXT_MAC_H_
6 #define UI_GFX_RENDER_TEXT_MAC_H_
8 #include <ApplicationServices/ApplicationServices.h>
10 #include <string>
11 #include <vector>
13 #include "base/mac/scoped_cftyperef.h"
14 #include "ui/gfx/gfx_export.h"
15 #include "ui/gfx/render_text.h"
17 namespace gfx {
19 // RenderTextMac is the Mac implementation of RenderText that uses CoreText for
20 // layout and Skia for drawing.
22 // Note: The current implementation only supports drawing and sizing the text,
23 // but not text selection or cursor movement.
24 class GFX_EXPORT RenderTextMac : public RenderText {
25 public:
26 RenderTextMac();
27 ~RenderTextMac() override;
29 // RenderText:
30 scoped_ptr<RenderText> CreateInstanceOfSameType() const override;
31 bool MultilineSupported() const override;
32 const base::string16& GetDisplayText() override;
33 Size GetStringSize() override;
34 SizeF GetStringSizeF() override;
35 SelectionModel FindCursorPosition(const Point& point) override;
36 std::vector<FontSpan> GetFontSpansForTesting() override;
38 protected:
39 // RenderText:
40 int GetDisplayTextBaseline() override;
41 SelectionModel AdjacentCharSelectionModel(
42 const SelectionModel& selection,
43 VisualCursorDirection direction) override;
44 SelectionModel AdjacentWordSelectionModel(
45 const SelectionModel& selection,
46 VisualCursorDirection direction) override;
47 Range GetGlyphBounds(size_t index) override;
48 std::vector<Rect> GetSubstringBounds(const Range& range) override;
49 size_t TextIndexToDisplayIndex(size_t index) override;
50 size_t DisplayIndexToTextIndex(size_t index) override;
51 bool IsValidCursorIndex(size_t index) override;
52 void OnLayoutTextAttributeChanged(bool text_changed) override;
53 void OnDisplayTextAttributeChanged() override;
54 void EnsureLayout() override;
55 void DrawVisualText(Canvas* canvas) override;
57 private:
58 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Mac_ElidedText);
60 struct TextRun {
61 CTRunRef ct_run;
62 SkPoint origin;
63 std::vector<uint16> glyphs;
64 std::vector<SkPoint> glyph_positions;
65 SkScalar width;
66 std::string font_name;
67 int font_style;
68 SkScalar text_size;
69 SkColor foreground;
70 bool underline;
71 bool strike;
72 bool diagonal_strike;
74 TextRun();
75 ~TextRun();
78 // Returns the width used to draw |layout_text_|.
79 float GetLayoutTextWidth();
81 // Computes the size used to draw |line|. Stores the baseline position into
82 // |baseline|.
83 gfx::SizeF GetCTLineSize(CTLineRef line, SkScalar* baseline);
85 // Creates Core Text line object and its attributes for the given text and
86 // returns the line. |attributes| keeps the ownership of the text attributes.
87 // See the comments of ArrayStyles() implementation for the ownership details.
88 base::ScopedCFTypeRef<CTLineRef> EnsureLayoutInternal(
89 const base::string16& text,
90 base::ScopedCFTypeRef<CFMutableArrayRef>* attributes);
92 // Applies RenderText styles to |attr_string| with the given |ct_font|.
93 // Returns the array of attributes to keep the ownership of the attributes.
94 // See the comments in .cc file for the details.
95 base::ScopedCFTypeRef<CFMutableArrayRef> ApplyStyles(
96 const base::string16& text,
97 CFMutableAttributedStringRef attr_string,
98 CTFontRef ct_font);
100 // Updates |runs_| based on |line_| and sets |runs_valid_| to true.
101 void ComputeRuns();
103 // The Core Text line of text. Created by |EnsureLayout()|.
104 base::ScopedCFTypeRef<CTLineRef> line_;
106 // Array to hold CFAttributedString attributes that allows Core Text to hold
107 // weak references to them without leaking.
108 base::ScopedCFTypeRef<CFMutableArrayRef> attributes_;
110 // Visual dimensions of the text. Computed by |EnsureLayout()|.
111 SizeF string_size_;
113 // Common baseline for this line of text. Computed by |EnsureLayout()|.
114 SkScalar common_baseline_;
116 // Visual text runs. Only valid if |runs_valid_| is true. Computed by
117 // |ComputeRuns()|.
118 std::vector<TextRun> runs_;
120 // Indicates that |runs_| are valid, set by |ComputeRuns()|.
121 bool runs_valid_;
123 DISALLOW_COPY_AND_ASSIGN(RenderTextMac);
126 } // namespace gfx
128 #endif // UI_GFX_RENDER_TEXT_MAC_H_