using System;
using System.Runtime.InteropServices;
+using Tizen.NUI.Accessibility;
namespace Tizen.NUI.BaseComponents
{
return Registry.GetManagedBaseHandleFromRefObject(refObjectPtr) as View;
}
+ private static T GetInterfaceFromRefObject<T>(IntPtr refObjectPtr)
+ {
+ var view = GetViewFromRefObject(refObjectPtr);
+
+ // NUIViewAccessible::CallMethod<T> checks whether a given interface is implemented
+ // before jumping to managed code, so this condition should always be true.
+ if (view is T atspiInterface)
+ {
+ return atspiInterface;
+ }
+
+ return default(T);
+ }
+
private static IntPtr DuplicateString(string value)
{
return Interop.ControlDevel.DaliAccessibilityDuplicateString(value ?? "");
return Interop.ControlDevel.DaliAccessibilityNewRange(range.StartOffset, range.EndOffset, range.Content);
}
+ private static IntPtr DuplicateAccessibilityRectangle(Rectangle rect)
+ {
+ return Interop.Rectangle.NewRectangle(rect.X, rect.Y, rect.Width, rect.Height);
+ }
+
//
// Accessible interface
//
ad.CalculateStates = AccessibilityCalculateStatesWrapper;
ad.GetDescription = AccessibilityGetDescriptionWrapper;
+ ad.GetInterfaces = AccessibilityGetInterfaces; // Not a wrapper, entirely private implementation
ad.GetName = AccessibilityGetNameWrapper;
}
private static ulong AccessibilityCalculateStatesWrapper(IntPtr self, ulong initialStates)
{
View view = GetViewFromRefObject(self);
+ if (view == null)
+ return 0UL;
+
ulong bitMask = 0UL;
lock (AccessibilityInitialStates)
return DuplicateString(description);
}
+ private static uint AccessibilityGetInterfaces(IntPtr self)
+ {
+ View view = GetViewFromRefObject(self);
+ uint flags = 0U;
+
+ if (view is IAtspiEditableText)
+ {
+ flags |= (1U << (int)AccessibilityInterface.EditableText);
+ }
+
+ if (view is IAtspiSelection)
+ {
+ flags |= (1U << (int)AccessibilityInterface.Selection);
+ }
+
+ if (view is IAtspiText)
+ {
+ flags |= (1U << (int)AccessibilityInterface.Text);
+ }
+
+ if (view is IAtspiValue)
+ {
+ flags |= (1U << (int)AccessibilityInterface.Value);
+ }
+
+ return flags;
+ }
+
private static IntPtr AccessibilityGetNameWrapper(IntPtr self)
{
string name = GetViewFromRefObject(self).AccessibilityGetName();
private static bool AccessibilityCopyTextWrapper(IntPtr self, int startPosition, int endPosition)
{
- return GetViewFromRefObject(self).AccessibilityCopyText(startPosition, endPosition);
+ return GetInterfaceFromRefObject<IAtspiEditableText>(self).AccessibilityCopyText(startPosition, endPosition);
}
private static bool AccessibilityCutTextWrapper(IntPtr self, int startPosition, int endPosition)
{
- return GetViewFromRefObject(self).AccessibilityCutText(startPosition, endPosition);
+ return GetInterfaceFromRefObject<IAtspiEditableText>(self).AccessibilityCutText(startPosition, endPosition);
}
private static bool AccessibilityDeleteTextWrapper(IntPtr self, int startPosition, int endPosition)
{
- return GetViewFromRefObject(self).AccessibilityDeleteText(startPosition, endPosition);
+ return GetInterfaceFromRefObject<IAtspiEditableText>(self).AccessibilityDeleteText(startPosition, endPosition);
}
private static bool AccessibilityInsertTextWrapper(IntPtr self, int startPosition, IntPtr text)
{
- return GetViewFromRefObject(self).AccessibilityInsertText(startPosition, Marshal.PtrToStringAnsi(text));
+ return GetInterfaceFromRefObject<IAtspiEditableText>(self).AccessibilityInsertText(startPosition, Marshal.PtrToStringAnsi(text));
}
private static bool AccessibilitySetTextContentsWrapper(IntPtr self, IntPtr newContents)
{
- return GetViewFromRefObject(self).AccessibilitySetTextContents(Marshal.PtrToStringAnsi(newContents));
+ return GetInterfaceFromRefObject<IAtspiEditableText>(self).AccessibilitySetTextContents(Marshal.PtrToStringAnsi(newContents));
}
//
private static bool AccessibilityClearSelectionWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityClearSelection();
+ return GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilityClearSelection();
}
private static bool AccessibilityDeselectChildWrapper(IntPtr self, int childIndex)
{
- return GetViewFromRefObject(self).AccessibilityDeselectChild(childIndex);
+ return GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilityDeselectChild(childIndex);
}
private static bool AccessibilityDeselectSelectedChildWrapper(IntPtr self, int selectedChildIndex)
{
- return GetViewFromRefObject(self).AccessibilityDeselectSelectedChild(selectedChildIndex);
+ return GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilityDeselectSelectedChild(selectedChildIndex);
}
private static IntPtr AccessibilityGetSelectedChildWrapper(IntPtr self, int selectedChildIndex)
{
- View child = GetViewFromRefObject(self).AccessibilityGetSelectedChild(selectedChildIndex);
+ View child = GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilityGetSelectedChild(selectedChildIndex);
return View.getCPtr(child).Handle;
}
private static int AccessibilityGetSelectedChildrenCountWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityGetSelectedChildrenCount();
+ return GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilityGetSelectedChildrenCount();
}
private static bool AccessibilityIsChildSelectedWrapper(IntPtr self, int childIndex)
{
- return GetViewFromRefObject(self).AccessibilityIsChildSelected(childIndex);
+ return GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilityIsChildSelected(childIndex);
}
private static bool AccessibilitySelectAllWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilitySelectAll();
+ return GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilitySelectAll();
}
private static bool AccessibilitySelectChildWrapper(IntPtr self, int childIndex)
{
- return GetViewFromRefObject(self).AccessibilitySelectChild(childIndex);
+ return GetInterfaceFromRefObject<IAtspiSelection>(self).AccessibilitySelectChild(childIndex);
}
//
ad.GetCharacterCount = AccessibilityGetCharacterCountWrapper;
ad.GetCursorOffset = AccessibilityGetCursorOffsetWrapper;
+ ad.GetRangeExtents = AccessibilityGetRangeExtentsWrapper;
ad.GetSelection = AccessibilityGetSelectionWrapper;
ad.GetText = AccessibilityGetTextWrapper;
ad.GetTextAtOffset = AccessibilityGetTextAtOffsetWrapper;
private static int AccessibilityGetCharacterCountWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityGetCharacterCount();
+ return GetInterfaceFromRefObject<IAtspiText>(self).AccessibilityGetCharacterCount();
}
private static int AccessibilityGetCursorOffsetWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityGetCursorOffset();
+ return GetInterfaceFromRefObject<IAtspiText>(self).AccessibilityGetCursorOffset();
+ }
+
+ private static IntPtr AccessibilityGetRangeExtentsWrapper(IntPtr self, int startOffset, int endOffset, int coordType)
+ {
+ using Rectangle rect = GetInterfaceFromRefObject<IAtspiText>(self).AccessibilityGetRangeExtents(startOffset, endOffset, (AccessibilityCoordinateType)coordType);
+
+ return DuplicateAccessibilityRectangle(rect);
}
private static IntPtr AccessibilityGetSelectionWrapper(IntPtr self, int selectionNumber)
{
- AccessibilityRange range = GetViewFromRefObject(self).AccessibilityGetSelection(selectionNumber);
+ AccessibilityRange range = GetInterfaceFromRefObject<IAtspiText>(self).AccessibilityGetSelection(selectionNumber);
return DuplicateAccessibilityRange(range);
}
private static IntPtr AccessibilityGetTextWrapper(IntPtr self, int startOffset, int endOffset)
{
- string text = GetViewFromRefObject(self).AccessibilityGetText(startOffset, endOffset);
+ string text = GetInterfaceFromRefObject<IAtspiText>(self).AccessibilityGetText(startOffset, endOffset);
return DuplicateString(text);
}
private static IntPtr AccessibilityGetTextAtOffsetWrapper(IntPtr self, int offset, int boundary)
{
- AccessibilityRange range = GetViewFromRefObject(self).AccessibilityGetTextAtOffset(offset, (AccessibilityTextBoundary)boundary);
+ AccessibilityRange range = GetInterfaceFromRefObject<IAtspiText>(self).AccessibilityGetTextAtOffset(offset, (AccessibilityTextBoundary)boundary);
return DuplicateAccessibilityRange(range);
}
private static bool AccessibilityRemoveSelectionWrapper(IntPtr self, int selectionNumber)
{
- return GetViewFromRefObject(self).AccessibilityRemoveSelection(selectionNumber);
+ return GetInterfaceFromRefObject<IAtspiText>(self).AccessibilityRemoveSelection(selectionNumber);
}
private static bool AccessibilitySetCursorOffsetWrapper(IntPtr self, int offset)
{
- return GetViewFromRefObject(self).AccessibilitySetCursorOffset(offset);
+ return GetInterfaceFromRefObject<IAtspiText>(self).AccessibilitySetCursorOffset(offset);
}
private static bool AccessibilitySetSelectionWrapper(IntPtr self, int selectionNumber, int startOffset, int endOffset)
{
- return GetViewFromRefObject(self).AccessibilitySetSelection(selectionNumber, startOffset, endOffset);
+ return GetInterfaceFromRefObject<IAtspiText>(self).AccessibilitySetSelection(selectionNumber, startOffset, endOffset);
}
//
private static double AccessibilityGetCurrentWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityGetCurrent();
+ return GetInterfaceFromRefObject<IAtspiValue>(self).AccessibilityGetCurrent();
}
private static double AccessibilityGetMaximumWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityGetMaximum();
+ return GetInterfaceFromRefObject<IAtspiValue>(self).AccessibilityGetMaximum();
}
private static double AccessibilityGetMinimumWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityGetMinimum();
+ return GetInterfaceFromRefObject<IAtspiValue>(self).AccessibilityGetMinimum();
}
private static double AccessibilityGetMinimumIncrementWrapper(IntPtr self)
{
- return GetViewFromRefObject(self).AccessibilityGetMinimumIncrement();
+ return GetInterfaceFromRefObject<IAtspiValue>(self).AccessibilityGetMinimumIncrement();
}
private static bool AccessibilitySetCurrentWrapper(IntPtr self, double value)
{
- return GetViewFromRefObject(self).AccessibilitySetCurrent(value);
+ return GetInterfaceFromRefObject<IAtspiValue>(self).AccessibilitySetCurrent(value);
}
//
var ad = Interop.ControlDevel.AccessibilityDelegate.Instance;
ad.ScrollToChild = AccessibilityScrollToChildWrapper;
- ad.ShouldReportZeroChildren = AccessibilityShouldReportZeroChildrenWrapper;
}
private static bool AccessibilityScrollToChildWrapper(IntPtr self, IntPtr child)
return view.AccessibilityScrollToChild(view.GetInstanceSafely<View>(child));
}
-
- private static bool AccessibilityShouldReportZeroChildrenWrapper(IntPtr self)
- {
- return GetViewFromRefObject(self).AccessibilityShouldReportZeroChildren();
- }
}
}