• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 OHOS_ROSEN_AVOID_AREA_CONTROLLER_H
17 #define OHOS_ROSEN_AVOID_AREA_CONTROLLER_H
18 
19 #include <map>
20 #include <set>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include <refbase.h>
25 
26 #include "class_var_definition.h"
27 #include "window_node.h"
28 #include "wm_common.h"
29 #include "wm_common_inner.h"
30 
31 namespace OHOS {
32 namespace Rosen {
33 enum class AvoidControlType : uint32_t {
34     AVOID_NODE_ADD,
35     AVOID_NODE_UPDATE,
36     AVOID_NODE_REMOVE,
37     AVOID_NODE_UNKNOWN,
38 };
39 
40 class AvoidAreaController : public RefBase {
41 public:
AvoidAreaController(uint32_t & focusedWindow)42     explicit AvoidAreaController(uint32_t& focusedWindow) : focusedWindow_(focusedWindow) {};
43     ~AvoidAreaController() = default;
44 
45     void UpdateAvoidAreaListener(sptr<WindowNode>& windowNode, bool isRegisterListener);
46     void ProcessWindowChange(const sptr<WindowNode>& windowNode, AvoidControlType avoidType,
47         const std::function<bool(sptr<WindowNode>)>& checkFunc);
48     AvoidArea GetAvoidAreaByType(const sptr<WindowNode>& node, AvoidAreaType avoidAreaType) const;
49 
50 private:
51     void AddOrRemoveOverlayWindowIfNeed(const sptr<WindowNode>& overlayNode, bool isAdding);
52     void AddOrRemoveKeyboard(const sptr<WindowNode>& keyboardNode, bool isAdding);
53     void UpdateOverlayWindowIfNeed(const sptr<WindowNode>& node,
54         const std::function<bool(sptr<WindowNode>)>& checkFunc);
55     AvoidPosType CalculateOverlayRect(const sptr<WindowNode>& node,
56         const sptr<WindowNode>& overlayNode, Rect& overlayRect) const;
57     AvoidPosType GetAvoidPosType(const Rect& windowRect, const Rect& overlayRect) const;
58     void SetAvoidAreaRect(AvoidArea& avoidArea, const Rect& rect, AvoidPosType type) const;
59     bool UpdateAvoidAreaIfNeed(const AvoidArea& avoidArea, const sptr<WindowNode>& node, AvoidAreaType avoidAreaType);
60     AvoidArea GetAvoidAreaSystemType(const sptr<WindowNode>& node) const;
61     AvoidArea GetAvoidAreaKeyboardType(const sptr<WindowNode>& node) const;
62 
63     uint32_t& focusedWindow_;
64     std::unordered_map<uint32_t, sptr<WindowNode>> overlayWindowMap_;
65     std::set<sptr<WindowNode>> avoidAreaListenerNodes_;
66     std::map<uint32_t, std::map<AvoidAreaType, AvoidArea>> lastUpdatedAvoidArea_;
67     uint32_t lastSoftInputKeyboardAreaUpdatedWindowId_ { 0 };
68     DEFINE_VAR_DEFAULT_FUNC_SET(bool, FlagForProcessWindowChange, isForbidProcessingWindowChange, false)
69 };
70 }
71 }
72 #endif // OHOS_ROSEN_AVOID_AREA_CONTROLLER_H
73