• 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 Get window mode.
264      *
265      * @return The mode of window.
266      */
267     WindowMode GetWindowMode() const;
268 
269     /**
270      * @brief Get window type.
271      *
272      * @return The type of window.
273      */
274     WindowType GetWindowType() const;
275 
276     /**
277      * @brief Get window tag.
278      *
279      * @return Return window tag.
280      */
281     WindowTag GetWindowTag() const;
282 
283     /**
284      * @brief Get window rect.
285      *
286      * @return The rect of window.
287      */
288     Rect GetWindowRect() const;
289 
290     /**
291      * @brief Get parent id.
292      *
293      * @return Return parent window id.
294      */
295     uint32_t GetParentId() const;
296 
297     /**
298      * @brief Get display id.
299      *
300      * @return Return diplay id.
301      */
302     DisplayId GetDisplayId() const;
303 
304     /**
305      * @brief Get window flags.
306      *
307      * @return Return the window flags.
308      */
309     uint32_t GetWindowFlags() const;
310 
311     /**
312      * @brief Get bundle name.
313      *
314      * @return Return the bundle name.
315      */
316     const std::string GetBundleName() const;
317 
318     /**
319      * @brief Get window name.
320      *
321      * @return Return the window name.
322      */
323     const std::string& GetWindowName() const;
324 
325     /**
326      * @brief Get window touchable.
327      *
328      * @return Return true means the window is touchable, otherwise not.
329      */
330     bool GetTouchable() 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 hit offset.
341      *
342      * @return Return hit offset value as PointInfo.
343      */
344     const PointInfo& GetHitOffset() const;
345 
346     /**
347      * @brief Get system bar property.
348      *
349      * @return Return system bar property map.
350      */
351     const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
352 
353     /**
354      * @brief Get window request orientation.
355      *
356      * @return Return window requested orientation.
357      */
358     Orientation GetRequestedOrientation() const;
359 
360     /**
361      * @brief Get window session type.
362      *
363      * @return Return window session type.
364      */
365     WindowSessionType GetWindowSessionType() const;
366 
367     /**
368      * @brief Get calling window id.
369      *
370      * @return Return the calling window id of window.
371      */
372     uint32_t GetCallingWindow() const;
373 
374     /**
375      * @brief Get window brightness.
376      *
377      * @return Return screen brightness.
378      */
379     float GetBrightness() const;
380 
381     /**
382      * @brief Get main handler available
383      *
384      * @return Return true means the main handler available, otherwise not.
385      */
386     bool GetMainHandlerAvailable() const;
387 
388     /**
389      * @brief Get only sceneboard supported
390      *
391      * @return Return ture means only sceneboard supported, otherwise not.
392      */
393     bool GetOnlySupportSceneBoard() const;
394 
395     /**
396      * @brief Get subwindow decor enable
397      *
398      * @return Return ture means the subwindow decor enabled, otherwise not.
399      */
400     bool GetSubWindowDecorEnable() const;
401 
402     /**
403      * @brief Get subwindow title
404      *
405      * @return Return the subwindow title
406      */
407     std::string GetSubWindowTitle() const;
408 
409     /**
410      * @brief Get window topmost
411      *
412      * @return true means the window is topmost, otherwise not.
413      */
414     bool GetWindowTopmost() const;
415 
416     /**
417      * @brief Get subwindow maximizeSupported
418      *
419      * @return true means subwindow support maximize, otherwise not.
420      */
421     bool GetSubWindowMaximizeSupported() const;
422 
423     /**
424      * @brief Set whether this window is a sub window of any level of UIExtension.
425      *
426      * @param isUIExtAnySubWindow true - is any sub window of UIExtension,
427      *                            false - is not any sub window of UIExtension.
428      */
429     void SetIsUIExtAnySubWindow(bool isUIExtAnySubWindow);
430 
431     /**
432      * @brief Get whether this window is a sub window of any level of UIExtension.
433      *
434      * @return true - is a sub window of any level of UIExtension,
435      *         false - is not a sub window of any level of UIExtension.
436      */
437     bool GetIsUIExtAnySubWindow() const;
438 
439 private:
440     Rect windowRect_ { 0, 0, 0, 0 };
441     std::string windowName_ { "" };
442     std::string bundleName_ { "" };
443     std::string subWindowTitle_ = { "" };
444     bool subWindowMaximizeSupported_ = false;
445     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
446     WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED };
447     bool focusable_ { true };
448     bool touchable_ { true };
449     bool subWindowDecorEnable_ = { false };
450     bool onlySupportSceneBoard_ = { false };
451     bool keepScreenOn_ = { false };
452     bool turnScreenOn_ = { false };
453     bool isMainHandlerAvailable_ = { true };
454     bool isTopmost_ = false;
455     DisplayId displayId_ { 0 };
456     uint32_t parentId_ = INVALID_WINDOW_ID;
457     uint32_t callingWindow_ = INVALID_WINDOW_ID;
458     uint32_t flags_ { 0 };
459     PointInfo hitOffset_ { 0, 0 };
460     WindowTag windowTag_;
461     WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION };
462     float brightness_ = UNDEFINED_BRIGHTNESS;
463     int32_t zLevel_ = 0;
464 
465     Orientation requestedOrientation_ { Orientation::UNSPECIFIED };
466     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
467         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty() },
468         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
469     };
470 };
471 } // namespace Rosen
472 } // namespace OHOS
473 #endif // OHOS_ROSEN_WINDOW_OPTION_H
474