summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchungryeol lim <cdark.lim@samsung.com>2017-03-09 17:35:07 +0900
committerKangho Hur <kangho.hur@samsung.com>2017-03-24 13:19:03 +0900
commitb9d538581fc4d06efeb5f80173bf040570c4d43d (patch)
treea41053211709f6b6b43064c16dbb2e54d0fcc324
parent1e105aae58f1303b178316546ac3cd6e10f37757 (diff)
downloadxamarin-forms-b9d538581fc4d06efeb5f80173bf040570c4d43d.tar.gz
xamarin-forms-b9d538581fc4d06efeb5f80173bf040570c4d43d.tar.bz2
xamarin-forms-b9d538581fc4d06efeb5f80173bf040570c4d43d.zip
Add WebViewRenderer
- Depend On : https://review.tizen.org/gerrit/#/c/115231/ (This will be added after WebView Merge) Change-Id: I1fdc0c4420ba7e7a6b48b6ee0ce60d59e31e3691 Signed-off-by: chungryeol lim <cdark.lim@samsung.com>
-rw-r--r--Xamarin.Forms.Platform.Tizen/Renderers/WebViewRenderer.cs177
-rwxr-xr-xXamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj1
-rw-r--r--Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json3
-rw-r--r--packaging/xamarin-forms-tizen.spec1
4 files changed, 181 insertions, 1 deletions
diff --git a/Xamarin.Forms.Platform.Tizen/Renderers/WebViewRenderer.cs b/Xamarin.Forms.Platform.Tizen/Renderers/WebViewRenderer.cs
new file mode 100644
index 00000000..56579fb7
--- /dev/null
+++ b/Xamarin.Forms.Platform.Tizen/Renderers/WebViewRenderer.cs
@@ -0,0 +1,177 @@
+using System;
+using System.ComponentModel;
+using Xamarin.Forms.Internals;
+using TChromium = Tizen.WebView.Chromium;
+using TWebView = Tizen.WebView.WebView;
+
+namespace Xamarin.Forms.Platform.Tizen
+{
+ public class WebViewRenderer : VisualElementRenderer<WebView>, IWebViewDelegate
+ {
+ bool _updating;
+ WebNavigationEvent _eventState;
+ TWebView _control = null;
+
+ public void LoadHtml(string html, string baseUrl)
+ {
+ _control.LoadHtml(html, baseUrl);
+ }
+
+ public void LoadUrl(string url)
+ {
+ if (!string.IsNullOrEmpty(url))
+ {
+ _control.LoadUrl(url);
+ }
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ if (Element != null)
+ {
+ if (_control != null)
+ {
+ _control.StopLoading();
+ _control.LoadStarted -= OnLoadStarted;
+ _control.LoadFinished -= OnLoadFinished;
+ _control.LoadError -= OnLoadError;
+ }
+ Element.EvalRequested -= OnEvalRequested;
+ Element.GoBackRequested -= OnGoBackRequested;
+ Element.GoForwardRequested -= OnGoForwardRequested;
+ }
+ }
+ base.Dispose(disposing);
+ }
+
+ protected override void OnElementChanged(ElementChangedEventArgs<WebView> e)
+ {
+ if (_control == null)
+ {
+ TChromium.Initialize();
+ Forms.Context.Terminated += (sender, arg) => TChromium.Shutdown();
+ _control = new TWebView(Forms.Context.MainWindow);
+ _control.LoadStarted += OnLoadStarted;
+ _control.LoadFinished += OnLoadFinished;
+ _control.LoadError += OnLoadError;
+ SetNativeControl(_control);
+ }
+
+ if (e.OldElement != null)
+ {
+ e.OldElement.EvalRequested -= OnEvalRequested;
+ e.OldElement.GoBackRequested -= OnGoBackRequested;
+ e.OldElement.GoForwardRequested -= OnGoForwardRequested;
+ }
+
+ if (e.NewElement != null)
+ {
+ e.NewElement.EvalRequested += OnEvalRequested;
+ e.NewElement.GoForwardRequested += OnGoForwardRequested;
+ e.NewElement.GoBackRequested += OnGoBackRequested;
+ Load();
+ }
+ base.OnElementChanged(e);
+ }
+
+ protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
+ {
+ if (e.PropertyName == WebView.SourceProperty.PropertyName)
+ Load();
+
+ base.OnElementPropertyChanged(sender, e);
+ }
+
+ void OnLoadError(object sender, global::Tizen.WebView.SmartCallbackLoadErrorArgs e)
+ {
+ string url = e.Url;
+ if (!string.IsNullOrEmpty(url))
+ SendNavigated(new UrlWebViewSource { Url = url }, _eventState, WebNavigationResult.Failure);
+ }
+
+ void OnLoadStarted(object sender, EventArgs e)
+ {
+ string url = _control.Url;
+ if (!string.IsNullOrEmpty(url))
+ {
+ var args = new WebNavigatingEventArgs(_eventState, new UrlWebViewSource { Url = url }, url);
+ Element.SendNavigating(args);
+
+ if (args.Cancel)
+ {
+ _eventState = WebNavigationEvent.NewPage;
+ }
+ }
+ }
+
+ void OnLoadFinished(object sender, EventArgs e)
+ {
+ string url = _control.Url;
+ if (!string.IsNullOrEmpty(url))
+ SendNavigated(new UrlWebViewSource { Url = url }, _eventState, WebNavigationResult.Success);
+
+ _control.SetFocus(true);
+ UpdateCanGoBackForward();
+ }
+
+ void Load()
+ {
+ if (_updating)
+ return;
+
+ if (Element.Source != null)
+ {
+ Element.Source.Load(this);
+ }
+
+ UpdateCanGoBackForward();
+ }
+
+ void OnEvalRequested(object sender, EvalRequested eventArg)
+ {
+ _control.Eval(eventArg.Script);
+ }
+
+ void OnGoBackRequested(object sender, EventArgs eventArgs)
+ {
+ if (_control.CanGoBack())
+ {
+ _eventState = WebNavigationEvent.Back;
+ _control.GoBack();
+ }
+
+ UpdateCanGoBackForward();
+ }
+
+ void OnGoForwardRequested(object sender, EventArgs eventArgs)
+ {
+ if (_control.CanGoForward())
+ {
+ _eventState = WebNavigationEvent.Forward;
+ _control.GoForward();
+ }
+
+ UpdateCanGoBackForward();
+ }
+
+ void SendNavigated(UrlWebViewSource source, WebNavigationEvent evnt, WebNavigationResult result)
+ {
+ _updating = true;
+ ((IElementController)Element).SetValueFromRenderer(WebView.SourceProperty, source);
+ _updating = false;
+
+ Element.SendNavigated(new WebNavigatedEventArgs(evnt, source, source.Url, result));
+
+ UpdateCanGoBackForward();
+ _eventState = WebNavigationEvent.NewPage;
+ }
+
+ void UpdateCanGoBackForward()
+ {
+ Element.CanGoBack = _control.CanGoBack();
+ Element.CanGoForward = _control.CanGoForward();
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj
index 1d50c336..85ad0a47 100755
--- a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj
+++ b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.csproj
@@ -133,6 +133,7 @@
<Compile Include="Renderers\TimePickerRenderer.cs" />
<Compile Include="Renderers\ViewRenderer.cs" />
<Compile Include="Renderers\VisualElementRenderer.cs" />
+ <Compile Include="Renderers\WebViewRenderer.cs" />
<Compile Include="ResourcePath.cs" />
<Compile Include="ResourcesProvider.cs" />
<Compile Include="TizenPlatformServices.cs" />
diff --git a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json
index b77e8cb5..154c2710 100644
--- a/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json
+++ b/Xamarin.Forms.Platform.Tizen/Xamarin.Forms.Platform.Tizen.project.json
@@ -4,7 +4,8 @@
"NETStandard.Library": "1.6.0",
"System.Runtime.Serialization.Xml": "4.1.1",
"Tizen.Applications": "1.1.0",
- "Tizen.System.Information": "1.0.1"
+ "Tizen.System.Information": "1.0.1",
+ "Tizen.WebView": "1.0.0"
},
"frameworks": {
"netstandard1.6": {
diff --git a/packaging/xamarin-forms-tizen.spec b/packaging/xamarin-forms-tizen.spec
index fea2a20e..39ce5b81 100644
--- a/packaging/xamarin-forms-tizen.spec
+++ b/packaging/xamarin-forms-tizen.spec
@@ -30,6 +30,7 @@ BuildRequires: csapi-information-nuget
BuildRequires: csapi-location-nuget
BuildRequires: csapi-maps-nuget
BuildRequires: elm-sharp-nuget
+BuildRequires: csapi-webview-nuget
%description
Allows one to use portable controls subsets that are mapped to native