| 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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 static RenderText* CreateInstance(); | 160 static RenderText* CreateInstance(); |
| 161 | 161 |
| 162 const base::string16& text() const { return text_; } | 162 const base::string16& text() const { return text_; } |
| 163 void SetText(const base::string16& text); | 163 void SetText(const base::string16& text); |
| 164 | 164 |
| 165 HorizontalAlignment horizontal_alignment() const { | 165 HorizontalAlignment horizontal_alignment() const { |
| 166 return horizontal_alignment_; | 166 return horizontal_alignment_; |
| 167 } | 167 } |
| 168 void SetHorizontalAlignment(HorizontalAlignment alignment); | 168 void SetHorizontalAlignment(HorizontalAlignment alignment); |
| 169 | 169 |
| 170 VerticalAlignment vertical_alignment() const { | |
| 171 return vertical_alignment_; | |
| 172 } | |
| 173 void SetVerticalAlignment(VerticalAlignment alignment); | |
| 174 | |
| 175 const FontList& font_list() const { return font_list_; } | 170 const FontList& font_list() const { return font_list_; } |
| 176 void SetFontList(const FontList& font_list); | 171 void SetFontList(const FontList& font_list); |
| 177 void SetFont(const Font& font); | 172 void SetFont(const Font& font); |
| 178 | 173 |
| 179 // Set the font size to |size| in pixels. | 174 // Set the font size to |size| in pixels. |
| 180 void SetFontSize(int size); | 175 void SetFontSize(int size); |
| 181 | 176 |
| 182 // Get the first font in |font_list_|. | 177 // Get the first font in |font_list_|. |
| 183 const Font& GetPrimaryFont() const; | 178 const Font& GetPrimaryFont() const; |
| 184 | 179 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 // The default implementation is same as GetStringSize. Certain platforms that | 326 // The default implementation is same as GetStringSize. Certain platforms that |
| 332 // compute the text size as floating-point values, like Mac, will override | 327 // compute the text size as floating-point values, like Mac, will override |
| 333 // this method. | 328 // this method. |
| 334 // See comment in Canvas::GetStringWidthF for its usage. | 329 // See comment in Canvas::GetStringWidthF for its usage. |
| 335 virtual SizeF GetStringSizeF(); | 330 virtual SizeF GetStringSizeF(); |
| 336 | 331 |
| 337 // Returns the width of the content (which is the wrapped width in multiline | 332 // Returns the width of the content (which is the wrapped width in multiline |
| 338 // mode). Reserves room for the cursor if |cursor_enabled_| is true. | 333 // mode). Reserves room for the cursor if |cursor_enabled_| is true. |
| 339 int GetContentWidth(); | 334 int GetContentWidth(); |
| 340 | 335 |
| 341 // Returns the common baseline of the text. The returned value is the vertical | 336 // Returns the common baseline of the text. The return value is the vertical |
| 342 // offset from the top of |display_rect| to the text baseline, in pixels. | 337 // offset from the top of |display_rect_| to the text baseline, in pixels. |
| 343 virtual int GetBaseline() = 0; | 338 // The baseline is determined from the font list and display rect, and does |
| 339 // not depend on the text. |
| 340 int GetBaseline(); |
| 344 | 341 |
| 345 void Draw(Canvas* canvas); | 342 void Draw(Canvas* canvas); |
| 346 | 343 |
| 347 // Draws a cursor at |position|. | 344 // Draws a cursor at |position|. |
| 348 void DrawCursor(Canvas* canvas, const SelectionModel& position); | 345 void DrawCursor(Canvas* canvas, const SelectionModel& position); |
| 349 | 346 |
| 350 // Draw the selected text without a cursor or selection highlight. Subpixel | 347 // Draw the selected text without a cursor or selection highlight. Subpixel |
| 351 // antialiasing is disabled and foreground color is forced to black. | 348 // antialiasing is disabled and foreground color is forced to black. |
| 352 void DrawSelectedTextForDrag(Canvas* canvas); | 349 void DrawSelectedTextForDrag(Canvas* canvas); |
| 353 | 350 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 391 | 388 |
| 392 protected: | 389 protected: |
| 393 RenderText(); | 390 RenderText(); |
| 394 | 391 |
| 395 const BreakList<SkColor>& colors() const { return colors_; } | 392 const BreakList<SkColor>& colors() const { return colors_; } |
| 396 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 393 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
| 397 | 394 |
| 398 const std::vector<internal::Line>& lines() const { return lines_; } | 395 const std::vector<internal::Line>& lines() const { return lines_; } |
| 399 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } | 396 void set_lines(std::vector<internal::Line>* lines) { lines_.swap(*lines); } |
| 400 | 397 |
| 398 // Returns the baseline of the layouted text. The return value depends on |
| 399 // the text and its layout while the return value of GetBaseline() doesn't. |
| 400 // GetAlignmentOffset() takes into account the difference between them. |
| 401 virtual int GetBaselineOfTextLayout() = 0; |
| 402 |
| 401 const Vector2d& GetUpdatedDisplayOffset(); | 403 const Vector2d& GetUpdatedDisplayOffset(); |
| 402 | 404 |
| 403 void set_cached_bounds_and_offset_valid(bool valid) { | 405 void set_cached_bounds_and_offset_valid(bool valid) { |
| 404 cached_bounds_and_offset_valid_ = valid; | 406 cached_bounds_and_offset_valid_ = valid; |
| 405 } | 407 } |
| 406 | 408 |
| 407 // Get the selection model that visually neighbors |position| by |break_type|. | 409 // Get the selection model that visually neighbors |position| by |break_type|. |
| 408 // The returned value represents a cursor/caret position without a selection. | 410 // The returned value represents a cursor/caret position without a selection. |
| 409 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, | 411 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, |
| 410 BreakType break_type, | 412 BreakType break_type, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 // Draw the selection. | 537 // Draw the selection. |
| 536 void DrawSelection(Canvas* canvas); | 538 void DrawSelection(Canvas* canvas); |
| 537 | 539 |
| 538 // Logical UTF-16 string data to be drawn. | 540 // Logical UTF-16 string data to be drawn. |
| 539 base::string16 text_; | 541 base::string16 text_; |
| 540 | 542 |
| 541 // Horizontal alignment of the text with respect to |display_rect_|. The | 543 // Horizontal alignment of the text with respect to |display_rect_|. The |
| 542 // default is to align left if the application UI is LTR and right if RTL. | 544 // default is to align left if the application UI is LTR and right if RTL. |
| 543 HorizontalAlignment horizontal_alignment_; | 545 HorizontalAlignment horizontal_alignment_; |
| 544 | 546 |
| 545 // Vertical alignment of the text with respect to |display_rect_|. The | |
| 546 // default is to align vertically centered. | |
| 547 VerticalAlignment vertical_alignment_; | |
| 548 | |
| 549 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. | 547 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. |
| 550 DirectionalityMode directionality_mode_; | 548 DirectionalityMode directionality_mode_; |
| 551 | 549 |
| 552 // The cached text direction, potentially computed from the text or UI locale. | 550 // The cached text direction, potentially computed from the text or UI locale. |
| 553 // Use GetTextDirection(), do not use this potentially invalid value directly! | 551 // Use GetTextDirection(), do not use this potentially invalid value directly! |
| 554 base::i18n::TextDirection text_direction_; | 552 base::i18n::TextDirection text_direction_; |
| 555 | 553 |
| 556 // A list of fonts used to render |text_|. | 554 // A list of fonts used to render |text_|. |
| 557 FontList font_list_; | 555 FontList font_list_; |
| 558 | 556 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 624 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) | 622 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) |
| 625 // that results in incorrect clipping when drawing to the document margins. | 623 // that results in incorrect clipping when drawing to the document margins. |
| 626 // This field allows disabling clipping to work around the issue. | 624 // This field allows disabling clipping to work around the issue. |
| 627 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. | 625 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. |
| 628 bool clip_to_display_rect_; | 626 bool clip_to_display_rect_; |
| 629 | 627 |
| 630 // The offset for the text to be drawn, relative to the display area. | 628 // The offset for the text to be drawn, relative to the display area. |
| 631 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). | 629 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). |
| 632 Vector2d display_offset_; | 630 Vector2d display_offset_; |
| 633 | 631 |
| 632 // The baseline of the text. This is determined from height and cap height |
| 633 // of the font list so the text is vertically centered. |
| 634 int baseline_; |
| 635 |
| 634 // The cached bounds and offset are invalidated by changes to the cursor, | 636 // The cached bounds and offset are invalidated by changes to the cursor, |
| 635 // selection, font, and other operations that adjust the visible text bounds. | 637 // selection, font, and other operations that adjust the visible text bounds. |
| 636 bool cached_bounds_and_offset_valid_; | 638 bool cached_bounds_and_offset_valid_; |
| 637 | 639 |
| 638 // Text shadows to be drawn. | 640 // Text shadows to be drawn. |
| 639 ShadowValues text_shadows_; | 641 ShadowValues text_shadows_; |
| 640 | 642 |
| 641 // A list of valid layout text line break positions. | 643 // A list of valid layout text line break positions. |
| 642 BreakList<size_t> line_breaks_; | 644 BreakList<size_t> line_breaks_; |
| 643 | 645 |
| 644 // Lines computed by EnsureLayout. These should be invalidated with | 646 // Lines computed by EnsureLayout. These should be invalidated with |
| 645 // ResetLayout and on |display_rect_| changes. | 647 // ResetLayout and on |display_rect_| changes. |
| 646 std::vector<internal::Line> lines_; | 648 std::vector<internal::Line> lines_; |
| 647 | 649 |
| 648 DISALLOW_COPY_AND_ASSIGN(RenderText); | 650 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 649 }; | 651 }; |
| 650 | 652 |
| 651 } // namespace gfx | 653 } // namespace gfx |
| 652 | 654 |
| 653 #endif // UI_GFX_RENDER_TEXT_H_ | 655 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |