1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 using System.Runtime.InteropServices;
18 using Tizen.NUI.BaseComponents;
22 public class WebViewLite : View
24 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26 internal WebViewLite(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.WebViewLite_SWIGUpcast(cPtr), cMemoryOwn) {
27 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
30 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebViewLite obj) {
31 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
35 /// To make Button instance be disposed.
37 protected override void Dispose(DisposeTypes type)
44 if (type == DisposeTypes.Explicit)
47 //Release your own managed resources here.
48 //You should release all of your own disposable objects here.
52 //Release your own unmanaged resources here.
53 //You should not access any managed member here except static instance.
54 //because the execution order of Finalizes is non-deterministic.
56 DisConnectFromSignals();
58 if (swigCPtr.Handle != global::System.IntPtr.Zero)
63 NDalicPINVOKE.delete_WebViewLite(swigCPtr);
65 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
71 private void DisConnectFromSignals()
74 global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
76 // Use BaseHandle CPtr as current might have been deleted already in derived classes.
77 swigCPtr = GetBaseHandleCPtrHandleRef;
79 if (_loadingFinishedEventCallback != null)
81 FinishedSignal().Disconnect(_loadingFinishedEventCallback);
84 // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
85 // Restore current CPtr.
86 swigCPtr = currentCPtr;
89 private LoadingFinishedCallbackType _loadingFinishedEventCallback;
90 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
91 private delegate void LoadingFinishedCallbackType(global::System.IntPtr data);
92 private EventHandler _loadingFinishedEventHandler;
94 public event EventHandler LoadingFinished
98 if (_loadingFinishedEventHandler == null)
100 NUILog.Debug("[add before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
101 _loadingFinishedEventCallback = OnFinished;
102 FinishedSignal().Connect(_loadingFinishedEventCallback);
103 NUILog.Debug("[add after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
105 _loadingFinishedEventHandler += value;
109 _loadingFinishedEventHandler -= value;
111 if (_loadingFinishedEventHandler == null && FinishedSignal().Empty() == false)
113 NUILog.Debug("[remove before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
114 FinishedSignal().Disconnect(_loadingFinishedEventCallback);
115 NUILog.Debug("[remove after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
119 private void OnFinished(IntPtr data)
121 if (_loadingFinishedEventHandler != null)
123 //here we send all data to user event handlers
124 _loadingFinishedEventHandler(this, null);
129 /// Creates an uninitialized WebViewLite.
131 public WebViewLite () : this (NDalicPINVOKE.WebViewLite_New(), true) {
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
137 /// Copy constructor.
138 /// <param name="webViewLite">WebViewLite to copy. The copied WebViewLite will point at the same implementation</param>
140 public WebViewLite(WebViewLite webViewLite) : this(NDalicPINVOKE.new_WebViewLite__SWIG_1(WebViewLite.getCPtr(webViewLite)), true) {
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 internal WebViewLite Assign(WebViewLite webViewLite) {
145 WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_Assign(swigCPtr, WebViewLite.getCPtr(webViewLite)), false);
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150 internal new static WebViewLite DownCast(BaseHandle handle) {
151 WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_DownCast(BaseHandle.getCPtr(handle)), true);
152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// Creates an internal web view instance (e.g. minimized web engine instance).
158 /// <param name="width">The width of Web</param>
159 /// <param name="height">The height of Web</param>
160 /// <param name="windowX">The x position of window</param>
161 /// <param name="windowY">The y position of window</param>
162 /// <param name="locale">The locale of Web</param>
163 /// <param name="timezoneID">The timezoneID of Web</param>
165 public void CreateInstance(int width, int height, int windowX, int windowY, string locale, string timezoneID) {
166 NDalicPINVOKE.WebViewLite_CreateInstance(swigCPtr, width, height, windowX, windowY, locale, timezoneID);
167 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171 /// Destroys an internal web view instance (e.g. minimized web engine instance).
173 public void DestroyInstance() {
174 NDalicPINVOKE.WebViewLite_DestroyInstance(swigCPtr);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 /// Loads a html file.
180 /// <param name="path">The path of Web</param>
182 public void LoadHtml(string path) {
183 NDalicPINVOKE.WebViewLite_LoadHtml(swigCPtr, path);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 internal WebViewLiteSignal FinishedSignal() {
188 WebViewLiteSignal ret = new WebViewLiteSignal(NDalicPINVOKE.WebViewLite_FinishedSignal(swigCPtr), false);
189 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();