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 <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... | |
33 #include "ui/gfx/selection_model.h" | 33 #include "ui/gfx/selection_model.h" |
34 #include "ui/gfx/shadow_value.h" | 34 #include "ui/gfx/shadow_value.h" |
35 #include "ui/gfx/text_constants.h" | 35 #include "ui/gfx/text_constants.h" |
36 | 36 |
37 class SkCanvas; | 37 class SkCanvas; |
38 class SkDrawLooper; | 38 class SkDrawLooper; |
39 struct SkPoint; | 39 struct SkPoint; |
40 class SkShader; | 40 class SkShader; |
41 class SkTypeface; | 41 class SkTypeface; |
42 | 42 |
43 namespace views { | |
msw
2016/12/13 03:04:55
Hmm, gfx shouldn't reference views, and I'm not su
karandeepb
2016/12/16 02:58:38
Would like to have a test testing multiline select
| |
44 class LabelSelectionTest; | |
45 } | |
46 | |
43 namespace gfx { | 47 namespace gfx { |
44 namespace test { | 48 namespace test { |
45 class RenderTextTestApi; | 49 class RenderTextTestApi; |
46 } | 50 } |
47 | 51 |
48 class Canvas; | 52 class Canvas; |
49 struct DecoratedText; | 53 struct DecoratedText; |
50 class Font; | 54 class Font; |
51 | 55 |
52 namespace internal { | 56 namespace internal { |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 SkPaint* paint); | 206 SkPaint* paint); |
203 | 207 |
204 } // namespace internal | 208 } // namespace internal |
205 | 209 |
206 // RenderText represents an abstract model of styled text and its corresponding | 210 // RenderText represents an abstract model of styled text and its corresponding |
207 // visual layout. Support is built in for a cursor, a selection, simple styling, | 211 // visual layout. Support is built in for a cursor, a selection, simple styling, |
208 // complex scripts, and bi-directional text. Implementations provide mechanisms | 212 // complex scripts, and bi-directional text. Implementations provide mechanisms |
209 // for rendering and translation between logical and visual data. | 213 // for rendering and translation between logical and visual data. |
210 class GFX_EXPORT RenderText { | 214 class GFX_EXPORT RenderText { |
211 public: | 215 public: |
212 // The character used for displaying obscured text. | |
213 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' | |
214 // that's available in the font (find_invisible_char() in gtkentry.c). | |
215 // Use a bullet character on Mac. | |
216 #if defined(OS_MACOSX) | 216 #if defined(OS_MACOSX) |
217 // The character used for displaying obscured text. Use a bullet character on | |
218 // Mac. | |
217 static constexpr base::char16 kPasswordReplacementChar = 0x2022; | 219 static constexpr base::char16 kPasswordReplacementChar = 0x2022; |
220 | |
221 // On Mac, while selecting text if the cursor is outside the vertical text | |
222 // bounds, drag to the end of the text. | |
223 static constexpr bool kDragToEndIfOutsideVerticalBounds = true; | |
218 #else | 224 #else |
219 static constexpr base::char16 kPasswordReplacementChar = '*'; | 225 static constexpr base::char16 kPasswordReplacementChar = '*'; |
226 static constexpr bool kDragToEndIfOutsideVerticalBounds = false; | |
220 #endif | 227 #endif |
221 | 228 |
222 virtual ~RenderText(); | 229 virtual ~RenderText(); |
223 | 230 |
224 // Creates a platform-specific or cross-platform RenderText instance. | 231 // Creates a platform-specific or cross-platform RenderText instance. |
225 static RenderText* CreateInstance(); | 232 static RenderText* CreateInstance(); |
226 static RenderText* CreateInstanceForEditing(); | 233 static RenderText* CreateInstanceForEditing(); |
227 | 234 |
228 // Creates another instance of the same concrete class. | 235 // Creates another instance of the same concrete class. |
229 virtual std::unique_ptr<RenderText> CreateInstanceOfSameType() const = 0; | 236 virtual std::unique_ptr<RenderText> CreateInstanceOfSameType() const = 0; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 // RenderText. | 412 // RenderText. |
406 bool GetStyle(TextStyle style) const; | 413 bool GetStyle(TextStyle style) const; |
407 | 414 |
408 // Set or get the text directionality mode and get the text direction yielded. | 415 // Set or get the text directionality mode and get the text direction yielded. |
409 void SetDirectionalityMode(DirectionalityMode mode); | 416 void SetDirectionalityMode(DirectionalityMode mode); |
410 DirectionalityMode directionality_mode() const { | 417 DirectionalityMode directionality_mode() const { |
411 return directionality_mode_; | 418 return directionality_mode_; |
412 } | 419 } |
413 base::i18n::TextDirection GetDisplayTextDirection(); | 420 base::i18n::TextDirection GetDisplayTextDirection(); |
414 | 421 |
415 // Returns the visual movement direction corresponding to the logical end | 422 // Returns the visual movement direction corresponding to the logical |
416 // of the text, considering only the dominant direction returned by | 423 // end/beginning of the text, considering only the dominant direction returned |
417 // |GetDisplayTextDirection()|, not the direction of a particular run. | 424 // by |GetDisplayTextDirection()|, not the direction of a particular run. |
418 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); | 425 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); |
426 VisualCursorDirection GetVisualDirectionOfLogicalBeginning(); | |
419 | 427 |
420 // Returns the text used to display, which may be obscured, truncated or | 428 // Returns the text used to display, which may be obscured, truncated or |
421 // elided. The subclass may compute elided text on the fly, or use | 429 // elided. The subclass may compute elided text on the fly, or use |
422 // precomputed the elided text. | 430 // precomputed the elided text. |
423 virtual const base::string16& GetDisplayText() = 0; | 431 virtual const base::string16& GetDisplayText() = 0; |
424 | 432 |
425 // Returns the size required to display the current string (which is the | 433 // Returns the size required to display the current string (which is the |
426 // wrapped size in multiline mode). The returned size does not include space | 434 // wrapped size in multiline mode). The returned size does not include space |
427 // reserved for the cursor or the offset text shadows. | 435 // reserved for the cursor or the offset text shadows. |
428 virtual Size GetStringSize() = 0; | 436 virtual Size GetStringSize() = 0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 // Returns true if this instance supports text selection. | 474 // Returns true if this instance supports text selection. |
467 virtual bool IsSelectionSupported() const = 0; | 475 virtual bool IsSelectionSupported() const = 0; |
468 | 476 |
469 // Get the visual bounds of a cursor at |caret|. These bounds typically | 477 // Get the visual bounds of a cursor at |caret|. These bounds typically |
470 // represent a vertical line if |insert_mode| is true. Pass false for | 478 // represent a vertical line if |insert_mode| is true. Pass false for |
471 // |insert_mode| to retrieve the bounds of the associated glyph. These bounds | 479 // |insert_mode| to retrieve the bounds of the associated glyph. These bounds |
472 // are in local coordinates, but may be outside the visible region if the text | 480 // are in local coordinates, but may be outside the visible region if the text |
473 // is longer than the textfield. Subsequent text, cursor, or bounds changes | 481 // is longer than the textfield. Subsequent text, cursor, or bounds changes |
474 // may invalidate returned values. Note that |caret| must be placed at | 482 // may invalidate returned values. Note that |caret| must be placed at |
475 // grapheme boundary, i.e. caret.caret_pos() must be a cursorable position. | 483 // grapheme boundary, i.e. caret.caret_pos() must be a cursorable position. |
484 // TODO(crbug.com/248597): Add multiline support. | |
476 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); | 485 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); |
477 | 486 |
478 // Compute the current cursor bounds, panning the text to show the cursor in | 487 // Compute the current cursor bounds, panning the text to show the cursor in |
479 // the display rect if necessary. These bounds are in local coordinates. | 488 // the display rect if necessary. These bounds are in local coordinates. |
480 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 489 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
481 const Rect& GetUpdatedCursorBounds(); | 490 const Rect& GetUpdatedCursorBounds(); |
482 | 491 |
483 // Given an |index| in text(), return the next or previous grapheme boundary | 492 // Given an |index| in text(), return the next or previous grapheme boundary |
484 // in logical order (i.e. the nearest cursorable index). The return value is | 493 // in logical order (i.e. the nearest cursorable index). The return value is |
485 // in the range 0 to text().length() inclusive (the input is clamped if it is | 494 // in the range 0 to text().length() inclusive (the input is clamped if it is |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
584 virtual SelectionModel AdjacentCharSelectionModel( | 593 virtual SelectionModel AdjacentCharSelectionModel( |
585 const SelectionModel& selection, | 594 const SelectionModel& selection, |
586 VisualCursorDirection direction) = 0; | 595 VisualCursorDirection direction) = 0; |
587 | 596 |
588 // Get the selection model visually left/right of |selection| by one word. | 597 // Get the selection model visually left/right of |selection| by one word. |
589 // The returned value represents a cursor/caret position without a selection. | 598 // The returned value represents a cursor/caret position without a selection. |
590 virtual SelectionModel AdjacentWordSelectionModel( | 599 virtual SelectionModel AdjacentWordSelectionModel( |
591 const SelectionModel& selection, | 600 const SelectionModel& selection, |
592 VisualCursorDirection direction) = 0; | 601 VisualCursorDirection direction) = 0; |
593 | 602 |
594 // Get the SelectionModels corresponding to visual text ends. | 603 // Get the selection model corresponding to visual text ends. |
595 // The returned value represents a cursor/caret position without a selection. | 604 // The returned value represents a cursor/caret position without a selection. |
596 SelectionModel EdgeSelectionModel(VisualCursorDirection direction); | 605 SelectionModel EdgeSelectionModel(VisualCursorDirection direction); |
597 | 606 |
607 // Get the selection model corresponding to visual text ends for |line_index|. | |
608 // The returned value represents a cursor/caret position without a selection. | |
609 SelectionModel LineSelectionModel(size_t line_index, | |
610 gfx::VisualCursorDirection direction); | |
611 | |
598 // Sets the selection model, the argument is assumed to be valid. | 612 // Sets the selection model, the argument is assumed to be valid. |
599 virtual void SetSelectionModel(const SelectionModel& model); | 613 virtual void SetSelectionModel(const SelectionModel& model); |
600 | 614 |
601 // Get the visual bounds containing the logical substring within the |range|. | 615 // Get the visual bounds containing the logical substring within the |range|. |
602 // If |range| is empty, the result is empty. These bounds could be visually | 616 // If |range| is empty, the result is empty. These bounds could be visually |
603 // discontinuous if the substring is split by a LTR/RTL level change. | 617 // discontinuous if the substring is split by a LTR/RTL level change. |
604 // These bounds are in local coordinates, but may be outside the visible | 618 // These bounds are in local coordinates, but may be outside the visible |
605 // region if the text is longer than the textfield. Subsequent text, cursor, | 619 // region if the text is longer than the textfield. Subsequent text, cursor, |
606 // or bounds changes may invalidate returned values. | 620 // or bounds changes may invalidate returned values. |
607 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; | 621 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; |
(...skipping 25 matching lines...) Expand all Loading... | |
633 // Update the display text. | 647 // Update the display text. |
634 void UpdateDisplayText(float text_width); | 648 void UpdateDisplayText(float text_width); |
635 | 649 |
636 // Returns display text positions that are suitable for breaking lines. | 650 // Returns display text positions that are suitable for breaking lines. |
637 const BreakList<size_t>& GetLineBreaks(); | 651 const BreakList<size_t>& GetLineBreaks(); |
638 | 652 |
639 // Apply (and undo) temporary composition underlines and selection colors. | 653 // Apply (and undo) temporary composition underlines and selection colors. |
640 void ApplyCompositionAndSelectionStyles(); | 654 void ApplyCompositionAndSelectionStyles(); |
641 void UndoCompositionAndSelectionStyles(); | 655 void UndoCompositionAndSelectionStyles(); |
642 | 656 |
643 // Convert points from the text space to the view space and back. Handles the | 657 // Convert points from the text space to the view space. Handles the display |
644 // display area, display offset, application LTR/RTL mode and multiline. | 658 // area, display offset, application LTR/RTL mode and multiline. |
645 Point ToTextPoint(const Point& point); | |
646 Point ToViewPoint(const Point& point); | 659 Point ToViewPoint(const Point& point); |
647 | 660 |
648 // Convert a text space x-coordinate range to rects in view space. | |
649 std::vector<Rect> TextBoundsToViewBounds(const Range& x); | |
650 | |
651 // Get the alignment, resolving ALIGN_TO_HEAD with the current text direction. | 661 // Get the alignment, resolving ALIGN_TO_HEAD with the current text direction. |
652 HorizontalAlignment GetCurrentHorizontalAlignment(); | 662 HorizontalAlignment GetCurrentHorizontalAlignment(); |
653 | 663 |
654 // Returns the line offset from the origin, accounts for text alignment only. | 664 // Returns the line offset from the origin, accounts for text alignment only. |
655 Vector2d GetAlignmentOffset(size_t line_number); | 665 Vector2d GetAlignmentOffset(size_t line_number); |
656 | 666 |
657 // Applies fade effects to |renderer|. | 667 // Applies fade effects to |renderer|. |
658 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); | 668 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
659 | 669 |
660 // Applies text shadows to |renderer|. | 670 // Applies text shadows to |renderer|. |
(...skipping 13 matching lines...) Expand all Loading... | |
674 void UpdateStyleLengths(); | 684 void UpdateStyleLengths(); |
675 | 685 |
676 // A convenience function to check whether the glyph attached to the caret | 686 // A convenience function to check whether the glyph attached to the caret |
677 // is within the given range. | 687 // is within the given range. |
678 static bool RangeContainsCaret(const Range& range, | 688 static bool RangeContainsCaret(const Range& range, |
679 size_t caret_pos, | 689 size_t caret_pos, |
680 LogicalCursorDirection caret_affinity); | 690 LogicalCursorDirection caret_affinity); |
681 | 691 |
682 private: | 692 private: |
683 friend class test::RenderTextTestApi; | 693 friend class test::RenderTextTestApi; |
694 friend class ::views::LabelSelectionTest; | |
684 | 695 |
685 // Set the cursor to |position|, with the caret trailing the previous | 696 // Set the cursor to |position|, with the caret trailing the previous |
686 // grapheme, or if there is no previous grapheme, leading the cursor position. | 697 // grapheme, or if there is no previous grapheme, leading the cursor position. |
687 // If |select| is false, the selection start is moved to the same position. | 698 // If |select| is false, the selection start is moved to the same position. |
688 // If the |position| is not a cursorable position (not on grapheme boundary), | 699 // If the |position| is not a cursorable position (not on grapheme boundary), |
689 // it is a NO-OP. | 700 // it is a NO-OP. |
690 void MoveCursorTo(size_t position, bool select); | 701 void MoveCursorTo(size_t position, bool select); |
691 | 702 |
692 // Updates |layout_text_| and |display_text_| as needed (or marks them dirty). | 703 // Updates |layout_text_| and |display_text_| as needed (or marks them dirty). |
693 void OnTextAttributeChanged(); | 704 void OnTextAttributeChanged(); |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 // Lines computed by EnsureLayout. These should be invalidated upon | 872 // Lines computed by EnsureLayout. These should be invalidated upon |
862 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 873 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
863 std::vector<internal::Line> lines_; | 874 std::vector<internal::Line> lines_; |
864 | 875 |
865 DISALLOW_COPY_AND_ASSIGN(RenderText); | 876 DISALLOW_COPY_AND_ASSIGN(RenderText); |
866 }; | 877 }; |
867 | 878 |
868 } // namespace gfx | 879 } // namespace gfx |
869 | 880 |
870 #endif // UI_GFX_RENDER_TEXT_H_ | 881 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |