| 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 <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <algorithm> | 11 #include <algorithm> |
| 12 #include <cstring> | 12 #include <cstring> |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "base/gtest_prod_util.h" | 18 #include "base/gtest_prod_util.h" |
| 19 #include "base/i18n/rtl.h" | 19 #include "base/i18n/rtl.h" |
| 20 #include "base/macros.h" | 20 #include "base/macros.h" |
| 21 #include "base/strings/string16.h" | 21 #include "base/strings/string16.h" |
| 22 #include "third_party/skia/include/core/SkColor.h" | 22 #include "third_party/skia/include/core/SkColor.h" |
| 23 #include "third_party/skia/include/core/SkPaint.h" | 23 #include "third_party/skia/include/core/SkPaint.h" |
| 24 #include "third_party/skia/include/core/SkRefCnt.h" | 24 #include "third_party/skia/include/core/SkRefCnt.h" |
| 25 #include "ui/gfx/break_list.h" | 25 #include "ui/gfx/break_list.h" |
| 26 #include "ui/gfx/decorated_text.h" |
| 26 #include "ui/gfx/font_list.h" | 27 #include "ui/gfx/font_list.h" |
| 27 #include "ui/gfx/font_render_params.h" | 28 #include "ui/gfx/font_render_params.h" |
| 28 #include "ui/gfx/geometry/point.h" | 29 #include "ui/gfx/geometry/point.h" |
| 29 #include "ui/gfx/geometry/rect.h" | 30 #include "ui/gfx/geometry/rect.h" |
| 30 #include "ui/gfx/geometry/size_f.h" | 31 #include "ui/gfx/geometry/size_f.h" |
| 31 #include "ui/gfx/geometry/vector2d.h" | 32 #include "ui/gfx/geometry/vector2d.h" |
| 32 #include "ui/gfx/range/range.h" | 33 #include "ui/gfx/range/range.h" |
| 33 #include "ui/gfx/range/range_f.h" | 34 #include "ui/gfx/range/range_f.h" |
| 34 #include "ui/gfx/selection_model.h" | 35 #include "ui/gfx/selection_model.h" |
| 35 #include "ui/gfx/shadow_value.h" | 36 #include "ui/gfx/shadow_value.h" |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 // Rect can't have a negative width.) | 491 // Rect can't have a negative width.) |
| 491 virtual Range GetGlyphBounds(size_t index) = 0; | 492 virtual Range GetGlyphBounds(size_t index) = 0; |
| 492 | 493 |
| 493 const Vector2d& GetUpdatedDisplayOffset(); | 494 const Vector2d& GetUpdatedDisplayOffset(); |
| 494 void SetDisplayOffset(int horizontal_offset); | 495 void SetDisplayOffset(int horizontal_offset); |
| 495 | 496 |
| 496 // Returns the line offset from the origin after applying the text alignment | 497 // Returns the line offset from the origin after applying the text alignment |
| 497 // and the display offset. | 498 // and the display offset. |
| 498 Vector2d GetLineOffset(size_t line_number); | 499 Vector2d GetLineOffset(size_t line_number); |
| 499 | 500 |
| 501 // Retreives the word displayed at the given |point| along with its styling |
| 502 // information. |point| is in the view's coordinates. If no word is displayed |
| 503 // at the point, returns a nearby word. |baseline_point| should correspond to |
| 504 // the left baseline point of the leftmost glyph of the |word| in the view's |
| 505 // coordinates. Returns false, if no word can be retreived. |
| 506 bool GetDecoratedWordAtPoint(const Point& point, |
| 507 DecoratedText* decorated_word, |
| 508 Point* baseline_point); |
| 509 |
| 510 // Retreives the text in the given |range|. |
| 511 base::string16 GetTextFromRange(const Range& range) const; |
| 512 |
| 500 protected: | 513 protected: |
| 501 RenderText(); | 514 RenderText(); |
| 502 | 515 |
| 503 // NOTE: The value of these accessors may be stale. Please make sure | 516 // NOTE: The value of these accessors may be stale. Please make sure |
| 504 // that these fields are up to date before accessing them. | 517 // that these fields are up to date before accessing them. |
| 505 const base::string16& layout_text() const { return layout_text_; } | 518 const base::string16& layout_text() const { return layout_text_; } |
| 506 const base::string16& display_text() const { return display_text_; } | 519 const base::string16& display_text() const { return display_text_; } |
| 507 bool text_elided() const { return text_elided_; } | 520 bool text_elided() const { return text_elided_; } |
| 508 | 521 |
| 509 const BreakList<SkColor>& colors() const { return colors_; } | 522 const BreakList<SkColor>& colors() const { return colors_; } |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 // Elides |email| as needed to fit the |available_width|. | 719 // Elides |email| as needed to fit the |available_width|. |
| 707 base::string16 ElideEmail(const base::string16& email, float available_width); | 720 base::string16 ElideEmail(const base::string16& email, float available_width); |
| 708 | 721 |
| 709 // Update the cached bounds and display offset to ensure that the current | 722 // Update the cached bounds and display offset to ensure that the current |
| 710 // cursor is within the visible display area. | 723 // cursor is within the visible display area. |
| 711 void UpdateCachedBoundsAndOffset(); | 724 void UpdateCachedBoundsAndOffset(); |
| 712 | 725 |
| 713 // Draw the selection. | 726 // Draw the selection. |
| 714 void DrawSelection(Canvas* canvas); | 727 void DrawSelection(Canvas* canvas); |
| 715 | 728 |
| 729 // Returns the nearest word start boundary for |index|. First searches in the |
| 730 // CURSOR_BACKWARD direction, then in the CURSOR_FORWARD direction. Returns |
| 731 // the text length if no valid boundary is found. |
| 732 size_t GetNearestWordStartBoundary(size_t index) const; |
| 733 |
| 734 // Expands |range| to its nearest word boundaries and returns the resulting |
| 735 // range. Maintains directionality of |range|. |
| 736 Range ExpandRangeToWordBoundary(const Range& range) const; |
| 737 |
| 738 // Returns the decorated text corresponding to |range|. Returns false if the |
| 739 // text cannot be retreived, e.g. if the text is obscured. |
| 740 virtual bool GetDecoratedTextForRange( |
| 741 const Range& range, |
| 742 DecoratedText* decorated_text) const = 0; |
| 743 |
| 716 // Logical UTF-16 string data to be drawn. | 744 // Logical UTF-16 string data to be drawn. |
| 717 base::string16 text_; | 745 base::string16 text_; |
| 718 | 746 |
| 719 // Horizontal alignment of the text with respect to |display_rect_|. The | 747 // Horizontal alignment of the text with respect to |display_rect_|. The |
| 720 // default is to align left if the application UI is LTR and right if RTL. | 748 // default is to align left if the application UI is LTR and right if RTL. |
| 721 HorizontalAlignment horizontal_alignment_; | 749 HorizontalAlignment horizontal_alignment_; |
| 722 | 750 |
| 723 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. | 751 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. |
| 724 DirectionalityMode directionality_mode_; | 752 DirectionalityMode directionality_mode_; |
| 725 | 753 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 850 // Lines computed by EnsureLayout. These should be invalidated upon | 878 // Lines computed by EnsureLayout. These should be invalidated upon |
| 851 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 879 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
| 852 std::vector<internal::Line> lines_; | 880 std::vector<internal::Line> lines_; |
| 853 | 881 |
| 854 DISALLOW_COPY_AND_ASSIGN(RenderText); | 882 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 855 }; | 883 }; |
| 856 | 884 |
| 857 } // namespace gfx | 885 } // namespace gfx |
| 858 | 886 |
| 859 #endif // UI_GFX_RENDER_TEXT_H_ | 887 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |