• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)31 WMError WindowAgent::UpdateWindowRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason)
32 {
33     if (window_ == nullptr) {
34         WLOGFE("window_ is nullptr");
35         return WMError::WM_ERROR_NULLPTR;
36     }
37     window_->UpdateRect(rect, decoStatus, reason);
38     return WMError::WM_OK;
39 }
40 
UpdateWindowMode(WindowMode mode)41 WMError WindowAgent::UpdateWindowMode(WindowMode mode)
42 {
43     if (window_ == nullptr) {
44         WLOGFE("window_ is nullptr");
45         return WMError::WM_ERROR_NULLPTR;
46     }
47     window_->UpdateMode(mode);
48     return WMError::WM_OK;
49 }
50 
UpdateWindowModeSupportInfo(uint32_t modeSupportInfo)51 WMError WindowAgent::UpdateWindowModeSupportInfo(uint32_t modeSupportInfo)
52 {
53     if (window_ == nullptr) {
54         WLOGFE("window_ is nullptr");
55         return WMError::WM_ERROR_NULLPTR;
56     }
57     window_->UpdateModeSupportInfo(modeSupportInfo);
58     return WMError::WM_OK;
59 }
60 
UpdateFocusStatus(bool focused)61 WMError WindowAgent::UpdateFocusStatus(bool focused)
62 {
63     if (window_ == nullptr) {
64         WLOGFE("window_ is nullptr");
65         return WMError::WM_ERROR_NULLPTR;
66     }
67     window_->UpdateFocusStatus(focused);
68     return WMError::WM_OK;
69 }
70 
UpdateAvoidArea(const sptr<AvoidArea> & avoidArea,AvoidAreaType type)71 WMError WindowAgent::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
72 {
73     if (window_ == nullptr || avoidArea == nullptr) {
74         WLOGFE("window_ or avoidArea is nullptr.");
75         return WMError::WM_ERROR_NULLPTR;
76     }
77     window_->UpdateAvoidArea(avoidArea, type);
78     return WMError::WM_OK;
79 }
80 
UpdateWindowState(WindowState state)81 WMError WindowAgent::UpdateWindowState(WindowState state)
82 {
83     if (window_ == nullptr) {
84         WLOGFE("window_ is nullptr");
85         return WMError::WM_ERROR_NULLPTR;
86     }
87     window_->UpdateWindowState(state);
88     return WMError::WM_OK;
89 }
90 
UpdateWindowDragInfo(const PointInfo & point,DragEvent event)91 WMError WindowAgent::UpdateWindowDragInfo(const PointInfo& point, DragEvent event)
92 {
93     if (window_ == nullptr) {
94         WLOGFE("window is null");
95         return WMError::WM_ERROR_NULLPTR;
96     }
97     window_->UpdateDragEvent(point, event);
98     return WMError::WM_OK;
99 }
100 
UpdateDisplayId(DisplayId from,DisplayId to)101 WMError WindowAgent::UpdateDisplayId(DisplayId from, DisplayId to)
102 {
103     if (window_ == nullptr) {
104         WLOGFE("window is null");
105         return WMError::WM_ERROR_NULLPTR;
106     }
107     window_->UpdateDisplayId(from, to);
108     return WMError::WM_OK;
109 }
110 
UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo> & info)111 WMError WindowAgent::UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info)
112 {
113     if (window_ == nullptr) {
114         WLOGFE("window is null");
115         return WMError::WM_ERROR_NULLPTR;
116     }
117     window_->UpdateOccupiedAreaChangeInfo(info);
118     return WMError::WM_OK;
119 }
120 
UpdateActiveStatus(bool isActive)121 WMError WindowAgent::UpdateActiveStatus(bool isActive)
122 {
123     if (window_ == nullptr) {
124         WLOGFE("window is null");
125         return WMError::WM_ERROR_NULLPTR;
126     }
127     window_->UpdateActiveStatus(isActive);
128     return WMError::WM_OK;
129 }
130 
GetWindowProperty()131 sptr<WindowProperty> WindowAgent::GetWindowProperty()
132 {
133     if (window_ == nullptr) {
134         WLOGFE("window_ is nullptr");
135         return nullptr;
136     }
137     return window_->GetWindowProperty();
138 }
139 
RestoreSplitWindowMode(uint32_t mode)140 WMError WindowAgent::RestoreSplitWindowMode(uint32_t mode)
141 {
142     if (window_ == nullptr) {
143         WLOGFE("window_ is nullptr");
144         return WMError::WM_ERROR_NULLPTR;
145     }
146     window_->RestoreSplitWindowMode(mode);
147     return WMError::WM_OK;
148 }
149 
NotifyTouchOutside()150 WMError WindowAgent::NotifyTouchOutside()
151 {
152     if (window_ == nullptr) {
153         WLOGFI("window is null");
154         return WMError::WM_ERROR_NULLPTR;
155     }
156     WLOGFD("called");
157     window_->NotifyTouchOutside();
158     return WMError::WM_OK;
159 }
160 
NotifyScreenshot()161 WMError WindowAgent::NotifyScreenshot()
162 {
163     if (window_ == nullptr) {
164         WLOGFE("notify screenshot failed: window is null.");
165         return WMError::WM_ERROR_NULLPTR;
166     }
167     WLOGFI("called");
168     window_->NotifyScreenshot();
169     return WMError::WM_OK;
170 }
171 
DumpInfo(const std::vector<std::string> & params)172 WMError WindowAgent::DumpInfo(const std::vector<std::string>& params)
173 {
174     if (window_ == nullptr) {
175         WLOGFE("window_ is nullptr");
176         return WMError::WM_ERROR_NULLPTR;
177     }
178     std::vector<std::string> info;
179     window_->DumpInfo(params, info);
180     return WMError::WM_OK;
181 }
182 
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)183 WMError WindowAgent::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
184 {
185     if (window_ == nullptr) {
186         WLOGFE("window_ is nullptr");
187         return WMError::WM_ERROR_NULLPTR;
188     }
189     window_->UpdateZoomTransform(trans, isDisplayZoomOn);
190     return WMError::WM_OK;
191 }
192 
NotifyDestroy(void)193 WMError WindowAgent::NotifyDestroy(void)
194 {
195     if (window_ == nullptr) {
196         WLOGFE("window_ is nullptr");
197         return WMError::WM_ERROR_NULLPTR;
198     }
199     window_->NotifyDestroy();
200     return WMError::WM_OK;
201 }
202 
NotifyForeground(void)203 WMError WindowAgent::NotifyForeground(void)
204 {
205     if (window_ == nullptr) {
206         WLOGFE("window_ is nullptr");
207         return WMError::WM_ERROR_NULLPTR;
208     }
209     window_->NotifyForeground();
210     return WMError::WM_OK;
211 }
212 
NotifyBackground(void)213 WMError WindowAgent::NotifyBackground(void)
214 {
215     if (window_ == nullptr) {
216         WLOGFE("window_ is nullptr");
217         return WMError::WM_ERROR_NULLPTR;
218     }
219     window_->NotifyBackground();
220     return WMError::WM_OK;
221 }
222 
NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent> & pointerEvent)223 WMError WindowAgent::NotifyWindowClientPointUp(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
224 {
225     if (window_ == nullptr) {
226         WLOGFE("window_ is nullptr");
227         return WMError::WM_ERROR_NULLPTR;
228     }
229     window_->ConsumePointerEvent(pointerEvent);
230     return WMError::WM_OK;
231 }
232 } // namespace Rosen
233 } // namespace OHOS
234