[ATSPI] Add more descriptions to Bridge objects
[platform/core/uifw/dali-adaptor.git] / dali / internal / accessibility / bridge / bridge-collection.h
1 #ifndef DALI_INTERNAL_ACCESSIBILITY_BRIDGE_COLLECTION_H
2 #define DALI_INTERNAL_ACCESSIBILITY_BRIDGE_COLLECTION_H
3
4 /*
5  * Copyright (c) 2021 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <array>
23 #include <tuple>
24 #include <unordered_map>
25 #include <vector>
26
27 // INTERNAL INCLUDES
28 #include <dali/internal/accessibility/bridge/bridge-base.h>
29
30 /**
31  * @brief The BridgeCollection class is to correspond with Dali::Accessibility::Collection.
32  *
33  * Collection interface is designed to allow AT-Clients to query the tree of accessibility objects
34  * exposed by an application with a single dbus call.
35  * The query takes as an input a match rule and returns zero or more matching accessibility objects as a result.
36  *
37  * A match rule can be a combination of at least one of four criteria :
38  *  Interface, Attribute, Role, State
39  *
40  * If more than one criteria is specified, the matching rule combines them using "AND" semantics.
41  */
42 class BridgeCollection : public virtual BridgeBase
43 {
44 private:
45   struct Comparer;
46
47   /**
48    * @brief Visits all nodes of Accessible object and pushes the object to 'result' container.
49    *
50    * To query the entire tree, the BridgeCollection::Comparer is used inside this method,
51    * which traverse the tree using GetChildAtIndex().
52    * @param[in] obj The Accessible object to search
53    * @param[out] result The vector container for result
54    * @param[in] comparer BridgeCollection::Comparer which do the comparison against a single accessible object
55    * @param[in] maxCount The maximum count of containing Accessible object
56    */
57   static void VisitNodes(Dali::Accessibility::Accessible* obj, std::vector<Dali::Accessibility::Accessible*>& result, Comparer& comparer, size_t maxCount);
58
59 protected:
60   BridgeCollection() = default;
61
62   /**
63    * @brief Registers Collection functions to dbus interfaces.
64    */
65   void RegisterInterfaces();
66
67   /**
68    * @brief Returns the Collection object of the currently executed DBus method call.
69    *
70    * @return The Collection object
71    */
72   Dali::Accessibility::Collection* FindSelf() const;
73
74 public:
75   /**
76    * MatchRule type is a tuple that only carries data of de-serialized parameter from BridgeCollection::GetMatches dbus method.
77    */
78   using MatchRule = std::tuple<
79     std::array<int32_t, 2>,
80     int32_t,
81     std::unordered_map<std::string, std::string>,
82     int32_t,
83     std::array<int32_t, 4>,
84     int32_t,
85     std::vector<std::string>,
86     int32_t,
87     bool>;
88
89   /**
90    * @brief Enumeration for Collection Index.
91    */
92   enum class Index
93   {
94     STATES,
95     STATES_MATCH_TYPE,
96     ATTRIBUTES,
97     ATTRIBUTES_MATCH_TYPE,
98     ROLES,
99     ROLES_MATCH_TYPE,
100     INTERFACES,
101     INTERFACES_MATCH_TYPE,
102   };
103
104   /**
105    * @brief Gets the matching Accessible objects with MatchRule.
106    *
107    * @param[in] rule BridgeCollection::MatchRule
108    * @param[in] sortBy SortOrder::CANONICAL or SortOrder::REVERSE_CANONICAL
109    * @param[in] count The maximum number of objects
110    * @param[in] traverse True if it is traverse, otherwise false.
111    * @return The matching Accessible objects
112    */
113   DBus::ValueOrError<std::vector<Dali::Accessibility::Accessible*> > GetMatches(MatchRule rule, uint32_t sortBy, int32_t count, bool traverse);
114 };
115
116 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_COLLECTION_H