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 struct Rect & rect)26 void WindowOption::SetWindowRect(const struct 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
SetTurnScreenOn(bool turnScreenOn)192 void WindowOption::SetTurnScreenOn(bool turnScreenOn)
193 {
194 turnScreenOn_ = turnScreenOn;
195 }
196
IsTurnScreenOn() const197 bool WindowOption::IsTurnScreenOn() const
198 {
199 return turnScreenOn_;
200 }
201
SetBrightness(float brightness)202 void WindowOption::SetBrightness(float brightness)
203 {
204 brightness_ = brightness;
205 }
206
GetBrightness() const207 float WindowOption::GetBrightness() const
208 {
209 return brightness_;
210 }
211
SetCallingWindow(uint32_t windowId)212 void WindowOption::SetCallingWindow(uint32_t windowId)
213 {
214 callingWindow_ = windowId;
215 }
216
GetCallingWindow() const217 uint32_t WindowOption::GetCallingWindow() const
218 {
219 return callingWindow_;
220 }
221
GetRequestedOrientation() const222 Orientation WindowOption::GetRequestedOrientation() const
223 {
224 return requestedOrientation_;
225 }
226
SetRequestedOrientation(Orientation orientation)227 void WindowOption::SetRequestedOrientation(Orientation orientation)
228 {
229 requestedOrientation_ = orientation;
230 }
231
SetBundleName(const std::string bundleName)232 void WindowOption::SetBundleName(const std::string bundleName)
233 {
234 bundleName_ = bundleName;
235 }
236
GetBundleName() const237 const std::string WindowOption::GetBundleName() const
238 {
239 return bundleName_;
240 }
241
SetSubWindowTitle(const std::string & subWindowTitle)242 void WindowOption::SetSubWindowTitle(const std::string& subWindowTitle)
243 {
244 subWindowTitle_ = subWindowTitle;
245 }
246
GetSubWindowTitle() const247 std::string WindowOption::GetSubWindowTitle() const
248 {
249 return subWindowTitle_;
250 }
251
SetSubWindowDecorEnable(bool subWindowDecorEnable)252 void WindowOption::SetSubWindowDecorEnable(bool subWindowDecorEnable)
253 {
254 subWindowDecorEnable_ = subWindowDecorEnable;
255 }
256
GetSubWindowDecorEnable() const257 bool WindowOption::GetSubWindowDecorEnable() const
258 {
259 return subWindowDecorEnable_;
260 }
261
SetOnlySupportSceneBoard(bool onlySupportSceneBoard)262 void WindowOption::SetOnlySupportSceneBoard(bool onlySupportSceneBoard)
263 {
264 onlySupportSceneBoard_ = onlySupportSceneBoard;
265 }
266
GetOnlySupportSceneBoard() const267 bool WindowOption::GetOnlySupportSceneBoard() const
268 {
269 return onlySupportSceneBoard_;
270 }
271
SetRealParentId(int32_t realParentId)272 void WindowOption::SetRealParentId(int32_t realParentId)
273 {
274 realParentId_ = realParentId;
275 }
276
GetRealParentId() const277 int32_t WindowOption::GetRealParentId() const
278 {
279 return realParentId_;
280 }
281
SetParentWindowType(WindowType parentWindowType)282 void WindowOption::SetParentWindowType(WindowType parentWindowType)
283 {
284 parentWindowType_ = parentWindowType;
285 }
286
GetParentWindowType() const287 WindowType WindowOption::GetParentWindowType() const
288 {
289 return parentWindowType_;
290 }
291
SetExtensionTag(bool isExtensionTag)292 void WindowOption::SetExtensionTag(bool isExtensionTag)
293 {
294 isExtensionTag_ = isExtensionTag;
295 }
296
GetExtensionTag() const297 bool WindowOption::GetExtensionTag() const
298 {
299 return isExtensionTag_;
300 }
301
SetUIExtensionUsage(uint32_t uiExtensionUsage)302 void WindowOption::SetUIExtensionUsage(uint32_t uiExtensionUsage)
303 {
304 if (uiExtensionUsage < static_cast<uint32_t>(UIExtensionUsage::UIEXTENSION_USAGE_END)) {
305 uiExtensionUsage_ = uiExtensionUsage;
306 } else {
307 uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::EMBEDDED);
308 }
309 }
310
GetUIExtensionUsage() const311 uint32_t WindowOption::GetUIExtensionUsage() const
312 {
313 return uiExtensionUsage_;
314 }
315
SetDialogDecorEnable(bool decorEnable)316 void WindowOption::SetDialogDecorEnable(bool decorEnable)
317 {
318 dialogDecorEnable_ = decorEnable;
319 }
320
SetIsUIExtensionSubWindowFlag(bool isUIExtensionSubWindowFlag)321 void WindowOption::SetIsUIExtensionSubWindowFlag(bool isUIExtensionSubWindowFlag)
322 {
323 isUIExtensionSubWindowFlag_ = isUIExtensionSubWindowFlag;
324 }
325
GetIsUIExtensionSubWindowFlag() const326 bool WindowOption::GetIsUIExtensionSubWindowFlag() const
327 {
328 return isUIExtensionSubWindowFlag_;
329 }
330
GetDialogDecorEnable() const331 bool WindowOption::GetDialogDecorEnable() const
332 {
333 return dialogDecorEnable_;
334 }
335
SetDialogTitle(const std::string & dialogTitle)336 void WindowOption::SetDialogTitle(const std::string& dialogTitle)
337 {
338 dialogTitle_ = dialogTitle;
339 }
340
GetDialogTitle() const341 std::string WindowOption::GetDialogTitle() const
342 {
343 return dialogTitle_;
344 }
345
SetWindowTopmost(bool isTopmost)346 void WindowOption::SetWindowTopmost(bool isTopmost)
347 {
348 isTopmost_ = isTopmost;
349 }
350
GetWindowTopmost() const351 bool WindowOption::GetWindowTopmost() const
352 {
353 return isTopmost_;
354 }
355
356 } // namespace Rosen
357 } // namespace OHOS
358
359