2 * Copyright (c) 2021 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
27 using namespace Aurum;
29 AccessibleNode::~AccessibleNode()
33 AccessibleNode::AccessibleNode()
34 : mText{""}, mPkg{""}, mRole{""}, mId{""}, mType{""}, mStyle{""},
35 mScreenBoundingBox{0,0,0,0}, mWindowBoundingBox{0,0,0,0}, mSupportingIfaces(0), mFeatureProperty(0), mValid{true}, mLock{}
39 std::string AccessibleNode::description() {
40 std::stringstream ss{};
43 ss << "\"mId\":\"" << this->mId << "\", ";
44 ss << "\"mAutomationId\":\"" << this->mAutomationId << "\", ";
45 ss << "\"mRole\":\"" << this->mRole << "\", ";
46 ss << "\"mText\":\"" << this->mText << "\", ";
47 ss << "\"mPkg\":\"" << this->mPkg << "\", ";
48 ss << "\"mType\":\"" << this->mType << "\", ";
49 ss << "\"mStyle\":\"" << this->mStyle << "\", ";
55 void AccessibleNode::notify(int type1, int type2, void *src)
57 void *handler = getRawHandler();
59 if ((EventType)type1 == EventType::Object && (ObjectEventType)type2 == ObjectEventType::ObjectStateDefunct) {
60 if (handler == src) invalidate();
64 void AccessibleNode::invalidate()
66 std::unique_lock<std::mutex> lock(mLock);
67 LOGI("object %p is now invalid", this);
71 bool AccessibleNode::isValid() const
73 std::unique_lock<std::mutex> lock(mLock);
74 if (!getRawHandler() || !mValid) return false;
78 void AccessibleNode::print(int depth, int maxDepth)
80 if (maxDepth <= 0 || depth > maxDepth) return;
83 auto children = this->getChildren();
84 for ( auto &child : children ) {
85 if (child) child->print(depth +1, maxDepth);
89 void AccessibleNode::print(int d)
92 LOGI("%s %s",std::string(d, ' ').c_str(), description().c_str());
95 bool AccessibleNode::isSupporting(AccessibleNodeInterface thisIface) const
97 return (mSupportingIfaces & static_cast<int>(thisIface)) != 0;
100 bool AccessibleNode::hasFeatureProperty(NodeFeatureProperties prop) const
102 return (mFeatureProperty & static_cast<int>(prop)) != 0;
105 void AccessibleNode::setFeatureProperty(NodeFeatureProperties prop, bool has)
108 mFeatureProperty |= static_cast<int>(prop);
110 mFeatureProperty &= ~static_cast<int>(prop);
113 void AccessibleNode::resetFeatureProperty()
115 mFeatureProperty = 0;
118 std::string AccessibleNode::getText() const
123 std::string AccessibleNode::getPkg() const
128 std::string AccessibleNode::getId() const
133 std::string AccessibleNode::getAutomationId() const
135 return mAutomationId;
138 std::string AccessibleNode::getRole() const
143 std::string AccessibleNode::getType() const
148 std::string AccessibleNode::getStyle() const
153 std::string AccessibleNode::getXPath() const
158 Rect<int> AccessibleNode::getScreenBoundingBox() const
160 return mScreenBoundingBox;
163 Rect<int> AccessibleNode::getWindowBoundingBox() const
165 return mWindowBoundingBox;
168 bool AccessibleNode::isCheckable() const
170 return hasFeatureProperty(NodeFeatureProperties::CHECKABLE);
173 bool AccessibleNode::isChecked() const
175 return hasFeatureProperty(NodeFeatureProperties::CHECKED);
178 bool AccessibleNode::isClickable() const
180 return hasFeatureProperty(NodeFeatureProperties::CLICKABLE);
183 bool AccessibleNode::isEnabled() const
185 return hasFeatureProperty(NodeFeatureProperties::ENABLED);
188 bool AccessibleNode::isFocusable() const
190 return hasFeatureProperty(NodeFeatureProperties::FOCUSABLE);
193 bool AccessibleNode::isFocused() const
195 return hasFeatureProperty(NodeFeatureProperties::FOCUSED);
198 bool AccessibleNode::isLongClickable() const
200 return hasFeatureProperty(NodeFeatureProperties::LONGCLICKABLE);
203 bool AccessibleNode::isScrollable() const
205 return hasFeatureProperty(NodeFeatureProperties::SCROLLABLE);
208 bool AccessibleNode::isSelectable() const
210 return hasFeatureProperty(NodeFeatureProperties::SELECTABLE);
213 bool AccessibleNode::isSelected() const
215 return hasFeatureProperty(NodeFeatureProperties::SELECTED);
218 bool AccessibleNode::isVisible() const
220 return hasFeatureProperty(NodeFeatureProperties::VISIBLE);
223 bool AccessibleNode::isShowing() const
225 return hasFeatureProperty(NodeFeatureProperties::SHOWING);
228 bool AccessibleNode::isActive() const
230 return hasFeatureProperty(NodeFeatureProperties::ACTIVE);