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 namespace Tizen.NUI.Accessibility
27 /// Accessibility provides Dali-ATSPI interface which has functionality of Screen-Reader and general accessibility
29 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
30 [SuppressMessage("Microsoft.Design", "CA1724: Type names should not match namespaces")]
31 [SuppressMessage("Microsoft.Design", "CA1001:Types that own disposable fields should be disposable", Justification = "This is a singleton class and is not disposed")]
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 public static class Accessibility
36 [SuppressMessage("Microsoft.Performance", "CA1810: Initialize reference type static fields inline", Justification = "Need to call native code")]
37 static Accessibility()
39 enabledSignalHandler = () =>
41 Enabled?.Invoke(typeof(Accessibility), EventArgs.Empty);
44 disabledSignalHandler = () =>
46 Disabled?.Invoke(typeof(Accessibility), EventArgs.Empty);
49 Interop.Accessibility.RegisterEnabledDisabledSignalHandler(enabledSignalHandler, disabledSignalHandler);
51 #endregion Constructor
55 /// Flag to check whether the state of Accessibility is enabled or not.
58 /// Getter returns true if Accessibility is enabled, false otherwise.
60 /// This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 public static bool IsEnabled
66 return (bool)Interop.Accessibility.IsEnabled();
76 /// <param name="sentence">Content to be spoken</param>
77 /// <param name="discardable">true to be stopped and discarded when other Say is triggered</param>
78 /// <returns></returns>
79 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public static bool Say(string sentence, bool discardable)
83 bool ret = Interop.Accessibility.Say(sentence, discardable, Marshal.GetFunctionPointerForDelegate<Delegate>(callback));
85 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90 /// To make Say be paused or resumed
92 /// <param name="pause">true to be paused, false to be resumed</param>
93 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
94 [EditorBrowsable(EditorBrowsableState.Never)]
95 public static void PauseResume(bool pause)
97 Interop.Accessibility.PauseResume(pause);
98 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102 /// Cancels anything screen-reader is reading / has queued to read
104 /// <param name="alsoNonDiscardable">whether to cancel non-discardable readings as well</param>
105 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
106 [EditorBrowsable(EditorBrowsableState.Never)]
107 public static void StopReading(bool alsoNonDiscardable)
109 Interop.Accessibility.StopReading(alsoNonDiscardable);
110 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114 /// Suppress reading of screen-reader
116 /// <param name="suppress">whether to suppress reading of screen-reader</param>
117 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 public static bool SuppressScreenReader(bool suppress)
121 bool ret = Interop.Accessibility.SuppressScreenReader(suppress);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 /// Re-enables auto-initialization of AT-SPI bridge
130 /// Normal applications do not have to call this function. The AT-SPI bridge is initialized on demand.
132 [EditorBrowsable(EditorBrowsableState.Never)]
133 public static void BridgeEnableAutoInit()
135 Interop.Accessibility.BridgeEnableAutoInit();
136 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 /// Blocks auto-initialization of AT-SPI bridge
143 /// Use this only if your application starts before DBus does, and call it early in Main().
144 /// When DBus is ready, call BridgeEnableAutoInit().
146 [EditorBrowsable(EditorBrowsableState.Never)]
147 public static void BridgeDisableAutoInit()
149 Interop.Accessibility.BridgeDisableAutoInit();
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 /// Get View that is used to highlight widget.
156 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
157 [EditorBrowsable(EditorBrowsableState.Never)]
158 public static View GetHighlightFrameView()
160 var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetHighlightActor();
161 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162 if (ptr == IntPtr.Zero)
164 return new View(ptr, true);
168 /// Set view that will be used to highlight widget.
170 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
171 [EditorBrowsable(EditorBrowsableState.Never)]
172 public static void SetHighlightFrameView(View view)
174 Interop.ControlDevel.DaliAccessibilityAccessibleSetHighlightActor(View.getCPtr(view));
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179 /// Get highligted View.
181 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
182 [EditorBrowsable(EditorBrowsableState.Never)]
183 public static View GetCurrentlyHighlightedView()
185 var ptr = Interop.ControlDevel.DaliAccessibilityAccessibleGetCurrentlyHighlightedActor();
187 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189 return dummyHandle.GetInstanceSafely<View>(ptr);
195 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
196 [EditorBrowsable(EditorBrowsableState.Never)]
197 public static bool ClearCurrentlyHighlightedView()
199 var view = GetCurrentlyHighlightedView();
201 return view?.ClearAccessibilityHighlight() ?? false;
206 #region Event, Enum, Struct, ETC
208 /// Enum of Say finished event argument status
210 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
211 [EditorBrowsable(EditorBrowsableState.Never)]
212 public enum SayFinishedState
217 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
218 [EditorBrowsable(EditorBrowsableState.Never)]
223 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
224 [EditorBrowsable(EditorBrowsableState.Never)]
229 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
230 [EditorBrowsable(EditorBrowsableState.Never)]
235 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
236 [EditorBrowsable(EditorBrowsableState.Never)]
241 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
242 [EditorBrowsable(EditorBrowsableState.Never)]
247 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
248 [EditorBrowsable(EditorBrowsableState.Never)]
253 /// When Say is finished, this event is triggered
255 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
256 [EditorBrowsable(EditorBrowsableState.Never)]
257 public static event EventHandler<SayFinishedEventArgs> SayFinished;
260 /// Triggered whenever the value of IsEnabled would change from false to true
262 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
263 [EditorBrowsable(EditorBrowsableState.Never)]
264 public static event EventHandler Enabled;
267 /// Triggered whenever the value of IsEnabled would change from true to false
269 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
270 [EditorBrowsable(EditorBrowsableState.Never)]
271 public static event EventHandler Disabled;
273 #endregion Event, Enum, Struct, ETC
277 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
278 private delegate void SayFinishedEventCallbackType(int result);
280 private static SayFinishedEventCallbackType callback = SayFinishedEventCallback;
282 private static Interop.Accessibility.EnabledDisabledSignalHandler enabledSignalHandler = null;
284 private static Interop.Accessibility.EnabledDisabledSignalHandler disabledSignalHandler = null;
286 private static void SayFinishedEventCallback(int result)
288 NUILog.Debug($"sayFinishedEventCallback(res={result}) called!");
289 SayFinished?.Invoke(typeof(Accessibility), new SayFinishedEventArgs(result));
292 private static BaseHandle dummyHandle = new BaseHandle();
298 /// Say Finished event arguments
300 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
301 [EditorBrowsable(EditorBrowsableState.Never)]
302 public class SayFinishedEventArgs : EventArgs
305 /// The state of Say finished
307 // This will be public opened after ACR done. (Before ACR, need to be hidden as Inhouse API)
308 [EditorBrowsable(EditorBrowsableState.Never)]
309 public Accessibility.SayFinishedState State
315 internal SayFinishedEventArgs(int result)
317 State = (Accessibility.SayFinishedState)(result);
318 NUILog.Debug($"SayFinishedEventArgs Constructor! State={State}");