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