Chromium Code Reviews| 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 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 private: | 129 private: |
| 130 BreakList<SkColor> colors_; | 130 BreakList<SkColor> colors_; |
| 131 std::vector<BreakList<bool> > styles_; | 131 std::vector<BreakList<bool> > styles_; |
| 132 | 132 |
| 133 BreakList<SkColor>::const_iterator color_; | 133 BreakList<SkColor>::const_iterator color_; |
| 134 std::vector<BreakList<bool>::const_iterator> style_; | 134 std::vector<BreakList<bool>::const_iterator> style_; |
| 135 | 135 |
| 136 DISALLOW_COPY_AND_ASSIGN(StyleIterator); | 136 DISALLOW_COPY_AND_ASSIGN(StyleIterator); |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 // Line segments are slices of the layout text to be rendered on a single line. | 139 // Line segments are slices of the display text to be rendered on a single line. |
| 140 struct LineSegment { | 140 struct LineSegment { |
| 141 LineSegment(); | 141 LineSegment(); |
| 142 ~LineSegment(); | 142 ~LineSegment(); |
| 143 | 143 |
| 144 // X coordinates of this line segment in text space. | 144 // X coordinates of this line segment in text space. |
| 145 Range x_range; | 145 Range x_range; |
| 146 | 146 |
| 147 // The character range this segment corresponds to. | 147 // The character range this segment corresponds to. |
| 148 Range char_range; | 148 Range char_range; |
| 149 | 149 |
| 150 // The width of this line segment in text space. This could be slightly | 150 // The width of this line segment in text space. This could be slightly |
| 151 // different from x_range.length(). | 151 // different from x_range.length(). |
| 152 // TODO(mukai): Fix Range to support float values and merge it into x_range. | 152 // TODO(mukai): Fix Range to support float values and merge it into x_range. |
| 153 float width; | 153 float width; |
| 154 | 154 |
| 155 // Index of the text run that generated this segment. | 155 // Index of the text run that generated this segment. |
| 156 size_t run; | 156 size_t run; |
| 157 }; | 157 }; |
| 158 | 158 |
| 159 // A line of layout text, comprised of a line segment list and some metrics. | 159 // A line of display text, comprised of a line segment list and some metrics. |
| 160 struct Line { | 160 struct Line { |
| 161 Line(); | 161 Line(); |
| 162 ~Line(); | 162 ~Line(); |
| 163 | 163 |
| 164 // Segments that make up this line in visual order. | 164 // Segments that make up this line in visual order. |
| 165 std::vector<LineSegment> segments; | 165 std::vector<LineSegment> segments; |
| 166 | 166 |
| 167 // The sum of segment widths and the maximum of segment heights. | 167 // The sum of segment widths and the maximum of segment heights. |
| 168 SizeF size; | 168 SizeF size; |
| 169 | 169 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 bool obscured() const { return obscured_; } | 244 bool obscured() const { return obscured_; } |
| 245 void SetObscured(bool obscured); | 245 void SetObscured(bool obscured); |
| 246 | 246 |
| 247 // Makes a char in obscured text at |index| to be revealed. |index| should be | 247 // Makes a char in obscured text at |index| to be revealed. |index| should be |
| 248 // a UTF16 text index. If there is a previous revealed index, the previous one | 248 // a UTF16 text index. If there is a previous revealed index, the previous one |
| 249 // is cleared and only the last set index will be revealed. If |index| is -1 | 249 // is cleared and only the last set index will be revealed. If |index| is -1 |
| 250 // or out of range, no char will be revealed. The revealed index is also | 250 // or out of range, no char will be revealed. The revealed index is also |
| 251 // cleared when SetText or SetObscured is called. | 251 // cleared when SetText or SetObscured is called. |
| 252 void SetObscuredRevealIndex(int index); | 252 void SetObscuredRevealIndex(int index); |
| 253 | 253 |
| 254 // Set whether newline characters should be replaced with newline symbols. | |
| 255 void SetReplaceNewlineCharsWithSymbols(bool replace); | |
| 256 | |
| 257 // TODO(ckocagil): Multiline text rendering is currently only supported on | 254 // TODO(ckocagil): Multiline text rendering is currently only supported on |
| 258 // Windows. Support other platforms. | 255 // Windows. Support other platforms. |
| 259 bool multiline() const { return multiline_; } | 256 bool multiline() const { return multiline_; } |
| 260 void SetMultiline(bool multiline); | 257 void SetMultiline(bool multiline); |
| 261 | 258 |
| 262 // TODO(ckocagil): Add vertical alignment and line spacing support instead. | 259 // TODO(ckocagil): Add vertical alignment and line spacing support instead. |
| 263 int min_line_height() const { return min_line_height_; } | 260 int min_line_height() const { return min_line_height_; } |
| 264 void SetMinLineHeight(int line_height); | 261 void SetMinLineHeight(int line_height); |
| 265 | 262 |
| 266 // Set the maximum length of the displayed layout text, not the actual text. | 263 // Set the maximum length of the layout text, not the actual text. |
| 267 // A |length| of 0 forgoes a hard limit, but does not guarantee proper | 264 // A |length| of 0 forgoes a hard limit, but does not guarantee proper |
| 268 // functionality of very long strings. Applies to subsequent SetText calls. | 265 // functionality of very long strings. Applies to subsequent SetText calls. |
| 269 // WARNING: Only use this for system limits, it lacks complex text support. | 266 // WARNING: Only use this for system limits, it lacks complex text support. |
| 270 void set_truncate_length(size_t length) { truncate_length_ = length; } | 267 void set_truncate_length(size_t length) { truncate_length_ = length; } |
| 271 | 268 |
| 272 // The layout text will be elided to fit |display_rect| using this behavior. | 269 // The layout text will be elided to fit |display_rect| using this behavior. |
| 273 // The layout text may be shortened further by the truncate length. | |
| 274 void SetElideBehavior(ElideBehavior elide_behavior); | 270 void SetElideBehavior(ElideBehavior elide_behavior); |
| 275 ElideBehavior elide_behavior() const { return elide_behavior_; } | 271 ElideBehavior elide_behavior() const { return elide_behavior_; } |
| 276 | 272 |
| 277 const base::string16& layout_text() const { return layout_text_; } | |
| 278 | |
| 279 const Rect& display_rect() const { return display_rect_; } | 273 const Rect& display_rect() const { return display_rect_; } |
| 280 void SetDisplayRect(const Rect& r); | 274 void SetDisplayRect(const Rect& r); |
| 281 | 275 |
| 282 bool background_is_transparent() const { return background_is_transparent_; } | 276 bool background_is_transparent() const { return background_is_transparent_; } |
| 283 void set_background_is_transparent(bool transparent) { | 277 void set_background_is_transparent(bool transparent) { |
| 284 background_is_transparent_ = transparent; | 278 background_is_transparent_ = transparent; |
| 285 } | 279 } |
| 286 | 280 |
| 287 const SelectionModel& selection_model() const { return selection_model_; } | 281 const SelectionModel& selection_model() const { return selection_model_; } |
| 288 | 282 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 344 | 338 |
| 345 // Returns whether this style is enabled consistently across the entire | 339 // Returns whether this style is enabled consistently across the entire |
| 346 // RenderText. | 340 // RenderText. |
| 347 bool GetStyle(TextStyle style) const; | 341 bool GetStyle(TextStyle style) const; |
| 348 | 342 |
| 349 // Set or get the text directionality mode and get the text direction yielded. | 343 // Set or get the text directionality mode and get the text direction yielded. |
| 350 void SetDirectionalityMode(DirectionalityMode mode); | 344 void SetDirectionalityMode(DirectionalityMode mode); |
| 351 DirectionalityMode directionality_mode() const { | 345 DirectionalityMode directionality_mode() const { |
| 352 return directionality_mode_; | 346 return directionality_mode_; |
| 353 } | 347 } |
| 354 base::i18n::TextDirection GetTextDirection(); | 348 base::i18n::TextDirection GetDisplayTextDirection(); |
| 355 | 349 |
| 356 // Returns the visual movement direction corresponding to the logical end | 350 // Returns the visual movement direction corresponding to the logical end |
| 357 // of the text, considering only the dominant direction returned by | 351 // of the text, considering only the dominant direction returned by |
| 358 // |GetTextDirection()|, not the direction of a particular run. | 352 // |GetDisplayTextDirection()|, not the direction of a particular run. |
| 359 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); | 353 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); |
| 360 | 354 |
| 355 // Returns the text used to display, which may be obscured, truncated or | |
| 356 // elided. The subclass may compute elided text on the fly, or use | |
| 357 // precomputed the elided text. | |
| 358 virtual const base::string16& GetDisplayText() = 0; | |
| 359 | |
| 361 // Returns the size required to display the current string (which is the | 360 // Returns the size required to display the current string (which is the |
| 362 // wrapped size in multiline mode). The returned size does not include space | 361 // wrapped size in multiline mode). The returned size does not include space |
| 363 // reserved for the cursor or the offset text shadows. | 362 // reserved for the cursor or the offset text shadows. |
| 364 virtual Size GetStringSize() = 0; | 363 virtual Size GetStringSize() = 0; |
| 365 | 364 |
| 366 // This is same as GetStringSize except that fractional size is returned. | 365 // This is same as GetStringSize except that fractional size is returned. |
| 367 // The default implementation is same as GetStringSize. Certain platforms that | 366 // The default implementation is same as GetStringSize. Certain platforms that |
| 368 // compute the text size as floating-point values, like Mac, will override | 367 // compute the text size as floating-point values, like Mac, will override |
| 369 // this method. | 368 // this method. |
| 370 // See comment in Canvas::GetStringWidthF for its usage. | 369 // See comment in Canvas::GetStringWidthF for its usage. |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 // Range will have is_reversed() true. (This does not return a Rect because a | 440 // Range will have is_reversed() true. (This does not return a Rect because a |
| 442 // Rect can't have a negative width.) | 441 // Rect can't have a negative width.) |
| 443 virtual Range GetGlyphBounds(size_t index) = 0; | 442 virtual Range GetGlyphBounds(size_t index) = 0; |
| 444 | 443 |
| 445 const Vector2d& GetUpdatedDisplayOffset(); | 444 const Vector2d& GetUpdatedDisplayOffset(); |
| 446 void SetDisplayOffset(int horizontal_offset); | 445 void SetDisplayOffset(int horizontal_offset); |
| 447 | 446 |
| 448 protected: | 447 protected: |
| 449 RenderText(); | 448 RenderText(); |
| 450 | 449 |
| 450 // NOTE: The value of these accessors may contain stale values. Please | |
|
msw
2015/02/14 02:02:15
nit: "The values of these accessors may be stale."
oshima
2015/02/14 02:04:20
Done.
| |
| 451 // make sure that these fields are up-to-date before accessing them. | |
| 452 const base::string16& layout_text() const { return layout_text_; } | |
| 453 const base::string16& display_text() const { return display_text_; } | |
| 454 bool text_elided() const { return text_elided_; } | |
| 455 | |
| 451 const BreakList<SkColor>& colors() const { return colors_; } | 456 const BreakList<SkColor>& colors() const { return colors_; } |
| 452 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 457 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
| 453 | 458 |
| 454 const std::vector<internal::Line>& lines() const { return lines_; } | 459 const std::vector<internal::Line>& lines() const { return lines_; } |
| 455 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } | 460 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
| 456 | 461 |
| 457 // Returns the baseline of the current text. The return value depends on | 462 // Returns the baseline of the current text. The return value depends on |
| 458 // the text and its layout while the return value of GetBaseline() doesn't. | 463 // the text and its layout while the return value of GetBaseline() doesn't. |
| 459 // GetAlignmentOffset() takes into account the difference between them. | 464 // GetAlignmentOffset() takes into account the difference between them. |
| 460 // | 465 // |
| 461 // We'd like a RenderText to show the text always on the same baseline | 466 // We'd like a RenderText to show the text always on the same baseline |
| 462 // regardless of the text, so the text does not jump up or down depending | 467 // regardless of the text, so the text does not jump up or down depending |
| 463 // on the text. However, underlying layout engines return different baselines | 468 // on the text. However, underlying layout engines return different baselines |
| 464 // depending on the text. In general, layout engines determine the minimum | 469 // depending on the text. In general, layout engines determine the minimum |
| 465 // bounding box for the text and return the baseline from the top of the | 470 // bounding box for the text and return the baseline from the top of the |
| 466 // bounding box. So the baseline changes depending on font metrics used to | 471 // bounding box. So the baseline changes depending on font metrics used to |
| 467 // layout the text. | 472 // layout the text. |
| 468 // | 473 // |
| 469 // For example, suppose there are FontA and FontB and the baseline of FontA | 474 // For example, suppose there are FontA and FontB and the baseline of FontA |
| 470 // is smaller than the one of FontB. If the text is laid out only with FontA, | 475 // is smaller than the one of FontB. If the text is laid out only with FontA, |
| 471 // then the baseline of FontA may be returned. If the text includes some | 476 // then the baseline of FontA may be returned. If the text includes some |
| 472 // characters which are laid out with FontB, then the baseline of FontB may | 477 // characters which are laid out with FontB, then the baseline of FontB may |
| 473 // be returned. | 478 // be returned. |
| 474 // | 479 // |
| 475 // GetBaseline() returns the fixed baseline regardless of the text. | 480 // GetBaseline() returns the fixed baseline regardless of the text. |
| 476 // GetLayoutTextBaseline() returns the baseline determined by the underlying | 481 // GetDisplayTextBaseline() returns the baseline determined by the underlying |
| 477 // layout engine, and it changes depending on the text. GetAlignmentOffset() | 482 // layout engine, and it changes depending on the text. GetAlignmentOffset() |
| 478 // returns the difference between them. | 483 // returns the difference between them. |
| 479 virtual int GetLayoutTextBaseline() = 0; | 484 virtual int GetDisplayTextBaseline() = 0; |
| 480 | 485 |
| 481 void set_cached_bounds_and_offset_valid(bool valid) { | 486 void set_cached_bounds_and_offset_valid(bool valid) { |
| 482 cached_bounds_and_offset_valid_ = valid; | 487 cached_bounds_and_offset_valid_ = valid; |
| 483 } | 488 } |
| 484 | 489 |
| 485 // Get the selection model that visually neighbors |position| by |break_type|. | 490 // Get the selection model that visually neighbors |position| by |break_type|. |
| 486 // The returned value represents a cursor/caret position without a selection. | 491 // The returned value represents a cursor/caret position without a selection. |
| 487 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, | 492 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, |
| 488 BreakType break_type, | 493 BreakType break_type, |
| 489 VisualCursorDirection direction); | 494 VisualCursorDirection direction); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 508 virtual void SetSelectionModel(const SelectionModel& model); | 513 virtual void SetSelectionModel(const SelectionModel& model); |
| 509 | 514 |
| 510 // Get the visual bounds containing the logical substring within the |range|. | 515 // Get the visual bounds containing the logical substring within the |range|. |
| 511 // If |range| is empty, the result is empty. These bounds could be visually | 516 // If |range| is empty, the result is empty. These bounds could be visually |
| 512 // discontinuous if the substring is split by a LTR/RTL level change. | 517 // discontinuous if the substring is split by a LTR/RTL level change. |
| 513 // These bounds are in local coordinates, but may be outside the visible | 518 // These bounds are in local coordinates, but may be outside the visible |
| 514 // region if the text is longer than the textfield. Subsequent text, cursor, | 519 // region if the text is longer than the textfield. Subsequent text, cursor, |
| 515 // or bounds changes may invalidate returned values. | 520 // or bounds changes may invalidate returned values. |
| 516 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; | 521 virtual std::vector<Rect> GetSubstringBounds(const Range& range) = 0; |
| 517 | 522 |
| 518 // Convert between indices into |text_| and indices into |obscured_text_|, | 523 // Convert between indices into |text_| and indices into |
| 519 // which differ when the text is obscured. Regardless of whether or not the | 524 // GetDisplayText(), which differ when the text is obscured, |
| 520 // text is obscured, the character (code point) offsets always match. | 525 // truncated or elided. Regardless of whether or not the text is |
| 521 virtual size_t TextIndexToLayoutIndex(size_t index) const = 0; | 526 // obscured, the character (code point) offsets always match. |
| 522 virtual size_t LayoutIndexToTextIndex(size_t index) const = 0; | 527 virtual size_t TextIndexToDisplayIndex(size_t index) = 0; |
| 528 virtual size_t DisplayIndexToTextIndex(size_t index) = 0; | |
| 523 | 529 |
| 524 // Reset the layout to be invalid. | 530 // Notifies that layout text, or attributes that affect the layout text |
| 525 virtual void ResetLayout() = 0; | 531 // shape have changed. |text_changed| is true if the content of the |
| 532 // |layout_text_| has changed, not just attributes. | |
| 533 virtual void OnLayoutTextAttributeChanged(bool text_changed) = 0; | |
| 534 | |
| 535 // Notifies that attributes that affect the display text shape have changed. | |
| 536 virtual void OnDisplayTextAttributeChanged() = 0; | |
| 526 | 537 |
| 527 // Ensure the text is laid out, lines are computed, and |lines_| is valid. | 538 // Ensure the text is laid out, lines are computed, and |lines_| is valid. |
| 528 virtual void EnsureLayout() = 0; | 539 virtual void EnsureLayout() = 0; |
| 529 | 540 |
| 530 // Draw the text. | 541 // Draw the text. |
| 531 virtual void DrawVisualText(Canvas* canvas) = 0; | 542 virtual void DrawVisualText(Canvas* canvas) = 0; |
| 532 | 543 |
| 533 // Returns the text used for layout, which may be obscured or truncated. | 544 // Update the display text. |
| 534 const base::string16& GetLayoutText() const; | 545 void UpdateDisplayText(float text_width); |
| 535 | 546 |
| 536 // Returns layout text positions that are suitable for breaking lines. | 547 // Returns display text positions that are suitable for breaking lines. |
| 537 const BreakList<size_t>& GetLineBreaks(); | 548 const BreakList<size_t>& GetLineBreaks(); |
| 538 | 549 |
| 539 // Apply (and undo) temporary composition underlines and selection colors. | 550 // Apply (and undo) temporary composition underlines and selection colors. |
| 540 void ApplyCompositionAndSelectionStyles(); | 551 void ApplyCompositionAndSelectionStyles(); |
| 541 void UndoCompositionAndSelectionStyles(); | 552 void UndoCompositionAndSelectionStyles(); |
| 542 | 553 |
| 543 // Returns the line offset from the origin after applying the text alignment | 554 // Returns the line offset from the origin after applying the text alignment |
| 544 // and the display offset. | 555 // and the display offset. |
| 545 Vector2d GetLineOffset(size_t line_number); | 556 Vector2d GetLineOffset(size_t line_number); |
| 546 | 557 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 557 | 568 |
| 558 // Returns the line offset from the origin, accounts for text alignment only. | 569 // Returns the line offset from the origin, accounts for text alignment only. |
| 559 Vector2d GetAlignmentOffset(size_t line_number); | 570 Vector2d GetAlignmentOffset(size_t line_number); |
| 560 | 571 |
| 561 // Applies fade effects to |renderer|. | 572 // Applies fade effects to |renderer|. |
| 562 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); | 573 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
| 563 | 574 |
| 564 // Applies text shadows to |renderer|. | 575 // Applies text shadows to |renderer|. |
| 565 void ApplyTextShadows(internal::SkiaTextRenderer* renderer); | 576 void ApplyTextShadows(internal::SkiaTextRenderer* renderer); |
| 566 | 577 |
| 578 // Get the text direction for the current directionality mode and given | |
| 579 // |text|. | |
| 580 base::i18n::TextDirection GetTextDirection(const base::string16& text); | |
| 581 | |
| 567 // A convenience function to check whether the glyph attached to the caret | 582 // A convenience function to check whether the glyph attached to the caret |
| 568 // is within the given range. | 583 // is within the given range. |
| 569 static bool RangeContainsCaret(const Range& range, | 584 static bool RangeContainsCaret(const Range& range, |
| 570 size_t caret_pos, | 585 size_t caret_pos, |
| 571 LogicalCursorDirection caret_affinity); | 586 LogicalCursorDirection caret_affinity); |
| 572 | 587 |
| 573 private: | 588 private: |
| 574 friend class RenderTextTest; | 589 friend class RenderTextTest; |
| 575 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 590 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
| 576 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); | 591 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 601 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes); | 616 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, PangoAttributes); |
| 602 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StringFitsOwnWidth); | 617 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, StringFitsOwnWidth); |
| 603 | 618 |
| 604 // Set the cursor to |position|, with the caret trailing the previous | 619 // Set the cursor to |position|, with the caret trailing the previous |
| 605 // grapheme, or if there is no previous grapheme, leading the cursor position. | 620 // grapheme, or if there is no previous grapheme, leading the cursor position. |
| 606 // If |select| is false, the selection start is moved to the same position. | 621 // If |select| is false, the selection start is moved to the same position. |
| 607 // If the |position| is not a cursorable position (not on grapheme boundary), | 622 // If the |position| is not a cursorable position (not on grapheme boundary), |
| 608 // it is a NO-OP. | 623 // it is a NO-OP. |
| 609 void MoveCursorTo(size_t position, bool select); | 624 void MoveCursorTo(size_t position, bool select); |
| 610 | 625 |
| 611 // Updates |layout_text_| if the text is obscured or truncated. | 626 // Updates |layout_text_| and |display_text_| as needed (or marks them dirty). |
| 612 void UpdateLayoutText(); | 627 void OnTextAttributeChanged(); |
| 613 | 628 |
| 614 // Elides |text| as needed to fit in the |available_width| using |behavior|. | 629 // Elides |text| as needed to fit in the |available_width| using |behavior|. |
| 630 // |text_width| is the pre-calculated width of the text shaped by this render | |
| 631 // text, or pass 0 if the width is unknown. | |
| 615 base::string16 Elide(const base::string16& text, | 632 base::string16 Elide(const base::string16& text, |
| 633 float text_width, | |
| 616 float available_width, | 634 float available_width, |
| 617 ElideBehavior behavior); | 635 ElideBehavior behavior); |
| 618 | 636 |
| 619 // Elides |email| as needed to fit the |available_width|. | 637 // Elides |email| as needed to fit the |available_width|. |
| 620 base::string16 ElideEmail(const base::string16& email, float available_width); | 638 base::string16 ElideEmail(const base::string16& email, float available_width); |
| 621 | 639 |
| 622 // Update the cached bounds and display offset to ensure that the current | 640 // Update the cached bounds and display offset to ensure that the current |
| 623 // cursor is within the visible display area. | 641 // cursor is within the visible display area. |
| 624 void UpdateCachedBoundsAndOffset(); | 642 void UpdateCachedBoundsAndOffset(); |
| 625 | 643 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 666 // The background color used for drawing the selection when focused. | 684 // The background color used for drawing the selection when focused. |
| 667 SkColor selection_background_focused_color_; | 685 SkColor selection_background_focused_color_; |
| 668 | 686 |
| 669 // The focus state of the text. | 687 // The focus state of the text. |
| 670 bool focused_; | 688 bool focused_; |
| 671 | 689 |
| 672 // Composition text range. | 690 // Composition text range. |
| 673 Range composition_range_; | 691 Range composition_range_; |
| 674 | 692 |
| 675 // Color and style breaks, used to color and stylize ranges of text. | 693 // Color and style breaks, used to color and stylize ranges of text. |
| 676 // BreakList positions are stored with text indices, not layout indices. | 694 // BreakList positions are stored with text indices, not display indices. |
| 677 // TODO(msw): Expand to support cursor, selection, background, etc. colors. | 695 // TODO(msw): Expand to support cursor, selection, background, etc. colors. |
| 678 BreakList<SkColor> colors_; | 696 BreakList<SkColor> colors_; |
| 679 std::vector<BreakList<bool> > styles_; | 697 std::vector<BreakList<bool> > styles_; |
| 680 | 698 |
| 681 // Breaks saved without temporary composition and selection styling. | 699 // Breaks saved without temporary composition and selection styling. |
| 682 BreakList<SkColor> saved_colors_; | 700 BreakList<SkColor> saved_colors_; |
| 683 BreakList<bool> saved_underlines_; | 701 BreakList<bool> saved_underlines_; |
| 684 bool composition_and_selection_styles_applied_; | 702 bool composition_and_selection_styles_applied_; |
| 685 | 703 |
| 686 // A flag to obscure actual text with asterisks for password fields. | 704 // A flag to obscure actual text with asterisks for password fields. |
| 687 bool obscured_; | 705 bool obscured_; |
| 688 // The index at which the char should be revealed in the obscured text. | 706 // The index at which the char should be revealed in the obscured text. |
| 689 int obscured_reveal_index_; | 707 int obscured_reveal_index_; |
| 690 | 708 |
| 691 // The maximum length of text to display, 0 forgoes a hard limit. | 709 // The maximum length of text to display, 0 forgoes a hard limit. |
| 692 size_t truncate_length_; | 710 size_t truncate_length_; |
| 693 | 711 |
| 712 // The obscured and/or truncated text used to layout the text to display. | |
| 713 base::string16 layout_text_; | |
| 714 | |
| 715 // The elided text displayed visually. This is empty if the text | |
| 716 // does not have to be elided, or became empty as a result of eliding. | |
| 717 // TODO(oshima): When the text is elided, painting can be done only with | |
| 718 // display text info, so it should be able to clear the |layout_text_| and | |
| 719 // associated information. | |
| 720 base::string16 display_text_; | |
| 721 | |
| 694 // The behavior for eliding, fading, or truncating. | 722 // The behavior for eliding, fading, or truncating. |
| 695 ElideBehavior elide_behavior_; | 723 ElideBehavior elide_behavior_; |
| 696 | 724 |
| 697 // The obscured and/or truncated text that will be displayed. | 725 // True if the text is elided given the current behavior and display area. |
| 698 base::string16 layout_text_; | 726 bool text_elided_; |
| 699 | |
| 700 // Whether newline characters should be replaced with newline symbols. | |
| 701 bool replace_newline_chars_with_symbols_; | |
| 702 | 727 |
| 703 // The minimum height a line should have. | 728 // The minimum height a line should have. |
| 704 int min_line_height_; | 729 int min_line_height_; |
| 705 | 730 |
| 706 // Whether the text should be broken into multiple lines. Uses the width of | 731 // Whether the text should be broken into multiple lines. Uses the width of |
| 707 // |display_rect_| as the width cap. | 732 // |display_rect_| as the width cap. |
| 708 bool multiline_; | 733 bool multiline_; |
| 709 | 734 |
| 710 // Is the background transparent (either partially or fully)? | 735 // Is the background transparent (either partially or fully)? |
| 711 bool background_is_transparent_; | 736 bool background_is_transparent_; |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 728 // centered. | 753 // centered. |
| 729 int baseline_; | 754 int baseline_; |
| 730 | 755 |
| 731 // The cached bounds and offset are invalidated by changes to the cursor, | 756 // The cached bounds and offset are invalidated by changes to the cursor, |
| 732 // selection, font, and other operations that adjust the visible text bounds. | 757 // selection, font, and other operations that adjust the visible text bounds. |
| 733 bool cached_bounds_and_offset_valid_; | 758 bool cached_bounds_and_offset_valid_; |
| 734 | 759 |
| 735 // Text shadows to be drawn. | 760 // Text shadows to be drawn. |
| 736 ShadowValues shadows_; | 761 ShadowValues shadows_; |
| 737 | 762 |
| 738 // A list of valid layout text line break positions. | 763 // A list of valid display text line break positions. |
| 739 BreakList<size_t> line_breaks_; | 764 BreakList<size_t> line_breaks_; |
| 740 | 765 |
| 741 // Lines computed by EnsureLayout. These should be invalidated with | 766 // Lines computed by EnsureLayout. These should be invalidated upon |
| 742 // ResetLayout and on |display_rect_| changes. | 767 // OnLayoutTextAttributeChanged and OnDisplayTextAttributeChanged calls. |
| 743 std::vector<internal::Line> lines_; | 768 std::vector<internal::Line> lines_; |
| 744 | 769 |
| 745 DISALLOW_COPY_AND_ASSIGN(RenderText); | 770 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 746 }; | 771 }; |
| 747 | 772 |
| 748 } // namespace gfx | 773 } // namespace gfx |
| 749 | 774 |
| 750 #endif // UI_GFX_RENDER_TEXT_H_ | 775 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |