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 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 | 186 |
184 // Moves the cursor left or right. Cursor movement is visual, meaning that | 187 // Moves the cursor left or right. Cursor movement is visual, meaning that |
185 // left and right are relative to screen, not the directionality of the text. | 188 // left and right are relative to screen, not the directionality of the text. |
186 // If |select| is false, the selection start is moved to the same position. | 189 // If |select| is false, the selection start is moved to the same position. |
187 void MoveCursorLeft(BreakType break_type, bool select); | 190 void MoveCursorLeft(BreakType break_type, bool select); |
188 void MoveCursorRight(BreakType break_type, bool select); | 191 void MoveCursorRight(BreakType break_type, bool select); |
189 | 192 |
190 // Set the selection_model_ to the value of |selection|. | 193 // Set the selection_model_ to the value of |selection|. |
191 // The selection model components are modified if invalid. | 194 // The selection model components are modified if invalid. |
192 // Returns true if the cursor position or selection range changed. | 195 // Returns true if the cursor position or selection range changed. |
| 196 // TODO(xji): need to check the cursor is set at grapheme boundary. |
193 bool MoveCursorTo(const SelectionModel& selection_model); | 197 bool MoveCursorTo(const SelectionModel& selection_model); |
194 | 198 |
195 // Move the cursor to the position associated with the clicked point. | 199 // Move the cursor to the position associated with the clicked point. |
196 // If |select| is false, the selection start is moved to the same position. | 200 // If |select| is false, the selection start is moved to the same position. |
197 // Returns true if the cursor position or selection range changed. | 201 // Returns true if the cursor position or selection range changed. |
198 bool MoveCursorTo(const Point& point, bool select); | 202 bool MoveCursorTo(const Point& point, bool select); |
199 | 203 |
200 size_t GetSelectionStart() const { | 204 size_t GetSelectionStart() const { |
201 return selection_model_.selection_start(); | 205 return selection_model_.selection_start(); |
202 } | 206 } |
203 size_t MinOfSelection() const { | 207 size_t MinOfSelection() const { |
204 return std::min(GetSelectionStart(), GetCursorPosition()); | 208 return std::min(GetSelectionStart(), GetCursorPosition()); |
205 } | 209 } |
206 size_t MaxOfSelection() const { | 210 size_t MaxOfSelection() const { |
207 return std::max(GetSelectionStart(), GetCursorPosition()); | 211 return std::max(GetSelectionStart(), GetCursorPosition()); |
208 } | 212 } |
209 bool EmptySelection() const { | 213 bool EmptySelection() const { |
210 return GetSelectionStart() == GetCursorPosition(); | 214 return GetSelectionStart() == GetCursorPosition(); |
211 } | 215 } |
212 | 216 |
213 // Returns true if the local point is over selected text. | 217 // Returns true if the local point is over selected text. |
214 bool IsPointInSelection(const Point& point); | 218 bool IsPointInSelection(const Point& point); |
215 | 219 |
216 // Selects no text, all text, or the word at the current cursor position. | 220 // Selects no text, all text, or the word at the current cursor position. |
217 void ClearSelection(); | 221 void ClearSelection(); |
218 void SelectAll(); | 222 void SelectAll(); |
219 void SelectWord(); | 223 void SelectWord(); |
220 | 224 |
221 const ui::Range& GetCompositionRange() const; | 225 const ui::Range& GetCompositionRange() const; |
222 void SetCompositionRange(const ui::Range& composition_range); | 226 virtual void SetCompositionRange(const ui::Range& composition_range); |
223 | 227 |
224 // Apply |style_range| to the internal style model. | 228 // Apply |style_range| to the internal style model. |
225 virtual void ApplyStyleRange(StyleRange style_range); | 229 virtual void ApplyStyleRange(StyleRange style_range); |
226 | 230 |
227 // Apply |default_style_| over the entire text range. | 231 // Apply |default_style_| over the entire text range. |
228 virtual void ApplyDefaultStyle(); | 232 virtual void ApplyDefaultStyle(); |
229 | 233 |
230 base::i18n::TextDirection GetTextDirection() const; | 234 virtual base::i18n::TextDirection GetTextDirection(); |
231 | 235 |
232 // Get the width of the entire string. | 236 // Get the width of the entire string. |
233 virtual int GetStringWidth(); | 237 virtual int GetStringWidth(); |
234 | 238 |
235 virtual void Draw(Canvas* canvas); | 239 virtual void Draw(Canvas* canvas); |
236 | 240 |
237 // Gets the SelectionModel from a visual point in local coordinates. | 241 // Gets the SelectionModel from a visual point in local coordinates. |
238 virtual SelectionModel FindCursorPosition(const Point& point); | 242 virtual SelectionModel FindCursorPosition(const Point& point); |
239 | 243 |
240 // Get the visual bounds of a cursor at |selection|. These bounds typically | 244 // Get the visual bounds of a cursor at |selection|. These bounds typically |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 // grapheme, or if there is no previous grapheme, leading the cursor position. | 312 // grapheme, or if there is no previous grapheme, leading the cursor position. |
309 // If |select| is false, the selection start is moved to the same position. | 313 // If |select| is false, the selection start is moved to the same position. |
310 void MoveCursorTo(size_t position, bool select); | 314 void MoveCursorTo(size_t position, bool select); |
311 | 315 |
312 bool IsPositionAtWordSelectionBoundary(size_t pos); | 316 bool IsPositionAtWordSelectionBoundary(size_t pos); |
313 | 317 |
314 // Update the cached bounds and display offset to ensure that the current | 318 // Update the cached bounds and display offset to ensure that the current |
315 // cursor is within the visible display area. | 319 // cursor is within the visible display area. |
316 void UpdateCachedBoundsAndOffset(); | 320 void UpdateCachedBoundsAndOffset(); |
317 | 321 |
| 322 // Returns the selection model of selection_start_. |
| 323 // The returned value represents a cursor/caret position without a selection. |
| 324 SelectionModel GetSelectionModelForSelectionStart(); |
| 325 |
318 // Logical UTF-16 string data to be drawn. | 326 // Logical UTF-16 string data to be drawn. |
319 string16 text_; | 327 string16 text_; |
320 | 328 |
321 // Logical selection range and visual cursor position. | 329 // Logical selection range and visual cursor position. |
322 SelectionModel selection_model_; | 330 SelectionModel selection_model_; |
323 | 331 |
324 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. | 332 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. |
325 Rect cursor_bounds_; | 333 Rect cursor_bounds_; |
326 | 334 |
327 // The cursor visibility and insert mode. | 335 // The cursor visibility and insert mode. |
(...skipping 20 matching lines...) Expand all Loading... |
348 // The cached bounds and offset are invalidated by changes to the cursor, | 356 // The cached bounds and offset are invalidated by changes to the cursor, |
349 // selection, font, and other operations that adjust the visible text bounds. | 357 // selection, font, and other operations that adjust the visible text bounds. |
350 bool cached_bounds_and_offset_valid_; | 358 bool cached_bounds_and_offset_valid_; |
351 | 359 |
352 DISALLOW_COPY_AND_ASSIGN(RenderText); | 360 DISALLOW_COPY_AND_ASSIGN(RenderText); |
353 }; | 361 }; |
354 | 362 |
355 } // namespace gfx | 363 } // namespace gfx |
356 | 364 |
357 #endif // UI_GFX_RENDER_TEXT_H_ | 365 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |