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 #include "window_listener.h"
17 #include "cj_lambda.h"
18 #include "event_handler.h"
19 #include "event_runner.h"
20 #include "window_manager_hilog.h"
21 
22 namespace OHOS {
23 namespace Rosen {
CjWindowListener(int64_t callbackObject)24 CjWindowListener::CjWindowListener(int64_t callbackObject)
25 {
26     weakRef_ = wptr<CjWindowListener>(this);
27     auto func = reinterpret_cast<void(*)(void*)>(callbackObject);
28     cjCallBack_ = CJLambda::Create(func);
29 }
30 
~CjWindowListener()31 CjWindowListener::~CjWindowListener()
32 {
33     TLOGI(WmsLogTag::WMS_DIALOG, "~CjWindowListener");
34 }
35 
SetMainEventHandler()36 void CjWindowListener::SetMainEventHandler()
37 {
38     auto mainRunner = AppExecFwk::EventRunner::GetMainEventRunner();
39     if (mainRunner == nullptr) {
40         return;
41     }
42     eventHandler_ = std::make_shared<AppExecFwk::EventHandler>(mainRunner);
43 }
44 
CallCjMethod(const char * methodName,void * argv,size_t argc)45 void CjWindowListener::CallCjMethod(const char* methodName, void* argv, size_t argc)
46 {
47     TLOGD(WmsLogTag::WMS_DIALOG, "[WindowListener]CallCjMethod methodName = %{public}s", methodName);
48     if (cjCallBack_ == nullptr) {
49         TLOGE(WmsLogTag::WMS_DIALOG, "[WindowListener]env_ nullptr or jsCallBack_ is nullptr");
50         return;
51     }
52     cjCallBack_(argv);
53 }
54 
OnSystemBarPropertyChange(DisplayId displayId,const SystemBarRegionTints & tints)55 void CjWindowListener::OnSystemBarPropertyChange(DisplayId displayId,
56     const SystemBarRegionTints& tints)
57 {
58 }
59 
OnSizeChange(Rect rect,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)60 void CjWindowListener::OnSizeChange(Rect rect, WindowSizeChangeReason reason,
61     const std::shared_ptr<RSTransaction>& rsTransaction)
62 {
63 }
64 
OnModeChange(WindowMode mode,bool hasDeco)65 void CjWindowListener::OnModeChange(WindowMode mode, bool hasDeco)
66 {
67 }
68 
OnAvoidAreaChanged(const AvoidArea avoidArea,AvoidAreaType type)69 void CjWindowListener::OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type)
70 {
71 }
72 
AfterForeground()73 void CjWindowListener::AfterForeground()
74 {
75 }
76 
AfterBackground()77 void CjWindowListener::AfterBackground()
78 {
79 }
80 
AfterFocused()81 void CjWindowListener::AfterFocused()
82 {
83 }
84 
AfterUnfocused()85 void CjWindowListener::AfterUnfocused()
86 {
87 }
88 
AfterResumed()89 void CjWindowListener::AfterResumed()
90 {
91 }
92 
AfterPaused()93 void CjWindowListener::AfterPaused()
94 {
95 }
96 
AfterDestroyed()97 void CjWindowListener::AfterDestroyed()
98 {
99 }
100 
OnSizeChange(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)101 void CjWindowListener::OnSizeChange(const sptr<OccupiedAreaChangeInfo>& info,
102     const std::shared_ptr<RSTransaction>& rsTransaction)
103 {
104     if (info == nullptr) {
105         TLOGE(WmsLogTag::WMS_DIALOG, "[WindowListener] this changeInfo is nullptr");
106         return;
107     }
108     TLOGI(WmsLogTag::WMS_DIALOG, "[WindowListener]OccupiedAreaChangeInfo, type: %{public}u, " \
109         "input rect: [%{public}d, %{public}d, %{public}u, %{public}u]",
110         static_cast<uint32_t>(info->type_),
111         info->rect_.posX_, info->rect_.posY_, info->rect_.width_, info->rect_.height_);
112     auto thisListener = weakRef_.promote();
113     if (thisListener == nullptr) {
114         TLOGE(WmsLogTag::WMS_DIALOG, "[WindowListener] this listener is nullptr");
115         return;
116     }
117     void* argv = &(info->rect_.height_);
118     size_t argc = 1;
119     thisListener->CallCjMethod(KEYBOARD_HEIGHT_CHANGE_CB.c_str(), argv, argc);
120 }
121 
OnTouchOutside() const122 void CjWindowListener::OnTouchOutside() const
123 {
124 }
125 
OnScreenshot()126 void CjWindowListener::OnScreenshot()
127 {
128 }
129 
OnDialogTargetTouch() const130 void CjWindowListener::OnDialogTargetTouch() const
131 {
132 }
133 
OnDialogDeathRecipient() const134 void CjWindowListener::OnDialogDeathRecipient() const
135 {
136 }
137 
OnGestureNavigationEnabledUpdate(bool enable)138 void CjWindowListener::OnGestureNavigationEnabledUpdate(bool enable)
139 {
140 }
141 
OnWaterMarkFlagUpdate(bool showWaterMark)142 void CjWindowListener::OnWaterMarkFlagUpdate(bool showWaterMark)
143 {
144 }
145 
OnWindowVisibilityChangedCallback(const bool isVisible)146 void CjWindowListener::OnWindowVisibilityChangedCallback(const bool isVisible)
147 {
148 }
149 
OnWindowStatusChange(WindowStatus status)150 void CjWindowListener::OnWindowStatusChange(WindowStatus status)
151 {
152 }
153 
OnWindowTitleButtonRectChanged(const TitleButtonRect & titleButtonRect)154 void CjWindowListener::OnWindowTitleButtonRectChanged(const TitleButtonRect& titleButtonRect)
155 {
156 }
157 }
158 }
159