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>
13 #include "base/mac/scoped_cftyperef.h"
14 #include "ui/gfx/gfx_export.h"
15 #include "ui/gfx/render_text.h"
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
{
27 ~RenderTextMac() override
;
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
;
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
;
58 FRIEND_TEST_ALL_PREFIXES(RenderTextTest
, Mac_ElidedText
);
63 std::vector
<uint16
> glyphs
;
64 std::vector
<SkPoint
> glyph_positions
;
66 std::string font_name
;
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
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
,
100 // Updates |runs_| based on |line_| and sets |runs_valid_| to true.
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()|.
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
118 std::vector
<TextRun
> runs_
;
120 // Indicates that |runs_| are valid, set by |ComputeRuns()|.
123 DISALLOW_COPY_AND_ASSIGN(RenderTextMac
);
128 #endif // UI_GFX_RENDER_TEXT_MAC_H_