[dali_2.1.18] Merge branch 'devel/master'
[platform/core/uifw/dali-csharp-binder.git] / dali-csharp-binder / src / nui-view-accessible.h
1
2 /*
3  * Copyright (c) 2022 Samsung Electronics Co., Ltd.
4  *
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
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  */
18
19 #ifndef NUI_VIEW_ACCESSIBLE_H
20 #define NUI_VIEW_ACCESSIBLE_H
21
22 // EXTERNAL INCLUDES
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>
29
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
34
35 {
36 public:
37     struct AccessibilityDelegate; // Forward declaration
38
39     NUIViewAccessible() = delete;
40     NUIViewAccessible(const NUIViewAccessible &) = delete;
41     NUIViewAccessible(NUIViewAccessible &&) = delete;
42
43     NUIViewAccessible& operator=(const NUIViewAccessible &) = delete;
44     NUIViewAccessible& operator=(NUIViewAccessible &&) = delete;
45
46     NUIViewAccessible(Dali::Actor actor);
47
48     static void SetAccessibilityDelegate(const AccessibilityDelegate *accessibilityDelegate);
49
50     // Standard interfaces (Accessible, Action, Component)
51
52     std::string GetNameRaw() const override;
53
54     std::string GetDescriptionRaw() const override;
55
56     bool GrabHighlight() override;
57
58     std::string GetActionName(std::size_t index) const override;
59
60     std::size_t GetActionCount() const override;
61
62     bool DoAction(std::size_t index) override;
63
64     bool DoAction(const std::string &name) override;
65
66     Dali::Accessibility::States CalculateStates() override;
67
68     Dali::Property::Index GetNamePropertyIndex() override;
69
70     Dali::Property::Index GetDescriptionPropertyIndex() override;
71
72     virtual bool ShouldReportZeroChildren() const;
73
74     bool IsScrollable() const override;
75
76     bool ScrollToChild(Dali::Actor child) override;
77
78     void DoGetChildren(std::vector<Accessible*>& children) override;
79
80     Dali::Accessibility::AtspiInterfaces DoGetInterfaces() const override;
81
82     // Value interface
83
84     double GetMinimum() const override;
85
86     double GetCurrent() const override;
87
88     double GetMaximum() const override;
89
90     bool SetCurrent(double value) override;
91
92     double GetMinimumIncrement() const override;
93
94     // Text interface
95
96     std::string GetText(std::size_t startOffset, std::size_t endOffset) const override;
97
98     std::size_t GetCharacterCount() const override;
99
100     std::size_t GetCursorOffset() const override;
101
102     bool SetCursorOffset(std::size_t offset) override;
103
104     Dali::Accessibility::Range GetTextAtOffset(std::size_t offset, Dali::Accessibility::TextBoundary boundary) const override;
105
106     Dali::Accessibility::Range GetRangeOfSelection(std::size_t selectionIndex) const override;
107
108     bool RemoveSelection(std::size_t selectionIndex) override;
109
110     bool SetRangeOfSelection(std::size_t selectionIndex, std::size_t startOffset, std::size_t endOffset) override;
111
112     Dali::Rect<> GetRangeExtents(std::size_t startOffset, std::size_t endOffset, Dali::Accessibility::CoordinateType type) override;
113
114     // EditableText interface
115
116     bool CopyText(std::size_t startPosition, std::size_t endPosition) override;
117
118     bool CutText(std::size_t startPosition, std::size_t endPosition) override;
119
120     bool InsertText(std::size_t startPosition, std::string text) override;
121
122     bool SetTextContents(std::string newContents) override;
123
124     bool DeleteText(std::size_t startPosition, std::size_t endPosition) override;
125
126     // Selection interface
127
128     int GetSelectedChildrenCount() const override;
129
130     Dali::Accessibility::Accessible* GetSelectedChild(int selectedChildIndex) override;
131
132     bool SelectChild(int childIndex) override;
133
134     bool DeselectSelectedChild(int selectedChildIndex) override;
135
136     bool IsChildSelected(int childIndex) const override;
137
138     bool SelectAll() override;
139
140     bool ClearSelection() override;
141
142     bool DeselectChild(int childIndex) override;
143
144 private:
145     // Points to memory managed from the C# side
146     static inline const AccessibilityDelegate *mTable = nullptr;
147
148     // Frees memory allocated in C# via a call to CSharp_Dali_Accessibility_DuplicateString
149     static std::string StealString(char *str);
150
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);
154
155     /**
156      * @brief Safely calls a virtual C# method through AccessibilityDelegate.
157      *
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).
163      *
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)
167      *
168      * @param method The method (function pointer from AccessibilityDelegate)
169      * @param args Method arguments
170      *
171      * @return Value returned by the chosen method
172      */
173     template <Dali::Accessibility::AtspiInterface I, typename R, typename... Args>
174     R CallMethod(R (*method)(Dali::RefObject *, Args...), Args... args) const;
175 };
176
177 #endif // NUI_VIEW_ACCESSIBLE_H