2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21 using Tizen.NUI.BaseComponents;
22 using System.Diagnostics.CodeAnalysis;
24 using tlog = Tizen.Log;
27 namespace Tizen.NUI.Accessibility
30 /// Accessibility provides Dali-ATSPI interface which has functionality of Screen-Reader and general accessibility
32 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
33 [SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
34 [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public class Accessibility
38 #region Constructor, Destructor, Dispose
39 private Accessibility()
42 dummy.Name = "dali-atspi-singleton";
45 /// destructor. This is HiddenAPI. recommended not to use in public.
49 Tizen.Log.Debug("NUI", $"Accessibility is destroyed\n");
51 #endregion Constructor, Destructor, Dispose
56 /// Instance for singleton
58 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public static Accessibility Instance
69 /// Get the current status
71 /// <returns>Current enabled status</returns>
72 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
73 [EditorBrowsable(EditorBrowsableState.Never)]
74 static public bool GetStatus()
82 /// <param name="sentence">Content to be spoken</param>
83 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
84 /// <returns></returns>
85 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
86 [EditorBrowsable(EditorBrowsableState.Never)]
87 public bool Say(string sentence, bool discardable)
89 IntPtr callbackIntPtr = IntPtr.Zero;
90 if (sayFinishedEventHandler != null)
92 callback = SayFinishedEventCallback;
93 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
95 bool ret = Interop.Accessibility.Say(View.getCPtr(dummy), sentence, discardable, callbackIntPtr);
96 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
101 /// To make Say be paused or resumed
103 /// <param name="pause">true to be paused, false to be resumed</param>
104 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
105 [EditorBrowsable(EditorBrowsableState.Never)]
106 public void PauseResume(bool pause)
108 Interop.Accessibility.PauseResume(View.getCPtr(dummy), pause);
109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 /// Cancels anything screen-reader is reading / has queued to read
115 /// <param name="alsoNonDiscardable">whether to cancel non-discardable readings as well</param>
116 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
117 [EditorBrowsable(EditorBrowsableState.Never)]
118 public void StopReading(bool alsoNonDiscardable)
120 Interop.Accessibility.StopReading(View.getCPtr(dummy), alsoNonDiscardable);
121 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
125 /// Get View that is used to highlight widget.
127 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
128 [EditorBrowsable(EditorBrowsableState.Never)]
129 public View GetHighlightFrameView()
131 var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetHighlightActor();
132 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
133 if (ptr == IntPtr.Zero)
135 return new View(ptr, true);
139 /// Set view that will be used to highlight widget.
141 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
142 [EditorBrowsable(EditorBrowsableState.Never)]
143 public void SetHighlightFrameView(View view)
145 Interop.ControlDevel.DaliAccessibilityAccessibleSetHighlightActor(View.getCPtr(view));
146 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
150 /// Get highligted View.
152 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
153 [EditorBrowsable(EditorBrowsableState.Never)]
154 public View GetCurrentlyHighlightedView()
156 var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetCurrentlyHighlightedActor();
157 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
158 if (ptr == IntPtr.Zero)
160 return new View(ptr, true);
166 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
167 [EditorBrowsable(EditorBrowsableState.Never)]
168 public bool ClearCurrentlyHighlightedView()
170 using (View view = GetCurrentlyHighlightedView())
172 return view?.ClearAccessibilityHighlight() ?? false;
178 #region Event, Enum, Struct, ETC
180 /// Enum of Say finished event argument status
182 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
183 [EditorBrowsable(EditorBrowsableState.Never)]
184 public enum SayFinishedState
189 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
190 [EditorBrowsable(EditorBrowsableState.Never)]
195 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
196 [EditorBrowsable(EditorBrowsableState.Never)]
201 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
202 [EditorBrowsable(EditorBrowsableState.Never)]
207 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
208 [EditorBrowsable(EditorBrowsableState.Never)]
213 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
214 [EditorBrowsable(EditorBrowsableState.Never)]
219 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
220 [EditorBrowsable(EditorBrowsableState.Never)]
225 /// When Say is finished, this event is triggered
227 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
228 [EditorBrowsable(EditorBrowsableState.Never)]
229 public event EventHandler<SayFinishedEventArgs> SayFinished
231 add => sayFinishedEventHandler += value;
232 remove => sayFinishedEventHandler -= value;
234 #endregion Event, Enum, Struct, ETC
238 internal void PauseResume(View target, bool pause)
240 Interop.Accessibility.PauseResume(View.getCPtr(target), pause);
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244 internal bool Say(View target, string sentence, bool discardable)
246 IntPtr callbackIntPtr = IntPtr.Zero;
247 if (sayFinishedEventHandler != null)
249 callback = SayFinishedEventCallback;
250 callbackIntPtr = Marshal.GetFunctionPointerForDelegate<Delegate>(callback);
252 bool ret = Interop.Accessibility.Say(View.getCPtr(target), sentence, discardable, callbackIntPtr);
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 private static readonly Accessibility accessibility = new Accessibility();
262 private event EventHandler<SayFinishedEventArgs> sayFinishedEventHandler;
264 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
265 private delegate void SayFinishedEventCallbackType(int result);
267 private SayFinishedEventCallbackType callback = null;
269 private void SayFinishedEventCallback(int result)
271 tlog.Fatal(tag, $"sayFinishedEventCallback(res={result}) called!");
272 sayFinishedEventHandler?.Invoke(this, new SayFinishedEventArgs(result));
277 private static string tag = "NUITEST";
282 /// Say Finished event arguments
284 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
285 [EditorBrowsable(EditorBrowsableState.Never)]
286 public class SayFinishedEventArgs : EventArgs
289 /// The state of Say finished
291 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public Accessibility.SayFinishedState State
299 internal SayFinishedEventArgs(int result)
301 State = (Accessibility.SayFinishedState)(result);
302 tlog.Fatal("NUITEST", $"SayFinishedEventArgs Constructor! State={State}");