Add C# binding for web view lite.
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / WebViewLite.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
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
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 *
15 */
16 using System;
17 using System.Runtime.InteropServices;
18 using Tizen.NUI.BaseComponents;
19
20 namespace Tizen.NUI {
21
22 public class WebViewLite : View
23 {
24   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
25
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);
28   }
29
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;
32   }
33
34   /// <summary>
35   /// To make Button instance be disposed.
36   /// </summary>
37   protected override void Dispose(DisposeTypes type)
38   {
39       if (disposed)
40       {
41           return;
42       }
43
44       if (type == DisposeTypes.Explicit)
45       {
46           //Called by User
47           //Release your own managed resources here.
48           //You should release all of your own disposable objects here.
49
50       }
51
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.
55
56       DisConnectFromSignals();
57
58       if (swigCPtr.Handle != global::System.IntPtr.Zero)
59       {
60           if (swigCMemOwn)
61           {
62               swigCMemOwn = false;
63               NDalicPINVOKE.delete_WebViewLite(swigCPtr);
64           }
65           swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
66       }
67
68       base.Dispose(type);
69   }
70
71   private void DisConnectFromSignals()
72   {
73       // Save current CPtr.
74       global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
75
76       // Use BaseHandle CPtr as current might have been deleted already in derived classes.
77       swigCPtr = GetBaseHandleCPtrHandleRef;
78
79       if (_loadingFinishedEventCallback != null)
80       {
81           FinishedSignal().Disconnect(_loadingFinishedEventCallback);
82       }
83
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;
87   }
88
89   private LoadingFinishedCallbackType _loadingFinishedEventCallback;
90   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
91   private delegate void LoadingFinishedCallbackType(global::System.IntPtr data);
92   private EventHandler _loadingFinishedEventHandler;
93
94   public event EventHandler LoadingFinished
95   {
96       add
97       {
98           if (_loadingFinishedEventHandler == null)
99           {
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());
104           }
105           _loadingFinishedEventHandler += value;
106       }
107       remove
108       {
109           _loadingFinishedEventHandler -= value;
110
111           if (_loadingFinishedEventHandler == null && FinishedSignal().Empty() == false)
112           {
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());
116           }
117       }
118   }
119   private void OnFinished(IntPtr data)
120   {
121       if (_loadingFinishedEventHandler != null)
122       {
123           //here we send all data to user event handlers
124           _loadingFinishedEventHandler(this, null);
125       }
126   }
127
128   /// <summary>
129   /// Creates an uninitialized WebViewLite.
130   /// </summary>
131   public WebViewLite () : this (NDalicPINVOKE.WebViewLite_New(), true) {
132       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133
134   }
135
136   /// <summary>
137   /// Copy constructor.
138   /// <param name="webViewLite">WebViewLite to copy. The copied WebViewLite will point at the same implementation</param>
139   /// </summary>
140   public WebViewLite(WebViewLite webViewLite) : this(NDalicPINVOKE.new_WebViewLite__SWIG_1(WebViewLite.getCPtr(webViewLite)), true) {
141     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
142   }
143
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();
147     return ret;
148   }
149
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();
153     return ret;
154   }
155
156   /// <summary>
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>
164   /// </summary>
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();
168   }
169
170   /// <summary>
171   /// Destroys an internal web view instance (e.g. minimized web engine instance).
172   /// </summary>
173   public void DestroyInstance() {
174     NDalicPINVOKE.WebViewLite_DestroyInstance(swigCPtr);
175     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176   }
177
178   /// <summary>
179   /// Loads a html file.
180   /// <param name="path">The path of Web</param>
181   /// </summary>
182   public void LoadHtml(string path) {
183     NDalicPINVOKE.WebViewLite_LoadHtml(swigCPtr, path);
184     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185   }
186
187   internal WebViewLiteSignal FinishedSignal() {
188     WebViewLiteSignal ret = new WebViewLiteSignal(NDalicPINVOKE.WebViewLite_FinishedSignal(swigCPtr), false);
189     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
190     return ret;
191   }
192
193 }
194
195 }