1- #if defined(DM_PLATFORM_IOS)
1+ #if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_OSX)
22
33#include < dmsdk/dlib/array.h>
44#include < dmsdk/dlib/log.h>
77#include < dmsdk/extension/extension.h>
88
99#import < Foundation/Foundation.h>
10- #import < UIKit/UIKit.h>
1110#import < WebKit/WebKit.h>
1211
12+ #if defined(DM_PLATFORM_IOS)
13+ #import < UIKit/UIKit.h>
14+ #endif
15+
16+
1317#include " webview_common.h"
1418
1519enum CommandType
3034 void * m_Data;
3135 const char * m_Url;
3236};
33-
37+ # if defined(DM_PLATFORM_IOS)
3438@interface WebViewDelegate : UIViewController <WKNavigationDelegate >
39+ #elif defined(DM_PLATFORM_OSX)
40+ @interface WebViewDelegate : NSViewController <WKNavigationDelegate >
41+ #endif
3542{
3643 @public int m_WebViewID;
3744 @public int m_RequestID;
@@ -142,7 +149,6 @@ static void QueueCommand(Command* cmd)
142149
143150namespace dmWebView
144151{
145-
146152int Platform_Create (lua_State* L, dmWebView::WebViewInfo* _info)
147153{
148154 // Find a free slot
@@ -163,12 +169,17 @@ int Platform_Create(lua_State* L, dmWebView::WebViewInfo* _info)
163169 }
164170
165171 g_WebView.m_Info [webview_id] = *_info;
166-
172+ # if defined(DM_PLATFORM_IOS)
167173 UIScreen* screen = [UIScreen mainScreen ];
168174
169175 WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc ] init ];
170176 WKWebView *view = [[WKWebView alloc ] initWithFrame: screen.bounds configuration: configuration];
177+ #elif defined(DM_PLATFORM_OSX)
178+ NSScreen * screen = [NSScreen mainScreen ];
171179
180+ WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc ] init ];
181+ WKWebView *view = [[WKWebView alloc ] initWithFrame: screen.visibleFrame configuration: configuration];
182+ #endif
172183 WebViewDelegate* navigationDelegate = [WebViewDelegate alloc ];
173184 navigationDelegate->m_WebViewID = webview_id;
174185 navigationDelegate->m_RequestID = 0 ;
@@ -178,8 +189,11 @@ int Platform_Create(lua_State* L, dmWebView::WebViewInfo* _info)
178189
179190 g_WebView.m_WebViews [webview_id] = view;
180191 g_WebView.m_WebViewDelegates [webview_id] = navigationDelegate;
181-
192+ # if defined(DM_PLATFORM_IOS)
182193 UIView * topView = [[[[UIApplication sharedApplication ] keyWindow ] subviews ] lastObject ];
194+ #elif defined(DM_PLATFORM_OSX)
195+ NSView * topView = [[[NSApplication sharedApplication ] keyWindow ] contentView ];
196+ #endif
183197 [topView addSubview: view];
184198 view.hidden = TRUE ;
185199
@@ -281,7 +295,11 @@ int Platform_IsVisible(lua_State* L, int webview_id)
281295int Platform_SetPosition (lua_State* L, int webview_id, int x, int y, int width, int height)
282296{
283297 CHECK_WEBVIEW_AND_RETURN ();
298+ #if defined(DM_PLATFORM_IOS)
284299 CGRect screenRect = [[UIScreen mainScreen ] bounds ];
300+ #elif defined(DM_PLATFORM_OSX)
301+ CGRect screenRect = [[NSScreen mainScreen ] visibleFrame ];
302+ #endif
285303 g_WebView.m_WebViews [webview_id].frame = CGRectMake (x, y, width >= 0 ? width : screenRect.size .width , height >= 0 ? height : screenRect.size .height );
286304 return 0 ;
287305}
@@ -379,4 +397,4 @@ int Platform_SetPosition(lua_State* L, int webview_id, int x, int y, int width,
379397
380398} // namespace dmWebView
381399
382- #endif // DM_PLATFORM_IOS
400+ #endif // DM_PLATFORM_IOS || DM_PLATFORM_OSX
0 commit comments