1 /* 2 * Copyright 2016 Google Inc. 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef Window_mac_DEFINED 9 #define Window_mac_DEFINED 10 11 #include "../Window.h" 12 #include "SkTDynamicHash.h" 13 14 #import <Cocoa/Cocoa.h> 15 16 namespace sk_app { 17 18 class Window_mac : public Window { 19 public: Window_mac()20 Window_mac() 21 : INHERITED() 22 , fWindow(nil) 23 , fMSAASampleCount(1) 24 , fIsMouseDown(false) {} ~Window_mac()25 ~Window_mac() override { 26 this->closeWindow(); 27 } 28 29 bool initWindow(); 30 31 void setTitle(const char*) override; 32 void show() override; 33 34 bool attach(BackendType) override; 35 onInval()36 void onInval() override {} 37 38 static void PaintWindows(); 39 static void HandleWindowEvent(const NSEvent* event); 40 GetKey(const Window_mac & w)41 static const NSInteger& GetKey(const Window_mac& w) { 42 return w.fWindowNumber; 43 } 44 Hash(const NSInteger & windowNumber)45 static uint32_t Hash(const NSInteger& windowNumber) { 46 return windowNumber; 47 } 48 needsPaint()49 bool needsPaint() { return this->fIsContentInvalidated; } 50 window()51 NSWindow* window() { return fWindow; } 52 void closeWindow(); 53 54 void resetMouse(); 55 56 private: 57 void handleEvent(const NSEvent* event); 58 59 NSWindow* fWindow; 60 NSInteger fWindowNumber; 61 int fMSAASampleCount; 62 bool fIsMouseDown; 63 NSPoint fMouseDownPos; 64 uint32_t fMouseModifiers; 65 66 static SkTDynamicHash<Window_mac, NSInteger> gWindowMap; 67 68 typedef Window INHERITED; 69 }; 70 71 } // namespace sk_app 72 73 #endif 74