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/views/round_rect_painter.h" | 5 #include "ui/views/round_rect_painter.h" |
6 | 6 |
7 #include "ui/gfx/canvas.h" | 7 #include "ui/gfx/canvas.h" |
8 #include "ui/gfx/path.h" | 8 #include "ui/gfx/path.h" |
9 #include "ui/gfx/skia_util.h" | 9 #include "ui/gfx/skia_util.h" |
10 | 10 |
11 namespace views { | 11 namespace views { |
12 | 12 |
13 RoundRectPainter::RoundRectPainter(SkColor border_color, int corner_radius) | 13 RoundRectPainter::RoundRectPainter(SkColor border_color, int corner_radius) |
14 : border_color_(border_color), | 14 : border_color_(border_color), |
15 corner_radius_(corner_radius) { | 15 corner_radius_(corner_radius) { |
16 } | 16 } |
17 | 17 |
18 RoundRectPainter::~RoundRectPainter() { | 18 RoundRectPainter::~RoundRectPainter() { |
19 } | 19 } |
20 | 20 |
21 gfx::Size RoundRectPainter::GetMinimumSize() const { | 21 gfx::Size RoundRectPainter::GetMinimumSize() const { |
22 return gfx::Size(1, 1); | 22 return gfx::Size(1, 1); |
23 } | 23 } |
24 | 24 |
25 void RoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { | 25 void RoundRectPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { |
26 SkPaint paint; | 26 SkPaint paint; |
27 paint.setColor(border_color_); | 27 paint.setColor(border_color_); |
28 paint.setStyle(SkPaint::kStroke_Style); | 28 paint.setStyle(SkPaint::kStroke_Style); |
29 paint.setStrokeWidth(1); | 29 paint.setStrokeWidth(kBorderWidth); |
30 paint.setFlags(SkPaint::kAntiAlias_Flag); | 30 paint.setFlags(SkPaint::kAntiAlias_Flag); |
31 gfx::Rect rect(size); | 31 gfx::Rect rect(size); |
32 rect.Inset(0, 0, 1, 1); | 32 rect.Inset(0, 0, kBorderWidth, kBorderWidth); |
33 SkRect skia_rect = gfx::RectToSkRect(rect); | 33 SkRect skia_rect = gfx::RectToSkRect(rect); |
34 skia_rect.offset(.5, .5); | 34 skia_rect.offset(kBorderWidth / 2.f, kBorderWidth / 2.f); |
35 canvas->sk_canvas()->drawRoundRect(skia_rect, SkIntToScalar(corner_radius_), | 35 canvas->sk_canvas()->drawRoundRect(skia_rect, SkIntToScalar(corner_radius_), |
36 SkIntToScalar(corner_radius_), paint); | 36 SkIntToScalar(corner_radius_), paint); |
37 } | 37 } |
38 | 38 |
39 } // namespace views | 39 } // namespace views |
OLD | NEW |