| 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 #include "ui/gfx/canvas.h" | 5 #include "ui/gfx/canvas.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "third_party/skia/include/core/SkPath.h" | 13 #include "third_party/skia/include/core/SkPath.h" |
| 14 #include "third_party/skia/include/core/SkRefCnt.h" | 14 #include "third_party/skia/include/core/SkRefCnt.h" |
| 15 #include "third_party/skia/include/effects/SkGradientShader.h" | 15 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 16 #include "ui/gfx/font_list.h" | 16 #include "ui/gfx/font_list.h" |
| 17 #include "ui/gfx/geometry/insets_f.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/gfx/geometry/rect_conversions.h" | 19 #include "ui/gfx/geometry/rect_conversions.h" |
| 19 #include "ui/gfx/geometry/rect_f.h" | 20 #include "ui/gfx/geometry/rect_f.h" |
| 20 #include "ui/gfx/geometry/safe_integer_conversions.h" | 21 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 21 #include "ui/gfx/geometry/size_conversions.h" | 22 #include "ui/gfx/geometry/size_conversions.h" |
| 22 #include "ui/gfx/scoped_canvas.h" | 23 #include "ui/gfx/scoped_canvas.h" |
| 23 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| 24 #include "ui/gfx/transform.h" | 25 #include "ui/gfx/transform.h" |
| 25 | 26 |
| 26 namespace gfx { | 27 namespace gfx { |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 } | 336 } |
| 336 | 337 |
| 337 void Canvas::DrawFocusRect(const Rect& rect) { | 338 void Canvas::DrawFocusRect(const Rect& rect) { |
| 338 DrawFocusRect(RectF(rect)); | 339 DrawFocusRect(RectF(rect)); |
| 339 } | 340 } |
| 340 | 341 |
| 341 void Canvas::DrawFocusRect(const RectF& rect) { | 342 void Canvas::DrawFocusRect(const RectF& rect) { |
| 342 DrawDashedRect(rect, SK_ColorGRAY); | 343 DrawDashedRect(rect, SK_ColorGRAY); |
| 343 } | 344 } |
| 344 | 345 |
| 345 void Canvas::DrawSolidFocusRect(const Rect& rect, SkColor color) { | 346 void Canvas::DrawSolidFocusRect(const RectF& rect, |
| 346 DrawSolidFocusRect(RectF(rect), color); | 347 SkColor color, |
| 347 } | 348 float thickness) { |
| 348 | |
| 349 void Canvas::DrawSolidFocusRect(const RectF& rect, SkColor color) { | |
| 350 SkPaint paint; | 349 SkPaint paint; |
| 351 paint.setColor(color); | 350 paint.setColor(color); |
| 352 paint.setStrokeWidth(SK_Scalar1); | 351 paint.setStrokeWidth(SkFloatToScalar(thickness)); |
| 353 // Note: We cannot use DrawRect since it would create a path and fill it which | 352 paint.setStyle(SkPaint::kStroke_Style); |
| 354 // would cause problems near the edge of the canvas. | 353 gfx::RectF draw_rect = rect; |
| 355 float x1 = std::min(rect.x(), rect.right()); | 354 draw_rect.Inset(gfx::InsetsF(thickness / 2)); |
| 356 float x2 = std::max(rect.x(), rect.right()); | 355 DrawRect(draw_rect, paint); |
| 357 float y1 = std::min(rect.y(), rect.bottom()); | |
| 358 float y2 = std::max(rect.y(), rect.bottom()); | |
| 359 DrawLine(PointF(x1, y1), PointF(x2, y1), paint); | |
| 360 DrawLine(PointF(x1, y2), PointF(x2, y2), paint); | |
| 361 DrawLine(PointF(x1, y1), PointF(x1, y2), paint); | |
| 362 DrawLine(PointF(x2, y1), PointF(x2, y2 + 1.f), paint); | |
| 363 } | 356 } |
| 364 | 357 |
| 365 void Canvas::DrawImageInt(const ImageSkia& image, int x, int y) { | 358 void Canvas::DrawImageInt(const ImageSkia& image, int x, int y) { |
| 366 SkPaint paint; | 359 SkPaint paint; |
| 367 DrawImageInt(image, x, y, paint); | 360 DrawImageInt(image, x, y, paint); |
| 368 } | 361 } |
| 369 | 362 |
| 370 void Canvas::DrawImageInt(const ImageSkia& image, int x, int y, uint8_t a) { | 363 void Canvas::DrawImageInt(const ImageSkia& image, int x, int y, uint8_t a) { |
| 371 SkPaint paint; | 364 SkPaint paint; |
| 372 paint.setAlpha(a); | 365 paint.setAlpha(a); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); | 588 p.setFilterQuality(filter ? kLow_SkFilterQuality : kNone_SkFilterQuality); |
| 596 p.setShader(CreateImageRepShaderForScale( | 589 p.setShader(CreateImageRepShaderForScale( |
| 597 image_rep, SkShader::kRepeat_TileMode, shader_scale, | 590 image_rep, SkShader::kRepeat_TileMode, shader_scale, |
| 598 remove_image_scale ? image_rep.scale() : 1.f)); | 591 remove_image_scale ? image_rep.scale() : 1.f)); |
| 599 | 592 |
| 600 // The rect will be filled by the bitmap. | 593 // The rect will be filled by the bitmap. |
| 601 canvas_->drawRect(dest_rect, p); | 594 canvas_->drawRect(dest_rect, p); |
| 602 } | 595 } |
| 603 | 596 |
| 604 } // namespace gfx | 597 } // namespace gfx |
| OLD | NEW |