-#include "AccessibleNode.h"
-#include <string.h>
-#include <iostream>
-#include <vector>
+#include "AtspiAccessibleNode.h"
-#include <loguru.hpp>
-#include "config.h"
-
-std::map<AtspiAccessible *, AccessibleNode *> AccessibleNode::mNodeMap{};
-
-AccessibleNode::~AccessibleNode()
-{
+#include <gio/gio.h>
-}
+#include <loguru.hpp>
-AccessibleNode::AccessibleNode() : AccessibleNode(nullptr)
-{
- // No meaning without AtspiAccessbile object
- // prohibited to create this object with this constructor
-}
+//std::map<AtspiAccessible *, AccessibleNode *> AccessibleNode::mNodeMap{};
-AccessibleNode::AccessibleNode(AtspiAccessible *node)
- : mNode(make_gobj_ref_unique(node)), mBoundingBox{0,0,0,0}, mSupportingIfaces(0), mFeatureProperty(0), mIsAlive(true)
+AtspiAccessibleNode::AtspiAccessibleNode(AtspiAccessible *node)
+: mNode{node}
{
- // prohibited to create this object this constructor
- // better to use AccessibleNode::get factory method.
-
- LOG_SCOPE_F(1, "AccessibleNode constructor %p", mNode.get());
- GArray *ifaces = atspi_accessible_get_interfaces(mNode.get());
+ GArray *ifaces = atspi_accessible_get_interfaces(mNode);
if (ifaces) {
for (unsigned int i = 0; i < ifaces->len; i++) {
char *iface = g_array_index(ifaces, char *, i);
g_free(iface);
}
-
g_array_free(ifaces, FALSE);
}
this->refresh();
}
-std::unique_ptr<AccessibleNode> AccessibleNode::get(AtspiAccessible *node)
+AtspiAccessibleNode::~AtspiAccessibleNode()
+{
+ if(mNode) g_object_unref(mNode);
+}
+
+int AtspiAccessibleNode::getChildCount() const
+{
+ int count = atspi_accessible_get_child_count(mNode, NULL);
+ if (count <= 0) return 0;
+ return count;
+}
+
+std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getChildAt(int index) const
+{
+ LOG_SCOPE_F(INFO, "getChild @ %d from node(%p)", index, mNode);
+ AtspiAccessible *rawChild = atspi_accessible_get_child_at_index(mNode, index, NULL);
+ return std::make_shared<AtspiAccessibleNode>(rawChild);
+}
+
+std::vector<std::shared_ptr<AccessibleNode>> AtspiAccessibleNode::getChildren() const
{
- return std::make_unique<AccessibleNode>(node);
+ std::vector<std::shared_ptr<AccessibleNode>> ret{};
+ int nchild = this->getChildCount();
+ for (int i = 0; i < nchild; i++) {
+ auto child = getChildAt(i);
+ if (child) ret.push_back(child);
+ }
+ return ret;
}
-void AccessibleNode::refresh() const
+std::shared_ptr<AccessibleNode> AtspiAccessibleNode::getParent() const
{
- gchar *rolename = atspi_accessible_get_role_name(mNode.get(), NULL);
+ AtspiAccessible *rawParent = atspi_accessible_get_parent(mNode, NULL);
+ return std::make_shared<AtspiAccessibleNode>(rawParent);
+/* auto node = AccessibleNode::get(parent);
+ if (parent) g_object_unref(parent);
+ return node; */
+}
+
+
+void* AtspiAccessibleNode::getRawHandler(void) const
+{
+ return static_cast<void*>(mNode);
+}
+
+void AtspiAccessibleNode::refresh()
+{
+ gchar *rolename = atspi_accessible_get_role_name(mNode, NULL);
if (rolename) {
mRole = rolename;
g_free(rolename);
}
-
- gchar *uID = atspi_accessible_get_unique_id(mNode.get(), NULL);
+#ifdef TIZEN
+ gchar *uID = atspi_accessible_get_unique_id(mNode, NULL);
if (uID) {
mRes = uID;
g_free(uID);
}
+#else
+ mRes = std::string{"N/A"};
+#endif
- GHashTable *attributes = atspi_accessible_get_attributes(mNode.get(), NULL);
+ gchar *name = atspi_accessible_get_name(mNode, NULL);
+ mText = name;
+ mPkg = name;
+ g_free(name);
+
+ GHashTable *attributes = atspi_accessible_get_attributes(mNode, NULL);
char *t = (char*)g_hash_table_lookup(attributes, "type");
char *s = (char*)g_hash_table_lookup(attributes, "style");
g_hash_table_unref(attributes);
- AtspiStateSet *st = atspi_accessible_get_state_set(mNode.get());
+ AtspiStateSet *st = atspi_accessible_get_state_set(mNode);
GArray *states = atspi_state_set_get_states(st);
char *state_name = NULL;
if (states) g_array_free(states, 0);
g_object_unref(st);
-}
-
-int AccessibleNode::getChildCount() const
-{
- return atspi_accessible_get_child_count(mNode.get(), NULL);
-}
-std::unique_ptr<AccessibleNode> AccessibleNode::getChildAt(int index) const
-{
- AtspiAccessible *child =
- atspi_accessible_get_child_at_index(mNode.get(), index, NULL);
- if (child) {
- auto node = AccessibleNode::get(child);
- g_object_unref(child);
- return node;
+ AtspiComponent *component = atspi_accessible_get_component_iface(mNode);
+ if (component) {
+ AtspiRect *extent = atspi_component_get_extents(
+ component, ATSPI_COORD_TYPE_SCREEN, NULL);
+ if (extent) {
+ mBoundingBox =
+ Rect<int>{extent->x, extent->y, extent->x + extent->width,
+ extent->y + extent->height};
+ g_free(extent);
+ }
+ g_object_unref(component);
}
- return AccessibleNode::get(nullptr);
-}
-
-std::unique_ptr<AccessibleNode> AccessibleNode::getParent() const
-{
- AtspiAccessible *parent = atspi_accessible_get_parent(mNode.get(), NULL);
- auto node = AccessibleNode::get(parent);
- if (parent) g_object_unref(parent);
- return node;
}
-void AccessibleNode::print(int d, int m) const
+std::vector<std::string> AtspiAccessibleNode::getActions() const
{
- if (m <= 0 || d > m) return;
+ std::vector<std::string> result{};
+ const char *name;
+ AtspiAction *action;
- int n = 0;
- this->print(d);
- n = getChildCount();
+ action = atspi_accessible_get_action_iface(mNode);
+ if (action) {
+ int a;
+ int n_actions = atspi_action_get_n_actions(action, NULL);
- for (int i = 0; i < n; i++) {
- auto child = getChildAt(i);
- if (child) child->print(d + 1, m);
+ for (a = 0; a < n_actions; a++) {
+ char *action_name = atspi_action_get_action_name(action, a, NULL);
+ if (!action_name) continue;
+ result.push_back(std::string{action_name});
+ g_free(action_name);
+ }
+ g_object_unref(action);
}
+ return result;
}
-void AccessibleNode::print(int d) const
+bool AtspiAccessibleNode::doAction(std::string actionName)
{
- char *name = atspi_accessible_get_name(mNode.get(), NULL);
- char *role = atspi_accessible_get_role_name(mNode.get(), NULL);
- LOG_F(INFO, "%s - %p(%s) / role:%s, pkg:%s, text:%s",
- std::string(d, ' ').c_str(), mNode.get(), name, role, getPkg().c_str(),
- getText().c_str());
- free(name);
- free(role);
-}
+ const char *name;
+ AtspiAction *action;
-bool AccessibleNode::isSupporting(AccessibleNodeInterface thisIface) const
-{
- return (mSupportingIfaces & static_cast<int>(thisIface)) != 0;
+ action = atspi_accessible_get_action_iface(mNode);
+ if (action) {
+ int a;
+ int n_actions = atspi_action_get_n_actions(action, NULL);
+
+ for (a = 0; a < n_actions; a++) {
+ char *action_name = atspi_action_get_action_name(action, a, NULL);
+ if (!action_name) return false;
+
+ if (!strcmp(actionName.c_str(), action_name)) {
+ atspi_action_do_action(action, a, NULL);
+ g_free(action_name);
+ g_object_unref(action);
+ return true;
+ }
+ g_free(action_name);
+ }
+ g_object_unref(action);
+ }
+ return false;
}
-bool AccessibleNode::hasFeatureProperty(NodeFeatureProperties prop) const
+void AtspiAccessibleNode::setValue(std::string text)
{
- return (mFeatureProperty & static_cast<int>(prop)) != 0;
+ AtspiEditableText *iface = atspi_accessible_get_editable_text(mNode);
+ LOG_F(INFO,"set Value iface:%p obj:%p text:%s", iface, mNode, text.c_str() );
+ if (iface) {
+ int len = getText().length();
+ atspi_editable_text_delete_text(iface, 0, len, NULL);
+ atspi_editable_text_insert_text(iface, 0, text.c_str(), text.length(),
+ NULL);
+ }
}
-void AccessibleNode::setFeatureProperty(AtspiStateType type) const
+void AtspiAccessibleNode::setFeatureProperty(AtspiStateType type)
{
/*
LONGCLICKABLE = 0X0040,
case ATSPI_STATE_SENSITIVE:
setFeatureProperty(NodeFeatureProperties::CLICKABLE, true);
break;
-
+ case ATSPI_STATE_DEFUNCT:
+ case ATSPI_STATE_INVALID:
+ setFeatureProperty(NodeFeatureProperties::INVALID, true);
+ break;
case ATSPI_STATE_TRANSIENT:
case ATSPI_STATE_TRUNCATED:
case ATSPI_STATE_ANIMATED:
- case ATSPI_STATE_INVALID:
case ATSPI_STATE_ARMED:
case ATSPI_STATE_BUSY:
case ATSPI_STATE_COLLAPSED:
- case ATSPI_STATE_DEFUNCT:
case ATSPI_STATE_EDITABLE:
case ATSPI_STATE_EXPANDABLE:
case ATSPI_STATE_EXPANDED:
case ATSPI_STATE_LAST_DEFINED:
break;
}
-}
-
-void AccessibleNode::setFeatureProperty(NodeFeatureProperties prop, bool has) const
-{
- if (has)
- mFeatureProperty |= static_cast<int>(prop);
- else
- mFeatureProperty &= ~static_cast<int>(prop);
-}
-
-std::string AccessibleNode::getDesc() const
-{
- return mDesc;
-}
-
-std::string AccessibleNode::getText() const
-{
- gchar *name = atspi_accessible_get_name(mNode.get(), NULL);
- mText = name;
- mPkg = name;
- g_free(name);
-
- return mText;
-}
-
-std::string AccessibleNode::getPkg() const
-{
- return mPkg;
-}
-
-std::string AccessibleNode::getRes() const
-{
- return mRes;
-}
-
-std::string AccessibleNode::getType() const
-{
- return mType;
-}
-
-std::string AccessibleNode::getStyle() const
-{
- return mStyle;
-}
-
-Rect<int> AccessibleNode::getBoundingBox() const
-{
- AtspiComponent *component = atspi_accessible_get_component_iface(mNode.get());
- if (component) {
- AtspiRect *extent = atspi_component_get_extents(
- component, ATSPI_COORD_TYPE_SCREEN, NULL);
- if (extent) {
- mBoundingBox =
- Rect<int>{extent->x, extent->y, extent->x + extent->width,
- extent->y + extent->height};
- g_free(extent);
- }
- g_object_unref(component);
- }
-
- return mBoundingBox;
-}
-
-bool AccessibleNode::isCheckable() const
-{
- return hasFeatureProperty(NodeFeatureProperties::CHECKABLE);
-}
-
-bool AccessibleNode::isChecked() const
-{
- return hasFeatureProperty(NodeFeatureProperties::CHECKED);
-}
-
-bool AccessibleNode::isClickable() const
-{
- return hasFeatureProperty(NodeFeatureProperties::CLICKABLE);
-}
-
-bool AccessibleNode::isEnabled() const
-{
- return hasFeatureProperty(NodeFeatureProperties::ENABLED);
-}
-
-bool AccessibleNode::isFocusable() const
-{
- return hasFeatureProperty(NodeFeatureProperties::FOCUSABLE);
-}
-
-bool AccessibleNode::isFocused() const
-{
- return hasFeatureProperty(NodeFeatureProperties::FOCUSED);
-}
-
-bool AccessibleNode::isLongClickable() const
-{
- return hasFeatureProperty(NodeFeatureProperties::LONGCLICKABLE);
-}
-
-bool AccessibleNode::isScrollable() const
-{
- return hasFeatureProperty(NodeFeatureProperties::SCROLLABLE);
-}
-
-bool AccessibleNode::isSelectable() const
-{
- return hasFeatureProperty(NodeFeatureProperties::SELECTABLE);
-}
-
-bool AccessibleNode::isSelected() const
-{
- return hasFeatureProperty(NodeFeatureProperties::SELECTED);
-}
-
-bool AccessibleNode::isVisible() const
-{
- return hasFeatureProperty(NodeFeatureProperties::VISIBLE);
-}
-
-bool AccessibleNode::isShowing() const
-{
- return hasFeatureProperty(NodeFeatureProperties::SHOWING);
-}
-
-bool AccessibleNode::isActive() const
-{
- return hasFeatureProperty(NodeFeatureProperties::ACTIVE);
-}
-
-AtspiAccessible *AccessibleNode::getAccessible() const
-{
- return mNode.get();
-}
-
-void AccessibleNode::setValue(std::string text) const
-{
- AtspiEditableText *iface = atspi_accessible_get_editable_text(mNode.get());
- LOG_F(INFO,"set Value iface:%p obj:%p text:%s", iface, mNode.get(), text.c_str() );
- if (iface) {
- int len = getText().length();
- atspi_editable_text_delete_text(iface, 0, len, NULL);
- atspi_editable_text_insert_text(iface, 0, text.c_str(), text.length(),
- NULL);
- }
-}
-
-std::vector<std::string> AccessibleNode::getActions() const
-{
- std::vector<std::string> result{};
- const char *name;
- AtspiAction *action;
-
- action = atspi_accessible_get_action_iface(mNode.get());
- if (action) {
- int a;
- int n_actions = atspi_action_get_n_actions(action, NULL);
-
- for (a = 0; a < n_actions; a++) {
- char *action_name = atspi_action_get_action_name(action, a, NULL);
- if (!action_name) continue;
- result.push_back(std::string{action_name});
- g_free(action_name);
- }
- g_object_unref(action);
- }
- return result;
-}
-
-bool AccessibleNode::doAction(std::string actionName) const
-{
- const char *name;
- AtspiAction *action;
-
- action = atspi_accessible_get_action_iface(mNode.get());
- if (action) {
- int a;
- int n_actions = atspi_action_get_n_actions(action, NULL);
-
- for (a = 0; a < n_actions; a++) {
- char *action_name = atspi_action_get_action_name(action, a, NULL);
- if (!action_name) return false;
-
- if (!strcmp(actionName.c_str(), action_name)) {
- atspi_action_do_action(action, a, NULL);
- g_free(action_name);
- g_object_unref(action);
- return true;
- }
- g_free(action_name);
- }
- g_object_unref(action);
- }
- return false;
}
\ No newline at end of file