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

Side by Side Diff: app/gfx/chrome_canvas.h

Issue 113443: ChromeCanvas->gfx::Canvas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 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 | « app/gfx/canvas_win.cc ('k') | app/gfx/chrome_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) 2006-2008 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 APP_GFX_CHROME_CANVAS_H_
6 #define APP_GFX_CHROME_CANVAS_H_
7
8 #if defined(OS_WIN)
9 #include <windows.h>
10 #endif
11
12 #include <string>
13
14 #include "base/basictypes.h"
15 #include "skia/ext/platform_canvas.h"
16
17 namespace gfx {
18 class Font;
19 class Rect;
20 }
21
22 #if defined(OS_LINUX)
23 typedef struct _cairo cairo_t;
24 #endif
25
26 // ChromeCanvas is the SkCanvas used by Views for all painting. It
27 // provides a handful of methods for the common operations used throughout
28 // Views. With few exceptions, you should NOT create a ChromeCanvas directly,
29 // rather one will be passed to you via the various paint methods in view.
30 //
31 // All methods that take integer arguments (as is used throughout views)
32 // end with Int. If you need to use methods provided by the superclass
33 // you'll need to do a conversion. In particular you'll need to use
34 // macro SkIntToScalar(xxx), or if converting from a scalar to an integer
35 // SkScalarRound.
36 //
37 // A handful of methods in this class are overloaded providing an additional
38 // argument of type SkPorterDuff::Mode. SkPorterDuff::Mode specifies how the
39 // source and destination colors are combined. Unless otherwise specified,
40 // the variant that does not take a SkPorterDuff::Mode uses a transfer mode
41 // of kSrcOver_Mode.
42 class ChromeCanvas : public skia::PlatformCanvas {
43 public:
44 // Specifies the alignment for text rendered with the DrawStringInt method.
45 enum {
46 TEXT_ALIGN_LEFT = 1,
47 TEXT_ALIGN_CENTER = 2,
48 TEXT_ALIGN_RIGHT = 4,
49 TEXT_VALIGN_TOP = 8,
50 TEXT_VALIGN_MIDDLE = 16,
51 TEXT_VALIGN_BOTTOM = 32,
52
53 // Specifies the text consists of multiple lines.
54 MULTI_LINE = 64,
55
56 // By default DrawStringInt does not process the prefix ('&') character
57 // specially. That is, the string "&foo" is rendered as "&foo". When
58 // rendering text from a resource that uses the prefix character for
59 // mnemonics, the prefix should be processed and can be rendered as an
60 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX).
61 SHOW_PREFIX = 128,
62 HIDE_PREFIX = 256,
63
64 // Prevent ellipsizing
65 NO_ELLIPSIS = 512,
66
67 // Specifies if words can be split by new lines.
68 // This only works with MULTI_LINE.
69 CHARACTER_BREAK = 1024,
70 };
71
72 // Creates an empty ChromeCanvas. Callers must use initialize before using
73 // the canvas.
74 ChromeCanvas();
75
76 ChromeCanvas(int width, int height, bool is_opaque);
77
78 virtual ~ChromeCanvas();
79
80 // Retrieves the clip rectangle and sets it in the specified rectangle if any.
81 // Returns true if the clip rect is non-empty.
82 bool GetClipRect(gfx::Rect* clip_rect);
83
84 // Wrapper function that takes integer arguments.
85 // Returns true if the clip is non-empty.
86 // See clipRect for specifics.
87 bool ClipRectInt(int x, int y, int w, int h);
88
89 // Test whether the provided rectangle intersects the current clip rect.
90 bool IntersectsClipRectInt(int x, int y, int w, int h);
91
92 // Wrapper function that takes integer arguments.
93 // See translate() for specifics.
94 void TranslateInt(int x, int y);
95
96 // Wrapper function that takes integer arguments.
97 // See scale() for specifics.
98 void ScaleInt(int x, int y);
99
100 // Fills the given rectangle with the given paint's parameters.
101 void FillRectInt(int x, int y, int w, int h, const SkPaint& paint);
102
103 // Fills the specified region with the specified color using a transfer
104 // mode of SkPorterDuff::kSrcOver_Mode.
105 void FillRectInt(const SkColor& color, int x, int y, int w, int h);
106
107 // Draws a single pixel rect in the specified region with the specified
108 // color, using a transfer mode of SkPorterDuff::kSrcOver_Mode.
109 //
110 // NOTE: if you need a single pixel line, use DraLineInt.
111 void DrawRectInt(const SkColor& color, int x, int y, int w, int h);
112
113 // Draws a single pixel rect in the specified region with the specified
114 // color and transfer mode.
115 //
116 // NOTE: if you need a single pixel line, use DraLineInt.
117 void DrawRectInt(const SkColor& color, int x, int y, int w, int h,
118 SkPorterDuff::Mode mode);
119
120 // Draws a single pixel line with the specified color.
121 void DrawLineInt(const SkColor& color, int x1, int y1, int x2, int y2);
122
123 // Draws a bitmap with the origin at the specified location. The upper left
124 // corner of the bitmap is rendered at the specified location.
125 void DrawBitmapInt(const SkBitmap& bitmap, int x, int y);
126
127 // Draws a bitmap with the origin at the specified location, using the
128 // specified paint. The upper left corner of the bitmap is rendered at the
129 // specified location.
130 void DrawBitmapInt(const SkBitmap& bitmap, int x, int y,
131 const SkPaint& paint);
132
133 // Draws a portion of a bitmap in the specified location. The src parameters
134 // correspond to the region of the bitmap to draw in the region defined
135 // by the dest coordinates.
136 //
137 // If the width or height of the source differs from that of the destination,
138 // the bitmap will be scaled. When scaling down, it is highly recommended
139 // that you call buildMipMap(false) on your bitmap to ensure that it has
140 // a mipmap, which will result in much higher-quality output. Set |filter|
141 // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm
142 // is used for resampling.
143 //
144 // An optional custom SkPaint can be provided.
145 void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, int src_w,
146 int src_h, int dest_x, int dest_y, int dest_w, int dest_h,
147 bool filter);
148 void DrawBitmapInt(const SkBitmap& bitmap, int src_x, int src_y, int src_w,
149 int src_h, int dest_x, int dest_y, int dest_w, int dest_h,
150 bool filter, const SkPaint& paint);
151
152 // Draws text with the specified color, font and location. The text is
153 // aligned to the left, vertically centered, clipped to the region. If the
154 // text is too big, it is truncated and '...' is added to the end.
155 void DrawStringInt(const std::wstring& text, const gfx::Font& font,
156 const SkColor& color, int x, int y, int w, int h);
157
158 // Draws text with the specified color, font and location. The last argument
159 // specifies flags for how the text should be rendered. It can be one of
160 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
161 void DrawStringInt(const std::wstring& text, const gfx::Font& font,
162 const SkColor& color, int x, int y, int w, int h,
163 int flags);
164
165 #ifdef OS_WIN // Only implemented on Windows for now.
166 // Draws text with a 1-pixel halo around it of the given color. It allows
167 // ClearType to be drawn to an otherwise transparenct bitmap for drag images.
168 // Drag images have only 1-bit of transparency, so we don't do any fancy
169 // blurring.
170 void DrawStringWithHalo(const std::wstring& text, const gfx::Font& font,
171 const SkColor& text_color, const SkColor& halo_color,
172 int x, int y, int w, int h, int flags);
173 #endif
174
175 // Draws a dotted gray rectangle used for focus purposes.
176 void DrawFocusRect(int x, int y, int width, int height);
177
178 // Tiles the image in the specified region.
179 void TileImageInt(const SkBitmap& bitmap, int x, int y, int w, int h);
180 void TileImageInt(const SkBitmap& bitmap, int src_x, int src_y,
181 int dest_x, int dest_y, int w, int h);
182
183 // Extracts a bitmap from the contents of this canvas.
184 SkBitmap ExtractBitmap();
185
186 #if defined(OS_LINUX)
187 // Applies current matrix on the canvas to the cairo context. This should be
188 // invoked anytime you plan on drawing directly to the cairo context. Be
189 // sure and set the matrix back to the identity when done.
190 void ApplySkiaMatrixToCairoContext(cairo_t* cr);
191 #endif
192
193 // Compute the size required to draw some text with the provided font.
194 // Attempts to fit the text with the provided width and height. Increases
195 // height and then width as needed to make the text fit. This method
196 // supports multiple lines.
197 static void SizeStringInt(const std::wstring& test, const gfx::Font& font,
198 int *width, int* height, int flags);
199
200 private:
201 #if defined(OS_WIN)
202 // Draws text with the specified color, font and location. The text is
203 // aligned to the left, vertically centered, clipped to the region. If the
204 // text is too big, it is truncated and '...' is added to the end.
205 void DrawStringInt(const std::wstring& text, HFONT font,
206 const SkColor& color, int x, int y, int w, int h,
207 int flags);
208 #endif
209
210 DISALLOW_EVIL_CONSTRUCTORS(ChromeCanvas);
211 };
212
213 #if defined(OS_WIN) || defined(OS_LINUX)
214 typedef skia::CanvasPaintT<ChromeCanvas> ChromeCanvasPaint;
215 #endif
216
217 #endif // APP_GFX_CHROME_CANVAS_H_
OLDNEW
« no previous file with comments | « app/gfx/canvas_win.cc ('k') | app/gfx/chrome_canvas.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698