From: Hosang Kim Date: Wed, 31 Jan 2024 05:07:11 +0000 (+0900) Subject: libaurum: Apply clean code to object releated classes X-Git-Tag: accepted/tizen/8.0/unified/20240216.155907~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b846d4143783cd3042d06ff3133a6983f7394ed;p=platform%2Fcore%2Fuifw%2Faurum.git libaurum: Apply clean code to object releated classes The IObject interface seems to have been added in the past to define a common interface between the ScreenAnalyzer object and the Ui Object. It seems better to delete it because there is no abstracted object other than UiObject. Clean Code was applied to the fact that UiObject calls getAccessibleNode even though it has Node. Change-Id: Icf1262cd5ef69a596fa8793721219404117eef34 --- diff --git a/libaurum/inc/Accessibility/AccessibleNode.h b/libaurum/inc/Accessibility/AccessibleNode.h index 26521db..88a04a0 100644 --- a/libaurum/inc/Accessibility/AccessibleNode.h +++ b/libaurum/inc/Accessibility/AccessibleNode.h @@ -25,7 +25,6 @@ #include #include "IEventConsumer.h" -#include "IObject.h" #include "Rect.h" #include "UiSelector.h" #include "config.h" @@ -86,7 +85,7 @@ enum class NodeFeatureProperties { * * @since_tizen 6.5 */ -class AccessibleNode : public std::enable_shared_from_this, public IEventConsumer, public IObject { +class AccessibleNode : public std::enable_shared_from_this, public IEventConsumer { public: /** * @brief AccessibleNode constructor. @@ -165,57 +164,57 @@ public: /** * @copydoc UiObject::getId() */ - std::string getId() const override; + std::string getId() const; /** * @copydoc UiObject::getType() */ - std::string getType() const override; + std::string getType() const; /** * @copydoc UiObject::getScreenBoundingBox() */ - const Rect getScreenBoundingBox() const override; + const Rect getScreenBoundingBox() const; /** * @copydoc UiObject::getOcrText() */ - std::string getOcrText() const override; + std::string getOcrText() const; /** * @copydoc UiObject::getWindowAngle() */ - int getWindowAngle() const override; + int getWindowAngle() const; /** * @copydoc UiObject::getTargetAngle() */ - int getTargetAngle() const override; + int getTargetAngle() const; /** * @copydoc UiObject::isFocusable() */ - bool isFocusable() const override; + bool isFocusable() const; /** * @copydoc UiObject::isFocused() */ - bool isFocused() const override; + bool isFocused() const; /** * @copydoc UiObject::isClickable() */ - bool isClickable() const override; + bool isClickable() const; /** * @copydoc UiObject::isActive() */ - bool isActive() const override; + bool isActive() const; /** * @copydoc UiObject::isShowing() */ - bool isShowing() const override; + bool isShowing() const; public: /** diff --git a/libaurum/inc/Aurum.h b/libaurum/inc/Aurum.h index 9abe627..d3089e3 100644 --- a/libaurum/inc/Aurum.h +++ b/libaurum/inc/Aurum.h @@ -52,7 +52,6 @@ #include "Waiter.h" #include "ISearchable.h" #include "IDevice.h" -#include "IObject.h" #include "Accessible.h" #include "Point2D.h" #include "Size2D.h" diff --git a/libaurum/inc/Interface/IObject.h b/libaurum/inc/Interface/IObject.h deleted file mode 100644 index 6fcaf42..0000000 --- a/libaurum/inc/Interface/IObject.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2022 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -#ifndef _IOBJECT_H_ -#define _IOBJECT_H_ - -#include "config.h" -#include "Rect.h" -#include - -namespace Aurum { - - -class IObject { -public: - - /** - * @brief IObject destructor - */ - virtual ~IObject() {} - - /** - * @copydoc UiObject::getId() - */ - virtual std::string getId() const = 0; - - /** - * @copydoc UiObject::getType() - */ - virtual std::string getType() const = 0; - - /** - * @copydoc UiObject::getScreenBoundingBox() - */ - virtual const Rect getScreenBoundingBox() const = 0; - - /** - * @copydoc UiObject::getOcrText() - */ - virtual std::string getOcrText() const = 0; - - /** - * @copydoc UiObject::getWindowAngle() - */ - virtual int getWindowAngle() const = 0; - - /** - * @copydoc UiObject::getTargetAngle() - */ - virtual int getTargetAngle() const = 0; - - /** - * @copydoc UiObject::isFocusable() - */ - virtual bool isFocusable() const = 0; - - /** - * @copydoc UiObject::isFocused() - */ - virtual bool isFocused() const = 0; - - /** - * @copydoc UiObject::isClickable() - */ - virtual bool isClickable() const = 0; - - /** - * @copydoc UiObject::isActive() - */ - virtual bool isActive() const = 0; - - /** - * @copydoc UiObject::isShowing() - */ - virtual bool isShowing() const = 0; -}; - -} - -#endif diff --git a/libaurum/inc/UiObject.h b/libaurum/inc/UiObject.h index 5ec7aa4..187d48e 100644 --- a/libaurum/inc/UiObject.h +++ b/libaurum/inc/UiObject.h @@ -22,7 +22,6 @@ #include "Accessible.h" #include "ISearchable.h" -#include "IObject.h" #include "UiSelector.h" #include "Waiter.h" @@ -56,7 +55,7 @@ public: * such as object's properties, states, geometry information. * also user can send and receive event via this class. */ -class UiObject : public ISearchable , public std::enable_shared_from_this, public IObject { +class UiObject : public ISearchable , public std::enable_shared_from_this { public: /** * @brief UiObject constructor with device, selector, node pointer. @@ -177,7 +176,7 @@ public: * * @since_tizen 6.5 */ - std::string getId() const override; + std::string getId() const; /** * @brief Gets object's type. @@ -186,7 +185,7 @@ public: * * @since_tizen 7.0 */ - std::string getType() const override; + std::string getType() const; /** * @brief Gets object's geometry of the screen. @@ -195,7 +194,7 @@ public: * * @since_tizen 6.5 */ - const Rect getScreenBoundingBox() const override; + const Rect getScreenBoundingBox() const; /** * @brief Gets object's ocr text. @@ -204,7 +203,7 @@ public: * * @since_tizen 7.0 */ - std::string getOcrText() const override; + std::string getOcrText() const; /** * @brief Gets object's angle of window. @@ -213,7 +212,7 @@ public: * * @since_tizen 7.5 */ - int getWindowAngle() const override; + int getWindowAngle() const; /** * @brief Gets object's angle of target device. @@ -222,7 +221,7 @@ public: * * @since_tizen 7.5 */ - int getTargetAngle() const override; + int getTargetAngle() const; /** * @brief Gets object's focusable property. @@ -231,7 +230,7 @@ public: * * @since_tizen 6.5 */ - bool isFocusable() const override; + bool isFocusable() const; /** * @brief Gets object's focused property. @@ -240,7 +239,7 @@ public: * * @since_tizen 6.5 */ - bool isFocused() const override; + bool isFocused() const; /** * @brief Gets object's clickable property. @@ -249,7 +248,7 @@ public: * * @since_tizen 6.5 */ - bool isClickable() const override; + bool isClickable() const; /** * @brief Gets object's active property. @@ -258,7 +257,7 @@ public: * * @since_tizen 6.5 */ - bool isActive() const override; + bool isActive() const; /** * @brief Gets object's showing property. @@ -267,7 +266,7 @@ public: * * @since_tizen 6.5 */ - bool isShowing() const override; + bool isShowing() const; public: /** diff --git a/libaurum/meson.build b/libaurum/meson.build index 97b50fb..05db20e 100644 --- a/libaurum/meson.build +++ b/libaurum/meson.build @@ -9,7 +9,6 @@ libaurum_install_inc = [ './inc/Waiter.h', './inc/Interface/ISearchable.h', './inc/Interface/IDevice.h', - './inc/Interface/IObject.h', './inc/A11yEvent.h', './inc/PartialMatch.h', './inc/UiScrollable.h', diff --git a/libaurum/src/UiObject.cc b/libaurum/src/UiObject.cc index d8c3cfa..8ef6b00 100644 --- a/libaurum/src/UiObject.cc +++ b/libaurum/src/UiObject.cc @@ -70,7 +70,7 @@ std::shared_ptr UiObject::getSelector() bool UiObject::hasObject(const std::shared_ptr selector) const { std::shared_ptr node = - Comparer::findObject(mDevice, selector, getAccessibleNode()); + Comparer::findObject(mDevice, selector, mNode); if (node != nullptr) { // todo : what is this node.recycle() return true; @@ -81,7 +81,7 @@ bool UiObject::hasObject(const std::shared_ptr selector) const std::shared_ptr UiObject::findObject(const std::shared_ptr selector) const { std::shared_ptr node = - Comparer::findObject(mDevice, selector, getAccessibleNode()); + Comparer::findObject(mDevice, selector, mNode); if (node) return std::make_shared(mDevice, selector, std::move(node)); else @@ -94,7 +94,7 @@ std::vector> UiObject::findObjects( std::vector> result{}; std::vector> nodes{}; - Comparer::findObjects(nodes, mDevice, selector, getAccessibleNode()); + Comparer::findObjects(nodes, mDevice, selector, mNode); for ( auto& node : nodes) { if (!node) { LOGI("Skipped! (node == nullptr)"); @@ -110,7 +110,7 @@ std::vector> UiObject::getMatches( { std::vector> result{}; - auto nodes = getAccessibleNode()->getMatches(selector, earlyReturn); + auto nodes = mNode->getMatches(selector, earlyReturn); for (auto &node : nodes) { result.push_back(std::make_shared(mDevice, selector, std::move(node))); } @@ -122,7 +122,7 @@ std::vector> UiObject::getMatchesInMatches( { std::vector> result{}; - auto nodes = getAccessibleNode()->getMatchesInMatches(firstSelector, secondSelector, earlyReturn); + auto nodes = mNode->getMatchesInMatches(firstSelector, secondSelector, earlyReturn); for (auto &node : nodes) { result.push_back(std::make_shared(mDevice, nullptr, std::move(node))); } @@ -150,18 +150,18 @@ bool UiObject::waitFor( UiObject *UiObject::getParent() const { - std::shared_ptr node = getAccessibleNode()->getParent(); + std::shared_ptr node = mNode->getParent(); if (!node) return nullptr; return new UiObject(mDevice, mSelector, std::move(node)); } int UiObject::getChildCount() const { - return getAccessibleNode()->getChildCount(); + return mNode->getChildCount(); } std::shared_ptr UiObject::getChildAt(int index) const { - auto childNode = getAccessibleNode()->getChildAt(index); + auto childNode = mNode->getChildAt(index); if (childNode) { return std::make_shared(mDevice, mSelector, childNode); } @@ -172,7 +172,7 @@ std::vector> UiObject::getChildren() const { std::vector> ret{}; - auto children = getAccessibleNode()->getChildren(); + auto children = mNode->getChildren(); for (auto &child : children) { ret.push_back(std::make_shared(mDevice, mSelector, child)); } @@ -193,178 +193,178 @@ std::shared_ptr UiObject::getDescendant() std::string UiObject::getApplicationPackage() const { - return getAccessibleNode()->getPkg(); + return mNode->getPkg(); } std::string UiObject::getId() const { - return getAccessibleNode()->getId(); + return mNode->getId(); } std::string UiObject::getAutomationId() const { - return getAccessibleNode()->getAutomationId(); + return mNode->getAutomationId(); } std::string UiObject::getType() const { - return getAccessibleNode()->getType(); + return mNode->getType(); } std::string UiObject::getElementStyle() const { - return getAccessibleNode()->getStyle(); + return mNode->getStyle(); } std::string UiObject::getText() const { - return getAccessibleNode()->getText(); + return mNode->getText(); } std::string UiObject::getRole() const { - return getAccessibleNode()->getRole(); + return mNode->getRole(); } std::string UiObject::getXPath() const { - return getAccessibleNode()->getXPath(); + return mNode->getXPath(); } const double UiObject::getMinValue() const { - return getAccessibleNode()->getMinValue(); + return mNode->getMinValue(); } const double UiObject::getMaxValue() const { - return getAccessibleNode()->getMaxValue(); + return mNode->getMaxValue(); } const double UiObject::getValue() const { - return getAccessibleNode()->getValue(); + return mNode->getValue(); } const double UiObject::getIncrement() const { - return getAccessibleNode()->getIncrement(); + return mNode->getIncrement(); } const Rect UiObject::getTextMinBoundingRect() const { - return getAccessibleNode()->getTextMinBoundingRect(); + return mNode->getTextMinBoundingRect(); } std::string UiObject::getInterface() const { - return getAccessibleNode()->getInterface(); + return mNode->getInterface(); } bool UiObject::setValue(double value) { - return getAccessibleNode()->setValue(value); + return mNode->setValue(value); } bool UiObject::setText(std::string text) { - return getAccessibleNode()->setValue(text); + return mNode->setValue(text); } std::string UiObject::getOcrText() const { - return getAccessibleNode()->getOcrText(); + return mNode->getOcrText(); } int UiObject::getWindowAngle() const { - return getAccessibleNode()->getWindowAngle(); + return mNode->getWindowAngle(); } int UiObject::getTargetAngle() const { - return getAccessibleNode()->getTargetAngle(); + return mNode->getTargetAngle(); } std::string UiObject::getToolkitName() const { - getAccessibleNode()->updateToolkitName(); - return getAccessibleNode()->getToolkitName(); + mNode->updateToolkitName(); + return mNode->getToolkitName(); } void UiObject::setOcrText(std::string text) { - getAccessibleNode()->setOcrText(text); + mNode->setOcrText(text); } bool UiObject::isCheckable() const { - return getAccessibleNode()->isCheckable(); + return mNode->isCheckable(); } bool UiObject::isChecked() const { - return getAccessibleNode()->isChecked(); + return mNode->isChecked(); } bool UiObject::isClickable() const { - return getAccessibleNode()->isClickable(); + return mNode->isClickable(); } bool UiObject::isEnabled() const { - return getAccessibleNode()->isEnabled(); + return mNode->isEnabled(); } bool UiObject::isFocusable() const { - return getAccessibleNode()->isFocusable(); + return mNode->isFocusable(); } bool UiObject::isFocused() const { - return getAccessibleNode()->isFocused(); + return mNode->isFocused(); } bool UiObject::isLongClickable() const { - return getAccessibleNode()->isLongClickable(); + return mNode->isLongClickable(); } bool UiObject::isScrollable() const { - return getAccessibleNode()->isScrollable(); + return mNode->isScrollable(); } bool UiObject::isSelectable() const { - return getAccessibleNode()->isSelectable(); + return mNode->isSelectable(); } bool UiObject::isSelected() const { - return getAccessibleNode()->isSelected(); + return mNode->isSelected(); } bool UiObject::isVisible() const { - return getAccessibleNode()->isVisible(); + return mNode->isVisible(); } bool UiObject::isShowing() const { - return getAccessibleNode()->isShowing(); + return mNode->isShowing(); } bool UiObject::isActive() const { - return getAccessibleNode()->isActive(); + return mNode->isActive(); } bool UiObject::isHighlightable() const { - return getAccessibleNode()->isHighlightable(); + return mNode->isHighlightable(); } void UiObject::refresh() const @@ -452,19 +452,22 @@ const Rect UiObject::getWindowBoundingBox() const return mNode->getWindowBoundingBox(); } +const Point2D getMidPoint(std::shared_ptr node) +{ + node->updateExtents(); + const Rect rect = node->getScreenBoundingBox(); + return rect.midPoint(); +} + void UiObject::click() const { - mNode->updateExtents(); - const Rect rect = mNode->getScreenBoundingBox(); - const Point2D midPoint = rect.midPoint(); + const Point2D midPoint = getMidPoint(mNode); mDevice->click(midPoint.x, midPoint.y); } void UiObject::longClick(const unsigned int durationMs) const { - mNode->updateExtents(); - const Rect rect = mNode->getScreenBoundingBox(); - const Point2D midPoint = rect.midPoint(); + const Point2D midPoint = getMidPoint(mNode); mDevice->click(midPoint.x, midPoint.y, durationMs); }