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_option.h"
17 #include "window_helper.h"
18 #include "wm_common.h"
19
20 namespace OHOS {
21 namespace Rosen {
WindowOption()22 WindowOption::WindowOption(): windowTag_(WindowTag::SYSTEM_WINDOW)
23 {
24 }
25
SetWindowRect(const Rect & rect)26 void WindowOption::SetWindowRect(const Rect& rect)
27 {
28 windowRect_ = rect;
29 }
30
SetWindowType(WindowType type)31 void WindowOption::SetWindowType(WindowType type)
32 {
33 type_ = type;
34 }
35
SetWindowMode(WindowMode mode)36 void WindowOption::SetWindowMode(WindowMode mode)
37 {
38 if (!WindowHelper::IsValidWindowMode(mode)) {
39 return;
40 }
41 mode_ = mode;
42 }
43
SetFocusable(bool isFocusable)44 void WindowOption::SetFocusable(bool isFocusable)
45 {
46 focusable_ = isFocusable;
47 }
48
SetTouchable(bool isTouchable)49 void WindowOption::SetTouchable(bool isTouchable)
50 {
51 touchable_ = isTouchable;
52 }
53
SetDisplayId(DisplayId displayId)54 void WindowOption::SetDisplayId(DisplayId displayId)
55 {
56 displayId_ = displayId;
57 }
58
SetParentId(uint32_t parentId)59 void WindowOption::SetParentId(uint32_t parentId)
60 {
61 parentId_ = parentId;
62 }
63
SetWindowName(const std::string & windowName)64 void WindowOption::SetWindowName(const std::string& windowName)
65 {
66 windowName_ = windowName;
67 }
68
AddWindowFlag(WindowFlag flag)69 void WindowOption::AddWindowFlag(WindowFlag flag)
70 {
71 flags_ |= static_cast<uint32_t>(flag);
72 }
73
RemoveWindowFlag(WindowFlag flag)74 void WindowOption::RemoveWindowFlag(WindowFlag flag)
75 {
76 flags_ &= ~(static_cast<uint32_t>(flag));
77 }
78
SetWindowFlags(uint32_t flags)79 void WindowOption::SetWindowFlags(uint32_t flags)
80 {
81 flags_ = flags;
82 }
83
SetSystemBarProperty(WindowType type,const SystemBarProperty & property)84 void WindowOption::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
85 {
86 if (type == WindowType::WINDOW_TYPE_STATUS_BAR || type == WindowType::WINDOW_TYPE_NAVIGATION_BAR) {
87 sysBarPropMap_[type] = property;
88 }
89 }
90
GetWindowRect() const91 Rect WindowOption::GetWindowRect() const
92 {
93 return windowRect_;
94 }
95
GetWindowType() const96 WindowType WindowOption::GetWindowType() const
97 {
98 return type_;
99 }
100
GetWindowMode() const101 WindowMode WindowOption::GetWindowMode() const
102 {
103 return mode_;
104 }
105
GetFocusable() const106 bool WindowOption::GetFocusable() const
107 {
108 return focusable_;
109 }
110
GetTouchable() const111 bool WindowOption::GetTouchable() const
112 {
113 return touchable_;
114 }
115
GetDisplayId() const116 DisplayId WindowOption::GetDisplayId() const
117 {
118 return displayId_;
119 }
120
GetParentId() const121 uint32_t WindowOption::GetParentId() const
122 {
123 return parentId_;
124 }
125
GetWindowName() const126 const std::string& WindowOption::GetWindowName() const
127 {
128 return windowName_;
129 }
130
GetWindowFlags() const131 uint32_t WindowOption::GetWindowFlags() const
132 {
133 return flags_;
134 }
135
SetHitOffset(int32_t x,int32_t y)136 void WindowOption::SetHitOffset(int32_t x, int32_t y)
137 {
138 hitOffset_.x = x;
139 hitOffset_.y = y;
140 }
141
SetWindowTag(WindowTag windowTag)142 void WindowOption::SetWindowTag(WindowTag windowTag)
143 {
144 windowTag_ = windowTag;
145 }
146
GetWindowTag() const147 WindowTag WindowOption::GetWindowTag() const
148 {
149 return windowTag_;
150 }
151
SetWindowSessionType(WindowSessionType sessionType)152 void WindowOption::SetWindowSessionType(WindowSessionType sessionType)
153 {
154 sessionType_ = sessionType;
155 }
156
GetWindowSessionType() const157 WindowSessionType WindowOption::GetWindowSessionType() const
158 {
159 return sessionType_;
160 }
161
SetMainHandlerAvailable(bool isMainHandlerAvailable)162 void WindowOption::SetMainHandlerAvailable(bool isMainHandlerAvailable)
163 {
164 isMainHandlerAvailable_ = isMainHandlerAvailable;
165 }
166
GetMainHandlerAvailable() const167 bool WindowOption::GetMainHandlerAvailable() const
168 {
169 return isMainHandlerAvailable_;
170 }
171
GetHitOffset() const172 const PointInfo& WindowOption::GetHitOffset() const
173 {
174 return hitOffset_;
175 }
176
GetSystemBarProperty() const177 const std::unordered_map<WindowType, SystemBarProperty>& WindowOption::GetSystemBarProperty() const
178 {
179 return sysBarPropMap_;
180 }
181
SetKeepScreenOn(bool keepScreenOn)182 void WindowOption::SetKeepScreenOn(bool keepScreenOn)
183 {
184 keepScreenOn_ = keepScreenOn;
185 }
186
IsKeepScreenOn() const187 bool WindowOption::IsKeepScreenOn() const
188 {
189 return keepScreenOn_;
190 }
191
SetViewKeepScreenOn(bool keepScreenOn)192 void WindowOption::SetViewKeepScreenOn(bool keepScreenOn)
193 {
194 viewKeepScreenOn_ = keepScreenOn;
195 }
196
IsViewKeepScreenOn() const197 bool WindowOption::IsViewKeepScreenOn() const
198 {
199 return viewKeepScreenOn_;
200 }
201
SetTurnScreenOn(bool turnScreenOn)202 void WindowOption::SetTurnScreenOn(bool turnScreenOn)
203 {
204 turnScreenOn_ = turnScreenOn;
205 }
206
IsTurnScreenOn() const207 bool WindowOption::IsTurnScreenOn() const
208 {
209 return turnScreenOn_;
210 }
211
SetBrightness(float brightness)212 void WindowOption::SetBrightness(float brightness)
213 {
214 brightness_ = brightness;
215 }
216
GetBrightness() const217 float WindowOption::GetBrightness() const
218 {
219 return brightness_;
220 }
221
SetCallingWindow(uint32_t windowId)222 void WindowOption::SetCallingWindow(uint32_t windowId)
223 {
224 callingWindow_ = windowId;
225 }
226
GetCallingWindow() const227 uint32_t WindowOption::GetCallingWindow() const
228 {
229 return callingWindow_;
230 }
231
GetRequestedOrientation() const232 Orientation WindowOption::GetRequestedOrientation() const
233 {
234 return requestedOrientation_;
235 }
236
SetRequestedOrientation(Orientation orientation)237 void WindowOption::SetRequestedOrientation(Orientation orientation)
238 {
239 requestedOrientation_ = orientation;
240 }
241
SetBundleName(const std::string bundleName)242 void WindowOption::SetBundleName(const std::string bundleName)
243 {
244 bundleName_ = bundleName;
245 }
246
GetBundleName() const247 const std::string WindowOption::GetBundleName() const
248 {
249 return bundleName_;
250 }
251
SetSubWindowMaximizeSupported(bool maximizeSupported)252 void WindowOption::SetSubWindowMaximizeSupported(bool maximizeSupported)
253 {
254 subWindowMaximizeSupported_ = maximizeSupported;
255 }
256
GetSubWindowMaximizeSupported() const257 bool WindowOption::GetSubWindowMaximizeSupported() const
258 {
259 return subWindowMaximizeSupported_;
260 }
261
SetSubWindowTitle(const std::string & subWindowTitle)262 void WindowOption::SetSubWindowTitle(const std::string& subWindowTitle)
263 {
264 subWindowTitle_ = subWindowTitle;
265 }
266
GetSubWindowTitle() const267 std::string WindowOption::GetSubWindowTitle() const
268 {
269 return subWindowTitle_;
270 }
271
SetSubWindowDecorEnable(bool subWindowDecorEnable)272 void WindowOption::SetSubWindowDecorEnable(bool subWindowDecorEnable)
273 {
274 subWindowDecorEnable_ = subWindowDecorEnable;
275 }
276
GetSubWindowDecorEnable() const277 bool WindowOption::GetSubWindowDecorEnable() const
278 {
279 return subWindowDecorEnable_;
280 }
281
SetOnlySupportSceneBoard(bool onlySupportSceneBoard)282 void WindowOption::SetOnlySupportSceneBoard(bool onlySupportSceneBoard)
283 {
284 onlySupportSceneBoard_ = onlySupportSceneBoard;
285 }
286
GetOnlySupportSceneBoard() const287 bool WindowOption::GetOnlySupportSceneBoard() const
288 {
289 return onlySupportSceneBoard_;
290 }
291
SetRealParentId(int32_t realParentId)292 void WindowOption::SetRealParentId(int32_t realParentId)
293 {
294 realParentId_ = realParentId;
295 }
296
GetRealParentId() const297 int32_t WindowOption::GetRealParentId() const
298 {
299 return realParentId_;
300 }
301
SetParentWindowType(WindowType parentWindowType)302 void WindowOption::SetParentWindowType(WindowType parentWindowType)
303 {
304 parentWindowType_ = parentWindowType;
305 }
306
GetParentWindowType() const307 WindowType WindowOption::GetParentWindowType() const
308 {
309 return parentWindowType_;
310 }
311
SetIsUIExtFirstSubWindow(bool isUIExtFirstSubWindow)312 void WindowOption::SetIsUIExtFirstSubWindow(bool isUIExtFirstSubWindow)
313 {
314 isUIExtFirstSubWindow_ = isUIExtFirstSubWindow;
315 }
316
GetIsUIExtFirstSubWindow() const317 bool WindowOption::GetIsUIExtFirstSubWindow() const
318 {
319 return isUIExtFirstSubWindow_;
320 }
321
SetUIExtensionUsage(uint32_t uiExtensionUsage)322 void WindowOption::SetUIExtensionUsage(uint32_t uiExtensionUsage)
323 {
324 if (uiExtensionUsage < static_cast<uint32_t>(UIExtensionUsage::UIEXTENSION_USAGE_END)) {
325 uiExtensionUsage_ = uiExtensionUsage;
326 } else {
327 uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::EMBEDDED);
328 }
329 }
330
GetUIExtensionUsage() const331 uint32_t WindowOption::GetUIExtensionUsage() const
332 {
333 return uiExtensionUsage_;
334 }
335
SetDialogDecorEnable(bool decorEnable)336 void WindowOption::SetDialogDecorEnable(bool decorEnable)
337 {
338 dialogDecorEnable_ = decorEnable;
339 }
340
SetIsUIExtAnySubWindow(bool isUIExtAnySubWindow)341 void WindowOption::SetIsUIExtAnySubWindow(bool isUIExtAnySubWindow)
342 {
343 isUIExtAnySubWindow_ = isUIExtAnySubWindow;
344 }
345
GetIsUIExtAnySubWindow() const346 bool WindowOption::GetIsUIExtAnySubWindow() const
347 {
348 return isUIExtAnySubWindow_;
349 }
350
GetDialogDecorEnable() const351 bool WindowOption::GetDialogDecorEnable() const
352 {
353 return dialogDecorEnable_;
354 }
355
SetDialogTitle(const std::string & dialogTitle)356 void WindowOption::SetDialogTitle(const std::string& dialogTitle)
357 {
358 dialogTitle_ = dialogTitle;
359 }
360
GetDialogTitle() const361 std::string WindowOption::GetDialogTitle() const
362 {
363 return dialogTitle_;
364 }
365
SetWindowTopmost(bool isTopmost)366 void WindowOption::SetWindowTopmost(bool isTopmost)
367 {
368 isTopmost_ = isTopmost;
369 }
370
GetWindowTopmost() const371 bool WindowOption::GetWindowTopmost() const
372 {
373 return isTopmost_;
374 }
375
SetSubWindowZLevel(int32_t zLevel)376 void WindowOption::SetSubWindowZLevel(int32_t zLevel)
377 {
378 zLevel_ = zLevel;
379 }
380
GetSubWindowZLevel() const381 int32_t WindowOption::GetSubWindowZLevel() const
382 {
383 return zLevel_;
384 }
385
SetIsSystemKeyboard(bool isSystemKeyboard)386 void WindowOption::SetIsSystemKeyboard(bool isSystemKeyboard)
387 {
388 isSystemKeyboard_ = isSystemKeyboard;
389 }
390
IsSystemKeyboard() const391 bool WindowOption::IsSystemKeyboard() const
392 {
393 return isSystemKeyboard_;
394 }
395
SetDensity(float density)396 void WindowOption::SetDensity(float density)
397 {
398 density_ = density;
399 }
400
GetDensity() const401 float WindowOption::GetDensity() const
402 {
403 return density_;
404 }
405
SetIsDensityFollowHost(bool isDensityFollowHost)406 void WindowOption::SetIsDensityFollowHost(bool isDensityFollowHost)
407 {
408 isDensityFollowHost_ = isDensityFollowHost;
409 }
410
GetIsDensityFollowHost() const411 bool WindowOption::GetIsDensityFollowHost() const
412 {
413 return isDensityFollowHost_;
414 }
415
SetConstrainedModal(bool isConstrainedModal)416 void WindowOption::SetConstrainedModal(bool isConstrainedModal)
417 {
418 isConstrainedModal_ = (uiExtensionUsage_ == static_cast<uint32_t>(UIExtensionUsage::MODAL)) && isConstrainedModal;
419 }
420
IsConstrainedModal() const421 bool WindowOption::IsConstrainedModal() const
422 {
423 return isConstrainedModal_;
424 }
425
426 } // namespace Rosen
427 } // namespace OHOS
428
429