From 9944c82c7c0d349dc0ba982241109695bf34325c Mon Sep 17 00:00:00 2001
From: Shivani Bhardwaj <shivanib134@gmail.com>
Date: Mon, 27 Feb 2017 18:11:20 +0530
Subject: [PATCH 1/3] src: ios_browser: Add support for webview

Add webview support for kivy-ios. Any URL can be opened in webview by
just doing the following:

```
import ios
url = "http://www.google.com"
ios.IOSWebView().open(url)
```

Tested:OK
---
 recipes/ios/src/ios_browser.m | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/recipes/ios/src/ios_browser.m b/recipes/ios/src/ios_browser.m
index 9bc4450..8b70d42 100644
--- a/recipes/ios/src/ios_browser.m
+++ b/recipes/ios/src/ios_browser.m
@@ -11,3 +11,30 @@ void ios_open_url(char *url)
 	NSString *nsurl = [NSString stringWithCString:(char *)url encoding:NSUTF8StringEncoding];
 	[[UIApplication sharedApplication] openURL:[NSURL URLWithString: nsurl]];
 }
+
+/*
+ * Webview support
+ */
+void load_url_webview(char *url)
+{
+    NSString *nsurl = [NSString stringWithCString:(char *)url encoding:NSUTF8StringEncoding];
+    UIWebView *webView = [[UIWebView alloc] initWithFrame: CGRectMake(0, 0, 320, 480)];
+    UIWindow *window = [[UIApplication sharedApplication] keyWindow];
+    UIView *view = [window.rootViewController view];
+    [view addSubview:webView];
+    NSURL *ur = [[NSURL alloc] initWithString: nsurl];
+    NSURLRequest *req = [[NSURLRequest alloc] initWithURL: ur];
+    [webView loadRequest: req];
+    [req release];
+    [ur release];
+  
+    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
+    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
+    [button setTitle:@"X" forState:UIControlStateNormal];
+    button.frame = CGRectMake(0.0, 0.0, 40, 40);
+    [button addTarget:webView
+         action:@selector(removeFromSuperview) forControlEvents:UIControlEventTouchDown];
+    [webView addSubview:button];
+    [button release];
+    [webView release];
+}

From d46da92cc66cfde7c31530e3e66fb5e19fecaaa5 Mon Sep 17 00:00:00 2001
From: Shivani Bhardwaj <shivanib134@gmail.com>
Date: Mon, 27 Feb 2017 18:15:01 +0530
Subject: [PATCH 2/3] Include webview in header

---
 recipes/ios/src/ios_wrapper.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/recipes/ios/src/ios_wrapper.h b/recipes/ios/src/ios_wrapper.h
index 2ad63b4..2558444 100644
--- a/recipes/ios/src/ios_wrapper.h
+++ b/recipes/ios/src/ios_wrapper.h
@@ -4,6 +4,7 @@
 float ios_uiscreen_get_scale(void);
 int ios_uiscreen_get_dpi(void);
 void ios_open_url(char *url);
+void load_url_webview(char *url);
 
 typedef void (*ios_send_email_cb)(char *, void *);
 

From 399694e0dffec31d65ed44c5cabc65e9415deac8 Mon Sep 17 00:00:00 2001
From: Shivani Bhardwaj <shivanib134@gmail.com>
Date: Mon, 27 Feb 2017 18:15:20 +0530
Subject: [PATCH 3/3] Add class IOSWebView and wrapper functions

---
 recipes/ios/src/ios.pyx | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/recipes/ios/src/ios.pyx b/recipes/ios/src/ios.pyx
index 05e9831..13c362c 100644
--- a/recipes/ios/src/ios.pyx
+++ b/recipes/ios/src/ios.pyx
@@ -14,6 +14,7 @@ cdef extern from "ios_wrapper.h":
     int ios_send_email(char *subject, char *text, char *mimetype, char
             *filename, char *filename_alias, ios_send_email_cb cb, void *userdata)
     void ios_open_url(char *url)
+    void load_url_webview(char *url)
     float ios_uiscreen_get_scale()
     int ios_uiscreen_get_dpi()
 
@@ -22,6 +23,29 @@ cdef void _send_email_done(char *status, void *data):
     callback(status)
     Py_DECREF(callback)
 
+#
+#Support for iOS webview
+#
+class IOSWebView(object):
+    def open(self, url):
+        open_url_wbv(url)
+        
+
+def open_url_wbv(url):
+    '''
+    OPEN URL in webview
+
+    :Parameters:
+        `url`: str
+            URL string
+
+    Example for opening up a web page in UIWebview::
+
+        import ios
+        url = "http://www.google.com"
+        ios.IOSWebView().open(url)
+    '''
+    load_url_webview(url)
 
 #
 # Support for webbrowser module