OLD | NEW |
1 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ | 1 #ifndef CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ |
2 #define CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ | 2 #define CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ |
3 | 3 |
4 #include "gfx/canvas.h" | 4 #include "gfx/canvas.h" |
5 #include "gfx/canvas_skia.h" | 5 #include "gfx/canvas_skia.h" |
6 #include "gfx/rect.h" | 6 #include "gfx/rect.h" |
7 | 7 |
8 namespace chromeos { | 8 namespace chromeos { |
9 | 9 |
10 namespace rounded_view { | 10 namespace rounded_view { |
11 | 11 |
12 // Corner radius of the RoundedView. | 12 // Corner radius of the RoundedView. |
13 const int kCornerRadius = 5; | 13 const SkScalar kCornerRadius = SkIntToScalar(5); |
14 | 14 |
15 // Stroke width to be used by the RoundedView. | 15 // Stroke width to be used by the RoundedView. |
16 const int kStrokeWidth = 1; | 16 const SkScalar kStrokeWidth = SkIntToScalar(1); |
17 | 17 |
18 // Color of the inner frame of the RoundedView. | 18 // Color of the inner frame of the RoundedView. |
19 const SkColor kInnerFrameColor = SK_ColorWHITE; | 19 const SkColor kInnerFrameColor = SK_ColorWHITE; |
20 | 20 |
21 // Color of the outer frame of the RoundedView. | 21 // Color of the outer frame of the RoundedView. |
22 const SkColor kOuterFrameColor = 0xFF555555; | 22 const SkColor kOuterFrameColor = 0xFF555555; |
23 | 23 |
24 } // namespace rounded_view | 24 } // namespace rounded_view |
25 | 25 |
26 // Class that sets up the round rectangle as a clip region of the view. | 26 // Class that sets up the round rectangle as a clip region of the view. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 // Add frame. | 62 // Add frame. |
63 DrawFrame(canvas); | 63 DrawFrame(canvas); |
64 } | 64 } |
65 | 65 |
66 template <typename C> | 66 template <typename C> |
67 SkPath RoundedView<C>::GetClipPath() const { | 67 SkPath RoundedView<C>::GetClipPath() const { |
68 SkPath round_view; | 68 SkPath round_view; |
69 SkRect view_rect = GetViewRect(); | 69 SkRect view_rect = GetViewRect(); |
70 view_rect.inset(2 * rounded_view::kStrokeWidth, | 70 view_rect.inset(2 * rounded_view::kStrokeWidth, |
71 2 * rounded_view::kStrokeWidth); | 71 2 * rounded_view::kStrokeWidth); |
| 72 // 3 is used instead of 2 to avoid empty points between the clip and |
| 73 // the frame. |
72 round_view.addRoundRect( | 74 round_view.addRoundRect( |
73 GetViewRect(), rounded_view::kCornerRadius, rounded_view::kCornerRadius); | 75 view_rect, |
| 76 rounded_view::kCornerRadius - 3 * rounded_view::kStrokeWidth, |
| 77 rounded_view::kCornerRadius - 3 * rounded_view::kStrokeWidth); |
| 78 |
74 return round_view; | 79 return round_view; |
75 } | 80 } |
76 | 81 |
77 template <typename C> | 82 template <typename C> |
78 SkRect RoundedView<C>::GetViewRect() const { | 83 SkRect RoundedView<C>::GetViewRect() const { |
79 gfx::Rect bounds = RoundedView<C>::GetLocalBounds(false); | 84 gfx::Rect bounds = RoundedView<C>::GetLocalBounds(false); |
80 SkRect view_rect; | 85 SkRect view_rect; |
81 view_rect.iset(bounds.x(), bounds.y(), | 86 view_rect.iset(bounds.x(), bounds.y(), |
82 bounds.x() + bounds.width(), | 87 bounds.x() + bounds.width(), |
83 bounds.y() + bounds.height()); | 88 bounds.y() + bounds.height()); |
84 return view_rect; | 89 return view_rect; |
85 } | 90 } |
86 | 91 |
87 template <typename C> | 92 template <typename C> |
88 void RoundedView<C>::DrawFrame(gfx::Canvas* canvas) { | 93 void RoundedView<C>::DrawFrame(gfx::Canvas* canvas) { |
89 SkPaint paint; | 94 SkPaint paint; |
90 paint.setStyle(SkPaint::kStroke_Style); | 95 paint.setStyle(SkPaint::kStroke_Style); |
91 paint.setStrokeWidth(rounded_view::kStrokeWidth); | 96 paint.setStrokeWidth(rounded_view::kStrokeWidth); |
92 paint.setAntiAlias(true); | 97 paint.setAntiAlias(true); |
93 SkRect view_rect = GetViewRect(); | 98 SkRect view_rect = GetViewRect(); |
94 | 99 |
| 100 // Used to make nested rounded rects look better. |
| 101 const SkScalar kOriginShift = 1.0; |
| 102 const SkScalar kDelta = 0.3; |
| 103 |
95 // Draw inner frame. | 104 // Draw inner frame. |
| 105 view_rect.fLeft -= kOriginShift; |
| 106 view_rect.fTop -= kOriginShift; |
96 view_rect.inset(rounded_view::kStrokeWidth, rounded_view::kStrokeWidth); | 107 view_rect.inset(rounded_view::kStrokeWidth, rounded_view::kStrokeWidth); |
97 paint.setColor(rounded_view::kInnerFrameColor); | 108 paint.setColor(rounded_view::kInnerFrameColor); |
98 canvas->AsCanvasSkia()->drawRoundRect(view_rect, rounded_view::kCornerRadius, | 109 canvas->AsCanvasSkia()-> |
99 rounded_view::kCornerRadius, paint); | 110 drawRoundRect(view_rect, |
| 111 rounded_view::kCornerRadius - rounded_view::kStrokeWidth, |
| 112 rounded_view::kCornerRadius - rounded_view::kStrokeWidth, |
| 113 paint); |
100 | 114 |
101 // Draw outer frame. | 115 // Draw outer frame. |
102 view_rect.inset(-rounded_view::kStrokeWidth, -rounded_view::kStrokeWidth); | 116 view_rect.fLeft -= kDelta; |
| 117 view_rect.fTop -= kDelta; |
| 118 view_rect.offset(rounded_view::kStrokeWidth - kDelta, |
| 119 rounded_view::kStrokeWidth - kDelta); |
103 paint.setColor(rounded_view::kOuterFrameColor); | 120 paint.setColor(rounded_view::kOuterFrameColor); |
104 canvas->AsCanvasSkia()->drawRoundRect(view_rect, rounded_view::kCornerRadius, | 121 canvas->AsCanvasSkia()->drawRoundRect(view_rect, rounded_view::kCornerRadius, |
105 rounded_view::kCornerRadius, paint); | 122 rounded_view::kCornerRadius, paint); |
106 } | 123 } |
107 | 124 |
108 } | 125 } |
109 | 126 |
110 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ | 127 #endif // CHROME_BROWSER_CHROMEOS_LOGIN_VIEW_FILTER_H_ |
OLD | NEW |