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

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

Issue 7511029: Implement Pango RenderText for Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: add dcheck and todo Created 9 years, 3 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_H_ 5 #ifndef UI_GFX_RENDER_TEXT_H_
6 #define UI_GFX_RENDER_TEXT_H_ 6 #define UI_GFX_RENDER_TEXT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 CaretPlacement caret_placement() const { return caret_placement_; } 114 CaretPlacement caret_placement() const { return caret_placement_; }
115 void set_caret_placement(CaretPlacement placement) { 115 void set_caret_placement(CaretPlacement placement) {
116 caret_placement_ = placement; 116 caret_placement_ = placement;
117 } 117 }
118 118
119 bool Equals(const SelectionModel& sel) const; 119 bool Equals(const SelectionModel& sel) const;
120 120
121 private: 121 private:
122 void Init(size_t start, size_t end, size_t pos, CaretPlacement status); 122 void Init(size_t start, size_t end, size_t pos, CaretPlacement status);
123 123
124 // Logical selection start. If there is non-empty selection, the selection 124 // Logical selection start. If there is non-empty selection, if
125 // always starts visually at the leading edge of the selection_start. So, we 125 // selection_start_ is less than selection_end_, the selection starts visually
126 // do not need extra information for visual selection bounding. 126 // at the leading edge of the selection_start_. If selection_start_ is greater
127 // than selection_end_, the selection starts visually at the trailing edge of
128 // selection_start_'s previous grapheme. So, we do not need extra information
129 // for visual bounding.
127 size_t selection_start_; 130 size_t selection_start_;
128 131
129 // The logical cursor position that next character will be inserted into. 132 // The logical cursor position that next character will be inserted into.
130 // It is also the end of the selection. 133 // It is also the end of the selection.
131 size_t selection_end_; 134 size_t selection_end_;
132 135
133 // The following two fields are used to guide cursor visual position. 136 // The following two fields are used to guide cursor visual position.
134 // The index of the character that cursor is visually attached to. 137 // The index of the character that cursor is visually attached to.
135 size_t caret_pos_; 138 size_t caret_pos_;
136 // The visual placement of the cursor, relative to its associated character. 139 // The visual placement of the cursor, relative to its associated character.
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 void set_default_style(StyleRange style) { default_style_ = style; } 172 void set_default_style(StyleRange style) { default_style_ = style; }
170 173
171 const Rect& display_rect() const { return display_rect_; } 174 const Rect& display_rect() const { return display_rect_; }
172 virtual void SetDisplayRect(const Rect& r); 175 virtual void SetDisplayRect(const Rect& r);
173 176
174 // This cursor position corresponds to SelectionModel::selection_end. In 177 // This cursor position corresponds to SelectionModel::selection_end. In
175 // addition to representing the selection end, it's also where logical text 178 // addition to representing the selection end, it's also where logical text
176 // edits take place, and doesn't necessarily correspond to 179 // edits take place, and doesn't necessarily correspond to
177 // SelectionModel::caret_pos. 180 // SelectionModel::caret_pos.
178 size_t GetCursorPosition() const; 181 size_t GetCursorPosition() const;
179 void SetCursorPosition(const size_t position); 182 void SetCursorPosition(size_t position);
180 183
181 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { 184 void SetCaretPlacement(SelectionModel::CaretPlacement placement) {
182 selection_model_.set_caret_placement(placement); 185 selection_model_.set_caret_placement(placement);
183 } 186 }
184 187
185 // Moves the cursor left or right. Cursor movement is visual, meaning that 188 // Moves the cursor left or right. Cursor movement is visual, meaning that
186 // left and right are relative to screen, not the directionality of the text. 189 // left and right are relative to screen, not the directionality of the text.
187 // If |select| is false, the selection range is emptied at the new position. 190 // If |select| is false, the selection range is emptied at the new position.
188 void MoveCursorLeft(BreakType break_type, bool select); 191 void MoveCursorLeft(BreakType break_type, bool select);
189 void MoveCursorRight(BreakType break_type, bool select); 192 void MoveCursorRight(BreakType break_type, bool select);
(...skipping 21 matching lines...) Expand all
211 214
212 // Returns true if the local point is over selected text. 215 // Returns true if the local point is over selected text.
213 bool IsPointInSelection(const Point& point); 216 bool IsPointInSelection(const Point& point);
214 217
215 // Selects no text, all text, or the word at the current cursor position. 218 // Selects no text, all text, or the word at the current cursor position.
216 void ClearSelection(); 219 void ClearSelection();
217 void SelectAll(); 220 void SelectAll();
218 void SelectWord(); 221 void SelectWord();
219 222
220 const ui::Range& GetCompositionRange() const; 223 const ui::Range& GetCompositionRange() const;
221 void SetCompositionRange(const ui::Range& composition_range); 224 virtual void SetCompositionRange(const ui::Range& composition_range);
222 225
223 // Apply |style_range| to the internal style model. 226 // Apply |style_range| to the internal style model.
224 virtual void ApplyStyleRange(StyleRange style_range); 227 virtual void ApplyStyleRange(StyleRange style_range);
225 228
226 // Apply |default_style_| over the entire text range. 229 // Apply |default_style_| over the entire text range.
227 virtual void ApplyDefaultStyle(); 230 virtual void ApplyDefaultStyle();
228 231
229 base::i18n::TextDirection GetTextDirection() const; 232 virtual base::i18n::TextDirection GetTextDirection();
230 233
231 // Get the width of the entire string. 234 // Get the width of the entire string.
232 virtual int GetStringWidth(); 235 virtual int GetStringWidth();
233 236
234 virtual void Draw(Canvas* canvas); 237 virtual void Draw(Canvas* canvas);
235 238
236 // Gets the SelectionModel from a visual point in local coordinates. 239 // Gets the SelectionModel from a visual point in local coordinates.
237 virtual SelectionModel FindCursorPosition(const Point& point); 240 virtual SelectionModel FindCursorPosition(const Point& point);
238 241
239 // Get the visual bounds containing the logical substring within |from| to 242 // Get the visual bounds containing the logical substring within |from| to
(...skipping 27 matching lines...) Expand all
267 270
268 const StyleRanges& style_ranges() const { return style_ranges_; } 271 const StyleRanges& style_ranges() const { return style_ranges_; }
269 272
270 // Get the selection model that visually neighbors |position| by |break_type|. 273 // Get the selection model that visually neighbors |position| by |break_type|.
271 // The returned value represents a cursor/caret position without a selection. 274 // The returned value represents a cursor/caret position without a selection.
272 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current, 275 virtual SelectionModel GetLeftSelectionModel(const SelectionModel& current,
273 BreakType break_type); 276 BreakType break_type);
274 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current, 277 virtual SelectionModel GetRightSelectionModel(const SelectionModel& current,
275 BreakType break_type); 278 BreakType break_type);
276 279
277 // Get the logical index of the grapheme preceeding the argument |position|. 280 // Get the logical index of the grapheme preceding the argument |position|.
278 virtual size_t GetIndexOfPreviousGrapheme(size_t position); 281 virtual size_t GetIndexOfPreviousGrapheme(size_t position);
279 282
280 // Apply composition style (underline) to composition range and selection 283 // Apply composition style (underline) to composition range and selection
281 // style (foreground) to selection range. 284 // style (foreground) to selection range.
282 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; 285 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const;
283 286
287 // Convert points from the text space to the view space and back.
288 // Handles the display area, display offset, and the application LTR/RTL mode.
289 Point ToTextPoint(const Point& point);
290 Point ToViewPoint(const Point& point);
291
284 private: 292 private:
285 friend class RenderTextTest; 293 friend class RenderTextTest;
286 294
287 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); 295 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle);
288 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); 296 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle);
289 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); 297 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange);
290 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); 298 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust);
291 299
292 // Clear out |style_ranges_|. 300 // Clear out |style_ranges_|.
293 void ClearStyleRanges(); 301 void ClearStyleRanges();
294 302
303 // Set the cursor to |position|, with the caret trailing the previous
304 // grapheme, or if there is no previous grapheme, leading the cursor position.
305 // If |select| is false, the selection start is moved to the same position.
306 void MoveCursorTo(size_t position, bool select);
307
295 bool IsPositionAtWordSelectionBoundary(size_t pos); 308 bool IsPositionAtWordSelectionBoundary(size_t pos);
296 309
297 // Update the cached bounds and display offset to ensure that the current 310 // Update the cached bounds and display offset to ensure that the current
298 // cursor is within the visible display area. 311 // cursor is within the visible display area.
299 void UpdateCachedBoundsAndOffset(); 312 void UpdateCachedBoundsAndOffset();
300 313
314 // Returns the selection model of selection_start_.
315 // The returned value represents a cursor/caret position without a selection.
316 SelectionModel GetSelectionModelForSelectionStart();
317
301 // Logical UTF-16 string data to be drawn. 318 // Logical UTF-16 string data to be drawn.
302 string16 text_; 319 string16 text_;
303 320
304 // Logical selection range and visual cursor position. 321 // Logical selection range and visual cursor position.
305 SelectionModel selection_model_; 322 SelectionModel selection_model_;
306 323
307 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. 324 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds.
308 Rect cursor_bounds_; 325 Rect cursor_bounds_;
309 326
310 // The cursor visibility and insert mode. 327 // The cursor visibility and insert mode.
(...skipping 21 matching lines...) Expand all
332 // SetCursorPosition, SetSelectionModel, Font related style change, and other 349 // SetCursorPosition, SetSelectionModel, Font related style change, and other
333 // operations that adjust the visible text bounds. 350 // operations that adjust the visible text bounds.
334 bool cached_bounds_and_offset_valid_; 351 bool cached_bounds_and_offset_valid_;
335 352
336 DISALLOW_COPY_AND_ASSIGN(RenderText); 353 DISALLOW_COPY_AND_ASSIGN(RenderText);
337 }; 354 };
338 355
339 } // namespace gfx 356 } // namespace gfx
340 357
341 #endif // UI_GFX_RENDER_TEXT_H_ 358 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698