| 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/i18n/rtl.h" | 18 #include "base/i18n/rtl.h" |
| 19 #include "base/macros.h" | 19 #include "base/macros.h" |
| 20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 21 #include "third_party/skia/include/core/SkColor.h" | 21 #include "third_party/skia/include/core/SkColor.h" |
| 22 #include "third_party/skia/include/core/SkPaint.h" | 22 #include "third_party/skia/include/core/SkPaint.h" |
| 23 #include "third_party/skia/include/core/SkRefCnt.h" | 23 #include "third_party/skia/include/core/SkRefCnt.h" |
| 24 #include "ui/gfx/break_list.h" | 24 #include "ui/gfx/break_list.h" |
| 25 #include "ui/gfx/decorated_text.h" |
| 25 #include "ui/gfx/font_list.h" | 26 #include "ui/gfx/font_list.h" |
| 26 #include "ui/gfx/font_render_params.h" | 27 #include "ui/gfx/font_render_params.h" |
| 27 #include "ui/gfx/geometry/point.h" | 28 #include "ui/gfx/geometry/point.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
| 29 #include "ui/gfx/geometry/size_f.h" | 30 #include "ui/gfx/geometry/size_f.h" |
| 30 #include "ui/gfx/geometry/vector2d.h" | 31 #include "ui/gfx/geometry/vector2d.h" |
| 31 #include "ui/gfx/range/range.h" | 32 #include "ui/gfx/range/range.h" |
| 32 #include "ui/gfx/range/range_f.h" | 33 #include "ui/gfx/range/range_f.h" |
| 33 #include "ui/gfx/selection_model.h" | 34 #include "ui/gfx/selection_model.h" |
| 34 #include "ui/gfx/shadow_value.h" | 35 #include "ui/gfx/shadow_value.h" |
| (...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 489 // Rect can't have a negative width.) | 490 // Rect can't have a negative width.) |
| 490 virtual Range GetGlyphBounds(size_t index) = 0; | 491 virtual Range GetGlyphBounds(size_t index) = 0; |
| 491 | 492 |
| 492 const Vector2d& GetUpdatedDisplayOffset(); | 493 const Vector2d& GetUpdatedDisplayOffset(); |
| 493 void SetDisplayOffset(int horizontal_offset); | 494 void SetDisplayOffset(int horizontal_offset); |
| 494 | 495 |
| 495 // Returns the line offset from the origin after applying the text alignment | 496 // Returns the line offset from the origin after applying the text alignment |
| 496 // and the display offset. | 497 // and the display offset. |
| 497 Vector2d GetLineOffset(size_t line_number); | 498 Vector2d GetLineOffset(size_t line_number); |
| 498 | 499 |
| 500 // Retreives the word displayed at the given |point| along with its styling |
| 501 // information. |point| is in the view's coordinates. If no word is displayed |
| 502 // at the point, returns a nearby word. |baseline_point| should correspond to |
| 503 // the left baseline point of the leftmost glyph of the |word| in the view's |
| 504 // coordinates. Returns false, if no word can be retreived. |
| 505 bool GetDecoratedWordAtPoint(const Point& point, |
| 506 DecoratedText* decorated_word, |
| 507 Point* baseline_point); |
| 508 |
| 509 // Retreives the text in the given |range|. |
| 510 base::string16 GetTextFromRange(const Range& range) const; |
| 511 |
| 499 protected: | 512 protected: |
| 500 RenderText(); | 513 RenderText(); |
| 501 | 514 |
| 502 // NOTE: The value of these accessors may be stale. Please make sure | 515 // NOTE: The value of these accessors may be stale. Please make sure |
| 503 // that these fields are up to date before accessing them. | 516 // that these fields are up to date before accessing them. |
| 504 const base::string16& layout_text() const { return layout_text_; } | 517 const base::string16& layout_text() const { return layout_text_; } |
| 505 const base::string16& display_text() const { return display_text_; } | 518 const base::string16& display_text() const { return display_text_; } |
| 506 bool text_elided() const { return text_elided_; } | 519 bool text_elided() const { return text_elided_; } |
| 507 | 520 |
| 508 const BreakList<SkColor>& colors() const { return colors_; } | 521 const BreakList<SkColor>& colors() const { return colors_; } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 671 // Elides |email| as needed to fit the |available_width|. | 684 // Elides |email| as needed to fit the |available_width|. |
| 672 base::string16 ElideEmail(const base::string16& email, float available_width); | 685 base::string16 ElideEmail(const base::string16& email, float available_width); |
| 673 | 686 |
| 674 // Update the cached bounds and display offset to ensure that the current | 687 // Update the cached bounds and display offset to ensure that the current |
| 675 // cursor is within the visible display area. | 688 // cursor is within the visible display area. |
| 676 void UpdateCachedBoundsAndOffset(); | 689 void UpdateCachedBoundsAndOffset(); |
| 677 | 690 |
| 678 // Draw the selection. | 691 // Draw the selection. |
| 679 void DrawSelection(Canvas* canvas); | 692 void DrawSelection(Canvas* canvas); |
| 680 | 693 |
| 694 // Returns the nearest word start boundary for |index|. First searches in the |
| 695 // CURSOR_BACKWARD direction, then in the CURSOR_FORWARD direction. Returns |
| 696 // the text length if no valid boundary is found. |
| 697 size_t GetNearestWordStartBoundary(size_t index) const; |
| 698 |
| 699 // Expands |range| to its nearest word boundaries and returns the resulting |
| 700 // range. Maintains directionality of |range|. |
| 701 Range ExpandRangeToWordBoundary(const Range& range) const; |
| 702 |
| 703 // Returns the decorated text corresponding to |range|. Returns false if the |
| 704 // text cannot be retreived, e.g. if the text is obscured. |
| 705 virtual bool GetDecoratedTextForRange( |
| 706 const Range& range, |
| 707 DecoratedText* decorated_text) const = 0; |
| 708 |
| 681 // Logical UTF-16 string data to be drawn. | 709 // Logical UTF-16 string data to be drawn. |
| 682 base::string16 text_; | 710 base::string16 text_; |
| 683 | 711 |
| 684 // Horizontal alignment of the text with respect to |display_rect_|. The | 712 // Horizontal alignment of the text with respect to |display_rect_|. The |
| 685 // default is to align left if the application UI is LTR and right if RTL. | 713 // default is to align left if the application UI is LTR and right if RTL. |
| 686 HorizontalAlignment horizontal_alignment_; | 714 HorizontalAlignment horizontal_alignment_; |
| 687 | 715 |
| 688 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. | 716 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. |
| 689 DirectionalityMode directionality_mode_; | 717 DirectionalityMode directionality_mode_; |
| 690 | 718 |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 // Lines computed by EnsureLayout. These should be invalidated upon | 843 // Lines computed by EnsureLayout. These should be invalidated upon |
| 816 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. | 844 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
| 817 std::vector<internal::Line> lines_; | 845 std::vector<internal::Line> lines_; |
| 818 | 846 |
| 819 DISALLOW_COPY_AND_ASSIGN(RenderText); | 847 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 820 }; | 848 }; |
| 821 | 849 |
| 822 } // namespace gfx | 850 } // namespace gfx |
| 823 | 851 |
| 824 #endif // UI_GFX_RENDER_TEXT_H_ | 852 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |