[NUI][AT-SPI] Static class Accessibility (#3987)
authorArtur Świgoń <aswigon@yandex.com>
Fri, 4 Mar 2022 00:39:56 +0000 (01:39 +0100)
committerdongsug-song <35130733+dongsug-song@users.noreply.github.com>
Fri, 4 Mar 2022 05:31:52 +0000 (14:31 +0900)
This class serves as a collection of unrelated methods, which are all
static in DALi anyway, and as such is a good candidate for migration to
a C# 'static class'.

Co-authored-by: Artur Świgoń <a.swigon@samsung.com>
src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs
src/Tizen.NUI/src/internal/Interop/Interop.Accessibility.cs
src/Tizen.NUI/src/public/Accessibility/Accessibility.cs
src/Tizen.NUI/src/public/BaseComponents/ViewAccessibility.cs
test/NUITestSample/NUITestSample/examples/AtspiTest.cs
test/Tizen.NUI.Tests/Tizen.NUI.Devel.Tests/testcase/public/Accessibility/TSAccessibility.cs

index 94ca551..a60dc14 100755 (executable)
@@ -860,7 +860,7 @@ namespace Tizen.NUI.Components
                 disappearedPage.UnregisterDefaultLabel();
                 //We can call disappearedPage.NotifyAccessibilityStatesChange
                 //To reduce accessibility events, we are using currently highlighted view instead
-                View curHighlightedView = Accessibility.Accessibility.Instance.GetCurrentlyHighlightedView();
+                View curHighlightedView = Accessibility.Accessibility.GetCurrentlyHighlightedView();
                 if (curHighlightedView != null)
                 {
                     curHighlightedView.NotifyAccessibilityStatesChange(new AccessibilityStates(AccessibilityState.Visible, AccessibilityState.Showing), AccessibilityStatesNotifyMode.Single);
index 9311088..e45066c 100755 (executable)
@@ -24,23 +24,19 @@ namespace Tizen.NUI
     {
         internal static partial class Accessibility
         {
-            [DllImport(NDalicPINVOKE.Lib, EntryPoint = "csharp_dali_accessibility_get_status")]
-            [return: MarshalAs(UnmanagedType.U1)]
-            public static extern bool GetStatus(HandleRef jarg1);
-
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "csharp_dali_accessibility_say")]
             [return: MarshalAs(UnmanagedType.U1)]
-            public static extern bool Say(HandleRef jarg1, string jarg2, bool jarg3, IntPtr jarg4);
+            public static extern bool Say(string jarg1, bool jarg2, IntPtr jarg3);
 
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "csharp_dali_accessibility_pause_resume")]
-            public static extern void PauseResume(HandleRef jarg1, bool jarg2);
+            public static extern void PauseResume(bool jarg1);
 
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "csharp_dali_accessibility_stop_reading")]
-            public static extern void StopReading(HandleRef jarg1, bool jarg2);
+            public static extern void StopReading(bool jarg1);
 
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "csharp_dali_accessibility_suppress_screen_reader")]
             [return: MarshalAs(UnmanagedType.U1)]
-            public static extern bool SuppressScreenReader(HandleRef jarg1, bool jarg2);
+            public static extern bool SuppressScreenReader(bool jarg1);
 
             [DllImport(NDalicPINVOKE.Lib, EntryPoint = "csharp_dali_accessibility_BridgeEnableAutoInit")]
             public static extern void BridgeEnableAutoInit();
