| 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 10 matching lines...) Expand all Loading... |
| 21 #include "third_party/skia/include/core/SkRect.h" | 21 #include "third_party/skia/include/core/SkRect.h" |
| 22 #include "ui/gfx/break_list.h" | 22 #include "ui/gfx/break_list.h" |
| 23 #include "ui/gfx/font_list.h" | 23 #include "ui/gfx/font_list.h" |
| 24 #include "ui/gfx/point.h" | 24 #include "ui/gfx/point.h" |
| 25 #include "ui/gfx/range/range.h" | 25 #include "ui/gfx/range/range.h" |
| 26 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
| 27 #include "ui/gfx/selection_model.h" | 27 #include "ui/gfx/selection_model.h" |
| 28 #include "ui/gfx/shadow_value.h" | 28 #include "ui/gfx/shadow_value.h" |
| 29 #include "ui/gfx/size_f.h" | 29 #include "ui/gfx/size_f.h" |
| 30 #include "ui/gfx/text_constants.h" | 30 #include "ui/gfx/text_constants.h" |
| 31 #include "ui/gfx/text_elider.h" | |
| 32 #include "ui/gfx/vector2d.h" | 31 #include "ui/gfx/vector2d.h" |
| 33 | 32 |
| 34 class SkCanvas; | 33 class SkCanvas; |
| 35 class SkDrawLooper; | 34 class SkDrawLooper; |
| 36 struct SkPoint; | 35 struct SkPoint; |
| 37 class SkShader; | 36 class SkShader; |
| 38 class SkTypeface; | 37 class SkTypeface; |
| 39 | 38 |
| 40 namespace gfx { | 39 namespace gfx { |
| 41 | 40 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 // Windows. Support other platforms. | 246 // Windows. Support other platforms. |
| 248 bool multiline() const { return multiline_; } | 247 bool multiline() const { return multiline_; } |
| 249 void SetMultiline(bool multiline); | 248 void SetMultiline(bool multiline); |
| 250 | 249 |
| 251 // Set the maximum length of the displayed layout text, not the actual text. | 250 // Set the maximum length of the displayed layout text, not the actual text. |
| 252 // A |length| of 0 forgoes a hard limit, but does not guarantee proper | 251 // A |length| of 0 forgoes a hard limit, but does not guarantee proper |
| 253 // functionality of very long strings. Applies to subsequent SetText calls. | 252 // functionality of very long strings. Applies to subsequent SetText calls. |
| 254 // WARNING: Only use this for system limits, it lacks complex text support. | 253 // WARNING: Only use this for system limits, it lacks complex text support. |
| 255 void set_truncate_length(size_t length) { truncate_length_ = length; } | 254 void set_truncate_length(size_t length) { truncate_length_ = length; } |
| 256 | 255 |
| 257 // Elides the text to fit in |display_rect| according to the specified | 256 // The layout text will be elided to fit |display_rect| using this behavior. |
| 258 // |elide_behavior|. |ELIDE_MIDDLE| is not supported. If a truncate length and | 257 // The layout text may be shortened further by the truncate length. |
| 259 // an elide mode are specified, the shorter of the two will be applicable. | |
| 260 void SetElideBehavior(ElideBehavior elide_behavior); | 258 void SetElideBehavior(ElideBehavior elide_behavior); |
| 261 | 259 |
| 260 const base::string16& layout_text() const { return layout_text_; } |
| 261 |
| 262 const Rect& display_rect() const { return display_rect_; } | 262 const Rect& display_rect() const { return display_rect_; } |
| 263 void SetDisplayRect(const Rect& r); | 263 void SetDisplayRect(const Rect& r); |
| 264 | 264 |
| 265 bool background_is_transparent() const { return background_is_transparent_; } | 265 bool background_is_transparent() const { return background_is_transparent_; } |
| 266 void set_background_is_transparent(bool transparent) { | 266 void set_background_is_transparent(bool transparent) { |
| 267 background_is_transparent_ = transparent; | 267 background_is_transparent_ = transparent; |
| 268 } | 268 } |
| 269 | 269 |
| 270 const SelectionModel& selection_model() const { return selection_model_; } | 270 const SelectionModel& selection_model() const { return selection_model_; } |
| 271 | 271 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 348 |
| 349 // This is same as GetStringSize except that fractional size is returned. | 349 // This is same as GetStringSize except that fractional size is returned. |
| 350 // The default implementation is same as GetStringSize. Certain platforms that | 350 // The default implementation is same as GetStringSize. Certain platforms that |
| 351 // compute the text size as floating-point values, like Mac, will override | 351 // compute the text size as floating-point values, like Mac, will override |
| 352 // this method. | 352 // this method. |
| 353 // See comment in Canvas::GetStringWidthF for its usage. | 353 // See comment in Canvas::GetStringWidthF for its usage. |
| 354 virtual SizeF GetStringSizeF(); | 354 virtual SizeF GetStringSizeF(); |
| 355 | 355 |
| 356 // Returns the width of the content (which is the wrapped width in multiline | 356 // Returns the width of the content (which is the wrapped width in multiline |
| 357 // mode). Reserves room for the cursor if |cursor_enabled_| is true. | 357 // mode). Reserves room for the cursor if |cursor_enabled_| is true. |
| 358 int GetContentWidth(); | 358 float GetContentWidth(); |
| 359 | 359 |
| 360 // Returns the common baseline of the text. The return value is the vertical | 360 // Returns the common baseline of the text. The return value is the vertical |
| 361 // offset from the top of |display_rect_| to the text baseline, in pixels. | 361 // offset from the top of |display_rect_| to the text baseline, in pixels. |
| 362 // The baseline is determined from the font list and display rect, and does | 362 // The baseline is determined from the font list and display rect, and does |
| 363 // not depend on the text. | 363 // not depend on the text. |
| 364 int GetBaseline(); | 364 int GetBaseline(); |
| 365 | 365 |
| 366 void Draw(Canvas* canvas); | 366 void Draw(Canvas* canvas); |
| 367 | 367 |
| 368 // Draws a cursor at |position|. | 368 // Draws a cursor at |position|. |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 // Set the cursor to |position|, with the caret trailing the previous | 573 // Set the cursor to |position|, with the caret trailing the previous |
| 574 // grapheme, or if there is no previous grapheme, leading the cursor position. | 574 // grapheme, or if there is no previous grapheme, leading the cursor position. |
| 575 // If |select| is false, the selection start is moved to the same position. | 575 // If |select| is false, the selection start is moved to the same position. |
| 576 // If the |position| is not a cursorable position (not on grapheme boundary), | 576 // If the |position| is not a cursorable position (not on grapheme boundary), |
| 577 // it is a NO-OP. | 577 // it is a NO-OP. |
| 578 void MoveCursorTo(size_t position, bool select); | 578 void MoveCursorTo(size_t position, bool select); |
| 579 | 579 |
| 580 // Updates |layout_text_| if the text is obscured or truncated. | 580 // Updates |layout_text_| if the text is obscured or truncated. |
| 581 void UpdateLayoutText(); | 581 void UpdateLayoutText(); |
| 582 | 582 |
| 583 // Elides |text| to fit in the |display_rect_| with given |elide_behavior_|. | 583 // Elides |text| as needed to fit in the |available_width| using |behavior|. |
| 584 // See ElideText in ui/gfx/text_elider.cc for reference. | 584 base::string16 Elide(const base::string16& text, |
| 585 base::string16 ElideText(const base::string16& text); | 585 float available_width, |
| 586 ElideBehavior behavior); |
| 587 |
| 588 // Elides |email| as needed to fit the |available_width|. |
| 589 base::string16 ElideEmail(const base::string16& email, float available_width); |
| 586 | 590 |
| 587 // Update the cached bounds and display offset to ensure that the current | 591 // Update the cached bounds and display offset to ensure that the current |
| 588 // cursor is within the visible display area. | 592 // cursor is within the visible display area. |
| 589 void UpdateCachedBoundsAndOffset(); | 593 void UpdateCachedBoundsAndOffset(); |
| 590 | 594 |
| 591 // Draw the selection. | 595 // Draw the selection. |
| 592 void DrawSelection(Canvas* canvas); | 596 void DrawSelection(Canvas* canvas); |
| 593 | 597 |
| 594 // Logical UTF-16 string data to be drawn. | 598 // Logical UTF-16 string data to be drawn. |
| 595 base::string16 text_; | 599 base::string16 text_; |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 // Lines computed by EnsureLayout. These should be invalidated with | 704 // Lines computed by EnsureLayout. These should be invalidated with |
| 701 // ResetLayout and on |display_rect_| changes. | 705 // ResetLayout and on |display_rect_| changes. |
| 702 std::vector<internal::Line> lines_; | 706 std::vector<internal::Line> lines_; |
| 703 | 707 |
| 704 DISALLOW_COPY_AND_ASSIGN(RenderText); | 708 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 705 }; | 709 }; |
| 706 | 710 |
| 707 } // namespace gfx | 711 } // namespace gfx |
| 708 | 712 |
| 709 #endif // UI_GFX_RENDER_TEXT_H_ | 713 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |