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.Collections.Generic;
20 using System.ComponentModel;
21 using System.Runtime.InteropServices;
24 namespace Tizen.NUI.BaseComponents
27 /// AccessibilityRange is used to store data related with Text.
29 [EditorBrowsable(EditorBrowsableState.Never)]
30 public class AccessibilityRange
33 /// Start position in stored text.
35 public int StartOffset { get; set; } = 0;
38 /// End position in stored text.
40 public int EndOffset { get; set; } = 0;
43 /// Text content in stored text.
45 public string Content { get; set; } = "";
49 /// View is the base class for all views.
51 /// <since_tizen> 3 </since_tizen>
52 public partial class View
54 ///////////////////////////////////////////////////////////////////
55 // ****************** Accessibility Attributes ****************** //
56 ///////////////////////////////////////////////////////////////////
59 /// Dictionary of accessibility attributes (key-value pairs of strings).
61 [EditorBrowsable(EditorBrowsableState.Never)]
62 protected Dictionary<string, string> AccessibilityAttributes { get; } = new Dictionary<string, string>();
64 ///////////////////////////////////////////////////////////////////
65 // ************************** Highlight ************************ //
66 ///////////////////////////////////////////////////////////////////
69 /// Clears accessibility highlight.
71 /// <returns>True if cleared, otherwise false when it is not possible</returns>
72 [EditorBrowsable(EditorBrowsableState.Never)]
73 public bool ClearAccessibilityHighlight()
75 bool result = Interop.ControlDevel.DaliToolkitDevelControlClearAccessibilityHighlight(SwigCPtr);
76 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
81 /// Grabs accessibility highlight.
83 /// <returns>True if cleared, otherwise false when it is not possible</returns>
84 [EditorBrowsable(EditorBrowsableState.Never)]
85 public bool GrabAccessibilityHighlight()
87 bool result = Interop.ControlDevel.DaliToolkitDevelControlGrabAccessibilityHighlight(SwigCPtr);
88 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
93 /// Flag to check whether this view is highlighted or not.
95 [EditorBrowsable(EditorBrowsableState.Never)]
96 protected bool IsHighlighted
100 return (this == Accessibility.Accessibility.GetCurrentlyHighlightedView());
104 ///////////////////////////////////////////////////////////////////
105 // ****************** Accessibility Relations ******************* //
106 ///////////////////////////////////////////////////////////////////
109 /// Creates relation between objects.
111 /// <param name="second">Object which will be in relation.</param>
112 /// <param name="relation">Relation type.</param>
113 /// <exception cref="ArgumentNullException">You must pass valid object. NULL could not be in relation.</exception>
114 [EditorBrowsable(EditorBrowsableState.Never)]
115 public void AppendAccessibilityRelation(View second, AccessibilityRelationType relation)
119 throw new ArgumentNullException(nameof(second));
122 Interop.ControlDevel.DaliToolkitDevelControlAppendAccessibilityRelation(SwigCPtr, second.SwigCPtr, (int)relation);
123 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127 /// Removes accessibility relation.
129 /// <param name="second">Object which will be removed in relation</param>
130 /// <param name="relation">Relation type</param>
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public void RemoveAccessibilityRelation(View second, AccessibilityRelationType relation)
136 throw new ArgumentNullException(nameof(second));
139 Interop.ControlDevel.DaliToolkitDevelControlRemoveAccessibilityRelation(SwigCPtr, second.SwigCPtr, (int)relation);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
144 /// Removes all previously appended relations.
146 [EditorBrowsable(EditorBrowsableState.Never)]
147 public void ClearAccessibilityRelations()
149 Interop.ControlDevel.DaliToolkitDevelControlClearAccessibilityRelations(SwigCPtr);
150 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154 /// Gets accessibility collection connected with the current object.
156 /// <returns>A dictionary mapping a relation type to a set of objects in that relation</returns>
157 [EditorBrowsable(EditorBrowsableState.Never)]
158 public Dictionary<AccessibilityRelationType, List<View>> GetAccessibilityRelations()
160 var list = new List<KeyValuePair<int, IntPtr>>();
161 var listHandle = GCHandle.Alloc(list);
162 var callback = new Interop.ControlDevel.GetAccessibilityRelationsCallback(GetAccessibilityRelationsCallback);
164 Interop.ControlDevel.DaliToolkitDevelControlGetAccessibilityRelations(SwigCPtr, callback, GCHandle.ToIntPtr(listHandle));
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168 var result = new Dictionary<AccessibilityRelationType, List<View>>();
170 foreach (var pair in list)
172 var key = (AccessibilityRelationType)pair.Key;
173 var value = this.GetInstanceSafely<View>(pair.Value);
175 if (!result.ContainsKey(key))
177 result[key] = new List<View>();
180 result[key].Add(value);
186 private static void GetAccessibilityRelationsCallback(int relationType, IntPtr relationTarget, IntPtr userData)
188 var handle = GCHandle.FromIntPtr(userData);
189 var list = (List<KeyValuePair<int, IntPtr>>)handle.Target;
191 list.Add(new KeyValuePair<int, IntPtr>(relationType, relationTarget));
194 ///////////////////////////////////////////////////////////////////
195 // ********************* ReadingInfoType *********************** //
196 ///////////////////////////////////////////////////////////////////
199 /// Sets accessibility reading information.
201 /// <param name="type">Reading information type</param>
202 [EditorBrowsable(EditorBrowsableState.Never)]
203 public void SetAccessibilityReadingInfoTypes(AccessibilityReadingInfoTypes type)
205 Interop.ControlDevel.DaliToolkitDevelControlSetAccessibilityReadingInfoTypes(SwigCPtr, (int)type);
206 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
210 /// Gets accessibility reading information.
212 /// <returns>Reading information type</returns>
213 [EditorBrowsable(EditorBrowsableState.Never)]
214 public AccessibilityReadingInfoTypes GetAccessibilityReadingInfoTypes()
216 AccessibilityReadingInfoTypes result = (AccessibilityReadingInfoTypes)Interop.ControlDevel.DaliToolkitDevelControlGetAccessibilityReadingInfoTypes(SwigCPtr);
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221 ///////////////////////////////////////////////////////////////////
222 // ******************** Accessibility States ******************* //
223 ///////////////////////////////////////////////////////////////////
226 /// Notifies sending notifications about the current states to accessibility clients.
229 /// In essence, this is equivalent to calling EmitAccessibilityStateChangedEvent in a loop for all specified states.
230 /// If recursive mode is specified, all children of the Accessibility object will also re-emit the states.
232 /// <param name="states">Accessibility States</param>
233 /// <param name="notifyMode">Controls the notification strategy</param>
234 [EditorBrowsable(EditorBrowsableState.Never)]
235 public void NotifyAccessibilityStatesChange(AccessibilityStates states, AccessibilityStatesNotifyMode notifyMode)
239 throw new ArgumentNullException(nameof(states));
242 Interop.ControlDevel.DaliToolkitDevelControlNotifyAccessibilityStateChange(SwigCPtr, states.BitMask, (int)notifyMode);
243 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247 /// Gets Accessibility States.
249 /// <returns>Accessibility States</returns>
250 [EditorBrowsable(EditorBrowsableState.Never)]
251 public AccessibilityStates GetAccessibilityStates()
253 var result = new AccessibilityStates {BitMask = Interop.ControlDevel.DaliToolkitDevelControlGetAccessibilityStates(SwigCPtr)};
254 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 ///////////////////////////////////////////////////////////////////
259 // ************************ Accessible ************************* //
260 ///////////////////////////////////////////////////////////////////
263 /// Emits accessibility property changed event.
265 /// <param name="changeEvent">Property changed event</param>
266 [EditorBrowsable(EditorBrowsableState.Never)]
267 public void EmitAccessibilityEvent(AccessibilityPropertyChangeEvent changeEvent)
269 Interop.ControlDevel.DaliAccessibilityEmitAccessibilityEvent(SwigCPtr, Convert.ToInt32(changeEvent));
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 /// Emits accessibility states changed event.
276 /// <param name="state">Accessibility state</param>
277 /// <param name="equal">True if the state is set or enabled, otherwise false</param>
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public void EmitAccessibilityStateChangedEvent(AccessibilityState state, bool equal)
281 Interop.ControlDevel.DaliAccessibilityEmitAccessibilityStateChangedEvent(SwigCPtr, (int)state, Convert.ToInt32(equal));
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Emits accessibility text inserted event.
288 /// <param name="cursorPosition">Text cursor position</param>
289 /// <param name="length">Text length</param>
290 /// <param name="content">Inserted text content</param>
291 [EditorBrowsable(EditorBrowsableState.Never)]
292 public void EmitTextInsertedEvent(int cursorPosition, int length, string content)
294 Interop.ControlDevel.DaliAccessibilityEmitTextInsertedEvent(SwigCPtr, cursorPosition, length, content);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 /// Emits accessibility text deleted event.
301 /// <param name="cursorPosition">Text cursor position</param>
302 /// <param name="length">Text length</param>
303 /// <param name="content">Inserted text content</param>
304 [EditorBrowsable(EditorBrowsableState.Never)]
305 public void EmitTextDeletedEvent(int cursorPosition, int length, string content)
307 Interop.ControlDevel.DaliAccessibilityEmitTextDeletedEvent(SwigCPtr, cursorPosition, length, content);
308 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 /// Emits accessibility text cursor moved event.
314 /// <param name="cursorPosition">The new cursor position</param>
315 [EditorBrowsable(EditorBrowsableState.Never)]
316 public void EmitTextCursorMovedEvent(int cursorPosition)
318 Interop.ControlDevel.DaliAccessibilityEmitTextCursorMovedEvent(SwigCPtr, cursorPosition);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 /// Modifiable collection of suppressed AT-SPI events (D-Bus signals).
325 [EditorBrowsable(EditorBrowsableState.Never)]
326 public AccessibilityEvents AccessibilitySuppressedEvents
330 return new AccessibilityEvents {Owner = this};
334 ///////////////////////////////////////////////////////////////////
335 // ************************** Bridge *************************** //
336 ///////////////////////////////////////////////////////////////////
339 /// Registers component as a source of an accessibility "default label".
340 /// The "Default label" is a text that could be read by screen-reader immediately
341 /// after the navigation context has changed (window activates, popup shows up, tab changes)
342 /// and before first UI element is highlighted.
344 [EditorBrowsable(EditorBrowsableState.Never)]
345 public void RegisterDefaultLabel()
347 Interop.ControlDevel.DaliAccessibilityBridgeRegisterDefaultLabel(SwigCPtr);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352 /// Unregisters component that has been registered previously as a source of an accessibility "default label".
353 /// The "Default label" is a text that could be read by screen-reader immediately
354 /// after the navigation context has changed (window activates, popup shows up, tab changes)
355 /// and before first UI element is highlighted.
357 [EditorBrowsable(EditorBrowsableState.Never)]
358 public void UnregisterDefaultLabel()
360 Interop.ControlDevel.DaliAccessibilityBridgeUnregisterDefaultLabel(SwigCPtr);
361 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 [EditorBrowsable(EditorBrowsableState.Never)]
365 protected override void Dispose(bool disposing)
374 if (disposing == false)
376 if (IsNativeHandleInvalid() || SwigCMemOwn == false)
378 // at this case, implicit nor explicit dispose is not required. No native object is made.
389 base.Dispose(disposing);
392 [EditorBrowsable(EditorBrowsableState.Never)]
393 protected static readonly string AccessibilityActivateAction = "activate";
394 [EditorBrowsable(EditorBrowsableState.Never)]
395 protected static readonly string AccessibilityReadingSkippedAction = "ReadingSkipped";
396 [EditorBrowsable(EditorBrowsableState.Never)]
397 protected static readonly string AccessibilityReadingCancelledAction = "ReadingCancelled";
398 [EditorBrowsable(EditorBrowsableState.Never)]
399 protected static readonly string AccessibilityReadingStoppedAction = "ReadingStopped";
400 [EditorBrowsable(EditorBrowsableState.Never)]
401 protected static readonly string AccessibilityReadingPausedAction = "ReadingPaused";
402 [EditorBrowsable(EditorBrowsableState.Never)]
403 protected static readonly string AccessibilityReadingResumedAction = "ReadingResumed";
405 [EditorBrowsable(EditorBrowsableState.Never)]
406 private static readonly string[] AccessibilityActions = {
407 AccessibilityActivateAction,
408 AccessibilityReadingSkippedAction,
409 AccessibilityReadingCancelledAction,
410 AccessibilityReadingStoppedAction,
411 AccessibilityReadingPausedAction,
412 AccessibilityReadingResumedAction,
415 [EditorBrowsable(EditorBrowsableState.Never)]
416 protected virtual string AccessibilityGetName()
421 [EditorBrowsable(EditorBrowsableState.Never)]
422 protected virtual string AccessibilityGetDescription()
427 [EditorBrowsable(EditorBrowsableState.Never)]
428 protected virtual bool AccessibilityDoAction(string name)
430 if (name == AccessibilityActivateAction)
432 if (ActivateSignal?.Empty() == false)
434 ActivateSignal?.Emit();
439 return OnAccessibilityActivated();
442 else if (name == AccessibilityReadingSkippedAction)
444 if (ReadingSkippedSignal?.Empty() == false)
446 ReadingSkippedSignal?.Emit();
451 return OnAccessibilityReadingSkipped();
454 else if (name == AccessibilityReadingCancelledAction)
456 if (ReadingCancelledSignal?.Empty() == false)
458 ReadingCancelledSignal?.Emit();
463 return OnAccessibilityReadingCancelled();
466 else if (name == AccessibilityReadingStoppedAction)
468 if (ReadingStoppedSignal?.Empty() == false)
470 ReadingStoppedSignal?.Emit();
475 return OnAccessibilityReadingStopped();
478 else if (name == AccessibilityReadingPausedAction)
480 if (ReadingPausedSignal?.Empty() == false)
482 ReadingPausedSignal?.Emit();
487 return OnAccessibilityReadingPaused();
490 else if (name == AccessibilityReadingResumedAction)
492 if (ReadingResumedSignal?.Empty() == false)
494 ReadingResumedSignal?.Emit();
499 return OnAccessibilityReadingResumed();
508 [EditorBrowsable(EditorBrowsableState.Never)]
509 protected virtual AccessibilityStates AccessibilityCalculateStates()
511 var states = AccessibilityInitialStates;
513 states[AccessibilityState.Focused] = this.State == States.Focused;
514 states[AccessibilityState.Enabled] = this.State != States.Disabled;
515 states[AccessibilityState.Sensitive] = this.Sensitive;
520 [EditorBrowsable(EditorBrowsableState.Never)]
521 protected virtual int AccessibilityGetActionCount()
523 return AccessibilityActions.Length;
526 [EditorBrowsable(EditorBrowsableState.Never)]
527 protected virtual string AccessibilityGetActionName(int index)
529 if (index >= 0 && index < AccessibilityActions.Length)
531 return AccessibilityActions[index];
539 [EditorBrowsable(EditorBrowsableState.Never)]
540 protected virtual bool AccessibilityIsScrollable()
545 [EditorBrowsable(EditorBrowsableState.Never)]
546 protected virtual bool AccessibilityScrollToChild(View child)
552 /// This method is called when the control accessibility is activated.<br />
553 /// Derived classes should override this to perform custom accessibility activation.<br />
555 /// <returns>True if this control can perform accessibility activation.</returns>
556 [EditorBrowsable(EditorBrowsableState.Never)]
557 protected virtual bool OnAccessibilityActivated()
563 /// This method is called when reading is skipped.
565 /// <returns>True if information was served.</returns>
566 [EditorBrowsable(EditorBrowsableState.Never)]
567 protected virtual bool OnAccessibilityReadingSkipped()
573 /// This method is called when reading is cancelled.
575 /// <returns>True if information was served.</returns>
576 [EditorBrowsable(EditorBrowsableState.Never)]
577 protected virtual bool OnAccessibilityReadingCancelled()
583 /// This method is called when reading is stopped.
585 /// <returns>True if information was served.</returns>
586 [EditorBrowsable(EditorBrowsableState.Never)]
587 protected virtual bool OnAccessibilityReadingStopped()
593 /// This method is called when reading was paused.
595 /// <returns>True if information was served.</returns>
596 [EditorBrowsable(EditorBrowsableState.Never)]
597 protected virtual bool OnAccessibilityReadingPaused()
603 /// This method is called when reading is resumed.
605 /// <returns>True if information was served.</returns>
606 [EditorBrowsable(EditorBrowsableState.Never)]
607 protected virtual bool OnAccessibilityReadingResumed()