Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ui/gfx/path_mac.h" | 5 #import "ui/gfx/path_mac.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | |
| 8 | |
| 9 #include "third_party/skia/include/core/SkRegion.h" | 7 #include "third_party/skia/include/core/SkRegion.h" |
| 10 #include "ui/gfx/path.h" | 8 #include "ui/gfx/path.h" |
| 11 | 9 |
| 12 namespace { | 10 namespace { |
| 13 | 11 |
| 14 // Convert a quadratic bezier curve to a cubic bezier curve. Based on the | 12 // Convert a quadratic bezier curve to a cubic bezier curve. Based on the |
| 15 // implementation of the private SkConvertQuadToCubic method inside Skia. | 13 // implementation of the private SkConvertQuadToCubic method inside Skia. |
| 16 void ConvertQuadToCubicBezier(NSPoint quad[3], NSPoint cubic[4]) { | 14 void ConvertQuadToCubicBezier(NSPoint quad[3], NSPoint cubic[4]) { |
| 17 // The resultant cubic will have the same endpoints. | 15 // The resultant cubic will have the same endpoints. |
| 18 cubic[0] = quad[0]; | 16 cubic[0] = quad[0]; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 break; | 113 break; |
| 116 case SkPath::kInverseWinding_FillType: | 114 case SkPath::kInverseWinding_FillType: |
| 117 case SkPath::kInverseEvenOdd_FillType: | 115 case SkPath::kInverseEvenOdd_FillType: |
| 118 NOTREACHED() << "NSBezierCurve does not support inverse fill types."; | 116 NOTREACHED() << "NSBezierCurve does not support inverse fill types."; |
| 119 break; | 117 break; |
| 120 } | 118 } |
| 121 | 119 |
| 122 return result; | 120 return result; |
| 123 } | 121 } |
| 124 | 122 |
| 123 base::ScopedCFTypeRef<CGPathRef> CreateCGPathFromNSBezierPath( | |
|
karandeepb
2016/02/24 04:27:18
This is slightly inspired from https://developer.a
tapted
2016/02/24 05:05:03
I think you can do
#import "third_party/google_to
karandeepb
2016/02/25 03:31:06
Done. Weird that the src folder doesn't show up on
| |
| 124 NSBezierPath* path) { | |
| 125 base::ScopedCFTypeRef<CGMutablePathRef> result(CGPathCreateMutable()); | |
| 126 NSPoint points[3]; | |
| 127 bool path_closed = true; | |
| 128 for (int i = 0; i < [path elementCount]; i++) { | |
| 129 switch ([path elementAtIndex:i associatedPoints:points]) { | |
| 130 case NSMoveToBezierPathElement: | |
| 131 CGPathMoveToPoint(result, nullptr, points[0].x, points[0].y); | |
| 132 break; | |
| 133 | |
| 134 case NSLineToBezierPathElement: | |
| 135 CGPathAddLineToPoint(result, nullptr, points[0].x, points[0].y); | |
| 136 path_closed = false; | |
| 137 break; | |
| 138 | |
| 139 case NSCurveToBezierPathElement: | |
| 140 CGPathAddCurveToPoint(result, nullptr, points[0].x, points[0].y, | |
| 141 points[1].x, points[1].y, points[2].x, | |
| 142 points[2].y); | |
| 143 path_closed = false; | |
| 144 break; | |
| 145 | |
| 146 case NSClosePathBezierPathElement: | |
| 147 CGPathCloseSubpath(result); | |
| 148 path_closed = true; | |
| 149 break; | |
| 150 } | |
| 151 } | |
| 152 | |
| 153 // For valid hit detection, path must be closed. | |
| 154 if (!path_closed) | |
| 155 CGPathCloseSubpath(result); | |
| 156 | |
| 157 // Return immutable copy of result. | |
| 158 return base::ScopedCFTypeRef<CGPathRef>(CGPathCreateCopy(result)); | |
| 159 } | |
| 160 | |
| 125 } // namespace gfx | 161 } // namespace gfx |
| OLD | NEW |