| 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 | 18 |
| 19 namespace gfx { | 19 namespace gfx { |
| 20 | 20 |
| 21 class Rect; | 21 class Rect; |
| 22 class Font; | 22 class Font; |
| 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()|, |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // that will later be blended with another image. | 89 // that will later be blended with another image. |
| 89 NO_SUBPIXEL_RENDERING = 1 << 10, | 90 NO_SUBPIXEL_RENDERING = 1 << 10, |
| 90 }; | 91 }; |
| 91 | 92 |
| 92 // Creates an empty canvas with scale factor of 1x. | 93 // Creates an empty canvas with scale factor of 1x. |
| 93 Canvas(); | 94 Canvas(); |
| 94 | 95 |
| 95 // Creates canvas with provided DIP |size| and |scale_factor|. | 96 // Creates canvas with provided DIP |size| and |scale_factor|. |
| 96 // If this canvas is not opaque, it's explicitly cleared to transparent before | 97 // If this canvas is not opaque, it's explicitly cleared to transparent before |
| 97 // being returned. | 98 // being returned. |
| 98 Canvas(const gfx::Size& size, | 99 Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque); |
| 99 ui::ScaleFactor scale_factor, | |
| 100 bool is_opaque); | |
| 101 | 100 |
| 102 // Constructs a canvas with the size and the scale factor of the | 101 // Constructs a canvas with the size and the scale factor of the |
| 103 // provided |image_rep|, and draws the |image_rep| into it. | 102 // provided |image_rep|, and draws the |image_rep| into it. |
| 104 Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque); | 103 Canvas(const ImageSkiaRep& image_rep, bool is_opaque); |
| 105 | 104 |
| 106 virtual ~Canvas(); | 105 virtual ~Canvas(); |
| 107 | 106 |
| 108 // Creates a gfx::Canvas backed by an |sk_canvas| with |scale_factor|. | 107 // Creates a Canvas backed by an |sk_canvas| with |scale_factor|. |
| 109 // |sk_canvas| is assumed to be already scaled based on |scale_factor| | 108 // |sk_canvas| is assumed to be already scaled based on |scale_factor| |
| 110 // so no additional scaling is applied. | 109 // so no additional scaling is applied. |
| 111 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas, | 110 static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas, |
| 112 ui::ScaleFactor scale_factor); | 111 ui::ScaleFactor scale_factor); |
| 113 | 112 |
| 114 // Recreates the backing platform canvas with DIP |size| and |scale_factor|. | 113 // Recreates the backing platform canvas with DIP |size| and |scale_factor|. |
| 115 // If the canvas is not opaque, it is explicitly cleared. | 114 // If the canvas is not opaque, it is explicitly cleared. |
| 116 // This method is public so that canvas_skia_paint can recreate the platform | 115 // This method is public so that canvas_skia_paint can recreate the platform |
| 117 // canvas after having initialized the canvas. | 116 // canvas after having initialized the canvas. |
| 118 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that | 117 // TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that |
| 119 // this method can be private. | 118 // this method can be private. |
| 120 void RecreateBackingCanvas(const gfx::Size& size, | 119 void RecreateBackingCanvas(const Size& size, |
| 121 ui::ScaleFactor scale_factor, | 120 ui::ScaleFactor scale_factor, |
| 122 bool is_opaque); | 121 bool is_opaque); |
| 123 | 122 |
| 124 // Compute the size required to draw some text with the provided font. | 123 // Compute the size required to draw some text with the provided fonts. |
| 125 // Attempts to fit the text with the provided width and height. Increases | 124 // Attempts to fit the text with the provided width and height. Increases |
| 126 // height and then width as needed to make the text fit. This method | 125 // height and then width as needed to make the text fit. This method |
| 127 // supports multiple lines. On Skia only a line_height can be specified and | 126 // supports multiple lines. On Skia only a line_height can be specified and |
| 128 // specifying a 0 value for it will cause the default height to be used. | 127 // specifying a 0 value for it will cause the default height to be used. |
| 129 static void SizeStringInt(const base::string16& text, | 128 static void SizeStringInt(const base::string16& text, |
| 130 const gfx::Font& font, | 129 const FontList& font_list, |
| 131 int* width, int* height, | 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, |
| 132 int line_height, | 139 int line_height, |
| 133 int flags); | 140 int flags); |
| 134 | 141 |
| 135 // Returns the number of horizontal pixels needed to display the specified | 142 // Returns the number of horizontal pixels needed to display the specified |
| 136 // |text| with |font|. | 143 // |text| with |font_list|. |
| 137 static int GetStringWidth(const base::string16& text, const gfx::Font& font); | 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); |
| 138 | 148 |
| 139 // Returns the default text alignment to be used when drawing text on a | 149 // Returns the default text alignment to be used when drawing text on a |
| 140 // gfx::Canvas based on the directionality of the system locale language. | 150 // Canvas based on the directionality of the system locale language. |
| 141 // This function is used by gfx::Canvas::DrawStringInt when the text alignment | 151 // This function is used by Canvas::DrawStringInt when the text alignment |
| 142 // is not specified. | 152 // is not specified. |
| 143 // | 153 // |
| 144 // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or | 154 // This function returns either Canvas::TEXT_ALIGN_LEFT or |
| 145 // gfx::Canvas::TEXT_ALIGN_RIGHT. | 155 // Canvas::TEXT_ALIGN_RIGHT. |
| 146 static int DefaultCanvasTextAlignment(); | 156 static int DefaultCanvasTextAlignment(); |
| 147 | 157 |
| 148 // Draws text with a 1-pixel halo around it of the given color. | 158 // Draws text with a 1-pixel halo around it of the given color. |
| 149 // On Windows, it allows ClearType to be drawn to an otherwise transparenct | 159 // On Windows, it allows ClearType to be drawn to an otherwise transparent |
| 150 // bitmap for drag images. Drag images have only 1-bit of transparency, so | 160 // bitmap for drag images. Drag images have only 1-bit of transparency, so |
| 151 // we don't do any fancy blurring. | 161 // we don't do any fancy blurring. |
| 152 // On Linux, text with halo is created by stroking it with 2px |halo_color| | 162 // On Linux, text with halo is created by stroking it with 2px |halo_color| |
| 153 // then filling it with |text_color|. | 163 // then filling it with |text_color|. |
| 154 // On Mac, NOTIMPLEMENTED. | 164 // On Mac, NOTIMPLEMENTED. |
| 155 // TODO(dhollowa): Skia-native implementation is underway. Cut over to | 165 // TODO(dhollowa): Skia-native implementation is underway. Cut over to |
| 156 // that when ready. http::/crbug.com/109946 | 166 // that when ready. http::/crbug.com/109946 |
| 167 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. |
| 157 void DrawStringWithHalo(const base::string16& text, | 174 void DrawStringWithHalo(const base::string16& text, |
| 158 const gfx::Font& font, | 175 const Font& font, |
| 159 SkColor text_color, | 176 SkColor text_color, |
| 160 SkColor halo_color, | 177 SkColor halo_color, |
| 161 int x, int y, int w, int h, | 178 int x, |
| 179 int y, |
| 180 int w, |
| 181 int h, |
| 162 int flags); | 182 int flags); |
| 163 | 183 |
| 164 // Extracts an ImageSkiaRep from the contents of this canvas. | 184 // Extracts an ImageSkiaRep from the contents of this canvas. |
| 165 gfx::ImageSkiaRep ExtractImageRep() const; | 185 ImageSkiaRep ExtractImageRep() const; |
| 166 | 186 |
| 167 // Draws a dashed rectangle of the specified color. | 187 // Draws a dashed rectangle of the specified color. |
| 168 void DrawDashedRect(const gfx::Rect& rect, SkColor color); | 188 void DrawDashedRect(const Rect& rect, SkColor color); |
| 169 | 189 |
| 170 // Saves a copy of the drawing state onto a stack, operating on this copy | 190 // Saves a copy of the drawing state onto a stack, operating on this copy |
| 171 // until a balanced call to Restore() is made. | 191 // until a balanced call to Restore() is made. |
| 172 void Save(); | 192 void Save(); |
| 173 | 193 |
| 174 // As with Save(), except draws to a layer that is blended with the canvas | 194 // As with Save(), except draws to a layer that is blended with the canvas |
| 175 // at the specified alpha once Restore() is called. | 195 // at the specified alpha once Restore() is called. |
| 176 // |layer_bounds| are the bounds of the layer relative to the current | 196 // |layer_bounds| are the bounds of the layer relative to the current |
| 177 // transform. | 197 // transform. |
| 178 void SaveLayerAlpha(uint8 alpha); | 198 void SaveLayerAlpha(uint8 alpha); |
| 179 void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); | 199 void SaveLayerAlpha(uint8 alpha, const Rect& layer_bounds); |
| 180 | 200 |
| 181 // Restores the drawing state after a call to Save*(). It is an error to | 201 // Restores the drawing state after a call to Save*(). It is an error to |
| 182 // call Restore() more times than Save*(). | 202 // call Restore() more times than Save*(). |
| 183 void Restore(); | 203 void Restore(); |
| 184 | 204 |
| 185 // Adds |rect| to the current clip. Returns true if the resulting clip is | 205 // Adds |rect| to the current clip. Returns true if the resulting clip is |
| 186 // non-empty. | 206 // non-empty. |
| 187 bool ClipRect(const gfx::Rect& rect); | 207 bool ClipRect(const Rect& rect); |
| 188 | 208 |
| 189 // Adds |path| to the current clip. Returns true if the resulting clip is | 209 // Adds |path| to the current clip. Returns true if the resulting clip is |
| 190 // non-empty. | 210 // non-empty. |
| 191 bool ClipPath(const SkPath& path); | 211 bool ClipPath(const SkPath& path); |
| 192 | 212 |
| 193 // Returns the bounds of the current clip (in local coordinates) in the | 213 // Returns the bounds of the current clip (in local coordinates) in the |
| 194 // |bounds| parameter, and returns true if it is non empty. | 214 // |bounds| parameter, and returns true if it is non empty. |
| 195 bool GetClipBounds(gfx::Rect* bounds); | 215 bool GetClipBounds(Rect* bounds); |
| 196 | 216 |
| 197 void Translate(const gfx::Vector2d& offset); | 217 void Translate(const Vector2d& offset); |
| 198 | 218 |
| 199 void Scale(int x_scale, int y_scale); | 219 void Scale(int x_scale, int y_scale); |
| 200 | 220 |
| 201 // Fills the entire canvas' bitmap (restricted to current clip) with | 221 // Fills the entire canvas' bitmap (restricted to current clip) with |
| 202 // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode. | 222 // specified |color| using a transfer mode of SkXfermode::kSrcOver_Mode. |
| 203 void DrawColor(SkColor color); | 223 void DrawColor(SkColor color); |
| 204 | 224 |
| 205 // Fills the entire canvas' bitmap (restricted to current clip) with | 225 // Fills the entire canvas' bitmap (restricted to current clip) with |
| 206 // specified |color| and |mode|. | 226 // specified |color| and |mode|. |
| 207 void DrawColor(SkColor color, SkXfermode::Mode mode); | 227 void DrawColor(SkColor color, SkXfermode::Mode mode); |
| 208 | 228 |
| 209 // Fills |rect| with |color| using a transfer mode of | 229 // Fills |rect| with |color| using a transfer mode of |
| 210 // SkXfermode::kSrcOver_Mode. | 230 // SkXfermode::kSrcOver_Mode. |
| 211 void FillRect(const gfx::Rect& rect, SkColor color); | 231 void FillRect(const Rect& rect, SkColor color); |
| 212 | 232 |
| 213 // Fills |rect| with the specified |color| and |mode|. | 233 // Fills |rect| with the specified |color| and |mode|. |
| 214 void FillRect(const gfx::Rect& rect, SkColor color, SkXfermode::Mode mode); | 234 void FillRect(const Rect& rect, SkColor color, SkXfermode::Mode mode); |
| 215 | 235 |
| 216 // Draws a single pixel rect in the specified region with the specified | 236 // Draws a single pixel rect in the specified region with the specified |
| 217 // color, using a transfer mode of SkXfermode::kSrcOver_Mode. | 237 // color, using a transfer mode of SkXfermode::kSrcOver_Mode. |
| 218 // | 238 // |
| 219 // NOTE: if you need a single pixel line, use DrawLine. | 239 // NOTE: if you need a single pixel line, use DrawLine. |
| 220 void DrawRect(const gfx::Rect& rect, SkColor color); | 240 void DrawRect(const Rect& rect, SkColor color); |
| 221 | 241 |
| 222 // Draws a single pixel rect in the specified region with the specified | 242 // Draws a single pixel rect in the specified region with the specified |
| 223 // color and transfer mode. | 243 // color and transfer mode. |
| 224 // | 244 // |
| 225 // NOTE: if you need a single pixel line, use DrawLine. | 245 // NOTE: if you need a single pixel line, use DrawLine. |
| 226 void DrawRect(const gfx::Rect& rect, SkColor color, SkXfermode::Mode mode); | 246 void DrawRect(const Rect& rect, SkColor color, SkXfermode::Mode mode); |
| 227 | 247 |
| 228 // Draws the given rectangle with the given |paint| parameters. | 248 // Draws the given rectangle with the given |paint| parameters. |
| 229 void DrawRect(const gfx::Rect& rect, const SkPaint& paint); | 249 void DrawRect(const Rect& rect, const SkPaint& paint); |
| 230 | 250 |
| 231 // Draw the given point with the given |paint| parameters. | 251 // Draw the given point with the given |paint| parameters. |
| 232 void DrawPoint(const gfx::Point& p, const SkPaint& paint); | 252 void DrawPoint(const Point& p, const SkPaint& paint); |
| 233 | 253 |
| 234 // Draws a single pixel line with the specified color. | 254 // Draws a single pixel line with the specified color. |
| 235 void DrawLine(const gfx::Point& p1, const gfx::Point& p2, SkColor color); | 255 void DrawLine(const Point& p1, const Point& p2, SkColor color); |
| 236 | 256 |
| 237 // Draws a line with the given |paint| parameters. | 257 // Draws a line with the given |paint| parameters. |
| 238 void DrawLine(const gfx::Point& p1, | 258 void DrawLine(const Point& p1, const Point& p2, const SkPaint& paint); |
| 239 const gfx::Point& p2, | |
| 240 const SkPaint& paint); | |
| 241 | 259 |
| 242 // Draws a circle with the given |paint| parameters. | 260 // Draws a circle with the given |paint| parameters. |
| 243 void DrawCircle(const gfx::Point& center_point, | 261 void DrawCircle(const Point& center_point, |
| 244 int radius, | 262 int radius, |
| 245 const SkPaint& paint); | 263 const SkPaint& paint); |
| 246 | 264 |
| 247 // Draws the given rectangle with rounded corners of |radius| using the | 265 // Draws the given rectangle with rounded corners of |radius| using the |
| 248 // given |paint| parameters. | 266 // given |paint| parameters. |
| 249 void DrawRoundRect(const gfx::Rect& rect, int radius, const SkPaint& paint); | 267 void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint); |
| 250 | 268 |
| 251 // Draws the given path using the given |paint| parameters. | 269 // Draws the given path using the given |paint| parameters. |
| 252 void DrawPath(const SkPath& path, const SkPaint& paint); | 270 void DrawPath(const SkPath& path, const SkPaint& paint); |
| 253 | 271 |
| 254 // Draws an image with the origin at the specified location. The upper left | 272 // Draws an image with the origin at the specified location. The upper left |
| 255 // corner of the bitmap is rendered at the specified location. | 273 // corner of the bitmap is rendered at the specified location. |
| 256 // Parameters are specified relative to current canvas scale not in pixels. | 274 // Parameters are specified relative to current canvas scale not in pixels. |
| 257 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. | 275 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
| 258 void DrawImageInt(const gfx::ImageSkia&, int x, int y); | 276 void DrawImageInt(const ImageSkia&, int x, int y); |
| 259 | 277 |
| 260 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and | 278 // Helper for DrawImageInt(..., paint) that constructs a temporary paint and |
| 261 // calls paint.setAlpha(alpha). | 279 // calls paint.setAlpha(alpha). |
| 262 void DrawImageInt(const gfx::ImageSkia&, int x, int y, uint8 alpha); | 280 void DrawImageInt(const ImageSkia&, int x, int y, uint8 alpha); |
| 263 | 281 |
| 264 // Draws an image with the origin at the specified location, using the | 282 // Draws an image with the origin at the specified location, using the |
| 265 // specified paint. The upper left corner of the bitmap is rendered at the | 283 // specified paint. The upper left corner of the bitmap is rendered at the |
| 266 // specified location. | 284 // specified location. |
| 267 // Parameters are specified relative to current canvas scale not in pixels. | 285 // Parameters are specified relative to current canvas scale not in pixels. |
| 268 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. | 286 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
| 269 void DrawImageInt(const gfx::ImageSkia& image, | 287 void DrawImageInt(const ImageSkia& image, |
| 270 int x, int y, | 288 int x, |
| 289 int y, |
| 271 const SkPaint& paint); | 290 const SkPaint& paint); |
| 272 | 291 |
| 273 // Draws a portion of an image in the specified location. The src parameters | 292 // Draws a portion of an image in the specified location. The src parameters |
| 274 // correspond to the region of the bitmap to draw in the region defined | 293 // correspond to the region of the bitmap to draw in the region defined |
| 275 // by the dest coordinates. | 294 // by the dest coordinates. |
| 276 // | 295 // |
| 277 // If the width or height of the source differs from that of the destination, | 296 // If the width or height of the source differs from that of the destination, |
| 278 // the image will be scaled. When scaling down, a mipmap will be generated. | 297 // the image will be scaled. When scaling down, a mipmap will be generated. |
| 279 // Set |filter| to use filtering for images, otherwise the nearest-neighbor | 298 // Set |filter| to use filtering for images, otherwise the nearest-neighbor |
| 280 // algorithm is used for resampling. | 299 // algorithm is used for resampling. |
| 281 // | 300 // |
| 282 // An optional custom SkPaint can be provided. | 301 // An optional custom SkPaint can be provided. |
| 283 // Parameters are specified relative to current canvas scale not in pixels. | 302 // Parameters are specified relative to current canvas scale not in pixels. |
| 284 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. | 303 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
| 285 void DrawImageInt(const gfx::ImageSkia& image, | 304 void DrawImageInt(const ImageSkia& image, |
| 286 int src_x, int src_y, int src_w, int src_h, | 305 int src_x, |
| 287 int dest_x, int dest_y, int dest_w, int dest_h, | 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, |
| 288 bool filter); | 313 bool filter); |
| 289 void DrawImageInt(const gfx::ImageSkia& image, | 314 void DrawImageInt(const ImageSkia& image, |
| 290 int src_x, int src_y, int src_w, int src_h, | 315 int src_x, |
| 291 int dest_x, int dest_y, int dest_w, int dest_h, | 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, |
| 292 bool filter, | 323 bool filter, |
| 293 const SkPaint& paint); | 324 const SkPaint& paint); |
| 294 | 325 |
| 295 // Draws an |image| with the top left corner at |x| and |y|, clipped to | 326 // Draws an |image| with the top left corner at |x| and |y|, clipped to |
| 296 // |path|. | 327 // |path|. |
| 297 // Parameters are specified relative to current canvas scale not in pixels. | 328 // Parameters are specified relative to current canvas scale not in pixels. |
| 298 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. | 329 // Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
| 299 void DrawImageInPath(const gfx::ImageSkia& image, | 330 void DrawImageInPath(const ImageSkia& image, |
| 300 int x, | 331 int x, |
| 301 int y, | 332 int y, |
| 302 const SkPath& path, | 333 const SkPath& path, |
| 303 const SkPaint& paint); | 334 const SkPaint& paint); |
| 304 | 335 |
| 305 // Draws text with the specified color, font and location. The text is | 336 // Draws text with the specified color, fonts and location. The text is |
| 306 // aligned to the left, vertically centered, clipped to the region. If the | 337 // aligned to the left, vertically centered, clipped to the region. If the |
| 307 // text is too big, it is truncated and '...' is added to the end. | 338 // text is too big, it is truncated and '...' is added to the end. |
| 339 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. |
| 308 void DrawStringInt(const base::string16& text, | 344 void DrawStringInt(const base::string16& text, |
| 309 const gfx::Font& font, | 345 const Font& font, |
| 310 SkColor color, | 346 SkColor color, |
| 311 int x, int y, int w, int h); | 347 int x, |
| 348 int y, |
| 349 int w, |
| 350 int h); |
| 312 void DrawStringInt(const base::string16& text, | 351 void DrawStringInt(const base::string16& text, |
| 313 const gfx::Font& font, | 352 const Font& font, |
| 314 SkColor color, | 353 SkColor color, |
| 315 const gfx::Rect& display_rect); | 354 const Rect& display_rect); |
| 316 | 355 |
| 317 // Draws text with the specified color, font and location. The last argument | 356 // Draws text with the specified color, fonts and location. The last argument |
| 318 // specifies flags for how the text should be rendered. It can be one of | 357 // specifies flags for how the text should be rendered. It can be one of |
| 319 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. | 358 // TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. |
| 359 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. |
| 320 void DrawStringInt(const base::string16& text, | 365 void DrawStringInt(const base::string16& text, |
| 321 const gfx::Font& font, | 366 const Font& font, |
| 322 SkColor color, | 367 SkColor color, |
| 323 int x, int y, int w, int h, | 368 int x, |
| 369 int y, |
| 370 int w, |
| 371 int h, |
| 324 int flags); | 372 int flags); |
| 325 | 373 |
| 326 // Similar to above DrawStringInt method but with text shadows support. | 374 // Similar to above DrawStringInt method but with text shadows support. |
| 327 // Currently it's only implemented for canvas skia. Specifying a 0 line_height | 375 // Currently it's only implemented for canvas skia. Specifying a 0 line_height |
| 328 // will cause the default height to be used. | 376 // will cause the default height to be used. |
| 377 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. |
| 329 void DrawStringWithShadows(const base::string16& text, | 385 void DrawStringWithShadows(const base::string16& text, |
| 330 const gfx::Font& font, | 386 const Font& font, |
| 331 SkColor color, | 387 SkColor color, |
| 332 const gfx::Rect& text_bounds, | 388 const Rect& text_bounds, |
| 333 int line_height, | 389 int line_height, |
| 334 int flags, | 390 int flags, |
| 335 const ShadowValues& shadows); | 391 const ShadowValues& shadows); |
| 336 | 392 |
| 337 // Draws a dotted gray rectangle used for focus purposes. | 393 // Draws a dotted gray rectangle used for focus purposes. |
| 338 void DrawFocusRect(const gfx::Rect& rect); | 394 void DrawFocusRect(const Rect& rect); |
| 339 | 395 |
| 340 // Tiles the image in the specified region. | 396 // Tiles the image in the specified region. |
| 341 // Parameters are specified relative to current canvas scale not in pixels. | 397 // Parameters are specified relative to current canvas scale not in pixels. |
| 342 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. | 398 // Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
| 343 void TileImageInt(const gfx::ImageSkia& image, | 399 void TileImageInt(const ImageSkia& image, |
| 344 int x, int y, int w, int h); | 400 int x, |
| 345 void TileImageInt(const gfx::ImageSkia& image, | 401 int y, |
| 346 int src_x, int src_y, | 402 int w, |
| 347 int dest_x, int dest_y, int w, int h); | 403 int h); |
| 348 void TileImageInt(const gfx::ImageSkia& image, | 404 void TileImageInt(const ImageSkia& image, |
| 349 int src_x, int src_y, | 405 int src_x, |
| 350 float tile_scale_x, float tile_scale_y, | 406 int src_y, |
| 351 int dest_x, int dest_y, int w, int h); | 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); |
| 352 | 420 |
| 353 // Returns a native drawing context for platform specific drawing routines to | 421 // Returns a native drawing context for platform specific drawing routines to |
| 354 // use. Must be balanced by a call to EndPlatformPaint(). | 422 // use. Must be balanced by a call to EndPlatformPaint(). |
| 355 NativeDrawingContext BeginPlatformPaint(); | 423 NativeDrawingContext BeginPlatformPaint(); |
| 356 | 424 |
| 357 // Signifies the end of platform drawing using the native drawing context | 425 // Signifies the end of platform drawing using the native drawing context |
| 358 // returned by BeginPlatformPaint(). | 426 // returned by BeginPlatformPaint(). |
| 359 void EndPlatformPaint(); | 427 void EndPlatformPaint(); |
| 360 | 428 |
| 361 // Apply transformation on the canvas. | 429 // Apply transformation on the canvas. |
| 362 void Transform(const gfx::Transform& transform); | 430 void Transform(const Transform& transform); |
| 363 | 431 |
| 364 // Draws the given string with the beginning and/or the end using a fade | 432 // Draws the given string with the beginning and/or the end using a fade |
| 365 // gradient. When truncating the head | 433 // gradient. When truncating the head |
| 366 // |desired_characters_to_truncate_from_head| specifies the maximum number of | 434 // |desired_characters_to_truncate_from_head| specifies the maximum number of |
| 367 // characters that can be truncated. | 435 // characters that can be truncated. |
| 436 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. |
| 368 void DrawFadeTruncatingString( | 444 void DrawFadeTruncatingString( |
| 369 const base::string16& text, | 445 const base::string16& text, |
| 370 TruncateFadeMode truncate_mode, | 446 TruncateFadeMode truncate_mode, |
| 371 size_t desired_characters_to_truncate_from_head, | 447 size_t desired_characters_to_truncate_from_head, |
| 372 const gfx::Font& font, | 448 const Font& font, |
| 373 SkColor color, | 449 SkColor color, |
| 374 const gfx::Rect& display_rect); | 450 const Rect& display_rect); |
| 375 | 451 |
| 376 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } | 452 skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } |
| 377 SkCanvas* sk_canvas() const { return canvas_; } | 453 SkCanvas* sk_canvas() const { return canvas_; } |
| 378 ui::ScaleFactor scale_factor() const { return scale_factor_; } | 454 ui::ScaleFactor scale_factor() const { return scale_factor_; } |
| 379 | 455 |
| 380 private: | 456 private: |
| 381 Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor); | 457 Canvas(SkCanvas* canvas, ui::ScaleFactor scale_factor); |
| 382 | 458 |
| 383 // Test whether the provided rectangle intersects the current clip rect. | 459 // Test whether the provided rectangle intersects the current clip rect. |
| 384 bool IntersectsClipRectInt(int x, int y, int w, int h); | 460 bool IntersectsClipRectInt(int x, int y, int w, int h); |
| 385 bool IntersectsClipRect(const gfx::Rect& rect); | 461 bool IntersectsClipRect(const Rect& rect); |
| 386 | 462 |
| 387 // Returns the image rep which best matches the canvas |scale_factor_|. | 463 // Returns the image rep which best matches the canvas |scale_factor_|. |
| 388 // Returns a null image rep if |image| contains no image reps. | 464 // Returns a null image rep if |image| contains no image reps. |
| 389 // Builds mip map for returned image rep if necessary. | 465 // Builds mip map for returned image rep if necessary. |
| 390 // | 466 // |
| 391 // An optional additional user defined scale can be provided. | 467 // An optional additional user defined scale can be provided. |
| 392 const gfx::ImageSkiaRep& GetImageRepToPaint( | 468 const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const; |
| 393 const gfx::ImageSkia& image) const; | 469 const ImageSkiaRep& GetImageRepToPaint( |
| 394 const gfx::ImageSkiaRep& GetImageRepToPaint( | 470 const ImageSkia& image, |
| 395 const gfx::ImageSkia& image, | |
| 396 float user_defined_scale_factor_x, | 471 float user_defined_scale_factor_x, |
| 397 float user_defined_scale_factor_y) const; | 472 float user_defined_scale_factor_y) const; |
| 398 | 473 |
| 399 // The device scale factor at which drawing on this canvas occurs. | 474 // The device scale factor at which drawing on this canvas occurs. |
| 400 // An additional scale can be applied via Canvas::Scale(). However, | 475 // An additional scale can be applied via Canvas::Scale(). However, |
| 401 // Canvas::Scale() does not affect |scale_factor_|. | 476 // Canvas::Scale() does not affect |scale_factor_|. |
| 402 ui::ScaleFactor scale_factor_; | 477 ui::ScaleFactor scale_factor_; |
| 403 | 478 |
| 404 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; | 479 skia::RefPtr<skia::PlatformCanvas> owned_canvas_; |
| 405 SkCanvas* canvas_; | 480 SkCanvas* canvas_; |
| 406 | 481 |
| 407 DISALLOW_COPY_AND_ASSIGN(Canvas); | 482 DISALLOW_COPY_AND_ASSIGN(Canvas); |
| 408 }; | 483 }; |
| 409 | 484 |
| 410 } // namespace gfx | 485 } // namespace gfx |
| 411 | 486 |
| 412 #endif // UI_GFX_CANVAS_H_ | 487 #endif // UI_GFX_CANVAS_H_ |
| OLD | NEW |