OLD | NEW |
---|---|
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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
93 const Rect& display_rect() const { return display_rect_; } | 93 const Rect& display_rect() const { return display_rect_; } |
94 virtual void SetDisplayRect(const Rect& r); | 94 virtual void SetDisplayRect(const Rect& r); |
95 | 95 |
96 // This cursor position corresponds to SelectionModel::selection_end. In | 96 // This cursor position corresponds to SelectionModel::selection_end. In |
97 // addition to representing the selection end, it's also where logical text | 97 // addition to representing the selection end, it's also where logical text |
98 // edits take place, and doesn't necessarily correspond to | 98 // edits take place, and doesn't necessarily correspond to |
99 // SelectionModel::caret_pos. | 99 // SelectionModel::caret_pos. |
100 size_t GetCursorPosition() const; | 100 size_t GetCursorPosition() const; |
101 void SetCursorPosition(size_t position); | 101 void SetCursorPosition(size_t position); |
102 | 102 |
103 void SetCaretPlacement(SelectionModel::CaretPlacement placement) { | |
104 selection_model_.set_caret_placement(placement); | |
105 } | |
106 | |
107 // Moves the cursor left or right. Cursor movement is visual, meaning that | 103 // Moves the cursor left or right. Cursor movement is visual, meaning that |
108 // left and right are relative to screen, not the directionality of the text. | 104 // left and right are relative to screen, not the directionality of the text. |
109 // If |select| is false, the selection start is moved to the same position. | 105 // If |select| is false, the selection start is moved to the same position. |
110 void MoveCursorLeft(BreakType break_type, bool select); | 106 void MoveCursorLeft(BreakType break_type, bool select); |
111 void MoveCursorRight(BreakType break_type, bool select); | 107 void MoveCursorRight(BreakType break_type, bool select); |
112 | 108 |
113 // Set the selection_model_ to the value of |selection|. | 109 // Set the selection_model_ to the value of |selection|. |
114 // The selection model components are modified if invalid. | 110 // The selection model components are modified if invalid. |
115 // Returns true if the cursor position or selection range changed. | 111 // Returns true if the cursor position or selection range changed. |
116 // If |selectin_start_| or |selection_end_| or |caret_pos_| in | 112 // If |selectin_start_| or |selection_end_| or |caret_pos_| in |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 bool insert_mode); | 168 bool insert_mode); |
173 | 169 |
174 // Compute the current cursor bounds, panning the text to show the cursor in | 170 // Compute the current cursor bounds, panning the text to show the cursor in |
175 // the display rect if necessary. These bounds are in local coordinates. | 171 // the display rect if necessary. These bounds are in local coordinates. |
176 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 172 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
177 const Rect& GetUpdatedCursorBounds(); | 173 const Rect& GetUpdatedCursorBounds(); |
178 | 174 |
179 // Get the logical index of the grapheme following the argument |position|. | 175 // Get the logical index of the grapheme following the argument |position|. |
180 virtual size_t GetIndexOfNextGrapheme(size_t position); | 176 virtual size_t GetIndexOfNextGrapheme(size_t position); |
181 | 177 |
178 // Returns the selection model of selection_start_. | |
msw
2011/09/29 02:20:21
|selection_start_| isn't a member of this class, c
xji
2011/10/03 23:18:57
Done.
| |
179 // The returned value represents a cursor/caret position without a selection. | |
180 SelectionModel GetSelectionModelForSelectionStart(); | |
181 | |
182 protected: | 182 protected: |
183 RenderText(); | 183 RenderText(); |
184 | 184 |
185 const Point& GetUpdatedDisplayOffset(); | 185 const Point& GetUpdatedDisplayOffset(); |
186 | 186 |
187 void set_cached_bounds_and_offset_valid(bool valid) { | 187 void set_cached_bounds_and_offset_valid(bool valid) { |
188 cached_bounds_and_offset_valid_ = valid; | 188 cached_bounds_and_offset_valid_ = valid; |
189 } | 189 } |
190 | 190 |
191 const StyleRanges& style_ranges() const { return style_ranges_; } | 191 const StyleRanges& style_ranges() const { return style_ranges_; } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
245 // grapheme, or if there is no previous grapheme, leading the cursor position. | 245 // grapheme, or if there is no previous grapheme, leading the cursor position. |
246 // If |select| is false, the selection start is moved to the same position. | 246 // If |select| is false, the selection start is moved to the same position. |
247 // If the |position| is not a cursorable position (not on grapheme boundary), | 247 // If the |position| is not a cursorable position (not on grapheme boundary), |
248 // it is a NO-OP. | 248 // it is a NO-OP. |
249 void MoveCursorTo(size_t position, bool select); | 249 void MoveCursorTo(size_t position, bool select); |
250 | 250 |
251 // Update the cached bounds and display offset to ensure that the current | 251 // Update the cached bounds and display offset to ensure that the current |
252 // cursor is within the visible display area. | 252 // cursor is within the visible display area. |
253 void UpdateCachedBoundsAndOffset(); | 253 void UpdateCachedBoundsAndOffset(); |
254 | 254 |
255 // Returns the selection model of selection_start_. | |
256 // The returned value represents a cursor/caret position without a selection. | |
257 SelectionModel GetSelectionModelForSelectionStart(); | |
258 | |
259 // Logical UTF-16 string data to be drawn. | 255 // Logical UTF-16 string data to be drawn. |
260 string16 text_; | 256 string16 text_; |
261 | 257 |
262 // Logical selection range and visual cursor position. | 258 // Logical selection range and visual cursor position. |
263 SelectionModel selection_model_; | 259 SelectionModel selection_model_; |
264 | 260 |
265 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. | 261 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. |
266 Rect cursor_bounds_; | 262 Rect cursor_bounds_; |
267 | 263 |
268 // The cursor visibility and insert mode. | 264 // The cursor visibility and insert mode. |
(...skipping 20 matching lines...) Expand all Loading... | |
289 // The cached bounds and offset are invalidated by changes to the cursor, | 285 // The cached bounds and offset are invalidated by changes to the cursor, |
290 // selection, font, and other operations that adjust the visible text bounds. | 286 // selection, font, and other operations that adjust the visible text bounds. |
291 bool cached_bounds_and_offset_valid_; | 287 bool cached_bounds_and_offset_valid_; |
292 | 288 |
293 DISALLOW_COPY_AND_ASSIGN(RenderText); | 289 DISALLOW_COPY_AND_ASSIGN(RenderText); |
294 }; | 290 }; |
295 | 291 |
296 } // namespace gfx | 292 } // namespace gfx |
297 | 293 |
298 #endif // UI_GFX_RENDER_TEXT_H_ | 294 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |