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

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

Issue 916203002: Reduce the number of text reshaping in RenderText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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') | 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 <algorithm> 8 #include <algorithm>
9 #include <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 void SetMultiline(bool multiline); 260 void SetMultiline(bool multiline);
261 261
262 // TODO(ckocagil): Add vertical alignment and line spacing support instead. 262 // TODO(ckocagil): Add vertical alignment and line spacing support instead.
263 int min_line_height() const { return min_line_height_; } 263 int min_line_height() const { return min_line_height_; }
264 void SetMinLineHeight(int line_height); 264 void SetMinLineHeight(int line_height);
265 265
266 // Set the maximum length of the displayed layout text, not the actual text. 266 // Set the maximum length of the displayed layout text, not the actual text.
267 // A |length| of 0 forgoes a hard limit, but does not guarantee proper 267 // A |length| of 0 forgoes a hard limit, but does not guarantee proper
268 // functionality of very long strings. Applies to subsequent SetText calls. 268 // functionality of very long strings. Applies to subsequent SetText calls.
269 // WARNING: Only use this for system limits, it lacks complex text support. 269 // WARNING: Only use this for system limits, it lacks complex text support.
270 void set_truncate_length(size_t length) { truncate_length_ = length; } 270 void set_truncate_length(size_t length) { truncate_length_ = length; }
Jun Mukai 2015/02/12 21:56:46 Doesn't this have to update the layout text?
oshima 2015/02/12 22:09:17 This is used as safe guard now. I'd like to change
msw 2015/02/12 22:45:06 That's fine with me.
271 271
272 // The layout text will be elided to fit |display_rect| using this behavior. 272 // The layout text will be elided to fit |display_rect| using this behavior.
273 // The layout text may be shortened further by the truncate length. 273 // The layout text may be shortened further by the truncate length.
274 void SetElideBehavior(ElideBehavior elide_behavior); 274 void SetElideBehavior(ElideBehavior elide_behavior);
275 ElideBehavior elide_behavior() const { return elide_behavior_; } 275 ElideBehavior elide_behavior() const { return elide_behavior_; }
276 276
277 const base::string16& layout_text() const { return layout_text_; }
278
279 const Rect& display_rect() const { return display_rect_; } 277 const Rect& display_rect() const { return display_rect_; }
280 void SetDisplayRect(const Rect& r); 278 void SetDisplayRect(const Rect& r);
281 279
282 bool background_is_transparent() const { return background_is_transparent_; } 280 bool background_is_transparent() const { return background_is_transparent_; }
283 void set_background_is_transparent(bool transparent) { 281 void set_background_is_transparent(bool transparent) {
284 background_is_transparent_ = transparent; 282 background_is_transparent_ = transparent;
285 } 283 }
286 284
287 const SelectionModel& selection_model() const { return selection_model_; } 285 const SelectionModel& selection_model() const { return selection_model_; }
288 286
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
351 DirectionalityMode directionality_mode() const { 349 DirectionalityMode directionality_mode() const {
352 return directionality_mode_; 350 return directionality_mode_;
353 } 351 }
354 base::i18n::TextDirection GetTextDirection(); 352 base::i18n::TextDirection GetTextDirection();
355 353
356 // Returns the visual movement direction corresponding to the logical end 354 // Returns the visual movement direction corresponding to the logical end
357 // of the text, considering only the dominant direction returned by 355 // of the text, considering only the dominant direction returned by
358 // |GetTextDirection()|, not the direction of a particular run. 356 // |GetTextDirection()|, not the direction of a particular run.
359 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); 357 VisualCursorDirection GetVisualDirectionOfLogicalEnd();
360 358
359 // Returns the text used for layout, which may be obscured,
360 // truncated or elided. The subclass may compute elided text on the fly,
361 // or use precomputed the elided text.
362 virtual const base::string16& GetLayoutText() = 0;
363
361 // Returns the size required to display the current string (which is the 364 // Returns the size required to display the current string (which is the
362 // wrapped size in multiline mode). The returned size does not include space 365 // wrapped size in multiline mode). The returned size does not include space
363 // reserved for the cursor or the offset text shadows. 366 // reserved for the cursor or the offset text shadows.
364 virtual Size GetStringSize() = 0; 367 virtual Size GetStringSize() = 0;
365 368
366 // This is same as GetStringSize except that fractional size is returned. 369 // This is same as GetStringSize except that fractional size is returned.
367 // The default implementation is same as GetStringSize. Certain platforms that 370 // The default implementation is same as GetStringSize. Certain platforms that
368 // compute the text size as floating-point values, like Mac, will override 371 // compute the text size as floating-point values, like Mac, will override
369 // this method. 372 // this method.
370 // See comment in Canvas::GetStringWidthF for its usage. 373 // See comment in Canvas::GetStringWidthF for its usage.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // Range will have is_reversed() true. (This does not return a Rect because a 444 // Range will have is_reversed() true. (This does not return a Rect because a
442 // Rect can't have a negative width.) 445 // Rect can't have a negative width.)
443 virtual Range GetGlyphBounds(size_t index) = 0; 446 virtual Range GetGlyphBounds(size_t index) = 0;
444 447
445 const Vector2d& GetUpdatedDisplayOffset(); 448 const Vector2d& GetUpdatedDisplayOffset();
446 void SetDisplayOffset(int horizontal_offset); 449 void SetDisplayOffset(int horizontal_offset);
447 450
448 protected: 451 protected:
449 RenderText(); 452 RenderText();
450 453
454 const base::string16& layout_text() const { return layout_text_; }
455 const base::string16& elided_text() const { return elided_text_; }
456 bool text_elided() const { return text_elided_; }
457
451 const BreakList<SkColor>& colors() const { return colors_; } 458 const BreakList<SkColor>& colors() const { return colors_; }
452 const std::vector<BreakList<bool> >& styles() const { return styles_; } 459 const std::vector<BreakList<bool> >& styles() const { return styles_; }
453 460
454 const std::vector<internal::Line>& lines() const { return lines_; } 461 const std::vector<internal::Line>& lines() const { return lines_; }
455 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } 462 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); }
456 463
457 // Returns the baseline of the current text. The return value depends on 464 // Returns the baseline of the current text. The return value depends on
458 // the text and its layout while the return value of GetBaseline() doesn't. 465 // the text and its layout while the return value of GetBaseline() doesn't.
459 // GetAlignmentOffset() takes into account the difference between them. 466 // GetAlignmentOffset() takes into account the difference between them.
460 // 467 //
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 virtual void SetSelectionModel(const SelectionModel& model); 515 virtual void SetSelectionModel(const SelectionModel& model);
509 516
510 // Get the visual bounds containing the logical substring within the |range|. 517 // Get the visual bounds containing the logical substring within the |range|.
511 // If |range| is empty, the result is empty. These bounds could be visually 518 // If |range| is empty, the result is empty. These bounds could be visually
512 // discontinuous if the substring is split by a LTR/RTL level change. 519 // discontinuous if the substring is split by a LTR/RTL level change.
513 // These bounds are in local coordinates, but may be outside the visible 520 // These bounds are in local coordinates, but may be outside the visible
514 // region if the text is longer than the textfield. Subsequent text, cursor, 521 // region if the text is longer than the textfield. Subsequent text, cursor,
515 // or bounds changes may invalidate returned values. 522 // or bounds changes may invalidate returned values.
516 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; 523 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0;
517 524
518 // Convert between indices into |text_| and indices into |obscured_text_|, 525 // Convert between indices into |text_| and indices into
519 // which differ when the text is obscured. Regardless of whether or not the 526 // GetLayoutText(), which differ when the text is obscured,
520 // text is obscured, the character (code point) offsets always match. 527 // truncated or elided. Regardless of whether or not the text is
521 virtual size_t TextIndexToLayoutIndex(size_t index) const = 0; 528 // obscured, the character (code point) offsets always match.
522 virtual size_t LayoutIndexToTextIndex(size_t index) const = 0; 529 virtual size_t TextIndexToLayoutIndex(size_t index) = 0;
530 virtual size_t LayoutIndexToTextIndex(size_t index) = 0;
523 531
524 // Reset the layout to be invalid. 532 // Notifies that layout text, or attributes that affects layout text
525 virtual void ResetLayout() = 0; 533 // shape have changed. |text_changed| is true if the content of the
534 // |layouttext_| has changed, not just attributes.
msw 2015/02/12 22:45:06 nit: |layout_text_|
oshima 2015/02/13 00:29:43 Done.
535 virtual void OnLayoutTextShapeChanged(bool text_changed) = 0;
536
537 // Notifies that attributes that affects elided text shape has changed.
msw 2015/02/12 22:45:06 nit: s/affects/affect/ and s/has/have/
oshima 2015/02/13 00:29:43 Done.
538 virtual void OnElidedTextShapeChanged() = 0;
526 539
527 // Ensure the text is laid out, lines are computed, and |lines_| is valid. 540 // Ensure the text is laid out, lines are computed, and |lines_| is valid.
528 virtual void EnsureLayout() = 0; 541 virtual void EnsureLayout() = 0;
529 542
530 // Draw the text. 543 // Draw the text.
531 virtual void DrawVisualText(Canvas* canvas) = 0; 544 virtual void DrawVisualText(Canvas* canvas) = 0;
532 545
533 // Returns the text used for layout, which may be obscured or truncated. 546 // Update the elided text.
534 const base::string16& GetLayoutText() const; 547 void UpdateElidedText(float visual_width);
535 548
536 // Returns layout text positions that are suitable for breaking lines. 549 // Returns layout text positions that are suitable for breaking lines.
537 const BreakList<size_t>& GetLineBreaks(); 550 const BreakList<size_t>& GetLineBreaks();
538 551
539 // Apply (and undo) temporary composition underlines and selection colors. 552 // Apply (and undo) temporary composition underlines and selection colors.
540 void ApplyCompositionAndSelectionStyles(); 553 void ApplyCompositionAndSelectionStyles();
541 void UndoCompositionAndSelectionStyles(); 554 void UndoCompositionAndSelectionStyles();
542 555
543 // Returns the line offset from the origin after applying the text alignment 556 // Returns the line offset from the origin after applying the text alignment
544 // and the display offset. 557 // and the display offset.
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
602 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StringFitsOwnWidth); 615 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StringFitsOwnWidth);
603 616
604 // Set the cursor to |position|, with the caret trailing the previous 617 // Set the cursor to |position|, with the caret trailing the previous
605 // grapheme, or if there is no previous grapheme, leading the cursor position. 618 // grapheme, or if there is no previous grapheme, leading the cursor position.
606 // If |select| is false, the selection start is moved to the same position. 619 // If |select| is false, the selection start is moved to the same position.
607 // If the |position| is not a cursorable position (not on grapheme boundary), 620 // If the |position| is not a cursorable position (not on grapheme boundary),
608 // it is a NO-OP. 621 // it is a NO-OP.
609 void MoveCursorTo(size_t position, bool select); 622 void MoveCursorTo(size_t position, bool select);
610 623
611 // Updates |layout_text_| if the text is obscured or truncated. 624 // Updates |layout_text_| if the text is obscured or truncated.
625 // This will triggers |elided_text_| update.
msw 2015/02/12 22:45:06 nit: merge the comments to something simpler, like
oshima 2015/02/13 00:29:43 Done.
612 void UpdateLayoutText(); 626 void UpdateLayoutText();
msw 2015/02/12 22:45:06 I like the pattern of On*Changed, and I could see
oshima 2015/02/13 00:29:43 Changed to OnTextAttributeChanged
613 627
614 // Elides |text| as needed to fit in the |available_width| using |behavior|. 628 // Elides |text| as needed to fit in the |available_width| using |behavior|.
629 // |text_width| is the pre-calculated width of the text shaped by this render
630 // text, or pass 0 if the width is unknown.
615 base::string16 Elide(const base::string16& text, 631 base::string16 Elide(const base::string16& text,
632 float text_width,
616 float available_width, 633 float available_width,
617 ElideBehavior behavior); 634 ElideBehavior behavior);
618 635
619 // Elides |email| as needed to fit the |available_width|. 636 // Elides |email| as needed to fit the |available_width|.
620 base::string16 ElideEmail(const base::string16& email, float available_width); 637 base::string16 ElideEmail(const base::string16& email, float available_width);
621 638
622 // Update the cached bounds and display offset to ensure that the current 639 // Update the cached bounds and display offset to ensure that the current
623 // cursor is within the visible display area. 640 // cursor is within the visible display area.
624 void UpdateCachedBoundsAndOffset(); 641 void UpdateCachedBoundsAndOffset();
625 642
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 bool obscured_; 704 bool obscured_;
688 // The index at which the char should be revealed in the obscured text. 705 // The index at which the char should be revealed in the obscured text.
689 int obscured_reveal_index_; 706 int obscured_reveal_index_;
690 707
691 // The maximum length of text to display, 0 forgoes a hard limit. 708 // The maximum length of text to display, 0 forgoes a hard limit.
692 size_t truncate_length_; 709 size_t truncate_length_;
693 710
694 // The behavior for eliding, fading, or truncating. 711 // The behavior for eliding, fading, or truncating.
695 ElideBehavior elide_behavior_; 712 ElideBehavior elide_behavior_;
696 713
697 // The obscured and/or truncated text that will be displayed. 714 // The obscured and/or truncated text, before elided.
msw 2015/02/12 22:45:06 Rename this, it doesn't match the semantics of Get
oshima 2015/02/13 00:29:43 kept layout_text_ and changed elided_text_ to disp
698 base::string16 layout_text_; 715 base::string16 layout_text_;
699 716
717 // The elided text. This is empty if the text does not have to be elided.
718 base::string16 elided_text_;
msw 2015/02/12 22:45:06 nit: reorder |elide_behavior_| to come immediately
oshima 2015/02/13 00:29:43 Done.
719
720 bool text_elided_;
msw 2015/02/12 22:45:06 nit: add a comment like "True if the text is elide
oshima 2015/02/13 00:29:43 Done.
721
700 // Whether newline characters should be replaced with newline symbols. 722 // Whether newline characters should be replaced with newline symbols.
701 bool replace_newline_chars_with_symbols_; 723 bool replace_newline_chars_with_symbols_;
702 724
703 // The minimum height a line should have. 725 // The minimum height a line should have.
704 int min_line_height_; 726 int min_line_height_;
705 727
706 // Whether the text should be broken into multiple lines. Uses the width of 728 // Whether the text should be broken into multiple lines. Uses the width of
707 // |display_rect_| as the width cap. 729 // |display_rect_| as the width cap.
708 bool multiline_; 730 bool multiline_;
709 731
(...skipping 22 matching lines...) Expand all
732 // selection, font, and other operations that adjust the visible text bounds. 754 // selection, font, and other operations that adjust the visible text bounds.
733 bool cached_bounds_and_offset_valid_; 755 bool cached_bounds_and_offset_valid_;
734 756
735 // Text shadows to be drawn. 757 // Text shadows to be drawn.
736 ShadowValues shadows_; 758 ShadowValues shadows_;
737 759
738 // A list of valid layout text line break positions. 760 // A list of valid layout text line break positions.
739 BreakList<size_t> line_breaks_; 761 BreakList<size_t> line_breaks_;
740 762
741 // Lines computed by EnsureLayout. These should be invalidated with 763 // Lines computed by EnsureLayout. These should be invalidated with
742 // ResetLayout and on |display_rect_| changes. 764 // ResetLayout and on |display_rect_| changes.
msw 2015/02/12 22:45:06 nit: Update the comment referencing ResetLayout.
743 std::vector<internal::Line> lines_; 765 std::vector<internal::Line> lines_;
744 766
745 DISALLOW_COPY_AND_ASSIGN(RenderText); 767 DISALLOW_COPY_AND_ASSIGN(RenderText);
746 }; 768 };
747 769
748 } // namespace gfx 770 } // namespace gfx
749 771
750 #endif // UI_GFX_RENDER_TEXT_H_ 772 #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