OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <algorithm> | 8 #include <algorithm> |
9 #include <cstring> | 9 #include <cstring> |
10 #include <string> | 10 #include <string> |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 int GetBaseline(); | 371 int GetBaseline(); |
372 | 372 |
373 void Draw(Canvas* canvas); | 373 void Draw(Canvas* canvas); |
374 | 374 |
375 // Draws a cursor at |position|. | 375 // Draws a cursor at |position|. |
376 void DrawCursor(Canvas* canvas, const SelectionModel& position); | 376 void DrawCursor(Canvas* canvas, const SelectionModel& position); |
377 | 377 |
378 // Gets the SelectionModel from a visual point in local coordinates. | 378 // Gets the SelectionModel from a visual point in local coordinates. |
379 virtual SelectionModel FindCursorPosition(const Point& point) = 0; | 379 virtual SelectionModel FindCursorPosition(const Point& point) = 0; |
380 | 380 |
381 // Return true if cursor can appear in front of the character at |position|, | 381 // Returns true if the position is a valid logical index into text(), and is |
382 // which means it is a grapheme boundary or the first character in the text. | 382 // also a valid grapheme boundary, which may be used as a cursor position. |
383 virtual bool IsCursorablePosition(size_t position) = 0; | 383 virtual bool IsValidCursorIndex(size_t index) = 0; |
| 384 |
| 385 // Returns true if the position is a valid logical index into text(). Indices |
| 386 // amid multi-character graphemes are allowed here, unlike IsValidCursorIndex. |
| 387 virtual bool IsValidLogicalIndex(size_t index); |
384 | 388 |
385 // Get the visual bounds of a cursor at |caret|. These bounds typically | 389 // Get the visual bounds of a cursor at |caret|. These bounds typically |
386 // represent a vertical line if |insert_mode| is true. Pass false for | 390 // represent a vertical line if |insert_mode| is true. Pass false for |
387 // |insert_mode| to retrieve the bounds of the associated glyph. These bounds | 391 // |insert_mode| to retrieve the bounds of the associated glyph. These bounds |
388 // are in local coordinates, but may be outside the visible region if the text | 392 // are in local coordinates, but may be outside the visible region if the text |
389 // is longer than the textfield. Subsequent text, cursor, or bounds changes | 393 // is longer than the textfield. Subsequent text, cursor, or bounds changes |
390 // may invalidate returned values. Note that |caret| must be placed at | 394 // may invalidate returned values. Note that |caret| must be placed at |
391 // grapheme boundary, that is, |IsCursorablePosition(caret.caret_pos())| must | 395 // grapheme boundary, i.e. caret.caret_pos() must be a cursorable position. |
392 // return true. | |
393 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); | 396 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); |
394 | 397 |
395 // Compute the current cursor bounds, panning the text to show the cursor in | 398 // Compute the current cursor bounds, panning the text to show the cursor in |
396 // the display rect if necessary. These bounds are in local coordinates. | 399 // the display rect if necessary. These bounds are in local coordinates. |
397 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 400 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
398 const Rect& GetUpdatedCursorBounds(); | 401 const Rect& GetUpdatedCursorBounds(); |
399 | 402 |
400 // Given an |index| in text(), return the next or previous grapheme boundary | 403 // Given an |index| in text(), return the next or previous grapheme boundary |
401 // in logical order (that is, the nearest index for which | 404 // in logical order (i.e. the nearest cursorable index). The return value is |
402 // |IsCursorablePosition(index)| returns true). The return value is in the | 405 // in the range 0 to text().length() inclusive (the input is clamped if it is |
403 // range 0 to text().length() inclusive (the input is clamped if it is out of | 406 // out of that range). Always moves by at least one character index unless the |
404 // that range). Always moves by at least one character index unless the | |
405 // supplied index is already at the boundary of the string. | 407 // supplied index is already at the boundary of the string. |
406 size_t IndexOfAdjacentGrapheme(size_t index, | 408 size_t IndexOfAdjacentGrapheme(size_t index, |
407 LogicalCursorDirection direction); | 409 LogicalCursorDirection direction); |
408 | 410 |
409 // Return a SelectionModel with the cursor at the current selection's start. | 411 // Return a SelectionModel with the cursor at the current selection's start. |
410 // The returned value represents a cursor/caret position without a selection. | 412 // The returned value represents a cursor/caret position without a selection. |
411 SelectionModel GetSelectionModelForSelectionStart(); | 413 SelectionModel GetSelectionModelForSelectionStart(); |
412 | 414 |
413 // Sets shadows to drawn with text. | 415 // Sets shadows to drawn with text. |
414 void SetTextShadows(const ShadowValues& shadows); | 416 void SetTextShadows(const ShadowValues& shadows); |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
706 // Lines computed by EnsureLayout. These should be invalidated with | 708 // Lines computed by EnsureLayout. These should be invalidated with |
707 // ResetLayout and on |display_rect_| changes. | 709 // ResetLayout and on |display_rect_| changes. |
708 std::vector<internal::Line> lines_; | 710 std::vector<internal::Line> lines_; |
709 | 711 |
710 DISALLOW_COPY_AND_ASSIGN(RenderText); | 712 DISALLOW_COPY_AND_ASSIGN(RenderText); |
711 }; | 713 }; |
712 | 714 |
713 } // namespace gfx | 715 } // namespace gfx |
714 | 716 |
715 #endif // UI_GFX_RENDER_TEXT_H_ | 717 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |