blob: d6479cc0b12b54839ba01dd920dc4741c70af2fd [file] [log] [blame]
[email protected]fa8cfb02012-01-13 00:27:411// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]267c03d2011-02-02 23:03:072// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef UI_GFX_CANVAS_H_
6#define UI_GFX_CANVAS_H_
[email protected]267c03d2011-02-02 23:03:077
[email protected]0834e1b12012-04-11 02:23:568#include <vector>
9
[email protected]3127f6632012-03-17 00:14:0610#include "base/basictypes.h"
11#include "base/memory/scoped_ptr.h"
[email protected]f3652ff92013-06-11 13:54:3112#include "base/strings/string16.h"
[email protected]3127f6632012-03-17 00:14:0613#include "skia/ext/platform_canvas.h"
[email protected]3699ae5a2012-12-05 01:00:5414#include "skia/ext/refptr.h"
[email protected]35d53342012-05-16 21:30:1215#include "ui/gfx/image/image_skia.h"
[email protected]3127f6632012-03-17 00:14:0616#include "ui/gfx/native_widget_types.h"
[email protected]25650682012-05-29 23:09:1917#include "ui/gfx/shadow_value.h"
[email protected]3127f6632012-03-17 00:14:0618
[email protected]267c03d2011-02-02 23:03:0719namespace gfx {
20
[email protected]3127f6632012-03-17 00:14:0621class Rect;
22class Font;
[email protected]ad8d9d52013-08-22 07:20:0523class FontList;
[email protected]3127f6632012-03-17 00:14:0624class Point;
25class Size;
[email protected]0f0453e2012-10-14 18:15:3526class Transform;
[email protected]3127f6632012-03-17 00:14:0627
28// Canvas is a SkCanvas wrapper that provides a number of methods for
29// common operations used throughout an application built using ui/gfx.
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 SkCanvas, you'll
33// need to do a conversion. In particular you'll need to use |SkIntToScalar()|,
34// or if converting from a scalar to an integer |SkScalarRound()|.
35//
36// A handful of methods in this class are overloaded providing an additional
37// argument of type SkXfermode::Mode. SkXfermode::Mode specifies how the
38// source and destination colors are combined. Unless otherwise specified,
39// the variant that does not take a SkXfermode::Mode uses a transfer mode
40// of kSrcOver_Mode.
41class UI_EXPORT Canvas {
[email protected]267c03d2011-02-02 23:03:0742 public:
[email protected]3127f6632012-03-17 00:14:0643 enum TruncateFadeMode {
44 TruncateFadeTail,
45 TruncateFadeHead,
46 TruncateFadeHeadAndTail,
47 };
48
49 // Specifies the alignment for text rendered with the DrawStringInt method.
50 enum {
51 TEXT_ALIGN_LEFT = 1 << 0,
52 TEXT_ALIGN_CENTER = 1 << 1,
[email protected]ff1af582012-11-06 03:34:1253 TEXT_ALIGN_RIGHT = 1 << 2,
[email protected]3127f6632012-03-17 00:14:0654
55 // Specifies the text consists of multiple lines.
[email protected]ff1af582012-11-06 03:34:1256 MULTI_LINE = 1 << 3,
[email protected]3127f6632012-03-17 00:14:0657
58 // By default DrawStringInt does not process the prefix ('&') character
59 // specially. That is, the string "&foo" is rendered as "&foo". When
60 // rendering text from a resource that uses the prefix character for
61 // mnemonics, the prefix should be processed and can be rendered as an
62 // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX).
[email protected]ff1af582012-11-06 03:34:1263 SHOW_PREFIX = 1 << 4,
64 HIDE_PREFIX = 1 << 5,
[email protected]3127f6632012-03-17 00:14:0665
66 // Prevent ellipsizing
[email protected]ff1af582012-11-06 03:34:1267 NO_ELLIPSIS = 1 << 6,
[email protected]3127f6632012-03-17 00:14:0668
69 // Specifies if words can be split by new lines.
70 // This only works with MULTI_LINE.
[email protected]ff1af582012-11-06 03:34:1271 CHARACTER_BREAK = 1 << 7,
[email protected]3127f6632012-03-17 00:14:0672
73 // Instructs DrawStringInt() to render the text using RTL directionality.
74 // In most cases, passing this flag is not necessary because information
75 // about the text directionality is going to be embedded within the string
76 // in the form of special Unicode characters. However, we don't insert
77 // directionality characters into strings if the locale is LTR because some
78 // platforms (for example, an English Windows XP with no RTL fonts
79 // installed) don't support these characters. Thus, this flag should be
80 // used to render text using RTL directionality when the locale is LTR.
[email protected]ff1af582012-11-06 03:34:1281 FORCE_RTL_DIRECTIONALITY = 1 << 8,
[email protected]3127f6632012-03-17 00:14:0682
83 // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right.
84 // See FORCE_RTL_DIRECTIONALITY for details.
[email protected]ff1af582012-11-06 03:34:1285 FORCE_LTR_DIRECTIONALITY = 1 << 9,
[email protected]3127f6632012-03-17 00:14:0686
87 // Instructs DrawStringInt() to not use subpixel rendering. This is useful
88 // when rendering text onto a fully- or partially-transparent background
89 // that will later be blended with another image.
[email protected]ff1af582012-11-06 03:34:1290 NO_SUBPIXEL_RENDERING = 1 << 10,
[email protected]3127f6632012-03-17 00:14:0691 };
92
[email protected]50b66262013-09-24 03:25:4893 // Creates an empty canvas with image_scale of 1x.
[email protected]94a0d2582012-03-09 00:30:5994 Canvas();
[email protected]267c03d2011-02-02 23:03:0795
[email protected]50b66262013-09-24 03:25:4896 // Creates canvas with provided DIP |size| and |image_scale|.
[email protected]3b2591a2012-06-27 17:58:4197 // If this canvas is not opaque, it's explicitly cleared to transparent before
98 // being returned.
[email protected]50b66262013-09-24 03:25:4899 Canvas(const Size& size, float image_scale, bool is_opaque);
[email protected]3127f6632012-03-17 00:14:06100
[email protected]50b66262013-09-24 03:25:48101 // Constructs a canvas with the size and the image_scale of the provided
102 // |image_rep|, and draws the |image_rep| into it.
[email protected]ad8d9d52013-08-22 07:20:05103 Canvas(const ImageSkiaRep& image_rep, bool is_opaque);
[email protected]3b2591a2012-06-27 17:58:41104
[email protected]57047da2012-07-23 20:55:08105 virtual ~Canvas();
[email protected]f7fc60212012-07-23 20:27:08106
[email protected]50b66262013-09-24 03:25:48107 // Creates a Canvas backed by an |sk_canvas| with |image_scale_|.
108 // |sk_canvas| is assumed to be already scaled based on |image_scale|
[email protected]de13f352012-07-24 16:51:16109 // so no additional scaling is applied.
110 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas,
[email protected]50b66262013-09-24 03:25:48111 float image_scale);
[email protected]de13f352012-07-24 16:51:16112
[email protected]50b66262013-09-24 03:25:48113 // Recreates the backing platform canvas with DIP |size| and |image_scale_|.
[email protected]3b2591a2012-06-27 17:58:41114 // If the canvas is not opaque, it is explicitly cleared.
115 // This method is public so that canvas_skia_paint can recreate the platform
116 // canvas after having initialized the canvas.
[email protected]50b66262013-09-24 03:25:48117 // TODO(pkotwicz): Push the image_scale into skia::PlatformCanvas such that
[email protected]3b2591a2012-06-27 17:58:41118 // this method can be private.
[email protected]ad8d9d52013-08-22 07:20:05119 void RecreateBackingCanvas(const Size& size,
[email protected]50b66262013-09-24 03:25:48120 float image_scale,
[email protected]3b2591a2012-06-27 17:58:41121 bool is_opaque);
122
[email protected]ad8d9d52013-08-22 07:20:05123 // Compute the size required to draw some text with the provided fonts.
[email protected]3127f6632012-03-17 00:14:06124 // Attempts to fit the text with the provided width and height. Increases
125 // height and then width as needed to make the text fit. This method
[email protected]561f7482013-04-19 03:39:58126 // supports multiple lines. On Skia only a line_height can be specified and
127 // specifying a 0 value for it will cause the default height to be used.
[email protected]031ffed2013-06-09 03:32:36128 static void SizeStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05129 const FontList& font_list,
130 int* width,
131 int* height,
132 int line_height,
133 int flags);
134 // Obsolete version. Use the above version which takes FontList.
135 static void SizeStringInt(const base::string16& text,
136 const Font& font,
137 int* width,
138 int* height,
[email protected]561f7482013-04-19 03:39:58139 int line_height,
[email protected]3127f6632012-03-17 00:14:06140 int flags);
141
142 // Returns the number of horizontal pixels needed to display the specified
[email protected]ad8d9d52013-08-22 07:20:05143 // |text| with |font_list|.
144 static int GetStringWidth(const base::string16& text,
145 const FontList& font_list);
146 // Obsolete version. Use the above version which takes FontList.
147 static int GetStringWidth(const base::string16& text, const Font& font);
[email protected]3127f6632012-03-17 00:14:06148
149 // Returns the default text alignment to be used when drawing text on a
[email protected]ad8d9d52013-08-22 07:20:05150 // Canvas based on the directionality of the system locale language.
151 // This function is used by Canvas::DrawStringInt when the text alignment
[email protected]3127f6632012-03-17 00:14:06152 // is not specified.
153 //
[email protected]ad8d9d52013-08-22 07:20:05154 // This function returns either Canvas::TEXT_ALIGN_LEFT or
155 // Canvas::TEXT_ALIGN_RIGHT.
[email protected]3127f6632012-03-17 00:14:06156 static int DefaultCanvasTextAlignment();
157
158 // Draws text with a 1-pixel halo around it of the given color.
[email protected]ad8d9d52013-08-22 07:20:05159 // On Windows, it allows ClearType to be drawn to an otherwise transparent
[email protected]3127f6632012-03-17 00:14:06160 // bitmap for drag images. Drag images have only 1-bit of transparency, so
161 // we don't do any fancy blurring.
162 // On Linux, text with halo is created by stroking it with 2px |halo_color|
163 // then filling it with |text_color|.
164 // On Mac, NOTIMPLEMENTED.
165 // TODO(dhollowa): Skia-native implementation is underway. Cut over to
166 // that when ready. http::/crbug.com/109946
[email protected]ad8d9d52013-08-22 07:20:05167 void DrawStringRectWithHalo(const base::string16& text,
168 const FontList& font_list,
169 SkColor text_color,
170 SkColor halo_color,
171 const Rect& display_rect,
172 int flags);
173 // Obsolete version. Use the above version which takes FontList.
[email protected]031ffed2013-06-09 03:32:36174 void DrawStringWithHalo(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05175 const Font& font,
[email protected]1b81ff22012-03-24 22:04:42176 SkColor text_color,
177 SkColor halo_color,
[email protected]ad8d9d52013-08-22 07:20:05178 int x,
179 int y,
180 int w,
181 int h,
[email protected]3127f6632012-03-17 00:14:06182 int flags);
183
[email protected]3b2591a2012-06-27 17:58:41184 // Extracts an ImageSkiaRep from the contents of this canvas.
[email protected]ad8d9d52013-08-22 07:20:05185 ImageSkiaRep ExtractImageRep() const;
[email protected]3b2591a2012-06-27 17:58:41186
[email protected]3127f6632012-03-17 00:14:06187 // Draws a dashed rectangle of the specified color.
[email protected]ad8d9d52013-08-22 07:20:05188 void DrawDashedRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06189
190 // Saves a copy of the drawing state onto a stack, operating on this copy
191 // until a balanced call to Restore() is made.
192 void Save();
193
194 // As with Save(), except draws to a layer that is blended with the canvas
195 // at the specified alpha once Restore() is called.
196 // |layer_bounds| are the bounds of the layer relative to the current
197 // transform.
198 void SaveLayerAlpha(uint8 alpha);
[email protected]ad8d9d52013-08-22 07:20:05199 void SaveLayerAlpha(uint8 alpha, const Rect& layer_bounds);
[email protected]3127f6632012-03-17 00:14:06200
201 // Restores the drawing state after a call to Save*(). It is an error to
202 // call Restore() more times than Save*().
[email protected]964c429d2012-10-25 15:28:45203 void Restore();
[email protected]3127f6632012-03-17 00:14:06204
[email protected]ffdd1fd2012-04-09 23:24:41205 // Adds |rect| to the current clip. Returns true if the resulting clip is
206 // non-empty.
[email protected]ad8d9d52013-08-22 07:20:05207 bool ClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06208
[email protected]ffdd1fd2012-04-09 23:24:41209 // Adds |path| to the current clip. Returns true if the resulting clip is
210 // non-empty.
211 bool ClipPath(const SkPath& path);
212
213 // Returns the bounds of the current clip (in local coordinates) in the
214 // |bounds| parameter, and returns true if it is non empty.
[email protected]ad8d9d52013-08-22 07:20:05215 bool GetClipBounds(Rect* bounds);
[email protected]ffdd1fd2012-04-09 23:24:41216
[email protected]ad8d9d52013-08-22 07:20:05217 void Translate(const Vector2d& offset);
[email protected]3127f6632012-03-17 00:14:06218
219 void Scale(int x_scale, int y_scale);
220
[email protected]ffdd1fd2012-04-09 23:24:41221 // Fills the entire canvas' bitmap (restricted to current clip) with
222 // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode.
223 void DrawColor(SkColor color);
224
225 // Fills the entire canvas' bitmap (restricted to current clip) with
226 // specified |color| and |mode|.
227 void DrawColor(SkColor color, SkXfermode::Mode mode);
228
[email protected]3127f6632012-03-17 00:14:06229 // Fills |rect| with |color| using a transfer mode of
230 // SkXfermode::kSrcOver_Mode.
[email protected]ad8d9d52013-08-22 07:20:05231 void FillRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06232
233 // Fills |rect| with the specified |color| and |mode|.
[email protected]ad8d9d52013-08-22 07:20:05234 void FillRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06235
[email protected]3127f6632012-03-17 00:14:06236 // Draws a single pixel rect in the specified region with the specified
237 // color, using a transfer mode of SkXfermode::kSrcOver_Mode.
238 //
239 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05240 void DrawRect(const Rect& rect, SkColor color);
[email protected]3127f6632012-03-17 00:14:06241
242 // Draws a single pixel rect in the specified region with the specified
243 // color and transfer mode.
244 //
245 // NOTE: if you need a single pixel line, use DrawLine.
[email protected]ad8d9d52013-08-22 07:20:05246 void DrawRect(const Rect& rect, SkColor color, SkXfermode::Mode mode);
[email protected]3127f6632012-03-17 00:14:06247
[email protected]ffdd1fd2012-04-09 23:24:41248 // Draws the given rectangle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05249 void DrawRect(const Rect& rect, const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06250
[email protected]ffdd1fd2012-04-09 23:24:41251 // Draw the given point with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05252 void DrawPoint(const Point& p, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41253
[email protected]3127f6632012-03-17 00:14:06254 // Draws a single pixel line with the specified color.
[email protected]ad8d9d52013-08-22 07:20:05255 void DrawLine(const Point& p1, const Point& p2, SkColor color);
[email protected]3127f6632012-03-17 00:14:06256
[email protected]ffdd1fd2012-04-09 23:24:41257 // Draws a line with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05258 void DrawLine(const Point& p1, const Point& p2, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41259
260 // Draws a circle with the given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05261 void DrawCircle(const Point& center_point,
[email protected]ffdd1fd2012-04-09 23:24:41262 int radius,
263 const SkPaint& paint);
264
265 // Draws the given rectangle with rounded corners of |radius| using the
266 // given |paint| parameters.
[email protected]ad8d9d52013-08-22 07:20:05267 void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint);
[email protected]ffdd1fd2012-04-09 23:24:41268
269 // Draws the given path using the given |paint| parameters.
270 void DrawPath(const SkPath& path, const SkPaint& paint);
271
[email protected]35d53342012-05-16 21:30:12272 // Draws an image with the origin at the specified location. The upper left
[email protected]3127f6632012-03-17 00:14:06273 // corner of the bitmap is rendered at the specified location.
[email protected]35d53342012-05-16 21:30:12274 // Parameters are specified relative to current canvas scale not in pixels.
[email protected]8232da6b2012-07-02 19:41:15275 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05276 void DrawImageInt(const ImageSkia&, int x, int y);
[email protected]3127f6632012-03-17 00:14:06277
[email protected]2885cb32012-10-03 19:41:11278 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and
279 // calls paint.setAlpha(alpha).
[email protected]ad8d9d52013-08-22 07:20:05280 void DrawImageInt(const ImageSkia&, int x, int y, uint8 alpha);
[email protected]2885cb32012-10-03 19:41:11281
[email protected]35d53342012-05-16 21:30:12282 // Draws an image with the origin at the specified location, using the
[email protected]3127f6632012-03-17 00:14:06283 // specified paint. The upper left corner of the bitmap is rendered at the
284 // specified location.
[email protected]35d53342012-05-16 21:30:12285 // Parameters are specified relative to current canvas scale not in pixels.
286 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05287 void DrawImageInt(const ImageSkia& image,
288 int x,
289 int y,
[email protected]243cac7d2012-06-07 13:29:20290 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06291
[email protected]35d53342012-05-16 21:30:12292 // Draws a portion of an image in the specified location. The src parameters
[email protected]3127f6632012-03-17 00:14:06293 // correspond to the region of the bitmap to draw in the region defined
294 // by the dest coordinates.
295 //
296 // If the width or height of the source differs from that of the destination,
[email protected]35d53342012-05-16 21:30:12297 // the image will be scaled. When scaling down, a mipmap will be generated.
298 // Set |filter| to use filtering for images, otherwise the nearest-neighbor
299 // algorithm is used for resampling.
[email protected]3127f6632012-03-17 00:14:06300 //
301 // An optional custom SkPaint can be provided.
[email protected]35d53342012-05-16 21:30:12302 // Parameters are specified relative to current canvas scale not in pixels.
303 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05304 void DrawImageInt(const ImageSkia& image,
305 int src_x,
306 int src_y,
307 int src_w,
308 int src_h,
309 int dest_x,
310 int dest_y,
311 int dest_w,
312 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20313 bool filter);
[email protected]ad8d9d52013-08-22 07:20:05314 void DrawImageInt(const ImageSkia& image,
315 int src_x,
316 int src_y,
317 int src_w,
318 int src_h,
319 int dest_x,
320 int dest_y,
321 int dest_w,
322 int dest_h,
[email protected]243cac7d2012-06-07 13:29:20323 bool filter,
324 const SkPaint& paint);
[email protected]3127f6632012-03-17 00:14:06325
[email protected]8232da6b2012-07-02 19:41:15326 // Draws an |image| with the top left corner at |x| and |y|, clipped to
327 // |path|.
328 // Parameters are specified relative to current canvas scale not in pixels.
329 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05330 void DrawImageInPath(const ImageSkia& image,
[email protected]8232da6b2012-07-02 19:41:15331 int x,
332 int y,
333 const SkPath& path,
334 const SkPaint& paint);
335
[email protected]ad8d9d52013-08-22 07:20:05336 // Draws text with the specified color, fonts and location. The text is
[email protected]3127f6632012-03-17 00:14:06337 // aligned to the left, vertically centered, clipped to the region. If the
338 // text is too big, it is truncated and '...' is added to the end.
[email protected]ad8d9d52013-08-22 07:20:05339 void DrawStringRect(const base::string16& text,
340 const FontList& font_list,
341 SkColor color,
342 const Rect& display_rect);
343 // Obsolete versions. Use the above versions which take FontList.
[email protected]031ffed2013-06-09 03:32:36344 void DrawStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05345 const Font& font,
[email protected]1b81ff22012-03-24 22:04:42346 SkColor color,
[email protected]ad8d9d52013-08-22 07:20:05347 int x,
348 int y,
349 int w,
350 int h);
[email protected]031ffed2013-06-09 03:32:36351 void DrawStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05352 const Font& font,
[email protected]1b81ff22012-03-24 22:04:42353 SkColor color,
[email protected]ad8d9d52013-08-22 07:20:05354 const Rect& display_rect);
[email protected]3127f6632012-03-17 00:14:06355
[email protected]ad8d9d52013-08-22 07:20:05356 // Draws text with the specified color, fonts and location. The last argument
[email protected]3127f6632012-03-17 00:14:06357 // specifies flags for how the text should be rendered. It can be one of
358 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT.
[email protected]ad8d9d52013-08-22 07:20:05359 void DrawStringRectWithFlags(const base::string16& text,
360 const FontList& font_list,
361 SkColor color,
362 const Rect& display_rect,
363 int flags);
364 // Obsolete version. Use the above version which takes FontList.
[email protected]031ffed2013-06-09 03:32:36365 void DrawStringInt(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05366 const Font& font,
[email protected]1b81ff22012-03-24 22:04:42367 SkColor color,
[email protected]ad8d9d52013-08-22 07:20:05368 int x,
369 int y,
370 int w,
371 int h,
[email protected]3127f6632012-03-17 00:14:06372 int flags);
373
[email protected]0834e1b12012-04-11 02:23:56374 // Similar to above DrawStringInt method but with text shadows support.
[email protected]561f7482013-04-19 03:39:58375 // Currently it's only implemented for canvas skia. Specifying a 0 line_height
376 // will cause the default height to be used.
[email protected]ad8d9d52013-08-22 07:20:05377 void DrawStringRectWithShadows(const base::string16& text,
378 const FontList& font_list,
379 SkColor color,
380 const Rect& text_bounds,
381 int line_height,
382 int flags,
383 const ShadowValues& shadows);
384 // Obsolete version. Use the above version which takes FontList.
[email protected]031ffed2013-06-09 03:32:36385 void DrawStringWithShadows(const base::string16& text,
[email protected]ad8d9d52013-08-22 07:20:05386 const Font& font,
[email protected]0834e1b12012-04-11 02:23:56387 SkColor color,
[email protected]ad8d9d52013-08-22 07:20:05388 const Rect& text_bounds,
[email protected]561f7482013-04-19 03:39:58389 int line_height,
[email protected]0834e1b12012-04-11 02:23:56390 int flags,
[email protected]25650682012-05-29 23:09:19391 const ShadowValues& shadows);
[email protected]0834e1b12012-04-11 02:23:56392
[email protected]3127f6632012-03-17 00:14:06393 // Draws a dotted gray rectangle used for focus purposes.
[email protected]ad8d9d52013-08-22 07:20:05394 void DrawFocusRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06395
396 // Tiles the image in the specified region.
[email protected]35d53342012-05-16 21:30:12397 // Parameters are specified relative to current canvas scale not in pixels.
398 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1.
[email protected]ad8d9d52013-08-22 07:20:05399 void TileImageInt(const ImageSkia& image,
400 int x,
401 int y,
402 int w,
403 int h);
404 void TileImageInt(const ImageSkia& image,
405 int src_x,
406 int src_y,
407 int dest_x,
408 int dest_y,
409 int w,
410 int h);
411 void TileImageInt(const ImageSkia& image,
412 int src_x,
413 int src_y,
414 float tile_scale_x,
415 float tile_scale_y,
416 int dest_x,
417 int dest_y,
418 int w,
419 int h);
[email protected]3127f6632012-03-17 00:14:06420
421 // Returns a native drawing context for platform specific drawing routines to
422 // use. Must be balanced by a call to EndPlatformPaint().
423 NativeDrawingContext BeginPlatformPaint();
424
425 // Signifies the end of platform drawing using the native drawing context
426 // returned by BeginPlatformPaint().
427 void EndPlatformPaint();
428
429 // Apply transformation on the canvas.
[email protected]ad8d9d52013-08-22 07:20:05430 void Transform(const Transform& transform);
[email protected]3127f6632012-03-17 00:14:06431
[email protected]3127f6632012-03-17 00:14:06432 // Draws the given string with the beginning and/or the end using a fade
433 // gradient. When truncating the head
434 // |desired_characters_to_truncate_from_head| specifies the maximum number of
435 // characters that can be truncated.
[email protected]ad8d9d52013-08-22 07:20:05436 void DrawFadeTruncatingStringRect(
437 const base::string16& text,
438 TruncateFadeMode truncate_mode,
439 size_t desired_characters_to_truncate_from_head,
440 const FontList& font_list,
441 SkColor color,
442 const Rect& display_rect);
443 // Obsolete version. Use the above version which takes FontList.
[email protected]3127f6632012-03-17 00:14:06444 void DrawFadeTruncatingString(
[email protected]031ffed2013-06-09 03:32:36445 const base::string16& text,
[email protected]3127f6632012-03-17 00:14:06446 TruncateFadeMode truncate_mode,
447 size_t desired_characters_to_truncate_from_head,
[email protected]ad8d9d52013-08-22 07:20:05448 const Font& font,
[email protected]1b81ff22012-03-24 22:04:42449 SkColor color,
[email protected]ad8d9d52013-08-22 07:20:05450 const Rect& display_rect);
[email protected]3127f6632012-03-17 00:14:06451
452 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); }
453 SkCanvas* sk_canvas() const { return canvas_; }
[email protected]50b66262013-09-24 03:25:48454 float image_scale() const { return image_scale_; }
[email protected]3127f6632012-03-17 00:14:06455
456 private:
[email protected]50b66262013-09-24 03:25:48457 Canvas(SkCanvas* canvas, float image_scale);
[email protected]de13f352012-07-24 16:51:16458
[email protected]3127f6632012-03-17 00:14:06459 // Test whether the provided rectangle intersects the current clip rect.
460 bool IntersectsClipRectInt(int x, int y, int w, int h);
[email protected]ad8d9d52013-08-22 07:20:05461 bool IntersectsClipRect(const Rect& rect);
[email protected]3127f6632012-03-17 00:14:06462
[email protected]50b66262013-09-24 03:25:48463 // Returns the image rep which best matches the canvas |image_scale_|.
[email protected]8232da6b2012-07-02 19:41:15464 // Returns a null image rep if |image| contains no image reps.
465 // Builds mip map for returned image rep if necessary.
[email protected]35d53342012-05-16 21:30:12466 //
467 // An optional additional user defined scale can be provided.
[email protected]ad8d9d52013-08-22 07:20:05468 const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const;
469 const ImageSkiaRep& GetImageRepToPaint(
470 const ImageSkia& image,
[email protected]8232da6b2012-07-02 19:41:15471 float user_defined_scale_factor_x,
[email protected]ad8d9d52013-08-22 07:20:05472 float user_defined_scale_factor_y) const;
[email protected]35d53342012-05-16 21:30:12473
[email protected]3b2591a2012-06-27 17:58:41474 // The device scale factor at which drawing on this canvas occurs.
475 // An additional scale can be applied via Canvas::Scale(). However,
[email protected]50b66262013-09-24 03:25:48476 // Canvas::Scale() does not affect |image_scale_|.
477 float image_scale_;
[email protected]3b2591a2012-06-27 17:58:41478
[email protected]3699ae5a2012-12-05 01:00:54479 skia::RefPtr<skia::PlatformCanvas> owned_canvas_;
[email protected]de13f352012-07-24 16:51:16480 SkCanvas* canvas_;
481
[email protected]3127f6632012-03-17 00:14:06482 DISALLOW_COPY_AND_ASSIGN(Canvas);
[email protected]267c03d2011-02-02 23:03:07483};
484
[email protected]7fe28392011-10-27 00:16:05485} // namespace gfx
[email protected]267c03d2011-02-02 23:03:07486
487#endif // UI_GFX_CANVAS_H_