OLD | NEW |
---|---|
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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
221 // Windows. Support other platforms. | 222 // Windows. Support other platforms. |
222 bool multiline() const { return multiline_; } | 223 bool multiline() const { return multiline_; } |
223 void SetMultiline(bool multiline); | 224 void SetMultiline(bool multiline); |
224 | 225 |
225 // Set the maximum length of the displayed layout text, not the actual text. | 226 // Set the maximum length of the displayed layout text, not the actual text. |
226 // A |length| of 0 forgoes a hard limit, but does not guarantee proper | 227 // A |length| of 0 forgoes a hard limit, but does not guarantee proper |
227 // functionality of very long strings. Applies to subsequent SetText calls. | 228 // functionality of very long strings. Applies to subsequent SetText calls. |
228 // WARNING: Only use this for system limits, it lacks complex text support. | 229 // WARNING: Only use this for system limits, it lacks complex text support. |
229 void set_truncate_length(size_t length) { truncate_length_ = length; } | 230 void set_truncate_length(size_t length) { truncate_length_ = length; } |
230 | 231 |
232 // Elides the text to fit in |display_rect| according to the specified | |
233 // |elide_behavior|. |ELIDE_IN_MIDDLE| is not supported. | |
234 // If both truncate and elide are specified, the shorter of the two will be | |
msw
2013/12/27 22:54:33
nit: wrap this above
Anuj
2013/12/30 22:46:58
Done.
| |
235 // applicable. | |
236 void SetElideBehavior(ElideBehavior elide_behavior); | |
237 | |
231 const Rect& display_rect() const { return display_rect_; } | 238 const Rect& display_rect() const { return display_rect_; } |
232 void SetDisplayRect(const Rect& r); | 239 void SetDisplayRect(const Rect& r); |
233 | 240 |
234 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } | 241 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } |
235 bool fade_head() const { return fade_head_; } | 242 bool fade_head() const { return fade_head_; } |
236 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } | 243 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } |
237 bool fade_tail() const { return fade_tail_; } | 244 bool fade_tail() const { return fade_tail_; } |
238 | 245 |
239 bool background_is_transparent() const { return background_is_transparent_; } | 246 bool background_is_transparent() const { return background_is_transparent_; } |
240 void set_background_is_transparent(bool transparent) { | 247 void set_background_is_transparent(bool transparent) { |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 size_t caret_pos, | 536 size_t caret_pos, |
530 LogicalCursorDirection caret_affinity); | 537 LogicalCursorDirection caret_affinity); |
531 | 538 |
532 private: | 539 private: |
533 friend class RenderTextTest; | 540 friend class RenderTextTest; |
534 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 541 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
535 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); | 542 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); |
536 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); | 543 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); |
537 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); | 544 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); |
538 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); | 545 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); |
546 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedText); | |
547 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ElidedObscuredText); | |
539 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText); | 548 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText); |
540 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); | 549 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); |
541 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); | 550 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
542 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); | 551 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); |
543 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); | 552 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); |
544 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); | 553 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); |
545 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); | 554 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_MinWidth); |
546 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); | 555 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_NormalWidth); |
547 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); | 556 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_SufficientWidth); |
548 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); | 557 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, Multiline_Newline); |
549 | 558 |
550 // Set the cursor to |position|, with the caret trailing the previous | 559 // Set the cursor to |position|, with the caret trailing the previous |
551 // grapheme, or if there is no previous grapheme, leading the cursor position. | 560 // grapheme, or if there is no previous grapheme, leading the cursor position. |
552 // If |select| is false, the selection start is moved to the same position. | 561 // If |select| is false, the selection start is moved to the same position. |
553 // If the |position| is not a cursorable position (not on grapheme boundary), | 562 // If the |position| is not a cursorable position (not on grapheme boundary), |
554 // it is a NO-OP. | 563 // it is a NO-OP. |
555 void MoveCursorTo(size_t position, bool select); | 564 void MoveCursorTo(size_t position, bool select); |
556 | 565 |
557 // Updates |layout_text_| if the text is obscured or truncated. | 566 // Updates |layout_text_| if the text is obscured or truncated. |
558 void UpdateLayoutText(); | 567 void UpdateLayoutText(); |
559 | 568 |
569 // Elides |text| to fit in the |display_rect_| with given |elide_behavior_|. | |
570 // See ElideText in ui/gfx/text_elider.cc for reference. | |
571 base::string16 ElideText(const base::string16& text); | |
572 | |
560 // Update the cached bounds and display offset to ensure that the current | 573 // Update the cached bounds and display offset to ensure that the current |
561 // cursor is within the visible display area. | 574 // cursor is within the visible display area. |
562 void UpdateCachedBoundsAndOffset(); | 575 void UpdateCachedBoundsAndOffset(); |
563 | 576 |
564 // Draw the selection. | 577 // Draw the selection. |
565 void DrawSelection(Canvas* canvas); | 578 void DrawSelection(Canvas* canvas); |
566 | 579 |
567 // Logical UTF-16 string data to be drawn. | 580 // Logical UTF-16 string data to be drawn. |
568 base::string16 text_; | 581 base::string16 text_; |
569 | 582 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 bool composition_and_selection_styles_applied_; | 635 bool composition_and_selection_styles_applied_; |
623 | 636 |
624 // A flag to obscure actual text with asterisks for password fields. | 637 // A flag to obscure actual text with asterisks for password fields. |
625 bool obscured_; | 638 bool obscured_; |
626 // The index at which the char should be revealed in the obscured text. | 639 // The index at which the char should be revealed in the obscured text. |
627 int obscured_reveal_index_; | 640 int obscured_reveal_index_; |
628 | 641 |
629 // The maximum length of text to display, 0 forgoes a hard limit. | 642 // The maximum length of text to display, 0 forgoes a hard limit. |
630 size_t truncate_length_; | 643 size_t truncate_length_; |
631 | 644 |
645 // The behavior for eliding or truncating. | |
646 ElideBehavior elide_behavior_; | |
647 | |
632 // The obscured and/or truncated text that will be displayed. | 648 // The obscured and/or truncated text that will be displayed. |
633 base::string16 layout_text_; | 649 base::string16 layout_text_; |
634 | 650 |
635 // 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 |
636 // |display_rect_| as the width cap. | 652 // |display_rect_| as the width cap. |
637 bool multiline_; | 653 bool multiline_; |
638 | 654 |
639 // 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_|. |
640 bool fade_head_; | 656 bool fade_head_; |
641 bool fade_tail_; | 657 bool fade_tail_; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
674 // Lines computed by EnsureLayout. These should be invalidated with | 690 // Lines computed by EnsureLayout. These should be invalidated with |
675 // ResetLayout and on |display_rect_| changes. | 691 // ResetLayout and on |display_rect_| changes. |
676 std::vector<internal::Line> lines_; | 692 std::vector<internal::Line> lines_; |
677 | 693 |
678 DISALLOW_COPY_AND_ASSIGN(RenderText); | 694 DISALLOW_COPY_AND_ASSIGN(RenderText); |
679 }; | 695 }; |
680 | 696 |
681 } // namespace gfx | 697 } // namespace gfx |
682 | 698 |
683 #endif // UI_GFX_RENDER_TEXT_H_ | 699 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |