• 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 INTERFACES_INNERKITS_WINDOW_SCENE_H
17 #define INTERFACES_INNERKITS_WINDOW_SCENE_H
18 
19 #include <refbase.h>
20 #include <iremote_object.h>
21 
22 #include "window.h"
23 #include "window_option.h"
24 
25 namespace OHOS::AppExecFwk {
26     class Configuration;
27 }
28 
29 namespace OHOS {
30 namespace Rosen {
31 class WindowScene : public RefBase {
32 public:
33     /**
34      * Default constructor used to create an empty WindowScene instance.
35      */
36     WindowScene() = default;
37 
38     /**
39      * Default deconstructor used to deconstruct.
40      *
41      */
42     ~WindowScene();
43 
44     /**
45      * Init a WindowScene instance based on the parameters displayId, context, listener and option.
46      *
47      * @param displayId the id of current display
48      * @param context current ability context
49      * @param listener the life cycle listener of the window
50      * @param option the settings for window, such as WindowType, width, height, etc
51      * @return the error code of window
52      */
53     WMError Init(DisplayId displayId, const std::shared_ptr<AbilityRuntime::Context>& context,
54         sptr<IWindowLifeCycle>& listener, sptr<WindowOption> option = nullptr);
55 
56     /**
57      * Init a WindowScene instance based on the parameters displayId, context, listener and option.
58      *
59      * @param displayId the id of current display
60      * @param context current ability context
61      * @param listener the life cycle listener of the window
62      * @param option the settings for window, such as WindowType, width, height, etc
63      * @param iSession session token of window session
64      * @return the error code of window
65      */
66     WMError Init(DisplayId displayId, const std::shared_ptr<AbilityRuntime::Context>& context,
67         sptr<IWindowLifeCycle>& listener, sptr<WindowOption> option, const sptr<IRemoteObject>& iSession);
68 
69     /**
70      * Create a window instance based on the parameters windowName and option.
71      *
72      * @param windowName the id of this window
73      * @param option the settings for window, such as WindowType, width, height, etc.
74      * @return the shared pointer of window
75      */
76     sptr<Window> CreateWindow(const std::string& windowName, sptr<WindowOption>& option) const;
77 
78     /**
79      * Get shared pointer of main window.
80      *
81      * @return the shared pointer of window
82      */
83     const sptr<Window>& GetMainWindow() const;
84 
85     /**
86      * Get a set of sub window.
87      *
88      * @return a set of sub window
89      */
90     std::vector<sptr<Window>> GetSubWindow();
91 
92     /**
93      * window go foreground.
94      *
95      * @param reason the reason of window to go to foreground, default 0.
96      * @return the error code of window
97      */
98     WMError GoForeground(uint32_t reason = 0);
99 
100     /**
101      * Window go background.
102      *
103      * @param reason the reason of window to go to background, default 0.
104      * @return the error code of window
105      */
106     WMError GoBackground(uint32_t reason = 0);
107 
108     /**
109      * Window go distroy.
110      *
111      * @return the error code of window
112      */
113     WMError GoDestroy();
114 
115     /**
116      * Window handle new want.
117      *
118      * @param want ability want.
119      * @return the error code of window
120      */
121     WMError OnNewWant(const AAFwk::Want& want);
122 
123     /**
124      * Request to get the focus.
125      *
126      * @return the error code of window
127      */
128     WMError RequestFocus() const;
129 
130     /**
131      * Update ability configuration.
132      *
133      * @param configuration the configuration of ability
134      */
135     void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
136 
137     /**
138      * Set main window system bar property
139      *
140      * @param type the type of window
141      * @param property the property of system bar
142      * @return the error code of window
143      */
144     WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const;
145 
146     /**
147      * Get content info of main window.
148      *
149      * @return content info of main window
150      */
151     std::string GetContentInfo() const;
152 
153     /**
154      * @brief Handle and notify memory.
155      *
156      * @param level memory level
157      * @return the error code of window
158      */
159     WMError NotifyMemoryLevel(int32_t level);
160 
161 public:
162     static const DisplayId DEFAULT_DISPLAY_ID = 0;
163     static const std::string MAIN_WINDOW_ID;
164 
165 private:
166     /**
167      * @param context the context of a main window
168      * @return the name of main window
169      */
170     std::string GenerateMainWindowName(const std::shared_ptr<AbilityRuntime::Context>& context) const;
171 
172 private:
173     sptr<Window> mainWindow_ = nullptr;
174     static inline std::atomic<uint32_t> count { 0 };
175     DisplayId displayId_ = DEFAULT_DISPLAY_ID;
176     std::shared_ptr<AbilityRuntime::Context> context_ = nullptr;
177 };
178 } // namespace Rosen
179 } // namespace OHOS
180 #endif // INTERFACES_INNERKITS_WINDOW_SCENE_H
181