1 #include "PartialMatch.h"
9 bool PartialMatch::checkCriteria(const std::string *textA, const std::string textB)
11 if (!textA) return false;
12 std::regex re(*textA);
13 return !std::regex_match(textB, re);
16 bool PartialMatch::checkCriteria(const bool *boolA, const bool boolB)
18 if (!boolA) return false;
19 return *boolA != boolB;
22 void PartialMatch::debugPrint()
25 LOG_F(INFO, "selector->pkg :%s", mSelector->mPkg->c_str());
27 LOG_F(INFO, "selector->pkg :%s", mSelector->mRes->c_str());
29 LOG_F(INFO, "selector->pkg :%s", mSelector->mText->c_str());
31 LOG_F(INFO, "selector->pkg :%s", mSelector->mDesc->c_str());
33 LOG_F(INFO, "selector->pkg :%s", mSelector->mType->c_str());
34 if (mSelector->mStyle)
35 LOG_F(INFO, "selector->pkg :%s", mSelector->mStyle->c_str());
38 bool PartialMatch::checkCriteria(const std::shared_ptr<UiSelector> selector,
39 const AccessibleNode *node)
41 if(checkCriteria(selector->mPkg.get(), node->getPkg())) return false;
42 if(checkCriteria(selector->mRes.get(), node->getRes())) return false;
43 if(checkCriteria(selector->mText.get(), node->getText())) return false;
44 if(checkCriteria(selector->mDesc.get(), node->getDesc())) return false;
45 if(checkCriteria(selector->mType.get(), node->getType())) return false;
46 if(checkCriteria(selector->mStyle.get(), node->getStyle())) return false;
47 if(checkCriteria(selector->mStyle.get(), node->getStyle())) return false;
49 if(checkCriteria(selector->mIschecked.get(), node->isChecked())) return false;
50 if(checkCriteria(selector->mIscheckable.get(), node->isCheckable())) return false;
51 if(checkCriteria(selector->mIsclickable.get(), node->isClickable())) return false;
52 if(checkCriteria(selector->mIsenabled.get(), node->isEnabled())) return false;
53 if(checkCriteria(selector->mIsfocused.get(), node->isFocused())) return false;
54 if(checkCriteria(selector->mIsfocusable.get(), node->isFocusable())) return false;
55 if(checkCriteria(selector->mIsscrollable.get(), node->isScrollable())) return false;
56 if(checkCriteria(selector->mIsselected.get(), node->isSelected())) return false;
57 if(checkCriteria(selector->mIsshowing.get(), node->isShowing())) return false;
58 if(checkCriteria(selector->mIsactive.get(), node->isActive())) return false;
63 PartialMatch::PartialMatch() : mSelector{nullptr}, mDepth{-1}, mPartialMatches{}
67 PartialMatch::PartialMatch(const std::shared_ptr<UiSelector> selector, const int absDepth)
68 : mSelector{selector}, mDepth{absDepth}, mPartialMatches{}
72 std::shared_ptr<PartialMatch> PartialMatch::accept(const AccessibleNode *node,
73 const std::shared_ptr<UiSelector> selector,
76 return PartialMatch::accept(node, selector, index, depth, depth);
79 std::shared_ptr<PartialMatch> PartialMatch::accept(const AccessibleNode *node,
80 const std::shared_ptr<UiSelector> selector,
81 int index, int absoluteDepth,
84 PartialMatch *match = nullptr;
86 if (PartialMatch::checkCriteria(selector, node)) {
87 LOG_SCOPE_F(INFO, "New Match found %p %d", selector, absoluteDepth);
88 match = new PartialMatch(selector, absoluteDepth);
91 return std::shared_ptr<PartialMatch>(match);
94 void PartialMatch::update(
95 const AccessibleNode *node, int index, int depth,
96 std::list<std::shared_ptr<PartialMatch>> &partialMatches)
98 for (auto childSelector : mSelector->mChild) {
99 auto match = PartialMatch::accept(node, childSelector, index, depth,
102 mPartialMatches.push_back(match);
103 partialMatches.push_front(match);
108 bool PartialMatch::finalizeMatch()
110 std::set<std::shared_ptr<UiSelector>> matches;
111 for (auto match : mPartialMatches) {
112 if (match->finalizeMatch()) {
113 matches.insert(match->mSelector);
117 for (auto sel : mSelector->mChild) {
118 if (!matches.count(sel)) return false;