1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3e0dac50fSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4e0dac50fSopenharmony_ci * you may not use this file except in compliance with the License.
5e0dac50fSopenharmony_ci * You may obtain a copy of the License at
6e0dac50fSopenharmony_ci *
7e0dac50fSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8e0dac50fSopenharmony_ci *
9e0dac50fSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10e0dac50fSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11e0dac50fSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12e0dac50fSopenharmony_ci * See the License for the specific language governing permissions and
13e0dac50fSopenharmony_ci * limitations under the License.
14e0dac50fSopenharmony_ci */
15e0dac50fSopenharmony_ci
16e0dac50fSopenharmony_ci#ifndef OHOS_ROSEN_AVOID_AREA_CONTROLLER_H
17e0dac50fSopenharmony_ci#define OHOS_ROSEN_AVOID_AREA_CONTROLLER_H
18e0dac50fSopenharmony_ci
19e0dac50fSopenharmony_ci#include <map>
20e0dac50fSopenharmony_ci#include <set>
21e0dac50fSopenharmony_ci#include <unordered_map>
22e0dac50fSopenharmony_ci#include <vector>
23e0dac50fSopenharmony_ci
24e0dac50fSopenharmony_ci#include <refbase.h>
25e0dac50fSopenharmony_ci
26e0dac50fSopenharmony_ci#include "class_var_definition.h"
27e0dac50fSopenharmony_ci#include "window_node.h"
28e0dac50fSopenharmony_ci#include "wm_common.h"
29e0dac50fSopenharmony_ci#include "wm_common_inner.h"
30e0dac50fSopenharmony_ci
31e0dac50fSopenharmony_cinamespace OHOS {
32e0dac50fSopenharmony_cinamespace Rosen {
33e0dac50fSopenharmony_cienum class AvoidControlType : uint32_t {
34e0dac50fSopenharmony_ci    AVOID_NODE_ADD,
35e0dac50fSopenharmony_ci    AVOID_NODE_UPDATE,
36e0dac50fSopenharmony_ci    AVOID_NODE_REMOVE,
37e0dac50fSopenharmony_ci    AVOID_NODE_UNKNOWN,
38e0dac50fSopenharmony_ci};
39e0dac50fSopenharmony_ci
40e0dac50fSopenharmony_ciclass AvoidAreaController : public RefBase {
41e0dac50fSopenharmony_cipublic:
42e0dac50fSopenharmony_ci    explicit AvoidAreaController(uint32_t& focusedWindow) : focusedWindow_(focusedWindow) {};
43e0dac50fSopenharmony_ci    ~AvoidAreaController() = default;
44e0dac50fSopenharmony_ci
45e0dac50fSopenharmony_ci    void UpdateAvoidAreaListener(sptr<WindowNode>& windowNode, bool isRegisterListener);
46e0dac50fSopenharmony_ci    void ProcessWindowChange(const sptr<WindowNode>& windowNode, AvoidControlType avoidType,
47e0dac50fSopenharmony_ci        const std::function<bool(sptr<WindowNode>)>& checkFunc);
48e0dac50fSopenharmony_ci    AvoidArea GetAvoidAreaByType(const sptr<WindowNode>& node, AvoidAreaType avoidAreaType) const;
49e0dac50fSopenharmony_ci
50e0dac50fSopenharmony_ciprivate:
51e0dac50fSopenharmony_ci    void AddOrRemoveOverlayWindowIfNeed(const sptr<WindowNode>& overlayNode, bool isAdding);
52e0dac50fSopenharmony_ci    void AddOrRemoveKeyboard(const sptr<WindowNode>& keyboardNode, bool isAdding);
53e0dac50fSopenharmony_ci    void UpdateOverlayWindowIfNeed(const sptr<WindowNode>& node,
54e0dac50fSopenharmony_ci        const std::function<bool(sptr<WindowNode>)>& checkFunc);
55e0dac50fSopenharmony_ci    AvoidPosType CalculateOverlayRect(const sptr<WindowNode>& node,
56e0dac50fSopenharmony_ci        const sptr<WindowNode>& overlayNode, Rect& overlayRect) const;
57e0dac50fSopenharmony_ci    AvoidPosType GetAvoidPosType(const Rect& windowRect, const Rect& overlayRect) const;
58e0dac50fSopenharmony_ci    void SetAvoidAreaRect(AvoidArea& avoidArea, const Rect& rect, AvoidPosType type) const;
59e0dac50fSopenharmony_ci    bool UpdateAvoidAreaIfNeed(const AvoidArea& avoidArea, const sptr<WindowNode>& node, AvoidAreaType avoidAreaType);
60e0dac50fSopenharmony_ci    AvoidArea GetAvoidAreaSystemType(const sptr<WindowNode>& node) const;
61e0dac50fSopenharmony_ci    AvoidArea GetAvoidAreaKeyboardType(const sptr<WindowNode>& node) const;
62e0dac50fSopenharmony_ci
63e0dac50fSopenharmony_ci    uint32_t& focusedWindow_;
64e0dac50fSopenharmony_ci    std::unordered_map<uint32_t, sptr<WindowNode>> overlayWindowMap_;
65e0dac50fSopenharmony_ci    std::set<sptr<WindowNode>> avoidAreaListenerNodes_;
66e0dac50fSopenharmony_ci    std::map<uint32_t, std::map<AvoidAreaType, AvoidArea>> lastUpdatedAvoidArea_;
67e0dac50fSopenharmony_ci    uint32_t lastSoftInputKeyboardAreaUpdatedWindowId_ { 0 };
68e0dac50fSopenharmony_ci    DEFINE_VAR_DEFAULT_FUNC_SET(bool, FlagForProcessWindowChange, isForbidProcessingWindowChange, false)
69e0dac50fSopenharmony_ci};
70e0dac50fSopenharmony_ci}
71e0dac50fSopenharmony_ci}
72e0dac50fSopenharmony_ci#endif // OHOS_ROSEN_AVOID_AREA_CONTROLLER_H
73