Release 4.0.0-preview1-00304
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / WebViewLite.cs
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17  
18 using System;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI {
23
24 /// <summary>
25 /// WebViewLite.
26 /// </summary>
27 public class WebViewLite : View
28 {
29   private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30
31   internal WebViewLite(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.WebViewLite_SWIGUpcast(cPtr), cMemoryOwn) {
32     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33   }
34
35   internal static global::System.Runtime.InteropServices.HandleRef getCPtr(WebViewLite obj) {
36     return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37   }
38
39   /// <summary>
40   /// To make Button instance be disposed.
41   /// </summary>
42   protected override void Dispose(DisposeTypes type)
43   {
44       if (disposed)
45       {
46           return;
47       }
48
49       if (type == DisposeTypes.Explicit)
50       {
51           //Called by User
52           //Release your own managed resources here.
53           //You should release all of your own disposable objects here.
54
55       }
56
57       //Release your own unmanaged resources here.
58       //You should not access any managed member here except static instance.
59       //because the execution order of Finalizes is non-deterministic.
60
61       DisConnectFromSignals();
62
63       if (swigCPtr.Handle != global::System.IntPtr.Zero)
64       {
65           if (swigCMemOwn)
66           {
67               swigCMemOwn = false;
68               NDalicPINVOKE.delete_WebViewLite(swigCPtr);
69           }
70           swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
71       }
72
73       base.Dispose(type);
74   }
75
76   private void DisConnectFromSignals()
77   {
78       // Save current CPtr.
79       global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
80
81       // Use BaseHandle CPtr as current might have been deleted already in derived classes.
82       swigCPtr = GetBaseHandleCPtrHandleRef;
83
84       if (_loadingFinishedEventCallback != null)
85       {
86           FinishedSignal().Disconnect(_loadingFinishedEventCallback);
87       }
88
89       // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
90       // Restore current CPtr.
91       swigCPtr = currentCPtr;
92   }
93
94   private LoadingFinishedCallbackType _loadingFinishedEventCallback;
95   [UnmanagedFunctionPointer(CallingConvention.StdCall)]
96   private delegate void LoadingFinishedCallbackType(global::System.IntPtr data);
97   private EventHandler _loadingFinishedEventHandler;
98
99   /// <summary>
100   /// Web View loading finished event.
101   /// </summary>
102   public event EventHandler LoadingFinished
103   {
104       add
105       {
106           if (_loadingFinishedEventHandler == null)
107           {
108               NUILog.Debug("[add before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
109               _loadingFinishedEventCallback = OnFinished;
110               FinishedSignal().Connect(_loadingFinishedEventCallback);
111               NUILog.Debug("[add after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
112           }
113           _loadingFinishedEventHandler += value;
114       }
115       remove
116       {
117           _loadingFinishedEventHandler -= value;
118
119           if (_loadingFinishedEventHandler == null && FinishedSignal().Empty() == false)
120           {
121               NUILog.Debug("[remove before]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
122               FinishedSignal().Disconnect(_loadingFinishedEventCallback);
123               NUILog.Debug("[remove after]FinishedSignal().Empty=" + FinishedSignal().Empty() + " GetConnectionCount=" + FinishedSignal().GetConnectionCount());
124           }
125       }
126   }
127   private void OnFinished(IntPtr data)
128   {
129       if (_loadingFinishedEventHandler != null)
130       {
131           //here we send all data to user event handlers
132           _loadingFinishedEventHandler(this, null);
133       }
134   }
135
136   /// <summary>
137   /// Creates an uninitialized WebViewLite.
138   /// </summary>
139   public WebViewLite () : this (NDalicPINVOKE.WebViewLite_New(), true) {
140       if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
141
142   }
143
144   /// <summary>
145   /// Copy constructor.
146   /// <param name="webViewLite">WebViewLite to copy. The copied WebViewLite will point at the same implementation</param>
147   /// </summary>
148   public WebViewLite(WebViewLite webViewLite) : this(NDalicPINVOKE.new_WebViewLite__SWIG_1(WebViewLite.getCPtr(webViewLite)), true) {
149     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150   }
151
152   internal WebViewLite Assign(WebViewLite webViewLite) {
153     WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_Assign(swigCPtr, WebViewLite.getCPtr(webViewLite)), false);
154     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
155     return ret;
156   }
157
158   internal new static WebViewLite DownCast(BaseHandle handle) {
159     WebViewLite ret = new WebViewLite(NDalicPINVOKE.WebViewLite_DownCast(BaseHandle.getCPtr(handle)), true);
160     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161     return ret;
162   }
163
164   /// <summary>
165   /// Creates an internal web view instance (e.g. minimized web engine instance).
166   /// <param name="width">The width of Web</param>
167   /// <param name="height">The height of Web</param>
168   /// <param name="windowX">The x position of window</param>
169   /// <param name="windowY">The y position of window</param>
170   /// <param name="locale">The locale of Web</param>
171   /// <param name="timezoneID">The timezoneID of Web</param>
172   /// </summary>
173   public void CreateInstance(int width, int height, int windowX, int windowY, string locale, string timezoneID) {
174     NDalicPINVOKE.WebViewLite_CreateInstance(swigCPtr, width, height, windowX, windowY, locale, timezoneID);
175     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176   }
177
178   /// <summary>
179   /// Destroys an internal web view instance (e.g. minimized web engine instance).
180   /// </summary>
181   public void DestroyInstance() {
182     NDalicPINVOKE.WebViewLite_DestroyInstance(swigCPtr);
183     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184   }
185
186   /// <summary>
187   /// Loads a html file.
188   /// <param name="path">The path of Web</param>
189   /// </summary>
190   public void LoadHtml(string path) {
191     NDalicPINVOKE.WebViewLite_LoadHtml(swigCPtr, path);
192     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193   }
194
195   internal WebViewLiteSignal FinishedSignal() {
196     WebViewLiteSignal ret = new WebViewLiteSignal(NDalicPINVOKE.WebViewLite_FinishedSignal(swigCPtr), false);
197     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198     return ret;
199   }
200
201 }
202
203 }