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_node.h"
17 #include "window_helper.h"
18 #include "window_manager_hilog.h"
19
20 namespace OHOS {
21 namespace Rosen {
22 namespace {
23 constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowNode"};
24 }
25
~WindowNode()26 WindowNode::~WindowNode()
27 {
28 WLOGFI("~WindowNode id:%{public}u", GetWindowId());
29 }
30
SetDisplayId(DisplayId displayId)31 void WindowNode::SetDisplayId(DisplayId displayId)
32 {
33 property_->SetDisplayId(displayId);
34 }
35
SetEntireWindowTouchHotArea(const Rect & rect)36 void WindowNode::SetEntireWindowTouchHotArea(const Rect& rect)
37 {
38 entireWindowTouchHotArea_ = rect;
39 }
40
SetEntireWindowPointerHotArea(const Rect & rect)41 void WindowNode::SetEntireWindowPointerHotArea(const Rect& rect)
42 {
43 entireWindowPointerHotArea_ = rect;
44 }
45
SetWindowRect(const Rect & rect)46 void WindowNode::SetWindowRect(const Rect& rect)
47 {
48 property_->SetWindowRect(rect);
49 }
50
SetDecoStatus(bool status)51 void WindowNode::SetDecoStatus(bool status)
52 {
53 property_->SetDecoStatus(status);
54 }
55
SetRequestRect(const Rect & rect)56 void WindowNode::SetRequestRect(const Rect& rect)
57 {
58 property_->SetRequestRect(rect);
59 }
60
SetWindowProperty(const sptr<WindowProperty> & property)61 void WindowNode::SetWindowProperty(const sptr<WindowProperty>& property)
62 {
63 property_ = property;
64 }
65
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)66 void WindowNode::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
67 {
68 property_->SetSystemBarProperty(type, property);
69 }
70
SetWindowMode(WindowMode mode)71 void WindowNode::SetWindowMode(WindowMode mode)
72 {
73 property_->SetWindowMode(mode);
74 }
75
SetBrightness(float brightness)76 void WindowNode::SetBrightness(float brightness)
77 {
78 property_->SetBrightness(brightness);
79 }
80
SetFocusable(bool focusable)81 void WindowNode::SetFocusable(bool focusable)
82 {
83 property_->SetFocusable(focusable);
84 }
85
SetTouchable(bool touchable)86 void WindowNode::SetTouchable(bool touchable)
87 {
88 property_->SetTouchable(touchable);
89 }
90
SetTurnScreenOn(bool turnScreenOn)91 void WindowNode::SetTurnScreenOn(bool turnScreenOn)
92 {
93 property_->SetTurnScreenOn(turnScreenOn);
94 }
95
SetKeepScreenOn(bool keepScreenOn)96 void WindowNode::SetKeepScreenOn(bool keepScreenOn)
97 {
98 property_->SetKeepScreenOn(keepScreenOn);
99 }
100
SetCallingWindow(uint32_t windowId)101 void WindowNode::SetCallingWindow(uint32_t windowId)
102 {
103 property_->SetCallingWindow(windowId);
104 }
105
GetCallingWindow() const106 uint32_t WindowNode::GetCallingWindow() const
107 {
108 return property_->GetCallingWindow();
109 }
110
SetWindowSizeChangeReason(WindowSizeChangeReason reason)111 void WindowNode::SetWindowSizeChangeReason(WindowSizeChangeReason reason)
112 {
113 windowSizeChangeReason_ = reason;
114 }
115
SetRequestedOrientation(Orientation orientation)116 void WindowNode::SetRequestedOrientation(Orientation orientation)
117 {
118 property_->SetRequestedOrientation(orientation);
119 }
120
SetShowingDisplays(const std::vector<DisplayId> & displayIdVec)121 void WindowNode::SetShowingDisplays(const std::vector<DisplayId>& displayIdVec)
122 {
123 showingDisplays_.clear();
124 showingDisplays_.assign(displayIdVec.begin(), displayIdVec.end());
125 }
126
SetModeSupportInfo(uint32_t modeSupportInfo)127 void WindowNode::SetModeSupportInfo(uint32_t modeSupportInfo)
128 {
129 property_->SetModeSupportInfo(modeSupportInfo);
130 }
131
ResetWindowSizeChangeReason()132 void WindowNode::ResetWindowSizeChangeReason()
133 {
134 windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED;
135 }
136
GetWindowToken() const137 const sptr<IWindow>& WindowNode::GetWindowToken() const
138 {
139 return windowToken_;
140 }
141
SetWindowToken(sptr<IWindow> window)142 void WindowNode::SetWindowToken(sptr<IWindow> window)
143 {
144 windowToken_ = window;
145 }
146
SetInputEventCallingPid(int32_t pid)147 void WindowNode::SetInputEventCallingPid(int32_t pid)
148 {
149 inputCallingPid_ = pid;
150 }
151
SetCallingPid(int32_t pid)152 void WindowNode::SetCallingPid(int32_t pid)
153 {
154 callingPid_ = pid;
155 SetInputEventCallingPid(pid);
156 }
157
SetCallingUid(int32_t uid)158 void WindowNode::SetCallingUid(int32_t uid)
159 {
160 callingUid_ = uid;
161 }
162
SetDragType(DragType dragType)163 void WindowNode::SetDragType(DragType dragType)
164 {
165 property_->SetDragType(dragType);
166 }
167
SetOriginRect(const Rect & rect)168 void WindowNode::SetOriginRect(const Rect& rect)
169 {
170 property_->SetOriginRect(rect);
171 }
172
SetTouchHotAreas(const std::vector<Rect> & rects)173 void WindowNode::SetTouchHotAreas(const std::vector<Rect>& rects)
174 {
175 touchHotAreas_ = rects;
176 }
177
SetPointerHotAreas(const std::vector<Rect> & rects)178 void WindowNode::SetPointerHotAreas(const std::vector<Rect>& rects)
179 {
180 pointerHotAreas_ = rects;
181 }
182
SetWindowSizeLimits(const WindowSizeLimits & sizeLimits)183 void WindowNode::SetWindowSizeLimits(const WindowSizeLimits& sizeLimits)
184 {
185 property_->SetSizeLimits(sizeLimits);
186 }
187
SetWindowUpdatedSizeLimits(const WindowSizeLimits & sizeLimits)188 void WindowNode::SetWindowUpdatedSizeLimits(const WindowSizeLimits& sizeLimits)
189 {
190 property_->SetUpdatedSizeLimits(sizeLimits);
191 }
192
ComputeTransform()193 void WindowNode::ComputeTransform()
194 {
195 property_->ComputeTransform();
196 }
197
SetTransform(const Transform & trans)198 void WindowNode::SetTransform(const Transform& trans)
199 {
200 property_->SetTransform(trans);
201 }
202
GetZoomTransform() const203 Transform WindowNode::GetZoomTransform() const
204 {
205 return property_->GetZoomTransform();
206 }
207
UpdateZoomTransform(const Transform & trans,bool isDisplayZoomOn)208 void WindowNode::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
209 {
210 property_->SetZoomTransform(trans);
211 property_->SetDisplayZoomState(isDisplayZoomOn);
212 if (windowToken_) {
213 windowToken_->UpdateZoomTransform(trans, isDisplayZoomOn);
214 }
215 }
216
GetWindowSizeLimits() const217 WindowSizeLimits WindowNode::GetWindowSizeLimits() const
218 {
219 return property_->GetSizeLimits();
220 }
221
GetWindowUpdatedSizeLimits() const222 WindowSizeLimits WindowNode::GetWindowUpdatedSizeLimits() const
223 {
224 return property_->GetUpdatedSizeLimits();
225 }
226
GetDragType() const227 DragType WindowNode::GetDragType() const
228 {
229 return property_->GetDragType();
230 }
231
GetStretchable() const232 bool WindowNode::GetStretchable() const
233 {
234 return property_->GetStretchable();
235 }
236
GetOriginRect() const237 const Rect& WindowNode::GetOriginRect() const
238 {
239 return property_->GetOriginRect();
240 }
241
GetDisplayId() const242 DisplayId WindowNode::GetDisplayId() const
243 {
244 return property_->GetDisplayId();
245 }
246
GetWindowName() const247 const std::string& WindowNode::GetWindowName() const
248 {
249 return property_->GetWindowName();
250 }
251
GetWindowId() const252 uint32_t WindowNode::GetWindowId() const
253 {
254 return property_->GetWindowId();
255 }
256
GetParentId() const257 uint32_t WindowNode::GetParentId() const
258 {
259 return property_->GetParentId();
260 }
261
GetEntireWindowTouchHotArea() const262 Rect WindowNode::GetEntireWindowTouchHotArea() const
263 {
264 return entireWindowTouchHotArea_;
265 }
266
GetEntireWindowPointerHotArea() const267 Rect WindowNode::GetEntireWindowPointerHotArea() const
268 {
269 return entireWindowPointerHotArea_;
270 }
271
GetWindowRect() const272 Rect WindowNode::GetWindowRect() const
273 {
274 return property_->GetWindowRect();
275 }
276
GetDecoStatus() const277 bool WindowNode::GetDecoStatus() const
278 {
279 return property_->GetDecoStatus();
280 }
281
GetRequestRect() const282 Rect WindowNode::GetRequestRect() const
283 {
284 return property_->GetRequestRect();
285 }
286
GetWindowType() const287 WindowType WindowNode::GetWindowType() const
288 {
289 return property_->GetWindowType();
290 }
291
GetWindowMode() const292 WindowMode WindowNode::GetWindowMode() const
293 {
294 return property_->GetWindowMode();
295 }
296
EnableDefaultAnimation(bool animationPlayed)297 bool WindowNode::EnableDefaultAnimation(bool animationPlayed)
298 {
299 // system config enabled && not in remote animation && not custom animation && not crash
300 bool defaultAnimation = property_->GetAnimationFlag() == (static_cast<uint32_t>(WindowAnimation::DEFAULT));
301 return ((!animationPlayed) && (defaultAnimation) && (!isAppCrash_));
302 }
303
GetBrightness() const304 float WindowNode::GetBrightness() const
305 {
306 return property_->GetBrightness();
307 }
308
IsTurnScreenOn() const309 bool WindowNode::IsTurnScreenOn() const
310 {
311 return property_->IsTurnScreenOn();
312 }
313
IsKeepScreenOn() const314 bool WindowNode::IsKeepScreenOn() const
315 {
316 return property_->IsKeepScreenOn();
317 }
318
GetWindowFlags() const319 uint32_t WindowNode::GetWindowFlags() const
320 {
321 return property_->GetWindowFlags();
322 }
323
GetWindowProperty() const324 const sptr<WindowProperty>& WindowNode::GetWindowProperty() const
325 {
326 return property_;
327 }
328
GetInputEventCallingPid() const329 int32_t WindowNode::GetInputEventCallingPid() const
330 {
331 return inputCallingPid_;
332 }
333
GetCallingPid() const334 int32_t WindowNode::GetCallingPid() const
335 {
336 return callingPid_;
337 }
338
GetCallingUid() const339 int32_t WindowNode::GetCallingUid() const
340 {
341 return callingUid_;
342 }
343
GetSystemBarProperty() const344 const std::unordered_map<WindowType, SystemBarProperty>& WindowNode::GetSystemBarProperty() const
345 {
346 return property_->GetSystemBarProperty();
347 }
348
IsSplitMode() const349 bool WindowNode::IsSplitMode() const
350 {
351 return (property_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ||
352 property_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
353 }
354
GetWindowSizeChangeReason() const355 WindowSizeChangeReason WindowNode::GetWindowSizeChangeReason() const
356 {
357 return windowSizeChangeReason_;
358 }
359
GetRequestedOrientation() const360 Orientation WindowNode::GetRequestedOrientation() const
361 {
362 return property_->GetRequestedOrientation();
363 }
364
GetShowingDisplays() const365 std::vector<DisplayId> WindowNode::GetShowingDisplays() const
366 {
367 return showingDisplays_;
368 }
369
GetModeSupportInfo() const370 uint32_t WindowNode::GetModeSupportInfo() const
371 {
372 return property_->GetModeSupportInfo();
373 }
374
GetTouchHotAreas(std::vector<Rect> & rects) const375 void WindowNode::GetTouchHotAreas(std::vector<Rect>& rects) const
376 {
377 rects = touchHotAreas_;
378 }
379
GetPointerHotAreas(std::vector<Rect> & rects) const380 void WindowNode::GetPointerHotAreas(std::vector<Rect>& rects) const
381 {
382 rects = pointerHotAreas_;
383 }
384
GetAccessTokenId() const385 uint32_t WindowNode::GetAccessTokenId() const
386 {
387 return property_->GetAccessTokenId();
388 }
389
SetSnapshot(std::shared_ptr<Media::PixelMap> pixelMap)390 void WindowNode::SetSnapshot(std::shared_ptr<Media::PixelMap> pixelMap)
391 {
392 snapshot_ = pixelMap;
393 }
394
GetSnapshot()395 std::shared_ptr<Media::PixelMap> WindowNode::GetSnapshot()
396 {
397 return snapshot_;
398 }
399 } // namespace Rosen
400 } // namespace OHOS
401