From 142bb4717dd7ed4fd4077a4cd9d67d1fc2a78140 Mon Sep 17 00:00:00 2001 From: huiyueun <35286162+huiyueun@users.noreply.github.com> Date: Tue, 19 Feb 2019 15:40:43 +0900 Subject: [PATCH] [NUI] sync with dalihub (#718) * [NUI] Codacy error fix Change-Id: Ib407c7be01ad4e42913bf7896edc050e9b4bd370 Signed-off-by: dongsug.song * [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 --- .../src/internal/Layouting/LayoutController.cs | 123 +++++++++++++++++++++ .../src/internal/Layouting/LayoutPINVOKE.cs | 19 +++- src/Tizen.NUI/src/internal/ManualPINVOKE.cs | 2 +- src/Tizen.NUI/src/internal/NDalicPINVOKE.cs | 2 + .../src/internal/Xaml/ApplyPropertiesVisitor.cs | 2 +- .../src/internal/Xaml/CreateValuesVisitor.cs | 66 ++++++----- .../src/internal/XamlBinding/ObservableWrapper.cs | 4 +- .../StyleSheets/StyleSheetExtensions.cs | 2 +- src/Tizen.NUI/src/public/ImageLoading.cs | 16 +++ src/Tizen.NUI/src/public/Window.cs | 12 +- 10 files changed, 211 insertions(+), 37 deletions(-) create mode 100644 src/Tizen.NUI/src/internal/Layouting/LayoutController.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 index 0000000..0d2c3e3 --- /dev/null +++ b/src/Tizen.NUI/src/internal/Layouting/LayoutController.cs @@ -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 +{ + /// + /// [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. + /// + 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; + + + /// + /// Constructs a LayoutController which controls the measuring and layouting.
+ ///
+ + 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); + } + + /// + /// Get the unique id of the LayoutController + /// + public int GetId() + { + return LayoutPINVOKE.LayoutController_GetId(unmanagedLayoutController); + } + + /// + /// Destructor which adds LayoutController to the Dispose queue. + /// + ~LayoutController() + { + Dispose(DisposeTypes.Explicit); + } + + /// + /// Explict Dispose. + /// + + public void Dispose() + { + Dispose(DisposeTypes.Explicit); + System.GC.SuppressFinalize(this); + } + + /// + /// Dispose Explict or Implicit + /// + 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; + } + + /// + /// Entry point into the C# Layouting that starts the Processing + /// + private void Process(int id) + { + NUILog.Debug("layoutController Process id:" + id ); + } + + } // class LayoutController + +} // namespace Tizen.NUI \ No newline at end of file diff --git a/src/Tizen.NUI/src/internal/Layouting/LayoutPINVOKE.cs b/src/Tizen.NUI/src/internal/Layouting/LayoutPINVOKE.cs index 011f0dc..e138fde 100755 --- a/src/Tizen.NUI/src/internal/Layouting/LayoutPINVOKE.cs +++ b/src/Tizen.NUI/src/internal/Layouting/LayoutPINVOKE.cs @@ -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); + } } diff --git a/src/Tizen.NUI/src/internal/ManualPINVOKE.cs b/src/Tizen.NUI/src/internal/ManualPINVOKE.cs index 836ea87..c968873 100755 --- a/src/Tizen.NUI/src/internal/ManualPINVOKE.cs +++ b/src/Tizen.NUI/src/internal/ManualPINVOKE.cs @@ -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. diff --git a/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs b/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs index 1ddf841..1b8b31a 100755 --- a/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs +++ b/src/Tizen.NUI/src/internal/NDalicPINVOKE.cs @@ -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); diff --git a/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs b/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs index af8a7ad..588f5c7 100755 --- a/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs +++ b/src/Tizen.NUI/src/internal/Xaml/ApplyPropertiesVisitor.cs @@ -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) { diff --git a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs index 1d5ce18..e3e40d8 100755 --- a/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs +++ b/src/Tizen.NUI/src/internal/Xaml/CreateValuesVisitor.cs @@ -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) diff --git a/src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs b/src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs index dcf80ec..b897657 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/ObservableWrapper.cs @@ -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; diff --git a/src/Tizen.NUI/src/internal/XamlBinding/StyleSheets/StyleSheetExtensions.cs b/src/Tizen.NUI/src/internal/XamlBinding/StyleSheets/StyleSheetExtensions.cs index a67a9c3..3a12a85 100755 --- a/src/Tizen.NUI/src/internal/XamlBinding/StyleSheets/StyleSheetExtensions.cs +++ b/src/Tizen.NUI/src/internal/XamlBinding/StyleSheets/StyleSheetExtensions.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Tizen.NUI.Binding; namespace Tizen.NUI.StyleSheets diff --git a/src/Tizen.NUI/src/public/ImageLoading.cs b/src/Tizen.NUI/src/public/ImageLoading.cs index 60d8506..028833e 100755 --- a/src/Tizen.NUI/src/public/ImageLoading.cs +++ b/src/Tizen.NUI/src/public/ImageLoading.cs @@ -211,6 +211,22 @@ namespace Tizen.NUI } /// + /// Get the size of an original image + /// + /// The name of the image. + /// Dimension of the original image. + /// 5 + /// 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; + } + + /// /// Load an image synchronously from a remote resource. /// /// The URL of the image file to load. diff --git a/src/Tizen.NUI/src/public/Window.cs b/src/Tizen.NUI/src/public/Window.cs index 542d513..717ca1f 100755 --- a/src/Tizen.NUI/src/public/Window.cs +++ b/src/Tizen.NUI/src/public/Window.cs @@ -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 /// /// 5 - internal void DisconnectNativeSignals() + internal void DisconnectNativeSignals() { if( _windowFocusChangedEventCallback != null ) { -- 2.7.4