shiny/driver: use new style mask and event constants on OSX 10.12

Some variables had been deprected since macOS, so we should use the new recommend one
and declare them on older OS X releases using Conditional compilation.

Fixes golang/go#17413.

Change-Id: Ib7e92e7e9bddb8d7940bd85e1f3db4535fcdbef0
Reviewed-on: https://go-review.googlesource.com/31543
Reviewed-by: David Crawshaw <crawshaw@golang.org>
diff --git a/shiny/driver/gldriver/cocoa.m b/shiny/driver/gldriver/cocoa.m
index 1d07af7..8da18f1 100644
--- a/shiny/driver/gldriver/cocoa.m
+++ b/shiny/driver/gldriver/cocoa.m
@@ -14,6 +14,24 @@
 #import <Foundation/Foundation.h>
 #import <OpenGL/gl3.h>
 
+#define IS_MAC_SIERRA_OR_LATER (NSAppKitVersionNumber - NSAppKitVersionNumber10_11)
+
+// The variables did not exist on older OS X releases,
+// we use the old variables deprecated on macOS to define them.
+#if !IS_MAC_SIERRA_OR_LATER
+enum
+{
+    NSEventTypeScrollWheel = NSScrollWheel,
+    NSEventTypeKeyDown = NSKeyDown
+};
+enum {
+    NSWindowStyleMaskTitled = NSTitledWindowMask,
+    NSWindowStyleMaskResizable = NSResizableWindowMask,
+    NSWindowStyleMaskMiniaturizable = NSMiniaturizableWindowMask,
+    NSWindowStyleMaskClosable = NSClosableWindowMask
+};
+#endif
+
 void makeCurrentContext(uintptr_t context) {
 	NSOpenGLContext* ctx = (NSOpenGLContext*)context;
 	[ctx makeCurrentContext];
@@ -107,7 +125,7 @@
 	double y = (h - p.y) * scale - 1; // flip origin from bottom-left to top-left.
 
 	double dx, dy;
-	if (theEvent.type == NSScrollWheel) {
+	if (theEvent.type == NSEventTypeScrollWheel) {
 		dx = theEvent.scrollingDeltaX;
 		dy = theEvent.scrollingDeltaY;
 	}
@@ -161,7 +179,7 @@
 	uint8_t direction;
 	if ([theEvent isARepeat]) {
 		direction = 0;
-	} else if (theEvent.type == NSKeyDown) {
+	} else if (theEvent.type == NSEventTypeKeyDown) {
 		direction = 1;
 	} else {
 		direction = 2;
@@ -250,12 +268,12 @@
 		NSRect rect = NSMakeRect(0, 0, w, h);
 
 		NSWindow* window = [[NSWindow alloc] initWithContentRect:rect
-				styleMask:NSTitledWindowMask
+				styleMask:NSWindowStyleMaskTitled
 				backing:NSBackingStoreBuffered
 				defer:NO];
-		window.styleMask |= NSResizableWindowMask;
-		window.styleMask |= NSMiniaturizableWindowMask ;
-		window.styleMask |= NSClosableWindowMask;
+		window.styleMask |= NSWindowStyleMaskResizable;
+		window.styleMask |= NSWindowStyleMaskMiniaturizable;
+		window.styleMask |= NSWindowStyleMaskClosable;
 		window.title = name;
 		window.displaysWhenScreenProfileChanges = YES;
 		[window cascadeTopLeftFromPoint:NSMakePoint(20,20)];