Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(116)

Side by Side Diff: gfx/canvas.h

Issue 2862025: Canvas refactoring part 2.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/webplugin_delegate_proxy.cc ('k') | gfx/canvas.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef GFX_CANVAS_H_
6 #define GFX_CANVAS_H_
7
8 #include "base/basictypes.h"
9 #include "gfx/canvas_2.h"
10 #include "skia/ext/platform_canvas.h"
11
12 #if defined(OS_POSIX) && !defined(OS_MACOSX)
13 typedef struct _GdkPixbuf GdkPixbuf;
14 #endif
15
16 namespace gfx {
17
18 // Canvas is a SkCanvas subclass that provides a number of methods for common
19 // operations used throughout an application built using base/gfx and app/gfx.
20 //
21 // All methods that take integer arguments (as is used throughout views)
22 // end with Int. If you need to use methods provided by the superclass
23 // you'll need to do a conversion. In particular you'll need to use
24 // macro SkIntToScalar(xxx), or if converting from a scalar to an integer
25 // SkScalarRound.
26 //
27 // A handful of methods in this class are overloaded providing an additional
28 // argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the
29 // source and destination colors are combined. Unless otherwise specified,
30 // the variant that does not take a SkXfermode::Mode uses a transfer mode
31 // of kSrcOver_Mode.
32 class Canvas : public skia::PlatformCanvas,
33 public Canvas2 {
34 public:
35 // Creates an empty Canvas. Callers must use initialize before using the
36 // canvas.
37 Canvas();
38
39 Canvas(int width, int height, bool is_opaque);
40
41 virtual ~Canvas();
42
43 // Compute the size required to draw some text with the provided font.
44 // Attempts to fit the text with the provided width and height. Increases
45 // height and then width as needed to make the text fit. This method
46 // supports multiple lines.
47 static void SizeStringInt(const std::wstring& text, const gfx::Font& font,
48 int* width, int* height, int flags);
49
50 // Returns the default text alignment to be used when drawing text on a
51 // gfx::Canvas based on the directionality of the system locale language. This
52 // function is used by gfx::Canvas::DrawStringInt when the text alignment is
53 // not specified.
54 //
55 // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or
56 // gfx::Canvas::TEXT_ALIGN_RIGHT.
57 static int DefaultCanvasTextAlignment();
58
59 #if defined(OS_POSIX) && !defined(OS_MACOSX)
60 // Draw the pixbuf in its natural size at (x, y).
61 void DrawGdkPixbuf(GdkPixbuf* pixbuf, int x, int y);
62 #endif
63
64 #ifdef OS_WIN // Only implemented on Windows for now.
65 // Draws text with a 1-pixel halo around it of the given color. It allows
66 // ClearType to be drawn to an otherwise transparenct bitmap for drag images.
67 // Drag images have only 1-bit of transparency, so we don't do any fancy
68 // blurring.
69 void DrawStringWithHalo(const std::wstring& text,
70 const gfx::Font& font,
71 const SkColor& text_color,
72 const SkColor& halo_color,
73 int x, int y, int w, int h, int flags);
74 #endif
75
76 // Overridden from Canvas2:
77 virtual bool GetClipRect(gfx::Rect* clip_rect);
78 virtual bool ClipRectInt(int x, int y, int w, int h);
79 virtual bool IntersectsClipRectInt(int x, int y, int w, int h);
80 virtual void TranslateInt(int x, int y);
81 virtual void ScaleInt(int x, int y);
82 virtual void FillRectInt(int x, int y, int w, int h,
83 const SkPaint& paint);
84 virtual void FillRectInt(const SkColor& color, int x, int y, int w,
85 int h);
86 virtual void DrawRectInt(const SkColor& color, int x, int y, int w,
87 int h);
88 virtual void DrawRectInt(const SkColor& color, int x, int y, int w, int h,
89 SkXfermode::Mode mode);
90 virtual void DrawLineInt(const SkColor& color, int x1, int y1, int x2,
91 int y2);
92 virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y);
93 virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y,
94 const SkPaint& paint);
95 virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y,
96 int src_w, int src_h, int dest_x, int dest_y,
97 int dest_w, int dest_h, bool filter);
98 virtual void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y,
99 int src_w, int src_h, int dest_x, int dest_y,
100 int dest_w, int dest_h, bool filter,
101 const SkPaint& paint);
102 virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font,
103 const SkColor& color, int x, int y, int w,
104 int h);
105 virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font,
106 const SkColor& color,
107 const gfx::Rect& display_rect);
108 virtual void DrawStringInt(const std::wstring& text, const gfx::Font& font,
109 const SkColor& color, int x, int y, int w, int h,
110 int flags);
111 virtual void DrawFocusRect(int x, int y, int width, int height);
112 virtual void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h);
113 virtual void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y,
114 int dest_x, int dest_y, int w, int h);
115 virtual SkBitmap ExtractBitmap() const;
116 virtual Canvas* AsCanvas();
117
118 private:
119 #if defined(OS_WIN)
120 // Draws text with the specified color, font and location. The text is
121 // aligned to the left, vertically centered, clipped to the region. If the
122 // text is too big, it is truncated and '...' is added to the end.
123 void DrawStringInt(const std::wstring& text, HFONT font,
124 const SkColor& color, int x, int y, int w, int h,
125 int flags);
126 #endif
127
128 DISALLOW_COPY_AND_ASSIGN(Canvas);
129 };
130
131 } // namespace gfx;
132
133 #endif // GFX_CANVAS_H_
OLDNEW
« no previous file with comments | « chrome/renderer/webplugin_delegate_proxy.cc ('k') | gfx/canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698