index 054cc9b..90eb52d 100755 (executable)
@@ -30,15 +30,10 @@ namespace Tizen.NUI.Accessibility
     [SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
     [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
     [EditorBrowsable(EditorBrowsableState.Never)]
-    public class Accessibility
+    public static class Accessibility
     {
-        #region Constructor, Destructor, Dispose
-        private Accessibility()
-        {
-            dummy = new View();
-            dummy.Name = "dali-atspi-singleton";
-        }
-
+        #region Constructor
+        [SuppressMessage("Microsoft.Performance", "CA1810: Initialize reference type static fields inline", Justification = "Need to call native code")]
         static Accessibility()
         {
             enabledSignalHandler = () =>
@@ -53,31 +48,10 @@ namespace Tizen.NUI.Accessibility
 
             Interop.Accessibility.RegisterEnabledDisabledSignalHandler(enabledSignalHandler, disabledSignalHandler);
         }
-
-        /// <summary>
-        /// destructor. This is HiddenAPI. recommended not to use in public.
-        /// </summary>
-        ~Accessibility()
-        {
-            Interop.Accessibility.RegisterEnabledDisabledSignalHandler(null, null);
-
-            Tizen.Log.Debug("NUI", $"Accessibility is destroyed\n");
-        }
-        #endregion Constructor, Destructor, Dispose
-
+        #endregion Constructor
 
         #region Property
         /// <summary>
-        /// Instance for singleton
-        /// </summary>
-        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        public static Accessibility Instance
-        {
-            get => accessibility;
-        }
-
-        /// <summary>
         /// Flag to check whether the state of Accessibility is enabled or not.
         /// </summary>
         /// <remarks>
@@ -95,20 +69,8 @@ namespace Tizen.NUI.Accessibility
 
         #endregion Property
 
-
         #region Method
         /// <summary>
-        /// Get the current status
-        /// </summary>
-        /// <returns>Current enabled status</returns>
-        // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
-        [EditorBrowsable(EditorBrowsableState.Never)]
-        static public bool GetStatus()
-        {
-            return true;
-        }
-
-        /// <summary>
         /// Start to speak
         /// </summary>
         /// <param name="sentence">Content to be spoken</param>
@@ -116,15 +78,10 @@ namespace Tizen.NUI.Accessibility
         /// <returns></returns>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool Say(string sentence, bool discardable)
+        public static bool Say(string sentence, bool discardable)
         {
-            IntPtr callbackIntPtr = IntPtr.Zero;
-            if (sayFinishedEventHandler != null)
-            {
-                callback = SayFinishedEventCallback;
-                callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
-            }
-            bool ret = Interop.Accessibility.Say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
+            bool ret = Interop.Accessibility.Say(sentence, discardable, Marshal.GetFunctionPointerForDelegate<Delegate>(callback));
+
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -135,9 +92,9 @@ namespace Tizen.NUI.Accessibility
         /// <param name="pause">true to be paused, false to be resumed</param>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void PauseResume(bool pause)
+        public static void PauseResume(bool pause)
         {
-            Interop.Accessibility.PauseResume(View.getCPtr(dummy), pause);
+            Interop.Accessibility.PauseResume(pause);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -147,9 +104,9 @@ namespace Tizen.NUI.Accessibility
         /// <param name="alsoNonDiscardable">whether to cancel non-discardable readings as well</param>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void StopReading(bool alsoNonDiscardable)
+        public static void StopReading(bool alsoNonDiscardable)
         {
-            Interop.Accessibility.StopReading(View.getCPtr(dummy), alsoNonDiscardable);
+            Interop.Accessibility.StopReading(alsoNonDiscardable);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
         }
 
@@ -159,9 +116,9 @@ namespace Tizen.NUI.Accessibility
         /// <param name="suppress">whether to suppress reading of screen-reader</param>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool SuppressScreenReader(bool suppress)
+        public static bool SuppressScreenReader(bool suppress)
         {
-            bool ret = Interop.Accessibility.SuppressScreenReader(View.getCPtr(dummy), suppress);
+            bool ret = Interop.Accessibility.SuppressScreenReader(suppress);
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
             return ret;
         }
@@ -198,7 +155,7 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View GetHighlightFrameView()
+        public static View GetHighlightFrameView()
         {
             var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetHighlightActor();
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -212,7 +169,7 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public void SetHighlightFrameView(View view)
+        public static void SetHighlightFrameView(View view)
         {
             Interop.ControlDevel.DaliAccessibilityAccessibleSetHighlightActor(View.getCPtr(view));
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
@@ -223,13 +180,13 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public View GetCurrentlyHighlightedView()
+        public static View GetCurrentlyHighlightedView()
         {
             var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetCurrentlyHighlightedActor();
 
             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
 
-            return this.GetInstanceSafely<View>(ptr);
+            return dummyHandle.GetInstanceSafely<View>(ptr);
         }
 
         /// <summary>
@@ -237,7 +194,7 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public bool ClearCurrentlyHighlightedView()
+        public static bool ClearCurrentlyHighlightedView()
         {
             var view = GetCurrentlyHighlightedView();
 
@@ -297,11 +254,7 @@ namespace Tizen.NUI.Accessibility
         /// </summary>
         // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
         [EditorBrowsable(EditorBrowsableState.Never)]
-        public event EventHandler<SayFinishedEventArgs> SayFinished
-        {
-            add => sayFinishedEventHandler += value;
-            remove => sayFinishedEventHandler -= value;
-        }
+        public static event EventHandler<SayFinishedEventArgs> SayFinished;
 
         /// <summary>
         /// Triggered whenever the value of IsEnabled would change from false to true
@@ -319,50 +272,24 @@ namespace Tizen.NUI.Accessibility
 
         #endregion Event, Enum, Struct, ETC
 
-
-        #region Internal
-        internal void PauseResume(View target, bool pause)
-        {
-            Interop.Accessibility.PauseResume(View.getCPtr(target), pause);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-        }
-
-        internal bool Say(View target, string sentence, bool discardable)
-        {
-            IntPtr callbackIntPtr = IntPtr.Zero;
-            if (sayFinishedEventHandler != null)
-            {
-                callback = SayFinishedEventCallback;
-                callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
-            }
-            bool ret = Interop.Accessibility.Say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
-            if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
-            return ret;
-        }
-        #endregion Internal
-
-
         #region Private
-        private static readonly Accessibility accessibility = new Accessibility();
-
-        private event EventHandler<SayFinishedEventArgs> sayFinishedEventHandler;
 
         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
         private delegate void SayFinishedEventCallbackType(int result);
 
-        private SayFinishedEventCallbackType callback = null;
+        private static SayFinishedEventCallbackType callback = SayFinishedEventCallback;
 
         private static Interop.Accessibility.EnabledDisabledSignalHandler enabledSignalHandler = null;
 
         private static Interop.Accessibility.EnabledDisabledSignalHandler disabledSignalHandler = null;
 
-        private void SayFinishedEventCallback(int result)
+        private static void SayFinishedEventCallback(int result)
         {
             NUILog.Debug($"sayFinishedEventCallback(res={result}) called!");
-            sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
+            SayFinished?.Invoke(typeof(Accessibility), new SayFinishedEventArgs(result));
         }
 
-        private View dummy;
+        private static BaseHandle dummyHandle = new BaseHandle();
 
         #endregion Private
     }
index 6388e2f..876c8e0 100755 (executable)
@@ -229,7 +229,7 @@ namespace Tizen.NUI.BaseComponents
         {
             get
             {
-                return (this == Accessibility.Accessibility.Instance.GetCurrentlyHighlightedView());
+                return (this == Accessibility.Accessibility.GetCurrentlyHighlightedView());
             }
         }
 
index 63eeed0..64b080b 100755 (executable)
@@ -76,35 +76,35 @@ namespace Tizen.TV.NUI.Example
                 //var accessbilityStatus = NDalicPINVOKE.accessibility_get_status(View.getCPtr(view));
                 if (e.Key.KeyPressedName == "Return")
                 {
-                    Accessibility.Instance.SayFinished -= Instance_SayFinished;
-                    Accessibility.Instance.Say("", true);
+                    Accessibility.SayFinished -= Instance_SayFinished;
+                    Accessibility.Say("", true);
                     repeatFlag = false;
                 }
                 else if (e.Key.KeyPressedName == "Right")
                 {
-                    Accessibility.Instance.Say(testScript1, true);
+                    Accessibility.Say(testScript1, true);
                 }
                 else if (e.Key.KeyPressedName == "Left")
                 {
-                    Accessibility.Instance.Say(testScript2, true);
+                    Accessibility.Say(testScript2, true);
                 }
                 else if (e.Key.KeyPressedName == "Up")
                 {
-                    Accessibility.Instance.Say(testScript3, true);
+                    Accessibility.Say(testScript3, true);
                 }
                 else if (e.Key.KeyPressedName == "Down")
                 {
                     repeatFlag = true;
-                    Accessibility.Instance.SayFinished += Instance_SayFinished;
-                    Accessibility.Instance.Say("my name is say api !!!", true);
+                    Accessibility.SayFinished += Instance_SayFinished;
+                    Accessibility.Say("my name is say api !!!", true);
                 }
                 else if (e.Key.KeyPressedName == "1")
                 {
-                    Accessibility.Instance.PauseResume(true);
+                    Accessibility.PauseResume(true);
                 }
                 else if (e.Key.KeyPressedName == "2")
                 {
-                    Accessibility.Instance.PauseResume(false);
+                    Accessibility.PauseResume(false);
                 }
             }
             return false;
@@ -115,7 +115,7 @@ namespace Tizen.TV.NUI.Example
             tlog.Fatal(tag, $"Instance_SayFinished()! State={e.State}");
             if (e.State == Accessibility.SayFinishedState.Stopped)
             {
-                Accessibility.Instance.Say("ÀÌ°Ç Äݹé Å×½ºÆ® ÀÔ´Ï´Ù. this is callback test!  ÄݹéÀ» »©·Á¸é È®ÀÎÅ°¸¦ ´©¸£¼¼¿ä. to remove callback please push Return key", true);
+                Accessibility.Say("ÀÌ°Ç Äݹé Å×½ºÆ® ÀÔ´Ï´Ù. this is callback test!  ÄݹéÀ» »©·Á¸é È®ÀÎÅ°¸¦ ´©¸£¼¼¿ä. to remove callback please push Return key", true);
             }
         }
 
index 19a38df..8ec5e18 100755 (executable)
@@ -28,24 +28,6 @@ namespace Tizen.NUI.Devel.Tests
 
         [Test]
         [Category("P1")]
-        [Description("Accessibility constructor.")]
-        [Property("SPEC", "Tizen.NUI.Accessibility.Accessibility C")]
-        [Property("SPEC_URL", "-")]
-        [Property("CRITERIA", "CONSTR")]
-        [Property("AUTHOR", "guowei.wang@samsung.com")]
-        public void AccessibilityConstructor()
-        {
-            tlog.Debug(tag, $"AccessibilityConstructor START");
-
-            var testingTarget = Accessibility.Accessibility.Instance; ;
-            Assert.IsNotNull(testingTarget, "Can't create success object Accessibility");
-            Assert.IsInstanceOf<Accessibility.Accessibility>(testingTarget, "Should be an instance of Accessibility type.");
-
-            tlog.Debug(tag, $"AccessibilityConstructor END (OK)");
-        }
-
-        [Test]
-        [Category("P1")]
         [Description("Accessibility GetStatus.")]
         [Property("SPEC", "Tizen.NUI.Accessibility.GetStatus M")]
         [Property("SPEC_URL", "-")]
@@ -80,11 +62,7 @@ namespace Tizen.NUI.Devel.Tests
         {
             tlog.Debug(tag, $"AccessibilitySay START");
 
-            var testingTarget = Accessibility.Accessibility.Instance; ;
-            Assert.IsNotNull(testingTarget, "Can't create success object Accessibility");
-            Assert.IsInstanceOf<Accessibility.Accessibility>(testingTarget, "Should be an instance of Accessibility type.");
-
-            var result = testingTarget.Say("Hi,Bixby! Please help to order a sandwich.", true);
+            var result = Accessibility.Accessibility.Say("Hi,Bixby! Please help to order a sandwich.", true);
             tlog.Debug(tag, "Status : " + result);
 
             tlog.Debug(tag, $"AccessibilitySay END (OK)");
@@ -101,13 +79,9 @@ namespace Tizen.NUI.Devel.Tests
         {
             tlog.Debug(tag, $"AccessibilityPauseResume START");
 
-            var testingTarget = Accessibility.Accessibility.Instance; ;
-            Assert.IsNotNull(testingTarget, "Can't create success object Accessibility");
-            Assert.IsInstanceOf<Accessibility.Accessibility>(testingTarget, "Should be an instance of Accessibility type.");
-
             try
             {
-                testingTarget.PauseResume(true);
+                Accessibility.Accessibility.PauseResume(true);
             }
             catch (Exception e)
             {
@@ -129,13 +103,9 @@ namespace Tizen.NUI.Devel.Tests
         {
             tlog.Debug(tag, $"AccessibilityStopReading START");
 
-            var testingTarget = Accessibility.Accessibility.Instance; ;
-            Assert.IsNotNull(testingTarget, "Can't create success object Accessibility");
-            Assert.IsInstanceOf<Accessibility.Accessibility>(testingTarget, "Should be an instance of Accessibility type.");
-
             try
             {
-                testingTarget.StopReading(true);
+                Accessibility.Accessibility.StopReading(true);
             }
             catch (Exception e)
             {
@@ -157,13 +127,9 @@ namespace Tizen.NUI.Devel.Tests
         {
             tlog.Debug(tag, $"AccessibilitySuppressScreenReader START");
 
-            var testingTarget = Accessibility.Accessibility.Instance; ;
-            Assert.IsNotNull(testingTarget, "Can't create success object Accessibility");
-            Assert.IsInstanceOf<Accessibility.Accessibility>(testingTarget, "Should be an instance of Accessibility type.");
-
             try
             {
-                testingTarget.SuppressScreenReader(false);
+                Accessibility.Accessibility.SuppressScreenReader(false);
             }
             catch (Exception e)
             {
@@ -233,10 +199,6 @@ namespace Tizen.NUI.Devel.Tests
         {
             tlog.Debug(tag, $"AccessibilitySetHighlightFrameView START");
 
-            var testingTarget = Accessibility.Accessibility.Instance; ;
-            Assert.IsNotNull(testingTarget, "Can't create success object Accessibility");
-            Assert.IsInstanceOf<Accessibility.Accessibility>(testingTarget, "Should be an instance of Accessibility type.");
-
             using (View view = new View())
             {
                 view.Size = new Size(100, 50);
@@ -246,11 +208,11 @@ namespace Tizen.NUI.Devel.Tests
 
                 try
                 {
-                    testingTarget.SetHighlightFrameView(view);
+                    Accessibility.Accessibility.SetHighlightFrameView(view);
 
-                    var result = testingTarget.GetHighlightFrameView();
+                    var result = Accessibility.Accessibility.GetHighlightFrameView();
                     tlog.Debug(tag, "HighlightFrameView : " + result);
-                    tlog.Debug(tag, "ClearCurrentlyHighlightedView : " + testingTarget.ClearCurrentlyHighlightedView());
+                    tlog.Debug(tag, "ClearCurrentlyHighlightedView : " + Accessibility.Accessibility.ClearCurrentlyHighlightedView());
                 }
                 catch (Exception e)
                 {
@@ -275,12 +237,8 @@ namespace Tizen.NUI.Devel.Tests
         {
             tlog.Debug(tag, $"AccessibilitySayFinished START");
 
-            var testingTarget = Accessibility.Accessibility.Instance;
-            Assert.IsNotNull(testingTarget, "Can't create success object Accessibility");
-            Assert.IsInstanceOf<Accessibility.Accessibility>(testingTarget, "Should be an instance of Accessibility type.");
-
-            testingTarget.SayFinished += OnSayFinished;
-            testingTarget.SayFinished -= OnSayFinished;
+            Accessibility.Accessibility.SayFinished += OnSayFinished;
+            Accessibility.Accessibility.SayFinished -= OnSayFinished;
 
             tlog.Debug(tag, $"AccessibilitySayFinished END (OK)");
         }