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

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

Issue 119813002: Implement eliding/truncating at end in RenderText (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed merge issue Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.cc ('k') | 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 <algorithm> 8 #include <algorithm>
9 #include <cstring> 9 #include <cstring>
10 #include <string> 10 #include <string>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
16 #include "base/strings/string16.h" 16 #include "base/strings/string16.h"
17 #include "skia/ext/refptr.h" 17 #include "skia/ext/refptr.h"
18 #include "third_party/skia/include/core/SkColor.h" 18 #include "third_party/skia/include/core/SkColor.h"
19 #include "third_party/skia/include/core/SkPaint.h" 19 #include "third_party/skia/include/core/SkPaint.h"
20 #include "third_party/skia/include/core/SkRect.h" 20 #include "third_party/skia/include/core/SkRect.h"
21 #include "ui/gfx/break_list.h" 21 #include "ui/gfx/break_list.h"
22 #include "ui/gfx/font_list.h" 22 #include "ui/gfx/font_list.h"
23 #include "ui/gfx/point.h" 23 #include "ui/gfx/point.h"
24 #include "ui/gfx/range/range.h" 24 #include "ui/gfx/range/range.h"
25 #include "ui/gfx/rect.h" 25 #include "ui/gfx/rect.h"
26 #include "ui/gfx/selection_model.h" 26 #include "ui/gfx/selection_model.h"
27 #include "ui/gfx/shadow_value.h" 27 #include "ui/gfx/shadow_value.h"
28 #include "ui/gfx/size_f.h" 28 #include "ui/gfx/size_f.h"
29 #include "ui/gfx/text_constants.h" 29 #include "ui/gfx/text_constants.h"
30 #include "ui/gfx/text_elider.h"
30 #include "ui/gfx/vector2d.h" 31 #include "ui/gfx/vector2d.h"
31 32
32 class SkCanvas; 33 class SkCanvas;
33 class SkDrawLooper; 34 class SkDrawLooper;
34 struct SkPoint; 35 struct SkPoint;
35 class SkShader; 36 class SkShader;
36 class SkTypeface; 37 class SkTypeface;
37 38
38 namespace gfx { 39 namespace gfx {
39 40
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // Windows. Support other platforms. 218 // Windows. Support other platforms.
218 bool multiline() const { return multiline_; } 219 bool multiline() const { return multiline_; }
219 void SetMultiline(bool multiline); 220 void SetMultiline(bool multiline);
220 221
221 // Set the maximum length of the displayed layout text, not the actual text. 222 // Set the maximum length of the displayed layout text, not the actual text.
222 // A |length| of 0 forgoes a hard limit, but does not guarantee proper 223 // A |length| of 0 forgoes a hard limit, but does not guarantee proper
223 // functionality of very long strings. Applies to subsequent SetText calls. 224 // functionality of very long strings. Applies to subsequent SetText calls.
224 // WARNING: Only use this for system limits, it lacks complex text support. 225 // WARNING: Only use this for system limits, it lacks complex text support.
225 void set_truncate_length(size_t length) { truncate_length_ = length; } 226 void set_truncate_length(size_t length) { truncate_length_ = length; }
226 227
228 // Elides the text to fit in |display_rect| according to the specified
229 // |elide_behavior|. |ELIDE_IN_MIDDLE| is not supported. If both truncate
230 // and elide are specified, the shorter of the two will be applicable.
231 void SetElideBehavior(ElideBehavior elide_behavior);
232
227 const Rect& display_rect() const { return display_rect_; } 233 const Rect& display_rect() const { return display_rect_; }
228 void SetDisplayRect(const Rect& r); 234 void SetDisplayRect(const Rect& r);
229 235
230 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } 236 void set_fade_head(bool fade_head) { fade_head_ = fade_head; }
231 bool fade_head() const { return fade_head_; } 237 bool fade_head() const { return fade_head_; }
232 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } 238 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; }
233 bool fade_tail() const { return fade_tail_; } 239 bool fade_tail() const { return fade_tail_; }
234 240
235 bool background_is_transparent() const { return background_is_transparent_; } 241 bool background_is_transparent() const { return background_is_transparent_; }
236 void set_background_is_transparent(bool transparent) { 242 void set_background_is_transparent(bool transparent) {
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 size_t caret_pos, 531 size_t caret_pos,
526 LogicalCursorDirection caret_affinity); 532 LogicalCursorDirection caret_affinity);
527 533
528 private: 534 private:
529 friend class RenderTextTest; 535 friend class RenderTextTest;
530 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); 536 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle);
531 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); 537 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle);
532 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); 538 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle);
533 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); 539 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText);
534 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); 540 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText);
541 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText);
542 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText);
535 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText); 543 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText);
536 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); 544 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText);
537 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); 545 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions);
538 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); 546 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels);
539 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); 547 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset);
540 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); 548 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL);
541 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); 549 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth);
542 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); 550 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth);
543 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); 551 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth);
544 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); 552 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline);
545 553
546 // Set the cursor to |position|, with the caret trailing the previous 554 // Set the cursor to |position|, with the caret trailing the previous
547 // grapheme, or if there is no previous grapheme, leading the cursor position. 555 // grapheme, or if there is no previous grapheme, leading the cursor position.
548 // If |select| is false, the selection start is moved to the same position. 556 // If |select| is false, the selection start is moved to the same position.
549 // If the |position| is not a cursorable position (not on grapheme boundary), 557 // If the |position| is not a cursorable position (not on grapheme boundary),
550 // it is a NO-OP. 558 // it is a NO-OP.
551 void MoveCursorTo(size_t position, bool select); 559 void MoveCursorTo(size_t position, bool select);
552 560
553 // Updates |layout_text_| if the text is obscured or truncated. 561 // Updates |layout_text_| if the text is obscured or truncated.
554 void UpdateLayoutText(); 562 void UpdateLayoutText();
555 563
564 // Elides |text| to fit in the |display_rect_| with given |elide_behavior_|.
565 // See ElideText in ui/gfx/text_elider.cc for reference.
566 base::string16 ElideText(const base::string16& text);
567
556 // Update the cached bounds and display offset to ensure that the current 568 // Update the cached bounds and display offset to ensure that the current
557 // cursor is within the visible display area. 569 // cursor is within the visible display area.
558 void UpdateCachedBoundsAndOffset(); 570 void UpdateCachedBoundsAndOffset();
559 571
560 // Draw the selection. 572 // Draw the selection.
561 void DrawSelection(Canvas* canvas); 573 void DrawSelection(Canvas* canvas);
562 574
563 // Logical UTF-16 string data to be drawn. 575 // Logical UTF-16 string data to be drawn.
564 base::string16 text_; 576 base::string16 text_;
565 577
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
618 bool composition_and_selection_styles_applied_; 630 bool composition_and_selection_styles_applied_;
619 631
620 // A flag to obscure actual text with asterisks for password fields. 632 // A flag to obscure actual text with asterisks for password fields.
621 bool obscured_; 633 bool obscured_;
622 // The index at which the char should be revealed in the obscured text. 634 // The index at which the char should be revealed in the obscured text.
623 int obscured_reveal_index_; 635 int obscured_reveal_index_;
624 636
625 // The maximum length of text to display, 0 forgoes a hard limit. 637 // The maximum length of text to display, 0 forgoes a hard limit.
626 size_t truncate_length_; 638 size_t truncate_length_;
627 639
640 // The behavior for eliding or truncating.
641 ElideBehavior elide_behavior_;
642
628 // The obscured and/or truncated text that will be displayed. 643 // The obscured and/or truncated text that will be displayed.
629 base::string16 layout_text_; 644 base::string16 layout_text_;
630 645
631 // Whether the text should be broken into multiple lines. Uses the width of 646 // Whether the text should be broken into multiple lines. Uses the width of
632 // |display_rect_| as the width cap. 647 // |display_rect_| as the width cap.
633 bool multiline_; 648 bool multiline_;
634 649
635 // Fade text head and/or tail, if text doesn't fit into |display_rect_|. 650 // Fade text head and/or tail, if text doesn't fit into |display_rect_|.
636 bool fade_head_; 651 bool fade_head_;
637 bool fade_tail_; 652 bool fade_tail_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
670 // Lines computed by EnsureLayout. These should be invalidated with 685 // Lines computed by EnsureLayout. These should be invalidated with
671 // ResetLayout and on |display_rect_| changes. 686 // ResetLayout and on |display_rect_| changes.
672 std::vector<internal::Line> lines_; 687 std::vector<internal::Line> lines_;
673 688
674 DISALLOW_COPY_AND_ASSIGN(RenderText); 689 DISALLOW_COPY_AND_ASSIGN(RenderText);
675 }; 690 };
676 691
677 } // namespace gfx 692 } // namespace gfx
678 693
679 #endif // UI_GFX_RENDER_TEXT_H_ 694 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_result_view.cc ('k') | ui/gfx/render_text.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698