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 #ifndef OHOS_ROSEN_WINDOW_OPTION_H
17 #define OHOS_ROSEN_WINDOW_OPTION_H
18 #include <refbase.h>
19 #include <string>
20 #include <unordered_map>
21 
22 #include "dm_common.h"
23 #include "wm_common.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 /**
28  * @class WindowOption
29  * WindowOption is used to create a window.
30  */
31 class WindowOption : public RefBase {
32 public:
33     /**
34      * @brief Default construct of WindowOption.
35      */
36     WindowOption();
37 
38     /**
39      * @brief Deconstruct of WindowOption.
40      */
41     virtual ~WindowOption() = default;
42 
43     /**
44      * @brief Set window rect.
45      *
46      * @param rect The rect of window to set window position and size.
47      */
48     void SetWindowRect(const struct Rect& rect);
49 
50     /**
51      * @brief Set window type.
52      *
53      * @param type The type of window.
54      */
55     void SetWindowType(WindowType type);
56 
57     /**
58      * @brief Set window mode.
59      *
60      * @param mode The mode of window.
61      */
62     void SetWindowMode(WindowMode mode);
63 
64     /**
65      * @brief Set window focusable.
66      *
67      * @param isFocusable True means the window can be focused, otherwise not.
68      */
69     void SetFocusable(bool isFocusable);
70 
71     /**
72      * @brief Set window touchable.
73      *
74      * @param isTouchable True means the window can be touched, otherwise not.
75      */
76     void SetTouchable(bool isTouchable);
77 
78     /**
79      * @brief Set display id.
80      *
81      * @param displayId The display id of window.
82      */
83     void SetDisplayId(DisplayId displayId);
84 
85     /**
86      * @brief Set parent id.
87      *
88      * @param parentId The parent window id.
89      */
90     void SetParentId(uint32_t parentId);
91 
92     /**
93      * @brief Set window name.
94      *
95      * @param windowName The window name.
96      */
97     void SetWindowName(const std::string& windowName);
98 
99     /**
100      * @brief Set bundle name.
101      *
102      * @param bundleName The bundle name.
103      */
104     void SetBundleName(const std::string bundleName);
105 
106     /**
107      * @brief Add window flag.
108      *
109      * @param flag The flag value added.
110      */
111     void AddWindowFlag(WindowFlag flag);
112 
113     /**
114      * @brief Remove winodw flag.
115      *
116      * @param flag The flag value removed.
117      */
118     void RemoveWindowFlag(WindowFlag flag);
119 
120     /**
121      * @brief Set window flags.
122      *
123      * @param flags The flag value.
124      */
125     void SetWindowFlags(uint32_t flags);
126 
127     /**
128      * @brief Set system bar property.
129      *
130      * @param type The system bar window type.
131      * @param property The system bar property.
132      */
133     void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
134 
135     /**
136      * @brief Set hit offset.
137      *
138      * @param x The position x of hit offset.
139      * @param y The position y of hit offset.
140      */
141     void SetHitOffset(int32_t x, int32_t y);
142     /**
143      * @brief Set window tag.
144      *
145      * @param windowTag The tag of window.
146      */
147     void SetWindowTag(WindowTag windowTag);
148 
149     /**
150      * @brief Set window session type.
151      *
152      * @param sessionType The session type of window.
153      */
154     void SetWindowSessionType(WindowSessionType sessionType);
155 
156     /**
157      * @brief Set keep screen on.
158      *
159      * @param keepScreenOn The window keep screen on or not.
160      */
161     void SetKeepScreenOn(bool keepScreenOn);
162 
163     /**
164      * @brief Is keep screen on.
165      *
166      * @return Return true means the window would keep screen on, otherwise not.
167      */
168     bool IsKeepScreenOn() const;
169 
170     /**
171      * @brief Set screen on.
172      *
173      * @param turnScreenOn mark the window to turn the screen on or not.
174      */
175     void SetTurnScreenOn(bool turnScreenOn);
176 
177     /**
178      * @brief Is turned screen on.
179      *
180      * @return The window is marked to turn the screen on or not.
181      */
182     bool IsTurnScreenOn() const;
183 
184     /**
185      * @brief Set window brightness.
186      *
187      * @param brightness The brightness of screen. the value is between 0.0 ~ 1.0.
188      */
189     void SetBrightness(float brightness);
190 
191     /**
192      * @brief Set window requested orientation.
193      *
194      * @param orientation The requested orientation of window.
195      */
196     void SetRequestedOrientation(Orientation orientation);
197 
198     /**
199      * @brief Set window calling window id.
200      *
201      * @param windowId The window id of calling window.
202      */
203     void SetCallingWindow(uint32_t windowId);
204 
205     /**
206      * @brief Set window main handler available.
207      *
208      * @param isMainHandlerAvailable is window main handler available.
209      */
210     void SetMainHandlerAvailable(bool isMainHandlerAvailable);
211 
212     /**
213      * @brief Set subwindow title.
214      *
215      * @param subWindowTitle the subwindow title.
216      */
217     void SetSubWindowTitle(const std::string& subWindowTitle);
218 
219     /**
220      * @brief Set subwindow decor enable.
221      *
222      * @param subWindowDecorEnable the subwindow decor enable.
223      */
224     void SetSubWindowDecorEnable(bool subWindowDecorEnable);
225 
226     /**
227      * @brief Set only sceneboard supported.
228      *
229      * @param onlySupportSceneBoard only sceneboard supported.
230      */
231     void SetOnlySupportSceneBoard(bool onlySupportSceneBoard);
232 
233     /**
234      * @brief Set ExtensionSubWindow tag.
235      *
236      * @param isExtensionTag ExtensionSubWindow tag.
237      */
238     void SetExtensionTag(bool isExtensionTag);
239 
240     /**
241      * @brief Set UIExtension usage.
242      *
243      * @param uiExtensionUsage UIExtension usage.
244      */
245     void SetUIExtensionUsage(uint32_t uiExtensionUsage);
246 
247     /**
248      * @brief Set Dialog Decor Enable Or Not.
249      *
250      * @param decorEnable true means enable, default disabled.
251      */
252     void SetDialogDecorEnable(bool decorEnable);
253 
254     /**
255      * @brief Set Dialog title.
256      *
257      * @param dialogTitle true means enable, default disabled.
258      */
259     void SetDialogTitle(const std::string& dialogTitle);
260 
261     /**
262      * @brief Set window topmost.
263      *
264      * @param isTopmost true means enable, default disabled.
265      */
266     void SetWindowTopmost(bool isTopmost);
267 
268     /**
269      * @brief Set real parent id of UIExtension
270      *
271      * @param realParentId real parent id of UIExtension
272      */
273     void SetRealParentId(int32_t realParentId);
274 
275     /**
276      * @brief Set parent window type of UIExtension
277      *
278      * @param parentWindowType Parent window type of UIExtension
279      */
280     void SetParentWindowType(WindowType parentWindowType);
281 
282     /**
283      * @brief Get window rect.
284      *
285      * @return The rect of window.
286      */
287     Rect GetWindowRect() const;
288 
289     /**
290      * @brief Get window type.
291      *
292      * @return The type of window.
293      */
294     WindowType GetWindowType() const;
295 
296     /**
297      * @brief Get window mode.
298      *
299      * @return The mode of window.
300      */
301     WindowMode GetWindowMode() const;
302 
303     /**
304      * @brief Get window focusable.
305      *
306      * @return Return true means the window is focusable, otherwise not.
307      */
308     bool GetFocusable() const;
309 
310     /**
311      * @brief Get window touchable.
312      *
313      * @return Return true means the window is touchable, otherwise not.
314      */
315     bool GetTouchable() const;
316 
317     /**
318      * @brief Get display id.
319      *
320      * @return Return diplay id.
321      */
322     DisplayId GetDisplayId() const;
323 
324     /**
325      * @brief Get parent id.
326      *
327      * @return Return parent window id.
328      */
329     uint32_t GetParentId() const;
330 
331     /**
332      * @brief Get window name.
333      *
334      * @return Return the window name.
335      */
336     const std::string& GetWindowName() const;
337 
338     /**
339      * @brief Get bundle name.
340      *
341      * @return Return the bundle name.
342      */
343     const std::string GetBundleName() const;
344 
345     /**
346      * @brief Get window flags.
347      *
348      * @return Return the window flags.
349      */
350     uint32_t GetWindowFlags() const;
351 
352     /**
353      * @brief Get system bar property.
354      *
355      * @return Return system bar property map.
356      */
357     const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
358 
359     /**
360      * @brief Get window hit offset.
361      *
362      * @return Return hit offset value as PointInfo.
363      */
364     const PointInfo& GetHitOffset() const;
365 
366     /**
367      * @brief Get window tag.
368      *
369      * @return Return window tag.
370      */
371     WindowTag GetWindowTag() const;
372 
373     /**
374      * @brief Get window session type.
375      *
376      * @return Return window session type.
377      */
378     WindowSessionType GetWindowSessionType() const;
379 
380     /**
381      * @brief Get window brightness.
382      *
383      * @return Return screen brightness.
384      */
385     float GetBrightness() const;
386 
387     /**
388      * @brief Get window request orientation.
389      *
390      * @return Return window requested orientation.
391      */
392     Orientation GetRequestedOrientation() const;
393 
394     /**
395      * @brief Get calling window id.
396      *
397      * @return Return the calling window id of window.
398      */
399     uint32_t GetCallingWindow() const;
400 
401     /**
402      * @brief Get main handler available
403      *
404      * @return Return true means the main handler available, otherwise not.
405      */
406     bool GetMainHandlerAvailable() const;
407 
408     /**
409      * @brief Get subwindow title
410      *
411      * @return Return the subwindow title
412     */
413     std::string GetSubWindowTitle() const;
414 
415     /**
416      * @brief Get subwindow decor enable
417      *
418      * @return Return ture means the subwindow decor enabled, otherwise not.
419     */
420     bool GetSubWindowDecorEnable() const;
421 
422     /**
423      * @brief Get only sceneboard supported
424      *
425      * @return Return ture means only sceneboard supported, otherwise not.
426     */
427     bool GetOnlySupportSceneBoard() const;
428 
429     /**
430      * @brief Get only sceneboard supported
431      *
432      * @return Return ExtensionTag of subwindow.
433     */
434     bool GetExtensionTag() const;
435 
436     /**
437      * @brief Get UIExtension usage.
438      *
439      * @param Return UIExtension usage.
440      */
441     uint32_t GetUIExtensionUsage() const;
442 
443     /**
444      * @brief Get dialog decor enable
445      *
446      * @return true means the dialog decor is enabled, otherwise not.
447     */
448     bool GetDialogDecorEnable() const;
449 
450     /**
451      * @brief Get dialog title
452      *
453      * @return Return the dialog title
454     */
455     std::string GetDialogTitle() const;
456 
457     /**
458      * @brief Get window topmost
459      *
460      * @return true means the window is topmost, otherwise not.
461     */
462     bool GetWindowTopmost() const;
463 
464     /**
465      * @brief Get the real parent id of UIExtension
466      *
467      * @return Return the real parent id of UIExtension
468      */
469     int32_t GetRealParentId() const;
470 
471     /*
472      * @brief Get the parent window type of UIExtension
473      *
474      * @return Parent window type of UIExtension
475      */
476     virtual WindowType GetParentWindowType() const;
477 
478     /**
479      * @brief Set whether this window is a sub window of the UIExtension.
480      *
481      * @return isUIExtensionSubWindowFlag.
482     */
483     void SetIsUIExtensionSubWindowFlag(bool isUIExtensionSubWindowFlag);
484     /**
485      * @brief Get IsUIExtensionSubWindowFlag of window.
486      *
487      * @return true - is UIExtension sub window, false - is not UIExtension sub window.
488      */
489     bool GetIsUIExtensionSubWindowFlag() const;
490 
491 private:
492     Rect windowRect_ { 0, 0, 0, 0 };
493     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
494     WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED };
495     bool focusable_ { true };
496     bool touchable_ { true };
497     DisplayId displayId_ { DISPLAY_ID_INVALID };
498     uint32_t parentId_ = INVALID_WINDOW_ID;
499     std::string windowName_ { "" };
500     std::string bundleName_ { "" };
501     uint32_t flags_ { 0 };
502     PointInfo hitOffset_ { 0, 0 };
503     WindowTag windowTag_;
504     WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION };
505     bool keepScreenOn_ = false;
506     bool turnScreenOn_ = false;
507     bool isMainHandlerAvailable_ = true;
508     float brightness_ = UNDEFINED_BRIGHTNESS;
509     uint32_t callingWindow_ = INVALID_WINDOW_ID;
510     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
511         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty() },
512         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
513     };
514     Orientation requestedOrientation_ { Orientation::UNSPECIFIED };
515     std::string subWindowTitle_ = { "" };
516     bool subWindowDecorEnable_ = false;
517     bool onlySupportSceneBoard_ = false;
518     bool dialogDecorEnable_ = false;
519     std::string dialogTitle_ = { "" };
520     bool isTopmost_ = false;
521 
522     /*
523      * UIExtension
524      */
525     int32_t realParentId_ = INVALID_WINDOW_ID;
526     uint32_t uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::EMBEDDED);
527     bool isExtensionTag_ = false;
528     bool isUIExtensionSubWindowFlag_ = false;
529     WindowType parentWindowType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
530 };
531 } // namespace Rosen
532 } // namespace OHOS
533 #endif // OHOS_ROSEN_WINDOW_OPTION_H
534