[NUI] Add ImageUrl
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / WebView / WebHitTestResult.cs
1 /*
2  * Copyright (c) 2021 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.ComponentModel;
20 using Tizen.NUI.BaseComponents;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// It is a class for hit test result of web view.
26     /// </summary>
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class WebHitTestResult : Disposable
29     {
30         internal WebHitTestResult(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
31         {
32         }
33
34         /// This will not be public opened.
35         /// <param name="swigCPtr"></param>
36         [EditorBrowsable(EditorBrowsableState.Never)]
37         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
38         {
39             Interop.WebHitTest.DeleteWebHitTest(swigCPtr);
40         }
41
42         /// <summary>
43         /// Enumeration for context of hit test result.
44         /// </summary>
45         [EditorBrowsable(EditorBrowsableState.Never)]
46         public enum ResultContext
47         {
48             /// <summary>
49             /// Anywhere in the document.
50             /// </summary>
51             [EditorBrowsable(EditorBrowsableState.Never)]
52             Document = 1 << 1,
53
54             /// <summary>
55             /// A hyperlink element.
56             /// </summary>
57             [EditorBrowsable(EditorBrowsableState.Never)]
58             Link = 1 << 2,
59
60             /// <summary>
61             /// An image element.
62             /// </summary>
63             [EditorBrowsable(EditorBrowsableState.Never)]
64             Image = 1 << 3,
65
66             /// <summary>
67             /// a video or audio element.
68             /// </summary>
69             [EditorBrowsable(EditorBrowsableState.Never)]
70             Media = 1 << 4,
71
72             /// <summary>
73             /// The area which is selected.
74             /// </summary>
75             [EditorBrowsable(EditorBrowsableState.Never)]
76             Selection = 1 << 5,
77
78             /// <summary>
79             /// The area which is editable
80             /// </summary>
81             [EditorBrowsable(EditorBrowsableState.Never)]
82             Editable = 1 << 6,
83
84             /// <summary>
85             /// the area which is text
86             /// </summary>
87             [EditorBrowsable(EditorBrowsableState.Never)]
88             Text = 1 << 7,
89         }
90
91         /// <summary>
92         /// Gets the context of the hit test.
93         /// </summary>
94         [EditorBrowsable(EditorBrowsableState.Never)]
95         public ResultContext TestResultContext
96         {
97             get
98             {
99                 return (ResultContext)Interop.WebHitTest.GetResultContext(SwigCPtr);
100             }
101         }
102
103         /// <summary>
104         /// Gets the link url of the hit test.
105         /// </summary>
106         [EditorBrowsable(EditorBrowsableState.Never)]
107         public string LinkUrl
108         {
109             get
110             {
111                 return Interop.WebHitTest.GetLinkUri(SwigCPtr);
112             }
113         }
114
115         /// <summary>
116         /// Gets the link title of the hit test.
117         /// </summary>
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public string LinkTitle
120         {
121             get
122             {
123                 return Interop.WebHitTest.GetLinkTitle(SwigCPtr);
124             }
125         }
126
127         /// <summary>
128         /// Gets the link label of the hit test.
129         /// </summary>
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         public string LinkLabel
132         {
133             get
134             {
135                 return Interop.WebHitTest.GetLinkLabel(SwigCPtr);
136             }
137         }
138
139         /// <summary>
140         /// Gets the image url of the hit test.
141         /// </summary>
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         public string ImageUrl
144         {
145             get
146             {
147                 return Interop.WebHitTest.GetImageUri(SwigCPtr);
148             }
149         }
150
151         /// <summary>
152         /// Gets the media url of the hit test.
153         /// </summary>
154         [EditorBrowsable(EditorBrowsableState.Never)]
155         public string MediaUrl
156         {
157             get
158             {
159                 return Interop.WebHitTest.GetMediaUri(SwigCPtr);
160             }
161         }
162
163         /// <summary>
164         /// Gets the tag name of hit element of the hit test.
165         /// </summary>
166         [EditorBrowsable(EditorBrowsableState.Never)]
167         public string TagName
168         {
169             get
170             {
171                 return Interop.WebHitTest.GetTagName(SwigCPtr);
172             }
173         }
174
175         /// <summary>
176         /// Gets the node value of hit element of the hit test.
177         /// </summary>
178         [EditorBrowsable(EditorBrowsableState.Never)]
179         public string NodeValue
180         {
181             get
182             {
183                 return Interop.WebHitTest.GetNodeValue(SwigCPtr);
184             }
185         }
186
187         /// <summary>
188         /// Gets the attributes of hit element of the hit test.
189         /// The attributes include the standard W3C HTML attributes.
190         /// For example, if <img src="img_girl.jpg" /> is hit,
191         /// key 'src', value 'img_girl.jpg' would be stored in the map.
192         /// </summary>
193         [EditorBrowsable(EditorBrowsableState.Never)]
194         public PropertyMap Attributes
195         {
196             get
197             {
198                 IntPtr arributesIntPtr = Interop.WebHitTest.GetAttributes(SwigCPtr);
199                 return new PropertyMap(arributesIntPtr, true);
200             }
201         }
202
203         /// <summary>
204         /// Gets the image file name extension of hit element of the hit test.
205         /// </summary>
206         [EditorBrowsable(EditorBrowsableState.Never)]
207         public string ImageFileNameExtension
208         {
209             get
210             {
211                 return Interop.WebHitTest.GetImageFileNameExtension(SwigCPtr);
212             }
213         }
214
215         /// <summary>
216         /// Gets the image of hit element of the hit test.
217         /// </summary>
218         [EditorBrowsable(EditorBrowsableState.Never)]
219         public ImageView Image
220         {
221             get
222             {
223                 IntPtr bufferIntPtr = Interop.WebHitTest.GetImageBuffer(SwigCPtr);
224                 PixelData pixelData = new PixelData(bufferIntPtr, true);
225                 ImageUrl url = pixelData.GenerateUrl();
226                 ImageView image = new ImageView(url.ToString());
227                 image.Size = new Size(pixelData.GetWidth(), pixelData.GetHeight());
228                 pixelData.Dispose();
229                 return image;
230             }
231         }
232     }
233 }