5 Comparer::Comparer(const std::shared_ptr<UiDevice> device, const std::shared_ptr<UiSelector> selector,
6 const bool &earlyReturn)
7 : mDevice(device), mSelector(selector), mEarlyReturn(earlyReturn)
11 Comparer::~Comparer() {}
13 std::shared_ptr<AccessibleNode> Comparer::findObject(const std::shared_ptr<UiDevice> device,
14 const std::shared_ptr<UiSelector> selector,
15 const std::shared_ptr<AccessibleNode> root)
17 Comparer comparer(device, selector, true);
18 std::vector<std::shared_ptr<AccessibleNode>> ret = comparer.findObjects(root);
20 return std::move(ret[0]);
25 std::vector<std::shared_ptr<AccessibleNode>> Comparer::findObjects(const std::shared_ptr<UiDevice> device,
26 const std::shared_ptr<UiSelector> selector,
27 const std::shared_ptr<AccessibleNode> root)
29 Comparer comparer(device, selector, false);
30 std::vector<std::shared_ptr<AccessibleNode>> ret = comparer.findObjects(root);
34 std::vector<std::shared_ptr<AccessibleNode>> Comparer::findObjects(const std::shared_ptr<AccessibleNode> root)
36 std::list<std::shared_ptr<PartialMatch>> partialList{};
37 std::vector<std::shared_ptr<AccessibleNode>> ret = findObjects(root, 0, 0, partialList);
41 std::vector<std::shared_ptr<AccessibleNode>> Comparer::findObjects(
42 const std::shared_ptr<AccessibleNode> root, const int &index, const int &depth,
43 std::list<std::shared_ptr<PartialMatch>> &partialMatches)
45 std::vector<std::shared_ptr<AccessibleNode>> ret;
47 LOG_SCOPE_F(INFO, "findObjects %s, %s, %s / i:%d d:%d / p.matches:%d", root->getText().c_str(), root->getType().c_str(), root->getStyle().c_str(), index, depth, partialMatches.size());
49 for (auto &match : partialMatches)
50 match->update(root, index, depth, partialMatches);
52 std::shared_ptr<PartialMatch> currentMatch =
53 PartialMatch::accept(root, mSelector, index, depth);
54 if (currentMatch) partialMatches.push_front(currentMatch);
56 if (!(mSelector->mMaxDepth && (depth+1 > *(mSelector->mMaxDepth)))) {
57 int childCnt = root->getChildCount();
58 for (int i = 0; i < childCnt; i++) {
59 std::shared_ptr<AccessibleNode> childNode = root->getChildAt(i);
60 if (childNode == nullptr) continue;
62 std::vector<std::shared_ptr<AccessibleNode>> childret =
63 findObjects(childNode, i, depth + 1, partialMatches);
64 std::move(std::begin(childret), std::end(childret), std::back_inserter(ret));
66 if (!ret.empty() && mEarlyReturn) return ret;
69 LOG_F(INFO, "no need to search children(maxDepth limit overflow, %d < %d < %d)", mSelector->mMinDepth?*(mSelector->mMinDepth):-1, depth, mSelector->mMaxDepth?*(mSelector->mMaxDepth):9999999);
72 if (currentMatch && currentMatch->finalizeMatch()){
73 LOG_F(INFO, "child 3 %p(raw:%p)", root.get(), root->getRawHandler());