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