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->mType->c_str());
32 if (mSelector->mStyle)
33 LOG_F(INFO, "selector->pkg :%s", mSelector->mStyle->c_str());
36 bool PartialMatch::checkCriteria(const std::shared_ptr<UiSelector> selector,
37 const std::shared_ptr<AccessibleNode> node)
39 if(checkCriteria(selector->mPkg.get(), node->getPkg())) return false;
40 if(checkCriteria(selector->mRes.get(), node->getRes())) return false;
41 if(checkCriteria(selector->mText.get(), node->getText())) return false;
42 if(checkCriteria(selector->mType.get(), node->getType())) return false;
43 if(checkCriteria(selector->mStyle.get(), node->getStyle())) return false;
44 if(checkCriteria(selector->mStyle.get(), node->getStyle())) return false;
46 if(checkCriteria(selector->mIschecked.get(), node->isChecked())) return false;
47 if(checkCriteria(selector->mIscheckable.get(), node->isCheckable())) return false;
48 if(checkCriteria(selector->mIsclickable.get(), node->isClickable())) return false;
49 if(checkCriteria(selector->mIsenabled.get(), node->isEnabled())) return false;
50 if(checkCriteria(selector->mIsfocused.get(), node->isFocused())) return false;
51 if(checkCriteria(selector->mIsfocusable.get(), node->isFocusable())) return false;
52 if(checkCriteria(selector->mIsscrollable.get(), node->isScrollable())) return false;
53 if(checkCriteria(selector->mIsselected.get(), node->isSelected())) return false;
54 if(checkCriteria(selector->mIsshowing.get(), node->isShowing())) return false;
55 if(checkCriteria(selector->mIsactive.get(), node->isActive())) return false;
60 PartialMatch::PartialMatch() : mSelector{nullptr}, mDepth{-1}, mPartialMatches{}
64 PartialMatch::PartialMatch(const std::shared_ptr<UiSelector> selector, const int absDepth)
65 : mSelector{selector}, mDepth{absDepth}, mPartialMatches{}
69 std::shared_ptr<PartialMatch> PartialMatch::accept(const std::shared_ptr<AccessibleNode> node,
70 const std::shared_ptr<UiSelector> selector,
73 return PartialMatch::accept(node, selector, index, depth, depth);
76 std::shared_ptr<PartialMatch> PartialMatch::accept(const std::shared_ptr<AccessibleNode> node,
77 const std::shared_ptr<UiSelector> selector,
78 int index, int absoluteDepth,
81 LOG_SCOPE_F(INFO, "accept checking i:%d a:%d r:%d / %d < %d < %d", index, absoluteDepth, relativeDepth, selector->mMinDepth?*(selector->mMinDepth):-1, relativeDepth, selector->mMaxDepth?*(selector->mMaxDepth):9999999);
82 PartialMatch *match = nullptr;
84 if ((selector->mMinDepth && (relativeDepth < *(selector->mMinDepth))) ||
85 (selector->mMaxDepth && (relativeDepth > *(selector->mMaxDepth)))) {
86 LOG_F(INFO, "depth limit overflow %d < %d < %d", selector->mMinDepth?*(selector->mMinDepth):-1, relativeDepth, selector->mMaxDepth?*(selector->mMaxDepth):9999999);
87 return std::shared_ptr<PartialMatch>(nullptr);
90 if (PartialMatch::checkCriteria(selector, node)) {
91 LOG_F(INFO, "New Match found %p %d", selector, absoluteDepth);
92 match = new PartialMatch(selector, absoluteDepth);
95 return std::shared_ptr<PartialMatch>(match);
98 void PartialMatch::update(
99 const std::shared_ptr<AccessibleNode> node, int index, int depth,
100 std::list<std::shared_ptr<PartialMatch>> &partialMatches)
102 for (auto &childSelector : mSelector->mChild) {
103 auto match = PartialMatch::accept(node, childSelector, index, depth,
106 mPartialMatches.push_back(match);
107 partialMatches.push_front(match);
112 bool PartialMatch::finalizeMatch()
114 std::set<std::shared_ptr<UiSelector>> matches;
115 for (auto &match : mPartialMatches) {
116 if (match->finalizeMatch()) {
117 matches.insert(match->mSelector);
121 for (auto &sel : mSelector->mChild) {
122 if (!matches.count(sel)) return false;