• 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 
SetWindowRect(const struct Rect & rect)32 void WindowProperty::SetWindowRect(const struct Rect& rect)
33 {
34     windowRect_ = rect;
35 }
36 
SetWindowType(WindowType type)37 void WindowProperty::SetWindowType(WindowType type)
38 {
39     type_ = type;
40 }
41 
SetWindowMode(WindowMode mode)42 void WindowProperty::SetWindowMode(WindowMode mode)
43 {
44     if (!WindowHelper::IsValidWindowMode(mode)) {
45         return;
46     }
47     if (!WindowHelper::IsSplitWindowMode(mode_)) {
48         lastMode_ = mode_;
49     }
50     mode_ = mode;
51 }
52 
SetLastWindowMode(WindowMode mode)53 void WindowProperty::SetLastWindowMode(WindowMode mode)
54 {
55     lastMode_ = mode;
56 }
57 
SetWindowBackgroundBlur(WindowBlurLevel level)58 void WindowProperty::SetWindowBackgroundBlur(WindowBlurLevel level)
59 {
60     if (!WindowHelper::IsValidWindowBlurLevel(level)) {
61         return;
62     }
63     level_ = level;
64 }
65 
SetFullScreen(bool isFullScreen)66 void WindowProperty::SetFullScreen(bool isFullScreen)
67 {
68     isFullScreen_ = isFullScreen;
69 }
70 
SetFocusable(bool isFocusable)71 void WindowProperty::SetFocusable(bool isFocusable)
72 {
73     focusable_ = isFocusable;
74 }
75 
SetTouchable(bool isTouchable)76 void WindowProperty::SetTouchable(bool isTouchable)
77 {
78     touchable_ = isTouchable;
79 }
80 
SetPrivacyMode(bool isPrivate)81 void WindowProperty::SetPrivacyMode(bool isPrivate)
82 {
83     isPrivacyMode_ = isPrivate;
84 }
85 
SetTransparent(bool isTransparent)86 void WindowProperty::SetTransparent(bool isTransparent)
87 {
88     isTransparent_ = isTransparent;
89 }
90 
SetAlpha(float alpha)91 void WindowProperty::SetAlpha(float alpha)
92 {
93     alpha_ = alpha;
94 }
95 
SetBrightness(float brightness)96 void WindowProperty::SetBrightness(float brightness)
97 {
98     brightness_ = brightness;
99 }
100 
SetTurnScreenOn(bool turnScreenOn)101 void WindowProperty::SetTurnScreenOn(bool turnScreenOn)
102 {
103     turnScreenOn_ = turnScreenOn;
104 }
105 
SetKeepScreenOn(bool keepScreenOn)106 void WindowProperty::SetKeepScreenOn(bool keepScreenOn)
107 {
108     keepScreenOn_ = keepScreenOn;
109 }
110 
SetCallingWindow(uint32_t windowId)111 void WindowProperty::SetCallingWindow(uint32_t windowId)
112 {
113     callingWindow_ = windowId;
114 }
115 
SetDisplayId(DisplayId displayId)116 void WindowProperty::SetDisplayId(DisplayId displayId)
117 {
118     displayId_ = displayId;
119 }
120 
SetWindowFlags(uint32_t flags)121 void WindowProperty::SetWindowFlags(uint32_t flags)
122 {
123     flags_ = flags;
124 }
125 
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)126 void WindowProperty::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
127 {
128     if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
129         sysBarPropMap_[type] = property;
130     }
131 }
132 
SetDecorEnable(bool decorEnable)133 void WindowProperty::SetDecorEnable(bool decorEnable)
134 {
135     isDecorEnable_ = decorEnable;
136 }
137 
SetHitOffset(const PointInfo & offset)138 void WindowProperty::SetHitOffset(const PointInfo& offset)
139 {
140     hitOffset_ = offset;
141 }
142 
SetAnimationFlag(uint32_t animationFlag)143 void WindowProperty::SetAnimationFlag(uint32_t animationFlag)
144 {
145     animationFlag_ = animationFlag;
146 }
147 
SetWindowSizeChangeReason(WindowSizeChangeReason reason)148 void WindowProperty::SetWindowSizeChangeReason(WindowSizeChangeReason reason)
149 {
150     windowSizeChangeReason_ = reason;
151 }
152 
GetWindowSizeChangeReason() const153 WindowSizeChangeReason WindowProperty::GetWindowSizeChangeReason() const
154 {
155     return windowSizeChangeReason_;
156 }
157 
ResumeLastWindowMode()158 void WindowProperty::ResumeLastWindowMode()
159 {
160     mode_ = lastMode_;
161 }
162 
GetWindowName() const163 const std::string& WindowProperty::GetWindowName() const
164 {
165     return windowName_ ;
166 }
167 
GetWindowRect() const168 Rect WindowProperty::GetWindowRect() const
169 {
170     return windowRect_;
171 }
172 
GetWindowType() const173 WindowType WindowProperty::GetWindowType() const
174 {
175     return type_;
176 }
177 
GetWindowMode() const178 WindowMode WindowProperty::GetWindowMode() const
179 {
180     return mode_;
181 }
182 
GetLastWindowMode() const183 WindowMode WindowProperty::GetLastWindowMode() const
184 {
185     return lastMode_;
186 }
187 
GetWindowBackgroundBlur() const188 WindowBlurLevel WindowProperty::GetWindowBackgroundBlur() const
189 {
190     return level_;
191 }
192 
GetFullScreen() const193 bool WindowProperty::GetFullScreen() const
194 {
195     return isFullScreen_;
196 }
197 
GetFocusable() const198 bool WindowProperty::GetFocusable() const
199 {
200     return focusable_;
201 }
202 
GetTouchable() const203 bool WindowProperty::GetTouchable() const
204 {
205     return touchable_;
206 }
207 
GetCallingWindow() const208 uint32_t WindowProperty::GetCallingWindow() const
209 {
210     return callingWindow_;
211 }
212 
GetPrivacyMode() const213 bool WindowProperty::GetPrivacyMode() const
214 {
215     return isPrivacyMode_;
216 }
217 
GetTransparent() const218 bool WindowProperty::GetTransparent() const
219 {
220     return isTransparent_;
221 }
222 
GetAlpha() const223 float WindowProperty::GetAlpha() const
224 {
225     return alpha_;
226 }
227 
GetBrightness() const228 float WindowProperty::GetBrightness() const
229 {
230     return brightness_;
231 }
232 
IsTurnScreenOn() const233 bool WindowProperty::IsTurnScreenOn() const
234 {
235     return turnScreenOn_;
236 }
237 
IsKeepScreenOn() const238 bool WindowProperty::IsKeepScreenOn() const
239 {
240     return keepScreenOn_;
241 }
242 
GetDisplayId() const243 DisplayId WindowProperty::GetDisplayId() const
244 {
245     return displayId_;
246 }
247 
GetWindowFlags() const248 uint32_t WindowProperty::GetWindowFlags() const
249 {
250     return flags_;
251 }
252 
GetSystemBarProperty() const253 const std::unordered_map<WindowType, SystemBarProperty>& WindowProperty::GetSystemBarProperty() const
254 {
255     return sysBarPropMap_;
256 }
257 
GetDecorEnable() const258 bool WindowProperty::GetDecorEnable() const
259 {
260     return isDecorEnable_;
261 }
262 
SetWindowId(uint32_t windowId)263 void WindowProperty::SetWindowId(uint32_t windowId)
264 {
265     windowId_ = windowId;
266 }
267 
SetParentId(uint32_t parentId)268 void WindowProperty::SetParentId(uint32_t parentId)
269 {
270     parentId_ = parentId;
271 }
272 
GetWindowId() const273 uint32_t WindowProperty::GetWindowId() const
274 {
275     return windowId_;
276 }
277 
GetParentId() const278 uint32_t WindowProperty::GetParentId() const
279 {
280     return parentId_;
281 }
282 
GetHitOffset() const283 const PointInfo& WindowProperty::GetHitOffset() const
284 {
285     return hitOffset_;
286 }
287 
GetAnimationFlag() const288 uint32_t WindowProperty::GetAnimationFlag() const
289 {
290     return animationFlag_;
291 }
292 
MapMarshalling(Parcel & parcel) const293 bool WindowProperty::MapMarshalling(Parcel& parcel) const
294 {
295     auto size = sysBarPropMap_.size();
296     if (!parcel.WriteUint32(static_cast<uint32_t>(size))) {
297         return false;
298     }
299     for (auto it : sysBarPropMap_) {
300         // write key(type)
301         if (!parcel.WriteUint32(static_cast<uint32_t>(it.first))) {
302             return false;
303         }
304         // write val(sysBarProps)
305         if (!(parcel.WriteBool(it.second.enable_) && parcel.WriteUint32(it.second.backgroundColor_) &&
306             parcel.WriteUint32(it.second.contentColor_))) {
307             return false;
308         }
309     }
310     return true;
311 }
312 
MapUnmarshalling(Parcel & parcel,sptr<WindowProperty> & property)313 void WindowProperty::MapUnmarshalling(Parcel& parcel, sptr<WindowProperty>& property)
314 {
315     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap;
316     uint32_t size = parcel.ReadUint32();
317     for (uint32_t i = 0; i < size; i++) {
318         WindowType type = static_cast<WindowType>(parcel.ReadUint32());
319         SystemBarProperty prop = { parcel.ReadBool(), parcel.ReadUint32(), parcel.ReadUint32() };
320         property->SetSystemBarProperty(type, prop);
321     }
322 }
323 
Marshalling(Parcel & parcel) const324 bool WindowProperty::Marshalling(Parcel& parcel) const
325 {
326     return parcel.WriteString(windowName_) && parcel.WriteInt32(windowRect_.posX_) &&
327         parcel.WriteInt32(windowRect_.posY_) && parcel.WriteUint32(windowRect_.width_) &&
328         parcel.WriteUint32(windowRect_.height_) && parcel.WriteUint32(static_cast<uint32_t>(type_)) &&
329         parcel.WriteUint32(static_cast<uint32_t>(mode_)) && parcel.WriteUint32(static_cast<uint32_t>(lastMode_)) &&
330         parcel.WriteUint32(static_cast<uint32_t>(level_)) && parcel.WriteUint32(flags_) &&
331         parcel.WriteBool(isFullScreen_) && parcel.WriteBool(focusable_) && parcel.WriteBool(touchable_) &&
332         parcel.WriteBool(isPrivacyMode_) && parcel.WriteBool(isTransparent_) && parcel.WriteFloat(alpha_) &&
333         parcel.WriteFloat(brightness_) && parcel.WriteUint64(displayId_) && parcel.WriteUint32(windowId_) &&
334         parcel.WriteUint32(parentId_) && MapMarshalling(parcel) && parcel.WriteBool(isDecorEnable_) &&
335         parcel.WriteInt32(hitOffset_.x) && parcel.WriteInt32(hitOffset_.y) && parcel.WriteUint32(animationFlag_) &&
336         parcel.WriteUint32(static_cast<uint32_t>(windowSizeChangeReason_)) && parcel.WriteUint32(callingWindow_) &&
337         parcel.WriteBool(turnScreenOn_) && parcel.WriteBool(keepScreenOn_) &&
338         parcel.WriteUint32(static_cast<uint32_t>(requestedOrientation_));
339 }
340 
Unmarshalling(Parcel & parcel)341 sptr<WindowProperty> WindowProperty::Unmarshalling(Parcel& parcel)
342 {
343     sptr<WindowProperty> property(new WindowProperty());
344     property->SetWindowName(parcel.ReadString());
345     Rect rect = { parcel.ReadInt32(), parcel.ReadInt32(), parcel.ReadUint32(), parcel.ReadUint32() };
346     property->SetWindowRect(rect);
347     property->SetWindowType(static_cast<WindowType>(parcel.ReadUint32()));
348     property->SetWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
349     property->SetLastWindowMode(static_cast<WindowMode>(parcel.ReadUint32()));
350     property->SetWindowBackgroundBlur(static_cast<WindowBlurLevel>(parcel.ReadUint32()));
351     property->SetWindowFlags(parcel.ReadUint32());
352     property->SetFullScreen(parcel.ReadBool());
353     property->SetFocusable(parcel.ReadBool());
354     property->SetTouchable(parcel.ReadBool());
355     property->SetPrivacyMode(parcel.ReadBool());
356     property->SetTransparent(parcel.ReadBool());
357     property->SetAlpha(parcel.ReadFloat());
358     property->SetBrightness(parcel.ReadFloat());
359     property->SetDisplayId(parcel.ReadUint64());
360     property->SetWindowId(parcel.ReadUint32());
361     property->SetParentId(parcel.ReadUint32());
362     MapUnmarshalling(parcel, property);
363     property->SetDecorEnable(parcel.ReadBool());
364     PointInfo offset = {parcel.ReadInt32(), parcel.ReadInt32()};
365     property->SetHitOffset(offset);
366     property->SetAnimationFlag(parcel.ReadUint32());
367     property->SetWindowSizeChangeReason(static_cast<WindowSizeChangeReason>(parcel.ReadUint32()));
368     property->SetCallingWindow(parcel.ReadUint32());
369     property->SetTurnScreenOn(parcel.ReadBool());
370     property->SetKeepScreenOn(parcel.ReadBool());
371     property->SetRequestedOrientation(static_cast<Orientation>(parcel.ReadUint32()));
372     return property;
373 }
374 
CopyFrom(const sptr<WindowProperty> & property)375 void WindowProperty::CopyFrom(const sptr<WindowProperty>& property)
376 {
377     windowName_ = property->windowName_;
378     windowRect_ = property->windowRect_;
379     type_ = property->type_;
380     mode_ = property->mode_;
381     level_ = property->level_;
382     lastMode_ = property->lastMode_;
383     flags_ = property->flags_;
384     isFullScreen_ = property->isFullScreen_;
385     focusable_ = property->focusable_;
386     touchable_ = property->touchable_;
387     isPrivacyMode_ = property->isPrivacyMode_;
388     isTransparent_ = property->isTransparent_;
389     alpha_ = property->alpha_;
390     brightness_ = property->brightness_;
391     displayId_ = property->displayId_;
392     windowId_ = property->windowId_;
393     parentId_ = property->parentId_;
394     hitOffset_ = property->hitOffset_;
395     animationFlag_ = property->animationFlag_;
396     windowSizeChangeReason_ = property->windowSizeChangeReason_;
397     sysBarPropMap_ = property->sysBarPropMap_;
398     isDecorEnable_ = property->isDecorEnable_;
399     callingWindow_ = property->callingWindow_;
400     turnScreenOn_ = property->turnScreenOn_;
401     keepScreenOn_ = property->keepScreenOn_;
402     requestedOrientation_ = property->requestedOrientation_;
403 }
404 }
405 }
406