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

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

Issue 7511029: Implement Pango RenderText for Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_LINUX_H_ 5 #ifndef UI_GFX_RENDER_TEXT_LINUX_H_
6 #define UI_GFX_RENDER_TEXT_LINUX_H_ 6 #define UI_GFX_RENDER_TEXT_LINUX_H_
7 #pragma once 7 #pragma once
8 8
9 #include "ui/gfx/render_text.h" 9 #include "ui/gfx/render_text.h"
10 10
11 #include <pango/pango.h>
oshima 2011/08/19 18:44:07 move this above chrome includes
xji 2011/08/20 00:53:05 Done.
12
11 namespace gfx { 13 namespace gfx {
12 14
13 // RenderTextLinux is the Linux implementation of RenderText using Pango. 15 // RenderTextLinux is the Linux implementation of RenderText using Pango.
14 class RenderTextLinux : public RenderText { 16 class RenderTextLinux : public RenderText {
15 public: 17 public:
16 RenderTextLinux(); 18 RenderTextLinux();
17 virtual ~RenderTextLinux(); 19 virtual ~RenderTextLinux();
18 20
oshima 2011/08/19 18:44:07 // Overridden from RenderText
xji 2011/08/20 00:53:05 Done.
19 private: 21 virtual void SetText(const string16& text) {
22 RenderText::SetText(text);
23 ResetLayout();
24 }
oshima 2011/08/19 18:44:07 please move all virtuals to .cc and OVERRIDE
xji 2011/08/20 00:53:05 Done.
25
26 virtual void SetDisplayRect(const Rect&r) {
27 RenderText::SetDisplayRect(r);
28 ResetLayout();
29 }
30
31 virtual void ApplyStyleRange(StyleRange style_range) {
32 RenderText::ApplyStyleRange(style_range);
33 ResetLayout();
34 }
35
36 virtual void ApplyDefaultStyle() {
37 RenderText::ApplyDefaultStyle();
38 ResetLayout();
39 }
40
41 virtual int GetStringWidth();
42
43 virtual void Draw(Canvas* canvas);
44
45 virtual SelectionModel FindCursorPosition(const Point& point);
46
47 virtual Rect GetCursorBounds(const SelectionModel& position,
48 bool insert_mode);
49
50 private:
51 enum CursorMovementDirection {
52 LEFT,
53 RIGHT
54 };
55
56 enum RelativeLogicalPosition {
57 PREVIOUS,
58 NEXT
59 };
60
61 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
62 BreakType break_type);
63 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
64 BreakType break_type);
65
66 virtual size_t GetIndexOfPreviousGrapheme(size_t position);
67
68 // Returns the SelectionModel for visual leftmost position in the line.
69 // The returned value represents a cursor/caret position without a selection.
70 SelectionModel GetSelectionModelForVisualLeftmost() const;
71
72 // Returns the run that contains the caret_pos in |current|. Based on moving
73 // direction, set whether the (caret_pos, caret_placement) is at the boundary
74 // of the run. If moving right, the trailing edge of LTR run or the leading
75 // edge of RTL run is at boundary of run. If moving left, the leading edge of
76 // LTR run or the trailing edge of RTL run is at the boundary of run.
77 //
78 // This does not work if |current| is the visually rightmost END position,
79 // which is SelectionModel(text().length(), text().length(), LEADING).
80 // This END position does not belong to any run.
81 GSList* GetRunContainsCaretPos(const SelectionModel& current,
82 CursorMovementDirection dir,
83 bool* at_boundary) const;
84
85 // Given |utf16_index_of_current_grapheme|, returns the UTF8 index of next
86 // graphame in the text if |pos| is NEXT, otherwise, returns the UTF8 index of
87 // previous grapheme.
88 size_t Utf8IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme,
89 RelativeLogicalPosition pos) const;
90
91 // Given |utf16_index_of_current_grapheme|, returns the UTF16 index of next
92 // graphame in the text if |pos| is NEXT, otherwise, returns the UTF16 index
93 // of previous grapheme.
94 size_t Utf16IndexOfAdjacentGrapheme(size_t utf16_index_of_current_grapheme,
95 RelativeLogicalPosition pos) const;
96
97 // Given a |run|, returns the SelectionModel that contains the logical first
98 // caret position inside (not at bounary of) the run.
99 // The returned value represents a cursor/caret position without a selection.
100 SelectionModel FirstSelectionModelInsideRun(const PangoItem* run) const;
101
102 // Given a |run|, returns the SelectionModel that contains the logical last
103 // caret position inside (not at bounary of) the run.
104 // The returned value represents a cursor/caret position without a selection.
105 SelectionModel LastSelectionModelInsideRun(const PangoItem* run) const;
106
107 // Given a |run|, returns the SelectionModel that contains the leftmost caret
108 // position inside (not at bounary of) the run.
109 // The returned value represents a cursor/caret position without a selection.
110 SelectionModel LeftmostSelectionModelInsideRun(const PangoItem* run) const;
111
112 // Given a |run|, returns the SelectionModel that contains the rightmost caret
113 // position inside (not at bounary of) the run.
114 // The returned value represents a cursor/caret position without a selection.
115 SelectionModel RightmostSelectionModelInsideRun(const PangoItem* run) const;
116
117 // when |sel| is the visually rightmost END position of line, set |adjacent|
118 // as the left or right (depends on |dir|) of |sel| and return true.
119 // Otherwise, return false.
120 // The value set in |adjacent| represnts a cursor/caret positin without a
121 // selection.
122 bool GetVisuallyAdjacentCursorPositionForEnd(const SelectionModel& current,
123 CursorMovementDirection dir,
124 SelectionModel* adjacent) const;
125
126 // Get the selection model that visually left of |current| by one grapheme.
127 // The returned value represents a cursor/caret position without a selection.
128 SelectionModel GetLeftSelectionModelByGrapheme(
129 const SelectionModel& current) const;
130
131 // Get the selection model that visually right of |current| by one grapheme.
132 // The returned value represents a cursor/caret position without a selection.
133 SelectionModel GetRightSelectionModelByGrapheme(
134 const SelectionModel& current) const;
135
136 // Creates, setup, and returns pango layout and pango layout line if layout_
137 // is NULL. Otherwise, return the cached layout_.
138 PangoLayout* EnsureLayout();
139
140 // Unref pango layout (layout_) and pango layout line (pango_line_). Set them
141 // to NULL. nds_.
142 void ResetLayout();
143
144 // Setup pango attribute: foreground, background, font, strike.
145 void SetupPangoAttributes(PangoLayout* layout);
146
147 // Append one pango attribute |pango_attr| into pango attribute list |attrs|.
148 void AppendPangoAttribute(size_t start,
149 size_t end,
150 PangoAttribute* pango_attr,
151 PangoAttrList* attrs);
152
153 // Returns |run|'s visually previous run.
154 GSList* GetPreviousRun(GSList* run) const;
155
156 // Returns last run in Layout_line_.
157 GSList* GetLastRun() const;
158
159 size_t Utf16IndexToUtf8Index(const string16& text, size_t index) const;
160 size_t Utf8IndexToUtf16Index(const string16& text, size_t index) const;
161
162 // Adjust |bounds| for non insert mode.
163 void AdjustBoundsForNonInsertMode(const SelectionModel& selection,
164 const PangoRectangle& pos,
165 Rect* bounds) const;
166
167 PangoLayout* layout_;
168
169 PangoLayoutLine* layout_line_;
170
20 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux); 171 DISALLOW_COPY_AND_ASSIGN(RenderTextLinux);
21 }; 172 };
22 173
23 } // namespace gfx; 174 } // namespace gfx;
24 175
25 #endif // UI_GFX_RENDER_TEXT_LINUX_H_ 176 #endif // UI_GFX_RENDER_TEXT_LINUX_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698