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 subwindow topmost.
229      *
230      * @param isTopmost true means enable, default disabled.
231      */
232     void SetWindowTopmost(bool isTopmost);
233 
234     /**
235      * @brief Set only sceneboard supported.
236      *
237      * @param onlySupportSceneBoard only sceneboard supported.
238      */
239     void SetOnlySupportSceneBoard(bool onlySupportSceneBoard);
240 
241     /**
242      * @brief Get window mode.
243      *
244      * @return The mode of window.
245      */
246     WindowMode GetWindowMode() const;
247 
248     /**
249      * @brief Get window type.
250      *
251      * @return The type of window.
252      */
253     WindowType GetWindowType() const;
254 
255     /**
256      * @brief Get window tag.
257      *
258      * @return Return window tag.
259      */
260     WindowTag GetWindowTag() const;
261 
262     /**
263      * @brief Get window rect.
264      *
265      * @return The rect of window.
266      */
267     Rect GetWindowRect() const;
268 
269     /**
270      * @brief Get parent id.
271      *
272      * @return Return parent window id.
273      */
274     uint32_t GetParentId() const;
275 
276     /**
277      * @brief Get display id.
278      *
279      * @return Return diplay id.
280      */
281     DisplayId GetDisplayId() const;
282 
283     /**
284      * @brief Get window flags.
285      *
286      * @return Return the window flags.
287      */
288     uint32_t GetWindowFlags() const;
289 
290     /**
291      * @brief Get bundle name.
292      *
293      * @return Return the bundle name.
294      */
295     const std::string GetBundleName() const;
296 
297     /**
298      * @brief Get window name.
299      *
300      * @return Return the window name.
301      */
302     const std::string& GetWindowName() const;
303 
304     /**
305      * @brief Get window touchable.
306      *
307      * @return Return true means the window is touchable, otherwise not.
308      */
309     bool GetTouchable() const;
310 
311     /**
312      * @brief Get window focusable.
313      *
314      * @return Return true means the window is focusable, otherwise not.
315      */
316     bool GetFocusable() const;
317 
318     /**
319      * @brief Get window hit offset.
320      *
321      * @return Return hit offset value as PointInfo.
322      */
323     const PointInfo& GetHitOffset() const;
324 
325     /**
326      * @brief Get system bar property.
327      *
328      * @return Return system bar property map.
329      */
330     const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
331 
332     /**
333      * @brief Get window request orientation.
334      *
335      * @return Return window requested orientation.
336      */
337     Orientation GetRequestedOrientation() const;
338 
339     /**
340      * @brief Get window session type.
341      *
342      * @return Return window session type.
343      */
344     WindowSessionType GetWindowSessionType() const;
345 
346     /**
347      * @brief Get calling window id.
348      *
349      * @return Return the calling window id of window.
350      */
351     uint32_t GetCallingWindow() const;
352 
353     /**
354      * @brief Get window brightness.
355      *
356      * @return Return screen brightness.
357      */
358     float GetBrightness() const;
359 
360     /**
361      * @brief Get main handler available
362      *
363      * @return Return true means the main handler available, otherwise not.
364      */
365     bool GetMainHandlerAvailable() const;
366 
367     /**
368      * @brief Get only sceneboard supported
369      *
370      * @return Return ture means only sceneboard supported, otherwise not.
371     */
372     bool GetOnlySupportSceneBoard() const;
373 
374     /**
375      * @brief Get subwindow decor enable
376      *
377      * @return Return ture means the subwindow decor enabled, otherwise not.
378     */
379     bool GetSubWindowDecorEnable() const;
380 
381     /**
382      * @brief Get subwindow title
383      *
384      * @return Return the subwindow title
385     */
386     std::string GetSubWindowTitle() const;
387 
388     /**
389      * @brief Get window topmost
390      *
391      * @return true means the window is topmost, otherwise not.
392     */
393     bool GetWindowTopmost() const;
394 
395     /**
396      * @brief Set whether this window is a sub window of the UIExtension.
397      *
398      * @return isUIExtensionSubWindowFlag.
399     */
400     void SetIsUIExtensionSubWindowFlag(bool isUIExtensionSubWindowFlag);
401     /**
402      * @brief Get IsUIExtensionSubWindowFlag of window.
403      *
404      * @return true - is UIExtension sub window, false - is not UIExtension sub window.
405      */
406     bool GetIsUIExtensionSubWindowFlag() const;
407 
408 private:
409     Rect windowRect_ { 0, 0, 0, 0 };
410     std::string windowName_ { "" };
411     std::string bundleName_ { "" };
412     std::string subWindowTitle_ = { "" };
413     WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW };
414     WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED };
415     bool focusable_ { true };
416     bool touchable_ { true };
417     bool subWindowDecorEnable_ = { false };
418     bool onlySupportSceneBoard_ = { false };
419     bool keepScreenOn_ = { false };
420     bool turnScreenOn_ = { false };
421     bool isMainHandlerAvailable_ = { true };
422     bool isTopmost_ = false;
423     DisplayId displayId_ { 0 };
424     uint32_t parentId_ = INVALID_WINDOW_ID;
425     uint32_t callingWindow_ = INVALID_WINDOW_ID;
426     uint32_t flags_ { 0 };
427     PointInfo hitOffset_ { 0, 0 };
428     WindowTag windowTag_;
429     WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION };
430     float brightness_ = UNDEFINED_BRIGHTNESS;
431 
432     Orientation requestedOrientation_ { Orientation::UNSPECIFIED };
433     std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ {
434         { WindowType::WINDOW_TYPE_STATUS_BAR,     SystemBarProperty() },
435         { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() },
436     };
437 };
438 } // namespace Rosen
439 } // namespace OHOS
440 #endif // OHOS_ROSEN_WINDOW_OPTION_H
441