diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-09 00:30:59 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-03-09 00:30:59 +0000 |
commit | 94a0d258287787cf09854492ce889eb14273c059 (patch) | |
tree | ff242b01f90ee3888fd10a1583b03268b9a15eb0 /ui | |
parent | fbddf8352b68292d26191060d37c3f0820c8875c (diff) | |
download | chromium_src-94a0d258287787cf09854492ce889eb14273c059.zip chromium_src-94a0d258287787cf09854492ce889eb14273c059.tar.gz chromium_src-94a0d258287787cf09854492ce889eb14273c059.tar.bz2 |
ui/gfx: Make gfx::Canvas inherit from gfx::CanvasSkia.
The final goal is to merge these two classes into a single gfx::Canvas class.
BUG=116572
R=ben@chromium.org,asvitkine@chromium.org
TBR=ben@chromium.org
Review URL: https://chromiumcodereview.appspot.com/9562038
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@125735 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
35 files changed, 260 insertions, 325 deletions
diff --git a/ui/aura/demo/demo_main.cc b/ui/aura/demo/demo_main.cc index d6eccc2..be1c684 100644 --- a/ui/aura/demo/demo_main.cc +++ b/ui/aura/demo/demo_main.cc @@ -15,7 +15,7 @@ #include "ui/base/resource/resource_bundle.h" #include "ui/aura/root_window.h" #include "ui/base/ui_base_paths.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/compositor/test/compositor_test_support.h" #include "ui/gfx/rect.h" diff --git a/ui/base/dragdrop/drag_utils.cc b/ui/base/dragdrop/drag_utils.cc index 70cfb7a..1ea4250 100644 --- a/ui/base/dragdrop/drag_utils.cc +++ b/ui/base/dragdrop/drag_utils.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -10,7 +10,7 @@ #include "googleurl/src/gurl.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/point.h" #include "ui/gfx/size.h" @@ -38,7 +38,7 @@ void CreateDragImageForFile(const FilePath& file_name, // Add +2 here to allow room for the halo. const int height = font.GetHeight() + icon->height() + kLinkDragImageVPadding + 2; - gfx::CanvasSkia canvas(gfx::Size(width, height), false /* translucent */); + gfx::Canvas canvas(gfx::Size(width, height), false /* translucent */); // Paint the icon. canvas.DrawBitmapInt(*icon, (width - icon->width()) / 2, 0); @@ -65,8 +65,8 @@ void SetDragImageOnDataObject(const gfx::Canvas& canvas, const gfx::Size& size, const gfx::Point& cursor_offset, ui::OSExchangeData* data_object) { - SetDragImageOnDataObject( - canvas.AsCanvasSkia()->ExtractBitmap(), size, cursor_offset, data_object); + SetDragImageOnDataObject(canvas.ExtractBitmap(), size, cursor_offset, + data_object); } } // namespace drag_utils diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc index 619f93f..0020707 100644 --- a/ui/gfx/canvas.cc +++ b/ui/gfx/canvas.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,20 +6,20 @@ namespace gfx { -CanvasSkia* Canvas::AsCanvasSkia() { - return NULL; +Canvas::Canvas() + : CanvasSkia() { } -const CanvasSkia* Canvas::AsCanvasSkia() const { - return NULL; +Canvas::Canvas(SkCanvas* canvas) + : CanvasSkia(canvas) { } -SkCanvas* Canvas::GetSkCanvas() { - return NULL; +Canvas::Canvas(const gfx::Size& size, bool is_opaque) + : CanvasSkia(size, is_opaque) { } -const SkCanvas* Canvas::GetSkCanvas() const { - return NULL; +Canvas::Canvas(const SkBitmap& bitmap, bool is_opaque) + : CanvasSkia(bitmap, is_opaque) { } } // namespace gfx diff --git a/ui/gfx/canvas.h b/ui/gfx/canvas.h index 7692605..3fd3867 100644 --- a/ui/gfx/canvas.h +++ b/ui/gfx/canvas.h @@ -6,215 +6,22 @@ #define UI_GFX_CANVAS_H_ #pragma once -#include <string> - -#include "base/string16.h" -// TODO(beng): remove these includes when we no longer depend on SkTypes. -#include "third_party/skia/include/core/SkColor.h" -#include "third_party/skia/include/core/SkXfermode.h" #include "ui/base/ui_export.h" -#include "ui/gfx/native_widget_types.h" - -class SkCanvas; - -namespace ui { -class Transform; -} +#include "ui/gfx/canvas_skia.h" namespace gfx { -class Brush; -class CanvasSkia; -class Font; -class Point; -class Rect; -class Size; - -// TODO(beng): documentation. -class UI_EXPORT Canvas { +// TODO(tfarina): This is a temporary work around until we rename all the +// entries from CanvasSkia to Canvas. +class UI_EXPORT Canvas : public CanvasSkia { public: - // Specifies the alignment for text rendered with the DrawStringInt method. - enum { - TEXT_ALIGN_LEFT = 1, - TEXT_ALIGN_CENTER = 2, - TEXT_ALIGN_RIGHT = 4, - TEXT_VALIGN_TOP = 8, - TEXT_VALIGN_MIDDLE = 16, - TEXT_VALIGN_BOTTOM = 32, - - // Specifies the text consists of multiple lines. - MULTI_LINE = 64, - - // By default DrawStringInt does not process the prefix ('&') character - // specially. That is, the string "&foo" is rendered as "&foo". When - // rendering text from a resource that uses the prefix character for - // mnemonics, the prefix should be processed and can be rendered as an - // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). - SHOW_PREFIX = 128, - HIDE_PREFIX = 256, - - // Prevent ellipsizing - NO_ELLIPSIS = 512, - - // Specifies if words can be split by new lines. - // This only works with MULTI_LINE. - CHARACTER_BREAK = 1024, - - // Instructs DrawStringInt() to render the text using RTL directionality. - // In most cases, passing this flag is not necessary because information - // about the text directionality is going to be embedded within the string - // in the form of special Unicode characters. However, we don't insert - // directionality characters into strings if the locale is LTR because some - // platforms (for example, an English Windows XP with no RTL fonts - // installed) don't support these characters. Thus, this flag should be - // used to render text using RTL directionality when the locale is LTR. - FORCE_RTL_DIRECTIONALITY = 2048, - - // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right. - // See FORCE_RTL_DIRECTIONALITY for details. - FORCE_LTR_DIRECTIONALITY = 4096, - }; - - virtual ~Canvas() {} - - // Saves a copy of the drawing state onto a stack, operating on this copy - // until a balanced call to Restore() is made. - virtual void Save() = 0; - - // As with Save(), except draws to a layer that is blended with the canvas - // at the specified alpha once Restore() is called. - // |layer_bounds| are the bounds of the layer relative to the current - // transform. - virtual void SaveLayerAlpha(uint8 alpha) = 0; - virtual void SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds) = 0; - - // Restores the drawing state after a call to Save*(). It is an error to - // call Restore() more times than Save*(). - virtual void Restore() = 0; - - // Returns true if the clip is non-empty. - virtual bool ClipRect(const gfx::Rect& rect) = 0; - - virtual void Translate(const gfx::Point& point) = 0; - - virtual void Scale(int x_scale, int y_scale) = 0; - - // Fills |rect| with |color| using a transfer mode of - // SkXfermode::kSrcOver_Mode. - virtual void FillRect(const gfx::Rect& rect, const SkColor& color) = 0; - - // Fills |rect| with the specified |color| and |mode|. - virtual void FillRect(const gfx::Rect& rect, - const SkColor& color, - SkXfermode::Mode mode) = 0; - - // Fills |rect| with the specified |brush|. - virtual void FillRect(const gfx::Rect& rect, const gfx::Brush* brush) = 0; - - // 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. - virtual void DrawRect(const gfx::Rect& rect, const SkColor& color) = 0; - - // 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. - virtual void DrawRect(const gfx::Rect& rect, - const SkColor& color, - SkXfermode::Mode mode) = 0; - - // Draws the given rectangle with the given paint's parameters. - virtual void DrawRect(const gfx::Rect& rect, const SkPaint& paint) = 0; - - // Draws a single pixel line with the specified color. - virtual void DrawLine(const gfx::Point& p1, - const gfx::Point& p2, - const SkColor& color) = 0; - - // Draws a bitmap with the origin at the specified location. The upper left - // corner of the bitmap is rendered at the specified location. - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) = 0; - - // Draws a bitmap with the origin at the specified location, using the - // specified paint. The upper left corner of the bitmap is rendered at the - // specified location. - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int x, int y, - const SkPaint& paint) = 0; - - // Draws a portion of a bitmap in the specified location. The src parameters - // correspond to the region of the bitmap to draw in the region defined - // by the dest coordinates. - // - // If the width or height of the source differs from that of the destination, - // the bitmap will be scaled. When scaling down, it is highly recommended - // that you call buildMipMap(false) on your bitmap to ensure that it has - // a mipmap, which will result in much higher-quality output. Set |filter| - // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm - // is used for resampling. - // - // An optional custom SkPaint can be provided. - virtual void DrawBitmapInt(const SkBitmap& bitmap, - 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) = 0; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - 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) = 0; - - // Draws text with the specified color, font 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. - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h) = 0; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) = 0; - - // Draws text with the specified color, font 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. - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) = 0; - - // Draws a dotted gray rectangle used for focus purposes. - virtual void DrawFocusRect(const gfx::Rect& rect) = 0; - - // Tiles the image in the specified region. - virtual void TileImageInt(const SkBitmap& bitmap, - int x, int y, int w, int h) = 0; - virtual void TileImageInt(const SkBitmap& bitmap, - int src_x, int src_y, - int dest_x, int dest_y, int w, int h) = 0; - - // Returns a native drawing context for platform specific drawing routines to - // use. Must be balanced by a call to EndPlatformPaint(). - virtual gfx::NativeDrawingContext BeginPlatformPaint() = 0; + Canvas(); - // Signifies the end of platform drawing using the native drawing context - // returned by BeginPlatformPaint(). - virtual void EndPlatformPaint() = 0; + explicit Canvas(SkCanvas* canvas); - // Apply transformation on the canvas. - virtual void Transform(const ui::Transform& transform) = 0; + Canvas(const gfx::Size& size, bool is_opaque); - // TODO(beng): remove this once we don't need to use any skia-specific methods - // through this interface. - // A quick and dirty way to obtain the underlying SkCanvas. - virtual CanvasSkia* AsCanvasSkia(); - virtual const CanvasSkia* AsCanvasSkia() const; - virtual SkCanvas* GetSkCanvas(); - virtual const SkCanvas* GetSkCanvas() const; + Canvas(const SkBitmap& bitmap, bool is_opaque); }; } // namespace gfx diff --git a/ui/gfx/canvas_paint_win.cc b/ui/gfx/canvas_paint_win.cc index 3264f3c..8bafe6d 100644 --- a/ui/gfx/canvas_paint_win.cc +++ b/ui/gfx/canvas_paint_win.cc @@ -4,6 +4,7 @@ #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/canvas_paint.h" #include "ui/gfx/canvas_skia_paint.h" #include "ui/gfx/rect.h" diff --git a/ui/gfx/canvas_skia.cc b/ui/gfx/canvas_skia.cc index 1e0d214..1dafe88 100644 --- a/ui/gfx/canvas_skia.cc +++ b/ui/gfx/canvas_skia.cc @@ -13,6 +13,7 @@ #include "ui/gfx/brush.h" #include "ui/gfx/font.h" #include "ui/gfx/rect.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/skia_util.h" #include "ui/gfx/transform.h" @@ -85,9 +86,8 @@ int CanvasSkia::GetStringWidth(const string16& text, const gfx::Font& font) { // static int CanvasSkia::DefaultCanvasTextAlignment() { - if (!base::i18n::IsRTL()) - return gfx::Canvas::TEXT_ALIGN_LEFT; - return gfx::Canvas::TEXT_ALIGN_RIGHT; + return base::i18n::IsRTL() ? Canvas::TEXT_ALIGN_RIGHT + : Canvas::TEXT_ALIGN_LEFT; } SkBitmap CanvasSkia::ExtractBitmap() const { diff --git a/ui/gfx/canvas_skia.h b/ui/gfx/canvas_skia.h index aee7711..464a398 100644 --- a/ui/gfx/canvas_skia.h +++ b/ui/gfx/canvas_skia.h @@ -7,18 +7,27 @@ #pragma once #include "base/basictypes.h" -#include "base/compiler_specific.h" #include "base/memory/scoped_ptr.h" #include "base/string16.h" #include "skia/ext/platform_canvas.h" -#include "ui/gfx/canvas.h" +#include "ui/gfx/native_widget_types.h" class SkBitmap; +namespace ui { +class Transform; +} + namespace gfx { +class Brush; +class Rect; +class Font; +class Point; +class Size; + // CanvasSkia is a SkCanvas wrapper that provides a number of methods for -// common operations used throughout an application built using base/gfx. +// common operations used throughout an application built using ui/gfx. // // All methods that take integer arguments (as is used throughout views) // end with Int. If you need to use methods provided by SkCanvas, you'll @@ -30,7 +39,7 @@ namespace gfx { // source and destination colors are combined. Unless otherwise specified, // the variant that does not take a SkXfermode::Mode uses a transfer mode // of kSrcOver_Mode. -class UI_EXPORT CanvasSkia : public Canvas { +class UI_EXPORT CanvasSkia { public: enum TruncateFadeMode { TruncateFadeTail, @@ -38,6 +47,48 @@ class UI_EXPORT CanvasSkia : public Canvas { TruncateFadeHeadAndTail, }; + // Specifies the alignment for text rendered with the DrawStringInt method. + enum { + TEXT_ALIGN_LEFT = 1, + TEXT_ALIGN_CENTER = 2, + TEXT_ALIGN_RIGHT = 4, + TEXT_VALIGN_TOP = 8, + TEXT_VALIGN_MIDDLE = 16, + TEXT_VALIGN_BOTTOM = 32, + + // Specifies the text consists of multiple lines. + MULTI_LINE = 64, + + // By default DrawStringInt does not process the prefix ('&') character + // specially. That is, the string "&foo" is rendered as "&foo". When + // rendering text from a resource that uses the prefix character for + // mnemonics, the prefix should be processed and can be rendered as an + // underline (SHOW_PREFIX), or not rendered at all (HIDE_PREFIX). + SHOW_PREFIX = 128, + HIDE_PREFIX = 256, + + // Prevent ellipsizing + NO_ELLIPSIS = 512, + + // Specifies if words can be split by new lines. + // This only works with MULTI_LINE. + CHARACTER_BREAK = 1024, + + // Instructs DrawStringInt() to render the text using RTL directionality. + // In most cases, passing this flag is not necessary because information + // about the text directionality is going to be embedded within the string + // in the form of special Unicode characters. However, we don't insert + // directionality characters into strings if the locale is LTR because some + // platforms (for example, an English Windows XP with no RTL fonts + // installed) don't support these characters. Thus, this flag should be + // used to render text using RTL directionality when the locale is LTR. + FORCE_RTL_DIRECTIONALITY = 2048, + + // Similar to FORCE_RTL_DIRECTIONALITY, but left-to-right. + // See FORCE_RTL_DIRECTIONALITY for details. + FORCE_LTR_DIRECTIONALITY = 4096, + }; + // Creates an empty canvas. CanvasSkia(); @@ -94,61 +145,143 @@ class UI_EXPORT CanvasSkia : public Canvas { // Extracts a bitmap from the contents of this canvas. SkBitmap ExtractBitmap() const; - // Overridden from Canvas: - virtual void Save() OVERRIDE; - virtual void SaveLayerAlpha(uint8 alpha) OVERRIDE; - virtual void SaveLayerAlpha(uint8 alpha, - const gfx::Rect& layer_bounds) OVERRIDE; - virtual void Restore() OVERRIDE; - virtual bool ClipRect(const gfx::Rect& rect) OVERRIDE; - virtual void Translate(const gfx::Point& point) OVERRIDE; - virtual void Scale(int x_scale, int y_scale) OVERRIDE; - virtual void FillRect(const gfx::Rect& rect, const SkColor& color) OVERRIDE; - virtual void FillRect(const gfx::Rect& rect, - const SkColor& color, - SkXfermode::Mode mode) OVERRIDE; - virtual void FillRect(const gfx::Rect& rect, - const gfx::Brush* brush) OVERRIDE; - virtual void DrawRect(const gfx::Rect& rect, const SkColor& color) OVERRIDE; - virtual void DrawRect(const gfx::Rect& rect, - const SkColor& color, - SkXfermode::Mode mode) OVERRIDE; - virtual void DrawRect(const gfx::Rect& rect, const SkPaint& paint) OVERRIDE; - virtual void DrawLine(const gfx::Point& p1, - const gfx::Point& p2, - const SkColor& color) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, int x, int y) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - int x, int y, - const SkPaint& paint) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - 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) OVERRIDE; - virtual void DrawBitmapInt(const SkBitmap& bitmap, - 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) OVERRIDE; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h) OVERRIDE; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - const gfx::Rect& display_rect) OVERRIDE; - virtual void DrawStringInt(const string16& text, - const gfx::Font& font, - const SkColor& color, - int x, int y, int w, int h, - int flags) OVERRIDE; + // Saves a copy of the drawing state onto a stack, operating on this copy + // until a balanced call to Restore() is made. + void Save(); + + // As with Save(), except draws to a layer that is blended with the canvas + // at the specified alpha once Restore() is called. + // |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); + + // Restores the drawing state after a call to Save*(). It is an error to + // call Restore() more times than Save*(). + void Restore() ; + + // Returns true if the clip is non-empty. + bool ClipRect(const gfx::Rect& rect); + + void Translate(const gfx::Point& point); + + void Scale(int x_scale, int y_scale); + + // Fills |rect| with |color| using a transfer mode of + // SkXfermode::kSrcOver_Mode. + void FillRect(const gfx::Rect& rect, const SkColor& color); + + // Fills |rect| with the specified |color| and |mode|. + void FillRect(const gfx::Rect& rect, + const SkColor& color, + SkXfermode::Mode mode); + + // Fills |rect| with the specified |brush|. + void FillRect(const gfx::Rect& rect, const gfx::Brush* brush); + + // 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, const 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, + const SkColor& color, + SkXfermode::Mode mode); + + // Draws the given rectangle with the given paint's parameters. + void DrawRect(const gfx::Rect& rect, const SkPaint& paint); + + // Draws a single pixel line with the specified color. + void DrawLine(const gfx::Point& p1, + const gfx::Point& p2, + const SkColor& color); + + // Draws a bitmap with the origin at the specified location. The upper left + // corner of the bitmap is rendered at the specified location. + void DrawBitmapInt(const SkBitmap& bitmap, int x, int y); + + // Draws a bitmap with the origin at the specified location, using the + // specified paint. The upper left corner of the bitmap is rendered at the + // specified location. + void DrawBitmapInt(const SkBitmap& bitmap, + int x, int y, + const SkPaint& paint); + + // Draws a portion of a bitmap in the specified location. The src parameters + // correspond to the region of the bitmap to draw in the region defined + // by the dest coordinates. + // + // If the width or height of the source differs from that of the destination, + // the bitmap will be scaled. When scaling down, it is highly recommended + // that you call buildMipMap(false) on your bitmap to ensure that it has + // a mipmap, which will result in much higher-quality output. Set |filter| + // to use filtering for bitmaps, otherwise the nearest-neighbor algorithm + // is used for resampling. + // + // An optional custom SkPaint can be provided. + void DrawBitmapInt(const SkBitmap& bitmap, + 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 DrawBitmapInt(const SkBitmap& bitmap, + 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); + + // Draws text with the specified color, font 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 DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h); + void DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + const gfx::Rect& display_rect); + + // Draws text with the specified color, font 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 DrawStringInt(const string16& text, + const gfx::Font& font, + const SkColor& color, + int x, int y, int w, int h, + int flags); + + // Draws a dotted gray rectangle used for focus purposes. + void DrawFocusRect(const gfx::Rect& rect); + + // Tiles the image in the specified region. + void TileImageInt(const SkBitmap& bitmap, + int x, int y, int w, int h); + void TileImageInt(const SkBitmap& bitmap, + int src_x, int src_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(). + NativeDrawingContext BeginPlatformPaint(); + + // Signifies the end of platform drawing using the native drawing context + // returned by BeginPlatformPaint(). + void EndPlatformPaint(); + + // Apply transformation on the canvas. + void Transform(const ui::Transform& transform); + #if defined(OS_WIN) // 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. - virtual void DrawFadeTruncatingString( + void DrawFadeTruncatingString( const string16& text, TruncateFadeMode truncate_mode, size_t desired_characters_to_truncate_from_head, @@ -156,21 +289,14 @@ class UI_EXPORT CanvasSkia : public Canvas { const SkColor& color, const gfx::Rect& display_rect); #endif - virtual void DrawFocusRect(const gfx::Rect& rect) OVERRIDE; - virtual void TileImageInt(const SkBitmap& bitmap, - int x, int y, int w, int h) OVERRIDE; - virtual void TileImageInt(const SkBitmap& bitmap, - int src_x, int src_y, - int dest_x, int dest_y, int w, int h) OVERRIDE; - virtual gfx::NativeDrawingContext BeginPlatformPaint() OVERRIDE; - virtual void EndPlatformPaint() OVERRIDE; - virtual void Transform(const ui::Transform& transform) OVERRIDE; - virtual CanvasSkia* AsCanvasSkia() OVERRIDE; - virtual const CanvasSkia* AsCanvasSkia() const OVERRIDE; - virtual SkCanvas* GetSkCanvas() OVERRIDE; - virtual const SkCanvas* GetSkCanvas() const OVERRIDE; + // TODO(tfarina): Remove these. And stick with sk_canvas() only. + CanvasSkia* AsCanvasSkia(); + const CanvasSkia* AsCanvasSkia() const; + SkCanvas* GetSkCanvas(); + const SkCanvas* GetSkCanvas() const; SkCanvas* sk_canvas() const { return canvas_; } + skia::PlatformCanvas* platform_canvas() const { return owned_canvas_.get(); } private: diff --git a/ui/gfx/canvas_skia_linux.cc b/ui/gfx/canvas_skia_linux.cc index 9f52b6c..207c66b 100644 --- a/ui/gfx/canvas_skia_linux.cc +++ b/ui/gfx/canvas_skia_linux.cc @@ -17,6 +17,7 @@ #include "ui/gfx/platform_font_pango.h" #include "ui/gfx/rect.h" #include "ui/gfx/skia_util.h" +#include "ui/gfx/canvas.h" using std::max; diff --git a/ui/gfx/canvas_skia_mac.mm b/ui/gfx/canvas_skia_mac.mm index 317a3ac..5d3f1a0a 100644 --- a/ui/gfx/canvas_skia_mac.mm +++ b/ui/gfx/canvas_skia_mac.mm @@ -4,7 +4,7 @@ #import <Cocoa/Cocoa.h> -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "base/logging.h" #include "base/sys_string_conversions.h" diff --git a/ui/gfx/canvas_skia_paint.h b/ui/gfx/canvas_skia_paint.h index ed061ff..885bf32 100644 --- a/ui/gfx/canvas_skia_paint.h +++ b/ui/gfx/canvas_skia_paint.h @@ -8,7 +8,7 @@ #include "base/logging.h" #include "skia/ext/canvas_paint.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" // Define a gfx::CanvasSkiaPaint type that wraps our gfx::Canvas like the // skia::PlatformCanvasPaint wraps PlatformCanvas. @@ -16,7 +16,7 @@ namespace skia { template<> inline -PlatformCanvas* GetPlatformCanvas(skia::CanvasPaintT<gfx::CanvasSkia>* canvas) { +PlatformCanvas* GetPlatformCanvas(skia::CanvasPaintT<gfx::Canvas>* canvas) { PlatformCanvas* platform_canvas = canvas->platform_canvas(); DCHECK(platform_canvas); return platform_canvas; @@ -26,7 +26,7 @@ PlatformCanvas* GetPlatformCanvas(skia::CanvasPaintT<gfx::CanvasSkia>* canvas) { namespace gfx { -typedef skia::CanvasPaintT<CanvasSkia> CanvasSkiaPaint; +typedef skia::CanvasPaintT<Canvas> CanvasSkiaPaint; } // namespace gfx diff --git a/ui/gfx/canvas_skia_win.cc b/ui/gfx/canvas_skia_win.cc index a02f6a8..8ab30cf 100644 --- a/ui/gfx/canvas_skia_win.cc +++ b/ui/gfx/canvas_skia_win.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include <limits> diff --git a/ui/gfx/compositor/layer.cc b/ui/gfx/compositor/layer.cc index f4853d7..fe5d161 100644 --- a/ui/gfx/compositor/layer.cc +++ b/ui/gfx/compositor/layer.cc @@ -17,7 +17,7 @@ #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h" #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSolidColorLayer.h" #include "ui/base/animation/animation.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/compositor/compositor_switches.h" #include "ui/gfx/compositor/layer_animator.h" #include "ui/gfx/interpolated_transform.h" @@ -325,7 +325,7 @@ void Layer::SuppressPaint() { void Layer::paintContents(WebKit::WebCanvas* web_canvas, const WebKit::WebRect& clip) { TRACE_EVENT0("ui", "Layer::paintContents"); - gfx::CanvasSkia canvas(web_canvas); + gfx::Canvas canvas(web_canvas); if (delegate_) delegate_->OnPaintLayer(&canvas); } diff --git a/ui/gfx/compositor/layer_unittest.cc b/ui/gfx/compositor/layer_unittest.cc index a00dfba..f7de8b7 100644 --- a/ui/gfx/compositor/layer_unittest.cc +++ b/ui/gfx/compositor/layer_unittest.cc @@ -10,7 +10,7 @@ #include "base/path_service.h" #include "base/string_util.h" #include "testing/gtest/include/gtest/gtest.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/codec/png_codec.h" #include "ui/gfx/compositor/compositor_observer.h" #include "ui/gfx/compositor/layer.h" diff --git a/ui/views/background.cc b/ui/views/background.cc index 92fa387..5c327dbd 100644 --- a/ui/views/background.cc +++ b/ui/views/background.cc @@ -7,7 +7,7 @@ #include "base/logging.h" #include "skia/ext/skia_utils_win.h" #include "third_party/skia/include/core/SkPaint.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" #include "ui/views/painter.h" #include "ui/views/view.h" diff --git a/ui/views/bubble/bubble_border.cc b/ui/views/bubble/bubble_border.cc index 372c24f..8012109 100644 --- a/ui/views/bubble/bubble_border.cc +++ b/ui/views/bubble/bubble_border.cc @@ -11,7 +11,7 @@ #include "grit/ui_resources_standard.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/skia_util.h" namespace views { diff --git a/ui/views/button_drag_utils.cc b/ui/views/button_drag_utils.cc index 5753fdc..d65bc29 100644 --- a/ui/views/button_drag_utils.cc +++ b/ui/views/button_drag_utils.cc @@ -10,7 +10,7 @@ #include "ui/base/dragdrop/drag_utils.h" #include "ui/base/dragdrop/os_exchange_data.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" #include "ui/views/controls/button/text_button.h" @@ -41,7 +41,7 @@ void SetURLAndDragImage(const GURL& url, button.SetBounds(0, 0, prefsize.width(), prefsize.height()); // Render the image. - gfx::CanvasSkia canvas(prefsize, false); + gfx::Canvas canvas(prefsize, false); button.PaintButton(&canvas, views::TextButton::PB_FOR_DRAG); drag_utils::SetDragImageOnDataObject(canvas, prefsize, gfx::Point(prefsize.width() / 2, prefsize.height() / 2), data); diff --git a/ui/views/controls/button/text_button.cc b/ui/views/controls/button/text_button.cc index 5c055ef..a92c539 100644 --- a/ui/views/controls/button/text_button.cc +++ b/ui/views/controls/button/text_button.cc @@ -10,7 +10,7 @@ #include "grit/ui_resources.h" #include "ui/base/animation/throb_animation.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/image/image.h" #include "ui/views/controls/button/button.h" #include "ui/views/events/event.h" diff --git a/ui/views/controls/glow_hover_controller.cc b/ui/views/controls/glow_hover_controller.cc index 4274508..d175b10 100644 --- a/ui/views/controls/glow_hover_controller.cc +++ b/ui/views/controls/glow_hover_controller.cc @@ -6,7 +6,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/effects/SkGradientShader.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/skbitmap_operations.h" #include "ui/views/view.h" diff --git a/ui/views/controls/label.cc b/ui/views/controls/label.cc index 58377cd..9d51b28 100644 --- a/ui/views/controls/label.cc +++ b/ui/views/controls/label.cc @@ -17,7 +17,7 @@ #include "ui/base/accessibility/accessible_view_state.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/text/text_elider.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/font.h" #include "ui/gfx/insets.h" diff --git a/ui/views/controls/menu/menu_controller.cc b/ui/views/controls/menu/menu_controller.cc index 4a13b3d..8a64110 100644 --- a/ui/views/controls/menu/menu_controller.cc +++ b/ui/views/controls/menu/menu_controller.cc @@ -13,7 +13,7 @@ #include "ui/base/events.h" #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/screen.h" #include "ui/views/controls/button/menu_button.h" #include "ui/views/controls/menu/menu_controller_delegate.h" @@ -836,7 +836,7 @@ void MenuController::StartDrag(SubmenuView* source, View::ConvertPointToView(NULL, item, &press_loc); gfx::Point widget_loc(press_loc); View::ConvertPointToWidget(item, &widget_loc); - gfx::CanvasSkia canvas(gfx::Size(item->width(), item->height()), false); + gfx::Canvas canvas(gfx::Size(item->width(), item->height()), false); item->PaintButton(&canvas, MenuItemView::PB_FOR_DRAG); OSExchangeData data; diff --git a/ui/views/controls/menu/menu_item_view_views.cc b/ui/views/controls/menu/menu_item_view_views.cc index 1f080d2..1019ccb 100644 --- a/ui/views/controls/menu/menu_item_view_views.cc +++ b/ui/views/controls/menu/menu_item_view_views.cc @@ -8,7 +8,7 @@ #include "grit/ui_resources.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/favicon_size.h" #include "ui/gfx/image/image.h" #include "ui/gfx/native_theme.h" diff --git a/ui/views/controls/menu/menu_item_view_win.cc b/ui/views/controls/menu/menu_item_view_win.cc index 19fc97f..f5cfc44 100644 --- a/ui/views/controls/menu/menu_item_view_win.cc +++ b/ui/views/controls/menu/menu_item_view_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,7 @@ #include <Vssym32.h> #include "grit/ui_strings.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/native_theme_win.h" #include "ui/views/controls/menu/menu_config.h" #include "ui/views/controls/menu/submenu_view.h" diff --git a/ui/views/controls/menu/menu_scroll_view_container.cc b/ui/views/controls/menu/menu_scroll_view_container.cc index 5e61f06..5db0cd5 100644 --- a/ui/views/controls/menu/menu_scroll_view_container.cc +++ b/ui/views/controls/menu/menu_scroll_view_container.cc @@ -11,7 +11,7 @@ #endif #include "ui/base/accessibility/accessible_view_state.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/native_theme.h" #include "ui/views/border.h" diff --git a/ui/views/controls/menu/menu_separator_win.cc b/ui/views/controls/menu/menu_separator_win.cc index 2692f79..6630290 100644 --- a/ui/views/controls/menu/menu_separator_win.cc +++ b/ui/views/controls/menu/menu_separator_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,7 @@ #include <uxtheme.h> #include <Vssym32.h> -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/native_theme.h" #include "ui/gfx/rect.h" #include "ui/views/controls/menu/menu_config.h" diff --git a/ui/views/controls/progress_bar.cc b/ui/views/controls/progress_bar.cc index 3abc820..5fd6c46 100644 --- a/ui/views/controls/progress_bar.cc +++ b/ui/views/controls/progress_bar.cc @@ -13,7 +13,7 @@ #include "third_party/skia/include/effects/SkBlurMaskFilter.h" #include "third_party/skia/include/effects/SkGradientShader.h" #include "ui/base/accessibility/accessible_view_state.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/color_utils.h" #include "ui/gfx/font.h" #include "ui/gfx/insets.h" diff --git a/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc b/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc index 7d9b4ae..115bbb0 100644 --- a/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc +++ b/ui/views/controls/tabbed_pane/native_tabbed_pane_views.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -7,7 +7,7 @@ #include "base/logging.h" #include "base/stl_util.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/views/controls/tabbed_pane/tabbed_pane.h" #include "ui/views/controls/tabbed_pane/tabbed_pane_listener.h" diff --git a/ui/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/ui/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 14698c3..580b4cf 100644 --- a/ui/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/ui/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,7 +11,7 @@ #include "ui/base/l10n/l10n_util_win.h" #include "ui/base/resource/resource_bundle.h" #include "ui/base/win/hwnd_util.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/native_theme_win.h" #include "ui/views/controls/tabbed_pane/tabbed_pane.h" diff --git a/ui/views/controls/table/table_view_views.cc b/ui/views/controls/table/table_view_views.cc index 187c0d6..aa71ce2 100644 --- a/ui/views/controls/table/table_view_views.cc +++ b/ui/views/controls/table/table_view_views.cc @@ -7,7 +7,7 @@ #include "base/i18n/rtl.h" #include "third_party/skia/include/core/SkBitmap.h" #include "ui/base/models/table_model.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/native_theme.h" #include "ui/gfx/skia_util.h" #include "ui/views/border.h" @@ -223,7 +223,7 @@ void TableView::OnPaint(gfx::Canvas* canvas) { int min_y, max_y; { SkRect sk_clip_rect; - if (canvas->GetSkCanvas()->getClipBounds(&sk_clip_rect)) { + if (canvas->sk_canvas()->getClipBounds(&sk_clip_rect)) { gfx::Rect clip_rect = gfx::SkRectToRect(sk_clip_rect); min_y = clip_rect.y(); max_y = clip_rect.bottom(); diff --git a/ui/views/view.cc b/ui/views/view.cc index 3c0c2a3..9cb513e 100644 --- a/ui/views/view.cc +++ b/ui/views/view.cc @@ -15,7 +15,7 @@ #include "third_party/skia/include/core/SkRect.h" #include "ui/base/accessibility/accessibility_types.h" #include "ui/base/dragdrop/drag_drop_types.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/compositor/layer_animator.h" diff --git a/ui/views/view_text_utils.cc b/ui/views/view_text_utils.cc index 41feef5..8bd5e15 100644 --- a/ui/views/view_text_utils.cc +++ b/ui/views/view_text_utils.cc @@ -8,7 +8,7 @@ #include "base/i18n/break_iterator.h" #include "base/logging.h" #include "base/utf_string_conversions.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" diff --git a/ui/views/view_unittest.cc b/ui/views/view_unittest.cc index b17067d..6caa4e5 100644 --- a/ui/views/view_unittest.cc +++ b/ui/views/view_unittest.cc @@ -13,7 +13,7 @@ #include "ui/base/clipboard/clipboard.h" #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/models/simple_menu_model.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/compositor/compositor.h" #include "ui/gfx/compositor/layer.h" #include "ui/gfx/compositor/layer_animator.h" diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index a3b7c28..e989da6 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -25,8 +25,8 @@ #include "ui/base/view_prop.h" #include "ui/base/win/hwnd_util.h" #include "ui/base/win/mouse_wheel_util.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/canvas_paint.h" -#include "ui/gfx/canvas_skia.h" #include "ui/gfx/canvas_skia_paint.h" #include "ui/gfx/icon_util.h" #include "ui/gfx/native_theme_win.h" @@ -2386,7 +2386,7 @@ void NativeWidgetWin::ClientAreaSizeChanged() { std::max(0, static_cast<int>(r.bottom - r.top))); delegate_->OnNativeWidgetSizeChanged(s); if (use_layered_buffer_) - layered_window_contents_.reset(new gfx::CanvasSkia(s, false)); + layered_window_contents_.reset(new gfx::Canvas(s, false)); } void NativeWidgetWin::UpdateDWMFrame() { diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h index 6b6fea1..fe9eae3 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -32,7 +32,7 @@ class ViewProp; } namespace gfx { -class CanvasSkia; +class Canvas; class Font; class Rect; } @@ -551,7 +551,7 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl, // A canvas that contains the window contents in the case of a layered // window. - scoped_ptr<gfx::CanvasSkia> layered_window_contents_; + scoped_ptr<gfx::Canvas> layered_window_contents_; // We must track the invalid rect ourselves, for two reasons: // For layered windows, Windows will not do this properly with diff --git a/ui/views/widget/root_view.cc b/ui/views/widget/root_view.cc index e4b7afa..78f1c120 100644 --- a/ui/views/widget/root_view.cc +++ b/ui/views/widget/root_view.cc @@ -11,7 +11,7 @@ #include "ui/base/accessibility/accessible_view_state.h" #include "ui/base/dragdrop/drag_drop_types.h" #include "ui/base/keycodes/keyboard_codes.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/compositor/layer.h" #include "ui/views/focus/view_storage.h" #include "ui/views/layout/fill_layout.h" diff --git a/ui/views/window/dialog_client_view.cc b/ui/views/window/dialog_client_view.cc index 28c5ff2..c7319da1 100644 --- a/ui/views/window/dialog_client_view.cc +++ b/ui/views/window/dialog_client_view.cc @@ -22,7 +22,7 @@ #include "ui/base/keycodes/keyboard_codes.h" #include "ui/base/l10n/l10n_util.h" #include "ui/base/resource/resource_bundle.h" -#include "ui/gfx/canvas_skia.h" +#include "ui/gfx/canvas.h" #include "ui/gfx/font.h" #include "ui/views/controls/button/text_button.h" #include "ui/views/layout/layout_constants.h" |