• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 WINDOW_EXPORT 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 mode.
45      *
46      * @param mode The mode of window.
47      */
48     void SetWindowMode(WindowMode mode);
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 rect.
59      *
60      * @param rect The rect of window to set window position and size.
61      */
62     void SetWindowRect(const struct Rect& rect);
63 
64     /**
65      * @brief Set parent id.
66      *
67      * @param parentId The parent window id.
68      */
69     void SetParentId(uint32_t parentId);
70 
71     /**
72      * @brief Set display id.
73      *
74      * @param displayId The display id of window.
75      */
76     void SetDisplayId(DisplayId displayId);
77 
78     /**
79      * @brief Set window focusable.
80      *
81      * @param isFocusable True means the window can be focused, otherwise not.
82      */
83     void SetFocusable(bool isFocusable);
84 
85     /**
86      * @brief Set window touchable.
87      *
88      * @param isTouchable True means the window can be touched, otherwise not.
89      */
90     void SetTouchable(bool isTouchable);
91 
92     /**
93      * @brief Set bundle name.
94      *
95      * @param bundleName The bundle name.
96      */
97     void SetBundleName(const std::string bundleName);
98 
99     /**
100      * @brief Set window name.
101      *
102      * @param windowName The window name.
103      */
104     void SetWindowName(const std::string& windowName);
105 
106     /**
107      * @brief Set window flags.
108      *
109      * @param flags The flag value.
110      */
111     void SetWindowFlags(uint32_t flags);
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 Add window flag.
122      *
123      * @param flag The flag value added.
124      */
125     void AddWindowFlag(WindowFlag flag);
126 
127     /**
128      * @brief Set window tag.
129      *
130      * @param windowTag The tag of window.
131      */
132     void SetWindowTag(WindowTag windowTag);
133 
134     /**
135      * @brief Set system bar property.
136      *
137      * @param type The system bar window type.
138      * @param property The system bar property.
139      */
140     void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
141 
142     /**
143      * @brief Set window session type.
144      *
145      * @param sessionType The session type of window.
146      */
147     void SetWindowSessionType(WindowSessionType sessionType);
148 
149     /**
150      * @brief Set hit offset.
151      *
152      * @param x The position x of hit offset.
153      * @param y The position y of hit offset.
154      */
155     void SetHitOffset(int32_t x, int32_t y);
156 
157     /**
158      * @brief Is turned screen on.
159      *
160      * @return The window is marked to turn the screen on or not.
161      */
162     bool IsTurnScreenOn() const;
163 
164     /**
165      * @brief Set screen on.
166      *
167      * @param turnScreenOn mark the window to turn the screen on or not.
168      */
169     void SetTurnScreenOn(bool turnScreenOn);
170 
171     /**
172      * @brief Is keep screen on.
173      *
174      * @return Return true means the window would keep screen on, otherwise not.
175      */
176     bool IsKeepScreenOn() const;
177 
178     /**
179      * @brief Set keep screen on.
180      *
181      * @param keepScreenOn The window keep screen on or not.
182      */
183     void SetKeepScreenOn(bool keepScreenOn);
184 
185     /**
186      * @brief Set window calling window id.
187      *
188      * @param windowId The window id of calling window.
189      */
190     void SetCallingWindow(uint32_t windowId);
191 
192     /**
193      * @brief Set window requested orientation.
194      *
195      * @param orientation The requested orientation of window.
196      */
197     void SetRequestedOrientation(Orientation orientation);
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 main handler available.
208      *
209      * @param isMainHandlerAvailable is window main handler available.
210      */
211     void SetMainHandlerAvailable(bool isMainHandlerAvailable);
212 
213     /**
214      * @brief Set subwindow decor enable.
215      *
216      * @param subWindowDecorEnable the subwindow decor enable.
217      */
218     void SetSubWindowDecorEnable(bool subWindowDecorEnable);
219 
220     /**
221      * @brief Set subwindow title.
222      *
223      * @param subWindowTitle the subwindow title.
224      */
225     void SetSubWindowTitle(const std::string& subWindowTitle);
226 
227     /**
228      * @brief Set is subwindow support maximize.
229      *
230      * @param maximizeSupported true means support default not support.
231      */
232     void SetSubWindowMaximizeSupported(bool maximizeSupported);
233 
234     /**
235      * @brief Set subwindow topmost.
236      *
237      * @param isTopmost true means enable, default disabled.
238      */
239     void SetWindowTopmost(bool isTopmost);
240 
241     /**
242      * @brief Set only sceneboard supported.
243      *
244      * @param onlySupportSceneBoard only sceneboard supported.
245      */
246     void SetOnlySupportSceneBoard(bool onlySupportSceneBoard);
247 
248     /**
249      * @brief Set sub window zLevel
250      *
251      * @param zLevel zLevel of sub window
252      */
253     void SetSubWindowZLevel(int32_t zLevel);
254 
255     /**
256      * @brief Get sub window zLevel
257      *
258      * @return The zLevel of sub window
259      */
260     int32_t GetSubWindowZLevel() const;
261 
262     /**
263      * @brief Set zIndex of specific window.
264      *
265      * @param zIndex zIndex of specific window
266      */
267     void SetZIndex(int32_t zIndex);
268 
269     /**
270      * @brief Get zIndex of specific window.
271      *
272      * @return Return zIndex of specific window
273      */
274     int32_t GetZIndex() const;
275 
276     /**
277      * @brief Set sub window outline enabled
278      *
279      * @param outlineEnabled whether show sub window outline
280      */
281     void SetSubWindowOutlineEnabled(bool outlineEnabled);
282 
283     /**
284      * @brief Get sub window outline enabled
285      *
286      */
287     bool IsSubWindowOutlineEnabled() const;
288 
289     /**
290      * @brief Get window mode.
291      *
292      * @return The mode of window.
293      */
294     WindowMode GetWindowMode() const;
295 
296     /**
297      * @brief Get window type.
298      *
299      * @return The type of window.
300      */
301     WindowType GetWindowType() const;
302 
303     /**
304      * @brief Get window tag.
305      *
306      * @return Return window tag.
307      */
308     WindowTag GetWindowTag() const;
309 
310     /**
311      * @brief Get window rect.
312      *
313      * @return The rect of window.
314      */
315     Rect GetWindowRect() const;
316 
317     /**
318      * @brief Get parent id.
319      *
320      * @return Return parent window id.
321      */
322     uint32_t GetParentId() const;
323 
324     /**
325      * @brief Get display id.
326      *
327      * @return Return diplay id.
328      */
329     DisplayId GetDisplayId() const;
330 
331     /**
332      * @brief Get window flags.
333      *
334      * @return Return the window flags.
335      */
336     uint32_t GetWindowFlags() 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 name.
347      *
348      * @return Return the window name.
349      */
350     const std::string& GetWindowName() const;
351 
352     /**
353      * @brief Get window touchable.
354      *
355      * @return Return true means the window is touchable, otherwise not.
356      */
357     bool GetTouchable() const;
358 
359     /**
360      * @brief Get window focusable.
361      *
362      * @return Return true means the window is focusable, otherwise not.
363      */
364     bool GetFocusable() const;
365 
366     /**
367      * @brief Get window hit offset.
368      *
369      * @return Return hit offset value as PointInfo.
370      */
371     const PointInfo& GetHitOffset() const;
372 
373     /**
374      * @brief Get system bar property.
375      *
376      * @return Return system bar property map.
377      */
378     const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
379 
380     /**
381      * @brief Get window request orientation.
382      *
383      * @return Return window requested orientation.
384      */
385     Orientation GetRequestedOrientation() const;
386 
387     /**
388      * @brief Get window session type.
389      *
390      * @return Return window session type.
391      */
392     WindowSessionType GetWindowSessionType() 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 window brightness.
403      *
404      * @return Return screen brightness.
405      */
406     float GetBrightness() const;
407 
408     /**
409      * @brief Get main handler available
410      *
411      * @return Return true means the main handler available, otherwise not.
412      */
413     bool GetMainHandlerAvailable() const;
414 
415     /**
416      * @brief Get only sceneboard supported
417      *
418      * @return Return ture means only sceneboard supported, otherwise not.
419      */
420     bool GetOnlySupportSceneBoard() const;
421 
422     /**
423      * @brief Get subwindow decor enable
424      *
425      * @return Return ture means the subwindow decor enabled, otherwise not.
426      */
427     bool GetSubWindowDecorEnable() const;
428 
429     /**
430      * @brief Get subwindow title
431      *
432      * @return Return the subwindow title
433      */
434     std::string GetSubWindowTitle() const;
435 
436     /**
437      * @brief Get window topmost
438      *
439      * @return true means the window is topmost, otherwise not.
440      */
441     bool GetWindowTopmost() const;
442 
443     /**
444      * @brief Get subwindow maximizeSupported
445      *
446      * @return true means subwindow support maximize, otherwise not.
447      */
448     bool GetSubWindowMaximizeSupported() const;
449 
450     /**
451      * @brief Set whether this window is a sub window of any level of UIExtension.
452      *
453      * @param isUIExtAnySubWindow true - is any sub window of UIExtension,
454      *                            false - is not any sub window of UIExtension.
455      */
456     void SetIsUIExtAnySubWindow(bool isUIExtAnySubWindow);
457 
458     /**
459      * @brief Get whether this window is a sub window of any level of UIExtension.
460      *
461      * @return true - is a sub window of any level of UIExtension,
462      *         false - is not a sub window of any level of UIExtension.
463      */
464     bool GetIsUIExtAnySubWindow() const;
465 
466 private:
467     Rect windowRect_ { 0, 0, 0, 0 };
468     std::string windowName_ { "" };
469     std::string bundleName_ { "" };
470     std::string subWindowTitle_ = { "" };
471     bool subWindowMaximizeSupported_ = false;
472     bool subWindowOutlineEnabled_ = false;
473     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
474     WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED };
475     bool focusable_ { true };
476     bool touchable_ { true };
477     bool subWindowDecorEnable_ = { false };
478     bool onlySupportSceneBoard_ = { false };
479     bool keepScreenOn_ = { false };
480     bool turnScreenOn_ = { false };
481     bool isMainHandlerAvailable_ = { true };
482     bool isTopmost_ = false;
483     DisplayId displayId_ { 0 };
484     uint32_t parentId_ = INVALID_WINDOW_ID;
485     uint32_t callingWindow_ = INVALID_WINDOW_ID;
486     uint32_t flags_ { 0 };
487     PointInfo hitOffset_ { 0, 0 };
488     WindowTag windowTag_;
489     WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION };
490     float brightness_ = UNDEFINED_BRIGHTNESS;
491     int32_t zLevel_ = 0;
492     int32_t zIndex_ = SPECIFIC_ZINDEX_INVALID;
493 
494     Orientation requestedOrientation_ { Orientation::UNSPECIFIED };
495     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
496         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty() },
497         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
498     };
499 };
500 } // namespace Rosen
501 } // namespace OHOS
502 #endif // OHOS_ROSEN_WINDOW_OPTION_H
503