Index: ui/gfx/canvas.h |
diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h |
index 8baa45c11e32f7a9b8a167bf5dd9268b7169beb5..c8996a234a85aedfbbb1aa53c64a9806a64badfc 100644 |
--- a/ui/gfx/canvas.h |
+++ b/ui/gfx/canvas.h |
@@ -20,6 +20,7 @@ namespace gfx { |
class Rect; |
class Font; |
+class FontList; |
class Point; |
class Size; |
class Transform; |
@@ -95,17 +96,15 @@ class UI_EXPORT Canvas { |
// Creates canvas with provided DIP |size| and |scale_factor|. |
// If this canvas is not opaque, it's explicitly cleared to transparent before |
// being returned. |
- Canvas(const gfx::Size& size, |
- ui::ScaleFactor scale_factor, |
- bool is_opaque); |
+ Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque); |
// Constructs a canvas with the size and the scale factor of the |
// provided |image_rep|, and draws the |image_rep| into it. |
- Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque); |
+ Canvas(const ImageSkiaRep& image_rep, bool is_opaque); |
virtual ~Canvas(); |
- // Creates a gfx::Canvas backed by an |sk_canvas| with |scale_factor|. |
+ // Creates a Canvas backed by an |sk_canvas| with |scale_factor|. |
// |sk_canvas| is assumed to be already scaled based on |scale_factor| |
// so no additional scaling is applied. |
static Canvas* CreateCanvasWithoutScaling(SkCanvas* sk_canvas, |
@@ -117,36 +116,47 @@ class UI_EXPORT Canvas { |
// canvas after having initialized the canvas. |
// TODO(pkotwicz): Push the scale factor into skia::PlatformCanvas such that |
// this method can be private. |
- void RecreateBackingCanvas(const gfx::Size& size, |
+ void RecreateBackingCanvas(const Size& size, |
ui::ScaleFactor scale_factor, |
bool is_opaque); |
- // Compute the size required to draw some text with the provided font. |
+ // Compute the size required to draw some text with the provided fonts. |
// Attempts to fit the text with the provided width and height. Increases |
// height and then width as needed to make the text fit. This method |
// supports multiple lines. On Skia only a line_height can be specified and |
// specifying a 0 value for it will cause the default height to be used. |
static void SizeStringInt(const base::string16& text, |
- const gfx::Font& font, |
- int* width, int* height, |
+ const FontList& font_list, |
+ int* width, |
+ int* height, |
+ int line_height, |
+ int flags); |
+ // Obsolete version. Use the above version which takes FontList. |
+ static void SizeStringInt(const base::string16& text, |
+ const Font& font, |
+ int* width, |
+ int* height, |
int line_height, |
int flags); |
// Returns the number of horizontal pixels needed to display the specified |
- // |text| with |font|. |
- static int GetStringWidth(const base::string16& text, const gfx::Font& font); |
+ // |text| with |font_list|. |
+ static int GetStringWidth(const base::string16& text, |
+ const FontList& font_list); |
+ // Obsolete version. Use the above version which takes FontList. |
+ static int GetStringWidth(const base::string16& text, const Font& font); |
// Returns the default text alignment to be used when drawing text on a |
- // gfx::Canvas based on the directionality of the system locale language. |
- // This function is used by gfx::Canvas::DrawStringInt when the text alignment |
+ // Canvas based on the directionality of the system locale language. |
+ // This function is used by Canvas::DrawStringInt when the text alignment |
// is not specified. |
// |
- // This function returns either gfx::Canvas::TEXT_ALIGN_LEFT or |
- // gfx::Canvas::TEXT_ALIGN_RIGHT. |
+ // This function returns either Canvas::TEXT_ALIGN_LEFT or |
+ // Canvas::TEXT_ALIGN_RIGHT. |
static int DefaultCanvasTextAlignment(); |
// Draws text with a 1-pixel halo around it of the given color. |
- // On Windows, it allows ClearType to be drawn to an otherwise transparenct |
+ // On Windows, it allows ClearType to be drawn to an otherwise transparent |
// bitmap for drag images. Drag images have only 1-bit of transparency, so |
// we don't do any fancy blurring. |
// On Linux, text with halo is created by stroking it with 2px |halo_color| |
@@ -154,18 +164,28 @@ class UI_EXPORT Canvas { |
// On Mac, NOTIMPLEMENTED. |
// TODO(dhollowa): Skia-native implementation is underway. Cut over to |
// that when ready. http::/crbug.com/109946 |
+ void DrawStringRectWithHalo(const base::string16& text, |
+ const FontList& font_list, |
+ SkColor text_color, |
+ SkColor halo_color, |
+ const Rect& display_rect, |
+ int flags); |
+ // Obsolete version. Use the above version which takes FontList. |
void DrawStringWithHalo(const base::string16& text, |
- const gfx::Font& font, |
+ const Font& font, |
SkColor text_color, |
SkColor halo_color, |
- int x, int y, int w, int h, |
+ int x, |
+ int y, |
+ int w, |
+ int h, |
int flags); |
// Extracts an ImageSkiaRep from the contents of this canvas. |
- gfx::ImageSkiaRep ExtractImageRep() const; |
+ ImageSkiaRep ExtractImageRep() const; |
// Draws a dashed rectangle of the specified color. |
- void DrawDashedRect(const gfx::Rect& rect, SkColor color); |
+ void DrawDashedRect(const Rect& rect, SkColor color); |
// Saves a copy of the drawing state onto a stack, operating on this copy |
// until a balanced call to Restore() is made. |
@@ -176,7 +196,7 @@ class UI_EXPORT Canvas { |
// |layer_bounds| are the bounds of the layer relative to the current |
// transform. |
void SaveLayerAlpha(uint8 alpha); |
- void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds); |
+ void SaveLayerAlpha(uint8 alpha, const Rect& layer_bounds); |
// Restores the drawing state after a call to Save*(). It is an error to |
// call Restore() more times than Save*(). |
@@ -184,7 +204,7 @@ class UI_EXPORT Canvas { |
// Adds |rect| to the current clip. Returns true if the resulting clip is |
// non-empty. |
- bool ClipRect(const gfx::Rect& rect); |
+ bool ClipRect(const Rect& rect); |
// Adds |path| to the current clip. Returns true if the resulting clip is |
// non-empty. |
@@ -192,9 +212,9 @@ class UI_EXPORT Canvas { |
// Returns the bounds of the current clip (in local coordinates) in the |
// |bounds| parameter, and returns true if it is non empty. |
- bool GetClipBounds(gfx::Rect* bounds); |
+ bool GetClipBounds(Rect* bounds); |
- void Translate(const gfx::Vector2d& offset); |
+ void Translate(const Vector2d& offset); |
void Scale(int x_scale, int y_scale); |
@@ -208,45 +228,43 @@ class UI_EXPORT Canvas { |
// Fills |rect| with |color| using a transfer mode of |
// SkXfermode::kSrcOver_Mode. |
- void FillRect(const gfx::Rect& rect, SkColor color); |
+ void FillRect(const Rect& rect, SkColor color); |
// Fills |rect| with the specified |color| and |mode|. |
- void FillRect(const gfx::Rect& rect, SkColor color, SkXfermode::Mode mode); |
+ void FillRect(const Rect& rect, SkColor color, SkXfermode::Mode mode); |
// Draws a single pixel rect in the specified region with the specified |
// color, using a transfer mode of SkXfermode::kSrcOver_Mode. |
// |
// NOTE: if you need a single pixel line, use DrawLine. |
- void DrawRect(const gfx::Rect& rect, SkColor color); |
+ void DrawRect(const Rect& rect, SkColor color); |
// Draws a single pixel rect in the specified region with the specified |
// color and transfer mode. |
// |
// NOTE: if you need a single pixel line, use DrawLine. |
- void DrawRect(const gfx::Rect& rect, SkColor color, SkXfermode::Mode mode); |
+ void DrawRect(const Rect& rect, SkColor color, SkXfermode::Mode mode); |
// Draws the given rectangle with the given |paint| parameters. |
- void DrawRect(const gfx::Rect& rect, const SkPaint& paint); |
+ void DrawRect(const Rect& rect, const SkPaint& paint); |
// Draw the given point with the given |paint| parameters. |
- void DrawPoint(const gfx::Point& p, const SkPaint& paint); |
+ void DrawPoint(const Point& p, const SkPaint& paint); |
// Draws a single pixel line with the specified color. |
- void DrawLine(const gfx::Point& p1, const gfx::Point& p2, SkColor color); |
+ void DrawLine(const Point& p1, const Point& p2, SkColor color); |
// Draws a line with the given |paint| parameters. |
- void DrawLine(const gfx::Point& p1, |
- const gfx::Point& p2, |
- const SkPaint& paint); |
+ void DrawLine(const Point& p1, const Point& p2, const SkPaint& paint); |
// Draws a circle with the given |paint| parameters. |
- void DrawCircle(const gfx::Point& center_point, |
+ void DrawCircle(const Point& center_point, |
int radius, |
const SkPaint& paint); |
// Draws the given rectangle with rounded corners of |radius| using the |
// given |paint| parameters. |
- void DrawRoundRect(const gfx::Rect& rect, int radius, const SkPaint& paint); |
+ void DrawRoundRect(const Rect& rect, int radius, const SkPaint& paint); |
// Draws the given path using the given |paint| parameters. |
void DrawPath(const SkPath& path, const SkPaint& paint); |
@@ -255,19 +273,20 @@ class UI_EXPORT Canvas { |
// corner of the bitmap is rendered at the specified location. |
// Parameters are specified relative to current canvas scale not in pixels. |
// Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
- void DrawImageInt(const gfx::ImageSkia&, int x, int y); |
+ void DrawImageInt(const ImageSkia&, int x, int y); |
// Helper for DrawImageInt(..., paint) that constructs a temporary paint and |
// calls paint.setAlpha(alpha). |
- void DrawImageInt(const gfx::ImageSkia&, int x, int y, uint8 alpha); |
+ void DrawImageInt(const ImageSkia&, int x, int y, uint8 alpha); |
// Draws an image with the origin at the specified location, using the |
// specified paint. The upper left corner of the bitmap is rendered at the |
// specified location. |
// Parameters are specified relative to current canvas scale not in pixels. |
// Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
- void DrawImageInt(const gfx::ImageSkia& image, |
- int x, int y, |
+ void DrawImageInt(const ImageSkia& image, |
+ int x, |
+ int y, |
const SkPaint& paint); |
// Draws a portion of an image in the specified location. The src parameters |
@@ -282,13 +301,25 @@ class UI_EXPORT Canvas { |
// An optional custom SkPaint can be provided. |
// Parameters are specified relative to current canvas scale not in pixels. |
// Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
- void DrawImageInt(const gfx::ImageSkia& image, |
- int src_x, int src_y, int src_w, int src_h, |
- int dest_x, int dest_y, int dest_w, int dest_h, |
+ void DrawImageInt(const ImageSkia& image, |
+ int src_x, |
+ int src_y, |
+ int src_w, |
+ int src_h, |
+ int dest_x, |
+ int dest_y, |
+ int dest_w, |
+ int dest_h, |
bool filter); |
- void DrawImageInt(const gfx::ImageSkia& image, |
- int src_x, int src_y, int src_w, int src_h, |
- int dest_x, int dest_y, int dest_w, int dest_h, |
+ void DrawImageInt(const ImageSkia& image, |
+ int src_x, |
+ int src_y, |
+ int src_w, |
+ int src_h, |
+ int dest_x, |
+ int dest_y, |
+ int dest_w, |
+ int dest_h, |
bool filter, |
const SkPaint& paint); |
@@ -296,59 +327,96 @@ class UI_EXPORT Canvas { |
// |path|. |
// Parameters are specified relative to current canvas scale not in pixels. |
// Thus, x is 2 pixels if canvas scale = 2 & |x| = 1. |
- void DrawImageInPath(const gfx::ImageSkia& image, |
+ void DrawImageInPath(const ImageSkia& image, |
int x, |
int y, |
const SkPath& path, |
const SkPaint& paint); |
- // Draws text with the specified color, font and location. The text is |
+ // Draws text with the specified color, fonts and location. The text is |
// aligned to the left, vertically centered, clipped to the region. If the |
// text is too big, it is truncated and '...' is added to the end. |
+ void DrawStringRect(const base::string16& text, |
+ const FontList& font_list, |
+ SkColor color, |
+ const Rect& display_rect); |
+ // Obsolete versions. Use the above versions which take FontList. |
void DrawStringInt(const base::string16& text, |
- const gfx::Font& font, |
+ const Font& font, |
SkColor color, |
- int x, int y, int w, int h); |
+ int x, |
+ int y, |
+ int w, |
+ int h); |
void DrawStringInt(const base::string16& text, |
- const gfx::Font& font, |
+ const Font& font, |
SkColor color, |
- const gfx::Rect& display_rect); |
+ const Rect& display_rect); |
- // Draws text with the specified color, font and location. The last argument |
+ // Draws text with the specified color, fonts and location. The last argument |
// specifies flags for how the text should be rendered. It can be one of |
// TEXT_ALIGN_CENTER, TEXT_ALIGN_RIGHT or TEXT_ALIGN_LEFT. |
+ void DrawStringRectWithFlags(const base::string16& text, |
+ const FontList& font_list, |
+ SkColor color, |
+ const Rect& display_rect, |
+ int flags); |
+ // Obsolete version. Use the above version which takes FontList. |
void DrawStringInt(const base::string16& text, |
- const gfx::Font& font, |
+ const Font& font, |
SkColor color, |
- int x, int y, int w, int h, |
+ int x, |
+ int y, |
+ int w, |
+ int h, |
int flags); |
// Similar to above DrawStringInt method but with text shadows support. |
// Currently it's only implemented for canvas skia. Specifying a 0 line_height |
// will cause the default height to be used. |
+ void DrawStringRectWithShadows(const base::string16& text, |
+ const FontList& font_list, |
+ SkColor color, |
+ const Rect& text_bounds, |
+ int line_height, |
+ int flags, |
+ const ShadowValues& shadows); |
+ // Obsolete version. Use the above version which takes FontList. |
void DrawStringWithShadows(const base::string16& text, |
- const gfx::Font& font, |
+ const Font& font, |
SkColor color, |
- const gfx::Rect& text_bounds, |
+ const Rect& text_bounds, |
int line_height, |
int flags, |
const ShadowValues& shadows); |
// Draws a dotted gray rectangle used for focus purposes. |
- void DrawFocusRect(const gfx::Rect& rect); |
+ void DrawFocusRect(const Rect& rect); |
// Tiles the image in the specified region. |
// Parameters are specified relative to current canvas scale not in pixels. |
// Thus, |x| is 2 pixels if canvas scale = 2 & |x| = 1. |
- void TileImageInt(const gfx::ImageSkia& image, |
- int x, int y, int w, int h); |
- void TileImageInt(const gfx::ImageSkia& image, |
- int src_x, int src_y, |
- int dest_x, int dest_y, int w, int h); |
- void TileImageInt(const gfx::ImageSkia& image, |
- int src_x, int src_y, |
- float tile_scale_x, float tile_scale_y, |
- int dest_x, int dest_y, int w, int h); |
+ void TileImageInt(const ImageSkia& image, |
+ int x, |
+ int y, |
+ int w, |
+ int h); |
+ void TileImageInt(const ImageSkia& image, |
+ int src_x, |
+ int src_y, |
+ int dest_x, |
+ int dest_y, |
+ int w, |
+ int h); |
+ void TileImageInt(const ImageSkia& image, |
+ int src_x, |
+ int src_y, |
+ float tile_scale_x, |
+ float tile_scale_y, |
+ int dest_x, |
+ int dest_y, |
+ int w, |
+ int h); |
// Returns a native drawing context for platform specific drawing routines to |
// use. Must be balanced by a call to EndPlatformPaint(). |
@@ -359,19 +427,27 @@ class UI_EXPORT Canvas { |
void EndPlatformPaint(); |
// Apply transformation on the canvas. |
- void Transform(const gfx::Transform& transform); |
+ void Transform(const Transform& transform); |
// Draws the given string with the beginning and/or the end using a fade |
// gradient. When truncating the head |
// |desired_characters_to_truncate_from_head| specifies the maximum number of |
// characters that can be truncated. |
+ void DrawFadeTruncatingStringRect( |
+ const base::string16& text, |
+ TruncateFadeMode truncate_mode, |
+ size_t desired_characters_to_truncate_from_head, |
+ const FontList& font_list, |
+ SkColor color, |
+ const Rect& display_rect); |
+ // Obsolete version. Use the above version which takes FontList. |
void DrawFadeTruncatingString( |
const base::string16& text, |
TruncateFadeMode truncate_mode, |
size_t desired_characters_to_truncate_from_head, |
- const gfx::Font& font, |
+ const Font& font, |
SkColor color, |
- const gfx::Rect& display_rect); |
+ const Rect& display_rect); |
skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } |
SkCanvas* sk_canvas() const { return canvas_; } |
@@ -382,19 +458,18 @@ class UI_EXPORT Canvas { |
// Test whether the provided rectangle intersects the current clip rect. |
bool IntersectsClipRectInt(int x, int y, int w, int h); |
- bool IntersectsClipRect(const gfx::Rect& rect); |
+ bool IntersectsClipRect(const Rect& rect); |
// Returns the image rep which best matches the canvas |scale_factor_|. |
// Returns a null image rep if |image| contains no image reps. |
// Builds mip map for returned image rep if necessary. |
// |
// An optional additional user defined scale can be provided. |
- const gfx::ImageSkiaRep& GetImageRepToPaint( |
- const gfx::ImageSkia& image) const; |
- const gfx::ImageSkiaRep& GetImageRepToPaint( |
- const gfx::ImageSkia& image, |
+ const ImageSkiaRep& GetImageRepToPaint(const ImageSkia& image) const; |
+ const ImageSkiaRep& GetImageRepToPaint( |
+ const ImageSkia& image, |
float user_defined_scale_factor_x, |
- float user_defined_scale_factor_y) const; |
+ float user_defined_scale_factor_y) const; |
// The device scale factor at which drawing on this canvas occurs. |
// An additional scale can be applied via Canvas::Scale(). However, |