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

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

Issue 112063003: Implement eliding/truncating at end in RenderText (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // Windows. Support other platforms. 221 // Windows. Support other platforms.
221 bool multiline() const { return multiline_; } 222 bool multiline() const { return multiline_; }
222 void SetMultiline(bool multiline); 223 void SetMultiline(bool multiline);
223 224
224 // Set the maximum length of the displayed layout text, not the actual text. 225 // Set the maximum length of the displayed layout text, not the actual text.
225 // A |length| of 0 forgoes a hard limit, but does not guarantee proper 226 // A |length| of 0 forgoes a hard limit, but does not guarantee proper
226 // functionality of very long strings. Applies to subsequent SetText calls. 227 // functionality of very long strings. Applies to subsequent SetText calls.
227 // WARNING: Only use this for system limits, it lacks complex text support. 228 // WARNING: Only use this for system limits, it lacks complex text support.
228 void set_truncate_length(size_t length) { truncate_length_ = length; } 229 void set_truncate_length(size_t length) { truncate_length_ = length; }
229 230
231 // Elides the text to fit in |available_pixel_width| according to the
232 // specified |elide_behavior|. Only one of elide or truncate should be used.
msw 2013/12/11 08:10:14 We should support simultaneous truncation and elid
Anuj 2013/12/11 18:41:32 The second part of the comment mentions what will
msw 2013/12/11 19:39:57 Then this says elide shouldn't be used on windows,
Anuj 2013/12/12 08:08:41 Done.
233 // If both are specified, the shorter of the two will be applicable.
234 void Elide(float available_pixel_width, ElideBehavior elide_behavior);
msw 2013/12/11 08:10:14 I would rather this function be SetElideBehavior(E
Anuj 2013/12/11 18:41:32 So I will need to add UpdateLayoutText to both of
msw 2013/12/11 19:39:57 I think that'll be okay, but you'll only need to U
Anuj 2013/12/12 08:08:41 Done.
235
230 const Rect& display_rect() const { return display_rect_; } 236 const Rect& display_rect() const { return display_rect_; }
231 void SetDisplayRect(const Rect& r); 237 void SetDisplayRect(const Rect& r);
232 238
233 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } 239 void set_fade_head(bool fade_head) { fade_head_ = fade_head; }
234 bool fade_head() const { return fade_head_; } 240 bool fade_head() const { return fade_head_; }
235 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } 241 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; }
236 bool fade_tail() const { return fade_tail_; } 242 bool fade_tail() const { return fade_tail_; }
237 243
238 bool background_is_transparent() const { return background_is_transparent_; } 244 bool background_is_transparent() const { return background_is_transparent_; }
239 void set_background_is_transparent(bool transparent) { 245 void set_background_is_transparent(bool transparent) {
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 // Set the cursor to |position|, with the caret trailing the previous 555 // Set the cursor to |position|, with the caret trailing the previous
550 // grapheme, or if there is no previous grapheme, leading the cursor position. 556 // grapheme, or if there is no previous grapheme, leading the cursor position.
551 // If |select| is false, the selection start is moved to the same position. 557 // If |select| is false, the selection start is moved to the same position.
552 // If the |position| is not a cursorable position (not on grapheme boundary), 558 // If the |position| is not a cursorable position (not on grapheme boundary),
553 // it is a NO-OP. 559 // it is a NO-OP.
554 void MoveCursorTo(size_t position, bool select); 560 void MoveCursorTo(size_t position, bool select);
555 561
556 // Updates |layout_text_| if the text is obscured or truncated. 562 // Updates |layout_text_| if the text is obscured or truncated.
557 void UpdateLayoutText(); 563 void UpdateLayoutText();
558 564
565 // Elides |text| to fit in the |available_pixel_width_| with given
566 // |elide_behavior_|.
567 // See ElideText in ui/gfx/text_elider.cc for reference.
568 base::string16 ElideText(const base::string16& text);
569
559 // Update the cached bounds and display offset to ensure that the current 570 // Update the cached bounds and display offset to ensure that the current
560 // cursor is within the visible display area. 571 // cursor is within the visible display area.
561 void UpdateCachedBoundsAndOffset(); 572 void UpdateCachedBoundsAndOffset();
562 573
563 // Draw the selection. 574 // Draw the selection.
564 void DrawSelection(Canvas* canvas); 575 void DrawSelection(Canvas* canvas);
565 576
566 // Logical UTF-16 string data to be drawn. 577 // Logical UTF-16 string data to be drawn.
567 base::string16 text_; 578 base::string16 text_;
568 579
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 bool composition_and_selection_styles_applied_; 632 bool composition_and_selection_styles_applied_;
622 633
623 // A flag to obscure actual text with asterisks for password fields. 634 // A flag to obscure actual text with asterisks for password fields.
624 bool obscured_; 635 bool obscured_;
625 // The index at which the char should be revealed in the obscured text. 636 // The index at which the char should be revealed in the obscured text.
626 int obscured_reveal_index_; 637 int obscured_reveal_index_;
627 638
628 // The maximum length of text to display, 0 forgoes a hard limit. 639 // The maximum length of text to display, 0 forgoes a hard limit.
629 size_t truncate_length_; 640 size_t truncate_length_;
630 641
642 // The maxmium width available to display the text.
msw 2013/12/11 08:10:14 nit: " // The maximum width used for eliding, dis
Anuj 2013/12/12 08:08:41 Done.
643 float available_pixel_width_;
644
645 // The behavior for eliding or truncating.
646 ElideBehavior elide_behavior_;
647
631 // The obscured and/or truncated text that will be displayed. 648 // The obscured and/or truncated text that will be displayed.
632 base::string16 layout_text_; 649 base::string16 layout_text_;
633 650
634 // Whether the text should be broken into multiple lines. Uses the width of 651 // Whether the text should be broken into multiple lines. Uses the width of
635 // |display_rect_| as the width cap. 652 // |display_rect_| as the width cap.
636 bool multiline_; 653 bool multiline_;
637 654
638 // Fade text head and/or tail, if text doesn't fit into |display_rect_|. 655 // Fade text head and/or tail, if text doesn't fit into |display_rect_|.
639 bool fade_head_; 656 bool fade_head_;
640 bool fade_tail_; 657 bool fade_tail_;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 // Lines computed by EnsureLayout. These should be invalidated with 690 // Lines computed by EnsureLayout. These should be invalidated with
674 // ResetLayout and on |display_rect_| changes. 691 // ResetLayout and on |display_rect_| changes.
675 std::vector<internal::Line> lines_; 692 std::vector<internal::Line> lines_;
676 693
677 DISALLOW_COPY_AND_ASSIGN(RenderText); 694 DISALLOW_COPY_AND_ASSIGN(RenderText);
678 }; 695 };
679 696
680 } // namespace gfx 697 } // namespace gfx
681 698
682 #endif // UI_GFX_RENDER_TEXT_H_ 699 #endif // UI_GFX_RENDER_TEXT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698