[ATSPI] Introduce GetMatchesInMatches API
[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/devel-api/atspi-interfaces/collection.h>
29 #include <dali/internal/accessibility/bridge/bridge-base.h>
30
31 /**
32  * @brief The BridgeCollection class is to correspond with Dali::Accessibility::Collection.
33  *
34  * Collection interface is designed to allow AT-Clients to query the tree of accessibility objects
35  * exposed by an application with a single dbus call.
36  * The query takes as an input a match rule and returns zero or more matching accessibility objects as a result.
37  *
38  * A match rule can be a combination of at least one of four criteria :
39  *  Interface, Attribute, Role, State
40  *
41  * If more than one criteria is specified, the matching rule combines them using "AND" semantics.
42  */
43 class BridgeCollection : public virtual BridgeBase
44 {
45 private:
46   struct Comparer;
47
48   /**
49    * @brief Visits all nodes of Accessible object and pushes the object to 'result' container.
50    *
51    * To query the entire tree, the BridgeCollection::Comparer is used inside this method,
52    * which traverse the tree using GetChildAtIndex().
53    * @param[in] obj The Accessible object to search
54    * @param[out] result The vector container for result
55    * @param[in] comparer BridgeCollection::Comparer which do the comparison against a single accessible object
56    * @param[in] maxCount The maximum count of containing Accessible object
57    */
58   static void VisitNodes(Dali::Accessibility::Accessible* obj, std::vector<Dali::Accessibility::Accessible*>& result, Comparer& comparer, size_t maxCount);
59
60 protected:
61   BridgeCollection() = default;
62
63   /**
64    * @brief Registers Collection functions to dbus interfaces.
65    */
66   void RegisterInterfaces();
67
68   /**
69    * @brief Returns the Collection object of the currently executed DBus method call.
70    *
71    * @return The Collection object
72    */
73   Dali::Accessibility::Collection* FindSelf() const;
74
75 public:
76   /**
77    * MatchRule type is a tuple that only carries data of de-serialized parameter from BridgeCollection::GetMatches dbus method.
78    */
79   using MatchRule = std::tuple<
80     std::array<int32_t, 2>,
81     int32_t,
82     std::unordered_map<std::string, std::string>,
83     int32_t,
84     std::array<int32_t, 4>,
85     int32_t,
86     std::vector<std::string>,
87     int32_t,
88     bool>;
89
90   /**
91    * @brief Enumeration for Collection Index.
92    */
93   enum class Index
94   {
95     STATES,
96     STATES_MATCH_TYPE,
97     ATTRIBUTES,
98     ATTRIBUTES_MATCH_TYPE,
99     ROLES,
100     ROLES_MATCH_TYPE,
101     INTERFACES,
102     INTERFACES_MATCH_TYPE,
103   };
104
105   /**
106    * @brief Gets the matching Accessible objects with MatchRule.
107    *
108    * @param[in] rule BridgeCollection::MatchRule
109    * @param[in] sortBy SortOrder::CANONICAL or SortOrder::REVERSE_CANONICAL
110    * @param[in] count The maximum number of objects
111    * @param[in] traverse True if it is traverse, otherwise false.
112    * @return The matching Accessible objects
113    */
114   DBus::ValueOrError<std::vector<Dali::Accessibility::Accessible*> > GetMatches(MatchRule rule, uint32_t sortBy, int32_t count, bool traverse);
115
116   /**
117    * @brief Gets the matching Accessible objects with two MatchRules.
118    *
119    * @param[in] firstRule The initial BridgeCollection::MatchRule.
120    * @param[in] secondRule An secondary BridgeCollection::MatchRule.
121    * @param[in] sortBy SortOrder::CANONICAL or SortOrder::REVERSE_CANONICAL
122    * @param[in] firstCount The maximum number of objects to return for the initial match.
123    * @param[in] secondCount The maximum number of objects to return for the secondary match.
124    * @param[in] traverse True if it is traverse, otherwise false.
125    * @return The matching Accessible objects
126    */
127   DBus::ValueOrError<std::vector<Dali::Accessibility::Accessible*> > GetMatchesInMatches(MatchRule firstRule, MatchRule secondRule, uint32_t sortBy, int32_t firstCount, int32_t secondCount,  bool traverse);
128 };
129
130 #endif // DALI_INTERNAL_ACCESSIBILITY_BRIDGE_COLLECTION_H