[NUI] sync with dalihub (#718)
authorhuiyueun <35286162+huiyueun@users.noreply.github.com>
Tue, 19 Feb 2019 06:40:43 +0000 (15:40 +0900)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Tue, 19 Feb 2019 06:40:43 +0000 (15:40 +0900)
* [NUI] Codacy error fix

Change-Id: Ib407c7be01ad4e42913bf7896edc050e9b4bd370
Signed-off-by: dongsug.song <dongsug.song@samsung.com>
* [NUI] Add API for get the original size of image

* Adding LayoutController

LayoutController from C# exclusive Layouting (LayoutingEx)
where all layouting in processed in the NUI side.

Change-Id: Ic97166e51cd2ef173f6685659f53f53253c93b21

* [NUI] Fix svace issue

Change-Id: I014294612530f600c14c237484f95dfff0c5ec96
Signed-off-by: huiyu.eun <huiyu.eun@samsung.com>
src/Tizen.NUI/src/internal/Layouting/LayoutController.cs [new file with mode: 0644]
src/Tizen.NUI/src/internal/Layouting/LayoutPINVOKE.cs
src/Tizen.NUI/src/internal/ManualPINVOKE.cs
src/Tizen.NUI/src/internal/NDalicPINVOKE.cs
src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs
src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs
src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs
src/Tizen.NUI/src/internal/XamlBinding/StyleSheets/StyleSheetExtensions.cs
src/Tizen.NUI/src/public/ImageLoading.cs
src/Tizen.NUI/src/public/Window.cs

diff --git a/src/Tizen.NUI/src/internal/Layouting/LayoutController.cs b/src/Tizen.NUI/src/internal/Layouting/LayoutController.cs
new file mode 100644 (file)
index 0000000..0d2c3e3
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+using System.ComponentModel;
+using System;
+using Tizen.NUI.BaseComponents;
+using System.Runtime.InteropServices;
+
+namespace Tizen.NUI
+{
+    /// <summary>
+    /// [Draft] The class that initiates the Measuring and Layouting of the tree,
+    ///         It sets a callback that becomes the entry point into the C# Layouting.
+    /// </summary>
+    internal class LayoutController : global::System.IDisposable
+    {
+        private global::System.Runtime.InteropServices.HandleRef unmanagedLayoutController;
+
+        [UnmanagedFunctionPointer(CallingConvention.StdCall)]
+        internal delegate void Callback(int id);
+
+        event Callback mInstance;
+
+        //A Flat to check if it is already disposed.
+        protected bool disposed = false;
+
+
+        /// <summary>
+        /// Constructs a LayoutController which controls the measuring and layouting.<br />
+        /// </summary>
+
+        public LayoutController()
+        {
+            global::System.IntPtr cPtr = LayoutPINVOKE.LayoutController_New();
+
+            // Wrap cPtr in a managed handle.
+            unmanagedLayoutController = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
+
+            mInstance = new Callback(Process);
+            LayoutPINVOKE.LayoutController_SetCallback(unmanagedLayoutController, mInstance);
+        }
+
+        /// <summary>
+        /// Get the unique id of the LayoutController
+        /// </summary>
+        public int GetId()
+        {
+            return LayoutPINVOKE.LayoutController_GetId(unmanagedLayoutController);
+        }
+
+        /// <summary>
+        /// Destructor which adds LayoutController to the Dispose queue.
+        /// </summary>
+        ~LayoutController()
+        {
+            Dispose(DisposeTypes.Explicit);
+        }
+
+        /// <summary>
+        /// Explict Dispose.
+        /// </summary>
+
+        public void Dispose()
+        {
+           Dispose(DisposeTypes.Explicit);
+           System.GC.SuppressFinalize(this);
+        }
+
+        /// <summary>
+        /// Dispose Explict or Implicit
+        /// </summary>
+        protected virtual void Dispose(DisposeTypes type)
+        {
+            if (disposed)
+            {
+                return;
+            }
+
+            if (type == DisposeTypes.Explicit)
+            {
+                //Called by User code
+                //Release your own managed resources here.
+                //You should release all of your own disposable objects here.
+            }
+
+            //Release your own unmanaged resources here.
+            //You should not access any managed member here except static instance.
+            //because the execution order of Finalizes is non-deterministic.
+
+            if (unmanagedLayoutController.Handle != global::System.IntPtr.Zero)
+            {
+                LayoutPINVOKE.delete_LayoutController(unmanagedLayoutController);
+                unmanagedLayoutController = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
+            }
+
+            disposed = true;
+        }
+
+        /// <summary>
+        /// Entry point into the C# Layouting that starts the Processing
+        /// </summary>
+        private void Process(int id)
+        {
+            NUILog.Debug("layoutController Process id:" + id );
+        }
+
+    } // class LayoutController
+
+} // namespace Tizen.NUI
\ No newline at end of file
index 011f0dc..e138fde 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -1085,5 +1085,20 @@ namespace Tizen.NUI
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint="CSharp_Dali_GridLayout__GetColumns")]
         public static extern int GridLayout_GetColumns(global::System.Runtime.InteropServices.HandleRef jarg1);
 
