1e0dac50fSopenharmony_ci/*
2e0dac50fSopenharmony_ci * Copyright (c) 2022-2024 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#ifndef OHOS_JS_WINDOW_REGISTER_MANAGER_H
16e0dac50fSopenharmony_ci#define OHOS_JS_WINDOW_REGISTER_MANAGER_H
17e0dac50fSopenharmony_ci#include <map>
18e0dac50fSopenharmony_ci#include <mutex>
19e0dac50fSopenharmony_ci#include "js_window_listener.h"
20e0dac50fSopenharmony_ci#include "native_engine/native_engine.h"
21e0dac50fSopenharmony_ci#include "native_engine/native_reference.h"
22e0dac50fSopenharmony_ci#include "native_engine/native_value.h"
23e0dac50fSopenharmony_ci#include "refbase.h"
24e0dac50fSopenharmony_ci#include "window.h"
25e0dac50fSopenharmony_cinamespace OHOS {
26e0dac50fSopenharmony_cinamespace Rosen {
27e0dac50fSopenharmony_cienum class CaseType {
28e0dac50fSopenharmony_ci    CASE_WINDOW_MANAGER = 0,
29e0dac50fSopenharmony_ci    CASE_WINDOW,
30e0dac50fSopenharmony_ci    CASE_STAGE
31e0dac50fSopenharmony_ci};
32e0dac50fSopenharmony_ci
33e0dac50fSopenharmony_cienum class ListenerFunctionType : uint32_t {
34e0dac50fSopenharmony_ci    SYSTEM_AVOID_AREA_CHANGE_CB,
35e0dac50fSopenharmony_ci    AVOID_AREA_CHANGE_CB,
36e0dac50fSopenharmony_ci};
37e0dac50fSopenharmony_ci
38e0dac50fSopenharmony_ciclass JsWindowRegisterManager {
39e0dac50fSopenharmony_cipublic:
40e0dac50fSopenharmony_ci    JsWindowRegisterManager();
41e0dac50fSopenharmony_ci    ~JsWindowRegisterManager();
42e0dac50fSopenharmony_ci    WmErrorCode RegisterListener(sptr<Window> window, std::string type,
43e0dac50fSopenharmony_ci        CaseType caseType, napi_env env, napi_value callback, napi_value parameter = nullptr);
44e0dac50fSopenharmony_ci    WmErrorCode UnregisterListener(sptr<Window> window, std::string type,
45e0dac50fSopenharmony_ci        CaseType caseType, napi_env env, napi_value value);
46e0dac50fSopenharmony_ci
47e0dac50fSopenharmony_ciprivate:
48e0dac50fSopenharmony_ci    bool IsCallbackRegistered(napi_env env, std::string& type, napi_value jsListenerObject);
49e0dac50fSopenharmony_ci    WmErrorCode ProcessSystemAvoidAreaChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window,
50e0dac50fSopenharmony_ci        bool isRegister, napi_env env, napi_value parameter = nullptr);
51e0dac50fSopenharmony_ci    WmErrorCode ProcessAvoidAreaChangeRegister(sptr<JsWindowListener> listener, sptr<Window> window, bool isRegister,
52e0dac50fSopenharmony_ci        napi_env env, napi_value parameter = nullptr);
53e0dac50fSopenharmony_ci    WmErrorCode ProcessRegisterCallback(ListenerFunctionType listenerFunctionType, CaseType caseType,
54e0dac50fSopenharmony_ci        const sptr<JsWindowListener>& listener, const sptr<Window>& window, bool isRegister, napi_env env,
55e0dac50fSopenharmony_ci        napi_value parameter);
56e0dac50fSopenharmony_ci    std::map<std::string, std::map<std::shared_ptr<NativeReference>, sptr<JsWindowListener>>> jsCbMap_;
57e0dac50fSopenharmony_ci    std::mutex mtx_;
58e0dac50fSopenharmony_ci};
59e0dac50fSopenharmony_ci} // namespace Rosen
60e0dac50fSopenharmony_ci} // namespace OHOS
61e0dac50fSopenharmony_ci#endif // OHOS_JS_WINDOW_REGISTER_MANAGER_H