{
if (!node) return;
- node->refresh(false);
+ node->updateUniqueId();
+ node->updateName();
+ node->updateRoleName();
+ node->updateAttributes();
+ node->updateToolkitName();
std::string name;
if (node->getType().empty())
element.set_name(name.c_str());
element.append_attribute("name") = node->getText().c_str();
- element.append_attribute("type") = node->getType().c_str();
element.append_attribute("id") = node->getId().c_str();
element.append_attribute("automationid") = node->getAutomationId().c_str();
- element.append_attribute("package") = node->getPkg().c_str();
-
- const Rect<int> &size = node->getScreenBoundingBox();
- element.append_attribute("x") = size.mTopLeft.x;
- element.append_attribute("y") = size.mTopLeft.y;
- element.append_attribute("width") = size.width();
- element.append_attribute("height") = size.height();
-
- const std::vector<std::pair<std::string, bool>> attributes = {
- {"checked", node->isChecked()},
- {"checkable", node->isCheckable()},
- {"clickable", node->isClickable()},
- {"enabled", node->isEnabled()},
- {"focused", node->isFocused()},
- {"focusable", node->isFocusable()},
- {"scrollable", node->isScrollable()},
- {"selected", node->isSelected()},
- {"showing", node->isShowing()},
- {"active", node->isActive()},
- {"visible", node->isVisible()},
- {"selectable", node->isSelectable()},
- {"highlightable", node->isHighlightable()}
- };
- for (const auto& attribute : attributes) {
- element.append_attribute(attribute.first.c_str()) = attribute.second;
- }
mXNodeMap[node->getId()] = node;
- int childCnt = node->getChildCount();
- for (int i = 0; i < childCnt; i++) {
- const std::shared_ptr<AccessibleNode>& childNode = node->getChildAt(i);
- if (childNode->getRawHandler() == nullptr) continue;
+ auto children = node->getChildren();
+ for (auto &child : children)
+ {
+ if (child->getRawHandler() == nullptr) continue;
xml_node childElement = element.append_child("");
- traverse(childElement, childNode);
+ traverse(childElement, child);
}
}
xml_node xmlNode = mDoc->select_node(query.c_str()).node();
if (xmlNode) {
- int childCnt = parent->getChildCount();
- for (int i = 0; i < childCnt; i++) {
- const std::shared_ptr<AccessibleNode>& childNode = parent->getChildAt(i);
- if (childNode->getRawHandler() == nullptr) continue;
+ auto children = node->getChildren();
+ for (auto &child : children) {
+ if (child->getRawHandler() == nullptr) continue;
xml_node childElement = xmlNode.append_child("");
- traverse(childElement, childNode);
+ traverse(childElement, child);
}
return parent;
}
if (currentMatch) partialMatches.push_front(currentMatch);
if (!(mSelector->mMaxDepth && (depth+1 > mSelector->mMaxDepth))) {
- int childCnt = root->getChildCount();
- for (int i = 0; i < childCnt; i++) {
- std::shared_ptr<AccessibleNode> childNode = root->getChildAt(i);
- if (childNode->getRawHandler() == nullptr) continue;
+ auto children = root->getChildren();
+ for (int i = 0; i < (int)children.size(); i++) {
+ auto child = children[i];
+ if (child->getRawHandler() == nullptr) continue;
std::vector<std::shared_ptr<AccessibleNode>> childret =
- findObjects(childNode, i, depth + 1, partialMatches);
+ findObjects(child, i, depth + 1, partialMatches);
std::move(std::begin(childret), std::end(childret), std::back_inserter(ret));
if (!ret.empty() && mEarlyReturn) {
LOGI("Object found and earlyReturn");
watcher->attach(shared_from_this());
if (mNode) {
- this->updateApplication();
this->updateUniqueId();
this->updateStates();
} else {
std::vector<std::shared_ptr<AccessibleNode>> AtspiAccessibleNode::getChildren() const
{
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);
+
+ GArray *children = AtspiWrapper::Atspi_accessible_get_children(mNode, NULL);
+ if (children) {
+ ret.reserve(children->len);
+ AtspiAccessible *child = nullptr;
+ for (unsigned int i = 0; i < children->len; i++) {
+ child = g_array_index(children, AtspiAccessible *, i);
+ if (child) {
+ ret.push_back(std::make_shared<AtspiAccessibleNode>(child));
+ }
+ }
+ g_array_free(children, true);
}
+
return ret;
}
void AtspiAccessibleNode::updateRoleName()
{
+ if (!mRole.empty()) return;
+
AtspiWrapper::Atspi_accessible_clear_cache(mNode);
gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL);
void AtspiAccessibleNode::updateUniqueId()
{
+ if (!mId.empty()) return;
+
AtspiWrapper::Atspi_accessible_clear_cache(mNode);
#ifdef TIZEN
void AtspiAccessibleNode::updateToolkitName()
{
+ if (!mToolkitName.empty()) return;
+
AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL);
if (app) {
gchar *toolkitName = AtspiWrapper::Atspi_accessible_get_toolkit_name(app, NULL);
void AtspiAccessibleNode::updateApplication()
{
+ if (!mPkg.empty()) return;
+
AtspiWrapper::Atspi_accessible_clear_cache(mNode);
AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL);
void AtspiAccessibleNode::updateAttributes()
{
+ if (!mType.empty()) return;
+
AtspiWrapper::Atspi_accessible_clear_cache(mNode);
GHashTable *attributes = AtspiWrapper::Atspi_accessible_get_attributes(mNode, NULL);
void AtspiAccessibleNode::updateExtents()
{
- AtspiWrapper::Atspi_accessible_clear_cache(mNode);
-
AtspiComponent *component = AtspiWrapper::Atspi_accessible_get_component_iface(mNode);
if (component) {
AtspiRect *screenExtent = AtspiWrapper::Atspi_component_get_extents(
void AtspiAccessibleNode::updatePid()
{
- AtspiWrapper::Atspi_accessible_clear_cache(mNode);
+ if (mPid > 0) return;
mPid = AtspiWrapper::Atspi_accessible_get_process_id(mNode, NULL);
}
void AtspiAccessibleNode::updateTextMinBoundingRect()
{
- AtspiWrapper::Atspi_accessible_clear_cache(mNode);
-
AtspiText *text = atspi_accessible_get_text_iface(mNode);
if (text)
{
AtspiWrapper::Atspi_accessible_clear_cache(mNode);
if (isValid()) {
- gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL);
- if (rolename) {
- mRole = rolename;
- g_free(rolename);
+ if (mRole.empty()) {
+ gchar *rolename = AtspiWrapper::Atspi_accessible_get_role_name(mNode, NULL);
+ if (rolename) {
+ mRole = rolename;
+ g_free(rolename);
+ }
}
#ifdef TIZEN
- gchar *uID = AtspiWrapper::Atspi_accessible_get_unique_id(mNode, NULL);
- if (uID) {
- mId = uID;
- g_free(uID);
+ if (mId.empty()) {
+ gchar *uID = AtspiWrapper::Atspi_accessible_get_unique_id(mNode, NULL);
+ if (uID) {
+ mId = uID;
+ g_free(uID);
+ }
}
#else
mId = std::string{"N/A"};
#endif
-
gchar *name = AtspiWrapper::Atspi_accessible_get_name(mNode, NULL);
if (name) {
mText = name;
g_free(name);
}
- gchar *toolkitName = AtspiWrapper::Atspi_accessible_get_toolkit_name(mNode, NULL);
- if (toolkitName) {
- mToolkitName = toolkitName;
- g_free(toolkitName);
+ if (mToolkitName.empty()) {
+ gchar *toolkitName = AtspiWrapper::Atspi_accessible_get_toolkit_name(mNode, NULL);
+ if (toolkitName) {
+ mToolkitName = toolkitName;
+ g_free(toolkitName);
+ }
}
- AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL);
- if (app) {
- gchar *pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL);
- if (pkg) {
- mPkg = pkg;
- g_free(pkg);
+ if (mPkg.empty()) {
+ AtspiAccessible *app = AtspiWrapper::Atspi_accessible_get_application(mNode, NULL);
+ if (app) {
+ gchar *pkg = AtspiWrapper::Atspi_accessible_get_name(app, NULL);
+ if (pkg) {
+ mPkg = pkg;
+ g_free(pkg);
+ }
+ g_object_unref(app);
}
- g_object_unref(app);
}
- GHashTable *attributes = AtspiWrapper::Atspi_accessible_get_attributes(mNode, NULL);
- if (attributes) {
- char *t = (char*)g_hash_table_lookup(attributes, "type");
- if (!t) t = (char*)g_hash_table_lookup(attributes, "t");
- if (!t) t = (char*)g_hash_table_lookup(attributes, "class");
- char *s = (char*)g_hash_table_lookup(attributes, "style");
- char *a = (char*)g_hash_table_lookup(attributes, "automationId");
-
- if (t) mType = std::string(t);
- else mType = mRole;
- if (s) mStyle = std::string(s);
- if (a) mAutomationId = std::string(a);
-
- g_hash_table_unref(attributes);
+ if (mType.empty()) {
+ GHashTable *attributes = AtspiWrapper::Atspi_accessible_get_attributes(mNode, NULL);
+ if (attributes) {
+ char *t = (char*)g_hash_table_lookup(attributes, "type");
+ if (!t) t = (char*)g_hash_table_lookup(attributes, "t");
+ if (!t) t = (char*)g_hash_table_lookup(attributes, "class");
+ char *s = (char*)g_hash_table_lookup(attributes, "style");
+ char *a = (char*)g_hash_table_lookup(attributes, "automationId");
+
+ if (t) mType = std::string(t);
+ else mType = mRole;
+ if (s) mStyle = std::string(s);
+ if (a) mAutomationId = std::string(a);
+
+ g_hash_table_unref(attributes);
+ }
}
AtspiStateSet *st = AtspiWrapper::Atspi_accessible_get_state_set(mNode);
atspi_init();
+ AtspiWrapper::Atspi_accessible_set_cache_mask(AtspiWrapper::Atspi_get_desktop(0), ATSPI_CACHE_ALL);
+
mEventThread = g_thread_new("AtspiEventThread", eventThreadLoop, this);
mDbusProxy = g_dbus_proxy_new_for_bus_sync(
void AtspiAccessibleWatcher::appendApp(AtspiAccessibleWatcher *instance, AtspiAccessible *app, char *pkg)
{
- AtspiWrapper::Atspi_accessible_set_cache_mask(app, ATSPI_CACHE_ALL);
LOGI("window activated in app(%s)", pkg);
if (!instance->mActiveAppMap.count(app)) {
LOGI("add activated window's app in map");
std::vector<std::shared_ptr<UiObject>> UiObject::getChildren() const
{
- auto sel = Sel::depth(2);
- return this->findObjects(sel);
+ std::vector<std::shared_ptr<UiObject>> ret{};
+
+ auto children = getAccessibleNode()->getChildren();
+ for (auto &child : children) {
+ ret.push_back(std::make_shared<UiObject>(mDevice, mSelector, child));
+ }
+
+ return ret;
}
std::shared_ptr<Node> UiObject::getDescendant()