-    }
+        // LayoutingEX
+
+        // LayoutController
+
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_new_LayoutController")]
+        public static extern global::System.IntPtr LayoutController_New();
+
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_delete_LayoutController")]
+        public static extern global::System.IntPtr delete_LayoutController(global::System.Runtime.InteropServices.HandleRef jarg1);
+
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_LayoutController_SetCallback")]
+        public static extern void LayoutController_SetCallback(global::System.Runtime.InteropServices.HandleRef jarg1, LayoutController.Callback jarg2);
+
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_LayoutController_GetId")]
+        public static extern int LayoutController_GetId(global::System.Runtime.InteropServices.HandleRef jarg1);
+         }
 }
index 836ea87..c968873 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
index 1ddf841..1b8b31a 100755 (executable)
@@ -15265,6 +15265,8 @@ namespace Tizen.NUI
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_GetClosestImageSize__SWIG_4")]
         public static extern global::System.IntPtr GetClosestImageSize__SWIG_4(string jarg1);
 
+        [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_GetOriginalImageSize")]
+        public static extern global::System.IntPtr GetOriginalImageSize(string jarg1);
 
         [global::System.Runtime.InteropServices.DllImport("libdali-csharp-binder.so", EntryPoint = "CSharp_Dali_DownloadImageSynchronously__SWIG_0")]
         public static extern global::System.IntPtr DownloadImageSynchronously__SWIG_0(string jarg1, global::System.Runtime.InteropServices.HandleRef jarg2, int jarg3, int jarg4, bool jarg5);
index af8a7ad..588f5c7 100755 (executable)
@@ -125,7 +125,7 @@ namespace Tizen.NUI.Xaml
                     var addMethod =
                         Context.Types[parentElement].GetRuntimeMethods().First(mi => mi.Name == "Add" && mi.GetParameters().Length == 1);
 
-                    addMethod.Invoke(source, new[] { value });
+                    addMethod?.Invoke(source, new[] { value });
                     return;
                 }
                 if (xpe == null && (contentProperty = GetContentPropertyName(Context.Types[parentElement].GetTypeInfo())) != null) {
index 1d5ce18..e3e40d8 100755 (executable)
@@ -197,7 +197,15 @@ namespace Tizen.NUI.Xaml
                             ci.GetParameters().Length != 0 && ci.IsPublic &&
                             ci.GetParameters().All(pi => pi.CustomAttributes.Any(attr => attr.AttributeType == typeof (ParameterAttribute))));
             object[] arguments = CreateArgumentsArray(node, ctorInfo);
-            return ctorInfo?.Invoke(arguments);
+
+            if (arguments != null)
+            {
+                return ctorInfo?.Invoke(arguments);
+            }
+            else
+            {
+                return null;
+            }
         }
 
         public object CreateFromFactory(Type nodeType, IElementNode node)
@@ -277,39 +285,43 @@ namespace Tizen.NUI.Xaml
 
         public object[] CreateArgumentsArray(IElementNode enode, ConstructorInfo ctorInfo)
         {
-            var n = ctorInfo.GetParameters().Length;
-            var array = new object[n];
-            for (var i = 0; i < n; i++)
+            if( ctorInfo != null )
             {
-                var parameter = ctorInfo.GetParameters()[i];
-                var propname =
-                    parameter?.CustomAttributes?.First(attr => attr.AttributeType == typeof (ParameterAttribute))?
-                        .ConstructorArguments.First()
-                        .Value as string;
-                var name = new XmlName("", propname);
-                INode node;
-                if (!enode.Properties.TryGetValue(name, out node))
+                var n = ctorInfo.GetParameters().Length;
+                var array = new object[n];
+                for (var i = 0; i < n; i++)
                 {
-                    String msg = "";
-                    if (propname != null)
-                    {
-                        msg = String.Format("The Property {0} is required to create a {1} object.", propname, ctorInfo.DeclaringType.FullName);
-                    }
-                    else
+                    var parameter = ctorInfo.GetParameters()[i];
+                    var propname =
+                        parameter?.CustomAttributes?.First(attr => attr.AttributeType == typeof (ParameterAttribute))?
+                            .ConstructorArguments.First()
+                            .Value as string;
+                    var name = new XmlName("", propname);
+                    INode node;
+                    if (!enode.Properties.TryGetValue(name, out node))
                     {
-                        msg = "propname is null.";
+                        String msg = "";
+                        if (propname != null)
+                        {
+                            msg = String.Format("The Property {0} is required to create a {1} object.", propname, ctorInfo.DeclaringType.FullName);
+                        }
+                        else
+                        {
+                            msg = "propname is null.";
+                        }
+                        throw new XamlParseException(msg, enode as IXmlLineInfo);
                     }
-                    throw new XamlParseException(msg, enode as IXmlLineInfo);
+                    if (!enode.SkipProperties.Contains(name))
+                        enode.SkipProperties.Add(name);
+                    var value = Context.Values[node];
+                    var serviceProvider = new XamlServiceProvider(enode, Context);
+                    var convertedValue = value.ConvertTo(parameter?.ParameterType, () => parameter, serviceProvider);
+                    array[i] = convertedValue;
                 }
-                if (!enode.SkipProperties.Contains(name))
-                    enode.SkipProperties.Add(name);
-                var value = Context.Values[node];
-                var serviceProvider = new XamlServiceProvider(enode, Context);
-                var convertedValue = value.ConvertTo(parameter.ParameterType, () => parameter, serviceProvider);
-                array[i] = convertedValue;
+                return array;
             }
 
-            return array;
+            return null;
         }
 
         static bool IsXaml2009LanguagePrimitive(IElementNode node)
