• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_STATUS_CHANGE_CB = "windowStatusChange";
45 const std::string WINDOW_TITLE_BUTTON_RECT_CHANGE_CB = "windowTitleButtonRectChange";
46 const std::string WINDOW_NO_INTERACTION_DETECTED_CB = "noInteractionDetected";
47 const std::string WINDOW_RECT_CHANGE_CB = "windowRectChange";
48 const std::string WINDOW_SUB_WINDOW_CLOSE_CB = "subWindowClose";
49 const std::string WINDOW_STAGE_CLOSE_CB = "windowStageClose";
50 
51 class CjWindowListener : public IWindowChangeListener,
52                          public ISystemBarChangedListener,
53                          public IAvoidAreaChangedListener,
54                          public IWindowLifeCycle,
55                          public IOccupiedAreaChangeListener,
56                          public ITouchOutsideListener,
57                          public IScreenshotListener,
58                          public IDialogTargetTouchListener,
59                          public IDialogDeathRecipientListener,
60                          public IWaterMarkFlagChangedListener,
61                          public IGestureNavigationEnabledChangedListener,
62                          public IWindowVisibilityChangedListener,
63                          public IWindowTitleButtonRectChangedListener,
64                          public IWindowStatusChangeListener,
65                          public IWindowRectChangeListener,
66                          public ISubWindowCloseListener,
67                          public IMainWindowCloseListener,
68                          public IWindowNoInteractionListener {
69 public:
70     CjWindowListener(int64_t callbackObject, CaseType caseType);
71     ~CjWindowListener() override;
72     void CallCjMethod(const char* methodName, void* argv);
73     void SetMainEventHandler();
74     void OnSystemBarPropertyChange(DisplayId displayId,
75         const SystemBarRegionTints& tints) override;
76     void OnSizeChange(Rect rect, WindowSizeChangeReason reason,
77         const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override;
78     void OnModeChange(WindowMode mode, bool hasDeco) override;
79     void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type,
80         const sptr<OccupiedAreaChangeInfo>& info = nullptr) override;
81     void AfterForeground() override;
82     void AfterBackground() override;
83     void AfterFocused() override;
84     void AfterUnfocused() override;
85     void AfterResumed() override;
86     void AfterPaused() override;
87     void AfterDestroyed() override;
88     void OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info,
89         const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override;
90     void OnTouchOutside() const override;
91     void OnScreenshot() override;
92     void OnDialogTargetTouch() const override;
93     void OnDialogDeathRecipient() const override;
94     void OnGestureNavigationEnabledUpdate(bool enable) override;
95     void OnWaterMarkFlagUpdate(bool showWaterMark) override;
96     void OnWindowVisibilityChangedCallback(const bool isVisible) override;
97     void OnWindowStatusChange(WindowStatus status) override;
98     void OnWindowTitleButtonRectChanged(const TitleButtonRect& titleButtonRect) override;
99     void SetTimeout(int64_t timeout) override;
100     int64_t GetTimeout() const override;
101     void OnWindowNoInteractionCallback() override;
102     void OnRectChange(Rect rect, WindowSizeChangeReason reason) override;
103     void OnMainWindowClose(bool& terminateCloseProcess) override;
104     void OnSubWindowClose(bool& terminateCloseProcess) override;
105 
106 private:
107     void LifeCycleCallBack(LifeCycleEventType eventType);
108     std::function<void(void*)> cjCallBack_;
109     wptr<CjWindowListener> weakRef_ = nullptr;
110     std::shared_ptr<AppExecFwk::EventHandler> eventHandler_ = nullptr;
111     CaseType caseType_ = CaseType::CASE_WINDOW;
112     WindowState state_ {WindowState::STATE_INITIAL};
113     Rect currRect_ = {0, 0, 0, 0};
114     int64_t noInteractionTimeout_ = 0;
115     RectChangeReason currentReason_ = RectChangeReason::UNDEFINED;
116 };
117 }
118 }
119 #endif
120