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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
202 SkPaint* paint); | 202 SkPaint* paint); |
203 | 203 |
204 } // namespace internal | 204 } // namespace internal |
205 | 205 |
206 // RenderText represents an abstract model of styled text and its corresponding | 206 // 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, | 207 // visual layout. Support is built in for a cursor, a selection, simple styling, |
208 // complex scripts, and bi-directional text. Implementations provide mechanisms | 208 // complex scripts, and bi-directional text. Implementations provide mechanisms |
209 // for rendering and translation between logical and visual data. | 209 // for rendering and translation between logical and visual data. |
210 class GFX_EXPORT RenderText { | 210 class GFX_EXPORT RenderText { |
211 public: | 211 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) | 212 #if defined(OS_MACOSX) |
213 // The character used for displaying obscured text. | |
214 // TODO(benrg): GTK uses the first of U+25CF, U+2022, U+2731, U+273A, '*' | |
msw
2016/12/07 20:20:35
nit: you can remove this TODO
karandeepb
2016/12/12 10:36:18
Done.
| |
215 // that's available in the font (find_invisible_char() in gtkentry.c). | |
216 // Use a bullet character on Mac. | |
217 static constexpr base::char16 kPasswordReplacementChar = 0x2022; | 217 static constexpr base::char16 kPasswordReplacementChar = 0x2022; |
218 | |
219 // On Mac, while selecting text if the cursor is outside the vertical text | |
220 // bounds, drag to the end of the text. | |
221 static constexpr bool kDragToEndIfOutsideVerticalBounds = true; | |
218 #else | 222 #else |
219 static constexpr base::char16 kPasswordReplacementChar = '*'; | 223 static constexpr base::char16 kPasswordReplacementChar = '*'; |
224 static constexpr bool kDragToEndIfOutsideVerticalBounds = false; | |
220 #endif | 225 #endif |
221 | 226 |
222 virtual ~RenderText(); | 227 virtual ~RenderText(); |
223 | 228 |
224 // Creates a platform-specific or cross-platform RenderText instance. | 229 // Creates a platform-specific or cross-platform RenderText instance. |
225 static RenderText* CreateInstance(); | 230 static RenderText* CreateInstance(); |
226 static RenderText* CreateInstanceForEditing(); | 231 static RenderText* CreateInstanceForEditing(); |
227 | 232 |
228 // Creates another instance of the same concrete class. | 233 // Creates another instance of the same concrete class. |
229 virtual std::unique_ptr<RenderText> CreateInstanceOfSameType() const = 0; | 234 virtual std::unique_ptr<RenderText> CreateInstanceOfSameType() const = 0; |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
405 // RenderText. | 410 // RenderText. |
406 bool GetStyle(TextStyle style) const; | 411 bool GetStyle(TextStyle style) const; |
407 | 412 |
408 // Set or get the text directionality mode and get the text direction yielded. | 413 // Set or get the text directionality mode and get the text direction yielded. |
409 void SetDirectionalityMode(DirectionalityMode mode); | 414 void SetDirectionalityMode(DirectionalityMode mode); |
410 DirectionalityMode directionality_mode() const { | 415 DirectionalityMode directionality_mode() const { |
411 return directionality_mode_; | 416 return directionality_mode_; |
412 } | 417 } |
413 base::i18n::TextDirection GetDisplayTextDirection(); | 418 base::i18n::TextDirection GetDisplayTextDirection(); |
414 | 419 |
415 // Returns the visual movement direction corresponding to the logical end | 420 // Returns the visual movement direction corresponding to the logical |
416 // of the text, considering only the dominant direction returned by | 421 // end/beginning of the text, considering only the dominant direction returned |
417 // |GetDisplayTextDirection()|, not the direction of a particular run. | 422 // by |GetDisplayTextDirection()|, not the direction of a particular run. |
418 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); | 423 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); |
424 VisualCursorDirection GetVisualDirectionOfLogicalBeginning(); | |
419 | 425 |
420 // Returns the text used to display, which may be obscured, truncated or | 426 // 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 | 427 // elided. The subclass may compute elided text on the fly, or use |
422 // precomputed the elided text. | 428 // precomputed the elided text. |
423 virtual const base::string16& GetDisplayText() = 0; | 429 virtual const base::string16& GetDisplayText() = 0; |
424 | 430 |
425 // Returns the size required to display the current string (which is the | 431 // 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 | 432 // wrapped size in multiline mode). The returned size does not include space |
427 // reserved for the cursor or the offset text shadows. | 433 // reserved for the cursor or the offset text shadows. |
428 virtual Size GetStringSize() = 0; | 434 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. | 472 // Returns true if this instance supports text selection. |
467 virtual bool IsSelectionSupported() const = 0; | 473 virtual bool IsSelectionSupported() const = 0; |
468 | 474 |
469 // Get the visual bounds of a cursor at |caret|. These bounds typically | 475 // 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 | 476 // 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 | 477 // |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 | 478 // 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 | 479 // is longer than the textfield. Subsequent text, cursor, or bounds changes |
474 // may invalidate returned values. Note that |caret| must be placed at | 480 // may invalidate returned values. Note that |caret| must be placed at |
475 // grapheme boundary, i.e. caret.caret_pos() must be a cursorable position. | 481 // grapheme boundary, i.e. caret.caret_pos() must be a cursorable position. |
482 // Note: This function does not support multiline currently. | |
msw
2016/12/07 20:20:35
nit: rephrase as a TODO; cite a bug if appropriate
karandeepb
2016/12/12 10:36:18
Done.
| |
476 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); | 483 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); |
477 | 484 |
478 // Compute the current cursor bounds, panning the text to show the cursor in | 485 // 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. | 486 // the display rect if necessary. These bounds are in local coordinates. |
480 // Subsequent text, cursor, or bounds changes may invalidate returned values. | 487 // Subsequent text, cursor, or bounds changes may invalidate returned values. |
481 const Rect& GetUpdatedCursorBounds(); | 488 const Rect& GetUpdatedCursorBounds(); |
482 | 489 |
483 // Given an |index| in text(), return the next or previous grapheme boundary | 490 // 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 | 491 // 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 | 492 // 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( | 591 virtual SelectionModel AdjacentCharSelectionModel( |
585 const SelectionModel& selection, | 592 const SelectionModel& selection, |
586 VisualCursorDirection direction) = 0; | 593 VisualCursorDirection direction) = 0; |
587 | 594 |
588 // Get the selection model visually left/right of |selection| by one word. | 595 // Get the selection model visually left/right of |selection| by one word. |
589 // The returned value represents a cursor/caret position without a selection. | 596 // The returned value represents a cursor/caret position without a selection. |
590 virtual SelectionModel AdjacentWordSelectionModel( | 597 virtual SelectionModel AdjacentWordSelectionModel( |
591 const SelectionModel& selection, | 598 const SelectionModel& selection, |
592 VisualCursorDirection direction) = 0; | 599 VisualCursorDirection direction) = 0; |
593 | 600 |
594 // Get the SelectionModels corresponding to visual text ends. | 601 // Get the SelectionModels corresponding to visual text ends. |
msw
2016/12/07 20:20:34
optional nit: "Get the selection model correspondi
karandeepb
2016/12/12 10:36:18
Done.
| |
595 // The returned value represents a cursor/caret position without a selection. | 602 // The returned value represents a cursor/caret position without a selection. |
596 SelectionModel EdgeSelectionModel(VisualCursorDirection direction); | 603 SelectionModel EdgeSelectionModel(VisualCursorDirection direction); |
597 | 604 |
605 // Get the selection model corresponding to visual text ends for the given | |
msw
2016/12/07 20:20:35
optional nit: "Get the selection model correspondi
karandeepb
2016/12/12 10:36:18
Done.
| |
606 // |line|. | |
607 // The returned value represents a cursor/caret position without a selection. | |
608 SelectionModel LineSelectionModel(const internal::Line& line, | |
609 gfx::VisualCursorDirection direction); | |
610 | |
598 // Sets the selection model, the argument is assumed to be valid. | 611 // Sets the selection model, the argument is assumed to be valid. |
599 virtual void SetSelectionModel(const SelectionModel& model); | 612 virtual void SetSelectionModel(const SelectionModel& model); |
600 | 613 |
601 // Get the visual bounds containing the logical substring within the |range|. | 614 // 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 | 615 // 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. | 616 // 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 | 617 // 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, | 618 // region if the text is longer than the textfield. Subsequent text, cursor, |
606 // or bounds changes may invalidate returned values. | 619 // or bounds changes may invalidate returned values. |
607 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; | 620 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; |
(...skipping 25 matching lines...) Expand all Loading... | |
633 // Update the display text. | 646 // Update the display text. |
634 void UpdateDisplayText(float text_width); | 647 void UpdateDisplayText(float text_width); |
635 | 648 |
636 // Returns display text positions that are suitable for breaking lines. | 649 // Returns display text positions that are suitable for breaking lines. |
637 const BreakList<size_t>& GetLineBreaks(); | 650 const BreakList<size_t>& GetLineBreaks(); |
638 | 651 |
639 // Apply (and undo) temporary composition underlines and selection colors. | 652 // Apply (and undo) temporary composition underlines and selection colors. |
640 void ApplyCompositionAndSelectionStyles(); | 653 void ApplyCompositionAndSelectionStyles(); |
641 void UndoCompositionAndSelectionStyles(); | 654 void UndoCompositionAndSelectionStyles(); |
642 | 655 |
643 // Convert points from the text space to the view space and back. Handles the | 656 // Convert points from the text space to the view space. Handles the display |
644 // display area, display offset, application LTR/RTL mode and multiline. | 657 // area, display offset, application LTR/RTL mode and multiline. |
645 Point ToTextPoint(const Point& point); | |
646 Point ToViewPoint(const Point& point); | 658 Point ToViewPoint(const Point& point); |
647 | 659 |
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. | 660 // Get the alignment, resolving ALIGN_TO_HEAD with the current text direction. |
652 HorizontalAlignment GetCurrentHorizontalAlignment(); | 661 HorizontalAlignment GetCurrentHorizontalAlignment(); |
653 | 662 |
654 // Returns the line offset from the origin, accounts for text alignment only. | 663 // Returns the line offset from the origin, accounts for text alignment only. |
655 Vector2d GetAlignmentOffset(size_t line_number); | 664 Vector2d GetAlignmentOffset(size_t line_number); |
656 | 665 |
657 // Applies fade effects to |renderer|. | 666 // Applies fade effects to |renderer|. |
658 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); | 667 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
659 | 668 |
660 // Applies text shadows to |renderer|. | 669 // Applies text shadows to |renderer|. |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
861 // Lines computed by EnsureLayout. These should be invalidated upon | 870 // Lines computed by EnsureLayout. These should be invalidated upon |
862 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 871 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
863 std::vector<internal::Line> lines_; | 872 std::vector<internal::Line> lines_; |
864 | 873 |
865 DISALLOW_COPY_AND_ASSIGN(RenderText); | 874 DISALLOW_COPY_AND_ASSIGN(RenderText); |
866 }; | 875 }; |
867 | 876 |
868 } // namespace gfx | 877 } // namespace gfx |
869 | 878 |
870 #endif // UI_GFX_RENDER_TEXT_H_ | 879 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |