• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef SELECT_STRATEGY_H
17 #define SELECT_STRATEGY_H
18 
19 #include "ui_model.h"
20 #include "element_node_iterator.h"
21 
22 namespace OHOS::uitest {
23     enum class StrategyEnum {
24         PLAIN,
25         WITH_IN,
26         IS_AFTER,
27         IS_BEFORE,
28         COMPLEX,
29     };
30 
31     struct StrategyBuildParam {
32         std::vector<WidgetMatchModel> myselfMatcher;
33         std::vector<std::vector<WidgetMatchModel>> afterAnchorMatcherVec;
34         std::vector<std::vector<WidgetMatchModel>> beforeAnchorMatcherVec;
35         std::vector<std::vector<WidgetMatchModel>> withInAnchorMatcherVec;
36     };
37 
38     class SelectStrategy {
39     public:
40         SelectStrategy() = default;
41         static unique_ptr<SelectStrategy> BuildSelectStrategy(const StrategyBuildParam &buildParam, bool isWantMulti);
42         virtual void SetAndCalcSelectWindowRect(const Rect &windowBounds, const std::vector<Rect> &windowBoundsVec);
43         virtual std::string Describe() const;
44         virtual void RegisterAnchorMatch(const WidgetMatchModel &matchModel);
45         virtual void RegisterMyselfMatch(const WidgetMatchModel &matchModel);
46         virtual void SetWantMulti(bool isWantMulti);
47         virtual StrategyEnum GetStrategyType() const = 0;
48         virtual void LocateNode(const Window &window, ElementNodeIterator &elementNodeRef,
49             vector<Widget> &visitWidgets, vector<int> &targetWidgets, bool isSkipInvisible = true) = 0;
50         virtual ~SelectStrategy();
51 
52     protected:
53         virtual void RefreshWidgetBounds(const Rect &containerParentRect, Widget &widget);
54         virtual void CalcWidgetVisibleBounds(const Widget &widget, const Rect &containerParentRect, Rect &visibleRect);
55         std::vector<WidgetMatchModel> anchorMatch_;
56         std::vector<WidgetMatchModel> myselfMatch_;
57         bool wantMulti_ = false;
58         Rect windowBounds_{0, 0, 0, 0};
59         std::vector<Rect> overplayWindowBoundsVec_;
60     };
61 } // namespace OHOS::uitest
62 
63 #endif