Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.

Commit fbc44bd

Browse files
committed
[[ libbrowser ]] Add new propererties to libbrowser
This patch adds extra properties to libbrowser that allow controlling aspects of the webview that are available on iOS. New properties: * scrollEnabled - the browser contents can be scrolled * scrollCanBounce - the contents can be scrolled beyond the edge of the view, bouncing back once released * canGoBack - the browser can navigate to the previous site in its history * canGoForward - the browser can navigate to the next site in its history * autoFit - browser contents are scaled to fit the width of the view * dataDetectorTypes - types of content that are detected within the browser * allowsInlineMediaPlayback - video plays within browser view or plays fullscreen * mediaPlaybackRequiresUserAction - media doesn't play unless triggered by the user These have been added to the iOS browser implementation. *Note*: modifying the 'dataDetectorTypes', 'allowsInlineMediaPlayback', 'mediaPlaybackRequiresUserAction' will reset the browser - these should ideally be set once when initialising the browser.
1 parent 3035347 commit fbc44bd

File tree

10 files changed

+628
-56
lines changed

10 files changed

+628
-56
lines changed

libbrowser/include/libbrowser.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,39 @@ enum MCBrowserNavigationType
3030
kMCBrowserNavigationTypeOther,
3131
};
3232

33+
enum MCBrowserDataDetectorType
34+
{
35+
kMCBrowserDataDetectorTypeNone = 0,
36+
37+
kMCBrowserDataDetectorTypePhoneNumberBit = 0,
38+
kMCBrowserDataDetectorTypeLinkBit = 1,
39+
kMCBrowserDataDetectorTypeEmailAddressBit = 2,
40+
kMCBrowserDataDetectorTypeMapAddressBit = 3,
41+
kMCBrowserDataDetectorTypeCalendarEventBit = 4,
42+
kMCBrowserDataDetectorTypeTrackingNumberBit = 5,
43+
kMCBrowserDataDetectorTypeFlightNumberBit = 6,
44+
kMCBrowserDataDetectorTypeLookupSuggestionBit = 7,
45+
46+
kMCBrowserDataDetectorTypePhoneNumber = (1 << kMCBrowserDataDetectorTypePhoneNumberBit),
47+
kMCBrowserDataDetectorTypeLink = (1 << kMCBrowserDataDetectorTypeLinkBit),
48+
kMCBrowserDataDetectorTypeEmailAddress = (1 << kMCBrowserDataDetectorTypeEmailAddressBit),
49+
kMCBrowserDataDetectorTypeMapAddress = (1 << kMCBrowserDataDetectorTypeMapAddressBit),
50+
kMCBrowserDataDetectorTypeCalendarEvent = (1 << kMCBrowserDataDetectorTypeCalendarEventBit),
51+
kMCBrowserDataDetectorTypeTrackingNumber = (1 << kMCBrowserDataDetectorTypeTrackingNumberBit),
52+
kMCBrowserDataDetectorTypeFlightNumber = (1 << kMCBrowserDataDetectorTypeFlightNumberBit),
53+
kMCBrowserDataDetectorTypeLookupSuggestion = (1 << kMCBrowserDataDetectorTypeLookupSuggestionBit),
54+
55+
kMCBrowserDataDetectorTypeAll =
56+
kMCBrowserDataDetectorTypePhoneNumber |
57+
kMCBrowserDataDetectorTypeLink |
58+
kMCBrowserDataDetectorTypeEmailAddress |
59+
kMCBrowserDataDetectorTypeMapAddress |
60+
kMCBrowserDataDetectorTypeCalendarEvent |
61+
kMCBrowserDataDetectorTypeTrackingNumber |
62+
kMCBrowserDataDetectorTypeFlightNumber |
63+
kMCBrowserDataDetectorTypeLookupSuggestion,
64+
};
65+
3366
class MCBrowserRefCounted
3467
{
3568
public:
@@ -109,6 +142,15 @@ enum MCBrowserProperty
109142
kMCBrowserJavaScriptHandlers, /* STRING */
110143

111144
kMCBrowseriOSDelayRequests, /* BOOLEAN */
145+
kMCBrowseriOSAllowsInlineMediaPlayback, /* BOOLEAN */
146+
kMCBrowseriOSMediaPlaybackRequiresUserAction, /* BOOLEAN */
147+
kMCBrowseriOSAutoFit, /* BOOLEAN */
148+
149+
kMCBrowserCanGoForward, /* BOOLEAN */
150+
kMCBrowserCanGoBack, /* BOOLEAN */
151+
kMCBrowserDataDetectorTypes, /* INTEGER */
152+
kMCBrowserScrollEnabled, /* BOOLEAN */
153+
kMCBrowserScrollCanBounce, /* BOOLEAN */
112154
};
113155

