Skip to content

Commit c2c17a5

Browse files
committed
[[ BrowserWidget ]] Add iOS UIWebView browser implementation
[[ BrowserWidget ]] Rework factory handling
1 parent 9060882 commit c2c17a5

9 files changed

Lines changed: 669 additions & 27 deletions

engine/src/native-layer-ios.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class MCNativeLayerIOS : public MCNativeLayer
3636
virtual void OnToolChanged(Tool p_new_tool);
3737
virtual void OnLayerChanged();
3838

39-
MCNativeLayerIOS(MCWidgetRef);
39+
MCNativeLayerIOS(MCWidgetRef, void *p_native_view);
4040
~MCNativeLayerIOS();
4141

42+
virtual bool GetNativeView(void *&r_view);
43+
4244
private:
4345

4446
MCWidgetRef m_widget;

engine/src/native-layer-ios.mm

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@
5353
#include "mblcontrol.h"
5454

5555

56-
MCNativeLayerIOS::MCNativeLayerIOS(MCWidgetRef p_widget) :
56+
MCNativeLayerIOS::MCNativeLayerIOS(MCWidgetRef p_widget, void *p_native_view) :
5757
m_widget(p_widget),
58-
m_view(nil)
58+
m_view([(UIView*)p_native_view retain])
5959
{
6060
;
6161
}
@@ -66,7 +66,6 @@
6666
{
6767
doDetach();
6868
MCIPhoneRunBlockOnMainFiber(^{[m_view release];});
69-
[m_view release];
7069
}
7170
}
7271

@@ -118,19 +117,6 @@
118117
{
119118
MCWidget* t_widget = MCWidgetGetHost(m_widget);
120119

121-
if (m_view == nil)
122-
{
123-
// TESTING
124-
/*
125-
UIButton *t_button;
126-
t_button = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
127-
[t_button setTitle:@"Native button" forState:UIControlStateNormal];
128-
[t_button setHidden:YES];
129-
m_view = t_button;
130-
doSetRect(m_widget->getrect());
131-
*/
132-
}
133-
134120
// Act as if there was a re-layer to put the widget in the right place
135121
doRelayer();
136122

@@ -241,9 +227,20 @@
241227
return MCIPhoneGetView();
242228
}
243229

230+
bool MCNativeLayerIOS::GetNativeView(void *&r_view)
231+
{
232+
if (m_view == nil)
233+
return false;
234+
235+
r_view = m_view;
236+
return true;
237+
}
238+
244239
////////////////////////////////////////////////////////////////////////////////
245240

246-
MCNativeLayer* MCWidget::createNativeLayer()
241+
MCNativeLayer *MCNativeLayer::CreateNativeLayer(MCWidgetRef p_widget, void *p_native_view)
247242
{
248-
return new MCNativeLayerIOS(getwidget());
243+
return new MCNativeLayerIOS(p_widget, p_native_view);
249244
}
245+
246+
////////////////////////////////////////////////////////////////////////////////

libbrowser/libbrowser.gyp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,30 @@
2727
[
2828
'include/libbrowser.h',
2929

30-
'src/libbrowser_memory.cpp',
3130
'src/libbrowser.cpp',
31+
'src/libbrowser_internal.h',
32+
'src/libbrowser_memory.cpp',
33+
'src/libbrowser_value.cpp',
34+
3235
'src/libbrowser_cef.cpp',
3336
'src/libbrowser_cef.h',
3437
'src/libbrowser_cef_lnx.cpp',
3538
'src/libbrowser_cef_osx.mm',
3639
'src/libbrowser_cef_win.cpp',
3740
'src/libbrowser_cefshared_osx.cpp',
3841
'src/libbrowser_cefshared_lnx.cpp',
39-
'src/libbrowser_value.cpp',
4042

4143
'src/libbrowser_win.rc.h',
4244
'src/libbrowser_win.rc',
4345

4446
'src/signal_restore_posix.cpp',
4547
'src/WebAuthenticationPanel.m',
48+
49+
'src/libbrowser_uiwebview.h',
50+
'src/libbrowser_uiwebview.mm',
51+
52+
'src/libbrowser_desktop_factories.cpp',
53+
'src/libbrowser_ios_factories.cpp',
4654
],
4755

