1 /*
2  * Copyright (c) 2021-2022 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_agent.h"
17 #include "window_manager_hilog.h"
18 #include "wm_common.h"
19 
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowAgent"};
24 }
25 
WindowAgent(sptr<WindowImpl> & windowImpl)26 WindowAgent::WindowAgent(sptr<WindowImpl>& windowImpl)
27 {
28     window_ = windowImpl;
29 }
30 
UpdateWindowRect(const struct Rect & rect,bool decoStatus,WindowSizeChangeReason reason,const std::shared_ptr<RSTransaction> & rsTransaction)31 WMError WindowAgent::UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason,
32     const std::shared_ptr<RSTransaction>& rsTransaction)
33 {
34     if (window_ == nullptr) {
35         WLOGFE("window_ is nullptr");
36         return WMError::WM_ERROR_NULLPTR;
37     }
38     window_->UpdateRect(rect, decoStatus, reason, rsTransaction);
39     return WMError::WM_OK;
40 }
41 
UpdateWindowMode(WindowMode mode)42 WMError WindowAgent::UpdateWindowMode(WindowMode mode)
43 {
44     if (window_ == nullptr) {
45         WLOGFE("window_ is nullptr");
46         return WMError::WM_ERROR_NULLPTR;
47     }
48     window_->UpdateMode(mode);
49     return WMError::WM_OK;
50 }
51 
UpdateWindowModeSupportType(uint32_t windowModeSupportType)52 WMError WindowAgent::UpdateWindowModeSupportType(uint32_t windowModeSupportType)
53 {
54     if (window_ == nullptr) {
55         WLOGFE("window_ is nullptr");
56         return WMError::WM_ERROR_NULLPTR;
57     }
58     window_->UpdateWindowModeSupportType(windowModeSupportType);
59     return WMError::WM_OK;
60 }
61 
UpdateFocusStatus(bool focused)62 WMError WindowAgent::UpdateFocusStatus(bool focused)
63 {
64     if (window_ == nullptr) {
65         WLOGFE("window_ is nullptr");
66         return WMError::WM_ERROR_NULLPTR;
67     }
68     window_->UpdateFocusStatus(focused);
69     return WMError::WM_OK;
70 }
71 
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)72 WMError WindowAgent::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
73 {
74     if (window_ == nullptr || avoidArea == nullptr) {
75         WLOGFE("window_ or avoidArea is nullptr.");
76         return WMError::WM_ERROR_NULLPTR;
77     }
78     window_->UpdateAvoidArea(avoidArea, type);
79     return WMError::WM_OK;
80 }
81 
UpdateWindowState(WindowState state)82 WMError WindowAgent::UpdateWindowState(WindowState state)
83 {
84     if (window_ == nullptr) {
85         WLOGFE("window_ is nullptr");
86         return WMError::WM_ERROR_NULLPTR;
87     }
88     window_->UpdateWindowState(state);
89     return WMError::WM_OK;
90 }
91 
UpdateWindowDragInfo(const PointInfo & point,DragEvent event)92 WMError WindowAgent::UpdateWindowDragInfo(const PointInfo& point, DragEvent event)
93 {
94     if (window_ == nullptr) {
95         WLOGFE("window is null");
96         return WMError::WM_ERROR_NULLPTR;
97     }
98     window_->UpdateDragEvent(point, event);
99     return WMError::WM_OK;
100 }
101 
UpdateDisplayId(DisplayId from,DisplayId to)102 WMError WindowAgent::UpdateDisplayId(DisplayId from, DisplayId to)
103 {
104     if (window_ == nullptr) {
105         WLOGFE("window is null");
106         return WMError::WM_ERROR_NULLPTR;
107     }
108     window_->UpdateDisplayId(from, to);
109     return WMError::WM_OK;
110 }
111 
UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo> & info,const std::shared_ptr<RSTransaction> & rsTransaction)112 WMError WindowAgent::UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info,
113     const std::shared_ptr<RSTransaction>& rsTransaction)
114 {
115     if (window_ == nullptr) {
116         WLOGFE("window is null");
117         return WMError::WM_ERROR_NULLPTR;
118     }
119     window_->UpdateOccupiedAreaChangeInfo(info, rsTransaction);
120     return WMError::WM_OK;
121 }
122 
UpdateOccupiedAreaAndRect(const sptr<OccupiedAreaChangeInfo> & info,const Rect & rect,const std::shared_ptr<RSTransaction> & rsTransaction)123 WMError WindowAgent::UpdateOccupiedAreaAndRect(const sptr<OccupiedAreaChangeInfo>& info, const Rect& rect,
124     const std::shared_ptr<RSTransaction>& rsTransaction)
125 {
126     if (window_ == nullptr) {
127         WLOGFE("window is null");
128         return WMError::WM_ERROR_NULLPTR;
129     }
130     auto property = window_->GetWindowProperty();
131     if (property) {
132         window_->UpdateRect(rect, property->GetDecoStatus(), WindowSizeChangeReason::UNDEFINED);
133     }
134     window_->UpdateOccupiedAreaChangeInfo(info, rsTransaction);
135     return WMError::WM_OK;
136 }
137 
UpdateActiveStatus(bool isActive)138 WMError WindowAgent::UpdateActiveStatus(bool isActive)
139 {
140     if (window_ == nullptr) {
141         WLOGFE("window is null");
142         return WMError::WM_ERROR_NULLPTR;
143     }
144     window_->UpdateActiveStatus(isActive);
145     return WMError::WM_OK;
146 }
147 
GetWindowProperty()148 sptr<WindowProperty> WindowAgent::GetWindowProperty()
149 {
150     if (window_ == nullptr) {
151         WLOGFE("window_ is nullptr");
152         return nullptr;
153     }
154     return window_->GetWindowProperty();
155 }
156 
RestoreSplitWindowMode(uint32_t mode)157 WMError WindowAgent::RestoreSplitWindowMode(uint32_t mode)
158 {
159     if (window_ == nullptr) {
160         WLOGFE("window_ is nullptr");
161         return WMError::WM_ERROR_NULLPTR;
162     }
163     window_->RestoreSplitWindowMode(mode);
164     return WMError::WM_OK;
165 }
166 
NotifyTouchOutside()167 WMError WindowAgent::NotifyTouchOutside()
168 {
169     if (window_ == nullptr) {
170         WLOGI("window is null");
171         return WMError::WM_ERROR_NULLPTR;
172     }
173     WLOGFD("called");
174     window_->NotifyTouchOutside();
175     return WMError::WM_OK;
176 }
177 
NotifyScreenshot()178 WMError WindowAgent::NotifyScreenshot()
179 {
180     if (window_ == nullptr) {
181         WLOGFE("notify screenshot failed: window is null.");
182         return WMError::WM_ERROR_NULLPTR;
183     }
184     WLOGFD("called");
185     window_->NotifyScreenshot();
186     return WMError::WM_OK;
187 }
188 
DumpInfo(const std::vector<std::string> & params)189 WMError WindowAgent::DumpInfo(const std::vector<std::string>& params)
190 {
191     if (window_ == nullptr) {
192         WLOGFE("window_ is nullptr");
193         return WMError::WM_ERROR_NULLPTR;
194     }
195     std::vector<std::string> info;
196     window_->DumpInfo(params, info);
197     return WMError::WM_OK;
198 }
199 
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)200 WMError WindowAgent::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
201 {
202     if (window_ == nullptr) {
203         WLOGFE("window_ is nullptr");
204         return WMError::WM_ERROR_NULLPTR;
205     }
206     window_->UpdateZoomTransform(trans, isDisplayZoomOn);
207     return WMError::WM_OK;
208 }
209 
NotifyDestroy(void)210 WMError WindowAgent::NotifyDestroy(void)
211 {
212     if (window_ == nullptr) {
213         WLOGFE("window_ is nullptr");
214         return WMError::WM_ERROR_NULLPTR;
215     }
216     window_->NotifyDestroy();
217     return WMError::WM_OK;
218 }
219 
NotifyForeground(void)220 WMError WindowAgent::NotifyForeground(void)
221 {
222     if (window_ == nullptr) {
223         WLOGFE("window_ is nullptr");
224         return WMError::WM_ERROR_NULLPTR;
225     }
226     window_->NotifyForeground();
227     return WMError::WM_OK;
228 }
229 
NotifyBackground(void)230 WMError WindowAgent::NotifyBackground(void)
231 {
232     if (window_ == nullptr) {
233         WLOGFE("window_ is nullptr");
234         return WMError::WM_ERROR_NULLPTR;
235     }
236     window_->NotifyBackground();
237     return WMError::WM_OK;
238 }
239 
NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)240 WMError WindowAgent::NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
241 {
242     if (window_ == nullptr) {
243         WLOGFE("window_ is nullptr");
244         return WMError::WM_ERROR_NULLPTR;
245     }
246     window_->ConsumePointerEvent(pointerEvent);
247     return WMError::WM_OK;
248 }
249 
ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)250 void WindowAgent::ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent> event)
251 {
252     if (window_ == nullptr) {
253         WLOGFE("window_ is nullptr");
254         return;
255     }
256     window_->ConsumeKeyEvent(event);
257 }
258 
NotifyForegroundInteractiveStatus(bool interactive)259 void WindowAgent::NotifyForegroundInteractiveStatus(bool interactive)
260 {
261     if (window_ == nullptr) {
262         WLOGFE("window_ is nullptr");
263         return;
264     }
265     window_->NotifyForegroundInteractiveStatus(interactive);
266 }
267 
268 } // namespace Rosen
269 } // namespace OHOS
270