| 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_CANVAS_H_ | 5 #ifndef UI_GFX_CANVAS_H_ |
| 6 #define UI_GFX_CANVAS_H_ | 6 #define UI_GFX_CANVAS_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "skia/ext/platform_canvas.h" | 13 #include "skia/ext/platform_canvas.h" |
| 14 #include "skia/ext/refptr.h" | 14 #include "skia/ext/refptr.h" |
| 15 #include "ui/gfx/image/image_skia.h" | 15 #include "ui/gfx/image/image_skia.h" |
| 16 #include "ui/gfx/native_widget_types.h" | 16 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/gfx/shadow_value.h" | 17 #include "ui/gfx/shadow_value.h" |
| 18 #include "ui/gfx/text_constants.h" |
| 18 | 19 |
| 19 namespace gfx { | 20 namespace gfx { |
| 20 | 21 |
| 21 class Rect; | 22 class Rect; |
| 22 class FontList; | 23 class FontList; |
| 23 class Point; | 24 class Point; |
| 24 class Size; | 25 class Size; |
| 25 class Transform; | 26 class Transform; |
| 26 | 27 |
| 27 // Canvas is a SkCanvas wrapper that provides a number of methods for | 28 // Canvas is a SkCanvas wrapper that provides a number of methods for |
| 28 // common operations used throughout an application built using ui/gfx. | 29 // common operations used throughout an application built using ui/gfx. |
| 29 // | 30 // |
| 30 // All methods that take integer arguments (as is used throughout views) | 31 // All methods that take integer arguments (as is used throughout views) |
| 31 // end with Int. If you need to use methods provided by SkCanvas, you'll | 32 // end with Int. If you need to use methods provided by SkCanvas, you'll |
| 32 // need to do a conversion. In particular you'll need to use |SkIntToScalar()|, | 33 // need to do a conversion. In particular you'll need to use |SkIntToScalar()|, |
| 33 // or if converting from a scalar to an integer |SkScalarRound()|. | 34 // or if converting from a scalar to an integer |SkScalarRound()|. |
| 34 // | 35 // |
| 35 // A handful of methods in this class are overloaded providing an additional | 36 // A handful of methods in this class are overloaded providing an additional |
| 36 // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the | 37 // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the |
| 37 // source and destination colors are combined. Unless otherwise specified, | 38 // source and destination colors are combined. Unless otherwise specified, |
| 38 // the variant that does not take a SkXfermode::Mode uses a transfer mode | 39 // the variant that does not take a SkXfermode::Mode uses a transfer mode |
| 39 // of kSrcOver_Mode. | 40 // of kSrcOver_Mode. |
| 40 class GFX_EXPORT Canvas { | 41 class GFX_EXPORT Canvas { |
| 41 public: | 42 public: |
| 42 enum TruncateFadeMode { | |
| 43 TruncateFadeTail, | |
| 44 TruncateFadeHead, | |
| 45 }; | |
| 46 | |
| 47 // Specifies the alignment for text rendered with the DrawStringRect method. | 43 // Specifies the alignment for text rendered with the DrawStringRect method. |
| 48 enum { | 44 enum { |
| 49 TEXT_ALIGN_LEFT = 1 << 0, | 45 TEXT_ALIGN_LEFT = 1 << 0, |
| 50 TEXT_ALIGN_CENTER = 1 << 1, | 46 TEXT_ALIGN_CENTER = 1 << 1, |
| 51 TEXT_ALIGN_RIGHT = 1 << 2, | 47 TEXT_ALIGN_RIGHT = 1 << 2, |
| 52 | 48 |
| 53 // Specifies the text consists of multiple lines. | 49 // Specifies the text consists of multiple lines. |
| 54 MULTI_LINE = 1 << 3, | 50 MULTI_LINE = 1 << 3, |
| 55 | 51 |
| 56 // By default DrawStringRect does not process the prefix ('&') character | 52 // By default DrawStringRect does not process the prefix ('&') character |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 // use. Must be balanced by a call to EndPlatformPaint(). | 407 // use. Must be balanced by a call to EndPlatformPaint(). |
| 412 NativeDrawingContext BeginPlatformPaint(); | 408 NativeDrawingContext BeginPlatformPaint(); |
| 413 | 409 |
| 414 // Signifies the end of platform drawing using the native drawing context | 410 // Signifies the end of platform drawing using the native drawing context |
| 415 // returned by BeginPlatformPaint(). | 411 // returned by BeginPlatformPaint(). |
| 416 void EndPlatformPaint(); | 412 void EndPlatformPaint(); |
| 417 | 413 |
| 418 // Apply transformation on the canvas. | 414 // Apply transformation on the canvas. |
| 419 void Transform(const Transform& transform); | 415 void Transform(const Transform& transform); |
| 420 | 416 |
| 421 // Draws the given string with the beginning or the end using a fade gradient. | 417 // Draws the given string with a fade gradient at the end. |
| 422 void DrawFadeTruncatingStringRect( | 418 void DrawFadedString(const base::string16& text, |
| 423 const base::string16& text, | 419 const FontList& font_list, |
| 424 TruncateFadeMode truncate_mode, | 420 SkColor color, |
| 425 const FontList& font_list, | 421 const Rect& display_rect, |
| 426 SkColor color, | 422 int flags); |
| 427 const Rect& display_rect); | |
| 428 void DrawFadeTruncatingStringRectWithFlags( | |
| 429 const base::string16& text, | |
| 430 TruncateFadeMode truncate_mode, | |
| 431 const FontList& font_list, | |
| 432 SkColor color, | |
| 433 const Rect& display_rect, | |
| 434 int flags); | |
| 435 | 423 |
| 436 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } | 424 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } |
| 437 SkCanvas* sk_canvas() const { return canvas_; } | 425 SkCanvas* sk_canvas() const { return canvas_; } |
| 438 float image_scale() const { return image_scale_; } | 426 float image_scale() const { return image_scale_; } |
| 439 | 427 |
| 440 private: | 428 private: |
| 441 Canvas(SkCanvas* canvas, float image_scale); | 429 Canvas(SkCanvas* canvas, float image_scale); |
| 442 | 430 |
| 443 // Test whether the provided rectangle intersects the current clip rect. | 431 // Test whether the provided rectangle intersects the current clip rect. |
| 444 bool IntersectsClipRectInt(int x, int y, int w, int h); | 432 bool IntersectsClipRectInt(int x, int y, int w, int h); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 468 | 456 |
| 469 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; | 457 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; |
| 470 SkCanvas* canvas_; | 458 SkCanvas* canvas_; |
| 471 | 459 |
| 472 DISALLOW_COPY_AND_ASSIGN(Canvas); | 460 DISALLOW_COPY_AND_ASSIGN(Canvas); |
| 473 }; | 461 }; |
| 474 | 462 |
| 475 } // namespace gfx | 463 } // namespace gfx |
| 476 | 464 |
| 477 #endif // UI_GFX_CANVAS_H_ | 465 #endif // UI_GFX_CANVAS_H_ |
| OLD | NEW |