| OLD | NEW |
| 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_MAC_H_ | 5 #ifndef UI_GFX_RENDER_TEXT_MAC_H_ |
| 6 #define UI_GFX_RENDER_TEXT_MAC_H_ | 6 #define UI_GFX_RENDER_TEXT_MAC_H_ |
| 7 | 7 |
| 8 #include <ApplicationServices/ApplicationServices.h> | 8 #include <ApplicationServices/ApplicationServices.h> |
| 9 | 9 |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
| 14 #include "ui/gfx/gfx_export.h" |
| 14 #include "ui/gfx/render_text.h" | 15 #include "ui/gfx/render_text.h" |
| 15 | 16 |
| 16 namespace gfx { | 17 namespace gfx { |
| 17 | 18 |
| 18 // RenderTextMac is the Mac implementation of RenderText that uses CoreText for | 19 // RenderTextMac is the Mac implementation of RenderText that uses CoreText for |
| 19 // layout and Skia for drawing. | 20 // layout and Skia for drawing. |
| 20 // | 21 // |
| 21 // Note: The current implementation only supports drawing and sizing the text, | 22 // Note: The current implementation only supports drawing and sizing the text, |
| 22 // but not text selection or cursor movement. | 23 // but not text selection or cursor movement. |
| 23 class RenderTextMac : public RenderText { | 24 class GFX_EXPORT RenderTextMac : public RenderText { |
| 24 public: | 25 public: |
| 25 RenderTextMac(); | 26 RenderTextMac(); |
| 26 ~RenderTextMac() override; | 27 ~RenderTextMac() override; |
| 27 | 28 |
| 28 // RenderText: | 29 // RenderText: |
| 29 scoped_ptr<RenderText> CreateInstanceOfSameType() const override; | 30 scoped_ptr<RenderText> CreateInstanceOfSameType() const override; |
| 30 const base::string16& GetDisplayText() override; | 31 const base::string16& GetDisplayText() override; |
| 31 Size GetStringSize() override; | 32 Size GetStringSize() override; |
| 32 SizeF GetStringSizeF() override; | 33 SizeF GetStringSizeF() override; |
| 33 SelectionModel FindCursorPosition(const Point& point) override; | 34 SelectionModel FindCursorPosition(const Point& point) override; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 46 std::vector<Rect> GetSubstringBounds(const Range& range) override; | 47 std::vector<Rect> GetSubstringBounds(const Range& range) override; |
| 47 size_t TextIndexToDisplayIndex(size_t index) override; | 48 size_t TextIndexToDisplayIndex(size_t index) override; |
| 48 size_t DisplayIndexToTextIndex(size_t index) override; | 49 size_t DisplayIndexToTextIndex(size_t index) override; |
| 49 bool IsValidCursorIndex(size_t index) override; | 50 bool IsValidCursorIndex(size_t index) override; |
| 50 void OnLayoutTextAttributeChanged(bool text_changed) override; | 51 void OnLayoutTextAttributeChanged(bool text_changed) override; |
| 51 void OnDisplayTextAttributeChanged() override; | 52 void OnDisplayTextAttributeChanged() override; |
| 52 void EnsureLayout() override; | 53 void EnsureLayout() override; |
| 53 void DrawVisualText(Canvas* canvas) override; | 54 void DrawVisualText(Canvas* canvas) override; |
| 54 | 55 |
| 55 private: | 56 private: |
| 57 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Mac_ElidedText); |
| 58 |
| 56 struct TextRun { | 59 struct TextRun { |
| 57 CTRunRef ct_run; | 60 CTRunRef ct_run; |
| 58 SkPoint origin; | 61 SkPoint origin; |
| 59 std::vector<uint16> glyphs; | 62 std::vector<uint16> glyphs; |
| 60 std::vector<SkPoint> glyph_positions; | 63 std::vector<SkPoint> glyph_positions; |
| 61 SkScalar width; | 64 SkScalar width; |
| 62 std::string font_name; | 65 std::string font_name; |
| 63 int font_style; | 66 int font_style; |
| 64 SkScalar text_size; | 67 SkScalar text_size; |
| 65 SkColor foreground; | 68 SkColor foreground; |
| 66 bool underline; | 69 bool underline; |
| 67 bool strike; | 70 bool strike; |
| 68 bool diagonal_strike; | 71 bool diagonal_strike; |
| 69 | 72 |
| 70 TextRun(); | 73 TextRun(); |
| 71 ~TextRun(); | 74 ~TextRun(); |
| 72 }; | 75 }; |
| 73 | 76 |
| 77 // Returns the width used to draw |layout_text_|. |
| 78 float GetLayoutTextWidth(); |
| 79 |
| 80 // Computes the size used to draw |line|. Stores the baseline position into |
| 81 // |baseline|. |
| 82 gfx::SizeF GetCTLineSize(CTLineRef line, SkScalar* baseline); |
| 83 |
| 84 // Creates Core Text line object and its attributes for the given text and |
| 85 // returns the line. |attributes| keeps the ownership of the text attributes. |
| 86 // See the comments of ArrayStyles() implementation for the ownership details. |
| 87 base::ScopedCFTypeRef<CTLineRef> EnsureLayoutInternal( |
| 88 const base::string16& text, |
| 89 base::ScopedCFTypeRef<CFMutableArrayRef>* attributes); |
| 90 |
| 74 // Applies RenderText styles to |attr_string| with the given |ct_font|. | 91 // Applies RenderText styles to |attr_string| with the given |ct_font|. |
| 75 void ApplyStyles(CFMutableAttributedStringRef attr_string, CTFontRef ct_font); | 92 // Returns the array of attributes to keep the ownership of the attributes. |
| 93 // See the comments in .cc file for the details. |
| 94 base::ScopedCFTypeRef<CFMutableArrayRef> ApplyStyles( |
| 95 const base::string16& text, |
| 96 CFMutableAttributedStringRef attr_string, |
| 97 CTFontRef ct_font); |
| 76 | 98 |
| 77 // Updates |runs_| based on |line_| and sets |runs_valid_| to true. | 99 // Updates |runs_| based on |line_| and sets |runs_valid_| to true. |
| 78 void ComputeRuns(); | 100 void ComputeRuns(); |
| 79 | 101 |
| 80 // The Core Text line of text. Created by |EnsureLayout()|. | 102 // The Core Text line of text. Created by |EnsureLayout()|. |
| 81 base::ScopedCFTypeRef<CTLineRef> line_; | 103 base::ScopedCFTypeRef<CTLineRef> line_; |
| 82 | 104 |
| 83 // Array to hold CFAttributedString attributes that allows Core Text to hold | 105 // Array to hold CFAttributedString attributes that allows Core Text to hold |
| 84 // weak references to them without leaking. | 106 // weak references to them without leaking. |
| 85 base::ScopedCFTypeRef<CFMutableArrayRef> attributes_; | 107 base::ScopedCFTypeRef<CFMutableArrayRef> attributes_; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 96 | 118 |
| 97 // Indicates that |runs_| are valid, set by |ComputeRuns()|. | 119 // Indicates that |runs_| are valid, set by |ComputeRuns()|. |
| 98 bool runs_valid_; | 120 bool runs_valid_; |
| 99 | 121 |
| 100 DISALLOW_COPY_AND_ASSIGN(RenderTextMac); | 122 DISALLOW_COPY_AND_ASSIGN(RenderTextMac); |
| 101 }; | 123 }; |
| 102 | 124 |
| 103 } // namespace gfx | 125 } // namespace gfx |
| 104 | 126 |
| 105 #endif // UI_GFX_RENDER_TEXT_MAC_H_ | 127 #endif // UI_GFX_RENDER_TEXT_MAC_H_ |
| OLD | NEW |