index dcf80ec..b897657 100755 (executable)
@@ -160,7 +160,7 @@ namespace Tizen.NUI.Binding
                     if (e.NewStartingIndex == -1 || e.NewItems?.Count > 1)
                         goto case NotifyCollectionChangedAction.Reset;
 
-                    var newItem = e.NewItems[0] as TRestrict;
+                    var newItem = e.NewItems?[0] as TRestrict;
                     if (newItem == null || !newItem.Owned)
                         break;
 
@@ -171,7 +171,7 @@ namespace Tizen.NUI.Binding
                     if (e.NewStartingIndex == -1 || e.OldStartingIndex == -1 || e.NewItems?.Count > 1)
                         goto case NotifyCollectionChangedAction.Reset;
 
-                    var movedItem = e.NewItems[0] as TRestrict;
+                    var movedItem = e.NewItems?[0] as TRestrict;
                     if (movedItem == null || !movedItem.Owned)
                         break;
 
index 60d8506..028833e 100755 (executable)
@@ -211,6 +211,22 @@ namespace Tizen.NUI
         }
 
         /// <summary>
+        /// Get the size of an original image
+        /// </summary>
+        /// <param name="filename">The name of the image.</param>
+        /// <returns>Dimension of the original image.</returns>
+        /// <since_tizen> 5 </since_tizen>
+        /// This will be released at Tizen.NET API Level 5. Therefore, currently this would be used as an in-house API.
+        [EditorBrowsable(EditorBrowsableState.Never)]
+        public static Size2D GetOriginalImageSize(string filename)
+        {
+            var val = new Uint16Pair(NDalicPINVOKE.GetOriginalImageSize(filename), true);
+            Size2D ret = new Size2D(val.GetWidth(), val.GetHeight());
+            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
+            return ret;
+        }
+
+        /// <summary>
         /// Load an image synchronously from a remote resource.
         /// </summary>
         /// <param name="url">The URL of the image file to load.</param>
index 542d513..717ca1f 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Copyright(c) 2018 Samsung Electronics Co., Ltd.
+ * Copyright(c) 2019 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -53,12 +53,18 @@ namespace Tizen.NUI
 
         private static readonly Window instance = Application.Instance?.GetWindow();
 
+        private LayoutController localController;
+
         internal Window(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Window_SWIGUpcast(cPtr), cMemoryOwn)
         {
             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
             if (NDalicPINVOKE.Stage_IsInstalled())
             {
                 stageCPtr = new global::System.Runtime.InteropServices.HandleRef(this, NDalicPINVOKE.Stage_GetCurrent());
+
+                localController = new LayoutController();
+                NUILog.Debug("layoutController id:" + localController.GetId() );
+
                 // Create a root layout (AbsoluteLayout) that is invisible to the user but enables layouts added to the Window
                 // Enables layouts added to the Window to have a parent layout.  As parent layout is needed to store measure spec properties.
                 // Currently without these measure specs the new layout added will always be the size of the window.
@@ -983,7 +989,7 @@ namespace Tizen.NUI
         {
             if (depth < LayersChildren?.Count)
             {
-                Layer ret = LayersChildren[Convert.ToInt32(depth)];
+                Layer ret = LayersChildren?[Convert.ToInt32(depth)];
                 return ret;
             }
             else
@@ -1802,7 +1808,7 @@ namespace Tizen.NUI
         /// Disconnect all native signals
         /// </summary>
         /// <since_tizen> 5 </since_tizen>
-        internal void DisconnectNativeSignals() 
+        internal void DisconnectNativeSignals()
         {
             if( _windowFocusChangedEventCallback != null )
             {