Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(593)

Unified Diff: ui/gfx/path_mac.mm

Issue 1633403002: MacViews: Add native drop shadow to dialogs on OSX < 10.10. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/gfx/path_mac.mm
diff --git a/ui/gfx/path_mac.mm b/ui/gfx/path_mac.mm
new file mode 100644
index 0000000000000000000000000000000000000000..80c444cf347746b4d06db3ed950e198a23454fd8
--- /dev/null
+++ b/ui/gfx/path_mac.mm
@@ -0,0 +1,111 @@
+// Copyright (c) 2016 The Chromium Authors. All rights reserved.
tapted 2016/01/28 05:59:21 nit: no (c)
karandeepb 2016/02/04 03:39:27 Done.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ui/gfx/path_mac.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "third_party/skia/include/core/SkRegion.h"
+#include "ui/gfx/path.h"
+
+namespace {
+
+// Convert an SkPoint to an NSPoint.
+NSPoint GetNSPointFromSkPoint(const SkPoint& point) {
+ return NSMakePoint(point.x(), point.y());
+}
+
+} // namespace
+
+namespace gfx {
+
+NSBezierPath* CreateNSBezierPathFromSkRegion(const SkRegion& region) {
+ NSBezierPath* result = [NSBezierPath bezierPath];
+ for (SkRegion::Iterator i(region); !i.done(); i.next()) {
+ const SkIRect& rect = i.rect();
+ [result appendBezierPathWithRect:NSMakeRect(rect.x(), rect.y(),
+ rect.width(), rect.height())];
+ }
+ return result;
+}
+
+NSBezierPath* CreateNSBezierPathFromSkPath(const SkPath& path) {
karandeepb 2016/01/27 23:25:03 A simpler implementation like that in path_win.cc
+ NSBezierPath* result = [NSBezierPath bezierPath];
+ SkPath::RawIter iter(path);
+ SkPoint points[4];
+ SkPath::Verb verb;
+ while ((verb = iter.next(points)) != SkPath::kDone_Verb) {
+ switch (verb) {
+ case SkPath::kMove_Verb:
+ [result moveToPoint:GetNSPointFromSkPoint(points[0])];
+ break;
+ case SkPath::kLine_Verb:
+ DCHECK(NSEqualPoints([result currentPoint],
+ GetNSPointFromSkPoint(points[0])));
+ [result lineToPoint:GetNSPointFromSkPoint(points[1])];
+ break;
+ case SkPath::kQuad_Verb: {
tapted 2016/01/28 05:59:21 typically if any `case` has curlies in Chrome, all
karandeepb 2016/02/04 03:39:27 Done.
+ DCHECK(NSEqualPoints([result currentPoint],
+ GetNSPointFromSkPoint(points[0])));
+ SkPoint quad[] = {points[0], points[1], points[2]};
+ // NSBezierPath does not support quadratic bezier curves. Hence convert
+ // to cubic bezier curve.
+ SkPath::ConvertQuadToCubic(quad, points);
tapted 2016/01/28 05:59:21 Does this function exist? Maybe you modified SkPat
karandeepb 2016/02/04 03:39:27 Yeah I did modify SkPath to expose the internal sk
+ [result curveToPoint:GetNSPointFromSkPoint(points[3])
+ controlPoint1:GetNSPointFromSkPoint(points[1])
+ controlPoint2:GetNSPointFromSkPoint(points[2])];
+ break;
+ }
+ case SkPath::kCubic_Verb:
+ DCHECK(NSEqualPoints([result currentPoint],
+ GetNSPointFromSkPoint(points[0])));
+ [result curveToPoint:GetNSPointFromSkPoint(points[3])
+ controlPoint1:GetNSPointFromSkPoint(points[1])
+ controlPoint2:GetNSPointFromSkPoint(points[2])];
+ break;
+ case SkPath::kConic_Verb: {
+ DCHECK(NSEqualPoints([result currentPoint],
+ GetNSPointFromSkPoint(points[0])));
+ // Approximate with quads. Use two for now, increase if more precision
tapted 2016/01/28 05:59:21 I think we can avoid this with [NSBezierPath appen
karandeepb 2016/02/04 03:39:27 I don't think we can approximate a kConicVerb(whic
+ // is needed.
+ const size_t kPow2 = 1;
+ const size_t quadCount = 1 << kPow2;
+ SkPoint quads[1 + 2 * quadCount];
+ SkPath::ConvertConicToQuads(points[0], points[1], points[2],
+ iter.conicWeight(), quads, kPow2);
+ for (size_t i = 0; i < quadCount; i++) {
+ SkPoint quad[] = {quads[2 * i], quads[2 * i + 1], quads[2 * i + 2]};
+ SkPath::ConvertQuadToCubic(quad, points);
+ [result curveToPoint:GetNSPointFromSkPoint(points[3])
+ controlPoint1:GetNSPointFromSkPoint(points[1])
+ controlPoint2:GetNSPointFromSkPoint(points[2])];
+ }
+ break;
+ }
+ case SkPath::kClose_Verb:
+ [result closePath];
+ break;
+ default:
+ NOTREACHED();
+ }
+ }
+
+ // Set up the fill type. NSBezierCurve does not have inverse fill types.
+ if (!path.isInverseFillType()) {
tapted 2016/01/28 05:59:21 instead can we DCHECK(!path.isInverseFillType());
karandeepb 2016/02/04 03:39:27 Done.
+ switch (path.getFillType()) {
+ case SkPath::kWinding_FillType:
+ [result setWindingRule:NSNonZeroWindingRule];
+ break;
+ case SkPath::kEvenOdd_FillType:
+ [result setWindingRule:NSEvenOddWindingRule];
+ break;
+ default:
+ NOTREACHED();
+ }
+ }
+
+ return result;
+}
+
+} // namespace gfx
« no previous file with comments | « ui/gfx/path_mac.h ('k') | ui/gfx/path_mac_unittest.mm » ('j') | ui/gfx/path_mac_unittest.mm » ('J')

Powered by Google App Engine
This is Rietveld 408576698