| 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> |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 bool obscured() const { return obscured_; } | 186 bool obscured() const { return obscured_; } |
| 187 void SetObscured(bool obscured); | 187 void SetObscured(bool obscured); |
| 188 | 188 |
| 189 // Makes a char in obscured text at |index| to be revealed. |index| should be | 189 // Makes a char in obscured text at |index| to be revealed. |index| should be |
| 190 // a UTF16 text index. If there is a previous revealed index, the previous one | 190 // a UTF16 text index. If there is a previous revealed index, the previous one |
| 191 // is cleared and only the last set index will be revealed. If |index| is -1 | 191 // is cleared and only the last set index will be revealed. If |index| is -1 |
| 192 // or out of range, no char will be revealed. The revealed index is also | 192 // or out of range, no char will be revealed. The revealed index is also |
| 193 // cleared when SetText or SetObscured is called. | 193 // cleared when SetText or SetObscured is called. |
| 194 void SetObscuredRevealIndex(int index); | 194 void SetObscuredRevealIndex(int index); |
| 195 | 195 |
| 196 // Set the maximum length of the displayed layout text, not the actual text. |
| 197 // A |length| of 0 forgoes a hard limit, but does not guarantee proper |
| 198 // functionality of very long strings. Applies to subsequent SetText calls. |
| 199 // WARNING: Only use this for system limits, it lacks complex text support. |
| 200 void set_truncate_length(size_t length) { truncate_length_ = length; } |
| 201 |
| 196 const Rect& display_rect() const { return display_rect_; } | 202 const Rect& display_rect() const { return display_rect_; } |
| 197 void SetDisplayRect(const Rect& r); | 203 void SetDisplayRect(const Rect& r); |
| 198 | 204 |
| 199 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } | 205 void set_fade_head(bool fade_head) { fade_head_ = fade_head; } |
| 200 bool fade_head() const { return fade_head_; } | 206 bool fade_head() const { return fade_head_; } |
| 201 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } | 207 void set_fade_tail(bool fade_tail) { fade_tail_ = fade_tail; } |
| 202 bool fade_tail() const { return fade_tail_; } | 208 bool fade_tail() const { return fade_tail_; } |
| 203 | 209 |
| 204 bool background_is_transparent() const { return background_is_transparent_; } | 210 bool background_is_transparent() const { return background_is_transparent_; } |
| 205 void set_background_is_transparent(bool transparent) { | 211 void set_background_is_transparent(bool transparent) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 | 411 |
| 406 // Reset the layout to be invalid. | 412 // Reset the layout to be invalid. |
| 407 virtual void ResetLayout() = 0; | 413 virtual void ResetLayout() = 0; |
| 408 | 414 |
| 409 // Ensure the text is laid out. | 415 // Ensure the text is laid out. |
| 410 virtual void EnsureLayout() = 0; | 416 virtual void EnsureLayout() = 0; |
| 411 | 417 |
| 412 // Draw the text. | 418 // Draw the text. |
| 413 virtual void DrawVisualText(Canvas* canvas) = 0; | 419 virtual void DrawVisualText(Canvas* canvas) = 0; |
| 414 | 420 |
| 415 // Returns the text used for layout, which may be |obscured_text_|. | 421 // Returns the text used for layout, which may be obscured or truncated. |
| 416 const base::string16& GetLayoutText() const; | 422 const base::string16& GetLayoutText() const; |
| 417 | 423 |
| 418 // Apply (and undo) temporary composition underlines and selection colors. | 424 // Apply (and undo) temporary composition underlines and selection colors. |
| 419 void ApplyCompositionAndSelectionStyles(); | 425 void ApplyCompositionAndSelectionStyles(); |
| 420 void UndoCompositionAndSelectionStyles(); | 426 void UndoCompositionAndSelectionStyles(); |
| 421 | 427 |
| 422 // Returns the text offset from the origin after applying text alignment and | 428 // Returns the text offset from the origin after applying text alignment and |
| 423 // display offset. | 429 // display offset. |
| 424 Vector2d GetTextOffset(); | 430 Vector2d GetTextOffset(); |
| 425 | 431 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 444 size_t caret_pos, | 450 size_t caret_pos, |
| 445 LogicalCursorDirection caret_affinity); | 451 LogicalCursorDirection caret_affinity); |
| 446 | 452 |
| 447 private: | 453 private: |
| 448 friend class RenderTextTest; | 454 friend class RenderTextTest; |
| 449 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 455 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
| 450 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); | 456 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); |
| 451 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); | 457 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); |
| 452 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); | 458 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); |
| 453 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); | 459 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, RevealObscuredText); |
| 460 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedText); |
| 461 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, TruncatedObscuredText); |
| 454 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); | 462 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
| 455 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); | 463 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); |
| 456 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); | 464 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffset); |
| 457 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); | 465 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GetTextOffsetHorizontalDefaultInRTL); |
| 458 | 466 |
| 459 // Set the cursor to |position|, with the caret trailing the previous | 467 // Set the cursor to |position|, with the caret trailing the previous |
| 460 // grapheme, or if there is no previous grapheme, leading the cursor position. | 468 // grapheme, or if there is no previous grapheme, leading the cursor position. |
| 461 // If |select| is false, the selection start is moved to the same position. | 469 // If |select| is false, the selection start is moved to the same position. |
| 462 // If the |position| is not a cursorable position (not on grapheme boundary), | 470 // If the |position| is not a cursorable position (not on grapheme boundary), |
| 463 // it is a NO-OP. | 471 // it is a NO-OP. |
| 464 void MoveCursorTo(size_t position, bool select); | 472 void MoveCursorTo(size_t position, bool select); |
| 465 | 473 |
| 466 // Updates |obscured_text_| if the text is obscured. | 474 // Updates |layout_text_| if the text is obscured or truncated. |
| 467 void UpdateObscuredText(); | 475 void UpdateLayoutText(); |
| 468 | 476 |
| 469 // Update the cached bounds and display offset to ensure that the current | 477 // Update the cached bounds and display offset to ensure that the current |
| 470 // cursor is within the visible display area. | 478 // cursor is within the visible display area. |
| 471 void UpdateCachedBoundsAndOffset(); | 479 void UpdateCachedBoundsAndOffset(); |
| 472 | 480 |
| 473 // Draw the selection. | 481 // Draw the selection. |
| 474 void DrawSelection(Canvas* canvas); | 482 void DrawSelection(Canvas* canvas); |
| 475 | 483 |
| 476 // Logical UTF-16 string data to be drawn. | 484 // Logical UTF-16 string data to be drawn. |
| 477 base::string16 text_; | 485 base::string16 text_; |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 // BreakList positions are stored with text indices, not layout indices. | 538 // BreakList positions are stored with text indices, not layout indices. |
| 531 // TODO(msw): Expand to support cursor, selection, background, etc. colors. | 539 // TODO(msw): Expand to support cursor, selection, background, etc. colors. |
| 532 BreakList<SkColor> colors_; | 540 BreakList<SkColor> colors_; |
| 533 std::vector<BreakList<bool> > styles_; | 541 std::vector<BreakList<bool> > styles_; |
| 534 | 542 |
| 535 // Breaks saved without temporary composition and selection styling. | 543 // Breaks saved without temporary composition and selection styling. |
| 536 BreakList<SkColor> saved_colors_; | 544 BreakList<SkColor> saved_colors_; |
| 537 BreakList<bool> saved_underlines_; | 545 BreakList<bool> saved_underlines_; |
| 538 bool composition_and_selection_styles_applied_; | 546 bool composition_and_selection_styles_applied_; |
| 539 | 547 |
| 540 // A flag and the text to display for obscured (password) fields. | 548 // A flag to obscure actual text with asterisks for password fields. |
| 541 // Asterisks are used instead of the actual text glyphs when true. | |
| 542 bool obscured_; | 549 bool obscured_; |
| 543 base::string16 obscured_text_; | |
| 544 | |
| 545 // The index at which the char should be revealed in the obscured text. | 550 // The index at which the char should be revealed in the obscured text. |
| 546 int obscured_reveal_index_; | 551 int obscured_reveal_index_; |
| 547 | 552 |
| 553 // The maximum length of text to display, 0 forgoes a hard limit. |
| 554 size_t truncate_length_; |
| 555 |
| 556 // The obscured and/or truncated text that will be displayed. |
| 557 base::string16 layout_text_; |
| 558 |
| 548 // Fade text head and/or tail, if text doesn't fit into |display_rect_|. | 559 // Fade text head and/or tail, if text doesn't fit into |display_rect_|. |
| 549 bool fade_head_; | 560 bool fade_head_; |
| 550 bool fade_tail_; | 561 bool fade_tail_; |
| 551 | 562 |
| 552 // Is the background transparent (either partially or fully)? | 563 // Is the background transparent (either partially or fully)? |
| 553 bool background_is_transparent_; | 564 bool background_is_transparent_; |
| 554 | 565 |
| 555 // The local display area for rendering the text. | 566 // The local display area for rendering the text. |
| 556 Rect display_rect_; | 567 Rect display_rect_; |
| 557 | 568 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 571 | 582 |
| 572 // Text shadows to be drawn. | 583 // Text shadows to be drawn. |
| 573 ShadowValues text_shadows_; | 584 ShadowValues text_shadows_; |
| 574 | 585 |
| 575 DISALLOW_COPY_AND_ASSIGN(RenderText); | 586 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 576 }; | 587 }; |
| 577 | 588 |
| 578 } // namespace gfx | 589 } // namespace gfx |
| 579 | 590 |
| 580 #endif // UI_GFX_RENDER_TEXT_H_ | 591 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |