diff options
Diffstat (limited to 'src/views/mac')
-rw-r--r-- | src/views/mac/SkEventNotifier.h | 13 | ||||
-rw-r--r-- | src/views/mac/SkEventNotifier.mm | 68 | ||||
-rw-r--r-- | src/views/mac/SkNSView.h | 51 | ||||
-rw-r--r-- | src/views/mac/SkNSView.mm | 443 | ||||
-rw-r--r-- | src/views/mac/SkOSWindow_Mac.mm | 107 | ||||
-rw-r--r-- | src/views/mac/SkOptionsTableView.h | 39 | ||||
-rw-r--r-- | src/views/mac/SkOptionsTableView.mm | 297 | ||||
-rw-r--r-- | src/views/mac/SkTextFieldCell.h | 14 | ||||
-rw-r--r-- | src/views/mac/SkTextFieldCell.m | 56 | ||||
-rw-r--r-- | src/views/mac/skia_mac.mm | 126 |
10 files changed, 0 insertions, 1214 deletions
diff --git a/src/views/mac/SkEventNotifier.h b/src/views/mac/SkEventNotifier.h deleted file mode 100644 index ea6bbf1e34..0000000000 --- a/src/views/mac/SkEventNotifier.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ -#import <Foundation/Foundation.h> - -@interface SkEventNotifier : NSObject -- (void)receiveSkEvent:(NSNotification*)notification; -+ (void)postTimedSkEvent:(NSTimeInterval)ti; -+ (void)timerFireMethod:(NSTimer*)theTimer; -@end diff --git a/src/views/mac/SkEventNotifier.mm b/src/views/mac/SkEventNotifier.mm deleted file mode 100644 index 0864380d95..0000000000 --- a/src/views/mac/SkEventNotifier.mm +++ /dev/null @@ -1,68 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import "SkEventNotifier.h" -#include "SkEvent.h" -#define SkEventClass @"SkEvenClass" -@implementation SkEventNotifier -- (id)init { - self = [super init]; - if (self) { - //Register as an observer for SkEventClass events and call - //receiveSkEvent: upon receiving the event - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(receiveSkEvent:) - name:SkEventClass - object:nil]; - } - return self; -} - -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; -} - --(BOOL) acceptsFirstResponder { - return YES; -} - -//SkEvent Handers -- (void)receiveSkEvent:(NSNotification *)notification { - if(SkEvent::ProcessEvent()) - SkEvent::SignalNonEmptyQueue(); -} - -+ (void)postTimedSkEvent:(NSTimeInterval)timeInterval { - [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self - selector:@selector(timerFireMethod:) - userInfo:nil repeats:NO]; -} - -+ (void)timerFireMethod:(NSTimer*)theTimer { - SkEvent::ServiceQueueTimer(); -} - -@end -//////////////////////////////////////////////////////////////////////////////// -void SkEvent::SignalNonEmptyQueue() { - //post a SkEventClass event to the default notification queue - NSNotification* notification = [NSNotification notificationWithName:SkEventClass object:nil]; - [[NSNotificationQueue defaultQueue] enqueueNotification:notification - postingStyle:NSPostWhenIdle - coalesceMask:NSNotificationNoCoalescing - forModes:nil]; -} - -void SkEvent::SignalQueueTimer(SkMSec delay) { - if (delay) { - //Convert to seconds - NSTimeInterval ti = delay/(float)SK_MSec1; - [SkEventNotifier postTimedSkEvent:ti]; - } -} diff --git a/src/views/mac/SkNSView.h b/src/views/mac/SkNSView.h deleted file mode 100644 index bf83c61c25..0000000000 --- a/src/views/mac/SkNSView.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import <QuartzCore/QuartzCore.h> -#import <Cocoa/Cocoa.h> -#import "SkWindow.h" - -class SkEvent; -@class SkNSView; - -@protocol SkNSViewOptionsDelegate <NSObject> -@optional -// Called when the view needs to handle adding an SkOSMenu -- (void) view:(SkNSView*)view didAddMenu:(const SkOSMenu*)menu; -- (void) view:(SkNSView*)view didUpdateMenu:(const SkOSMenu*)menu; -@end - -@interface SkNSView : NSView -@property (nonatomic, retain) NSString* fTitle; -#if SK_SUPPORT_GPU -@property (nonatomic, retain) NSOpenGLContext* fGLContext; -#endif -@property (nonatomic, assign) id<SkNSViewOptionsDelegate> fOptionsDelegate; - -- (id)initWithDefaults; -- (void)setNSViewSize:(NSSize)size; -- (void)setUpWindow; -- (void)resizeSkView:(NSSize)newSize; -- (void)setSkTitle:(const char*)title; -- (void)onAddMenu:(const SkOSMenu*)menu; -- (void)onUpdateMenu:(const SkOSMenu*)menu; -- (void)postInvalWithRect:(const SkIRect*)rectOrNil; -- (BOOL)onHandleEvent:(const SkEvent&)event; - -- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType withMSAASampleCount:(int) sampleCount andGetInfo:(SkOSWindow::AttachmentInfo*) info; -- (void)detach; -- (void)present; - -- (void)setVSync:(bool)enable; - -- (void)freeNativeWind; - -@end - -@interface SkNSView() - @property (nonatomic, readwrite) SkOSWindow *fWind; -@end diff --git a/src/views/mac/SkNSView.mm b/src/views/mac/SkNSView.mm deleted file mode 100644 index 9e25f2e7b4..0000000000 --- a/src/views/mac/SkNSView.mm +++ /dev/null @@ -1,443 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import "SkNSView.h" -#include "SkCanvas.h" -#include "SkSurface.h" -#include "SkCGUtils.h" -#include "SkEvent.h" -static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build"); -#include <OpenGL/gl.h> - -//#define FORCE_REDRAW -// Can be dropped when we no longer support 10.6. -#if defined(MAC_OS_X_VERSION_10_7) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_7 - #define RETINA_API_AVAILABLE 1 -#else - #define RETINA_API_AVAILABLE 0 -#endif - -@implementation SkNSView -@synthesize fWind, fTitle, fOptionsDelegate, fGLContext; - -BOOL fRedrawRequestPending; - -- (id)initWithCoder:(NSCoder*)coder { - if ((self = [super initWithCoder:coder])) { - self = [self initWithDefaults]; - [self setUpWindow]; - } - return self; -} - -- (id)initWithFrame:(NSRect)frameRect { - if ((self = [super initWithFrame:frameRect])) { - self = [self initWithDefaults]; - [self setUpWindow]; - } - return self; -} - -- (id)initWithDefaults { -#if RETINA_API_AVAILABLE - [self setWantsBestResolutionOpenGLSurface:YES]; -#endif - fRedrawRequestPending = false; - fWind = NULL; - return self; -} - -- (void)setNSViewSize:(NSSize)size { - NSWindow* w = [self window]; - NSRect f = w.frame; - f.size = size; - [w setFrame:f display:YES]; -} - -- (void)setUpWindow { - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(backingPropertiesChanged:) - name:@"NSWindowDidChangeBackingPropertiesNotification" - object:[self window]]; - if (fWind) { - fWind->setVisibleP(true); - NSSize size = self.frame.size; -#if RETINA_API_AVAILABLE - size = [self convertSizeToBacking:self.frame.size]; -#endif - fWind->resize((int) size.width, (int) size.height); - [[self window] setAcceptsMouseMovedEvents:YES]; - } -} - --(BOOL) isFlipped { - return YES; -} - -- (BOOL)acceptsFirstResponder { - return YES; -} - -- (float)scaleFactor { - NSWindow *window = [self window]; -#if RETINA_API_AVAILABLE - if (window) { - return [window backingScaleFactor]; - } - return [[NSScreen mainScreen] backingScaleFactor]; -#else - if (window) { - return [window userSpaceScaleFactor]; - } - return [[NSScreen mainScreen] userSpaceScaleFactor]; -#endif -} - -- (void)backingPropertiesChanged:(NSNotification *)notification { - CGFloat oldBackingScaleFactor = (CGFloat)[ - [notification.userInfo objectForKey:@"NSBackingPropertyOldScaleFactorKey"] doubleValue - ]; - CGFloat newBackingScaleFactor = [self scaleFactor]; - if (oldBackingScaleFactor == newBackingScaleFactor) { - return; - } - - // TODO: need a better way to force a refresh (that works). - // [fGLContext update] does not appear to update if the point size has not changed, - // even if the backing size has changed. - [self setFrameSize:NSMakeSize(self.frame.size.width + 1, self.frame.size.height + 1)]; -} - -- (void)resizeSkView:(NSSize)newSize { -#if RETINA_API_AVAILABLE - newSize = [self convertSizeToBacking:newSize]; -#endif - if (fWind && (fWind->width() != newSize.width || fWind->height() != newSize.height)) { - fWind->resize((int) newSize.width, (int) newSize.height); - if (fGLContext) { - glClear(GL_STENCIL_BUFFER_BIT); - [fGLContext update]; - } - } -} - -- (void) setFrameSize:(NSSize)newSize { - [super setFrameSize:newSize]; - [self resizeSkView:newSize]; -} - -- (void)dealloc { - [self freeNativeWind]; - self.fGLContext = nil; - self.fTitle = nil; - [super dealloc]; -} - -- (void)freeNativeWind { - delete fWind; - fWind = nil; -} - -//////////////////////////////////////////////////////////////////////////////// - -- (void)drawSkia { - fRedrawRequestPending = false; - if (fWind) { - sk_sp<SkSurface> surface(fWind->makeSurface()); - fWind->draw(surface->getCanvas()); -#ifdef FORCE_REDRAW - fWind->inval(NULL); -#endif - } -} - -- (void)setSkTitle:(const char *)title { - self.fTitle = [NSString stringWithUTF8String:title]; - [[self window] setTitle:self.fTitle]; -} - -- (BOOL)onHandleEvent:(const SkEvent&)evt { - return false; -} - -#include "SkOSMenu.h" -- (void)onAddMenu:(const SkOSMenu*)menu { - [self.fOptionsDelegate view:self didAddMenu:menu]; -} - -- (void)onUpdateMenu:(const SkOSMenu*)menu { - [self.fOptionsDelegate view:self didUpdateMenu:menu]; -} - -- (void)postInvalWithRect:(const SkIRect*)r { - if (!fRedrawRequestPending) { - fRedrawRequestPending = true; - [self setNeedsDisplay:YES]; - [self performSelector:@selector(drawSkia) withObject:nil afterDelay:0]; - } -} -/////////////////////////////////////////////////////////////////////////////// - -#include "SkKey.h" -enum { - SK_MacReturnKey = 36, - SK_MacDeleteKey = 51, - SK_MacEndKey = 119, - SK_MacLeftKey = 123, - SK_MacRightKey = 124, - SK_MacDownKey = 125, - SK_MacUpKey = 126, - SK_Mac0Key = 0x52, - SK_Mac1Key = 0x53, - SK_Mac2Key = 0x54, - SK_Mac3Key = 0x55, - SK_Mac4Key = 0x56, - SK_Mac5Key = 0x57, - SK_Mac6Key = 0x58, - SK_Mac7Key = 0x59, - SK_Mac8Key = 0x5b, - SK_Mac9Key = 0x5c -}; - -static SkKey raw2key(UInt32 raw) -{ - static const struct { - UInt32 fRaw; - SkKey fKey; - } gKeys[] = { - { SK_MacUpKey, kUp_SkKey }, - { SK_MacDownKey, kDown_SkKey }, - { SK_MacLeftKey, kLeft_SkKey }, - { SK_MacRightKey, kRight_SkKey }, - { SK_MacReturnKey, kOK_SkKey }, - { SK_MacDeleteKey, kBack_SkKey }, - { SK_MacEndKey, kEnd_SkKey }, - { SK_Mac0Key, k0_SkKey }, - { SK_Mac1Key, k1_SkKey }, - { SK_Mac2Key, k2_SkKey }, - { SK_Mac3Key, k3_SkKey }, - { SK_Mac4Key, k4_SkKey }, - { SK_Mac5Key, k5_SkKey }, - { SK_Mac6Key, k6_SkKey }, - { SK_Mac7Key, k7_SkKey }, - { SK_Mac8Key, k8_SkKey }, - { SK_Mac9Key, k9_SkKey } - }; - - for (unsigned i = 0; i < SK_ARRAY_COUNT(gKeys); i++) - if (gKeys[i].fRaw == raw) - return gKeys[i].fKey; - return kNONE_SkKey; -} - -- (void)keyDown:(NSEvent *)event { - if (NULL == fWind) - return; - - SkKey key = raw2key([event keyCode]); - if (kNONE_SkKey != key) - fWind->handleKey(key); - else{ - unichar c = [[event characters] characterAtIndex:0]; - fWind->handleChar((SkUnichar)c); - } -} - -- (void)keyUp:(NSEvent *)event { - if (NULL == fWind) - return; - - SkKey key = raw2key([event keyCode]); - if (kNONE_SkKey != key) - fWind->handleKeyUp(key); - // else - // unichar c = [[event characters] characterAtIndex:0]; -} - -static const struct { - unsigned fNSModifierMask; - unsigned fSkModifierMask; -} gModifierMasks[] = { - { NSAlphaShiftKeyMask, kShift_SkModifierKey }, - { NSShiftKeyMask, kShift_SkModifierKey }, - { NSControlKeyMask, kControl_SkModifierKey }, - { NSAlternateKeyMask, kOption_SkModifierKey }, - { NSCommandKeyMask, kCommand_SkModifierKey }, -}; - -static unsigned convertNSModifiersToSk(NSUInteger nsModi) { - unsigned skModi = 0; - for (size_t i = 0; i < SK_ARRAY_COUNT(gModifierMasks); ++i) { - if (nsModi & gModifierMasks[i].fNSModifierMask) { - skModi |= gModifierMasks[i].fSkModifierMask; - } - } - return skModi; -} - -- (void)mouseDown:(NSEvent *)event { - NSPoint p = [event locationInWindow]; - unsigned modi = convertNSModifiersToSk([event modifierFlags]); - - if ([self mouse:p inRect:[self bounds]] && fWind) { - NSPoint loc = [self convertPoint:p fromView:nil]; -#if RETINA_API_AVAILABLE - loc = [self convertPointToBacking:loc]; //y-up - loc.y = -loc.y; -#endif - fWind->handleClick((int) loc.x, (int) loc.y, - SkView::Click::kDown_State, self, modi); - } -} - -- (void)mouseDragged:(NSEvent *)event { - NSPoint p = [event locationInWindow]; - unsigned modi = convertNSModifiersToSk([event modifierFlags]); - - if ([self mouse:p inRect:[self bounds]] && fWind) { - NSPoint loc = [self convertPoint:p fromView:nil]; -#if RETINA_API_AVAILABLE - loc = [self convertPointToBacking:loc]; //y-up - loc.y = -loc.y; -#endif - fWind->handleClick((int) loc.x, (int) loc.y, - SkView::Click::kMoved_State, self, modi); - } -} - -- (void)mouseMoved:(NSEvent *)event { - NSPoint p = [event locationInWindow]; - unsigned modi = convertNSModifiersToSk([event modifierFlags]); - - if ([self mouse:p inRect:[self bounds]] && fWind) { - NSPoint loc = [self convertPoint:p fromView:nil]; -#if RETINA_API_AVAILABLE - loc = [self convertPointToBacking:loc]; //y-up - loc.y = -loc.y; -#endif - fWind->handleClick((int) loc.x, (int) loc.y, - SkView::Click::kMoved_State, self, modi); - } -} - -- (void)mouseUp:(NSEvent *)event { - NSPoint p = [event locationInWindow]; - unsigned modi = convertNSModifiersToSk([event modifierFlags]); - - if ([self mouse:p inRect:[self bounds]] && fWind) { - NSPoint loc = [self convertPoint:p fromView:nil]; -#if RETINA_API_AVAILABLE - loc = [self convertPointToBacking:loc]; //y-up - loc.y = -loc.y; -#endif - fWind->handleClick((int) loc.x, (int) loc.y, - SkView::Click::kUp_State, self, modi); - } -} - -/////////////////////////////////////////////////////////////////////////////// -#include <OpenGL/OpenGL.h> - -static CGLContextObj createGLContext(int msaaSampleCount) { - GLint major, minor; - CGLGetVersion(&major, &minor); - - static const CGLPixelFormatAttribute attributes[] = { - kCGLPFAStencilSize, (CGLPixelFormatAttribute) 8, - kCGLPFAAccelerated, - kCGLPFADoubleBuffer, - kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core, - (CGLPixelFormatAttribute)0 - }; - - CGLPixelFormatObj format; - GLint npix = 0; - if (msaaSampleCount > 0) { - static const int kAttributeCount = SK_ARRAY_COUNT(attributes); - CGLPixelFormatAttribute msaaAttributes[kAttributeCount + 5]; - memcpy(msaaAttributes, attributes, sizeof(attributes)); - SkASSERT(0 == msaaAttributes[kAttributeCount - 1]); - msaaAttributes[kAttributeCount - 1] = kCGLPFASampleBuffers; - msaaAttributes[kAttributeCount + 0] = (CGLPixelFormatAttribute)1; - msaaAttributes[kAttributeCount + 1] = kCGLPFAMultisample; - msaaAttributes[kAttributeCount + 2] = kCGLPFASamples; - msaaAttributes[kAttributeCount + 3] = - (CGLPixelFormatAttribute)msaaSampleCount; - msaaAttributes[kAttributeCount + 4] = (CGLPixelFormatAttribute)0; - CGLChoosePixelFormat(msaaAttributes, &format, &npix); - } - if (!npix) { - CGLChoosePixelFormat(attributes, &format, &npix); - } - CGLContextObj ctx; - CGLCreateContext(format, NULL, &ctx); - CGLDestroyPixelFormat(format); - - static const GLint interval = 1; - CGLSetParameter(ctx, kCGLCPSwapInterval, &interval); - CGLSetCurrentContext(ctx); - return ctx; -} - -- (void)viewDidMoveToWindow { - [super viewDidMoveToWindow]; - - //Attaching view to fGLContext requires that the view to be part of a window, - //and that the NSWindow instance must have a CoreGraphics counterpart (or - //it must NOT be deferred or should have been on screen at least once) - if ([fGLContext view] != self && nil != self.window) { - [fGLContext setView:self]; - } -} -- (bool)attach:(SkOSWindow::SkBackEndTypes)attachType - withMSAASampleCount:(int) sampleCount - andGetInfo:(SkOSWindow::AttachmentInfo*) info { - if (nil == fGLContext) { - CGLContextObj ctx = createGLContext(sampleCount); - SkASSERT(ctx); - fGLContext = [[NSOpenGLContext alloc] initWithCGLContextObj:ctx]; - CGLReleaseContext(ctx); - if (NULL == fGLContext) { - return false; - } - [fGLContext setView:self]; - } - - [fGLContext makeCurrentContext]; - CGLPixelFormatObj format = CGLGetPixelFormat((CGLContextObj)[fGLContext CGLContextObj]); - CGLDescribePixelFormat(format, 0, kCGLPFASamples, &info->fSampleCount); - CGLDescribePixelFormat(format, 0, kCGLPFAStencilSize, &info->fStencilBits); - NSSize size = self.bounds.size; -#if RETINA_API_AVAILABLE - size = [self convertSizeToBacking:size]; -#endif - glViewport(0, 0, (int) size.width, (int) size.height); - glClearColor(0, 0, 0, 0); - glClearStencil(0); - glClear(GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - return true; -} - -- (void)detach { - [fGLContext release]; - fGLContext = nil; -} - -- (void)present { - if (nil != fGLContext) { - [fGLContext flushBuffer]; - } -} - -- (void)setVSync:(bool)enable { - if (fGLContext) { - GLint interval = enable ? 1 : 0; - CGLContextObj ctx = (CGLContextObj)[fGLContext CGLContextObj]; - CGLSetParameter(ctx, kCGLCPSwapInterval, &interval); - } -} -@end diff --git a/src/views/mac/SkOSWindow_Mac.mm b/src/views/mac/SkOSWindow_Mac.mm deleted file mode 100644 index bb00bbcf77..0000000000 --- a/src/views/mac/SkOSWindow_Mac.mm +++ /dev/null @@ -1,107 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import <Cocoa/Cocoa.h> -#include "SkOSWindow_Mac.h" -#include "SkOSMenu.h" -#include "SkTypes.h" -#include "SkWindow.h" -#import "SkNSView.h" -#import "SkEventNotifier.h" -#define kINVAL_NSVIEW_EventType "inval-nsview" - -static constexpr int DEFAULT_W = 1024; -static constexpr int DEFAULT_H = 768; - -static_assert(SK_SUPPORT_GPU, "not_implemented_for_non_gpu_build"); - -SkOSWindow::SkOSWindow(void* hwnd, int w, int h): fHWND(hwnd) { - this->init(hwnd, w, h); -} - -SkOSWindow::SkOSWindow(void* hWnd) : fHWND(hWnd) { - this->init(hWnd, DEFAULT_W, DEFAULT_H); -} - -void SkOSWindow::init(void* hwnd, int w, int h) { - fInvalEventIsPending = false; - fGLContext = NULL; - fNotifier = [[SkEventNotifier alloc] init]; - [(SkNSView*)hwnd setNSViewSize:NSMakeSize(w, h)]; -} - -SkOSWindow::~SkOSWindow() { - [(SkEventNotifier*)fNotifier release]; -} - -void SkOSWindow::onHandleInval(const SkIRect& r) { - if (!fInvalEventIsPending) { - fInvalEventIsPending = true; - (new SkEvent(kINVAL_NSVIEW_EventType, this->getSinkID()))->post(); - } -} - -bool SkOSWindow::onEvent(const SkEvent& evt) { - if (evt.isType(kINVAL_NSVIEW_EventType)) { - fInvalEventIsPending = false; - const SkIRect& r = this->getDirtyBounds(); - [(SkNSView*)fHWND postInvalWithRect:&r]; - [(NSOpenGLContext*)fGLContext update]; - return true; - } - if ([(SkNSView*)fHWND onHandleEvent:evt]) { - return true; - } - return this->INHERITED::onEvent(evt); -} - -bool SkOSWindow::onDispatchClick(int x, int y, Click::State state, void* owner, - unsigned modi) { - return this->INHERITED::onDispatchClick(x, y, state, owner, modi); -} - -void SkOSWindow::onSetTitle(const char title[]) { - [(SkNSView*)fHWND setSkTitle:title]; -} - -void SkOSWindow::onAddMenu(const SkOSMenu* menu) { - [(SkNSView*)fHWND onAddMenu:menu]; -} - -void SkOSWindow::onUpdateMenu(const SkOSMenu* menu) { - [(SkNSView*)fHWND onUpdateMenu:menu]; -} - -bool SkOSWindow::attach(SkBackEndTypes attachType, int sampleCount, bool /*deepColor*/, - AttachmentInfo* info) { - return [(SkNSView*)fHWND attach:attachType withMSAASampleCount:sampleCount andGetInfo:info]; -} - -void SkOSWindow::release() { - [(SkNSView*)fHWND detach]; -} - -void SkOSWindow::present() { - [(SkNSView*)fHWND present]; -} - -void SkOSWindow::closeWindow() { - [[(SkNSView*)fHWND window] close]; -} - -void SkOSWindow::setVsync(bool enable) { - [(SkNSView*)fHWND setVSync:enable]; -} - -bool SkOSWindow::makeFullscreen() { - NSScreen* _Nullable screen = [NSScreen mainScreen]; - if (screen) { - [(SkNSView*)fHWND enterFullScreenMode:(NSScreen* _Nonnull)screen withOptions:nil]; - } - return true; -} - diff --git a/src/views/mac/SkOptionsTableView.h b/src/views/mac/SkOptionsTableView.h deleted file mode 100644 index 8fa03d1fc5..0000000000 --- a/src/views/mac/SkOptionsTableView.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import <Cocoa/Cocoa.h> -#import "SkNSView.h" -#import "SkOSMenu.h" -#import "SkEvent.h" -@interface SkOptionItem : NSObject { - NSCell* fCell; - const SkOSMenu::Item* fItem; -} -@property (nonatomic, assign) const SkOSMenu::Item* fItem; -@property (nonatomic, retain) NSCell* fCell; -@end - -@interface SkOptionsTableView : NSTableView <SkNSViewOptionsDelegate, NSTableViewDelegate, NSTableViewDataSource> { - NSMutableArray* fItems; - const SkTDArray<SkOSMenu*>* fMenus; - BOOL fShowKeys; -} -@property (nonatomic, retain) NSMutableArray* fItems; - -- (void)registerMenus:(const SkTDArray<SkOSMenu*>*)menus; -- (void)updateMenu:(const SkOSMenu*)menu; -- (void)loadMenu:(const SkOSMenu*)menu; -- (IBAction)toggleKeyEquivalents:(id)sender; - -- (NSCell*)createAction; -- (NSCell*)createList:(NSArray*)items current:(int)index; -- (NSCell*)createSlider:(float)value min:(float)min max:(float)max; -- (NSCell*)createSwitch:(BOOL)state; -- (NSCell*)createTextField:(NSString*)placeHolder; -- (NSCell*)createTriState:(NSCellStateValue)state; - -@end diff --git a/src/views/mac/SkOptionsTableView.mm b/src/views/mac/SkOptionsTableView.mm deleted file mode 100644 index 51d4864833..0000000000 --- a/src/views/mac/SkOptionsTableView.mm +++ /dev/null @@ -1,297 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import "SkOptionsTableView.h" -#import "SkTextFieldCell.h" -@implementation SkOptionItem -@synthesize fCell, fItem; -- (void)dealloc { - [fCell release]; - [super dealloc]; -} -@end - -@implementation SkOptionsTableView -@synthesize fItems; - -- (id)initWithCoder:(NSCoder*)coder { - if ((self = [super initWithCoder:coder])) { - self.dataSource = self; - self.delegate = self; - fMenus = NULL; - fShowKeys = YES; - [self setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleNone]; - self.fItems = [NSMutableArray array]; - } - return self; -} - -- (void)dealloc { - self.fItems = nil; - [super dealloc]; -} - -- (void) view:(SkNSView*)view didAddMenu:(const SkOSMenu*)menu {} -- (void) view:(SkNSView*)view didUpdateMenu:(const SkOSMenu*)menu { - [self updateMenu:menu]; -} - -- (IBAction)toggleKeyEquivalents:(id)sender { - fShowKeys = !fShowKeys; - NSMenuItem* item = (NSMenuItem*)sender; - [item setState:fShowKeys]; - [self reloadData]; -} - -- (void)registerMenus:(const SkTDArray<SkOSMenu*>*)menus { - fMenus = menus; - for (int i = 0; i < fMenus->count(); ++i) { - [self loadMenu:(*fMenus)[i]]; - } -} - -- (void)updateMenu:(const SkOSMenu*)menu { - // the first menu is always assumed to be the static, the second is - // repopulated every time over and over again - - // seems pretty weird that we have to get rid of the const'ness here, - // but trying to propagate the const'ness through all the way to the fMenus - // vector was a non-starter. - - int menuIndex = fMenus->find(const_cast<SkOSMenu *>(menu)); - if (menuIndex >= 0 && menuIndex < fMenus->count()) { - NSUInteger first = 0; - for (int i = 0; i < menuIndex; ++i) { - first += (*fMenus)[i]->getCount(); - } - [fItems removeObjectsInRange:NSMakeRange(first, [fItems count] - first)]; - [self loadMenu:menu]; - } - [self reloadData]; -} - -- (NSCellStateValue)triStateToNSState:(SkOSMenu::TriState)state { - if (SkOSMenu::kOnState == state) - return NSOnState; - else if (SkOSMenu::kOffState == state) - return NSOffState; - else - return NSMixedState; -} - -- (void)loadMenu:(const SkOSMenu*)menu { - const SkOSMenu::Item* menuitems[menu->getCount()]; - menu->getItems(menuitems); - for (int i = 0; i < menu->getCount(); ++i) { - const SkOSMenu::Item* item = menuitems[i]; - SkOptionItem* option = [[SkOptionItem alloc] init]; - option.fItem = item; - - if (SkOSMenu::kList_Type == item->getType()) { - int index = 0, count = 0; - SkOSMenu::FindListItemCount(*item->getEvent(), &count); - NSMutableArray* optionstrs = [[NSMutableArray alloc] initWithCapacity:count]; - std::unique_ptr<SkString[]> ada(new SkString[count]); - SkString* options = ada.get(); - SkOSMenu::FindListItems(*item->getEvent(), options); - for (int i = 0; i < count; ++i) - [optionstrs addObject:[NSString stringWithUTF8String:options[i].c_str()]]; - SkOSMenu::FindListIndex(*item->getEvent(), item->getSlotName(), &index); - option.fCell = [self createList:optionstrs current:index]; - [optionstrs release]; - } - else { - bool state = false; - SkString str; - SkOSMenu::TriState tristate; - switch (item->getType()) { - case SkOSMenu::kAction_Type: - option.fCell = [self createAction]; - break; - case SkOSMenu::kSlider_Type: - SkScalar min, max, value; - SkOSMenu::FindSliderValue(*item->getEvent(), item->getSlotName(), &value); - SkOSMenu::FindSliderMin(*item->getEvent(), &min); - SkOSMenu::FindSliderMax(*item->getEvent(), &max); - option.fCell = [self createSlider:value - min:min - max:max]; - break; - case SkOSMenu::kSwitch_Type: - SkOSMenu::FindSwitchState(*item->getEvent(), item->getSlotName(), &state); - option.fCell = [self createSwitch:(BOOL)state]; - break; - case SkOSMenu::kTriState_Type: - SkOSMenu::FindTriState(*item->getEvent(), item->getSlotName(), &tristate); - option.fCell = [self createTriState:[self triStateToNSState:tristate]]; - break; - case SkOSMenu::kTextField_Type: - SkOSMenu::FindText(*item->getEvent(),item->getSlotName(), &str); - option.fCell = [self createTextField:[NSString stringWithUTF8String:str.c_str()]]; - break; - default: - break; - } - } - [fItems addObject:option]; - [option release]; - } -} - -- (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView { - return [self.fItems count]; -} - -- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]]; - if (columnIndex == 0) { - const SkOSMenu::Item* item = ((SkOptionItem*)[fItems objectAtIndex:row]).fItem; - NSString* label = [NSString stringWithUTF8String:item->getLabel()]; - if (fShowKeys) - return [NSString stringWithFormat:@"%@ (%c)", label, item->getKeyEquivalent()]; - else - return label; - } - else - return nil; -} - -- (NSCell *)tableView:(NSTableView *)tableView dataCellForTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - if (tableColumn) { - NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]]; - if (columnIndex == 1) - return [((SkOptionItem*)[fItems objectAtIndex:row]).fCell copy]; - else - return [[[SkTextFieldCell alloc] init] autorelease]; - } - return nil; -} - -- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]]; - if (columnIndex == 1) { - SkOptionItem* option = (SkOptionItem*)[self.fItems objectAtIndex:row]; - NSCell* storedCell = option.fCell; - const SkOSMenu::Item* item = option.fItem; - switch (item->getType()) { - case SkOSMenu::kAction_Type: - break; - case SkOSMenu::kList_Type: - [cell selectItemAtIndex:[(NSPopUpButtonCell*)storedCell indexOfSelectedItem]]; - break; - case SkOSMenu::kSlider_Type: - [cell setFloatValue:[storedCell floatValue]]; - break; - case SkOSMenu::kSwitch_Type: - [cell setState:[(NSButtonCell*)storedCell state]]; - break; - case SkOSMenu::kTextField_Type: - if ([[storedCell stringValue] length] > 0) - [cell setStringValue:[storedCell stringValue]]; - break; - case SkOSMenu::kTriState_Type: - [cell setState:[(NSButtonCell*)storedCell state]]; - break; - default: - break; - } - } - else { - [(SkTextFieldCell*)cell setEditable:NO]; - } -} - -- (void)tableView:(NSTableView *)tableView setObjectValue:(id)anObject forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { - NSInteger columnIndex = [tableView columnWithIdentifier:[tableColumn identifier]]; - if (columnIndex == 1) { - SkOptionItem* option = (SkOptionItem*)[self.fItems objectAtIndex:row]; - NSCell* cell = option.fCell; - const SkOSMenu::Item* item = option.fItem; - switch (item->getType()) { - case SkOSMenu::kAction_Type: - item->postEvent(); - break; - case SkOSMenu::kList_Type: - [(NSPopUpButtonCell*)cell selectItemAtIndex:[anObject intValue]]; - item->setInt([anObject intValue]); - break; - case SkOSMenu::kSlider_Type: - [cell setFloatValue:[anObject floatValue]]; - item->setScalar([anObject floatValue]); - break; - case SkOSMenu::kSwitch_Type: - [cell setState:[anObject boolValue]]; - item->setBool([anObject boolValue]); - break; - case SkOSMenu::kTextField_Type: - if ([anObject length] > 0) { - [cell setStringValue:anObject]; - item->setString([anObject UTF8String]); - } - break; - case SkOSMenu::kTriState_Type: - [cell setState:[anObject intValue]]; - item->setTriState((SkOSMenu::TriState)[anObject intValue]); - break; - default: - break; - } - item->postEvent(); - } -} - -- (NSCell*)createAction{ - NSButtonCell* cell = [[[NSButtonCell alloc] init] autorelease]; - [cell setTitle:@""]; - [cell setButtonType:NSMomentaryPushInButton]; - [cell setBezelStyle:NSSmallSquareBezelStyle]; - return cell; -} - -- (NSCell*)createList:(NSArray*)items current:(int)index { - NSPopUpButtonCell* cell = [[[NSPopUpButtonCell alloc] init] autorelease]; - [cell addItemsWithTitles:items]; - [cell selectItemAtIndex:index]; - [cell setArrowPosition:NSPopUpArrowAtBottom]; - [cell setBezelStyle:NSSmallSquareBezelStyle]; - return cell; -} - -- (NSCell*)createSlider:(float)value min:(float)min max:(float)max { - NSSliderCell* cell = [[[NSSliderCell alloc] init] autorelease]; - [cell setFloatValue:value]; - [cell setMinValue:min]; - [cell setMaxValue:max]; - return cell; -} - -- (NSCell*)createSwitch:(BOOL)state { - NSButtonCell* cell = [[[NSButtonCell alloc] init] autorelease]; - [cell setState:state]; - [cell setTitle:@""]; - [cell setButtonType:NSSwitchButton]; - return cell; -} - -- (NSCell*)createTextField:(NSString*)placeHolder { - SkTextFieldCell* cell = [[[SkTextFieldCell alloc] init] autorelease]; - [cell setEditable:YES]; - [cell setStringValue:@""]; - [cell setPlaceholderString:placeHolder]; - return cell; -} - -- (NSCell*)createTriState:(NSCellStateValue)state { - NSButtonCell* cell = [[[NSButtonCell alloc] init] autorelease]; - [cell setAllowsMixedState:TRUE]; - [cell setTitle:@""]; - [cell setState:(NSInteger)state]; - [cell setButtonType:NSSwitchButton]; - return cell; -} -@end diff --git a/src/views/mac/SkTextFieldCell.h b/src/views/mac/SkTextFieldCell.h deleted file mode 100644 index dfca7ae690..0000000000 --- a/src/views/mac/SkTextFieldCell.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - - -#import <Cocoa/Cocoa.h> -//A text field cell that has vertically centered text -@interface SkTextFieldCell : NSTextFieldCell { - BOOL selectingOrEditing; -} -@end diff --git a/src/views/mac/SkTextFieldCell.m b/src/views/mac/SkTextFieldCell.m deleted file mode 100644 index fbfed05f7f..0000000000 --- a/src/views/mac/SkTextFieldCell.m +++ /dev/null @@ -1,56 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#import "SkTextFieldCell.h" -@implementation SkTextFieldCell -- (NSRect)drawingRectForBounds:(NSRect)theRect { - NSRect newRect = [super drawingRectForBounds:theRect]; - if (selectingOrEditing == NO) { - NSSize textSize = [self cellSizeForBounds:theRect]; - float heightDelta = newRect.size.height - textSize.height; - if (heightDelta > 0) { - newRect.size.height -= heightDelta; - newRect.origin.y += (heightDelta / 2); - } - } - return newRect; -} - -- (void)selectWithFrame:(NSRect)aRect - inView:(NSView *)controlView - editor:(NSText *)textObj - delegate:(id)anObject - start:(NSInteger)selStart - length:(NSInteger)selLength { - aRect = [self drawingRectForBounds:aRect]; - selectingOrEditing = YES; - [super selectWithFrame:aRect - inView:controlView - editor:textObj - delegate:anObject - start:selStart - length:selLength]; - selectingOrEditing = NO; -} - -- (void)editWithFrame:(NSRect)aRect - inView:(NSView *)controlView - editor:(NSText *)textObj - delegate:(id)anObject - event:(NSEvent *)theEvent { - aRect = [self drawingRectForBounds:aRect]; - selectingOrEditing = YES; - [super editWithFrame:aRect - inView:controlView - editor:textObj - delegate:anObject - event:theEvent]; - selectingOrEditing = NO; -} - -@end diff --git a/src/views/mac/skia_mac.mm b/src/views/mac/skia_mac.mm deleted file mode 100644 index b2c59516e0..0000000000 --- a/src/views/mac/skia_mac.mm +++ /dev/null @@ -1,126 +0,0 @@ - -/* - * Copyright 2011 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include <crt_externs.h> -#import <Cocoa/Cocoa.h> -#include "SkApplication.h" -#include "SkGraphics.h" -#include "SkNSView.h" - -@interface MainView : SkNSView { -} -- (id)initWithFrame: (NSRect)frame ; -- (void)dealloc; -- (void)begin; -@end - -@implementation MainView : SkNSView - -- (id)initWithFrame: (NSRect)frame { - self = [super initWithFrame:frame]; - return self; -} - -- (void)dealloc { - delete self.fWind; - [super dealloc]; -} - -- (void)begin { - self.fWind = create_sk_window(self, *_NSGetArgc(), *_NSGetArgv()); - [self setUpWindow]; -} -@end - -@interface AppDelegate : NSObject<NSApplicationDelegate, NSWindowDelegate> { -} -- (id)init; -- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication; -@end - -# -@implementation AppDelegate : NSObject -- (id)init { - self = [super init]; - return self; -} - -- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication { - return TRUE; -} -@end - -int main(int argc, char *argv[]) { - SkGraphics::Init(); - signal(SIGPIPE, SIG_IGN); - NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; - - NSApplication* app = [NSApplication sharedApplication]; - - NSUInteger windowStyle = (NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask); - - NSRect windowRect = NSMakeRect(100, 100, 1000, 1000); - NSWindow* window = [[NSWindow alloc] initWithContentRect:windowRect styleMask:windowStyle backing:NSBackingStoreBuffered defer:NO]; - - NSRect rect = [NSWindow contentRectForFrameRect:windowRect styleMask:windowStyle]; - MainView* customView = [[MainView alloc] initWithFrame:rect]; - [customView setTranslatesAutoresizingMaskIntoConstraints:NO]; - NSView* contentView = window.contentView; - [contentView addSubview:customView]; - NSDictionary *views = NSDictionaryOfVariableBindings(customView); - - [contentView addConstraints: - [NSLayoutConstraint constraintsWithVisualFormat:@"H:|[customView]|" - options:0 - metrics:nil - views:views]]; - - [contentView addConstraints: - [NSLayoutConstraint constraintsWithVisualFormat:@"V:|[customView]|" - options:0 - metrics:nil - views:views]]; - - [customView begin]; - [customView release]; - - [window makeKeyAndOrderFront:NSApp]; - - AppDelegate * appDelegate = [[[AppDelegate alloc] init] autorelease]; - - app.delegate = appDelegate; - - NSMenu* menu=[[NSMenu alloc] initWithTitle:@"AMainMenu"]; - NSMenuItem* item; - NSMenu* subMenu; - - //Create the application menu. - item=[[NSMenuItem alloc] initWithTitle:@"Apple" action:NULL keyEquivalent:@""]; - [menu addItem:item]; - subMenu=[[NSMenu alloc] initWithTitle:@"Apple"]; - [menu setSubmenu:subMenu forItem:item]; - [item release]; - item=[[NSMenuItem alloc] initWithTitle:@"Quit" action:@selector(terminate:) keyEquivalent:@"q"]; - [subMenu addItem:item]; - [item release]; - [subMenu release]; - - //Add the menu to the app. - [app setMenu:menu]; - - [app setActivationPolicy:NSApplicationActivationPolicyRegular]; - - [app run]; - - [menu release]; - [appDelegate release]; - [window release]; - [pool release]; - - return EXIT_SUCCESS; -} |