4856
'conditions':
@@ -55,6 +63,7 @@
5563
'sources!':
5664
[
5765
'src/libbrowser_cef.cpp',
66+
'src/libbrowser_desktop_factories.cpp',
5867
],
5968
},
6069
],
@@ -95,6 +104,17 @@
95104
},
96105
],
97106

107+
[
108+
'OS != "ios"',
109+
{
110+
'sources!':
111+
[
112+
'src/libbrowser_uiwebview.mm',
113+
'src/libbrowser_ios_factories.cpp',
114+
],
115+
},
116+
],
117+
98118
[
99119
'OS == "mac"',
100120
{
@@ -211,6 +231,7 @@
211231
'OS != "mac" and OS != "win" and OS != "linux"',
212232
{
213233
'type': 'none',
234+
'mac_bundle': 0,
214235
},
215236
],
216237

libbrowser/src/libbrowser.cpp

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,46 @@ void MCBrowserLibraryFinalize()
134134
//////////
135135

136136
// Factory
137-
138-
extern bool MCCefBrowserFactoryCreate(MCBrowserFactoryRef &r_factory);
139-
bool MCBrowserFactoryGet(const char *p_factory, MCBrowserFactoryRef &r_factory)
137+
bool MCBrowserFactoryEnsureAvailable(MCBrowserFactoryMap &p_map, MCBrowserFactoryRef &r_instance)
140138
{
141-
if (s_browser_factory == nil && !MCCefBrowserFactoryCreate(s_browser_factory))
139+
if (p_map.instance != nil)
140+
{
141+
r_instance = p_map.instance;
142+
return true;
143+
}
144+
145+
if (p_map.constructor == nil)
146+
return false;
147+
148+
if (!p_map.constructor(p_map.instance))
142149
return false;
143150

144-
r_factory = s_browser_factory;
151+
r_instance = p_map.instance;
145152
return true;
146153
}
147154

155+
bool MCBrowserFactoryGet(const char *p_factory, MCBrowserFactoryRef &r_factory)
156+
{
157+
if (s_factory_list == nil)
158+
return false; // no browser factories available;
159+
160+
if (p_factory == nil || MCCStringIsEmpty(p_factory) || MCCStringEqualCaseless(p_factory, "default"))
161+
{
162+
// use first available browser factory
163+
for (uint32_t i = 0; s_factory_list[i].factory_id != nil; i++)
164+
{
165+
if (MCBrowserFactoryEnsureAvailable(s_factory_list[i], r_factory))
166+
return true;
167+
}
168+
}
169+
170+
for (uint32_t i = 0; s_factory_list[i].factory_id != nil; i++)
171+
if (MCCStringEqualCaseless(p_factory, s_factory_list[i].factory_id))
172+
return MCBrowserFactoryEnsureAvailable(s_factory_list[i], r_factory);
173+
174+
return false;
175+
}
176+
148177
bool MCBrowserFactoryCreateBrowser(MCBrowserFactoryRef p_factory, void *p_display, void *p_parent_window, MCBrowserRef &r_browser)
149178
{
150179
if (p_factory == nil)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright (C) 2015 Runtime Revolution Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include <core.h>
18+
19+
#include "libbrowser_internal.h"
20+
21+
extern bool MCCefBrowserFactoryCreate(MCBrowserFactoryRef &r_factory);
22+
23+
MCBrowserFactoryMap s_factory_list[] =
24+
{
25+
{ "cef", nil, MCCefBrowserFactoryCreate },
26+
};
27+

libbrowser/src/libbrowser_internal.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class MCBrowserBase : public MCBrowser
3737
void SetEventHandler(MCBrowserEventHandler *p_handler);
3838
void SetJavaScriptHandler(MCBrowserJavaScriptHandler *p_handler);
3939

40-
protected:
4140
void OnNavigationBegin(bool p_in_frame, const char *p_url);
4241
void OnNavigationComplete(bool p_in_frame, const char *p_url);
4342
void OnNavigationFailed(bool p_in_frame, const char *p_url, const char *p_error);
@@ -54,6 +53,19 @@ class MCBrowserBase : public MCBrowser
5453

5554
////////////////////////////////////////////////////////////////////////////////
5655

56+
typedef bool (*MCBrowserFactoryCreationFunc)(MCBrowserFactoryRef &r_factory);
57+
struct MCBrowserFactoryMap
58+
{
59+
const char *factory_id;
60+
MCBrowserFactoryRef instance;
61+
62+
MCBrowserFactoryCreationFunc constructor;
63+
};
64+
65+
extern MCBrowserFactoryMap s_factory_list[];
66+
67+
////////////////////////////////////////////////////////////////////////////////
68+
5769
bool MCBrowserAddRunloopAction(MCBrowserRunloopCallback p_callback, void *p_context);
5870
void MCBrowserRemoveRunloopAction(MCBrowserRunloopCallback p_callback, void *p_context);
5971
bool MCBrowserRunloopWait();
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* Copyright (C) 2015 Runtime Revolution Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#include <core.h>
18+
19+
#include "libbrowser_internal.h"
20+
21+
extern bool MCUIWebViewBrowserFactoryCreate(MCBrowserFactoryRef &r_factory);
22+
23+
MCBrowserFactoryMap s_factory_list[] =
24+
{
25+
{ "uiwebview", nil, MCUIWebViewBrowserFactoryCreate },
26+
};
27+
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Copyright (C) 2003-2015 Runtime Revolution Ltd.
2+
3+
This file is part of LiveCode.
4+
5+
LiveCode is free software; you can redistribute it and/or modify it under
6+
the terms of the GNU General Public License v3 as published by the Free
7+
Software Foundation.
8+
9+
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
10+
WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12+
for more details.
13+
14+
You should have received a copy of the GNU General Public License
15+
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
16+
17+
#ifndef __LIBBROWSER_IOS_H__
18+
#define __LIBBROWSER_IOS_H__
19+
20+
#include "libbrowser_internal.h"
21+
22+
@class MCUIWebViewBrowserDelegate;
23+
24+
class MCUIWebViewBrowser : public MCBrowserBase
25+
{
26+
public:
27+
MCUIWebViewBrowser();
28+
virtual ~MCUIWebViewBrowser();
29+
30+
bool Init(void);
31+
32+
virtual void *GetNativeLayer();
33+
34+
virtual bool GetRect(MCBrowserRect &r_rect);
35+
virtual bool SetRect(const MCBrowserRect &p_rect);
36+
37+
virtual bool GetBoolProperty(MCBrowserProperty p_property, bool &r_value);
38+
virtual bool SetBoolProperty(MCBrowserProperty p_property, bool p_value);
39+
40+
virtual bool GetStringProperty(MCBrowserProperty p_property, char *&r_utf8_string);
41+
virtual bool SetStringProperty(MCBrowserProperty p_property, const char *p_utf8_string);
42+
43+
virtual bool GoBack();
44+
virtual bool GoForward();
45+
virtual bool GoToURL(const char *p_url);
46+
virtual bool EvaluateJavaScript(const char *p_script, char *&r_result);
47+
48+
protected:
49+
bool GetUrl(char *& r_url);
50+
51+
bool GetHTMLText(char *&r_htmltext);
52+
bool SetHTMLText(const char *p_htmltext);
53+
54+
bool GetScrollingEnabled(bool& r_value);
55+
bool SetScrollingEnabled(bool p_value);
56+
57+
// Browser-specific actions
58+
bool ExecAdvance();
59+
bool ExecRetreat();
60+
bool ExecReload();
61+
bool ExecStop();
62+
bool ExecExecute(const char * p_script);
63+
bool ExecLoad(const char *p_url, const char *p_html);
64+
65+
UIScrollView *GetScrollView(void);
66+
67+
private:
68+
bool GetView(UIWebView *&r_view);
69+
70+
UIWebView *m_view;
71+
MCUIWebViewBrowserDelegate *m_delegate;
72+
};
73+
74+
//////////
75+
76+
bool MCUIWebViewBrowserFactoryCreate(MCBrowserFactoryRef &r_factory);
77+
78+
#endif // __LIBBROWSER_IOS_H__

0 commit comments

Comments
 (0)