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