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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 // Note that this returns the raw size of the string, which does not include | 268 // Note that this returns the raw size of the string, which does not include |
269 // the margin area of text shadows. | 269 // the margin area of text shadows. |
270 virtual Size GetStringSize() = 0; | 270 virtual Size GetStringSize() = 0; |
271 | 271 |
272 // Returns the common baseline of the text. The returned value is the vertical | 272 // Returns the common baseline of the text. The returned value is the vertical |
273 // offset from the top of |display_rect| to the text baseline, in pixels. | 273 // offset from the top of |display_rect| to the text baseline, in pixels. |
274 virtual int GetBaseline() = 0; | 274 virtual int GetBaseline() = 0; |
275 | 275 |
276 void Draw(Canvas* canvas); | 276 void Draw(Canvas* canvas); |
277 | 277 |
| 278 // Draws a cursor at |position|. |
| 279 void DrawCursor(Canvas* canvas, const SelectionModel& position); |
| 280 |
278 // Draw the selected text without a cursor or selection highlight. | 281 // Draw the selected text without a cursor or selection highlight. |
279 void DrawSelectedText(Canvas* canvas); | 282 void DrawSelectedText(Canvas* canvas); |
280 | 283 |
281 // Gets the SelectionModel from a visual point in local coordinates. | 284 // Gets the SelectionModel from a visual point in local coordinates. |
282 virtual SelectionModel FindCursorPosition(const Point& point) = 0; | 285 virtual SelectionModel FindCursorPosition(const Point& point) = 0; |
283 | 286 |
284 // Get the visual bounds of a cursor at |selection|. These bounds typically | 287 // Get the visual bounds of a cursor at |selection|. These bounds typically |
285 // represent a vertical line, but if |insert_mode| is true they contain the | 288 // represent a vertical line, but if |insert_mode| is true they contain the |
286 // bounds of the associated glyph. These bounds are in local coordinates, but | 289 // bounds of the associated glyph. These bounds are in local coordinates, but |
287 // may be outside the visible region if the text is longer than the textfield. | 290 // may be outside the visible region if the text is longer than the textfield. |
(...skipping 21 matching lines...) Expand all Loading... |
309 // Sets shadows to drawn with text. | 312 // Sets shadows to drawn with text. |
310 void SetTextShadows(const ShadowValues& shadows); | 313 void SetTextShadows(const ShadowValues& shadows); |
311 | 314 |
312 typedef std::pair<Font, ui::Range> FontSpan; | 315 typedef std::pair<Font, ui::Range> FontSpan; |
313 // For testing purposes, returns which fonts were chosen for which parts of | 316 // For testing purposes, returns which fonts were chosen for which parts of |
314 // the text by returning a vector of Font and Range pairs, where each range | 317 // the text by returning a vector of Font and Range pairs, where each range |
315 // specifies the character range for which the corresponding font has been | 318 // specifies the character range for which the corresponding font has been |
316 // chosen. | 319 // chosen. |
317 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; | 320 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; |
318 | 321 |
| 322 // A convenience function to check whether the glyph attached to the caret |
| 323 // is within the given range. |
| 324 static bool RangeContainsCaret(const ui::Range& range, |
| 325 size_t caret_pos, |
| 326 LogicalCursorDirection caret_affinity); |
| 327 |
319 protected: | 328 protected: |
320 RenderText(); | 329 RenderText(); |
321 | 330 |
322 const BreakList<SkColor>& colors() const { return colors_; } | 331 const BreakList<SkColor>& colors() const { return colors_; } |
323 const std::vector<BreakList<bool> >& styles() const { return styles_; } | 332 const std::vector<BreakList<bool> >& styles() const { return styles_; } |
324 | 333 |
325 const Vector2d& GetUpdatedDisplayOffset(); | 334 const Vector2d& GetUpdatedDisplayOffset(); |
326 | 335 |
327 void set_cached_bounds_and_offset_valid(bool valid) { | 336 void set_cached_bounds_and_offset_valid(bool valid) { |
328 cached_bounds_and_offset_valid_ = valid; | 337 cached_bounds_and_offset_valid_ = valid; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // Returns the offset for drawing text. Does not account for font | 421 // Returns the offset for drawing text. Does not account for font |
413 // baseline, as needed by Skia. | 422 // baseline, as needed by Skia. |
414 Vector2d GetOffsetForDrawing(); | 423 Vector2d GetOffsetForDrawing(); |
415 | 424 |
416 // Applies fade effects to |renderer|. | 425 // Applies fade effects to |renderer|. |
417 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); | 426 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
418 | 427 |
419 // Applies text shadows to |renderer|. | 428 // Applies text shadows to |renderer|. |
420 void ApplyTextShadows(internal::SkiaTextRenderer* renderer); | 429 void ApplyTextShadows(internal::SkiaTextRenderer* renderer); |
421 | 430 |
422 // A convenience function to check whether the glyph attached to the caret | |
423 // is within the given range. | |
424 static bool RangeContainsCaret(const ui::Range& range, | |
425 size_t caret_pos, | |
426 LogicalCursorDirection caret_affinity); | |
427 | |
428 private: | 431 private: |
429 friend class RenderTextTest; | 432 friend class RenderTextTest; |
430 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); | 433 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, DefaultStyle); |
431 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); | 434 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, SetColorAndStyle); |
432 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); | 435 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ApplyColorAndStyle); |
433 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); | 436 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, ObscuredText); |
434 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); | 437 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, GraphemePositions); |
435 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); | 438 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, EdgeSelectionModels); |
436 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, OriginForDrawing); | 439 FRIEND_TEST_ALL_PREFIXES(RenderTextTest, OriginForDrawing); |
437 | 440 |
438 // Set the cursor to |position|, with the caret trailing the previous | 441 // Set the cursor to |position|, with the caret trailing the previous |
439 // grapheme, or if there is no previous grapheme, leading the cursor position. | 442 // grapheme, or if there is no previous grapheme, leading the cursor position. |
440 // If |select| is false, the selection start is moved to the same position. | 443 // If |select| is false, the selection start is moved to the same position. |
441 // If the |position| is not a cursorable position (not on grapheme boundary), | 444 // If the |position| is not a cursorable position (not on grapheme boundary), |
442 // it is a NO-OP. | 445 // it is a NO-OP. |
443 void MoveCursorTo(size_t position, bool select); | 446 void MoveCursorTo(size_t position, bool select); |
444 | 447 |
445 // Updates |obscured_text_| if the text is obscured. | 448 // Updates |obscured_text_| if the text is obscured. |
446 void UpdateObscuredText(); | 449 void UpdateObscuredText(); |
447 | 450 |
448 // Update the cached bounds and display offset to ensure that the current | 451 // Update the cached bounds and display offset to ensure that the current |
449 // cursor is within the visible display area. | 452 // cursor is within the visible display area. |
450 void UpdateCachedBoundsAndOffset(); | 453 void UpdateCachedBoundsAndOffset(); |
451 | 454 |
452 // Draw the selection and cursor. | 455 // Draw the selection. |
453 void DrawSelection(Canvas* canvas); | 456 void DrawSelection(Canvas* canvas); |
454 void DrawCursor(Canvas* canvas); | |
455 | 457 |
456 // Logical UTF-16 string data to be drawn. | 458 // Logical UTF-16 string data to be drawn. |
457 string16 text_; | 459 string16 text_; |
458 | 460 |
459 // Horizontal alignment of the text with respect to |display_rect_|. | 461 // Horizontal alignment of the text with respect to |display_rect_|. |
460 HorizontalAlignment horizontal_alignment_; | 462 HorizontalAlignment horizontal_alignment_; |
461 | 463 |
462 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. | 464 // The text directionality mode, defaults to DIRECTIONALITY_FROM_TEXT. |
463 DirectionalityMode directionality_mode_; | 465 DirectionalityMode directionality_mode_; |
464 | 466 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 | 545 |
544 // Text shadows to be drawn. | 546 // Text shadows to be drawn. |
545 ShadowValues text_shadows_; | 547 ShadowValues text_shadows_; |
546 | 548 |
547 DISALLOW_COPY_AND_ASSIGN(RenderText); | 549 DISALLOW_COPY_AND_ASSIGN(RenderText); |
548 }; | 550 }; |
549 | 551 |
550 } // namespace gfx | 552 } // namespace gfx |
551 | 553 |
552 #endif // UI_GFX_RENDER_TEXT_H_ | 554 #endif // UI_GFX_RENDER_TEXT_H_ |
OLD | NEW |