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;
23 namespace Tizen.NUI.BaseComponents
26 /// Address represents an unique object address on accessibility bus.
28 [EditorBrowsable(EditorBrowsableState.Never)]
32 /// Creates an initialized Address.
34 /// <param name="bus">Accessibility bus</param>
35 /// <param name="path">Accessibility path</param>
36 [EditorBrowsable(EditorBrowsableState.Never)]
37 public Address(string bus, string path)
44 /// Gets or sets accessibility bus.
46 [EditorBrowsable(EditorBrowsableState.Never)]
47 public string Bus { get; set; }
50 /// Gets or sets accessibility path.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public string Path { get; set; }
57 /// AddressCollection.
59 [EditorBrowsable(EditorBrowsableState.Never)]
60 public class AddressCollection : SafeHandle
63 /// Creates an initialized AddressCollection.
65 /// <param name="collection">Initialized AddressCollection</param>
66 [EditorBrowsable(EditorBrowsableState.Never)]
67 public AddressCollection(IntPtr collection) : base(collection, true)
72 /// Checks whether this handle is invalid or not.
74 [EditorBrowsable(EditorBrowsableState.Never)]
75 public override bool IsInvalid
79 return this.handle == IntPtr.Zero;
84 /// Gets the size of accessibility relation.
86 /// <param name="relation">Accessibility relation</param>
87 /// <returns>The size of relation, which means the number of elements</returns>
88 [EditorBrowsable(EditorBrowsableState.Never)]
89 public uint GetRelationSize(AccessibilityRelationType relation)
91 uint result = Interop.ControlDevel.DaliToolkitDevelControlAccessibilityRelationsRelationSize(this, Convert.ToInt32(relation));
92 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
97 /// Gets Address object using contained bus and path.
99 /// <param name="relation">Accessibility relation</param>
100 /// <param name="position">Position</param>
101 /// <returns>Accessibility Adress</returns>
102 [EditorBrowsable(EditorBrowsableState.Never)]
103 public Address GetAddressAt(AccessibilityRelationType relation, int position)
105 var bus = Interop.ControlDevel.DaliToolkitDevelControlAccessibilityRelationsAt(this, Convert.ToInt32(relation), position, 0);
106 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108 var path = Interop.ControlDevel.DaliToolkitDevelControlAccessibilityRelationsAt(this, Convert.ToInt32(relation), position, 1);
109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
111 return new Address(bus, path);
115 /// Releases handle itself.
117 /// <returns>true when released successfully.</returns>
118 [EditorBrowsable(EditorBrowsableState.Never)]
119 protected override bool ReleaseHandle()
121 Interop.ControlDevel.DaliToolkitDevelControlDeleteAccessibilityRelations(handle);
122 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123 this.SetHandle(IntPtr.Zero);
129 /// AccessibilityRange is used to store data related with Text.
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public class AccessibilityRange
135 /// Start position in stored text.
137 public int StartOffset { get; set; } = 0;
140 /// End position in stored text.
142 public int EndOffset { get; set; } = 0;
145 /// Text content in stored text.
147 public string Content { get; set; } = "";
151 /// View is the base class for all views.
153 /// <since_tizen> 3 </since_tizen>
154 public partial class View
156 ///////////////////////////////////////////////////////////////////
157 // ****************** Accessibility Attributes ****************** //
158 ///////////////////////////////////////////////////////////////////
161 /// Adds or modifies the value matched with given key.
164 /// Modification takes place if key was previously set.
166 /// <param name="key">The key to insert</param>
167 /// <param name="value">The value to insert</param>
168 [EditorBrowsable(EditorBrowsableState.Never)]
169 public void AppendAccessibilityAttribute(string key, string value)
171 Interop.ControlDevel.DaliToolkitDevelControlAppendAccessibilityAttribute(SwigCPtr, key, value);
172 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176 /// Erases a key with its value from accessibility attributes.
178 /// <param name="key">The key to remove</param>
179 [EditorBrowsable(EditorBrowsableState.Never)]
180 public void RemoveAccessibilityAttribute(string key)
182 Interop.ControlDevel.DaliToolkitDevelControlRemoveAccessibilityAttribute(SwigCPtr, key);
183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187 /// Clears accessibility attributes.
189 [EditorBrowsable(EditorBrowsableState.Never)]
190 public void ClearAccessibilityAttributes()
192 Interop.ControlDevel.DaliToolkitDevelControlClearAccessibilityAttributes(SwigCPtr);
193 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196 ///////////////////////////////////////////////////////////////////
197 // ************************** Highlight ************************ //
198 ///////////////////////////////////////////////////////////////////
201 /// Clears accessibility highlight.
203 /// <returns>True if cleared, otherwise false when it is not possible</returns>
204 [EditorBrowsable(EditorBrowsableState.Never)]
205 public bool ClearAccessibilityHighlight()
207 bool result = Interop.ControlDevel.DaliToolkitDevelControlClearAccessibilityHighlight(SwigCPtr);
208 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 /// Grabs accessibility highlight.
215 /// <returns>True if cleared, otherwise false when it is not possible</returns>
216 [EditorBrowsable(EditorBrowsableState.Never)]
217 public bool GrabAccessibilityHighlight()
219 bool result = Interop.ControlDevel.DaliToolkitDevelControlGrabAccessibilityHighlight(SwigCPtr);
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 /// Flag to check whether this view is highlighted or not.
227 [EditorBrowsable(EditorBrowsableState.Never)]
228 protected bool IsHighlighted
232 return (this == Accessibility.Accessibility.Instance.GetCurrentlyHighlightedView());
236 ///////////////////////////////////////////////////////////////////
237 // ****************** Accessibility Relations ******************* //
238 ///////////////////////////////////////////////////////////////////
241 /// Creates relation between objects.
243 /// <param name="second">Object which will be in relation.</param>
244 /// <param name="relation">Relation type.</param>
245 /// <exception cref="ArgumentNullException">You must pass valid object. NULL could not be in relation.</exception>
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public void AppendAccessibilityRelation(View second, AccessibilityRelationType relation)
251 throw new ArgumentNullException(nameof(second));
254 Interop.ControlDevel.DaliToolkitDevelControlAppendAccessibilityRelation(SwigCPtr, second.SwigCPtr, (int)relation);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 /// Removes accessibility relation.
261 /// <param name="second">Object which will be removed in relation</param>
262 /// <param name="relation">Relation type</param>
263 [EditorBrowsable(EditorBrowsableState.Never)]
264 public void RemoveAccessibilityRelation(View second, AccessibilityRelationType relation)
268 throw new ArgumentNullException(nameof(second));
271 Interop.ControlDevel.DaliToolkitDevelControlRemoveAccessibilityRelation(SwigCPtr, second.SwigCPtr, (int)relation);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 /// Removes all previously appended relations.
278 [EditorBrowsable(EditorBrowsableState.Never)]
279 public void ClearAccessibilityRelations()
281 Interop.ControlDevel.DaliToolkitDevelControlClearAccessibilityRelations(SwigCPtr);
282 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Gets accessibility collection connected with the current object.
288 /// <returns>AddressCollection</returns>
289 [EditorBrowsable(EditorBrowsableState.Never)]
290 public AddressCollection GetAccessibilityRelations()
292 var result = new AddressCollection(Interop.ControlDevel.DaliToolkitDevelControlNewGetAccessibilityRelations(SwigCPtr));
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 ///////////////////////////////////////////////////////////////////
298 // ********************* ReadingInfoType *********************** //
299 ///////////////////////////////////////////////////////////////////
302 /// Sets accessibility reading information.
304 /// <param name="type">Reading information type</param>
305 [EditorBrowsable(EditorBrowsableState.Never)]
306 public void SetAccessibilityReadingInfoTypes(AccessibilityReadingInfoTypes type)
308 Interop.ControlDevel.DaliToolkitDevelControlSetAccessibilityReadingInfoTypes(SwigCPtr, (int)type);
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313 /// Gets accessibility reading information.
315 /// <returns>Reading information type</returns>
316 [EditorBrowsable(EditorBrowsableState.Never)]
317 public AccessibilityReadingInfoTypes GetAccessibilityReadingInfoTypes()
319 AccessibilityReadingInfoTypes result = (AccessibilityReadingInfoTypes)Interop.ControlDevel.DaliToolkitDevelControlGetAccessibilityReadingInfoTypes(SwigCPtr);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 ///////////////////////////////////////////////////////////////////
325 // ******************** Accessibility States ******************* //
326 ///////////////////////////////////////////////////////////////////
329 /// Notifies sending notifications about the current states to accessibility clients.
332 /// In essence, this is equivalent to calling EmitAccessibilityStateChangedEvent in a loop for all specified states.
333 /// If recursive mode is specified, all children of the Accessibility object will also re-emit the states.
335 /// <param name="states">Accessibility States</param>
336 /// <param name="notifyMode">Controls the notification strategy</param>
337 [EditorBrowsable(EditorBrowsableState.Never)]
338 public void NotifyAccessibilityStatesChange(AccessibilityStates states, AccessibilityStatesNotifyMode notifyMode)
342 throw new ArgumentNullException(nameof(states));
345 Interop.ControlDevel.DaliToolkitDevelControlNotifyAccessibilityStateChange(SwigCPtr, states.BitMask, (int)notifyMode);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350 /// Gets Accessibility States.
352 /// <returns>Accessibility States</returns>
353 [EditorBrowsable(EditorBrowsableState.Never)]
354 public AccessibilityStates GetAccessibilityStates()
356 var result = new AccessibilityStates {BitMask = Interop.ControlDevel.DaliToolkitDevelControlGetAccessibilityStates(SwigCPtr)};
357 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 ///////////////////////////////////////////////////////////////////
362 // ************************ Accessible ************************* //
363 ///////////////////////////////////////////////////////////////////
366 /// Emits accessibility property changed event.
368 /// <param name="changeEvent">Property changed event</param>
369 [EditorBrowsable(EditorBrowsableState.Never)]
370 public void EmitAccessibilityEvent(AccessibilityPropertyChangeEvent changeEvent)
372 Interop.ControlDevel.DaliAccessibilityEmitAccessibilityEvent(SwigCPtr, Convert.ToInt32(changeEvent));
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 /// Emits accessibility states changed event.
379 /// <param name="state">Accessibility state</param>
380 /// <param name="equal">True if the state is set or enabled, otherwise false</param>
381 [EditorBrowsable(EditorBrowsableState.Never)]
382 public void EmitAccessibilityStateChangedEvent(AccessibilityState state, bool equal)
384 Interop.ControlDevel.DaliAccessibilityEmitAccessibilityStateChangedEvent(SwigCPtr, (int)state, Convert.ToInt32(equal));
385 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
389 /// Emits accessibility text inserted event.
391 /// <param name="cursorPosition">Text cursor position</param>
392 /// <param name="length">Text length</param>
393 /// <param name="content">Inserted text content</param>
394 [EditorBrowsable(EditorBrowsableState.Never)]
395 public void EmitTextInsertedEvent(int cursorPosition, int length, string content)
397 Interop.ControlDevel.DaliAccessibilityEmitTextInsertedEvent(SwigCPtr, cursorPosition, length, content);
398 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
402 /// Emits accessibility text deleted event.
404 /// <param name="cursorPosition">Text cursor position</param>
405 /// <param name="length">Text length</param>
406 /// <param name="content">Inserted text content</param>
407 [EditorBrowsable(EditorBrowsableState.Never)]
408 public void EmitTextDeletedEvent(int cursorPosition, int length, string content)
410 Interop.ControlDevel.DaliAccessibilityEmitTextDeletedEvent(SwigCPtr, cursorPosition, length, content);
411 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
415 /// Emits accessibility text cursor moved event.
417 /// <param name="cursorPosition">The new cursor position</param>
418 [EditorBrowsable(EditorBrowsableState.Never)]
419 public void EmitTextCursorMovedEvent(int cursorPosition)
421 Interop.ControlDevel.DaliAccessibilityEmitTextCursorMovedEvent(SwigCPtr, cursorPosition);
422 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
425 ///////////////////////////////////////////////////////////////////
426 // ************************** Bridge *************************** //
427 ///////////////////////////////////////////////////////////////////
430 /// Registers component as a source of an accessibility "default label".
431 /// The "Default label" is a text that could be read by screen-reader immediately
432 /// after the navigation context has changed (window activates, popup shows up, tab changes)
433 /// and before first UI element is highlighted.
435 [EditorBrowsable(EditorBrowsableState.Never)]
436 public void RegisterDefaultLabel()
438 Interop.ControlDevel.DaliAccessibilityBridgeRegisterDefaultLabel(SwigCPtr);
439 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
443 /// Unregisters component that has been registered previously as a source of an accessibility "default label".
444 /// The "Default label" is a text that could be read by screen-reader immediately
445 /// after the navigation context has changed (window activates, popup shows up, tab changes)
446 /// and before first UI element is highlighted.
448 [EditorBrowsable(EditorBrowsableState.Never)]
449 public void UnregisterDefaultLabel()
451 Interop.ControlDevel.DaliAccessibilityBridgeUnregisterDefaultLabel(SwigCPtr);
452 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 /// Sets the specific constructor for creating accessibility structure with its role and interface.
459 /// The method should be called inside OnInitialize method of all classes inheriting from View.
461 /// <param name="role">Accessibility role</param>
462 /// <param name="accessibilityInterface">Accessibility interface</param>
463 [EditorBrowsable(EditorBrowsableState.Never)]
464 public void SetAccessibilityConstructor(Role role, AccessibilityInterface accessibilityInterface = AccessibilityInterface.None)
466 // We have to store the interface flags until we remove SetAccessibilityConstructor and switch to native C# interfaces
467 AtspiInterfaceFlags = (1U << (int)accessibilityInterface);
468 Interop.ControlDevel.DaliToolkitDevelControlSetAccessibilityConstructor(SwigCPtr, (int)role);
469 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
472 [EditorBrowsable(EditorBrowsableState.Never)]
473 protected override void Dispose(bool disposing)
480 if (disposing == false)
482 if (IsNativeHandleInvalid() || SwigCMemOwn == false)
484 // at this case, implicit nor explicit dispose is not required. No native object is made.
495 base.Dispose(disposing);
498 [EditorBrowsable(EditorBrowsableState.Never)]
499 protected static readonly string AccessibilityActivateAction = "activate";
500 [EditorBrowsable(EditorBrowsableState.Never)]
501 protected static readonly string AccessibilityReadingSkippedAction = "ReadingSkipped";
502 [EditorBrowsable(EditorBrowsableState.Never)]
503 protected static readonly string AccessibilityReadingCancelledAction = "ReadingCancelled";
504 [EditorBrowsable(EditorBrowsableState.Never)]
505 protected static readonly string AccessibilityReadingStoppedAction = "ReadingStopped";
506 [EditorBrowsable(EditorBrowsableState.Never)]
507 protected static readonly string AccessibilityReadingPausedAction = "ReadingPaused";
508 [EditorBrowsable(EditorBrowsableState.Never)]
509 protected static readonly string AccessibilityReadingResumedAction = "ReadingResumed";
511 [EditorBrowsable(EditorBrowsableState.Never)]
512 private static readonly string[] AccessibilityActions = {
513 AccessibilityActivateAction,
514 AccessibilityReadingSkippedAction,
515 AccessibilityReadingCancelledAction,
516 AccessibilityReadingStoppedAction,
517 AccessibilityReadingPausedAction,
518 AccessibilityReadingResumedAction,
521 [EditorBrowsable(EditorBrowsableState.Never)]
522 protected virtual string AccessibilityGetName()
527 [EditorBrowsable(EditorBrowsableState.Never)]
528 protected virtual string AccessibilityGetDescription()
533 [EditorBrowsable(EditorBrowsableState.Never)]
534 protected virtual bool AccessibilityDoAction(string name)
539 [EditorBrowsable(EditorBrowsableState.Never)]
540 protected virtual AccessibilityStates AccessibilityCalculateStates()
542 var states = AccessibilityInitialStates;
544 states[AccessibilityState.Focused] = this.State == States.Focused;
545 states[AccessibilityState.Enabled] = this.State != States.Disabled;
546 states[AccessibilityState.Sensitive] = this.Sensitive;
551 [EditorBrowsable(EditorBrowsableState.Never)]
552 protected virtual int AccessibilityGetActionCount()
554 return AccessibilityActions.Length;
557 [EditorBrowsable(EditorBrowsableState.Never)]
558 protected virtual string AccessibilityGetActionName(int index)
560 if (index >= 0 && index < AccessibilityActions.Length)
562 return AccessibilityActions[index];
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 protected virtual bool AccessibilityShouldReportZeroChildren()
576 [EditorBrowsable(EditorBrowsableState.Never)]
577 protected virtual double AccessibilityGetMinimum()
582 [EditorBrowsable(EditorBrowsableState.Never)]
583 protected virtual double AccessibilityGetCurrent()
588 [EditorBrowsable(EditorBrowsableState.Never)]
589 protected virtual double AccessibilityGetMaximum()
594 [EditorBrowsable(EditorBrowsableState.Never)]
595 protected virtual bool AccessibilitySetCurrent(double value)
600 [EditorBrowsable(EditorBrowsableState.Never)]
601 protected virtual double AccessibilityGetMinimumIncrement()
606 [EditorBrowsable(EditorBrowsableState.Never)]
607 protected virtual bool AccessibilityIsScrollable()
612 [EditorBrowsable(EditorBrowsableState.Never)]
613 protected virtual string AccessibilityGetText(int startOffset, int endOffset)
618 [EditorBrowsable(EditorBrowsableState.Never)]
619 protected virtual int AccessibilityGetCharacterCount()
624 [EditorBrowsable(EditorBrowsableState.Never)]
625 protected virtual int AccessibilityGetCursorOffset()
630 [EditorBrowsable(EditorBrowsableState.Never)]
631 protected virtual bool AccessibilitySetCursorOffset(int offset)
636 [EditorBrowsable(EditorBrowsableState.Never)]
637 protected virtual AccessibilityRange AccessibilityGetTextAtOffset(int offset, AccessibilityTextBoundary boundary)
639 return new AccessibilityRange();
642 [EditorBrowsable(EditorBrowsableState.Never)]
643 protected virtual AccessibilityRange AccessibilityGetSelection(int selectionNumber)
645 return new AccessibilityRange();
648 [EditorBrowsable(EditorBrowsableState.Never)]
649 protected virtual bool AccessibilityRemoveSelection(int selectionNumber)
654 [EditorBrowsable(EditorBrowsableState.Never)]
655 protected virtual bool AccessibilitySetSelection(int selectionNumber, int startOffset, int endOffset)
660 [EditorBrowsable(EditorBrowsableState.Never)]
661 protected virtual bool AccessibilityCopyText(int startPosition, int endPosition)
666 [EditorBrowsable(EditorBrowsableState.Never)]
667 protected virtual bool AccessibilityCutText(int startPosition, int endPosition)
672 [EditorBrowsable(EditorBrowsableState.Never)]
673 protected virtual bool AccessibilityInsertText(int startPosition, string text)
678 [EditorBrowsable(EditorBrowsableState.Never)]
679 protected virtual bool AccessibilitySetTextContents(string newContents)
684 [EditorBrowsable(EditorBrowsableState.Never)]
685 protected virtual bool AccessibilityDeleteText(int startPosition, int endPosition)
690 [EditorBrowsable(EditorBrowsableState.Never)]
691 protected virtual bool AccessibilityScrollToChild(View child)
696 [EditorBrowsable(EditorBrowsableState.Never)]
697 protected virtual int AccessibilityGetSelectedChildrenCount()
702 [EditorBrowsable(EditorBrowsableState.Never)]
703 protected virtual View AccessibilityGetSelectedChild(int selectedChildIndex)
708 [EditorBrowsable(EditorBrowsableState.Never)]
709 protected virtual bool AccessibilitySelectChild(int childIndex)
714 [EditorBrowsable(EditorBrowsableState.Never)]
715 protected virtual bool AccessibilityDeselectSelectedChild(int selectedChildIndex)
720 [EditorBrowsable(EditorBrowsableState.Never)]
721 protected virtual bool AccessibilityIsChildSelected(int childIndex)
726 [EditorBrowsable(EditorBrowsableState.Never)]
727 protected virtual bool AccessibilitySelectAll()
732 [EditorBrowsable(EditorBrowsableState.Never)]
733 protected virtual bool AccessibilityClearSelection()
738 [EditorBrowsable(EditorBrowsableState.Never)]
739 protected virtual bool AccessibilityDeselectChild(int childIndex)