Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: ui/gfx/render_text.h

Issue 2541313002: RenderTextHarfBuzz: Add support for multi line text selection. (Closed)
Patch Set: Fix test. Created 3 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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. Use a bullet character on
214 // Mac.
217 static constexpr base::char16 kPasswordReplacementChar = 0x2022; 215 static constexpr base::char16 kPasswordReplacementChar = 0x2022;
216
217 // On Mac, while selecting text if the cursor is outside the vertical text
218 // bounds, drag to the end of the text.
219 static constexpr bool kDragToEndIfOutsideVerticalBounds = true;
218 #else 220 #else
219 static constexpr base::char16 kPasswordReplacementChar = '*'; 221 static constexpr base::char16 kPasswordReplacementChar = '*';
222 static constexpr bool kDragToEndIfOutsideVerticalBounds = false;
220 #endif 223 #endif
221 224
222 virtual ~RenderText(); 225 virtual ~RenderText();
223 226
224 // Creates a platform-specific or cross-platform RenderText instance. 227 // Creates a platform-specific or cross-platform RenderText instance.
225 static RenderText* CreateInstance(); 228 static RenderText* CreateInstance();
226 static RenderText* CreateInstanceForEditing(); 229 static RenderText* CreateInstanceForEditing();
227 230
228 // Creates another instance of the same concrete class. 231 // Creates another instance of the same concrete class.
229 virtual std::unique_ptr<RenderText> CreateInstanceOfSameType() const = 0; 232 virtual std::unique_ptr<RenderText> CreateInstanceOfSameType() const = 0;
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 // RenderText. 408 // RenderText.
406 bool GetStyle(TextStyle style) const; 409 bool GetStyle(TextStyle style) const;
407 410
408 // Set or get the text directionality mode and get the text direction yielded. 411 // Set or get the text directionality mode and get the text direction yielded.
409 void SetDirectionalityMode(DirectionalityMode mode); 412 void SetDirectionalityMode(DirectionalityMode mode);
410 DirectionalityMode directionality_mode() const { 413 DirectionalityMode directionality_mode() const {
411 return directionality_mode_; 414 return directionality_mode_;
412 } 415 }
413 base::i18n::TextDirection GetDisplayTextDirection(); 416 base::i18n::TextDirection GetDisplayTextDirection();
414 417
415 // Returns the visual movement direction corresponding to the logical end 418 // Returns the visual movement direction corresponding to the logical
416 // of the text, considering only the dominant direction returned by 419 // end/beginning of the text, considering only the dominant direction returned
417 // |GetDisplayTextDirection()|, not the direction of a particular run. 420 // by |GetDisplayTextDirection()|, not the direction of a particular run.
418 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); 421 VisualCursorDirection GetVisualDirectionOfLogicalEnd();
422 VisualCursorDirection GetVisualDirectionOfLogicalBeginning();
419 423
420 // Returns the text used to display, which may be obscured, truncated or 424 // 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 425 // elided. The subclass may compute elided text on the fly, or use
422 // precomputed the elided text. 426 // precomputed the elided text.
423 virtual const base::string16& GetDisplayText() = 0; 427 virtual const base::string16& GetDisplayText() = 0;
424 428
425 // Returns the size required to display the current string (which is the 429 // 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 430 // wrapped size in multiline mode). The returned size does not include space
427 // reserved for the cursor or the offset text shadows. 431 // reserved for the cursor or the offset text shadows.
428 virtual Size GetStringSize() = 0; 432 virtual Size GetStringSize() = 0;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
466 // Returns true if this instance supports text selection. 470 // Returns true if this instance supports text selection.
467 virtual bool IsSelectionSupported() const = 0; 471 virtual bool IsSelectionSupported() const = 0;
468 472
469 // Get the visual bounds of a cursor at |caret|. These bounds typically 473 // 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 474 // 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 475 // |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 476 // 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 477 // is longer than the textfield. Subsequent text, cursor, or bounds changes
474 // may invalidate returned values. Note that |caret| must be placed at 478 // may invalidate returned values. Note that |caret| must be placed at
475 // grapheme boundary, i.e. caret.caret_pos() must be a cursorable position. 479 // grapheme boundary, i.e. caret.caret_pos() must be a cursorable position.
480 // TODO(crbug.com/248597): Add multiline support.
476 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode); 481 Rect GetCursorBounds(const SelectionModel& caret, bool insert_mode);
477 482
478 // Compute the current cursor bounds, panning the text to show the cursor in 483 // 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. 484 // the display rect if necessary. These bounds are in local coordinates.
480 // Subsequent text, cursor, or bounds changes may invalidate returned values. 485 // Subsequent text, cursor, or bounds changes may invalidate returned values.
481 const Rect& GetUpdatedCursorBounds(); 486 const Rect& GetUpdatedCursorBounds();
482 487
483 // Given an |index| in text(), return the next or previous grapheme boundary 488 // 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 489 // 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 490 // in the range 0 to text().length() inclusive (the input is clamped if it is
(...skipping 10 matching lines...) Expand all
496 void set_shadows(const ShadowValues& shadows) { shadows_ = shadows; } 501 void set_shadows(const ShadowValues& shadows) { shadows_ = shadows; }
497 const ShadowValues& shadows() const { return shadows_; } 502 const ShadowValues& shadows() const { return shadows_; }
498 503
499 typedef std::pair<Font, Range> FontSpan; 504 typedef std::pair<Font, Range> FontSpan;
500 // For testing purposes, returns which fonts were chosen for which parts of 505 // For testing purposes, returns which fonts were chosen for which parts of
501 // the text by returning a vector of Font and Range pairs, where each range 506 // the text by returning a vector of Font and Range pairs, where each range
502 // specifies the character range for which the corresponding font has been 507 // specifies the character range for which the corresponding font has been
503 // chosen. 508 // chosen.
504 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; 509 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0;
505 510
511 // Helper function to be used in tests for retrieving the substring bounds.
512 std::vector<Rect> GetSubstringBoundsForTesting(const gfx::Range& range);
513
506 // Gets the horizontal bounds (relative to the left of the text, not the view) 514 // Gets the horizontal bounds (relative to the left of the text, not the view)
507 // of the glyph starting at |index|. If the glyph is RTL then the returned 515 // of the glyph starting at |index|. If the glyph is RTL then the returned
508 // Range will have is_reversed() true. (This does not return a Rect because a 516 // Range will have is_reversed() true. (This does not return a Rect because a
509 // Rect can't have a negative width.) 517 // Rect can't have a negative width.)
510 virtual Range GetGlyphBounds(size_t index) = 0; 518 virtual Range GetGlyphBounds(size_t index) = 0;
511 519
512 const Vector2d& GetUpdatedDisplayOffset(); 520 const Vector2d& GetUpdatedDisplayOffset();
513 void SetDisplayOffset(int horizontal_offset); 521 void SetDisplayOffset(int horizontal_offset);
514 522
515 // Returns the line offset from the origin after applying the text alignment 523 // Returns the line offset from the origin after applying the text alignment
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
584 virtual SelectionModel AdjacentCharSelectionModel( 592 virtual SelectionModel AdjacentCharSelectionModel(
585 const SelectionModel& selection, 593 const SelectionModel& selection,
586 VisualCursorDirection direction) = 0; 594 VisualCursorDirection direction) = 0;
587 595
588 // Get the selection model visually left/right of |selection| by one word. 596 // Get the selection model visually left/right of |selection| by one word.
589 // The returned value represents a cursor/caret position without a selection. 597 // The returned value represents a cursor/caret position without a selection.
590 virtual SelectionModel AdjacentWordSelectionModel( 598 virtual SelectionModel AdjacentWordSelectionModel(
591 const SelectionModel& selection, 599 const SelectionModel& selection,
592 VisualCursorDirection direction) = 0; 600 VisualCursorDirection direction) = 0;
593 601
594 // Get the SelectionModels corresponding to visual text ends. 602 // Get the selection model corresponding to visual text ends.
595 // The returned value represents a cursor/caret position without a selection. 603 // The returned value represents a cursor/caret position without a selection.
596 SelectionModel EdgeSelectionModel(VisualCursorDirection direction); 604 SelectionModel EdgeSelectionModel(VisualCursorDirection direction);
597 605
606 // Get the selection model corresponding to visual text ends for |line_index|.
607 // The returned value represents a cursor/caret position without a selection.
608 SelectionModel LineSelectionModel(size_t line_index,
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
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
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_
OLDNEW
« no previous file with comments | « no previous file | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698