1
- #if defined(DM_PLATFORM_IOS)
1
+ #if defined(DM_PLATFORM_IOS) || defined(DM_PLATFORM_OSX)
2
2
3
3
#include < dmsdk/dlib/array.h>
4
4
#include < dmsdk/dlib/log.h>
7
7
#include < dmsdk/extension/extension.h>
8
8
9
9
#import < Foundation/Foundation.h>
10
- #import < UIKit/UIKit.h>
11
10
#import < WebKit/WebKit.h>
12
11
12
+ #if defined(DM_PLATFORM_IOS)
13
+ #import < UIKit/UIKit.h>
14
+ #endif
15
+
16
+
13
17
#include " webview_common.h"
14
18
15
19
enum CommandType
30
34
void * m_Data;
31
35
const char * m_Url;
32
36
};
33
-
37
+ # if defined(DM_PLATFORM_IOS)
34
38
@interface WebViewDelegate : UIViewController <WKNavigationDelegate >
39
+ #elif defined(DM_PLATFORM_OSX)
40
+ @interface WebViewDelegate : NSViewController <WKNavigationDelegate >
41
+ #endif
35
42
{
36
43
@public int m_WebViewID;
37
44
@public int m_RequestID;
@@ -142,7 +149,6 @@ static void QueueCommand(Command* cmd)
142
149
143
150
namespace dmWebView
144
151
{
145
-
146
152
int Platform_Create (lua_State* L, dmWebView::WebViewInfo* _info)
147
153
{
148
154
// Find a free slot
@@ -163,12 +169,17 @@ int Platform_Create(lua_State* L, dmWebView::WebViewInfo* _info)
163
169
}
164
170
165
171
g_WebView.m_Info [webview_id] = *_info;
166
-
172
+ # if defined(DM_PLATFORM_IOS)
167
173
UIScreen* screen = [UIScreen mainScreen ];
168
174
169
175
WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc ] init ];
170
176
WKWebView *view = [[WKWebView alloc ] initWithFrame: screen.bounds configuration: configuration];
177
+ #elif defined(DM_PLATFORM_OSX)
178
+ NSScreen * screen = [NSScreen mainScreen ];
171
179
180
+ WKWebViewConfiguration *configuration = [[WKWebViewConfiguration alloc ] init ];
181
+ WKWebView *view = [[WKWebView alloc ] initWithFrame: screen.visibleFrame configuration: configuration];
182
+ #endif
172
183
WebViewDelegate* navigationDelegate = [WebViewDelegate alloc ];
173
184
navigationDelegate->m_WebViewID = webview_id;
174
185
navigationDelegate->m_RequestID = 0 ;
@@ -178,8 +189,11 @@ int Platform_Create(lua_State* L, dmWebView::WebViewInfo* _info)
178
189
179
190
g_WebView.m_WebViews [webview_id] = view;
180
191
g_WebView.m_WebViewDelegates [webview_id] = navigationDelegate;
181
-
192
+ # if defined(DM_PLATFORM_IOS)
182
193
UIView * topView = [[[[UIApplication sharedApplication ] keyWindow ] subviews ] lastObject ];
194
+ #elif defined(DM_PLATFORM_OSX)
195
+ NSView * topView = [[[NSApplication sharedApplication ] keyWindow ] contentView ];
196
+ #endif
183
197
[topView addSubview: view];
184
198
view.hidden = TRUE ;
185
199
@@ -281,7 +295,11 @@ int Platform_IsVisible(lua_State* L, int webview_id)
281
295
int Platform_SetPosition (lua_State* L, int webview_id, int x, int y, int width, int height)
282
296
{
283
297
CHECK_WEBVIEW_AND_RETURN ();
298
+ #if defined(DM_PLATFORM_IOS)
284
299
CGRect screenRect = [[UIScreen mainScreen ] bounds ];
300
+ #elif defined(DM_PLATFORM_OSX)
301
+ CGRect screenRect = [[NSScreen mainScreen ] visibleFrame ];
302
+ #endif
285
303
g_WebView.m_WebViews [webview_id].frame = CGRectMake (x, y, width >= 0 ? width : screenRect.size .width , height >= 0 ? height : screenRect.size .height );
286
304
return 0 ;
287
305
}
@@ -379,4 +397,4 @@ int Platform_SetPosition(lua_State* L, int webview_id, int x, int y, int width,
379
397
380
398
} // namespace dmWebView
381
399
382
- #endif // DM_PLATFORM_IOS
400
+ #endif // DM_PLATFORM_IOS || DM_PLATFORM_OSX
0 commit comments