3 * Copyright (c) 2022 Samsung Electronics Co., Ltd.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #ifndef NUI_VIEW_ACCESSIBLE_H
20 #define NUI_VIEW_ACCESSIBLE_H
23 #include <dali/devel-api/adaptor-framework/accessibility.h>
24 #include <dali/devel-api/atspi-interfaces/editable-text.h>
25 #include <dali/devel-api/atspi-interfaces/text.h>
26 #include <dali/devel-api/atspi-interfaces/selection.h>
27 #include <dali/devel-api/atspi-interfaces/value.h>
28 #include <dali-toolkit/devel-api/controls/control-accessible.h>
30 class NUIViewAccessible : public Dali::Toolkit::DevelControl::ControlAccessible,
31 public virtual Dali::Accessibility::EditableText, // includes Text
32 public virtual Dali::Accessibility::Selection,
33 public virtual Dali::Accessibility::Value
37 struct AccessibilityDelegate; // Forward declaration
39 NUIViewAccessible() = delete;
40 NUIViewAccessible(const NUIViewAccessible &) = delete;
41 NUIViewAccessible(NUIViewAccessible &&) = delete;
43 NUIViewAccessible& operator=(const NUIViewAccessible &) = delete;
44 NUIViewAccessible& operator=(NUIViewAccessible &&) = delete;
46 NUIViewAccessible(Dali::Actor actor);
48 static void SetAccessibilityDelegate(const AccessibilityDelegate *accessibilityDelegate);
50 // Standard interfaces (Accessible, Action, Component)
52 std::string GetNameRaw() const override;
54 std::string GetDescriptionRaw() const override;
56 bool GrabHighlight() override;
58 std::string GetActionName(std::size_t index) const override;
60 std::size_t GetActionCount() const override;
62 bool DoAction(std::size_t index) override;
64 bool DoAction(const std::string &name) override;
66 Dali::Accessibility::States CalculateStates() override;
68 Dali::Property::Index GetNamePropertyIndex() override;
70 Dali::Property::Index GetDescriptionPropertyIndex() override;
72 virtual bool ShouldReportZeroChildren() const;
74 bool IsScrollable() const override;
76 bool ScrollToChild(Dali::Actor child) override;
78 void DoGetChildren(std::vector<Accessible*>& children) override;
80 Dali::Accessibility::AtspiInterfaces DoGetInterfaces() const override;
84 double GetMinimum() const override;
86 double GetCurrent() const override;
88 double GetMaximum() const override;
90 bool SetCurrent(double value) override;
92 double GetMinimumIncrement() const override;
96 std::string GetText(std::size_t startOffset, std::size_t endOffset) const override;
98 std::size_t GetCharacterCount() const override;
100 std::size_t GetCursorOffset() const override;
102 bool SetCursorOffset(std::size_t offset) override;
104 Dali::Accessibility::Range GetTextAtOffset(std::size_t offset, Dali::Accessibility::TextBoundary boundary) const override;
106 Dali::Accessibility::Range GetRangeOfSelection(std::size_t selectionIndex) const override;
108 bool RemoveSelection(std::size_t selectionIndex) override;
110 bool SetRangeOfSelection(std::size_t selectionIndex, std::size_t startOffset, std::size_t endOffset) override;
112 Dali::Rect<> GetRangeExtents(std::size_t startOffset, std::size_t endOffset, Dali::Accessibility::CoordinateType type) override;
114 // EditableText interface
116 bool CopyText(std::size_t startPosition, std::size_t endPosition) override;
118 bool CutText(std::size_t startPosition, std::size_t endPosition) override;
120 bool InsertText(std::size_t startPosition, std::string text) override;
122 bool SetTextContents(std::string newContents) override;
124 bool DeleteText(std::size_t startPosition, std::size_t endPosition) override;
126 // Selection interface
128 int GetSelectedChildrenCount() const override;
130 Dali::Accessibility::Accessible* GetSelectedChild(int selectedChildIndex) override;
132 bool SelectChild(int childIndex) override;
134 bool DeselectSelectedChild(int selectedChildIndex) override;
136 bool IsChildSelected(int childIndex) const override;
138 bool SelectAll() override;
140 bool ClearSelection() override;
142 bool DeselectChild(int childIndex) override;
145 // Points to memory managed from the C# side
146 static inline const AccessibilityDelegate *mTable = nullptr;
148 // Frees memory allocated in C# via a call to CSharp_Dali_Accessibility_DuplicateString
149 static std::string StealString(char *str);
151 // Frees memory allocated in C# via a call to an interop that calls 'operator new'
152 template <typename T>
153 static T StealObject(T *obj);
156 * @brief Safely calls a virtual C# method through AccessibilityDelegate.
158 * This verifies that the specified function pointer is not null and that
159 * the specified interface is implemented by the target object. This is due
160 * to the fact that dynamic_cast can see more interfaces than this object
161 * is meant to represent (dynamic_cast cannot be used to examine C# objects,
162 * so we have to rely on a set of AtspiInterfaces returned by GetInterfaces).
164 * @tparam I The interface that the method belongs to
165 * @tparam R The return type of the method (deduced automatically)
166 * @tparam Args The parameter types of the method (deduced automatically)
168 * @param method The method (function pointer from AccessibilityDelegate)
169 * @param args Method arguments
171 * @return Value returned by the chosen method
173 template <Dali::Accessibility::AtspiInterface I, typename R, typename... Args>
174 R CallMethod(R (*method)(Dali::RefObject *, Args...), Args... args) const;
177 #endif // NUI_VIEW_ACCESSIBLE_H