• 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 #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     /**
144      * @brief Set window tag.
145      *
146      * @param windowTag The tag of window.
147      */
148     void SetWindowTag(WindowTag windowTag);
149 
150     /**
151      * @brief Set window session type.
152      *
153      * @param sessionType The session type of window.
154      */
155     void SetWindowSessionType(WindowSessionType sessionType);
156 
157     /**
158      * @brief Set keep screen on.
159      *
160      * @param keepScreenOn The window keep screen on or not.
161      */
162     void SetKeepScreenOn(bool keepScreenOn);
163 
164     /**
165      * @brief Is keep screen on.
166      *
167      * @return Return true means the window would keep screen on, otherwise not.
168      */
169     bool IsKeepScreenOn() const;
170 
171     /**
172      * @brief Set view keep screen on.
173      *
174      * @param keepScreenOn The view keep screen on or not.
175      */
176     void SetViewKeepScreenOn(bool keepScreenOn);
177 
178     /**
179      * @brief Is view keep screen on.
180      *
181      * @return Return true means the view would keep screen on, otherwise not.
182      */
183     bool IsViewKeepScreenOn() const;
184 
185     /**
186      * @brief Set screen on.
187      *
188      * @param turnScreenOn mark the window to turn the screen on or not.
189      */
190     void SetTurnScreenOn(bool turnScreenOn);
191 
192     /**
193      * @brief Is turned screen on.
194      *
195      * @return The window is marked to turn the screen on or not.
196      */
197     bool IsTurnScreenOn() const;
198 
199     /**
200      * @brief Set window brightness.
201      *
202      * @param brightness The brightness of screen. the value is between 0.0 ~ 1.0.
203      */
204     void SetBrightness(float brightness);
205 
206     /**
207      * @brief Set window requested orientation.
208      *
209      * @param orientation The requested orientation of window.
210      */
211     void SetRequestedOrientation(Orientation orientation);
212 
213     /**
214      * @brief Set window calling window id.
215      *
216      * @param windowId The window id of calling window.
217      */
218     void SetCallingWindow(uint32_t windowId);
219 
220     /**
221      * @brief Set window main handler available.
222      *
223      * @param isMainHandlerAvailable is window main handler available.
224      */
225     void SetMainHandlerAvailable(bool isMainHandlerAvailable);
226 
227     /**
228      * @brief Set subwindow title.
229      *
230      * @param subWindowTitle the subwindow title.
231      */
232     void SetSubWindowTitle(const std::string& subWindowTitle);
233 
234     /**
235      * @brief Set is subwindow support maximize.
236      *
237      * @param maximizeSupported true means support default not support.
238      */
239     void SetSubWindowMaximizeSupported(bool maximizeSupported);
240 
241     /**
242      * @brief Set subwindow decor enable.
243      *
244      * @param subWindowDecorEnable the subwindow decor enable.
245      */
246     void SetSubWindowDecorEnable(bool subWindowDecorEnable);
247 
248     /**
249      * @brief Set only sceneboard supported.
250      *
251      * @param onlySupportSceneBoard only sceneboard supported.
252      */
253     void SetOnlySupportSceneBoard(bool onlySupportSceneBoard);
254 
255     /**
256      * @brief Set whether this window is the first level sub window of UIExtension.
257      *
258      * @param isUIExtFirstSubWindow whether is the first sub window of UIExtension.
259      */
260     void SetIsUIExtFirstSubWindow(bool isUIExtFirstSubWindow);
261 
262     /**
263      * @brief Set UIExtension usage.
264      *
265      * @param uiExtensionUsage UIExtension usage.
266      */
267     void SetUIExtensionUsage(uint32_t uiExtensionUsage);
268 
269     /**
270      * @brief Set Dialog Decor Enable Or Not.
271      *
272      * @param decorEnable true means enable, default disabled.
273      */
274     void SetDialogDecorEnable(bool decorEnable);
275 
276     /**
277      * @brief Set Dialog title.
278      *
279      * @param dialogTitle true means enable, default disabled.
280      */
281     void SetDialogTitle(const std::string& dialogTitle);
282 
283     /**
284      * @brief Set window topmost.
285      *
286      * @param isTopmost true means enable, default disabled.
287      */
288     void SetWindowTopmost(bool isTopmost);
289 
290     /**
291      * @brief Set sub window zLevel
292      *
293      * @param zLevel zLevel of sub window to specify the hierarchical relationship among sub windows
294      */
295     void SetSubWindowZLevel(int32_t zLevel);
296 
297     /**
298      * @brief Set real parent id of UIExtension
299      *
300      * @param realParentId real parent id of UIExtension
301      */
302     void SetRealParentId(int32_t realParentId);
303 
304     /**
305      * @brief Set parent window type of UIExtension
306      *
307      * @param parentWindowType Parent window type of UIExtension
308      */
309     void SetParentWindowType(WindowType parentWindowType);
310 
311     /**
312      * @brief Get window rect.
313      *
314      * @return The rect of window.
315      */
316     Rect GetWindowRect() const;
317 
318     /**
319      * @brief Get window type.
320      *
321      * @return The type of window.
322      */
323     WindowType GetWindowType() const;
324 
325     /**
326      * @brief Get window mode.
327      *
328      * @return The mode of window.
329      */
330     WindowMode GetWindowMode() const;
331 
332     /**
333      * @brief Get window focusable.
334      *
335      * @return Return true means the window is focusable, otherwise not.
336      */
337     bool GetFocusable() const;
338 
339     /**
340      * @brief Get window touchable.
341      *
342      * @return Return true means the window is touchable, otherwise not.
343      */
344     bool GetTouchable() const;
345 
346     /**
347      * @brief Get display id.
348      *
349      * @return Return diplay id.
350      */
351     DisplayId GetDisplayId() const;
352 
353     /**
354      * @brief Get parent id.
355      *
356      * @return Return parent window id.
357      */
358     uint32_t GetParentId() const;
359 
360     /**
361      * @brief Get window name.
362      *
363      * @return Return the window name.
364      */
365     const std::string& GetWindowName() const;
366 
367     /**
368      * @brief Get bundle name.
369      *
370      * @return Return the bundle name.
371      */
372     const std::string GetBundleName() const;
373 
374     /**
375      * @brief Get window flags.
376      *
377      * @return Return the window flags.
378      */
379     uint32_t GetWindowFlags() const;
380 
381     /**
382      * @brief Get system bar property.
383      *
384      * @return Return system bar property map.
385      */
386     const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
387 
388     /**
389      * @brief Get window hit offset.
390      *
391      * @return Return hit offset value as PointInfo.
392      */
393     const PointInfo& GetHitOffset() const;
394 
395     /**
396      * @brief Get window tag.
397      *
398      * @return Return window tag.
399      */
400     WindowTag GetWindowTag() const;
401 
402     /**
403      * @brief Get window session type.
404      *
405      * @return Return window session type.
406      */
407     WindowSessionType GetWindowSessionType() const;
408 
409     /**
410      * @brief Get window brightness.
411      *
412      * @return Return screen brightness.
413      */
414     float GetBrightness() const;
415 
416     /**
417      * @brief Get window request orientation.
418      *
419      * @return Return window requested orientation.
420      */
421     Orientation GetRequestedOrientation() const;
422 
423     /**
424      * @brief Get calling window id.
425      *
426      * @return Return the calling window id of window.
427      */
428     uint32_t GetCallingWindow() const;
429 
430     /**
431      * @brief Get main handler available
432      *
433      * @return Return true means the main handler available, otherwise not.
434      */
435     bool GetMainHandlerAvailable() const;
436 
437     /**
438      * @brief Get subwindow title
439      *
440      * @return Return the subwindow title
441      */
442     std::string GetSubWindowTitle() const;
443 
444     /**
445      * @brief Get subwindow decor enable
446      *
447      * @return Return ture means the subwindow decor enabled, otherwise not.
448      */
449     bool GetSubWindowDecorEnable() const;
450 
451     /**
452      * @brief Get only sceneboard supported
453      *
454      * @return Return ture means only sceneboard supported, otherwise not.
455      */
456     bool GetOnlySupportSceneBoard() const;
457 
458     /**
459      * @brief Get whether this window is the first level sub window of UIExtension.
460      *
461      * @return true - is the first sub window of UIExtension, false - is not the first sub window of UIExtension
462      */
463     bool GetIsUIExtFirstSubWindow() const;
464 
465     /**
466      * @brief Get UIExtension usage.
467      *
468      * @param Return UIExtension usage.
469      */
470     uint32_t GetUIExtensionUsage() const;
471 
472     /**
473      * @brief Get dialog decor enable
474      *
475      * @return true means the dialog decor is enabled, otherwise not.
476      */
477     bool GetDialogDecorEnable() const;
478 
479     /**
480      * @brief Get dialog title
481      *
482      * @return Return the dialog title
483      */
484     std::string GetDialogTitle() const;
485 
486     /**
487      * @brief Get window topmost
488      *
489      * @return true means the window is topmost, otherwise not.
490      */
491     bool GetWindowTopmost() const;
492 
493     /**
494      * @brief Get sub window zLevel
495      *
496      * @return Return zLevel of sub window
497      */
498     int32_t GetSubWindowZLevel() const;
499 
500     /**
501      * @brief Get subwindow maximizeSupported
502      *
503      * @return true means subwindow support maximize, otherwise not.
504      */
505     bool GetSubWindowMaximizeSupported() const;
506 
507     /**
508      * @brief Get the real parent id of UIExtension
509      *
510      * @return Return the real parent id of UIExtension
511      */
512     int32_t GetRealParentId() const;
513 
514     /*
515      * @brief Get the parent window type of UIExtension
516      *
517      * @return Parent window type of UIExtension
518      */
519     virtual WindowType GetParentWindowType() const;
520 
521     /**
522      * @brief Set whether this window is a sub window of any level of UIExtension.
523      *
524      * @param isUIExtAnySubWindow true - is any sub window of UIExtension,
525      *                            false - is not any sub window of UIExtension.
526      */
527     void SetIsUIExtAnySubWindow(bool isUIExtAnySubWindow);
528 
529     /**
530      * @brief Get whether this window is a sub window of any level of UIExtension.
531      *
532      * @return true - is a sub window of any level of UIExtension,
533      *         false - is not a sub window of any level of UIExtension.
534      */
535     bool GetIsUIExtAnySubWindow() const;
536 
537     /**
538      * @brief Set whether this window is a system keyboard
539      *
540      * @param isSystemKeyboard true means the window is a system keyboard.
541      */
542     void SetIsSystemKeyboard(bool isSystemKeyboard);
543 
544     /**
545      * @brief Check whether this window is a system keyboard.
546      *
547      * @return true - this window is a system keyboard, false - this window is not a system keyboard.
548      */
549     bool IsSystemKeyboard() const;
550 
551     /**
552      * @brief Set density of UIExtension.
553      *
554      * @param density Density of UIExtension.
555      */
556     void SetDensity(float density);
557 
558     /**
559      * @brief Get density of UIExtension.
560      *
561      * @return Density of UIExtension.
562      */
563     float GetDensity() const;
564 
565     /**
566      * @brief Set DPI follow-up mode of UIExtension.
567      *
568      * @param isDensityFollowHost DPI follow-up mode of UIExtension.
569      */
570     void SetIsDensityFollowHost(bool isDensityFollowHost);
571 
572     /**
573      * @brief Get DPI follow-up mode of UIExtension.
574      *
575      * @return true - DPI follows host, false - DPI follows UIExtensionAbility.
576      */
577     bool GetIsDensityFollowHost() const;
578 
579     /**
580      * @brief Set whether this modal UIExt is a constrained modal UIExtension.
581      *
582      * @param isConstrainedModal true - is a constrained modal UIExtension,
583      *                           false - is not a constrained modal UIExtension,
584      */
585     void SetConstrainedModal(bool isConstrainedModal);
586 
587     /**
588      * @brief Get whether this modal UIExt is a constrained modal UIExtension.
589      *
590      * @return true - is a constrained modal UIExtension,
591      *         false - is not a constrained modal UIExtension,
592      */
593     bool IsConstrainedModal() const;
594 
595 private:
596     Rect windowRect_ { 0, 0, 0, 0 };
597     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
598     WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED };
599     bool focusable_ { true };
600     bool touchable_ { true };
601     DisplayId displayId_ { DISPLAY_ID_INVALID };
602     uint32_t parentId_ = INVALID_WINDOW_ID;
603     std::string windowName_ { "" };
604     std::string bundleName_ { "" };
605     uint32_t flags_ { 0 };
606     PointInfo hitOffset_ { 0, 0 };
607     WindowTag windowTag_;
608     WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION };
609     bool keepScreenOn_ = false;
610     bool viewKeepScreenOn_ = false;
611     bool turnScreenOn_ = false;
612     bool isMainHandlerAvailable_ = true;
613     float brightness_ = UNDEFINED_BRIGHTNESS;
614     uint32_t callingWindow_ = INVALID_WINDOW_ID;
615     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
616         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty() },
617         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
618     };
619     Orientation requestedOrientation_ { Orientation::UNSPECIFIED };
620     std::string subWindowTitle_ = { "" };
621     bool subWindowDecorEnable_ = false;
622     bool subWindowMaximizeSupported_ = false;
623     bool onlySupportSceneBoard_ = false;
624     bool dialogDecorEnable_ = false;
625     std::string dialogTitle_ = { "" };
626     bool isTopmost_ = false;
627     int32_t zLevel_ = 0;
628     bool isSystemKeyboard_ = false;
629 
630     /*
631      * UIExtension
632      */
633     int32_t realParentId_ = INVALID_WINDOW_ID;
634     uint32_t uiExtensionUsage_ = static_cast<uint32_t>(UIExtensionUsage::EMBEDDED);
635     bool isUIExtFirstSubWindow_ = false;
636     bool isUIExtAnySubWindow_ = false;
637     WindowType parentWindowType_ = WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
638     float density_ = 1.0f;
639     bool isDensityFollowHost_ = false;
640     bool isConstrainedModal_ = false;
641 };
642 } // namespace Rosen
643 } // namespace OHOS
644 #endif // OHOS_ROSEN_WINDOW_OPTION_H
645