114156
// Convenience struct for rect properties
@@ -137,6 +179,9 @@ class MCBrowser : public MCBrowserRefCounted
137179
virtual bool GetStringProperty(MCBrowserProperty p_property, char *&r_utf8_string) = 0;
138180
virtual bool SetStringProperty(MCBrowserProperty p_property, const char *p_utf8_string) = 0;
139181

182+
virtual bool GetIntegerProperty(MCBrowserProperty p_property, int32_t &r_value) = 0;
183+
virtual bool SetIntegerProperty(MCBrowserProperty p_property, int32_t p_value) = 0;
184+
140185
virtual bool GoBack() = 0;
141186
virtual bool GoForward() = 0;
142187
virtual bool GoToURL(const char *p_url) = 0;
@@ -306,6 +351,9 @@ MC_BROWSER_DLLEXPORT bool MCBrowserSetBoolProperty(MCBrowserRef p_browser, MCBro
306351
MC_BROWSER_DLLEXPORT bool MCBrowserGetStringProperty(MCBrowserRef p_browser, MCBrowserProperty p_property, char *&r_utf8_string);
307352
MC_BROWSER_DLLEXPORT bool MCBrowserSetStringProperty(MCBrowserRef p_browser, MCBrowserProperty p_property, const char *p_utf8_string);
308353

354+
MC_BROWSER_DLLEXPORT bool MCBrowserGetIntegerProperty(MCBrowserRef p_browser, MCBrowserProperty p_property, int32_t &r_value);
355+
MC_BROWSER_DLLEXPORT bool MCBrowserSetIntegerProperty(MCBrowserRef p_browser, MCBrowserProperty p_property, int32_t p_value);
356+
309357
MC_BROWSER_DLLEXPORT bool MCBrowserGoBack(MCBrowserRef p_browser);
310358
MC_BROWSER_DLLEXPORT bool MCBrowserGoForward(MCBrowserRef p_browser);
311359
MC_BROWSER_DLLEXPORT bool MCBrowserGoToURL(MCBrowserRef p_browser, const char *p_url);

libbrowser/src/libbrowser.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,24 @@ bool MCBrowserSetStringProperty(MCBrowserRef p_browser, MCBrowserProperty p_prop
529529
return p_browser->SetStringProperty(p_property, p_value);
530530
}
531531

532+
MC_BROWSER_DLLEXPORT_DEF
533+
bool MCBrowserGetIntegerProperty(MCBrowserRef p_browser, MCBrowserProperty p_property, int32_t &r_value)
534+
{
535+
if (p_browser == nil)
536+
return false;
537+
538+
return p_browser->GetIntegerProperty(p_property, r_value);
539+
}
540+
541+
MC_BROWSER_DLLEXPORT_DEF
542+
bool MCBrowserSetIntegerProperty(MCBrowserRef p_browser, MCBrowserProperty p_property, int32_t p_value)
543+
{
544+
if (p_browser == nil)
545+
return false;
546+
547+
return p_browser->SetIntegerProperty(p_property, p_value);
548+
}
549+
532550
MC_BROWSER_DLLEXPORT_DEF
533551
bool MCBrowserGoBack(MCBrowserRef p_browser)
534552
{

libbrowser/src/libbrowser_android.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -694,6 +694,28 @@ class MCAndroidWebViewBrowser : public MCBrowserBase
694694
return true;
695695
}
696696

697+
virtual bool SetIntegerProperty(MCBrowserProperty p_property, int32_t p_value)
698+
{
699+
switch (p_property)
700+
{
701+
default:
702+
break;
703+
}
704+
705+
return true;
706+
}
707+
708+
virtual bool GetIntegerProperty(MCBrowserProperty p_property, int32_t &r_value)
709+
{
710+
switch (p_property)
711+
{
712+
default:
713+
break;
714+
}
715+
716+
return true;
717+
}
718+
697719
virtual bool GoBack()
698720
{
699721
MCAndroidObjectRemoteCall(m_view, "goBack", "vi", nil, 1);

libbrowser/src/libbrowser_cef.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2006,6 +2006,28 @@ bool MCCefBrowserBase::GetStringProperty(MCBrowserProperty p_property, char *&r_
20062006
return true;
20072007
}
20082008

2009+
bool MCCefBrowserBase::SetIntegerProperty(MCBrowserProperty p_property, int32_t p_value)
2010+
{
2011+
switch (p_property)
2012+
{
2013+
default:
2014+
break;
2015+
}
2016+
2017+
return true;
2018+
}
2019+
2020+
bool MCCefBrowserBase::GetIntegerProperty(MCBrowserProperty p_property, int32_t &r_value)
2021+
{
2022+
switch (p_property)
2023+
{
2024+
default:
2025+
break;
2026+
}
2027+
2028+
return true;
2029+
}
2030+
20092031
////////////////////////////////////////////////////////////////////////////////
20102032
// Cef browser factory
20112033

libbrowser/src/libbrowser_cef.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ class MCCefBrowserBase : public MCBrowserBase
5151

5252
virtual bool GetBoolProperty(MCBrowserProperty p_property, bool &r_value);
5353
virtual bool SetBoolProperty(MCBrowserProperty p_property, bool p_value);
54-
5554
virtual bool GetStringProperty(MCBrowserProperty p_property, char *&r_utf8_string);
5655
virtual bool SetStringProperty(MCBrowserProperty p_property, const char *p_utf8_string);
57-
56+
virtual bool GetIntegerProperty(MCBrowserProperty p_property, int32_t &r_value);
57+
virtual bool SetIntegerProperty(MCBrowserProperty p_property, int32_t p_value);
58+
5859
virtual bool GoBack();
5960
virtual bool GoForward();
6061
virtual bool GoToURL(const char *p_url);

libbrowser/src/libbrowser_internal.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,28 @@ inline void MCBrowserMemoryClear(T &p_struct)
184184

185185
////////////////////////////////////////////////////////////////////////////////
186186

187+
inline void MCBrowserCStringAssign(char *&x_variable, char *p_value)
188+
{
189+
if (x_variable == p_value)
190+
return;
191+
192+
if (x_variable != nil)
193+
MCCStringFree(x_variable);
194+
x_variable = p_value;
195+
}
196+
197+
inline bool MCBrowserCStringAssignCopy(char *&x_variable, const char *p_value)
198+
{
199+
char *t_copy;
200+
if (!MCCStringClone(p_value, t_copy))
201+
return false;
202+
203+
MCBrowserCStringAssign(x_variable, t_copy);
204+
return true;
205+
}
206+
207+
////////////////////////////////////////////////////////////////////////////////
208+
187209
struct MCBrowserValue
188210
{
189211
MCBrowserValueType type;

libbrowser/src/libbrowser_osx_webview.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ class MCWebViewBrowser : public MCBrowserBase
4040

4141
virtual bool GetBoolProperty(MCBrowserProperty p_property, bool &r_value);
4242
virtual bool SetBoolProperty(MCBrowserProperty p_property, bool p_value);
43-
4443
virtual bool GetStringProperty(MCBrowserProperty p_property, char *&r_utf8_string);
4544
virtual bool SetStringProperty(MCBrowserProperty p_property, const char *p_utf8_string);
46-
45+
virtual bool GetIntegerProperty(MCBrowserProperty p_property, int32_t &r_value);
46+
virtual bool SetIntegerProperty(MCBrowserProperty p_property, int32_t p_value);
47+
4748
virtual bool GoBack();
4849
virtual bool GoForward();
4950
virtual bool GoToURL(const char *p_url);

libbrowser/src/libbrowser_osx_webview.mm

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,28 @@ + (BOOL)isSelectorExcludedFromWebScript:(SEL)selector
757757
return true;
758758
}
759759

760+
bool MCWebViewBrowser::SetIntegerProperty(MCBrowserProperty p_property, int32_t p_value)
761+
{
762+
switch (p_property)
763+
{
764+
default:
765+
break;
766+
}
767+
768+
return true;
769+
}
770+
771+
bool MCWebViewBrowser::GetIntegerProperty(MCBrowserProperty p_property, int32_t &r_value)
772+
{
773+
switch (p_property)
774+
{
775+
default:
776+
break;
777+
}
778+
779+
return true;
780+
}
781+
760782
bool MCWebViewBrowser::GetRect(MCBrowserRect &r_rect)
761783
{
762784
WebView *t_view;

libbrowser/src/libbrowser_wkwebview.h

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
#include "libbrowser_internal.h"
2121

22+
////////////////////////////////////////////////////////////////////////////////
23+
2224
@class com_livecode_libbrowser_MCWKWebViewNavigationDelegate;
2325
@class MCWKWebViewScriptMessageHandler;
2426

@@ -37,10 +39,11 @@ class MCWKWebViewBrowser : public MCBrowserBase
3739

3840
virtual bool GetBoolProperty(MCBrowserProperty p_property, bool &r_value);
3941
virtual bool SetBoolProperty(MCBrowserProperty p_property, bool p_value);
40-
4142
virtual bool GetStringProperty(MCBrowserProperty p_property, char *&r_utf8_string);
4243
virtual bool SetStringProperty(MCBrowserProperty p_property, const char *p_utf8_string);
43-
44+
virtual bool GetIntegerProperty(MCBrowserProperty p_property, int32_t &r_value);
45+
virtual bool SetIntegerProperty(MCBrowserProperty p_property, int32_t p_value);
46+
4447
virtual bool GoBack();
4548
virtual bool GoForward();
4649
virtual bool GoToURL(const char *p_url);
@@ -58,6 +61,10 @@ class MCWKWebViewBrowser : public MCBrowserBase
5861
bool SetVerticalScrollbarEnabled(bool p_value);
5962
bool GetHorizontalScrollbarEnabled(bool& r_value);
6063
bool SetHorizontalScrollbarEnabled(bool p_value);
64+
bool GetScrollEnabled(bool& r_value);
65+
bool SetScrollEnabled(bool p_value);
66+
bool GetScrollCanBounce(bool& r_value);
67+
bool SetScrollCanBounce(bool p_value);
6168

6269
bool GetJavaScriptHandlers(char *&r_handlers);
6370
bool SetJavaScriptHandlers(const char *p_handlers);
@@ -66,27 +73,54 @@ class MCWKWebViewBrowser : public MCBrowserBase
6673
bool SetUserAgent(const char *p_useragent);
6774

6875
bool GetIsSecure(bool& r_value);
76+
77+
bool GetCanGoForward(bool& r_value);
78+
bool GetCanGoBack(bool& r_value);
6979

7080
bool GetAllowUserInteraction(bool& r_value);
7181
bool SetAllowUserInteraction(bool p_value);
7282

7383
bool GetDelayRequests(bool& r_value);
7484
bool SetDelayRequests(bool p_value);
85+
86+
bool GetAutoFit(bool& r_value);
87+
bool SetAutoFit(bool p_value);
88+
89+
bool GetDataDetectorTypes(int32_t &r_types);
90+
bool SetDataDetectorTypes(int32_t p_types);
91+
92+
bool GetAllowsInlineMediaPlayback(bool& r_value);
93+
bool SetAllowsInlineMediaPlayback(bool p_value);
94+
95+
bool GetMediaPlaybackRequiresUserAction(bool& r_value);
96+
bool SetMediaPlaybackRequiresUserAction(bool p_value);
7597

7698
private:
77-
bool GetView(WKWebView *&r_view);
99+
bool GetWebView(WKWebView *&r_view);
100+
bool GetContainerView(UIView *&r_view);
101+
102+
bool Reconfigure(void);
78103

79104
bool SyncJavaScriptHandlers(NSArray *p_handlers);
80105

81106
WKWebView *m_view;
107+
UIView *m_container_view;
82108
com_livecode_libbrowser_MCWKWebViewNavigationDelegate *m_delegate;
83109
MCWKWebViewScriptMessageHandler *m_message_handler;
110+
WKUserContentController *m_content_controller;
111+
WKWebViewConfiguration *m_configuration;
84112

85113
char *m_js_handlers;
114+
char *m_htmltext;
115+
char *m_url;
116+
117+
bool m_autofit;
86118
};
87119

88-
//////////
120+
////////////////////////////////////////////////////////////////////////////////
89121

90122
bool MCWKWebViewBrowserFactoryCreate(MCBrowserFactoryRef &r_factory);
91123

124+
////////////////////////////////////////////////////////////////////////////////
125+
92126
#endif // __LIBBROWSER_WKWEBVIEW_H__

0 commit comments

Comments
 (0)