| 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> |
| 11 #include <utility> | 11 #include <utility> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/gtest_prod_util.h" | 14 #include "base/gtest_prod_util.h" |
| 15 #include "base/i18n/rtl.h" | 15 #include "base/i18n/rtl.h" |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "third_party/skia/include/core/SkColor.h" | 17 #include "third_party/skia/include/core/SkColor.h" |
| 18 #include "third_party/skia/include/core/SkPaint.h" | 18 #include "third_party/skia/include/core/SkPaint.h" |
| 19 #include "ui/base/range/range.h" | 19 #include "ui/base/range/range.h" |
| 20 #include "ui/gfx/font_list.h" | 20 #include "ui/gfx/font_list.h" |
| 21 #include "ui/gfx/point.h" | 21 #include "ui/gfx/point.h" |
| 22 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
| 23 #include "ui/gfx/selection_model.h" | 23 #include "ui/gfx/selection_model.h" |
| 24 #include "ui/gfx/shadow_value.h" | 24 #include "ui/gfx/shadow_value.h" |
| 25 #include "ui/gfx/text_constants.h" |
| 25 | 26 |
| 26 class SkCanvas; | 27 class SkCanvas; |
| 27 class SkDrawLooper; | 28 class SkDrawLooper; |
| 28 struct SkPoint; | 29 struct SkPoint; |
| 29 class SkShader; | 30 class SkShader; |
| 30 class SkTypeface; | 31 class SkTypeface; |
| 31 | 32 |
| 32 namespace gfx { | 33 namespace gfx { |
| 33 | 34 |
| 34 class Canvas; | 35 class Canvas; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 // A gfx::Font::FontStyle flag to specify bold and italic styles. | 84 // A gfx::Font::FontStyle flag to specify bold and italic styles. |
| 84 int font_style; | 85 int font_style; |
| 85 bool strike; | 86 bool strike; |
| 86 bool diagonal_strike; | 87 bool diagonal_strike; |
| 87 bool underline; | 88 bool underline; |
| 88 ui::Range range; | 89 ui::Range range; |
| 89 }; | 90 }; |
| 90 | 91 |
| 91 typedef std::vector<StyleRange> StyleRanges; | 92 typedef std::vector<StyleRange> StyleRanges; |
| 92 | 93 |
| 93 // TODO(msw): Distinguish between logical character stops and glyph stops? | |
| 94 // CHARACTER_BREAK cursor movements should stop at neighboring characters. | |
| 95 // WORD_BREAK cursor movements should stop at the nearest word boundaries. | |
| 96 // LINE_BREAK cursor movements should stop at the text ends as shown on screen. | |
| 97 enum BreakType { | |
| 98 CHARACTER_BREAK, | |
| 99 WORD_BREAK, | |
| 100 LINE_BREAK, | |
| 101 }; | |
| 102 | |
| 103 // Horizontal text alignment styles. | |
| 104 enum HorizontalAlignment { | |
| 105 ALIGN_LEFT, | |
| 106 ALIGN_CENTER, | |
| 107 ALIGN_RIGHT, | |
| 108 }; | |
| 109 | |
| 110 // RenderText represents an abstract model of styled text and its corresponding | 94 // RenderText represents an abstract model of styled text and its corresponding |
| 111 // visual layout. Support is built in for a cursor, a selection, simple styling, | 95 // visual layout. Support is built in for a cursor, a selection, simple styling, |
| 112 // complex scripts, and bi-directional text. Implementations provide mechanisms | 96 // complex scripts, and bi-directional text. Implementations provide mechanisms |
| 113 // for rendering and translation between logical and visual data. | 97 // for rendering and translation between logical and visual data. |
| 114 class UI_EXPORT RenderText { | 98 class UI_EXPORT RenderText { |
| 115 public: | 99 public: |
| 116 virtual ~RenderText(); | 100 virtual ~RenderText(); |
| 117 | 101 |
| 118 // Creates a platform-specific RenderText instance. | 102 // Creates a platform-specific RenderText instance. |
| 119 static RenderText* CreateInstance(); | 103 static RenderText* CreateInstance(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 | 223 |
| 240 const ui::Range& GetCompositionRange() const; | 224 const ui::Range& GetCompositionRange() const; |
| 241 void SetCompositionRange(const ui::Range& composition_range); | 225 void SetCompositionRange(const ui::Range& composition_range); |
| 242 | 226 |
| 243 // Apply |style_range| to the internal style model. | 227 // Apply |style_range| to the internal style model. |
| 244 void ApplyStyleRange(const StyleRange& style_range); | 228 void ApplyStyleRange(const StyleRange& style_range); |
| 245 | 229 |
| 246 // Apply |default_style_| over the entire text range. | 230 // Apply |default_style_| over the entire text range. |
| 247 void ApplyDefaultStyle(); | 231 void ApplyDefaultStyle(); |
| 248 | 232 |
| 249 // Returns the dominant direction of the current text. | 233 // Set the text directionality mode and get the text direction yielded. |
| 250 virtual base::i18n::TextDirection GetTextDirection() = 0; | 234 void SetDirectionalityMode(DirectionalityMode mode); |
| 235 base::i18n::TextDirection GetTextDirection(); |
| 251 | 236 |
| 252 // Returns the visual movement direction corresponding to the logical end | 237 // Returns the visual movement direction corresponding to the logical end |
| 253 // of the text, considering only the dominant direction returned by | 238 // of the text, considering only the dominant direction returned by |
| 254 // |GetTextDirection()|, not the direction of a particular run. | 239 // |GetTextDirection()|, not the direction of a particular run. |
| 255 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); | 240 VisualCursorDirection GetVisualDirectionOfLogicalEnd(); |
| 256 | 241 |
| 257 // Returns the size in pixels of the entire string. For the height, this will | 242 // Returns the size in pixels of the entire string. For the height, this will |
| 258 // return the maximum height among the different fonts in the text runs. | 243 // return the maximum height among the different fonts in the text runs. |
| 259 // Note that this returns the raw size of the string, which does not include | 244 // Note that this returns the raw size of the string, which does not include |
| 260 // the margin area of text shadows. | 245 // the margin area of text shadows. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 // Draw the selection and cursor. | 417 // Draw the selection and cursor. |
| 433 void DrawSelection(Canvas* canvas); | 418 void DrawSelection(Canvas* canvas); |
| 434 void DrawCursor(Canvas* canvas); | 419 void DrawCursor(Canvas* canvas); |
| 435 | 420 |
| 436 // Logical UTF-16 string data to be drawn. | 421 // Logical UTF-16 string data to be drawn. |
| 437 string16 text_; | 422 string16 text_; |
| 438 | 423 |
| 439 // Horizontal alignment of the text with respect to |display_rect_|. | 424 // Horizontal alignment of the text with respect to |display_rect_|. |
| 440 HorizontalAlignment horizontal_alignment_; | 425 HorizontalAlignment horizontal_alignment_; |
| 441 | 426 |
| 427 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. |
| 428 DirectionalityMode directionality_mode_; |
| 429 |
| 430 // The cached text direction, potentially computed from the text or UI locale. |
| 431 // Use GetTextDirection(), do not use this potentially invalid value directly! |
| 432 base::i18n::TextDirection text_direction_; |
| 433 |
| 442 // A list of fonts used to render |text_|. | 434 // A list of fonts used to render |text_|. |
| 443 FontList font_list_; | 435 FontList font_list_; |
| 444 | 436 |
| 445 // Logical selection range and visual cursor position. | 437 // Logical selection range and visual cursor position. |
| 446 SelectionModel selection_model_; | 438 SelectionModel selection_model_; |
| 447 | 439 |
| 448 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. | 440 // The cached cursor bounds; get these bounds with GetUpdatedCursorBounds. |
| 449 Rect cursor_bounds_; | 441 Rect cursor_bounds_; |
| 450 | 442 |
| 451 // Specifies whether the cursor is enabled. If disabled, no space is reserved | 443 // Specifies whether the cursor is enabled. If disabled, no space is reserved |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 | 500 |
| 509 // Text shadows to be drawn. | 501 // Text shadows to be drawn. |
| 510 ShadowValues text_shadows_; | 502 ShadowValues text_shadows_; |
| 511 | 503 |
| 512 DISALLOW_COPY_AND_ASSIGN(RenderText); | 504 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 513 }; | 505 }; |
| 514 | 506 |
| 515 } // namespace gfx | 507 } // namespace gfx |
| 516 | 508 |
| 517 #endif // UI_GFX_RENDER_TEXT_H_ | 509 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |