From 46c987f2073ae43e1578f57b215443c4fa265c1e Mon Sep 17 00:00:00 2001 From: Hosang Kim Date: Mon, 10 Mar 2025 13:17:42 +0900 Subject: [PATCH] libaurum: use dumpTree for reducing dbus message calls. Change-Id: I3ac096d2669b487db58630c981444e936be2ad04 --- libaurum/inc/Accessibility/AccessibleNode.h | 18 +++++++ .../Impl/Accessibility/AtspiAccessibleNode.h | 7 +++ .../Impl/Accessibility/MockAccessibleNode.h | 7 +++ libaurum/inc/UiObject.h | 7 +++ .../Impl/Accessibility/AtspiAccessibleNode.cc | 17 +++++++ .../Impl/Accessibility/MockAccessibleNode.cc | 6 +++ libaurum/src/UiObject.cc | 51 ++++++++++++++++++- .../src/Commands/DumpObjectTreeCommand.cc | 1 - 8 files changed, 112 insertions(+), 2 deletions(-) diff --git a/libaurum/inc/Accessibility/AccessibleNode.h b/libaurum/inc/Accessibility/AccessibleNode.h index f1d4e89..f1381a7 100644 --- a/libaurum/inc/Accessibility/AccessibleNode.h +++ b/libaurum/inc/Accessibility/AccessibleNode.h @@ -537,6 +537,24 @@ public: */ virtual void refresh(bool updateAll = true) = 0; + /** + * @brief refresh method for updating properties of accessible node. This method is called when the node is created. + * + * @param text + * @param role + * @param type + * @param automationId + * @param description + * @param value + * @param minValue + * @param maxValue + * @param increment + * @param extents + */ + virtual void refresh(const std::string &text, const std::string &role, const std::string &type, + const std::string &automationId, const std::string &description, const std::string &imgSrc, + double value, double minValue, double maxValue, double increment, const Rect &extents) = 0; + /** * @brief Gets available atspi action name. * diff --git a/libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h b/libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h index 149980d..cca75d0 100644 --- a/libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h +++ b/libaurum/inc/Impl/Accessibility/AtspiAccessibleNode.h @@ -201,6 +201,13 @@ public: */ void refresh(bool updateAll = true) override; + /** + * @copydoc AccessibleNode::refresh() + */ + void refresh(const std::string &text, const std::string &role, const std::string &type, + const std::string &automationId, const std::string &description, const std::string &imgSrc, + double value, double minValue, double maxValue, double increment, const Rect &extents) override; + /** * @copydoc AccessibleNode::getActions() */ diff --git a/libaurum/inc/Impl/Accessibility/MockAccessibleNode.h b/libaurum/inc/Impl/Accessibility/MockAccessibleNode.h index f0bc7f0..a2db6ad 100644 --- a/libaurum/inc/Impl/Accessibility/MockAccessibleNode.h +++ b/libaurum/inc/Impl/Accessibility/MockAccessibleNode.h @@ -211,6 +211,13 @@ public: */ void refresh(bool updateAll = true) override; + /** + * @brief TBD + */ + void refresh(const std::string &text, const std::string &role, const std::string &type, + const std::string &automationId, const std::string &description, const std::string &imgSrc, + double value, double minValue, double maxValue, double increment, const Rect &extents) override; + /** * @brief TBD * @since_tizen 6.5 diff --git a/libaurum/inc/UiObject.h b/libaurum/inc/UiObject.h index cf6865e..fa24c77 100644 --- a/libaurum/inc/UiObject.h +++ b/libaurum/inc/UiObject.h @@ -26,9 +26,13 @@ #include "UiSelector.h" #include "Waiter.h" +#include "rapidjson/document.h" + #include #include +using namespace rapidjson; + namespace Aurum { class UiDevice; @@ -791,6 +795,9 @@ public: */ bool getIncludeHidden() const; +private: + std::shared_ptr parseTreeFromJson(Value &doc); + private: std::shared_ptr mDevice; std::shared_ptr mSelector; diff --git a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc index 316cd5e..87bf878 100644 --- a/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc +++ b/libaurum/src/Impl/Accessibility/AtspiAccessibleNode.cc @@ -456,6 +456,23 @@ void AtspiAccessibleNode::refresh(bool updateAll) } } +void AtspiAccessibleNode::refresh(const std::string &text, const std::string &role, const std::string &type, + const std::string &automationId, const std::string &description, const std::string &imgSrc, + double value, double minValue, double maxValue, double increment, const Rect &extents) +{ + mText = text; + mRole = role; + mType = type; + mAutomationId = automationId; + mDescription = description; + mImgSrc = imgSrc; + mValue = value; + mMinValue = minValue; + mMaxValue = maxValue; + mIncrement = increment; + mScreenBoundingBox = extents; +} + std::vector AtspiAccessibleNode::getActions() const { std::vector result{}; diff --git a/libaurum/src/Impl/Accessibility/MockAccessibleNode.cc b/libaurum/src/Impl/Accessibility/MockAccessibleNode.cc index 5501b92..4cd6a65 100644 --- a/libaurum/src/Impl/Accessibility/MockAccessibleNode.cc +++ b/libaurum/src/Impl/Accessibility/MockAccessibleNode.cc @@ -225,6 +225,12 @@ void MockAccessibleNode::refresh(bool updateAll) mFeatureProperty = (int)NodeFeatureProperties::SELECTABLE | (int)NodeFeatureProperties::SELECTED; } +void MockAccessibleNode::refresh(const std::string &text, const std::string &role, const std::string &type, + const std::string &automationId, const std::string &description, const std::string &imgSrc, + double value, double minValue, double maxValue, double increment, const Rect &extents) +{ +} + std::vector MockAccessibleNode::getActions() const { std::vector ret{}; diff --git a/libaurum/src/UiObject.cc b/libaurum/src/UiObject.cc index bec1d6d..e5d2934 100644 --- a/libaurum/src/UiObject.cc +++ b/libaurum/src/UiObject.cc @@ -180,12 +180,61 @@ std::vector> UiObject::getChildren() const return ret; } +std::shared_ptr UiObject::parseTreeFromJson(Value &value) +{ + std::vector> nodeChildren{}; + + if ((value.HasMember("appname") && value["appname"].IsString()) && + (value.HasMember("path") && value["path"].IsString())) { + auto appName = value["appname"].GetString(); + auto path = value["path"].GetString(); + auto node = mNode->refAccessibleNode(appName, path); + if (node) { + auto text = value.HasMember("text") && value["text"].IsString()? value["text"].GetString() : ""; + auto role = value.HasMember("role") && value["role"].IsString()? value["role"].GetString() : ""; + auto type = value.HasMember("type") && value["type"].IsString()? value["type"].GetString() : ""; + auto automationId = value.HasMember("automationId") && value["automationId"].IsString()? value["automationId"].GetString() : ""; + auto description = value.HasMember("description") && value["description"].IsString()? value["description"].GetString() : ""; + auto current = value.HasMember("value") && value["value"].HasMember("current") && value["value"]["current"].IsDouble()? value["value"]["current"].GetDouble() : 0.0f; + auto minValue = value.HasMember("value") && value["value"].HasMember("min") && value["value"]["min"].IsDouble()? value["value"]["min"].GetDouble() : 0.0f; + auto maxValue = value.HasMember("value") && value["value"].HasMember("max") && value["value"]["max"].IsDouble()? value["value"]["mimaxn"].GetDouble() : 0.0f; + auto increment = value.HasMember("value") && value["value"].HasMember("increment") && value["value"]["increment"].IsDouble()? value["value"]["increment"].GetDouble() : 0.0f; + auto x = value.HasMember("x") ? (value["x"].IsInt() ? value["x"].GetInt() : value["x"].GetDouble()) : 0; + auto y = value.HasMember("y") ? (value["y"].IsInt() ? value["y"].GetInt() : value["y"].GetDouble()) : 0; + auto w = value.HasMember("w") ? (value["w"].IsInt() ? value["w"].GetInt() : value["w"].GetDouble()) : 0; + auto h = value.HasMember("h") ? (value["h"].IsInt() ? value["h"].GetInt() : value["h"].GetDouble()) : 0; + auto extents = Rect{x, y, x + w, y + h}; + auto imgSrc = value.HasMember("attributes") && value["attributes"].HasMember("imgSrc") && value["attributes"]["imgSrc"].IsString() ? value["attributes"]["imgSrc"].GetString() : ""; + node->refresh(text, role, type, automationId, description, imgSrc, current, minValue, maxValue, increment, extents); + + if (value.HasMember("children") && value["children"].IsArray()) { + for (auto &child : value["children"].GetArray()) { + nodeChildren.push_back(parseTreeFromJson(child)); + } + } + + auto obj = std::make_shared(mDevice, mSelector, node); + return std::make_shared(obj, nodeChildren); + } + } + return std::make_shared(nullptr, nodeChildren); +} + std::shared_ptr UiObject::getDescendant() { + Document document; std::vector> nodeChildren{}; + auto json = mNode->dumpTree(); + document.Parse(json.c_str()); + if (!document.HasParseError()) { + auto node = parseTreeFromJson(document); + if (node->mNode) return node; + } + auto children = getChildren(); for (auto &&child : children) { + child->refresh(); nodeChildren.push_back(child->getDescendant()); } return std::make_shared(shared_from_this(), nodeChildren); @@ -543,4 +592,4 @@ void UiObject::setIncludeHidden(bool enabled) const { bool UiObject::getIncludeHidden() const { return mNode->getIncludeHidden(); -} \ No newline at end of file +} diff --git a/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc b/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc index 8faacbd..a98bfe4 100644 --- a/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc +++ b/org.tizen.aurum-bootstrap/src/Commands/DumpObjectTreeCommand.cc @@ -35,7 +35,6 @@ void DumpObjectTreeCommand::traverse(::aurum::Element *root, std::shared_ptrmNode) return; std::shared_ptr obj = node->mNode; - obj->refresh(); if (mObjMap->getElement(obj->getId()) == nullptr) mObjMap->addElement(obj); -- 2.34.1