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

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

Issue 10543057: Initial RenderTextMac implementation using CoreText. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #ifndef UI_GFX_RENDER_TEXT_MAC_H_
6 #define UI_GFX_RENDER_TEXT_MAC_H_
7 #pragma once
8
9 #include <ApplicationServices/ApplicationServices.h>
10
11 #include <string>
12 #include <vector>
13
14 #include "base/mac/scoped_cftyperef.h"
15 #include "ui/gfx/render_text.h"
16
17 namespace gfx {
18
19 // RenderTextMac is the Mac implementation of RenderText that uses CoreText for
20 // layout and Skia for drawing.
21 //
22 // Note: The current implementation only supports drawing and sizing the text,
23 // but not text selection or cursor movement.
24 class RenderTextMac : public RenderText {
25 public:
26 RenderTextMac();
27 virtual ~RenderTextMac();
28
29 // Overridden from RenderText:
30 virtual base::i18n::TextDirection GetTextDirection() OVERRIDE;
31 virtual Size GetStringSize() OVERRIDE;
32 virtual int GetBaseline() OVERRIDE;
33 virtual SelectionModel FindCursorPosition(const Point& point) OVERRIDE;
34 virtual std::vector<FontSpan> GetFontSpansForTesting() OVERRIDE;
35
36 protected:
37 // Overridden from RenderText:
38 virtual SelectionModel AdjacentCharSelectionModel(
39 const SelectionModel& selection,
40 VisualCursorDirection direction) OVERRIDE;
41 virtual SelectionModel AdjacentWordSelectionModel(
42 const SelectionModel& selection,
43 VisualCursorDirection direction) OVERRIDE;
44 virtual void GetGlyphBounds(size_t index,
45 ui::Range* xspan,
46 int* height) OVERRIDE;
47 virtual std::vector<Rect> GetSubstringBounds(ui::Range range) OVERRIDE;
48 virtual bool IsCursorablePosition(size_t position) OVERRIDE;
49 virtual void ResetLayout() OVERRIDE;
50 virtual void EnsureLayout() OVERRIDE;
51 virtual void DrawVisualText(Canvas* canvas) OVERRIDE;
52
53 private:
54 struct TextRun {
55 CTRunRef ct_run;
56 SkPoint origin;
57 std::vector<uint16> glyphs;
58 std::vector<SkPoint> glyph_positions;
59 SkScalar width;
60 std::string font_name;
61 int font_style;
62 SkScalar text_size;
63 SkColor foreground;
64 StyleRange style;
65
66 TextRun();
67 ~TextRun();
68 };
69
70 // Applies RenderText styles to |attr_string| with the given |ct_font|.
71 void ApplyStyles(CFMutableAttributedStringRef attr_string, CTFontRef ct_font);
72
73 // Updates |runs_| based on |line_| and sets |runs_valid_| to true.
74 void ComputeRuns();
75
76 // The Core Text line of text. Created by |EnsureLayout()|.
77 base::mac::ScopedCFTypeRef<CTLineRef> line_;
78
79 // Visual dimensions of the text. Computed by |EnsureLayout()|.
80 Size string_size_;
81
82 // Common baseline for this line of text. Computed by |EnsureLayout()|.
83 SkScalar common_baseline_;
84
85 // Visual text runs. Only valid if |runs_valid_| is true. Computed by
86 // |ComputeRuns()|.
87 std::vector<TextRun> runs_;
88
89 // Indicates that |runs_| are valid, set by |ComputeRuns()|.
90 bool runs_valid_;
91
92 DISALLOW_COPY_AND_ASSIGN(RenderTextMac);
93 };
94
95 } // namespace gfx
96
97 #endif // UI_GFX_RENDER_TEXT_MAC_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698