1 /*
2  * Copyright (c) 2024 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 WINDOW_LISTENER_H
17 #define WINDOW_LISTENER_H
18 
19 #include "event_handler.h"
20 #include "refbase.h"
21 #include "window.h"
22 #include "window_manager.h"
23 #include "window_utils.h"
24 #include "wm_common.h"
25 
26 namespace OHOS {
27 namespace Rosen {
28 constexpr int64_t NONE_CALLBACK_OBJECT = -1;
29 const std::string WINDOW_SIZE_CHANGE_CB = "windowSizeChange";
30 const std::string SYSTEM_BAR_TINT_CHANGE_CB = "systemBarTintChange";
31 const std::string SYSTEM_AVOID_AREA_CHANGE_CB = "systemAvoidAreaChange";
32 const std::string AVOID_AREA_CHANGE_CB = "avoidAreaChange";
33 const std::string LIFECYCLE_EVENT_CB = "lifeCycleEvent";
34 const std::string WINDOW_STAGE_EVENT_CB = "windowStageEvent";
35 const std::string WINDOW_EVENT_CB = "windowEvent";
36 const std::string KEYBOARD_HEIGHT_CHANGE_CB = "keyboardHeightChange";
37 const std::string TOUCH_OUTSIDE_CB = "touchOutside";
38 const std::string SCREENSHOT_EVENT_CB = "screenshot";
39 const std::string DIALOG_TARGET_TOUCH_CB = "dialogTargetTouch";
40 const std::string DIALOG_DEATH_RECIPIENT_CB = "dialogDeathRecipient";
41 const std::string GESTURE_NAVIGATION_ENABLED_CHANGE_CB = "gestureNavigationEnabledChange";
42 const std::string WATER_MARK_FLAG_CHANGE_CB = "waterMarkFlagChange";
43 const std::string WINDOW_VISIBILITY_CHANGE_CB = "windowVisibilityChange";
44 const std::string WINDOW_DISPLAYID_CHANGE_CB = "displayIdChange";
45 const std::string WINDOW_STATUS_CHANGE_CB = "windowStatusChange";
46 const std::string WINDOW_TITLE_BUTTON_RECT_CHANGE_CB = "windowTitleButtonRectChange";
47 
48 class CjWindowListener : public IWindowChangeListener,
49                          public ISystemBarChangedListener,
50                          public IAvoidAreaChangedListener,
51                          public IWindowLifeCycle,
52                          public IOccupiedAreaChangeListener,
53                          public ITouchOutsideListener,
54                          public IScreenshotListener,
55                          public IDialogTargetTouchListener,
56                          public IDialogDeathRecipientListener,
57                          public IWaterMarkFlagChangedListener,
58                          public IGestureNavigationEnabledChangedListener,
59                          public IDisplayIdChangeListener,
60                          public IWindowVisibilityChangedListener,
61                          public IWindowTitleButtonRectChangedListener,
62                          public IWindowStatusChangeListener {
63 public:
64     explicit CjWindowListener(int64_t callbackObject);
65     ~CjWindowListener() override;
66     void CallCjMethod(const char* methodName, void* argv, size_t argc);
67     void SetMainEventHandler();
68     void OnSystemBarPropertyChange(DisplayId displayId,
69         const SystemBarRegionTints& tints) override;
70     void OnSizeChange(Rect rect, WindowSizeChangeReason reason,
71         const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override;
72     void OnModeChange(WindowMode mode, bool hasDeco) override;
73     void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) override;
74     void AfterForeground() override;
75     void AfterBackground() override;
76     void AfterFocused() override;
77     void AfterUnfocused() override;
78     void AfterResumed() override;
79     void AfterPaused() override;
80     void AfterDestroyed() override;
81     void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info,
82         const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override;
83     void OnTouchOutside() const override;
84     void OnScreenshot() override;
85     void OnDialogTargetTouch() const override;
86     void OnDialogDeathRecipient() const override;
87     void OnGestureNavigationEnabledUpdate(bool enable) override;
88     void OnWaterMarkFlagUpdate(bool showWaterMark) override;
89     void OnWindowVisibilityChangedCallback(const bool isVisible) override;
90     void OnWindowStatusChange(WindowStatus status) override;
91     void OnWindowTitleButtonRectChanged(const TitleButtonRect& titleButtonRect) override;
92 private:
93     std::function<void(void*)> cjCallBack_;
94     wptr<CjWindowListener> weakRef_ = nullptr;
95     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
96 };
97 }
98 }
99 #endif
100