| 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 "third_party/skia/include/core/SkRect.h" | 19 #include "third_party/skia/include/core/SkRect.h" |
| 20 #include "ui/base/range/range.h" | 20 #include "ui/base/range/range.h" |
| 21 #include "ui/gfx/font_list.h" | 21 #include "ui/gfx/font_list.h" |
| 22 #include "ui/gfx/point.h" | 22 #include "ui/gfx/point.h" |
| 23 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
| 24 #include "ui/gfx/selection_model.h" | 24 #include "ui/gfx/selection_model.h" |
| 25 #include "ui/gfx/shadow_value.h" | 25 #include "ui/gfx/shadow_value.h" |
| 26 #include "ui/gfx/text_constants.h" | 26 #include "ui/gfx/text_constants.h" |
| 27 #include "ui/gfx/vector2d.h" |
| 27 | 28 |
| 28 class SkCanvas; | 29 class SkCanvas; |
| 29 class SkDrawLooper; | 30 class SkDrawLooper; |
| 30 struct SkPoint; | 31 struct SkPoint; |
| 31 class SkShader; | 32 class SkShader; |
| 32 class SkTypeface; | 33 class SkTypeface; |
| 33 | 34 |
| 34 namespace gfx { | 35 namespace gfx { |
| 35 | 36 |
| 36 class Canvas; | 37 class Canvas; |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 typedef std::pair<Font, ui::Range> FontSpan; | 288 typedef std::pair<Font, ui::Range> FontSpan; |
| 288 // For testing purposes, returns which fonts were chosen for which parts of | 289 // For testing purposes, returns which fonts were chosen for which parts of |
| 289 // the text by returning a vector of Font and Range pairs, where each range | 290 // the text by returning a vector of Font and Range pairs, where each range |
| 290 // specifies the character range for which the corresponding font has been | 291 // specifies the character range for which the corresponding font has been |
| 291 // chosen. | 292 // chosen. |
| 292 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; | 293 virtual std::vector<FontSpan> GetFontSpansForTesting() = 0; |
| 293 | 294 |
| 294 protected: | 295 protected: |
| 295 RenderText(); | 296 RenderText(); |
| 296 | 297 |
| 297 const Point& GetUpdatedDisplayOffset(); | 298 const Vector2d& GetUpdatedDisplayOffset(); |
| 298 | 299 |
| 299 void set_cached_bounds_and_offset_valid(bool valid) { | 300 void set_cached_bounds_and_offset_valid(bool valid) { |
| 300 cached_bounds_and_offset_valid_ = valid; | 301 cached_bounds_and_offset_valid_ = valid; |
| 301 } | 302 } |
| 302 | 303 |
| 303 const StyleRanges& style_ranges() const { return style_ranges_; } | 304 const StyleRanges& style_ranges() const { return style_ranges_; } |
| 304 | 305 |
| 305 // Get the selection model that visually neighbors |position| by |break_type|. | 306 // Get the selection model that visually neighbors |position| by |break_type|. |
| 306 // The returned value represents a cursor/caret position without a selection. | 307 // The returned value represents a cursor/caret position without a selection. |
| 307 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, | 308 SelectionModel GetAdjacentSelectionModel(const SelectionModel& current, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 // Draw the text. | 361 // Draw the text. |
| 361 virtual void DrawVisualText(Canvas* canvas) = 0; | 362 virtual void DrawVisualText(Canvas* canvas) = 0; |
| 362 | 363 |
| 363 // Returns the text used for layout, which may be |obscured_text_|. | 364 // Returns the text used for layout, which may be |obscured_text_|. |
| 364 const string16& GetLayoutText() const; | 365 const string16& GetLayoutText() const; |
| 365 | 366 |
| 366 // Apply composition style (underline) to composition range and selection | 367 // Apply composition style (underline) to composition range and selection |
| 367 // style (foreground) to selection range. | 368 // style (foreground) to selection range. |
| 368 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges); | 369 void ApplyCompositionAndSelectionStyles(StyleRanges* style_ranges); |
| 369 | 370 |
| 370 // Returns the text origin after applying text alignment and display offset. | 371 // Returns the text offset from the origin after applying text alignment and |
| 371 Point GetTextOrigin(); | 372 // display offset. |
| 373 Vector2d GetTextOffset(); |
| 372 | 374 |
| 373 // Convert points from the text space to the view space and back. | 375 // Convert points from the text space to the view space and back. |
| 374 // Handles the display area, display offset, and the application LTR/RTL mode. | 376 // Handles the display area, display offset, and the application LTR/RTL mode. |
| 375 Point ToTextPoint(const Point& point); | 377 Point ToTextPoint(const Point& point); |
| 376 Point ToViewPoint(const Point& point); | 378 Point ToViewPoint(const Point& point); |
| 377 | 379 |
| 378 // Returns the width of content, which reserves room for the cursor if | 380 // Returns the width of content, which reserves room for the cursor if |
| 379 // |cursor_enabled_| is true. | 381 // |cursor_enabled_| is true. |
| 380 int GetContentWidth(); | 382 int GetContentWidth(); |
| 381 | 383 |
| 382 // Returns display offset based on current text alignment. | 384 // Returns display offset based on current text alignment. |
| 383 Point GetAlignmentOffset(); | 385 Vector2d GetAlignmentOffset(); |
| 384 | 386 |
| 385 // Returns the origin point for drawing text. Does not account for font | 387 // Returns the origin point for drawing text. Does not account for font |
| 386 // baseline, as needed by Skia. | 388 // baseline, as needed by Skia. |
| 387 Point GetOriginForDrawing(); | 389 Point GetOriginForDrawing(); |
| 388 | 390 |
| 389 // Applies fade effects to |renderer|. | 391 // Applies fade effects to |renderer|. |
| 390 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); | 392 void ApplyFadeEffects(internal::SkiaTextRenderer* renderer); |
| 391 | 393 |
| 392 // Applies text shadows to |renderer|. | 394 // Applies text shadows to |renderer|. |
| 393 void ApplyTextShadows(internal::SkiaTextRenderer* renderer); | 395 void ApplyTextShadows(internal::SkiaTextRenderer* renderer); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 Rect display_rect_; | 499 Rect display_rect_; |
| 498 | 500 |
| 499 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) | 501 // Flag to work around a Skia bug with the PDF path (http://crbug.com/133548) |
| 500 // that results in incorrect clipping when drawing to the document margins. | 502 // that results in incorrect clipping when drawing to the document margins. |
| 501 // This field allows disabling clipping to work around the issue. | 503 // This field allows disabling clipping to work around the issue. |
| 502 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. | 504 // TODO(asvitkine): Remove this when the underlying Skia bug is fixed. |
| 503 bool clip_to_display_rect_; | 505 bool clip_to_display_rect_; |
| 504 | 506 |
| 505 // The offset for the text to be drawn, relative to the display area. | 507 // The offset for the text to be drawn, relative to the display area. |
| 506 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). | 508 // Get this point with GetUpdatedDisplayOffset (or risk using a stale value). |
| 507 Point display_offset_; | 509 Vector2d display_offset_; |
| 508 | 510 |
| 509 // The cached bounds and offset are invalidated by changes to the cursor, | 511 // The cached bounds and offset are invalidated by changes to the cursor, |
| 510 // selection, font, and other operations that adjust the visible text bounds. | 512 // selection, font, and other operations that adjust the visible text bounds. |
| 511 bool cached_bounds_and_offset_valid_; | 513 bool cached_bounds_and_offset_valid_; |
| 512 | 514 |
| 513 // Text shadows to be drawn. | 515 // Text shadows to be drawn. |
| 514 ShadowValues text_shadows_; | 516 ShadowValues text_shadows_; |
| 515 | 517 |
| 516 DISALLOW_COPY_AND_ASSIGN(RenderText); | 518 DISALLOW_COPY_AND_ASSIGN(RenderText); |
| 517 }; | 519 }; |
| 518 | 520 |
| 519 } // namespace gfx | 521 } // namespace gfx |
| 520 | 522 |
| 521 #endif // UI_GFX_RENDER_TEXT_H_ | 523 #endif // UI_GFX_RENDER_TEXT_H_ |
| OLD | NEW |