[NUI] Save the cropMask value internally in ImageView (#3983)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / ImageView.cs
1 /*
2 * Copyright(c) 2019 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 using System;
18 using System.Runtime.InteropServices;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.BaseComponents
23 {
24
25     /// <summary>
26     /// ImageView is a class for displaying an image resource.<br />
27     /// An instance of ImageView can be created using a URL or an image instance.<br />
28     /// </summary>
29     /// <since_tizen> 3 </since_tizen>
30     public class ImageView : View
31     {
32         static ImageView() { }
33
34         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         public static readonly BindableProperty ResourceUrlProperty = BindableProperty.Create(nameof(ImageView.ResourceUrl), typeof(string), typeof(ImageView), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
37         {
38             var imageView = (ImageView)bindable;
39
40             if (newValue is Selector<string> selector)
41             {
42                 imageView.ResourceUrlSelector = selector;
43             }
44             else
45             {
46                 imageView.resourceUrlSelector?.Reset(imageView);
47                 imageView.SetResourceUrl((string)newValue);
48             }
49         },
50         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
51         {
52             var imageView = (ImageView)bindable;
53             string ret = "";
54
55             PropertyMap imageMap = new PropertyMap();
56             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
57             imageMap.Find(ImageVisualProperty.URL)?.Get(out ret);
58             return ret;
59         }));
60
61         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(ImageView.Image), typeof(PropertyMap), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
64         {
65             var imageView = (ImageView)bindable;
66             if (newValue != null)
67             {
68                 PropertyMap map = (PropertyMap)newValue;
69                 if (imageView.IsCreateByXaml)
70                 {
71                     string url = "", alphaMaskURL = "", auxiliaryImageURL = "";
72                     string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
73                     PropertyValue urlValue = map.Find(NDalic.ImageVisualUrl);
74                     bool ret = false;
75                     if (urlValue != null) ret = urlValue.Get(out url);
76                     PropertyMap mmap = new PropertyMap();
77                     if (ret && url.StartsWith("*Resource*"))
78                     {
79                         url = url.Replace("*Resource*", resource);
80                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(url));
81                     }
82
83                     ret = false;
84                     PropertyValue alphaMaskUrlValue = map.Find(NDalic.ImageVisualAlphaMaskUrl);
85                     if (alphaMaskUrlValue != null) ret = alphaMaskUrlValue.Get(out alphaMaskURL);
86                     if (ret && alphaMaskURL.StartsWith("*Resource*"))
87                     {
88                         alphaMaskURL = alphaMaskURL.Replace("*Resource*", resource);
89                         mmap.Insert(NDalic.ImageVisualUrl, new PropertyValue(alphaMaskURL));
90                     }
91
92                     ret = false;
93                     PropertyValue auxiliaryImageURLValue = map.Find(NDalic.ImageVisualAuxiliaryImageUrl);
94                     if (auxiliaryImageURLValue != null) ret = auxiliaryImageURLValue.Get(out auxiliaryImageURL);
95                     if (ret && auxiliaryImageURL.StartsWith("*Resource*"))
96                     {
97                         auxiliaryImageURL = auxiliaryImageURL.Replace("*Resource*", resource);
98                         mmap.Insert(NDalic.ImageVisualAuxiliaryImageUrl, new PropertyValue(auxiliaryImageURL));
99                     }
100
101                     map.Merge(mmap);
102                 }
103                 if (imageView._border == null)
104                 {
105                     Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE, new Tizen.NUI.PropertyValue(map));
106                 }
107             }
108         }),
109         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
110         {
111             var imageView = (ImageView)bindable;
112             if (imageView._border == null)
113             {
114                 PropertyMap temp = new PropertyMap();
115                 Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(temp);
116                 return temp;
117             }
118             else
119             {
120                 return null;
121             }
122         }));
123
124         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
125         [EditorBrowsable(EditorBrowsableState.Never)]
126         public static readonly BindableProperty PreMultipliedAlphaProperty = BindableProperty.Create(nameof(PreMultipliedAlpha), typeof(bool), typeof(ImageView), false, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
127         {
128             var imageView = (ImageView)bindable;
129             if (newValue != null)
130             {
131                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha, new Tizen.NUI.PropertyValue((bool)newValue));
132             }
133         }),
134         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
135         {
136             var imageView = (ImageView)bindable;
137             bool temp = false;
138             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PreMultipliedAlpha).Get(out temp);
139             return temp;
140         }));
141
142         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143         [EditorBrowsable(EditorBrowsableState.Never)]
144         public static readonly BindableProperty PixelAreaProperty = BindableProperty.Create(nameof(PixelArea), typeof(RelativeVector4), typeof(ImageView), null, propertyChanged: (BindableProperty.BindingPropertyChangedDelegate)((bindable, oldValue, newValue) =>
145         {
146             var imageView = (ImageView)bindable;
147             if (newValue != null)
148             {
149                 Tizen.NUI.Object.SetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea, new Tizen.NUI.PropertyValue((RelativeVector4)newValue));
150             }
151         }),
152         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
153         {
154             var imageView = (ImageView)bindable;
155             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
156             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.PixelArea).Get(temp);
157             RelativeVector4 relativeTemp = new RelativeVector4(temp.X, temp.Y, temp.Z, temp.W);
158             return relativeTemp;
159         }));
160
161         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
162         [EditorBrowsable(EditorBrowsableState.Never)]
163         public static readonly BindableProperty BorderProperty = BindableProperty.Create(nameof(Border), typeof(Rectangle), typeof(ImageView), null, propertyChanged: (bindable, oldValue, newValue) =>
164         {
165             var imageView = (ImageView)bindable;
166             imageView.borderSelector?.Reset(imageView);
167
168             if (newValue is Selector<Rectangle> selector)
169             {
170                 if (selector.HasAll()) imageView.SetBorder(selector.All);
171                 else imageView.borderSelector = new TriggerableSelector<Rectangle>(imageView, selector, imageView.SetBorder, true);
172             }
173             else
174             {
175                 imageView.SetBorder((Rectangle)newValue);
176             }
177         },
178         defaultValueCreator: (bindable) =>
179         {
180             var imageView = (ImageView)bindable;
181             return imageView._border;
182         });
183
184         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
185         [EditorBrowsable(EditorBrowsableState.Never)]
186         public static readonly BindableProperty BorderOnlyProperty = BindableProperty.Create(nameof(BorderOnly), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
187         {
188             var imageView = (ImageView)bindable;
189             if (newValue != null)
190             {
191                 imageView.UpdateImage(NpatchImageVisualProperty.BorderOnly, new PropertyValue((bool)newValue));
192             }
193         },
194         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
195         {
196             var imageView = (ImageView)bindable;
197             bool ret = false;
198             PropertyMap imageMap = new PropertyMap();
199             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
200             imageMap.Find(ImageVisualProperty.BorderOnly)?.Get(out ret);
201             return ret;
202         }));
203
204         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
205         [EditorBrowsable(EditorBrowsableState.Never)]
206         public static readonly BindableProperty SynchronosLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
207         {
208             var imageView = (ImageView)bindable;
209             if (newValue != null)
210             {
211                 imageView._synchronousLoading = (bool)newValue;
212                 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
213             }
214         },
215         defaultValueCreator: (bindable) =>
216         {
217             var imageView = (ImageView)bindable;
218             return imageView._synchronousLoading;
219         });
220
221         /// This will be public opened in tizen_7.0 after ACR done. Before ACR, need to be hidden as inhouse API.
222         [EditorBrowsable(EditorBrowsableState.Never)]
223         public static readonly BindableProperty SynchronousLoadingProperty = BindableProperty.Create(nameof(SynchronousLoading), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
224         {
225             var imageView = (ImageView)bindable;
226             if (newValue != null)
227             {
228                 imageView._synchronousLoading = (bool)newValue;
229                 imageView.UpdateImage(NpatchImageVisualProperty.SynchronousLoading, new PropertyValue((bool)newValue));
230             }
231         },
232         defaultValueCreator: (bindable) =>
233         {
234             var imageView = (ImageView)bindable;
235             return imageView._synchronousLoading;
236         });
237
238         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
239         [EditorBrowsable(EditorBrowsableState.Never)]
240         public static readonly BindableProperty OrientationCorrectionProperty = BindableProperty.Create(nameof(OrientationCorrection), typeof(bool), typeof(ImageView), false, propertyChanged: (bindable, oldValue, newValue) =>
241         {
242             var imageView = (ImageView)bindable;
243             if (newValue != null)
244             {
245                 imageView.UpdateImage(ImageVisualProperty.OrientationCorrection, new PropertyValue((bool)newValue));
246             }
247         },
248         defaultValueCreator: (BindableProperty.CreateDefaultValueDelegate)((bindable) =>
249         {
250             var imageView = (ImageView)bindable;
251
252             bool ret = false;
253             PropertyMap imageMap = new PropertyMap();
254             Tizen.NUI.Object.GetProperty((HandleRef)imageView.SwigCPtr, ImageView.Property.IMAGE).Get(imageMap);
255             imageMap?.Find(ImageVisualProperty.OrientationCorrection)?.Get(out ret);
256
257             return ret;
258         }));
259
260         private EventHandler<ResourceReadyEventArgs> _resourceReadyEventHandler;
261         private ResourceReadyEventCallbackType _resourceReadyEventCallback;
262         private EventHandler<ResourceLoadedEventArgs> _resourceLoadedEventHandler;
263         private _resourceLoadedCallbackType _resourceLoadedCallback;
264
265         private Rectangle _border;
266         private string _resourceUrl = "";
267         private bool _synchronousLoading = false;
268         private string _alphaMaskUrl = null;
269         private int _desired_width = -1;
270         private int _desired_height = -1;
271          private bool _cropToMask = false;
272         private VisualFittingModeType _fittingMode = VisualFittingModeType.Fill;
273         private TriggerableSelector<string> resourceUrlSelector;
274         private TriggerableSelector<Rectangle> borderSelector;
275
276         /// <summary>
277         /// Creates an initialized ImageView.
278         /// </summary>
279         /// <since_tizen> 3 </since_tizen>
280         public ImageView() : this(Interop.ImageView.New(), true)
281         {
282             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283         }
284
285         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
286         [EditorBrowsable(EditorBrowsableState.Never)]
287         public ImageView(ViewStyle viewStyle) : this(Interop.ImageView.New(), true, viewStyle)
288         {
289         }
290
291         /// <summary>
292         /// Creates an initialized ImageView with setting the status of shown or hidden.
293         /// </summary>
294         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
295         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
296         [EditorBrowsable(EditorBrowsableState.Never)]
297         public ImageView(bool shown) : this(Interop.ImageView.New(), true)
298         {
299             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300             SetVisible(shown);
301         }
302
303         /// <summary>
304         /// Creates an initialized ImageView from a URL to an image resource.<br />
305         /// If the string is empty, ImageView will not display anything.<br />
306         /// </summary>
307         /// <param name="url">The URL of the image resource to display.</param>
308         /// <since_tizen> 3 </since_tizen>
309         public ImageView(string url) : this(Interop.ImageView.New(url), true)
310         {
311             ResourceUrl = url;
312             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313
314         }
315
316         /// <summary>
317         /// Creates an initialized ImageView from a URL to an image resource with setting shown or hidden.
318         /// </summary>
319         /// <param name="url">The URL of the image resource to display.</param>
320         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
321         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
322         [EditorBrowsable(EditorBrowsableState.Never)]
323         public ImageView(string url, bool shown) : this(Interop.ImageView.New(url), true)
324         {
325             ResourceUrl = url;
326             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327             SetVisible(shown);
328         }
329
330         internal ImageView(string url, Uint16Pair size, bool shown = true) : this(Interop.ImageView.New(url, Uint16Pair.getCPtr(size)), true)
331         {
332             ResourceUrl = url;
333             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334
335             if (!shown)
336             {
337                 SetVisible(false);
338             }
339         }
340
341         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
342         {
343             if (!shown)
344             {
345                 SetVisible(false);
346             }
347         }
348
349         internal ImageView(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
350         {
351             if (!shown)
352             {
353                 SetVisible(false);
354             }
355         }
356
357         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
358         private delegate void ResourceReadyEventCallbackType(IntPtr data);
359         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
360         private delegate void _resourceLoadedCallbackType(IntPtr view);
361
362         /// <summary>
363         /// An event for ResourceReady signal which can be used to subscribe or unsubscribe the event handler.<br />
364         /// This signal is emitted after all resources required by a control are loaded and ready.<br />
365         /// Most resources are only loaded when the control is placed on the stage.<br />
366         /// </summary>
367         /// <since_tizen> 3 </since_tizen>
368         public event EventHandler<ResourceReadyEventArgs> ResourceReady
369         {
370             add
371             {
372                 if (_resourceReadyEventHandler == null)
373                 {
374                     _resourceReadyEventCallback = OnResourceReady;
375                     ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
376                     resourceReadySignal?.Connect(_resourceReadyEventCallback);
377                     resourceReadySignal?.Dispose();
378                 }
379
380                 _resourceReadyEventHandler += value;
381             }
382
383             remove
384             {
385                 _resourceReadyEventHandler -= value;
386
387                 ViewResourceReadySignal resourceReadySignal = ResourceReadySignal(this);
388                 if (_resourceReadyEventHandler == null && resourceReadySignal?.Empty() == false)
389                 {
390                     resourceReadySignal?.Disconnect(_resourceReadyEventCallback);
391                 }
392                 resourceReadySignal?.Dispose();
393             }
394         }
395
396         internal event EventHandler<ResourceLoadedEventArgs> ResourceLoaded
397         {
398             add
399             {
400                 if (_resourceLoadedEventHandler == null)
401                 {
402                     _resourceLoadedCallback = OnResourceLoaded;
403                     ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
404                     resourceReadySignal?.Connect(_resourceLoadedCallback);
405                     resourceReadySignal?.Dispose();
406                 }
407
408                 _resourceLoadedEventHandler += value;
409             }
410             remove
411             {
412                 _resourceLoadedEventHandler -= value;
413                 ViewResourceReadySignal resourceReadySignal = this.ResourceReadySignal(this);
414                 if (_resourceLoadedEventHandler == null && resourceReadySignal?.Empty() == false)
415                 {
416                     resourceReadySignal?.Disconnect(_resourceLoadedCallback);
417                 }
418                 resourceReadySignal?.Dispose();
419             }
420         }
421
422         /// <summary>
423         /// Enumeration for LoadingStatus of image.
424         /// </summary>
425         /// <since_tizen> 5 </since_tizen>
426         public enum LoadingStatusType
427         {
428             /// <summary>
429             /// Loading preparing status.
430             /// </summary>
431             /// <since_tizen> 5 </since_tizen>
432             Preparing,
433             /// <summary>
434             /// Loading ready status.
435             /// </summary>
436             /// <since_tizen> 5 </since_tizen>
437             Ready,
438             /// <summary>
439             /// Loading failed status.
440             /// </summary>
441             /// <since_tizen> 5 </since_tizen>
442             Failed
443         }
444
445         /// <summary>
446         /// ImageView ResourceUrl, type string.
447         /// This is one of mandatory property. Even if not set or null set, it sets empty string ("") internally.
448         /// When it is set as null, it gives empty string ("") to be read.
449         /// </summary>
450         /// <since_tizen> 3 </since_tizen>
451         public string ResourceUrl
452         {
453             get
454             {
455                 return (string)GetValue(ResourceUrlProperty);
456             }
457             set
458             {
459                 SetValue(ResourceUrlProperty, value);
460                 NotifyPropertyChanged();
461             }
462         }
463
464         /// <summary>
465         /// This will be deprecated, please use Image instead. <br />
466         /// ImageView ImageMap, type PropertyMap: string if it is a URL, map otherwise.
467         /// </summary>
468         /// <since_tizen> 3 </since_tizen>
469         [Obsolete("Please do not use! This will be deprecated! Please use Image property instead!")]
470         [EditorBrowsable(EditorBrowsableState.Never)]
471         public PropertyMap ImageMap
472         {
473             get
474             {
475                 if (_border == null)
476                 {
477                     PropertyMap returnValue = new PropertyMap();
478                     PropertyValue image = GetProperty(ImageView.Property.IMAGE);
479                     image?.Get(returnValue);
480                     image?.Dispose();
481                     return returnValue;
482                 }
483                 else
484                 {
485                     return null;
486                 }
487             }
488             set
489             {
490                 if (_border == null)
491                 {
492                     PropertyValue setValue = new Tizen.NUI.PropertyValue(value);
493                     SetProperty(ImageView.Property.IMAGE, setValue);
494                     NotifyPropertyChanged();
495                     setValue?.Dispose();
496                 }
497             }
498         }
499
500         /// <summary>
501         /// ImageView Image, type PropertyMap: string if it is a URL, map otherwise.
502         /// </summary>
503         /// <remarks>
504         /// This PropertyMap use a <see cref="ImageVisualProperty"/>. <br />
505         /// See <see cref="ImageVisualProperty"/> for a detailed description. <br />
506         /// you can also use <see cref="Visual.Property"/>. <br />
507         /// See <see cref="Visual.Property"/> for a detailed description. <br />
508         /// </remarks>
509         /// <example>
510         /// The following example demonstrates how to use the Image property.
511         /// <code>
512         /// PropertyMap map = new PropertyMap();
513         /// map.Insert(Visual.Property.Type, new PropertyValue((int)Visual.Type.Image));
514         /// map.Insert(ImageVisualProperty.AlphaMaskURL, new PropertyValue(url));
515         /// map.Insert(ImageVisualProperty.FittingMode, new PropertyValue((int)FittingModeType.ScaleToFill);
516         /// imageview.Image = map;
517         /// </code>
518         /// </example>
519         /// <since_tizen> 4 </since_tizen>
520         public PropertyMap Image
521         {
522             get
523             {
524                 if (_border == null)
525                 {
526                     return (PropertyMap)GetValue(ImageProperty);
527                 }
528                 else
529                 {
530                     return null;
531                 }
532             }
533             set
534             {
535                 if (_border == null)
536                 {
537                     SetValue(ImageProperty, value);
538                     NotifyPropertyChanged();
539                 }
540             }
541         }
542
543         /// <summary>
544         /// ImageView PreMultipliedAlpha, type Boolean.<br />
545         /// Image must be initialized.<br />
546         /// </summary>
547         /// <since_tizen> 3 </since_tizen>
548         public bool PreMultipliedAlpha
549         {
550             get
551             {
552                 return (bool)GetValue(PreMultipliedAlphaProperty);
553             }
554             set
555             {
556                 SetValue(PreMultipliedAlphaProperty, value);
557                 NotifyPropertyChanged();
558             }
559         }
560
561         /// <summary>
562         /// ImageView PixelArea, type Vector4 (Animatable property).<br />
563         /// Pixel area is a relative value with the whole image area as [0.0, 0.0, 1.0, 1.0].<br />
564         /// </summary>
565         /// <remarks>
566         /// The property cascade chaining set is possible. For example, this (imageView.PixelArea.X = 0.1f;) is possible.
567         /// </remarks>
568         /// <since_tizen> 3 </since_tizen>
569         public RelativeVector4 PixelArea
570         {
571             get
572             {
573                 RelativeVector4 temp = (RelativeVector4)GetValue(PixelAreaProperty);
574                 return new RelativeVector4(OnPixelAreaChanged, temp.X, temp.Y, temp.Z, temp.W);
575             }
576             set
577             {
578                 SetValue(PixelAreaProperty, value);
579                 NotifyPropertyChanged();
580             }
581         }
582
583         /// <summary>
584         /// The border of the image in the order: left, right, bottom, top.<br />
585         /// If set, ImageMap will be ignored.<br />
586         /// For N-Patch images only.<br />
587         /// Optional.
588         /// </summary>
589         /// <remarks>
590         /// The property cascade chaining set is possible. For example, this (imageView.Border.X = 1;) is possible.
591         /// </remarks>
592         /// <since_tizen> 3 </since_tizen>
593         public Rectangle Border
594         {
595             get
596             {
597                 Rectangle temp = (Rectangle)GetValue(BorderProperty);
598                 if (null == temp)
599                 {
600                     return null;
601                 }
602                 else
603                 {
604                     return new Rectangle(OnBorderChanged, temp.X, temp.Y, temp.Width, temp.Height);
605                 }
606             }
607             set
608             {
609                 SetValue(BorderProperty, value);
610                 NotifyPropertyChanged();
611             }
612         }
613
614         /// <summary>
615         /// Gets or sets whether to draw the borders only (if true).<br />
616         /// If not specified, the default is false.<br />
617         /// For N-Patch images only.<br />
618         /// Optional.
619         /// </summary>
620         /// <since_tizen> 3 </since_tizen>
621         public bool BorderOnly
622         {
623             get
624             {
625                 return (bool)GetValue(BorderOnlyProperty);
626             }
627             set
628             {
629                 SetValue(BorderOnlyProperty, value);
630                 NotifyPropertyChanged();
631             }
632         }
633
634         /// <summary>
635         /// Gets or sets whether to synchronous loading the resourceurl of image.<br />
636         /// </summary>
637         /// <since_tizen> 3 </since_tizen>
638         [Obsolete("Deprecated since API level 9 and will be removed in API level 11. Please use SynchronousLoading instead!")]
639         public bool SynchronosLoading
640         {
641             get
642             {
643                 return SynchronousLoading;
644             }
645             set
646             {
647                 SynchronousLoading = value;
648             }
649         }
650
651         /// <summary>
652         /// Gets or sets whether the image of the ResourceUrl property will be loaded synchronously.<br />
653         /// </summary>
654         /// <remarks>
655         /// Changing this property make this ImageView load image synchronously at the next loading
656         /// by following operation: <see cref="Reload"/>, <see cref="SetImage(string)"/>,
657         /// and by some properties those cause reloading: <see cref="ResourceUrl"/>, <see cref="PreMultipliedAlpha"/> and etc.
658         /// </remarks>
659         /// <since_tizen> 9 </since_tizen>
660         public bool SynchronousLoading
661         {
662             get
663             {
664                 return (bool)GetValue(SynchronousLoadingProperty);
665             }
666             set
667             {
668                 SetValue(SynchronousLoadingProperty, value);
669                 NotifyPropertyChanged();
670             }
671         }
672
673         /// <summary>
674         /// Gets or sets whether to automatically correct the orientation of an image.<br />
675         /// </summary>
676         /// <since_tizen> 5 </since_tizen>
677         public bool OrientationCorrection
678         {
679             get
680             {
681                 return (bool)GetValue(OrientationCorrectionProperty);
682             }
683             set
684             {
685                 SetValue(OrientationCorrectionProperty, value);
686                 NotifyPropertyChanged();
687             }
688         }
689
690         /// <summary>
691         /// Gets the loading state of the visual resource.
692         /// </summary>
693         /// <since_tizen> 5 </since_tizen>
694         public ImageView.LoadingStatusType LoadingStatus
695         {
696             get
697             {
698                 return (ImageView.LoadingStatusType)Interop.View.GetVisualResourceStatus(SwigCPtr, (int)Property.IMAGE);
699             }
700         }
701
702         /// <summary>
703         /// Downcasts a handle to imageView handle.
704         /// </summary>
705         /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
706         /// Please do not use! this will be deprecated!
707         /// Instead please use as keyword.
708         /// <since_tizen> 3 </since_tizen>
709         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
710         "Like: " +
711         "BaseHandle handle = new ImageView(imagePath); " +
712         "ImageView image = handle as ImageView")]
713         [EditorBrowsable(EditorBrowsableState.Never)]
714         public static ImageView DownCast(BaseHandle handle)
715         {
716             if (null == handle)
717             {
718                 throw new ArgumentNullException(nameof(handle));
719             }
720             ImageView ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ImageView;
721             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
722             return ret;
723         }
724
725         /// <summary>
726         /// Sets this ImageView from the given URL.<br />
727         /// If the URL is empty, ImageView will not display anything.<br />
728         /// </summary>
729         /// <param name="url">The URL to the image resource to display.</param>
730         /// <exception cref="ArgumentNullException"> Thrown when url is null. </exception>
731         /// <since_tizen> 3 </since_tizen>
732         public void SetImage(string url)
733         {
734             if (null == url)
735             {
736                 throw new ArgumentNullException(nameof(url));
737             }
738
739             if (url.Contains(".json"))
740             {
741                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
742                 return;
743             }
744
745             Interop.ImageView.SetImage(SwigCPtr, url);
746             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
747
748             ResourceUrl = url;
749         }
750
751         /// <summary>
752         /// Queries if all resources required by a control are loaded and ready.<br />
753         /// Most resources are only loaded when the control is placed on the stage.<br />
754         /// True if the resources are loaded and ready, false otherwise.<br />
755         /// </summary>
756         /// <since_tizen> 3 </since_tizen>
757         public new bool IsResourceReady()
758         {
759             bool ret = Interop.View.IsResourceReady(SwigCPtr);
760             if (NDalicPINVOKE.SWIGPendingException.Pending)
761                 throw NDalicPINVOKE.SWIGPendingException.Retrieve();
762             return ret;
763         }
764
765         /// <summary>
766         /// Forcefully reloads the image. All the visuals using this image will reload to the latest image.
767         /// </summary>
768         /// <since_tizen> 5 </since_tizen>
769         public void Reload()
770         {
771             PropertyValue attributes = new PropertyValue(0);
772             this.DoAction(ImageView.Property.IMAGE, ActionReload, attributes);
773             attributes?.Dispose();
774         }
775
776         /// <summary>
777         /// Plays the animated GIF. This is also the default playback mode.
778         /// </summary>
779         /// <since_tizen> 5 </since_tizen>
780         public void Play()
781         {
782             PropertyValue attributes = new PropertyValue(0);
783             this.DoAction(ImageView.Property.IMAGE, ActionPlay, attributes);
784             attributes?.Dispose();
785         }
786
787         /// <summary>
788         /// Pauses the animated GIF.
789         /// </summary>
790         /// <since_tizen> 5 </since_tizen>
791         public void Pause()
792         {
793             PropertyValue attributes = new PropertyValue(0);
794             this.DoAction(ImageView.Property.IMAGE, ActionPause, attributes);
795             attributes?.Dispose();
796         }
797
798         /// <summary>
799         /// Stops the animated GIF.
800         /// </summary>
801         /// <since_tizen> 5 </since_tizen>
802         public void Stop()
803         {
804             PropertyValue attributes = new PropertyValue(0);
805             this.DoAction(ImageView.Property.IMAGE, ActionStop, attributes);
806             attributes?.Dispose();
807         }
808
809         /// <summary>
810         /// Gets or sets the URL of the alpha mask.<br />
811         /// Optional.
812         /// </summary>
813         /// <since_tizen> 6</since_tizen>
814         [EditorBrowsable(EditorBrowsableState.Never)]
815         public string AlphaMaskURL
816         {
817             get
818             {
819                 string ret = "";
820                 PropertyMap imageMap = new PropertyMap();
821                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
822                 image?.Get(imageMap);
823                 PropertyValue maskUrl = imageMap?.Find(ImageVisualProperty.AlphaMaskURL);
824                 maskUrl?.Get(out ret);
825                 _alphaMaskUrl = ret;
826
827                 imageMap?.Dispose();
828                 image?.Dispose();
829                 maskUrl?.Dispose();
830
831                 return ret;
832             }
833             set
834             {
835                 if (value == null)
836                 {
837                     value = "";
838                 }
839
840                 _alphaMaskUrl = value;
841
842                 PropertyValue setValue = new PropertyValue(value);
843                 UpdateImage(ImageVisualProperty.AlphaMaskURL, setValue);
844                 setValue?.Dispose();
845             }
846         }
847
848
849         /// <summary>
850         ///  Whether to crop image to mask or scale mask to fit image.
851         /// </summary>
852         /// <since_tizen> 6 </since_tizen>
853         public bool CropToMask
854         {
855             get
856             {
857                 bool ret =  _cropToMask;
858                 PropertyMap imageMap = new PropertyMap();
859                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
860                 image?.Get(imageMap);
861                 PropertyValue cropUrl = imageMap?.Find(ImageVisualProperty.CropToMask);
862                 cropUrl?.Get(out ret);
863                 _cropToMask = ret;
864
865                 imageMap?.Dispose();
866                 image?.Dispose();
867                 cropUrl?.Dispose();
868
869                 return ret;
870             }
871             set
872             {
873                 _cropToMask = value;
874                 PropertyValue setValue = new PropertyValue(value);
875                 UpdateImage(ImageVisualProperty.CropToMask, setValue);
876                 setValue.Dispose();
877             }
878         }
879
880         /// <summary>
881         /// Actions property value for Reload image.
882         /// </summary>
883         private int ActionReload { get; set; } = Interop.ImageView.ImageVisualActionReloadGet();
884
885         /// <summary>
886         /// Actions property value to Play animated images.
887         /// This property can be redefined by child class if it use different value.
888         /// </summary>
889         [EditorBrowsable(EditorBrowsableState.Never)]
890         protected int ActionPlay { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionPlayGet();
891
892         /// <summary>
893         /// Actions property value to Pause animated images.
894         /// This property can be redefined by child class if it use different value.
895         /// </summary>
896         [EditorBrowsable(EditorBrowsableState.Never)]
897         protected int ActionPause { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionPauseGet();
898
899         /// <summary>
900         /// Actions property value to Stop animated images.
901         /// This property can be redefined by child class if it use different value.
902         /// </summary>
903         [EditorBrowsable(EditorBrowsableState.Never)]
904         protected int ActionStop { get; set; } = Interop.AnimatedImageView.AnimatedImageVisualActionStopGet();
905
906         internal VisualFittingModeType ConvertFittingModetoVisualFittingMode(FittingModeType value)
907         {
908             switch (value)
909             {
910                 case FittingModeType.ShrinkToFit:
911                     return VisualFittingModeType.FitKeepAspectRatio;
912                 case FittingModeType.ScaleToFill:
913                     return VisualFittingModeType.OverFitKeepAspectRatio;
914                 case FittingModeType.Center:
915                     return VisualFittingModeType.Center;
916                 case FittingModeType.Fill:
917                     return VisualFittingModeType.Fill;
918                 case FittingModeType.FitHeight:
919                     return VisualFittingModeType.FitHeight;
920                 case FittingModeType.FitWidth:
921                     return VisualFittingModeType.FitWidth;
922                 default:
923                     return VisualFittingModeType.Fill;
924             }
925         }
926
927         internal FittingModeType ConvertVisualFittingModetoFittingMode(VisualFittingModeType value)
928         {
929             switch (value)
930             {
931                 case VisualFittingModeType.FitKeepAspectRatio:
932                     return FittingModeType.ShrinkToFit;
933                 case VisualFittingModeType.OverFitKeepAspectRatio:
934                     return FittingModeType.ScaleToFill;
935                 case VisualFittingModeType.Center:
936                     return FittingModeType.Center;
937                 case VisualFittingModeType.Fill:
938                     return FittingModeType.Fill;
939                 case VisualFittingModeType.FitHeight:
940                     return FittingModeType.FitHeight;
941                 case VisualFittingModeType.FitWidth:
942                     return FittingModeType.FitWidth;
943                 default:
944                     return FittingModeType.ShrinkToFit;
945             }
946         }
947
948         internal override LayoutItem CreateDefaultLayout()
949         {
950             return new ImageLayout();
951         }
952
953         /// <summary>
954         /// Gets or sets fitting options used when resizing images to fit.<br />
955         /// If not supplied, the default is FittingModeType.Fill.<br />
956         /// For normal quad images only.<br />
957         /// Optional.
958         /// </summary>
959         /// <since_tizen> 6 </since_tizen>
960         [EditorBrowsable(EditorBrowsableState.Never)]
961         public FittingModeType FittingMode
962         {
963             get
964             {
965                 int ret = (int)_fittingMode;
966                 PropertyMap imageMap = new PropertyMap();
967                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
968                 image?.Get(imageMap);
969                 PropertyValue fittingMode = imageMap?.Find(Visual.Property.VisualFittingMode);
970                 fittingMode?.Get(out ret);
971                 _fittingMode = (VisualFittingModeType)ret;
972
973                 imageMap?.Dispose();
974                 image?.Dispose();
975                 fittingMode?.Dispose();
976
977                 return ConvertVisualFittingModetoFittingMode((VisualFittingModeType)ret);
978             }
979             set
980             {
981                 VisualFittingModeType ret = ConvertFittingModetoVisualFittingMode(value);
982                 PropertyValue setValue = new PropertyValue((int)ret);
983                 if(_fittingMode != ret)
984                 {
985                     _fittingMode = ret;
986                     UpdateImage(Visual.Property.VisualFittingMode, setValue);
987                 }
988                 setValue?.Dispose();
989             }
990         }
991
992
993
994         /// <summary>
995         /// Gets or sets the desired image width.<br />
996         /// If not specified, the actual image width is used.<br />
997         /// For normal quad images only.<br />
998         /// Optional.
999         /// </summary>
1000         /// <since_tizen> 6 </since_tizen>
1001         [EditorBrowsable(EditorBrowsableState.Never)]
1002         public int DesiredWidth
1003         {
1004             get
1005             {
1006                 PropertyMap imageMap = new PropertyMap();
1007                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1008                 image?.Get(imageMap);
1009                 PropertyValue desireWidth = imageMap?.Find(ImageVisualProperty.DesiredWidth);
1010                 desireWidth?.Get(out _desired_width);
1011
1012                 imageMap?.Dispose();
1013                 image?.Dispose();
1014                 desireWidth?.Dispose();
1015
1016                 return _desired_width;
1017             }
1018             set
1019             {
1020                 if (_desired_width != value)
1021                 {
1022                     _desired_width = value;
1023                     UpdateImage(0, null);
1024                 }
1025             }
1026         }
1027
1028         /// <summary>
1029         /// Gets or sets the desired image height.<br />
1030         /// If not specified, the actual image height is used.<br />
1031         /// For normal quad images only.<br />
1032         /// Optional.
1033         /// </summary>
1034         /// <since_tizen> 6 </since_tizen>
1035         [EditorBrowsable(EditorBrowsableState.Never)]
1036         public int DesiredHeight
1037         {
1038             get
1039             {
1040                 PropertyMap imageMap = new PropertyMap();
1041                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1042                 image?.Get(imageMap);
1043                 PropertyValue desireheight = imageMap?.Find(ImageVisualProperty.DesiredHeight);
1044                 desireheight?.Get(out _desired_height);
1045
1046                 imageMap?.Dispose();
1047                 image?.Dispose();
1048                 desireheight?.Dispose();
1049
1050                 return _desired_height;
1051             }
1052             set
1053             {
1054                 if (_desired_height != value)
1055                 {
1056                     _desired_height = value;
1057                     UpdateImage(0, null);
1058                 }
1059             }
1060         }
1061
1062         /// <summary>
1063         /// Gets or sets ReleasePolicy for image.<br />
1064         /// If not supplied, the default is ReleasePolicyType.Detached.<br />
1065         /// </summary>
1066         [EditorBrowsable(EditorBrowsableState.Never)]
1067         public ReleasePolicyType ReleasePolicy
1068         {
1069             get
1070             {
1071                 int ret = (int)ReleasePolicyType.Detached;
1072                 PropertyMap imageMap = new PropertyMap();
1073                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1074                 image?.Get(imageMap);
1075                 PropertyValue releasePoli = imageMap?.Find(ImageVisualProperty.ReleasePolicy);
1076                 releasePoli?.Get(out ret);
1077
1078                 imageMap?.Dispose();
1079                 image?.Dispose();
1080                 releasePoli?.Dispose();
1081
1082                 return (ReleasePolicyType)ret;
1083             }
1084             set
1085             {
1086                 PropertyValue setValue = new PropertyValue((int)value);
1087                 UpdateImage(ImageVisualProperty.ReleasePolicy, setValue);
1088                 setValue?.Dispose();
1089             }
1090         }
1091
1092         /// <summary>
1093         /// Gets or sets the wrap mode for the u coordinate.<br />
1094         /// It decides how the texture should be sampled when the u coordinate exceeds the range of 0.0 to 1.0.<br />
1095         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1096         /// For normal quad images only.<br />
1097         /// Optional.
1098         /// </summary>
1099         /// <since_tizen> 6 </since_tizen>
1100         [EditorBrowsable(EditorBrowsableState.Never)]
1101         public WrapModeType WrapModeU
1102         {
1103             get
1104             {
1105                 int ret = (int)WrapModeType.Default;
1106                 PropertyMap imageMap = new PropertyMap();
1107                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1108                 image?.Get(imageMap);
1109                 PropertyValue warpModeU = imageMap?.Find(ImageVisualProperty.WrapModeU);
1110                 warpModeU?.Get(out ret);
1111
1112                 imageMap?.Dispose();
1113                 image?.Dispose();
1114                 warpModeU?.Dispose();
1115
1116                 return (WrapModeType)ret;
1117             }
1118             set
1119             {
1120                 PropertyValue setValue = new PropertyValue((int)value);
1121                 UpdateImage(ImageVisualProperty.WrapModeU, setValue);
1122                 setValue?.Dispose();
1123             }
1124         }
1125
1126         /// <summary>
1127         /// Gets or sets the wrap mode for the v coordinate.<br />
1128         /// It decides how the texture should be sampled when the v coordinate exceeds the range of 0.0 to 1.0.<br />
1129         /// The first two elements indicate the top-left position of the area, and the last two elements are the areas of the width and the height respectively.<br />
1130         /// If not specified, the default is WrapModeType.Default(CLAMP).<br />
1131         /// For normal quad images only.
1132         /// Optional.
1133         /// </summary>
1134         /// <since_tizen> 6 </since_tizen>
1135         [EditorBrowsable(EditorBrowsableState.Never)]
1136         public WrapModeType WrapModeV
1137         {
1138             get
1139             {
1140                 int ret = (int)WrapModeType.Default;
1141                 PropertyMap imageMap = new PropertyMap();
1142                 PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1143                 image?.Get(imageMap);
1144                 PropertyValue wrapModeV = imageMap?.Find(ImageVisualProperty.WrapModeV);
1145                 wrapModeV?.Get(out ret);
1146
1147                 imageMap?.Dispose();
1148                 image?.Dispose();
1149                 wrapModeV?.Dispose();
1150
1151                 return (WrapModeType)ret;
1152             }
1153             set
1154             {
1155                 PropertyValue setValue = new PropertyValue((int)value);
1156                 UpdateImage(ImageVisualProperty.WrapModeV, setValue);
1157                 setValue?.Dispose();
1158             }
1159         }
1160
1161         /// <summary>
1162         /// Gets or sets the mode to adjust view size to preserve the aspect ratio of the image resource.
1163         /// </summary>
1164         /// <remarks>
1165         /// This is false by default.
1166         /// If this is set to be true, then the width or height value, which is not set by user explicitly, can be changed automatically
1167         /// to preserve the aspect ratio of the image resource.
1168         /// AdjustViewSize works only if ImageView is added to a View having Layout.
1169         /// e.g. If the image resource size is (100, 100), then the ImageView requests size (100, 100) to its parent layout by default.
1170         ///      If the ImageView's HeightSpecification is 50 and AdjustViewSize is true, then the ImageView requests size (50, 50) instead of (100, 50).
1171         /// </remarks>
1172         /// <since_tizen> 9 </since_tizen>
1173         public bool AdjustViewSize { get; set; } = false;
1174
1175         internal Selector<string> ResourceUrlSelector
1176         {
1177             get => GetSelector<string>(resourceUrlSelector, ImageView.ResourceUrlProperty);
1178             set
1179             {
1180                 resourceUrlSelector?.Reset(this);
1181                 if (value == null) return;
1182
1183                 if (value.HasAll()) SetResourceUrl(value.All);
1184                 else resourceUrlSelector = new TriggerableSelector<string>(this, value, SetResourceUrl, true);
1185             }
1186         }
1187
1188         /// <summary>
1189         /// Get attributes, it is abstract function and must be override.
1190         /// </summary>
1191         [EditorBrowsable(EditorBrowsableState.Never)]
1192         protected override ViewStyle CreateViewStyle()
1193         {
1194             return new ImageViewStyle();
1195         }
1196
1197         internal void SetImage(string url, Uint16Pair size)
1198         {
1199             if (url.Contains(".json"))
1200             {
1201                 Tizen.Log.Fatal("NUI", "[ERROR] Please DO NOT set lottie file in ImageView! This is temporary checking, will be removed soon!");
1202                 return;
1203             }
1204
1205             Interop.ImageView.SetImage(SwigCPtr, url, Uint16Pair.getCPtr(size));
1206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1207
1208             ResourceUrl = url;
1209         }
1210
1211         internal ViewResourceReadySignal ResourceReadySignal(View view)
1212         {
1213             ViewResourceReadySignal ret = new ViewResourceReadySignal(Interop.View.ResourceReadySignal(View.getCPtr(view)), false);
1214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1215             return ret;
1216         }
1217
1218         internal override void ApplyCornerRadius()
1219         {
1220             base.ApplyCornerRadius();
1221
1222             UpdateImage(0, null);
1223         }
1224
1225         internal override void ApplyBorderline()
1226         {
1227             base.ApplyBorderline();
1228
1229             // Apply borderline to IMAGE.
1230             if (backgroundExtraData != null)
1231             {
1232                 var borderlineColor = backgroundExtraData.BorderlineColor == null ? new PropertyValue(Color.Black) : new PropertyValue(backgroundExtraData.BorderlineColor);
1233
1234                 // Apply to the image visual
1235                 PropertyMap imageMap = new PropertyMap();
1236                 PropertyValue imageValue = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1237                 if (imageValue.Get(imageMap) && !imageMap.Empty())
1238                 {
1239                     imageMap[Visual.Property.BorderlineWidth] = new PropertyValue(backgroundExtraData.BorderlineWidth);
1240                     imageMap[Visual.Property.BorderlineColor] = borderlineColor;
1241                     imageMap[Visual.Property.BorderlineOffset] = new PropertyValue(backgroundExtraData.BorderlineOffset);
1242                     var temp = new PropertyValue(imageMap);
1243                     Tizen.NUI.Object.SetProperty(SwigCPtr, ImageView.Property.IMAGE, temp);
1244                     temp.Dispose();
1245                 }
1246                 imageMap.Dispose();
1247                 imageValue.Dispose();
1248                 borderlineColor.Dispose();
1249             }
1250
1251             UpdateImage(0, null);
1252         }
1253
1254         internal ResourceLoadingStatusType GetResourceStatus()
1255         {
1256             return (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1257         }
1258
1259         /// <summary>
1260         /// you can override it to clean-up your own resources.
1261         /// </summary>
1262         /// <param name="type">DisposeTypes</param>
1263         /// <since_tizen> 3 </since_tizen>
1264         protected override void Dispose(DisposeTypes type)
1265         {
1266             if (disposed)
1267             {
1268                 return;
1269             }
1270
1271             if (type == DisposeTypes.Explicit)
1272             {
1273                 //Called by User
1274                 //Release your own managed resources here.
1275                 //You should release all of your own disposable objects here.
1276                 _border?.Dispose();
1277                 _border = null;
1278                 borderSelector?.Reset(this);
1279                 resourceUrlSelector?.Reset(this);
1280             }
1281
1282             base.Dispose(type);
1283         }
1284
1285         /// This will not be public opened.
1286         [EditorBrowsable(EditorBrowsableState.Never)]
1287         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1288         {
1289             Interop.ImageView.DeleteImageView(swigCPtr);
1290         }
1291
1292         // Callback for View ResourceReady signal
1293         private void OnResourceReady(IntPtr data)
1294         {
1295             ResourceReadyEventArgs e = new ResourceReadyEventArgs();
1296             if (data != null)
1297             {
1298                 e.View = Registry.GetManagedBaseHandleFromNativePtr(data) as View;
1299             }
1300
1301             if (_resourceReadyEventHandler != null)
1302             {
1303                 _resourceReadyEventHandler(this, e);
1304             }
1305         }
1306
1307         private void SetResourceUrl(string value)
1308         {
1309             value = (value == null ? "" : value);
1310             if (value.StartsWith("*Resource*"))
1311             {
1312                 string resource = Tizen.Applications.Application.Current.DirectoryInfo.Resource;
1313                 value = value.Replace("*Resource*", resource);
1314             }
1315             _resourceUrl = value;
1316             UpdateImage(ImageVisualProperty.URL, new PropertyValue(value));
1317         }
1318
1319         private void SetBorder(Rectangle value)
1320         {
1321             if (value == null)
1322             {
1323                 return;
1324             }
1325             _border = new Rectangle(value);
1326             UpdateImage(NpatchImageVisualProperty.Border, new PropertyValue(_border));
1327         }
1328
1329         private void UpdateImageMap(PropertyMap fromMap)
1330         {
1331             PropertyMap imageMap = new PropertyMap();
1332
1333             PropertyValue image = Tizen.NUI.Object.GetProperty(SwigCPtr, ImageView.Property.IMAGE);
1334             image?.Get(imageMap);
1335             imageMap?.Merge(fromMap);
1336             PropertyValue setValue = new PropertyValue(imageMap);
1337             SetProperty(ImageView.Property.IMAGE, setValue);
1338
1339             imageMap?.Dispose();
1340             image?.Dispose();
1341             setValue?.Dispose();
1342         }
1343
1344         private void UpdateImage(int key, PropertyValue value)
1345         {
1346             PropertyMap imageMap = new PropertyMap();
1347
1348             if (_alphaMaskUrl != null)
1349             {
1350                 PropertyValue alphaMaskUrl = new PropertyValue(_alphaMaskUrl);
1351                 imageMap?.Insert(ImageVisualProperty.AlphaMaskURL, alphaMaskUrl);
1352                 alphaMaskUrl?.Dispose();
1353             }
1354
1355             if(key != ImageVisualProperty.CropToMask)
1356             {
1357                 PropertyValue cropToMask = new PropertyValue(_cropToMask);
1358                 imageMap?.Insert(ImageVisualProperty.CropToMask, cropToMask);
1359                 cropToMask?.Dispose();
1360             }
1361
1362             if (string.IsNullOrEmpty(_resourceUrl))
1363             {
1364                 PropertyValue resourceUrl = new PropertyValue(_resourceUrl);
1365                 imageMap?.Insert(ImageVisualProperty.URL, resourceUrl);
1366                 PropertyValue setValue = new PropertyValue(imageMap);
1367                 SetProperty(ImageView.Property.IMAGE, setValue);
1368                 resourceUrl?.Dispose();
1369                 setValue?.Dispose();
1370                 return;
1371             }
1372
1373             if (_border == null)
1374             {
1375                 PropertyValue image = new PropertyValue((int)Visual.Type.Image);
1376                 imageMap?.Insert(Visual.Property.Type, image);
1377                 image?.Dispose();
1378             }
1379             else
1380             {
1381                 PropertyValue nPatch = new PropertyValue((int)Visual.Type.NPatch);
1382                 imageMap?.Insert(Visual.Property.Type, nPatch);
1383                 nPatch?.Dispose();
1384                 PropertyValue border = new PropertyValue(_border);
1385                 imageMap?.Insert(NpatchImageVisualProperty.Border, border);
1386                 border?.Dispose();
1387             }
1388
1389             if(key != Visual.Property.VisualFittingMode && _fittingMode != VisualFittingModeType.Fill)
1390             {
1391                 PropertyValue fittingMode = new PropertyValue((int)_fittingMode);
1392                 imageMap?.Insert(Visual.Property.VisualFittingMode, fittingMode);
1393                 fittingMode?.Dispose();
1394             }
1395
1396             PropertyValue synchronousLoading = new PropertyValue(_synchronousLoading);
1397             imageMap?.Insert(NpatchImageVisualProperty.SynchronousLoading, synchronousLoading);
1398             synchronousLoading?.Dispose();
1399
1400             if (backgroundExtraData != null && backgroundExtraData.CornerRadius != null)
1401             {
1402                 using (var cornerRadius = new PropertyValue(backgroundExtraData.CornerRadius))
1403                 using (var cornerRadiusPolicy = new PropertyValue((int)backgroundExtraData.CornerRadiusPolicy))
1404                 {
1405                     imageMap.Insert(Visual.Property.CornerRadius, cornerRadius);
1406                     imageMap.Insert(Visual.Property.CornerRadiusPolicy, new PropertyValue((int)(backgroundExtraData.CornerRadiusPolicy)));
1407                 }
1408             }
1409
1410             if (backgroundExtraData != null && backgroundExtraData.BorderlineWidth > 0.0f)
1411             {
1412                 using (var borderlineWidth = new PropertyValue(backgroundExtraData.BorderlineWidth))
1413                 using (var borderlineColor = new PropertyValue(backgroundExtraData.BorderlineColor))
1414                 using (var borderlineOffset = new PropertyValue(backgroundExtraData.BorderlineOffset))
1415                 {
1416                     imageMap.Insert(Visual.Property.BorderlineWidth, borderlineWidth);
1417                     imageMap.Insert(Visual.Property.BorderlineColor, borderlineColor);
1418                     imageMap.Insert(Visual.Property.BorderlineOffset, borderlineOffset);
1419                 }
1420             }
1421
1422             if (value != null)
1423             {
1424                 imageMap?.Insert(key, value);
1425             }
1426
1427             // Do Fitting Buffer when desired dimension is set
1428             if (_desired_width != -1 && _desired_height != -1)
1429             {
1430                 if (_resourceUrl != null)
1431                 {
1432                     Size2D imageSize = ImageLoader.GetOriginalImageSize(_resourceUrl, true);
1433                     if( imageSize.Height > 0 && imageSize.Width > 0 && _desired_width > 0  && _desired_height > 0 )
1434                     {
1435                         int adjustedDesiredWidth, adjustedDesiredHeight;
1436                         float aspectOfDesiredSize = (float)_desired_height / (float)_desired_width;
1437                         float aspectOfImageSize = (float)imageSize.Height / (float)imageSize.Width;
1438                         if (aspectOfImageSize > aspectOfDesiredSize)
1439                         {
1440                             adjustedDesiredWidth = _desired_width;
1441                             adjustedDesiredHeight = imageSize.Height * _desired_width / imageSize.Width;
1442                         }
1443                         else
1444                         {
1445                             adjustedDesiredWidth = imageSize.Width * _desired_height / imageSize.Height;
1446                             adjustedDesiredHeight = _desired_height;
1447                         }
1448
1449                         PropertyValue returnWidth = new PropertyValue(adjustedDesiredWidth);
1450                         imageMap?.Insert(ImageVisualProperty.DesiredWidth, returnWidth);
1451                         returnWidth?.Dispose();
1452                         PropertyValue returnHeight = new PropertyValue(adjustedDesiredHeight);
1453                         imageMap?.Insert(ImageVisualProperty.DesiredHeight, returnHeight);
1454                         returnHeight?.Dispose();
1455                         PropertyValue scaleToFit = new PropertyValue((int)FittingModeType.ScaleToFill);
1456                         imageMap?.Insert(ImageVisualProperty.FittingMode, scaleToFit);
1457                         scaleToFit?.Dispose();
1458                     }
1459                     else
1460                     {
1461                         Tizen.Log.Fatal("NUI", "[ERROR] Can't use DesiredSize when ImageLoading is failed.");
1462                     }
1463                     imageSize?.Dispose();
1464                 }
1465             }
1466
1467             UpdateImageMap(imageMap);
1468
1469             imageMap?.Dispose();
1470             imageMap = null;
1471         }
1472
1473
1474         private void OnResourceLoaded(IntPtr view)
1475         {
1476             ResourceLoadedEventArgs e = new ResourceLoadedEventArgs();
1477             e.Status = (ResourceLoadingStatusType)Interop.View.GetVisualResourceStatus(this.SwigCPtr, Property.IMAGE);
1478
1479             if (_resourceLoadedEventHandler != null)
1480             {
1481                 _resourceLoadedEventHandler(this, e);
1482             }
1483         }
1484
1485         /// <summary>
1486         /// Event arguments of resource ready.
1487         /// </summary>
1488         /// <since_tizen> 3 </since_tizen>
1489         public class ResourceReadyEventArgs : EventArgs
1490         {
1491             private View _view;
1492
1493             /// <summary>
1494             /// The view whose resource is ready.
1495             /// </summary>
1496             /// <since_tizen> 3 </since_tizen>
1497             public View View
1498             {
1499                 get
1500                 {
1501                     return _view;
1502                 }
1503                 set
1504                 {
1505                     _view = value;
1506                 }
1507             }
1508         }
1509
1510         internal class ResourceLoadedEventArgs : EventArgs
1511         {
1512             private ResourceLoadingStatusType status = ResourceLoadingStatusType.Invalid;
1513             public ResourceLoadingStatusType Status
1514             {
1515                 get
1516                 {
1517                     return status;
1518                 }
1519                 set
1520                 {
1521                     status = value;
1522                 }
1523             }
1524         }
1525
1526         internal new class Property
1527         {
1528             internal static readonly int IMAGE = Interop.ImageView.ImageGet();
1529             internal static readonly int PreMultipliedAlpha = Interop.ImageView.PreMultipliedAlphaGet();
1530             internal static readonly int PixelArea = Interop.ImageView.PixelAreaGet();
1531         }
1532
1533         private enum ImageType
1534         {
1535             /// <summary>
1536             /// For Normal Image.
1537             /// </summary>
1538             Normal = 0,
1539
1540             /// <summary>
1541             /// For normal image, with synchronous loading and orientation correction property
1542             /// </summary>
1543             Specific = 1,
1544
1545             /// <summary>
1546             /// For nine-patch image
1547             /// </summary>
1548             Npatch = 2,
1549         }
1550
1551         private void OnBorderChanged(int x, int y, int width, int height)
1552         {
1553             Border = new Rectangle(x, y, width, height);
1554         }
1555         private void OnPixelAreaChanged(float x, float y, float z, float w)
1556         {
1557             PixelArea = new RelativeVector4(x, y, z, w);
1558         }
1559
1560         private class ImageLayout : LayoutItem
1561         {
1562             /// <summary>
1563             /// Gets or sets the mode to adjust view size to preserve the aspect ratio of the image resource.
1564             /// If this is set to be true, then the width or height, which is not set by user explicitly, can be adjusted to preserve the aspect ratio of the image resource.
1565             /// </summary>
1566             [EditorBrowsable(EditorBrowsableState.Never)]
1567             public bool AdjustViewSize
1568             {
1569                 get
1570                 {
1571                     return (Owner as ImageView)?.AdjustViewSize ?? false;
1572                 }
1573                 set
1574                 {
1575                     if (Owner is ImageView imageView)
1576                     {
1577                         imageView.AdjustViewSize = value;
1578                     }
1579                 }
1580             }
1581
1582             /// <inheritdoc/>
1583             [EditorBrowsable(EditorBrowsableState.Never)]
1584             protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
1585             {
1586                 // To not change the view size by DALi
1587                 Owner.WidthResizePolicy = ResizePolicyType.Fixed;
1588                 Owner.HeightResizePolicy = ResizePolicyType.Fixed;
1589
1590                 float specWidth = widthMeasureSpec.Size.AsDecimal();
1591                 float specHeight = heightMeasureSpec.Size.AsDecimal();
1592                 float naturalWidth = Owner.NaturalSize.Width;
1593                 float naturalHeight = Owner.NaturalSize.Height;
1594                 float minWidth = Owner.MinimumSize.Width;
1595                 float maxWidth = Owner.MaximumSize.Width;
1596                 float minHeight = Owner.MinimumSize.Height;
1597                 float maxHeight = Owner.MaximumSize.Height;
1598                 float aspectRatio = (naturalWidth > 0) ? (naturalHeight / naturalWidth) : 0;
1599
1600                 // Assume that the new width and height are given from the view's suggested size by default.
1601                 float newWidth = Math.Min(Math.Max(naturalWidth, minWidth), (maxWidth < 0 ? Int32.MaxValue : maxWidth));
1602                 float newHeight = Math.Min(Math.Max(naturalHeight, minHeight), (maxHeight < 0 ? Int32.MaxValue : maxHeight));
1603
1604                 // The width and height measure specs are going to be used to set measured size.
1605                 // Mark that the measure specs are changed by default to update measure specs later.
1606                 bool widthSpecChanged = true;
1607                 bool heightSpecChanged = true;
1608
1609                 if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
1610                 {
1611                     newWidth = specWidth;
1612                     widthSpecChanged = false;
1613
1614                     if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
1615                     {
1616                         if ((AdjustViewSize) && (aspectRatio > 0))
1617                         {
1618                             newHeight = newWidth * aspectRatio;
1619                         }
1620                     }
1621                 }
1622
1623                 if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
1624                 {
1625                     newHeight = specHeight;
1626                     heightSpecChanged = false;
1627
1628                     if (widthMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
1629                     {
1630                         if ((AdjustViewSize) && (aspectRatio > 0))
1631                         {
1632                             newWidth = newHeight / aspectRatio;
1633                         }
1634                     }
1635                 }
1636
1637                 if (widthSpecChanged)
1638                 {
1639                     widthMeasureSpec = new MeasureSpecification(new LayoutLength(newWidth), MeasureSpecification.ModeType.Exactly);
1640                 }
1641
1642                 if (heightSpecChanged)
1643                 {
1644                     heightMeasureSpec = new MeasureSpecification(new LayoutLength(newHeight), MeasureSpecification.ModeType.Exactly);
1645                 }
1646
1647                 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
1648                 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
1649
1650                 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(newWidth), widthMeasureSpec, childWidthState),
1651                                       ResolveSizeAndState(new LayoutLength(newHeight), heightMeasureSpec, childHeightState));
1652             }
1653         }
1654     }
1655 }