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_property.h"
17#include "window_helper.h"
18#include "wm_common.h"
19
20namespace OHOS {
21namespace Rosen {
22namespace {
23constexpr uint32_t SYSTEM_BAR_PROPERTY_MAX_NUM = 2;
24constexpr uint32_t TOUCH_HOT_AREA_MAX_NUM = 50;
25}
26WindowProperty::WindowProperty(const sptr<WindowProperty>& property)
27{
28    CopyFrom(property);
29}
30
31void WindowProperty::SetWindowName(const std::string& name)
32{
33    windowName_ = name;
34}
35
36void WindowProperty::SetAbilityInfo(const AbilityInfo& info)
37{
38    abilityInfo_ = info;
39}
40
41void WindowProperty::SetWindowRect(const struct Rect& rect)
42{
43    ComputeTransform();
44    windowRect_ = rect;
45}
46
47void WindowProperty::SetDecoStatus(bool decoStatus)
48{
49    decoStatus_ = decoStatus;
50}
51
52void WindowProperty::SetRequestRect(const Rect& requestRect)
53{
54    requestRect_ = requestRect;
55}
56
57void WindowProperty::SetWindowType(WindowType type)
58{
59    type_ = type;
60}
61
62void WindowProperty::SetWindowMode(WindowMode mode)
63{
64    if (!WindowHelper::IsValidWindowMode(mode) || !WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) {
65        return;
66    }
67    if (!WindowHelper::IsSplitWindowMode(mode_)) {
68        lastMode_ = mode_;
69    }
70    mode_ = mode;
71}
72
73void WindowProperty::SetLastWindowMode(WindowMode mode)
74{
75    if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, mode)) {
76        return;
77    }
78    lastMode_ = mode;
79}
80
81void WindowProperty::SetFullScreen(bool isFullScreen)
82{
83    isFullScreen_ = isFullScreen;
84}
85
86void WindowProperty::SetFocusable(bool isFocusable)
87{
88    focusable_ = isFocusable;
89}
90
91void WindowProperty::SetTouchable(bool isTouchable)
92{
93    touchable_ = isTouchable;
94}
95
96void WindowProperty::SetPrivacyMode(bool isPrivate)
97{
98    isPrivacyMode_ = isPrivate;
99}
100
101void WindowProperty::SetSnapshotSkip(bool isSkip)
102{
103    isSnapshotSkip_ = isSkip;
104}
105
106void WindowProperty::SetSystemPrivacyMode(bool isSystemPrivate)
107{
108    isSystemPrivacyMode_ = isSystemPrivate;
109}
110
111void WindowProperty::SetTransparent(bool isTransparent)
112{
113    isTransparent_ = isTransparent;
114}
115
116void WindowProperty::SetAlpha(float alpha)
117{
118    alpha_ = alpha;
119}
120
121void WindowProperty::SetTransform(const Transform& trans)
122{
123    recomputeTransformMat_ = true;
124    trans_ = trans;
125}
126
127void WindowProperty::HandleComputeTransform(const Transform& trans)
128{
129    TransformHelper::Vector3 pivotPos = { windowRect_.posX_ + trans.pivotX_ * windowRect_.width_,
130        windowRect_.posY_ + trans.pivotY_ * windowRect_.height_, 0 };
131    worldTransformMat_ = TransformHelper::CreateTranslation(-pivotPos) *
132                            WindowHelper::ComputeWorldTransformMat4(trans) *
133                            TransformHelper::CreateTranslation(pivotPos);
134    // transformMat = worldTransformMat * viewProjectionMat
135    transformMat_ = worldTransformMat_;
136    // Z component of camera position is constant value
137    constexpr float cameraZ = -576.f;
138    TransformHelper::Vector3 cameraPos(pivotPos.x_ + trans.translateX_, pivotPos.y_ + trans.translateY_, cameraZ);
139    // Concatenate with view projection matrix
140    transformMat_ *= TransformHelper::CreateLookAt(cameraPos,
141        TransformHelper::Vector3(cameraPos.x_, cameraPos.y_, 0), TransformHelper::Vector3(0, 1, 0)) *
142        TransformHelper::CreatePerspective(cameraPos);
143}
144
145void WindowProperty::ComputeTransform()
146{
147    if (isDisplayZoomOn_) {
148        if (reCalcuZoomTransformMat_) {
149            HandleComputeTransform(zoomTrans_);
150            reCalcuZoomTransformMat_ = false;
151        }
152    } else if (recomputeTransformMat_) {
153        HandleComputeTransform(trans_);
154        recomputeTransformMat_ = false;
155    }
156}
157
158void WindowProperty::SetZoomTransform(const Transform& trans)
159{
160    zoomTrans_ = trans;
161    reCalcuZoomTransformMat_ = true;
162}
163
164void WindowProperty::ClearTransformZAxisOffset(Transform& trans)
165{
166    // replace Z axis translation by scaling
167    TransformHelper::Matrix4 preTransformMat = transformMat_;
168    HandleComputeTransform(trans);
169    Rect rect = WindowHelper::TransformRect(transformMat_, windowRect_);
170    float translateZ = trans.translateZ_;
171    trans.translateZ_ = 0.f;
172    HandleComputeTransform(trans);
173    Rect rectWithoutZAxisOffset = WindowHelper::TransformRect(transformMat_, windowRect_);
174    if (rectWithoutZAxisOffset.width_ == 0) {
175        trans.translateZ_ = translateZ;
176        return;
177    }
178    float scale = rect.width_ * 1.0f / rectWithoutZAxisOffset.width_;
179    trans.scaleX_ *= scale;
180    trans.scaleY_ *= scale;
181    transformMat_ = preTransformMat;
182}
183
184void WindowProperty::UpdatePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
185{
186    if (trans_ == Transform::Identity() && zoomTrans_ == Transform::Identity()) {
187        return;
188    }
189    ComputeTransform();
190    MMI::PointerEvent::PointerItem pointerItem;
191    if (!pointerEvent->GetPointerItem(pointerEvent->GetPointerId(), pointerItem)) {
192        return;
193    }
194    PointInfo originPos =
195        WindowHelper::CalculateOriginPosition(transformMat_,
196        { pointerItem.GetDisplayX(), pointerItem.GetDisplayY() });
197    pointerItem.SetDisplayX(originPos.x);
198    pointerItem.SetDisplayY(originPos.y);
199    pointerItem.SetWindowX(originPos.x - windowRect_.posX_);
200    pointerItem.SetWindowY(originPos.y - windowRect_.posY_);
201    pointerEvent->UpdatePointerItem(pointerEvent->GetPointerId(), pointerItem);
202}
203
204bool WindowProperty::isNeedComputerTransform()
205{
206    return ((!isDisplayZoomOn_ && trans_ != Transform::Identity()) || zoomTrans_ != Transform::Identity());
207}
208
209void WindowProperty::SetAnimateWindowFlag(bool isAnimateWindow)
210{
211    isAnimateWindow_ = isAnimateWindow;
212}
213
214void WindowProperty::SetDisplayZoomState(bool isDisplayZoomOn)
215{
216    isDisplayZoomOn_ = isDisplayZoomOn;
217}
218
219bool WindowProperty::IsDisplayZoomOn() const
220{
221    return isDisplayZoomOn_;
222}
223
224bool WindowProperty::IsAnimateWindow() const
225{
226    return isAnimateWindow_;
227}
228
229const Transform& WindowProperty::GetZoomTransform() const
230{
231    return zoomTrans_;
232}
233
234void WindowProperty::SetBrightness(float brightness)
235{
236    brightness_ = brightness;
237}
238
239void WindowProperty::SetTurnScreenOn(bool turnScreenOn)
240{
241    turnScreenOn_ = turnScreenOn;
242}
243
244void WindowProperty::SetKeepScreenOn(bool keepScreenOn)
245{
246    keepScreenOn_ = keepScreenOn;
247}
248
249void WindowProperty::SetCallingWindow(uint32_t windowId)
250{
251    callingWindow_ = windowId;
252}
253
254void WindowProperty::SetDisplayId(DisplayId displayId)
255{
256    displayId_ = displayId;
257}
258
259void WindowProperty::SetWindowFlags(uint32_t flags)
260{
261    flags_ = flags;
262}
263
264void WindowProperty::SetSizeLimits(const WindowLimits& sizeLimits)
265{
266    sizeLimits_ = sizeLimits;
267}
268
269void WindowProperty::SetUpdatedSizeLimits(const WindowLimits& sizeLimits)
270{
271    updatedSizeLimits_ = sizeLimits;
272}
273
274void WindowProperty::AddWindowFlag(WindowFlag flag)
275{
276    flags_ |= static_cast<uint32_t>(flag);
277}
278
279void WindowProperty::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
280{
281    if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
282        sysBarPropMap_[type] = property;
283    }
284}
285
286void WindowProperty::SetDecorEnable(bool decorEnable)
287{
288    isDecorEnable_ = decorEnable;
289}
290
291void WindowProperty::SetHitOffset(const PointInfo& offset)
292{
293    hitOffset_ = offset;
294}
295
296void WindowProperty::SetAnimationFlag(uint32_t animationFlag)
297{
298    animationFlag_ = animationFlag;
299}
300
301void WindowProperty::SetWindowSizeChangeReason(WindowSizeChangeReason reason)
302{
303    windowSizeChangeReason_ = reason;
304}
305
306void WindowProperty::SetDragType(DragType dragType)
307{
308    dragType_ = dragType;
309}
310
311void WindowProperty::SetStretchable(bool stretchable)
312{
313    isStretchable_ = stretchable;
314}
315
316void WindowProperty::SetOriginRect(const Rect& rect)
317{
318    originRect_ = rect;
319}
320
321void WindowProperty::SetAccessTokenId(uint32_t accessTokenId)
322{
323    accessTokenId_ = accessTokenId;
324}
325
326WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const
327{
328    return windowSizeChangeReason_;
329}
330
331void WindowProperty::ResumeLastWindowMode()
332{
333    // if lastMode isn't supported, get supported mode from supportModeInfo
334    if (!WindowHelper::IsWindowModeSupported(modeSupportInfo_, lastMode_)) {
335        auto mode = WindowHelper::GetWindowModeFromModeSupportInfo(modeSupportInfo_);
336        if (!WindowHelper::IsSplitWindowMode(mode)) {
337            mode_ = mode;
338        }
339        return;
340    }
341    mode_ = lastMode_;
342}
343
344const std::string& WindowProperty::GetWindowName() const
345{
346    return windowName_ ;
347}
348
349const AbilityInfo& WindowProperty::GetAbilityInfo() const
350{
351    return abilityInfo_ ;
352}
353
354Rect WindowProperty::GetWindowRect() const
355{
356    return windowRect_;
357}
358
359bool WindowProperty::GetDecoStatus() const
360{
361    return decoStatus_;
362}
363
364Rect WindowProperty::GetRequestRect() const
365{
366    return requestRect_;
367}
368
369WindowType WindowProperty::GetWindowType() const
370{
371    return type_;
372}
373
374WindowMode WindowProperty::GetWindowMode() const
375{
376    return mode_;
377}
378
379WindowMode WindowProperty::GetLastWindowMode() const
380{
381    return lastMode_;
382}
383
384bool WindowProperty::GetFullScreen() const
385{
386    return isFullScreen_;
387}
388
389bool WindowProperty::GetFocusable() const
390{
391    return focusable_;
392}
393
394bool WindowProperty::GetTouchable() const
395{
396    return touchable_;
397}
398
399uint32_t WindowProperty::GetCallingWindow() const
400{
401    return callingWindow_;
402}
403
404bool WindowProperty::GetPrivacyMode() const
405{
406    return isPrivacyMode_;
407}
408
409bool WindowProperty::GetSystemPrivacyMode() const
410{
411    return isSystemPrivacyMode_;
412}
413
414bool WindowProperty::GetSnapshotSkip() const
415{
416    return isSnapshotSkip_;
417}
418
419bool WindowProperty::GetTransparent() const
420{
421    return isTransparent_;
422}
423
424float WindowProperty::GetAlpha() const
425{
426    return alpha_;
427}
428
429const Transform& WindowProperty::GetTransform() const
430{
431    return trans_;
432}
433
434float WindowProperty::GetBrightness() const
435{
436    return brightness_;
437}
438
439bool WindowProperty::IsTurnScreenOn() const
440{
441    return turnScreenOn_;
442}
443
444bool WindowProperty::IsKeepScreenOn() const
445{
446    return keepScreenOn_;
447}
448
449DisplayId WindowProperty::GetDisplayId() const
450{
451    return displayId_;
452}
453
454uint32_t WindowProperty::GetWindowFlags() const
455{
456    return flags_;
457}
458
459const std::unordered_map<WindowType, SystemBarProperty>& WindowProperty::GetSystemBarProperty() const
460{
461    return sysBarPropMap_;
462}
463
464bool WindowProperty::GetDecorEnable() const
465{
466    return isDecorEnable_;
467}
468
469void WindowProperty::SetWindowId(uint32_t windowId)
470{
471    windowId_ = windowId;
472}
473
474void WindowProperty::SetParentId(uint32_t parentId)
475{
476    parentId_ = parentId;
477}
478
479void WindowProperty::SetTokenState(bool hasToken)
480{
481    tokenState_ = hasToken;
482}
483
484void WindowProperty::SetModeSupportInfo(uint32_t modeSupportInfo)
485{
486    modeSupportInfo_ = modeSupportInfo;
487}
488
489void WindowProperty::SetRequestModeSupportInfo(uint32_t requestModeSupportInfo)
490{
491    requestModeSupportInfo_ = requestModeSupportInfo;
492}
493
494uint32_t WindowProperty::GetWindowId() const
495{
496    return windowId_;
497}
498
499uint32_t WindowProperty::GetParentId() const
500{
501    return parentId_;
502}
503
504const PointInfo& WindowProperty::GetHitOffset() const
505{
506    return hitOffset_;
507}
508
509uint32_t WindowProperty::GetAnimationFlag() const
510{
511    return animationFlag_;
512}
513
514uint32_t WindowProperty::GetModeSupportInfo() const
515{
516    return modeSupportInfo_;
517}
518
519uint32_t WindowProperty::GetRequestModeSupportInfo() const
520{
521    return requestModeSupportInfo_;
522}
523
524bool WindowProperty::GetTokenState() const
525{
526    return tokenState_;
527}
528
529DragType WindowProperty::GetDragType() const
530{
531    return dragType_;
532}
533
534const Rect& WindowProperty::GetOriginRect() const
535{
536    return originRect_;
537}
538
539bool WindowProperty::GetStretchable() const
540{
541    return isStretchable_;
542}
543
544WindowLimits WindowProperty::GetSizeLimits() const
545{
546    return sizeLimits_;
547}
548
549WindowLimits WindowProperty::GetUpdatedSizeLimits() const
550{
551    return updatedSizeLimits_;
552}
553
554const TransformHelper::Matrix4& WindowProperty::GetTransformMat() const
555{
556    return transformMat_;
557}
558
559const TransformHelper::Matrix4& WindowProperty::GetWorldTransformMat() const
560{
561    return worldTransformMat_;
562}
563
564void WindowProperty::SetTouchHotAreas(const std::vector<Rect>& rects)
565{
566    touchHotAreas_ = rects;
567}
568
569void WindowProperty::GetTouchHotAreas(std::vector<Rect>& rects) const
570{
571    rects = touchHotAreas_;
572}
573
574void WindowProperty::SetAspectRatio(float ratio)
575{
576    aspectRatio_ = ratio;
577}
578
579void WindowProperty::SetMaximizeMode(MaximizeMode maximizeMode)
580{
581    maximizeMode_ = maximizeMode;
582}
583
584float WindowProperty::GetAspectRatio() const
585{
586    return aspectRatio_;
587}
588
589MaximizeMode WindowProperty::GetMaximizeMode() const
590{
591    return maximizeMode_;
592}
593
594uint32_t WindowProperty::GetAccessTokenId() const
595{
596    return accessTokenId_;
597}
598
599void WindowProperty::SetWindowGravity(WindowGravity gravity, uint32_t percent)
600{
601    windowGravity_ = gravity;
602    windowGravitySizePercent_ = percent;
603}
604
605void WindowProperty::GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const
606{
607    gravity = windowGravity_;
608    percent = windowGravitySizePercent_;
609}
610
611bool WindowProperty::MapMarshalling(Parcel& parcel) const
612{
613    auto size = sysBarPropMap_.size();
614    if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
615        return false;
616    }
617    for (auto it : sysBarPropMap_) {
618        // write key(type)
619        if (!parcel.WriteUint32(static_cast<uint32_t>(it.first))) {
620            return false;
621        }
622        // write val(sysBarProps)
623        if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) &&
624            parcel.WriteUint32(it.second.contentColor_))) {
625            return false;
626        }
627    }
628    return true;
629}
630
631void WindowProperty::MapUnmarshalling(Parcel& parcel, WindowProperty* property)
632{
633    uint32_t size = parcel.ReadUint32();
634    if (size > SYSTEM_BAR_PROPERTY_MAX_NUM) {
635        return;
636    }
637    for (uint32_t i = 0; i < size; i++) {
638        WindowType type = static_cast<WindowType>(parcel.ReadUint32());
639        SystemBarProperty prop = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32() };
640        property->SetSystemBarProperty(type, prop);
641    }
642}
643
644bool WindowProperty::MarshallingTouchHotAreas(Parcel& parcel) const
645{
646    auto size = touchHotAreas_.size();
647    if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
648        return false;
649    }
650    for (const auto& rect : touchHotAreas_) {
651        if (!(parcel.WriteInt32(rect.posX_) && parcel.WriteInt32(rect.posY_) &&
652            parcel.WriteUint32(rect.width_) && parcel.WriteUint32(rect.height_))) {
653            return false;
654        }
655    }
656    return true;
657}
658
659void WindowProperty::UnmarshallingTouchHotAreas(Parcel& parcel, WindowProperty* property)
660{
661    uint32_t size = parcel.ReadUint32();
662    if (size > TOUCH_HOT_AREA_MAX_NUM) {
663        return;
664    }
665    for (uint32_t i = 0; i < size; i++) {
666        property->touchHotAreas_.emplace_back(
667            Rect{ parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() });
668    }
669}
670
671bool WindowProperty::MarshallingTransform(Parcel& parcel) const
672{
673    return parcel.WriteFloat(trans_.pivotX_) && parcel.WriteFloat(trans_.pivotY_) &&
674        parcel.WriteFloat(trans_.scaleX_) && parcel.WriteFloat(trans_.scaleY_) &&
675        parcel.WriteFloat(trans_.rotationX_) && parcel.WriteFloat(trans_.rotationY_) &&
676        parcel.WriteFloat(trans_.rotationZ_) && parcel.WriteFloat(trans_.translateX_) &&
677        parcel.WriteFloat(trans_.translateY_) && parcel.WriteFloat(trans_.translateZ_);
678}
679
680void WindowProperty::UnmarshallingTransform(Parcel& parcel, WindowProperty* property)
681{
682    Transform trans;
683    trans.pivotX_ = parcel.ReadFloat();
684    trans.pivotY_ = parcel.ReadFloat();
685    trans.scaleX_ = parcel.ReadFloat();
686    trans.scaleY_ = parcel.ReadFloat();
687    trans.rotationX_ = parcel.ReadFloat();
688    trans.rotationY_ = parcel.ReadFloat();
689    trans.rotationZ_ = parcel.ReadFloat();
690    trans.translateX_ = parcel.ReadFloat();
691    trans.translateY_ = parcel.ReadFloat();
692    trans.translateZ_ = parcel.ReadFloat();
693    property->SetTransform(trans);
694}
695
696bool WindowProperty::MarshallingWindowSizeLimits(Parcel& parcel) const
697{
698    if (parcel.WriteUint32(sizeLimits_.maxWidth_) &&
699        parcel.WriteUint32(sizeLimits_.maxHeight_) && parcel.WriteUint32(sizeLimits_.minWidth_) &&
700        parcel.WriteUint32(sizeLimits_.minHeight_) && parcel.WriteFloat(sizeLimits_.maxRatio_) &&
701        parcel.WriteFloat(sizeLimits_.minRatio_)) {
702        return true;
703    }
704    return false;
705}
706
707void WindowProperty::UnmarshallingWindowSizeLimits(Parcel& parcel, WindowProperty* property)
708{
709    WindowLimits sizeLimits = { parcel.ReadUint32(), parcel.ReadUint32(), parcel.ReadUint32(),
710                                parcel.ReadUint32(), parcel.ReadFloat(), parcel.ReadFloat() };
711    property->SetSizeLimits(sizeLimits);
712}
713
714bool WindowProperty::Marshalling(Parcel& parcel) const
715{
716    return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) &&
717        parcel.WriteInt32(windowRect_.posY_) && parcel.WriteUint32(windowRect_.width_) &&
718        parcel.WriteUint32(windowRect_.height_) && parcel.WriteInt32(requestRect_.posX_) &&
719        parcel.WriteInt32(requestRect_.posY_) && parcel.WriteUint32(requestRect_.width_) &&
720        parcel.WriteUint32(requestRect_.height_) && parcel.WriteBool(decoStatus_) &&
721        parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
722        parcel.WriteUint32(static_cast<uint32_t>(mode_)) && parcel.WriteUint32(static_cast<uint32_t>(lastMode_)) &&
723        parcel.WriteUint32(flags_) &&
724        parcel.WriteBool(isFullScreen_) && parcel.WriteBool(focusable_) && parcel.WriteBool(touchable_) &&
725        parcel.WriteBool(isPrivacyMode_) && parcel.WriteBool(isTransparent_) && parcel.WriteFloat(alpha_) &&
726        parcel.WriteFloat(brightness_) && parcel.WriteUint64(displayId_) && parcel.WriteUint32(windowId_) &&
727        parcel.WriteUint32(parentId_) && MapMarshalling(parcel) && parcel.WriteBool(isDecorEnable_) &&
728        parcel.WriteInt32(hitOffset_.x) && parcel.WriteInt32(hitOffset_.y) && parcel.WriteUint32(animationFlag_) &&
729        parcel.WriteUint32(static_cast<uint32_t>(windowSizeChangeReason_)) && parcel.WriteBool(tokenState_) &&
730        parcel.WriteUint32(callingWindow_) && parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_)) &&
731        parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) &&
732        parcel.WriteUint32(modeSupportInfo_) && parcel.WriteUint32(requestModeSupportInfo_) &&
733        parcel.WriteUint32(static_cast<uint32_t>(dragType_)) &&
734        parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) &&
735        parcel.WriteBool(isStretchable_) && MarshallingTouchHotAreas(parcel) && parcel.WriteUint32(accessTokenId_) &&
736        MarshallingTransform(parcel) && MarshallingWindowSizeLimits(parcel) && zoomTrans_.Marshalling(parcel) &&
737        parcel.WriteBool(isDisplayZoomOn_) && parcel.WriteString(abilityInfo_.bundleName_) &&
738        parcel.WriteString(abilityInfo_.abilityName_) && parcel.WriteInt32(abilityInfo_.missionId_) &&
739        parcel.WriteBool(isSnapshotSkip_) &&
740        parcel.WriteDouble(textFieldPositionY_) && parcel.WriteDouble(textFieldHeight_);
741}
742
743WindowProperty* WindowProperty::Unmarshalling(Parcel& parcel)
744{
745    WindowProperty* property = new(std::nothrow) WindowProperty();
746    if (property == nullptr) {
747        return nullptr;
748    }
749    property->SetWindowName(parcel.ReadString());
750    Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() };
751    property->SetWindowRect(rect);
752    Rect reqRect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() };
753    property->SetRequestRect(reqRect);
754    property->SetDecoStatus(parcel.ReadBool());
755    property->SetWindowType(static_cast<WindowType>(parcel.ReadUint32()));
756    property->SetWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
757    property->SetLastWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
758    property->SetWindowFlags(parcel.ReadUint32());
759    property->SetFullScreen(parcel.ReadBool());
760    property->SetFocusable(parcel.ReadBool());
761    property->SetTouchable(parcel.ReadBool());
762    property->SetPrivacyMode(parcel.ReadBool());
763    property->SetTransparent(parcel.ReadBool());
764    property->SetAlpha(parcel.ReadFloat());
765    property->SetBrightness(parcel.ReadFloat());
766    property->SetDisplayId(parcel.ReadUint64());
767    property->SetWindowId(parcel.ReadUint32());
768    property->SetParentId(parcel.ReadUint32());
769    MapUnmarshalling(parcel, property);
770    property->SetDecorEnable(parcel.ReadBool());
771    PointInfo offset = {parcel.ReadInt32(), parcel.ReadInt32()};
772    property->SetHitOffset(offset);
773    property->SetAnimationFlag(parcel.ReadUint32());
774    property->SetWindowSizeChangeReason(static_cast<WindowSizeChangeReason>(parcel.ReadUint32()));
775    property->SetTokenState(parcel.ReadBool());
776    property->SetCallingWindow(parcel.ReadUint32());
777    property->SetRequestedOrientation(static_cast<Orientation>(parcel.ReadUint32()));
778    property->SetTurnScreenOn(parcel.ReadBool());
779    property->SetKeepScreenOn(parcel.ReadBool());
780    property->SetModeSupportInfo(parcel.ReadUint32());
781    property->SetRequestModeSupportInfo(parcel.ReadUint32());
782    property->SetDragType(static_cast<DragType>(parcel.ReadUint32()));
783    uint32_t w = parcel.ReadUint32();
784    uint32_t h = parcel.ReadUint32();
785    property->SetOriginRect(Rect { 0, 0, w, h });
786    property->SetStretchable(parcel.ReadBool());
787    UnmarshallingTouchHotAreas(parcel, property);
788    property->SetAccessTokenId(parcel.ReadUint32());
789    UnmarshallingTransform(parcel, property);
790    UnmarshallingWindowSizeLimits(parcel, property);
791    Transform zoomTrans;
792    zoomTrans.Unmarshalling(parcel);
793    property->SetZoomTransform(zoomTrans);
794    property->SetDisplayZoomState(parcel.ReadBool());
795    AbilityInfo info = { parcel.ReadString(), parcel.ReadString(), parcel.ReadInt32() };
796    property->SetAbilityInfo(info);
797    property->SetSnapshotSkip(parcel.ReadBool());
798    property->SetTextFieldPositionY(parcel.ReadDouble());
799    property->SetTextFieldHeight(parcel.ReadDouble());
800    return property;
801}
802
803bool WindowProperty::Write(Parcel& parcel, PropertyChangeAction action)
804{
805    bool ret = parcel.WriteUint32(static_cast<uint32_t>(windowId_));
806    switch (action) {
807        case PropertyChangeAction::ACTION_UPDATE_RECT:
808            ret = ret && parcel.WriteBool(decoStatus_) && parcel.WriteUint32(static_cast<uint32_t>(dragType_)) &&
809                parcel.WriteInt32(originRect_.posX_) && parcel.WriteInt32(originRect_.posY_) &&
810                parcel.WriteUint32(originRect_.width_) && parcel.WriteUint32(originRect_.height_) &&
811                parcel.WriteInt32(requestRect_.posX_) && parcel.WriteInt32(requestRect_.posY_) &&
812                parcel.WriteUint32(requestRect_.width_) && parcel.WriteUint32(requestRect_.height_) &&
813                parcel.WriteUint32(static_cast<uint32_t>(windowSizeChangeReason_));
814            break;
815        case PropertyChangeAction::ACTION_UPDATE_MODE:
816            ret = ret && parcel.WriteUint32(static_cast<uint32_t>(mode_)) && parcel.WriteBool(isDecorEnable_);
817            break;
818        case PropertyChangeAction::ACTION_UPDATE_FLAGS:
819            ret = ret && parcel.WriteUint32(flags_);
820            break;
821        case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS:
822            ret = ret && MapMarshalling(parcel);
823            break;
824        case PropertyChangeAction::ACTION_UPDATE_FOCUSABLE:
825            ret = ret && parcel.WriteBool(focusable_);
826            break;
827        case PropertyChangeAction::ACTION_UPDATE_TOUCHABLE:
828            ret = ret && parcel.WriteBool(touchable_);
829            break;
830        case PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW:
831            ret = ret && parcel.WriteUint32(callingWindow_);
832            break;
833        case PropertyChangeAction::ACTION_UPDATE_ORIENTATION:
834            ret = ret && parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_));
835            break;
836        case PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON:
837            ret = ret && parcel.WriteBool(turnScreenOn_);
838            break;
839        case PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON:
840            ret = ret && parcel.WriteBool(keepScreenOn_);
841            break;
842        case PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS:
843            ret = ret && parcel.WriteFloat(brightness_);
844            break;
845        case PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO:
846            ret = ret && parcel.WriteUint32(modeSupportInfo_);
847            break;
848        case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
849            ret = ret && MarshallingTouchHotAreas(parcel);
850            break;
851        case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
852            ret = ret && MarshallingTransform(parcel);
853            break;
854        case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG:
855            ret = ret && parcel.WriteUint32(animationFlag_);
856            break;
857        case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE:
858            ret = ret && parcel.WriteBool(isPrivacyMode_) && parcel.WriteBool(isSystemPrivacyMode_);
859            break;
860        case PropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE:
861            ret = ret && parcel.WriteBool(isPrivacyMode_) && parcel.WriteBool(isSystemPrivacyMode_);
862            break;
863        case PropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP:
864            ret = ret && parcel.WriteBool(isSnapshotSkip_) && parcel.WriteBool(isSystemPrivacyMode_);
865            break;
866        case PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO:
867            ret = ret && parcel.WriteFloat(aspectRatio_);
868            break;
869        case PropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE:
870            ret = ret && parcel.WriteUint32(static_cast<uint32_t>(maximizeMode_));
871            break;
872        case PropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO:
873            ret = ret && parcel.WriteDouble(textFieldPositionY_) && parcel.WriteDouble(textFieldHeight_);
874            break;
875        default:
876            break;
877    }
878    return ret;
879}
880
881void WindowProperty::Read(Parcel& parcel, PropertyChangeAction action)
882{
883    SetWindowId(parcel.ReadUint32());
884    switch (action) {
885        case PropertyChangeAction::ACTION_UPDATE_RECT:
886            SetDecoStatus(parcel.ReadBool());
887            SetDragType(static_cast<DragType>(parcel.ReadUint32()));
888            SetOriginRect(Rect { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() });
889            SetRequestRect(Rect { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() });
890            SetWindowSizeChangeReason(static_cast<WindowSizeChangeReason>(parcel.ReadUint32()));
891            break;
892        case PropertyChangeAction::ACTION_UPDATE_MODE:
893            SetWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
894            SetDecorEnable(parcel.ReadBool());
895            break;
896        case PropertyChangeAction::ACTION_UPDATE_FLAGS:
897            SetWindowFlags(parcel.ReadUint32());
898            break;
899        case PropertyChangeAction::ACTION_UPDATE_OTHER_PROPS:
900            MapUnmarshalling(parcel, this);
901            break;
902        case PropertyChangeAction::ACTION_UPDATE_FOCUSABLE:
903            SetFocusable(parcel.ReadBool());
904            break;
905        case PropertyChangeAction::ACTION_UPDATE_TOUCHABLE:
906            SetTouchable(parcel.ReadBool());
907            break;
908        case PropertyChangeAction::ACTION_UPDATE_CALLING_WINDOW:
909            SetCallingWindow(parcel.ReadUint32());
910            break;
911        case PropertyChangeAction::ACTION_UPDATE_ORIENTATION:
912            SetRequestedOrientation(static_cast<Orientation>(parcel.ReadUint32()));
913            break;
914        case PropertyChangeAction::ACTION_UPDATE_TURN_SCREEN_ON:
915            SetTurnScreenOn(parcel.ReadBool());
916            break;
917        case PropertyChangeAction::ACTION_UPDATE_KEEP_SCREEN_ON:
918            SetKeepScreenOn(parcel.ReadBool());
919            break;
920        case PropertyChangeAction::ACTION_UPDATE_SET_BRIGHTNESS:
921            SetBrightness(parcel.ReadFloat());
922            break;
923        case PropertyChangeAction::ACTION_UPDATE_MODE_SUPPORT_INFO:
924            SetModeSupportInfo(parcel.ReadUint32());
925            break;
926        case PropertyChangeAction::ACTION_UPDATE_TOUCH_HOT_AREA:
927            UnmarshallingTouchHotAreas(parcel, this);
928            break;
929        case PropertyChangeAction::ACTION_UPDATE_TRANSFORM_PROPERTY:
930            UnmarshallingTransform(parcel, this);
931            break;
932        case PropertyChangeAction::ACTION_UPDATE_ANIMATION_FLAG: {
933            SetAnimationFlag(parcel.ReadUint32());
934            break;
935        }
936        case PropertyChangeAction::ACTION_UPDATE_PRIVACY_MODE:
937            SetPrivacyMode(parcel.ReadBool());
938            SetSystemPrivacyMode(parcel.ReadBool());
939            break;
940        case PropertyChangeAction::ACTION_UPDATE_SYSTEM_PRIVACY_MODE:
941            SetPrivacyMode(parcel.ReadBool());
942            SetSystemPrivacyMode(parcel.ReadBool());
943            break;
944        case PropertyChangeAction::ACTION_UPDATE_SNAPSHOT_SKIP:
945            SetSnapshotSkip(parcel.ReadBool());
946            SetSystemPrivacyMode(parcel.ReadBool());
947            break;
948        case PropertyChangeAction::ACTION_UPDATE_ASPECT_RATIO:
949            SetAspectRatio(parcel.ReadFloat());
950            break;
951        case PropertyChangeAction::ACTION_UPDATE_MAXIMIZE_STATE:
952            SetMaximizeMode(static_cast<MaximizeMode>(parcel.ReadUint32()));
953            break;
954        case PropertyChangeAction::ACTION_UPDATE_TEXTFIELD_AVOID_INFO:
955            SetTextFieldPositionY(parcel.ReadDouble());
956            SetTextFieldHeight(parcel.ReadDouble());
957            break;
958        default:
959            break;
960    }
961}
962
963void WindowProperty::CopyFrom(const sptr<WindowProperty>& property)
964{
965    windowName_ = property->windowName_;
966    windowRect_ = property->windowRect_;
967    requestRect_ = property->requestRect_;
968    decoStatus_ = property->decoStatus_;
969    type_ = property->type_;
970    mode_ = property->mode_;
971    lastMode_ = property->lastMode_;
972    flags_ = property->flags_;
973    isFullScreen_ = property->isFullScreen_;
974    focusable_ = property->focusable_;
975    touchable_ = property->touchable_;
976    isPrivacyMode_ = property->isPrivacyMode_;
977    isTransparent_ = property->isTransparent_;
978    alpha_ = property->alpha_;
979    brightness_ = property->brightness_;
980    displayId_ = property->displayId_;
981    windowId_ = property->windowId_;
982    parentId_ = property->parentId_;
983    hitOffset_ = property->hitOffset_;
984    animationFlag_ = property->animationFlag_;
985    windowSizeChangeReason_ = property->windowSizeChangeReason_;
986    sysBarPropMap_ = property->sysBarPropMap_;
987    isDecorEnable_ = property->isDecorEnable_;
988    tokenState_ = property->tokenState_;
989    callingWindow_ = property->callingWindow_;
990    requestedOrientation_ = property->requestedOrientation_;
991    turnScreenOn_ = property->turnScreenOn_;
992    keepScreenOn_ = property->keepScreenOn_;
993    modeSupportInfo_ = property->modeSupportInfo_;
994    requestModeSupportInfo_ = property->requestModeSupportInfo_;
995    dragType_ = property->dragType_;
996    originRect_ = property->originRect_;
997    isStretchable_ = property->isStretchable_;
998    touchHotAreas_ = property->touchHotAreas_;
999    accessTokenId_ = property->accessTokenId_;
1000    trans_ = property->trans_;
1001    sizeLimits_ = property->sizeLimits_;
1002    zoomTrans_ = property->zoomTrans_;
1003    isDisplayZoomOn_ = property->isDisplayZoomOn_;
1004    reCalcuZoomTransformMat_ = true;
1005    abilityInfo_ = property->abilityInfo_;
1006    isSnapshotSkip_ = property->isSnapshotSkip_;
1007    textFieldPositionY_ = property->textFieldPositionY_;
1008    textFieldHeight_ = property->textFieldHeight_;
1009}
1010void WindowProperty::SetTextFieldPositionY(double textFieldPositionY)
1011{
1012    textFieldPositionY_ = textFieldPositionY;
1013}
1014
1015void WindowProperty::SetTextFieldHeight(double textFieldHeight)
1016{
1017    textFieldHeight_ = textFieldHeight;
1018}
1019
1020double WindowProperty::GetTextFieldPositionY() const
1021{
1022    return textFieldPositionY_;
1023}
1024
1025double WindowProperty::GetTextFieldHeight() const
1026{
1027    return textFieldHeight_;
1028}
1029}
1030}
1031