1 #include "AtspiAccessibleNode.h"
7 //std::map<AtspiAccessible *, AccessibleNode *> AccessibleNode::mNodeMap{};
9 AtspiAccessibleNode::AtspiAccessibleNode(AtspiAccessible *node)
12 GArray *ifaces = atspi_accessible_get_interfaces(mNode);
14 for (unsigned int i = 0; i < ifaces->len; i++) {
15 char *iface = g_array_index(ifaces, char *, i);
16 if (!strcmp(iface, "Action"))
18 static_cast<int>(AccessibleNodeInterface::ACTION);
19 else if (!strcmp(iface, "Collection"))
21 static_cast<int>(AccessibleNodeInterface::COLLECTION);
22 else if (!strcmp(iface, "Component"))
24 static_cast<int>(AccessibleNodeInterface::COMPONENT);
25 else if (!strcmp(iface, "Document"))
27 static_cast<int>(AccessibleNodeInterface::DOCUMENT);
28 else if (!strcmp(iface, "EditableText"))
30 static_cast<int>(AccessibleNodeInterface::EDITABLETEXT);
31 else if (!strcmp(iface, "Hypertext"))
33 static_cast<int>(AccessibleNodeInterface::HYPERTEXT);
34 else if (!strcmp(iface, "Image"))
36 static_cast<int>(AccessibleNodeInterface::IMAGE);
37 else if (!strcmp(iface, "Selection"))
39 static_cast<int>(AccessibleNodeInterface::SELECTION);
40 else if (!strcmp(iface, "Text"))
42 static_cast<int>(AccessibleNodeInterface::TEXT);
43 else if (!strcmp(iface, "Value"))
45 static_cast<int>(AccessibleNodeInterface::VALUE);
46 else if (!strcmp(iface, "Accessible"))
48 static_cast<int>(AccessibleNodeInterface::ACCESSIBLE);
49 else if (!strcmp(iface, "Table"))
51 static_cast<int>(AccessibleNodeInterface::TABLE);
52 else if (!strcmp(iface, "TableCell"))
54 static_cast<int>(AccessibleNodeInterface::TABLECELL);
56 LOG_F(WARNING, "Not Supported interface found %s", iface);
60 g_array_free(ifaces, FALSE);
65 AtspiAccessibleNode::~AtspiAccessibleNode()
67 if(mNode) g_object_unref(mNode);
70 int AtspiAccessibleNode::getChildCount() const
72 int count = atspi_accessible_get_child_count(mNode, NULL);
73 if (count <= 0) return 0;
77 std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getChildAt(int index) const
79 LOG_SCOPE_F(INFO, "getChild @ %d from node(%p)", index, mNode);
80 AtspiAccessible *rawChild = atspi_accessible_get_child_at_index(mNode, index, NULL);
81 return std::make_shared<AtspiAccessibleNode>(rawChild);
84 std::vector<std::shared_ptr<AccessibleNode>> AtspiAccessibleNode::getChildren() const
86 std::vector<std::shared_ptr<AccessibleNode>> ret{};
87 int nchild = this->getChildCount();
88 for (int i = 0; i < nchild; i++) {
89 auto child = getChildAt(i);
90 if (child) ret.push_back(child);
95 std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getParent() const
97 AtspiAccessible *rawParent = atspi_accessible_get_parent(mNode, NULL);
98 return std::make_shared<AtspiAccessibleNode>(rawParent);
99 /* auto node = AccessibleNode::get(parent);
100 if (parent) g_object_unref(parent);
105 void* AtspiAccessibleNode::getRawHandler(void) const
107 return static_cast<void*>(mNode);
110 void AtspiAccessibleNode::refresh()
112 gchar *rolename = atspi_accessible_get_role_name(mNode, NULL);
118 gchar *uID = atspi_accessible_get_unique_id(mNode, NULL);
124 mRes = std::string{"N/A"};
127 gchar *name = atspi_accessible_get_name(mNode, NULL);
132 GHashTable *attributes = atspi_accessible_get_attributes(mNode, NULL);
133 char *t = (char*)g_hash_table_lookup(attributes, "type");
134 char *s = (char*)g_hash_table_lookup(attributes, "style");
136 if (t) mType = std::string(t);
137 if (s) mStyle = std::string(s);
142 g_hash_table_unref(attributes);
144 AtspiStateSet *st = atspi_accessible_get_state_set(mNode);
145 GArray *states = atspi_state_set_get_states(st);
147 char *state_name = NULL;
149 for (int i = 0; states && (i < states->len); ++i) {
150 stat = g_array_index(states, AtspiStateType, i);
151 setFeatureProperty(stat);
154 if (states) g_array_free(states, 0);
157 AtspiComponent *component = atspi_accessible_get_component_iface(mNode);
159 AtspiRect *extent = atspi_component_get_extents(
160 component, ATSPI_COORD_TYPE_SCREEN, NULL);
163 Rect<int>{extent->x, extent->y, extent->x + extent->width,
164 extent->y + extent->height};
167 g_object_unref(component);
171 std::vector<std::string> AtspiAccessibleNode::getActions() const
173 std::vector<std::string> result{};
177 action = atspi_accessible_get_action_iface(mNode);
180 int n_actions = atspi_action_get_n_actions(action, NULL);
182 for (a = 0; a < n_actions; a++) {
183 char *action_name = atspi_action_get_action_name(action, a, NULL);
184 if (!action_name) continue;
185 result.push_back(std::string{action_name});
188 g_object_unref(action);
193 bool AtspiAccessibleNode::doAction(std::string actionName)
198 action = atspi_accessible_get_action_iface(mNode);
201 int n_actions = atspi_action_get_n_actions(action, NULL);
203 for (a = 0; a < n_actions; a++) {
204 char *action_name = atspi_action_get_action_name(action, a, NULL);
205 if (!action_name) return false;
207 if (!strcmp(actionName.c_str(), action_name)) {
208 atspi_action_do_action(action, a, NULL);
210 g_object_unref(action);
215 g_object_unref(action);
220 void AtspiAccessibleNode::setValue(std::string text)
222 AtspiEditableText *iface = atspi_accessible_get_editable_text(mNode);
223 LOG_F(INFO,"set Value iface:%p obj:%p text:%s", iface, mNode, text.c_str() );
225 int len = getText().length();
226 atspi_editable_text_delete_text(iface, 0, len, NULL);
227 atspi_editable_text_insert_text(iface, 0, text.c_str(), text.length(),
232 void AtspiAccessibleNode::setFeatureProperty(AtspiStateType type)
235 LONGCLICKABLE = 0X0040,
239 case ATSPI_STATE_CHECKED:
240 setFeatureProperty(NodeFeatureProperties::CHECKED, true);
242 case ATSPI_STATE_CHECKABLE:
243 setFeatureProperty(NodeFeatureProperties::CHECKABLE, true);
245 case ATSPI_STATE_ENABLED:
246 setFeatureProperty(NodeFeatureProperties::ENABLED, true);
248 case ATSPI_STATE_FOCUSABLE:
249 setFeatureProperty(NodeFeatureProperties::FOCUSABLE, true);
251 case ATSPI_STATE_FOCUSED:
252 setFeatureProperty(NodeFeatureProperties::FOCUSED, true);
254 case ATSPI_STATE_SELECTABLE:
255 setFeatureProperty(NodeFeatureProperties::SELECTABLE, true);
257 case ATSPI_STATE_SELECTED:
258 setFeatureProperty(NodeFeatureProperties::SELECTED, true);
260 case ATSPI_STATE_SHOWING:
261 setFeatureProperty(NodeFeatureProperties::SHOWING, true);
263 case ATSPI_STATE_VISIBLE:
264 setFeatureProperty(NodeFeatureProperties::VISIBLE, true);
266 case ATSPI_STATE_ACTIVE:
267 setFeatureProperty(NodeFeatureProperties::ACTIVE, true);
269 case ATSPI_STATE_SENSITIVE:
270 setFeatureProperty(NodeFeatureProperties::CLICKABLE, true);
272 case ATSPI_STATE_DEFUNCT:
273 case ATSPI_STATE_INVALID:
274 setFeatureProperty(NodeFeatureProperties::INVALID, true);
276 case ATSPI_STATE_TRANSIENT:
277 case ATSPI_STATE_TRUNCATED:
278 case ATSPI_STATE_ANIMATED:
279 case ATSPI_STATE_ARMED:
280 case ATSPI_STATE_BUSY:
281 case ATSPI_STATE_COLLAPSED:
282 case ATSPI_STATE_EDITABLE:
283 case ATSPI_STATE_EXPANDABLE:
284 case ATSPI_STATE_EXPANDED:
285 case ATSPI_STATE_HAS_TOOLTIP:
286 case ATSPI_STATE_HORIZONTAL:
287 case ATSPI_STATE_ICONIFIED:
288 case ATSPI_STATE_MODAL:
289 case ATSPI_STATE_MULTI_LINE:
290 case ATSPI_STATE_MULTISELECTABLE:
291 case ATSPI_STATE_OPAQUE:
292 case ATSPI_STATE_PRESSED:
293 case ATSPI_STATE_RESIZABLE:
294 case ATSPI_STATE_SINGLE_LINE:
295 case ATSPI_STATE_STALE:
296 case ATSPI_STATE_VERTICAL:
297 case ATSPI_STATE_MANAGES_DESCENDANTS:
298 case ATSPI_STATE_INDETERMINATE:
299 case ATSPI_STATE_REQUIRED:
300 case ATSPI_STATE_INVALID_ENTRY:
301 case ATSPI_STATE_SUPPORTS_AUTOCOMPLETION:
302 case ATSPI_STATE_SELECTABLE_TEXT:
303 case ATSPI_STATE_IS_DEFAULT:
304 case ATSPI_STATE_VISITED:
305 case ATSPI_STATE_HAS_POPUP:
306 case ATSPI_STATE_READ_ONLY:
307 case ATSPI_STATE_LAST_DEFINED: