5 Comparer::Comparer(const UiDevice *device, const UiSelector *selector,
6 const bool &earlyReturn)
7 : mDevice(device), mSelector(selector), mEarlyReturn(earlyReturn)
11 Comparer::~Comparer() {}
13 AccessibleNode *Comparer::findObject(const UiDevice * device,
14 const UiSelector * selector,
15 const AccessibleNode *root)
17 Comparer comparer(device, selector, true);
18 std::vector<AccessibleNode *> ret = comparer.findObjects(root);
25 std::vector<AccessibleNode *> Comparer::findObjects(const UiDevice * device,
26 const UiSelector *selector,
27 const AccessibleNode *root)
29 Comparer comparer(device, selector, false);
30 std::vector<AccessibleNode *> ret = comparer.findObjects(root);
31 return std::move(ret);
34 std::vector<AccessibleNode *> Comparer::findObjects(const AccessibleNode *root)
36 std::list<std::shared_ptr<PartialMatch>> partialList{};
37 std::vector<AccessibleNode *> ret = findObjects(root, 0, 0, partialList);
38 return std::move(ret);
41 std::vector<AccessibleNode *> Comparer::findObjects(
42 const AccessibleNode *root, const int &index, const int &depth,
43 std::list<std::shared_ptr<PartialMatch>> &partialMatches)
45 std::vector<AccessibleNode *> ret;
48 // LOG_F(INFO, "%p %s / i:%d d:%d", root, root->getText().c_str(), index,
51 for (auto match : partialMatches)
52 match->update(root, index, depth, partialMatches);
54 std::shared_ptr<PartialMatch> currentMatch =
55 PartialMatch::accept(root, mSelector, index, depth);
56 if (currentMatch) partialMatches.push_front(currentMatch);
58 int childCnt = root->getChildCount();
59 for (int i = 0; i < childCnt; i++) {
60 AccessibleNode * childNode = root->getChildAt(i);
61 std::vector<AccessibleNode *> childret =
62 findObjects(childNode, i, depth + 1, partialMatches);
63 ret.insert(ret.end(), childret.begin(), childret.end());
65 if (!ret.empty() && mEarlyReturn) return ret;
68 if (currentMatch && currentMatch->finalizeMatch())
69 ret.push_back(const_cast<AccessibleNode *>(root));