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

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

Issue 2541313002: RenderTextHarfBuzz: Add support for multi line text selection. (Closed)
Patch Set: -- Created 4 years 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') | ui/gfx/render_text.cc » ('J')
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 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
152 152
153 DISALLOW_COPY_AND_ASSIGN(StyleIterator); 153 DISALLOW_COPY_AND_ASSIGN(StyleIterator);
154 }; 154 };
155 155
156 // Line segments are slices of the display text to be rendered on a single line. 156 // Line segments are slices of the display text to be rendered on a single line.
157 struct LineSegment { 157 struct LineSegment {
158 LineSegment(); 158 LineSegment();
159 ~LineSegment(); 159 ~LineSegment();
160 160
161 // X coordinates of this line segment in text space. 161 // X coordinates of this line segment in text space.
162 RangeF x_range; 162 RangeF x_range;
karandeepb 2016/12/07 03:57:47 I'd like to point out some issues I found with the
msw 2016/12/13 03:04:55 I'm afraid I can't offer much useful insight here.
karandeepb 2016/12/16 02:58:38 Yeah I think if this goes through, xrange can be r
163 163
164 // The character range this segment corresponds to. 164 // The character range this segment corresponds to.
165 Range char_range; 165 Range char_range;
166 166
167 // Index of the text run that generated this segment. 167 // Index of the text run that generated this segment.
168 size_t run; 168 size_t run;
169 169
170 // Returns the width of this line segment in text space. 170 // Returns the width of this line segment in text space.
171 float width() const { return x_range.length(); } 171 float width() const { return x_range.length(); }
172 }; 172 };
(...skipping 29 matching lines...) Expand all
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, '*'
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
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
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.
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
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.
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
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
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') | ui/gfx/render_text.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698