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