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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 // render the text and its attributes. | 227 // render the text and its attributes. |
228 virtual void UpdateLayout() = 0; | 228 virtual void UpdateLayout() = 0; |
229 | 229 |
230 // Ensure the text is laid out. | 230 // Ensure the text is laid out. |
231 virtual void EnsureLayout() = 0; | 231 virtual void EnsureLayout() = 0; |
232 | 232 |
233 // Draw the text. | 233 // Draw the text. |
234 virtual void DrawVisualText(Canvas* canvas) = 0; | 234 virtual void DrawVisualText(Canvas* canvas) = 0; |
235 | 235 |
236 // Get the logical index of the grapheme preceding the argument |position|. | 236 // Get the logical index of the grapheme preceding the argument |position|. |
| 237 // If |IsCursorablePosition(position)| is true, the result will be the start |
| 238 // of the previous grapheme, if any. Otherwise, the result will be the start |
| 239 // of the grapheme containing |position|. |
237 size_t GetIndexOfPreviousGrapheme(size_t position); | 240 size_t GetIndexOfPreviousGrapheme(size_t position); |
238 | 241 |
239 // Apply composition style (underline) to composition range and selection | 242 // Apply composition style (underline) to composition range and selection |
240 // style (foreground) to selection range. | 243 // style (foreground) to selection range. |
241 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; | 244 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges) const; |
242 | 245 |
243 // Convert points from the text space to the view space and back. | 246 // Convert points from the text space to the view space and back. |
244 // Handles the display area, display offset, and the application LTR/RTL mode. | 247 // Handles the display area, display offset, and the application LTR/RTL mode. |
245 Point ToTextPoint(const Point& point); | 248 Point ToTextPoint(const Point& point); |
246 Point ToViewPoint(const Point& point); | 249 Point ToViewPoint(const Point& point); |
247 | 250 |
248 private: | 251 private: |
249 friend class RenderTextTest; | 252 friend class RenderTextTest; |
250 | 253 |
251 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 254 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
252 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); | 255 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, CustomDefaultStyle); |
253 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); | 256 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyStyleRange); |
254 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); | 257 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StyleRangesAdjust); |
| 258 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
| 259 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SelectionModels); |
255 | 260 |
256 // Return an index belonging to the |next| or previous logical grapheme. | 261 // Return an index belonging to the |next| or previous logical grapheme. |
| 262 // If |next| is false and |IsCursorablePosition(index)| is true, the result |
| 263 // will be the start of the previous grapheme, if any. Otherwise, the result |
| 264 // will be the start of the grapheme containing |index|. |
257 // The return value is bounded by 0 and the text length, inclusive. | 265 // The return value is bounded by 0 and the text length, inclusive. |
258 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0; | 266 virtual size_t IndexOfAdjacentGrapheme(size_t index, bool next) = 0; |
259 | 267 |
260 // Set the cursor to |position|, with the caret trailing the previous | 268 // Set the cursor to |position|, with the caret trailing the previous |
261 // grapheme, or if there is no previous grapheme, leading the cursor position. | 269 // grapheme, or if there is no previous grapheme, leading the cursor position. |
262 // If |select| is false, the selection start is moved to the same position. | 270 // If |select| is false, the selection start is moved to the same position. |
263 // If the |position| is not a cursorable position (not on grapheme boundary), | 271 // If the |position| is not a cursorable position (not on grapheme boundary), |
264 // it is a NO-OP. | 272 // it is a NO-OP. |
265 void MoveCursorTo(size_t position, bool select); | 273 void MoveCursorTo(size_t position, bool select); |
266 | 274 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 // The cached bounds and offset are invalidated by changes to the cursor, | 313 // The cached bounds and offset are invalidated by changes to the cursor, |
306 // selection, font, and other operations that adjust the visible text bounds. | 314 // selection, font, and other operations that adjust the visible text bounds. |
307 bool cached_bounds_and_offset_valid_; | 315 bool cached_bounds_and_offset_valid_; |
308 | 316 |
309 DISALLOW_COPY_AND_ASSIGN(RenderText); | 317 DISALLOW_COPY_AND_ASSIGN(RenderText); |
310 }; | 318 }; |
311 | 319 |
312 } // namespace gfx | 320 } // namespace gfx |
313 | 321 |
314 #endif // UI_GFX_RENDER_TEXT_H_ | 322 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |