Index: ui/gfx/canvas.cc |
diff --git a/ui/gfx/canvas.cc b/ui/gfx/canvas.cc |
index 2b0f5046cf0ced0cccf96b9274e1b8965af1e667..b59d2a0d8888f4f8eaeac13403107388ec8caf6c 100644 |
--- a/ui/gfx/canvas.cc |
+++ b/ui/gfx/canvas.cc |
@@ -11,7 +11,7 @@ |
#include "third_party/skia/include/core/SkBitmap.h" |
#include "third_party/skia/include/effects/SkGradientShader.h" |
#include "ui/gfx/canvas.h" |
-#include "ui/gfx/font.h" |
+#include "ui/gfx/font_list.h" |
#include "ui/gfx/rect.h" |
#include "ui/gfx/size_conversions.h" |
#include "ui/gfx/skia_util.h" |
@@ -23,13 +23,11 @@ |
namespace gfx { |
-Canvas::Canvas(const gfx::Size& size, |
- ui::ScaleFactor scale_factor, |
- bool is_opaque) |
- : scale_factor_(scale_factor), |
- canvas_(NULL) { |
- gfx::Size pixel_size = gfx::ToCeiledSize( |
- gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); |
+Canvas::Canvas(const Size& size, ui::ScaleFactor scale_factor, bool is_opaque) |
+ : scale_factor_(scale_factor), |
+ canvas_(NULL) { |
+ Size pixel_size = ToCeiledSize( |
+ ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); |
owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), |
pixel_size.height(), |
is_opaque)); |
@@ -45,7 +43,7 @@ Canvas::Canvas(const gfx::Size& size, |
canvas_->scale(scale, scale); |
} |
-Canvas::Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque) |
+Canvas::Canvas(const ImageSkiaRep& image_rep, bool is_opaque) |
: scale_factor_(image_rep.scale_factor()), |
owned_canvas_(skia::AdoptRef( |
skia::CreatePlatformCanvas(image_rep.pixel_width(), |
@@ -54,7 +52,7 @@ Canvas::Canvas(const gfx::ImageSkiaRep& image_rep, bool is_opaque) |
canvas_(owned_canvas_.get()) { |
SkScalar scale = SkFloatToScalar(ui::GetScaleFactorScale(scale_factor_)); |
canvas_->scale(scale, scale); |
- DrawImageInt(gfx::ImageSkia(image_rep), 0, 0); |
+ DrawImageInt(ImageSkia(image_rep), 0, 0); |
} |
Canvas::Canvas() |
@@ -72,12 +70,12 @@ Canvas* Canvas::CreateCanvasWithoutScaling(SkCanvas* canvas, |
return new Canvas(canvas, scale_factor); |
} |
-void Canvas::RecreateBackingCanvas(const gfx::Size& size, |
+void Canvas::RecreateBackingCanvas(const Size& size, |
ui::ScaleFactor scale_factor, |
bool is_opaque) { |
scale_factor_ = scale_factor; |
- gfx::Size pixel_size = gfx::ToFlooredSize( |
- gfx::ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); |
+ Size pixel_size = ToFlooredSize( |
+ ScaleSize(size, ui::GetScaleFactorScale(scale_factor))); |
owned_canvas_ = skia::AdoptRef(skia::CreatePlatformCanvas(pixel_size.width(), |
pixel_size.height(), |
is_opaque)); |
@@ -87,9 +85,27 @@ void Canvas::RecreateBackingCanvas(const gfx::Size& size, |
} |
// static |
-int Canvas::GetStringWidth(const base::string16& text, const gfx::Font& font) { |
+void Canvas::SizeStringInt(const base::string16& text, |
+ const Font& font, |
+ int* width, |
+ int* height, |
+ int line_height, |
+ int flags) { |
+ SizeStringInt(text, FontList(font), width, height, line_height, flags); |
+} |
+ |
+// static |
+int Canvas::GetStringWidth(const base::string16& text, |
+ const FontList& font_list) { |
+ int width = 0, height = 0; |
+ SizeStringInt(text, font_list, &width, &height, 0, NO_ELLIPSIS); |
+ return width; |
+} |
+ |
+// static |
+int Canvas::GetStringWidth(const base::string16& text, const Font& font) { |
int width = 0, height = 0; |
- Canvas::SizeStringInt(text, font, &width, &height, 0, NO_ELLIPSIS); |
+ SizeStringInt(text, FontList(font), &width, &height, 0, NO_ELLIPSIS); |
return width; |
} |
@@ -98,7 +114,20 @@ int Canvas::DefaultCanvasTextAlignment() { |
return base::i18n::IsRTL() ? TEXT_ALIGN_RIGHT : TEXT_ALIGN_LEFT; |
} |
-gfx::ImageSkiaRep Canvas::ExtractImageRep() const { |
+void Canvas::DrawStringWithHalo(const base::string16& text, |
+ const Font& font, |
+ SkColor text_color, |
+ SkColor halo_color_in, |
+ int x, |
+ int y, |
+ int w, |
+ int h, |
+ int flags) { |
+ DrawStringRectWithHalo(text, FontList(font), text_color, halo_color_in, |
+ Rect(x, y, w, h), flags); |
+} |
+ |
+ImageSkiaRep Canvas::ExtractImageRep() const { |
const SkBitmap& device_bitmap = canvas_->getDevice()->accessBitmap(false); |
// Make a bitmap to return, and a canvas to draw into it. We don't just want |
@@ -107,10 +136,10 @@ gfx::ImageSkiaRep Canvas::ExtractImageRep() const { |
SkBitmap result; |
device_bitmap.copyTo(&result, SkBitmap::kARGB_8888_Config); |
- return gfx::ImageSkiaRep(result, scale_factor_); |
+ return ImageSkiaRep(result, scale_factor_); |
} |
-void Canvas::DrawDashedRect(const gfx::Rect& rect, SkColor color) { |
+void Canvas::DrawDashedRect(const Rect& rect, SkColor color) { |
// Create a 2D bitmap containing alternating on/off pixels - we do this |
// so that you never get two pixels of the same color around the edges |
// of the focus rect (this may mean that opposing edges of the rect may |
@@ -149,11 +178,11 @@ void Canvas::DrawDashedRect(const gfx::Rect& rect, SkColor color) { |
SkPaint paint; |
paint.setShader(shader.get()); |
- DrawRect(gfx::Rect(rect.x(), rect.y(), rect.width(), 1), paint); |
- DrawRect(gfx::Rect(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1), |
+ DrawRect(Rect(rect.x(), rect.y(), rect.width(), 1), paint); |
+ DrawRect(Rect(rect.x(), rect.y() + rect.height() - 1, rect.width(), 1), |
paint); |
- DrawRect(gfx::Rect(rect.x(), rect.y(), 1, rect.height()), paint); |
- DrawRect(gfx::Rect(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()), |
+ DrawRect(Rect(rect.x(), rect.y(), 1, rect.height()), paint); |
+ DrawRect(Rect(rect.x() + rect.width() - 1, rect.y(), 1, rect.height()), |
paint); |
} |
@@ -166,8 +195,8 @@ void Canvas::SaveLayerAlpha(uint8 alpha) { |
} |
-void Canvas::SaveLayerAlpha(uint8 alpha, const gfx::Rect& layer_bounds) { |
- SkRect bounds(gfx::RectToSkRect(layer_bounds)); |
+void Canvas::SaveLayerAlpha(uint8 alpha, const Rect& layer_bounds) { |
+ SkRect bounds(RectToSkRect(layer_bounds)); |
canvas_->saveLayerAlpha(&bounds, alpha); |
} |
@@ -175,22 +204,22 @@ void Canvas::Restore() { |
canvas_->restore(); |
} |
-bool Canvas::ClipRect(const gfx::Rect& rect) { |
- return canvas_->clipRect(gfx::RectToSkRect(rect)); |
+bool Canvas::ClipRect(const Rect& rect) { |
+ return canvas_->clipRect(RectToSkRect(rect)); |
} |
bool Canvas::ClipPath(const SkPath& path) { |
return canvas_->clipPath(path); |
} |
-bool Canvas::GetClipBounds(gfx::Rect* bounds) { |
+bool Canvas::GetClipBounds(Rect* bounds) { |
SkRect out; |
bool has_non_empty_clip = canvas_->getClipBounds(&out); |
bounds->SetRect(out.left(), out.top(), out.width(), out.height()); |
return has_non_empty_clip; |
} |
-void Canvas::Translate(const gfx::Vector2d& offset) { |
+void Canvas::Translate(const Vector2d& offset) { |
canvas_->translate(SkIntToScalar(offset.x()), SkIntToScalar(offset.y())); |
} |
@@ -206,11 +235,11 @@ void Canvas::DrawColor(SkColor color, SkXfermode::Mode mode) { |
canvas_->drawColor(color, mode); |
} |
-void Canvas::FillRect(const gfx::Rect& rect, SkColor color) { |
+void Canvas::FillRect(const Rect& rect, SkColor color) { |
FillRect(rect, color, SkXfermode::kSrcOver_Mode); |
} |
-void Canvas::FillRect(const gfx::Rect& rect, |
+void Canvas::FillRect(const Rect& rect, |
SkColor color, |
SkXfermode::Mode mode) { |
SkPaint paint; |
@@ -220,11 +249,11 @@ void Canvas::FillRect(const gfx::Rect& rect, |
DrawRect(rect, paint); |
} |
-void Canvas::DrawRect(const gfx::Rect& rect, SkColor color) { |
+void Canvas::DrawRect(const Rect& rect, SkColor color) { |
DrawRect(rect, color, SkXfermode::kSrcOver_Mode); |
} |
-void Canvas::DrawRect(const gfx::Rect& rect, |
+void Canvas::DrawRect(const Rect& rect, |
SkColor color, |
SkXfermode::Mode mode) { |
SkPaint paint; |
@@ -239,38 +268,34 @@ void Canvas::DrawRect(const gfx::Rect& rect, |
DrawRect(rect, paint); |
} |
-void Canvas::DrawRect(const gfx::Rect& rect, const SkPaint& paint) { |
+void Canvas::DrawRect(const Rect& rect, const SkPaint& paint) { |
canvas_->drawIRect(RectToSkIRect(rect), paint); |
} |
-void Canvas::DrawPoint(const gfx::Point& p1, const SkPaint& paint) { |
+void Canvas::DrawPoint(const Point& p1, const SkPaint& paint) { |
canvas_->drawPoint(SkIntToScalar(p1.x()), SkIntToScalar(p1.y()), paint); |
} |
-void Canvas::DrawLine(const gfx::Point& p1, |
- const gfx::Point& p2, |
- SkColor color) { |
+void Canvas::DrawLine(const Point& p1, const Point& p2, SkColor color) { |
SkPaint paint; |
paint.setColor(color); |
paint.setStrokeWidth(SkIntToScalar(1)); |
DrawLine(p1, p2, paint); |
} |
-void Canvas::DrawLine(const gfx::Point& p1, |
- const gfx::Point& p2, |
- const SkPaint& paint) { |
+void Canvas::DrawLine(const Point& p1, const Point& p2, const SkPaint& paint) { |
canvas_->drawLine(SkIntToScalar(p1.x()), SkIntToScalar(p1.y()), |
SkIntToScalar(p2.x()), SkIntToScalar(p2.y()), paint); |
} |
-void Canvas::DrawCircle(const gfx::Point& center_point, |
+void Canvas::DrawCircle(const Point& center_point, |
int radius, |
const SkPaint& paint) { |
canvas_->drawCircle(SkIntToScalar(center_point.x()), |
SkIntToScalar(center_point.y()), SkIntToScalar(radius), paint); |
} |
-void Canvas::DrawRoundRect(const gfx::Rect& rect, |
+void Canvas::DrawRoundRect(const Rect& rect, |
int radius, |
const SkPaint& paint) { |
canvas_->drawRoundRect(RectToSkRect(rect), SkIntToScalar(radius), |
@@ -281,25 +306,26 @@ void Canvas::DrawPath(const SkPath& path, const SkPaint& paint) { |
canvas_->drawPath(path, paint); |
} |
-void Canvas::DrawFocusRect(const gfx::Rect& rect) { |
+void Canvas::DrawFocusRect(const Rect& rect) { |
DrawDashedRect(rect, SK_ColorGRAY); |
} |
-void Canvas::DrawImageInt(const gfx::ImageSkia& image, int x, int y) { |
+void Canvas::DrawImageInt(const ImageSkia& image, int x, int y) { |
SkPaint paint; |
DrawImageInt(image, x, y, paint); |
} |
-void Canvas::DrawImageInt(const gfx::ImageSkia& image, int x, int y, uint8 a) { |
+void Canvas::DrawImageInt(const ImageSkia& image, int x, int y, uint8 a) { |
SkPaint paint; |
paint.setAlpha(a); |
DrawImageInt(image, x, y, paint); |
} |
-void Canvas::DrawImageInt(const gfx::ImageSkia& image, |
- int x, int y, |
+void Canvas::DrawImageInt(const ImageSkia& image, |
+ int x, |
+ int y, |
const SkPaint& paint) { |
- const gfx::ImageSkiaRep& image_rep = GetImageRepToPaint(image); |
+ const ImageSkiaRep& image_rep = GetImageRepToPaint(image); |
if (image_rep.is_null()) |
return; |
const SkBitmap& bitmap = image_rep.sk_bitmap(); |
@@ -315,18 +341,30 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image, |
canvas_->restore(); |
} |
-void Canvas::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 Canvas::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) { |
SkPaint p; |
DrawImageInt(image, src_x, src_y, src_w, src_h, dest_x, dest_y, |
dest_w, dest_h, filter, p); |
} |
-void Canvas::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 Canvas::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) { |
DLOG_ASSERT(src_x + src_w < std::numeric_limits<int16_t>::max() && |
@@ -342,7 +380,7 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image, |
float user_scale_x = static_cast<float>(dest_w) / src_w; |
float user_scale_y = static_cast<float>(dest_h) / src_h; |
- const gfx::ImageSkiaRep& image_rep = GetImageRepToPaint(image, |
+ const ImageSkiaRep& image_rep = GetImageRepToPaint(image, |
user_scale_x, user_scale_y); |
if (image_rep.is_null()) |
return; |
@@ -373,7 +411,7 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image, |
shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); |
shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); |
- skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
+ skia::RefPtr<SkShader> shader = CreateImageRepShader( |
image_rep, |
SkShader::kRepeat_TileMode, |
shader_scale); |
@@ -388,18 +426,18 @@ void Canvas::DrawImageInt(const gfx::ImageSkia& image, |
canvas_->drawRect(dest_rect, p); |
} |
-void Canvas::DrawImageInPath(const gfx::ImageSkia& image, |
+void Canvas::DrawImageInPath(const ImageSkia& image, |
int x, |
int y, |
const SkPath& path, |
const SkPaint& paint) { |
- const gfx::ImageSkiaRep& image_rep = GetImageRepToPaint(image); |
+ const ImageSkiaRep& image_rep = GetImageRepToPaint(image); |
if (image_rep.is_null()) |
return; |
SkMatrix matrix; |
matrix.setTranslate(SkIntToScalar(x), SkIntToScalar(y)); |
- skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
+ skia::RefPtr<SkShader> shader = CreateImageRepShader( |
image_rep, |
SkShader::kRepeat_TileMode, |
matrix); |
@@ -409,55 +447,96 @@ void Canvas::DrawImageInPath(const gfx::ImageSkia& image, |
canvas_->drawPath(path, p); |
} |
+void Canvas::DrawStringRect(const base::string16& text, |
+ const FontList& font_list, |
+ SkColor color, |
+ const Rect& display_rect) { |
+ DrawStringRectWithFlags(text, font_list, color, display_rect, |
+ DefaultCanvasTextAlignment()); |
+} |
+ |
+void Canvas::DrawStringRectWithFlags(const base::string16& text, |
+ const FontList& font_list, |
+ SkColor color, |
+ const Rect& display_rect, |
+ int flags) { |
+ DrawStringRectWithShadows(text, font_list, color, display_rect, 0, flags, |
+ ShadowValues()); |
+} |
+ |
void Canvas::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) { |
DrawStringInt(text, font, color, x, y, w, h, DefaultCanvasTextAlignment()); |
} |
void Canvas::DrawStringInt(const base::string16& text, |
- const gfx::Font& font, |
+ const Font& font, |
SkColor color, |
- const gfx::Rect& display_rect) { |
+ const Rect& display_rect) { |
DrawStringInt(text, font, color, display_rect.x(), display_rect.y(), |
display_rect.width(), display_rect.height()); |
} |
void Canvas::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) { |
- DrawStringWithShadows(text, |
- font, |
- color, |
- gfx::Rect(x, y, w, h), |
- 0, |
- flags, |
+ DrawStringWithShadows(text, font, color, Rect(x, y, w, h), 0, flags, |
ShadowValues()); |
} |
-void Canvas::TileImageInt(const gfx::ImageSkia& image, |
- int x, int y, int w, int h) { |
+void Canvas::DrawStringWithShadows(const base::string16& text, |
+ const Font& font, |
+ SkColor color, |
+ const Rect& text_bounds, |
+ int line_height, |
+ int flags, |
+ const ShadowValues& shadows) { |
+ DrawStringRectWithShadows(text, FontList(font), color, text_bounds, |
+ line_height, flags, shadows); |
+} |
+ |
+void Canvas::TileImageInt(const ImageSkia& image, |
+ int x, |
+ int y, |
+ int w, |
+ int h) { |
TileImageInt(image, 0, 0, x, y, w, h); |
} |
-void Canvas::TileImageInt(const gfx::ImageSkia& image, |
- int src_x, int src_y, |
- int dest_x, int dest_y, int w, int h) { |
+void Canvas::TileImageInt(const ImageSkia& image, |
+ int src_x, |
+ int src_y, |
+ int dest_x, |
+ int dest_y, |
+ int w, |
+ int h) { |
TileImageInt(image, src_x, src_y, 1.0f, 1.0f, dest_x, dest_y, w, h); |
} |
-void Canvas::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 Canvas::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) { |
if (!IntersectsClipRectInt(dest_x, dest_y, w, h)) |
return; |
- const gfx::ImageSkiaRep& image_rep = GetImageRepToPaint(image, |
- tile_scale_x, tile_scale_y); |
+ const ImageSkiaRep& image_rep = GetImageRepToPaint( |
+ image, tile_scale_x, tile_scale_y); |
if (image_rep.is_null()) |
return; |
@@ -467,7 +546,7 @@ void Canvas::TileImageInt(const gfx::ImageSkia& image, |
shader_scale.preTranslate(SkIntToScalar(-src_x), SkIntToScalar(-src_y)); |
shader_scale.postTranslate(SkIntToScalar(dest_x), SkIntToScalar(dest_y)); |
- skia::RefPtr<SkShader> shader = gfx::CreateImageRepShader( |
+ skia::RefPtr<SkShader> shader = CreateImageRepShader( |
image_rep, |
SkShader::kRepeat_TileMode, |
shader_scale); |
@@ -483,7 +562,7 @@ void Canvas::TileImageInt(const gfx::ImageSkia& image, |
canvas_->drawRect(dest_rect, paint); |
} |
-gfx::NativeDrawingContext Canvas::BeginPlatformPaint() { |
+NativeDrawingContext Canvas::BeginPlatformPaint() { |
return skia::BeginPlatformPaint(canvas_); |
} |
@@ -509,21 +588,20 @@ bool Canvas::IntersectsClipRectInt(int x, int y, int w, int h) { |
SkIntToScalar(y + h)); |
} |
-bool Canvas::IntersectsClipRect(const gfx::Rect& rect) { |
+bool Canvas::IntersectsClipRect(const Rect& rect) { |
return IntersectsClipRectInt(rect.x(), rect.y(), |
rect.width(), rect.height()); |
} |
-const gfx::ImageSkiaRep& Canvas::GetImageRepToPaint( |
- const gfx::ImageSkia& image) const { |
+const ImageSkiaRep& Canvas::GetImageRepToPaint(const ImageSkia& image) const { |
return GetImageRepToPaint(image, 1.0f, 1.0f); |
} |
-const gfx::ImageSkiaRep& Canvas::GetImageRepToPaint( |
- const gfx::ImageSkia& image, |
+const ImageSkiaRep& Canvas::GetImageRepToPaint( |
+ const ImageSkia& image, |
float user_additional_scale_x, |
float user_additional_scale_y) const { |
- const gfx::ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor_); |
+ const ImageSkiaRep& image_rep = image.GetRepresentation(scale_factor_); |
if (!image_rep.is_null()) { |
SkMatrix m = canvas_->getTotalMatrix(); |