1/*
2 * Copyright (c) 2021-2023 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
20namespace OHOS {
21namespace Rosen {
22namespace {
23constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowNode"};
24}
25
26WindowNode::~WindowNode()
27{
28    WLOGI("~WindowNode id:%{public}u", GetWindowId());
29}
30
31void WindowNode::SetDisplayId(DisplayId displayId)
32{
33    property_->SetDisplayId(displayId);
34}
35
36void WindowNode::SetEntireWindowTouchHotArea(const Rect& rect)
37{
38    entireWindowTouchHotArea_ = rect;
39}
40
41void WindowNode::SetEntireWindowPointerHotArea(const Rect& rect)
42{
43    entireWindowPointerHotArea_ = rect;
44}
45
46void WindowNode::SetWindowRect(const Rect& rect)
47{
48    property_->SetWindowRect(rect);
49}
50
51void WindowNode::SetDecorEnable(bool decorEnable)
52{
53    property_->SetDecorEnable(decorEnable);
54}
55
56void WindowNode::SetDecoStatus(bool decoStatus)
57{
58    property_->SetDecoStatus(decoStatus);
59}
60
61void WindowNode::SetRequestRect(const Rect& rect)
62{
63    property_->SetRequestRect(rect);
64}
65
66void WindowNode::SetWindowProperty(const sptr<WindowProperty>& property)
67{
68    property_ = property;
69}
70
71void WindowNode::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
72{
73    property_->SetSystemBarProperty(type, property);
74}
75
76void WindowNode::SetWindowMode(WindowMode mode)
77{
78    property_->SetWindowMode(mode);
79}
80
81void WindowNode::SetBrightness(float brightness)
82{
83    property_->SetBrightness(brightness);
84}
85
86void WindowNode::SetFocusable(bool focusable)
87{
88    property_->SetFocusable(focusable);
89}
90
91void WindowNode::SetTouchable(bool touchable)
92{
93    property_->SetTouchable(touchable);
94}
95
96void WindowNode::SetTurnScreenOn(bool turnScreenOn)
97{
98    property_->SetTurnScreenOn(turnScreenOn);
99}
100
101void WindowNode::SetKeepScreenOn(bool keepScreenOn)
102{
103    property_->SetKeepScreenOn(keepScreenOn);
104}
105
106void WindowNode::SetCallingWindow(uint32_t windowId)
107{
108    property_->SetCallingWindow(windowId);
109}
110
111uint32_t WindowNode::GetCallingWindow() const
112{
113    return property_->GetCallingWindow();
114}
115
116void WindowNode::SetWindowSizeChangeReason(WindowSizeChangeReason reason)
117{
118    windowSizeChangeReason_ = reason;
119}
120
121void WindowNode::SetRequestedOrientation(Orientation orientation)
122{
123    property_->SetRequestedOrientation(orientation);
124}
125
126void WindowNode::SetShowingDisplays(const std::vector<DisplayId>& displayIdVec)
127{
128    showingDisplays_.clear();
129    showingDisplays_.assign(displayIdVec.begin(), displayIdVec.end());
130}
131
132void WindowNode::SetModeSupportInfo(uint32_t modeSupportInfo)
133{
134    property_->SetModeSupportInfo(modeSupportInfo);
135}
136
137void WindowNode::ResetWindowSizeChangeReason()
138{
139    windowSizeChangeReason_ = WindowSizeChangeReason::UNDEFINED;
140}
141
142const sptr<IWindow>& WindowNode::GetWindowToken() const
143{
144    return windowToken_;
145}
146
147void WindowNode::SetWindowToken(sptr<IWindow> window)
148{
149    windowToken_ = window;
150}
151
152void WindowNode::SetInputEventCallingPid(int32_t pid)
153{
154    inputCallingPid_ = pid;
155}
156
157void WindowNode::SetCallingPid(int32_t pid)
158{
159    callingPid_ = pid;
160    SetInputEventCallingPid(pid);
161}
162
163void WindowNode::SetCallingUid(int32_t uid)
164{
165    callingUid_ = uid;
166}
167
168void WindowNode::SetDragType(DragType dragType)
169{
170    property_->SetDragType(dragType);
171}
172
173void WindowNode::SetOriginRect(const Rect& rect)
174{
175    property_->SetOriginRect(rect);
176}
177
178void WindowNode::SetTouchHotAreas(const std::vector<Rect>& rects)
179{
180    touchHotAreas_ = rects;
181}
182
183void WindowNode::SetPointerHotAreas(const std::vector<Rect>& rects)
184{
185    pointerHotAreas_ = rects;
186}
187
188void WindowNode::SetWindowSizeLimits(const WindowLimits& sizeLimits)
189{
190    property_->SetSizeLimits(sizeLimits);
191}
192
193void WindowNode::SetWindowUpdatedSizeLimits(const WindowLimits& sizeLimits)
194{
195    property_->SetUpdatedSizeLimits(sizeLimits);
196}
197
198void WindowNode::ComputeTransform()
199{
200    property_->ComputeTransform();
201}
202
203void WindowNode::SetTransform(const Transform& trans)
204{
205    property_->SetTransform(trans);
206}
207
208Transform WindowNode::GetZoomTransform() const
209{
210    return property_->GetZoomTransform();
211}
212
213void WindowNode::UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn)
214{
215    property_->SetZoomTransform(trans);
216    property_->SetDisplayZoomState(isDisplayZoomOn);
217    if (windowToken_) {
218        windowToken_->UpdateZoomTransform(trans, isDisplayZoomOn);
219    }
220}
221
222WindowLimits WindowNode::GetWindowSizeLimits() const
223{
224    return property_->GetSizeLimits();
225}
226
227WindowLimits WindowNode::GetWindowUpdatedSizeLimits() const
228{
229    return property_->GetUpdatedSizeLimits();
230}
231
232DragType WindowNode::GetDragType() const
233{
234    return property_->GetDragType();
235}
236
237bool WindowNode::GetStretchable() const
238{
239    return property_->GetStretchable();
240}
241
242const Rect& WindowNode::GetOriginRect() const
243{
244    return property_->GetOriginRect();
245}
246
247DisplayId WindowNode::GetDisplayId() const
248{
249    return property_->GetDisplayId();
250}
251
252const std::string& WindowNode::GetWindowName() const
253{
254    return property_->GetWindowName();
255}
256
257uint32_t WindowNode::GetWindowId() const
258{
259    return property_->GetWindowId();
260}
261
262uint32_t WindowNode::GetParentId() const
263{
264    return property_->GetParentId();
265}
266
267Rect WindowNode::GetEntireWindowTouchHotArea() const
268{
269    return entireWindowTouchHotArea_;
270}
271
272Rect WindowNode::GetEntireWindowPointerHotArea() const
273{
274    return entireWindowPointerHotArea_;
275}
276
277Rect WindowNode::GetWindowRect() const
278{
279    return property_->GetWindowRect();
280}
281
282bool WindowNode::GetDecoStatus() const
283{
284    return property_->GetDecoStatus();
285}
286
287Rect WindowNode::GetRequestRect() const
288{
289    return property_->GetRequestRect();
290}
291
292WindowType WindowNode::GetWindowType() const
293{
294    return property_->GetWindowType();
295}
296
297WindowMode WindowNode::GetWindowMode() const
298{
299    return property_->GetWindowMode();
300}
301
302bool WindowNode::EnableDefaultAnimation(bool animationPlayed)
303{
304    // system config enabled && not in remote animation && not custom animation && not crash
305    bool defaultAnimation = property_->GetAnimationFlag() == (static_cast<uint32_t>(WindowAnimation::DEFAULT));
306    return ((!animationPlayed) && (defaultAnimation) && (!isAppCrash_));
307}
308
309float WindowNode::GetBrightness() const
310{
311    return property_->GetBrightness();
312}
313
314bool WindowNode::IsTurnScreenOn() const
315{
316    return property_->IsTurnScreenOn();
317}
318
319bool WindowNode::IsKeepScreenOn() const
320{
321    return property_->IsKeepScreenOn();
322}
323
324uint32_t WindowNode::GetWindowFlags() const
325{
326    return property_->GetWindowFlags();
327}
328
329const sptr<WindowProperty>& WindowNode::GetWindowProperty() const
330{
331    return property_;
332}
333
334int32_t WindowNode::GetInputEventCallingPid() const
335{
336    return inputCallingPid_;
337}
338
339int32_t WindowNode::GetCallingPid() const
340{
341    return callingPid_;
342}
343
344int32_t WindowNode::GetCallingUid() const
345{
346    return callingUid_;
347}
348
349const std::unordered_map<WindowType, SystemBarProperty>& WindowNode::GetSystemBarProperty() const
350{
351    return property_->GetSystemBarProperty();
352}
353
354bool WindowNode::IsSplitMode() const
355{
356    return (property_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_PRIMARY ||
357        property_->GetWindowMode() == WindowMode::WINDOW_MODE_SPLIT_SECONDARY);
358}
359
360WindowSizeChangeReason WindowNode::GetWindowSizeChangeReason() const
361{
362    return windowSizeChangeReason_;
363}
364
365Orientation WindowNode::GetRequestedOrientation() const
366{
367    return property_->GetRequestedOrientation();
368}
369
370std::vector<DisplayId> WindowNode::GetShowingDisplays() const
371{
372    return showingDisplays_;
373}
374
375uint32_t WindowNode::GetModeSupportInfo() const
376{
377    return property_->GetModeSupportInfo();
378}
379
380void WindowNode::GetTouchHotAreas(std::vector<Rect>& rects) const
381{
382    rects = touchHotAreas_;
383}
384
385void WindowNode::GetPointerHotAreas(std::vector<Rect>& rects) const
386{
387    rects = pointerHotAreas_;
388}
389
390uint32_t WindowNode::GetAccessTokenId() const
391{
392    return property_->GetAccessTokenId();
393}
394
395void WindowNode::SetSnapshot(std::shared_ptr<Media::PixelMap> pixelMap)
396{
397    snapshot_ = pixelMap;
398}
399
400std::shared_ptr<Media::PixelMap> WindowNode::GetSnapshot()
401{
402    return snapshot_;
403}
404
405void WindowNode::SetAspectRatio(float ratio)
406{
407    property_->SetAspectRatio(ratio);
408}
409
410float WindowNode::GetAspectRatio() const
411{
412    return property_->GetAspectRatio();
413}
414
415void WindowNode::SetWindowGravity(WindowGravity gravity, uint32_t percent)
416{
417    property_->SetWindowGravity(gravity, percent);
418}
419
420void WindowNode::GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const
421{
422    property_->GetWindowGravity(gravity, percent);
423}
424
425void WindowNode::SetVisibilityState(WindowVisibilityState state)
426{
427    visibilityState_ = state;
428}
429
430WindowVisibilityState WindowNode::GetVisibilityState() const
431{
432    return visibilityState_;
433}
434
435bool WindowNode::GetTouchable() const
436{
437    return property_->GetTouchable();
438}
439} // namespace Rosen
440} // namespace OHOS
441