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 * Create a window instance based on the parameters windowName and option. 58 * 59 * @param windowName the id of this window 60 * @param option the settings for window, such as WindowType, width, height, etc. 61 * @return the shared pointer of window 62 */ 63 sptr<Window> CreateWindow(const std::string& windowName, sptr<WindowOption>& option) const; 64 65 /** 66 * Get shared pointer of main window. 67 * 68 * @return the shared pointer of window 69 */ 70 const sptr<Window>& GetMainWindow() const; 71 72 /** 73 * Get a set of sub window. 74 * 75 * @return a set of sub window 76 */ 77 std::vector<sptr<Window>> GetSubWindow(); 78 79 /** 80 * window go foreground. 81 * 82 * @param reason the reason of window to go to foreground, default 0. 83 * @return the error code of window 84 */ 85 WMError GoForeground(uint32_t reason = 0); 86 87 /** 88 * Window go background. 89 * 90 * @param reason the reason of window to go to background, default 0. 91 * @return the error code of window 92 */ 93 WMError GoBackground(uint32_t reason = 0); 94 95 /** 96 * Window go distroy. 97 * 98 * @return the error code of window 99 */ 100 WMError GoDestroy(); 101 102 /** 103 * Window handle new want. 104 * 105 * @param want ability want. 106 * @return the error code of window 107 */ 108 WMError OnNewWant(const AAFwk::Want& want); 109 110 /** 111 * Request to get the focus. 112 * 113 * @return the error code of window 114 */ 115 WMError RequestFocus() const; 116 117 /** 118 * Update ability configuration. 119 * 120 * @param configuration the configuration of ability 121 */ 122 void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 123 124 /** 125 * Set main window system bar property 126 * 127 * @param type the type of window 128 * @param property the property of system bar 129 * @return the error code of window 130 */ 131 WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) const; 132 133 /** 134 * Get content info of main window. 135 * 136 * @return content info of main window 137 */ 138 std::string GetContentInfo() const; 139 140 /** 141 * @brief Handle and notify memory. 142 * 143 * @param level memory level 144 * @return the error code of window 145 */ 146 WMError NotifyMemoryLevel(int32_t level) const; 147 148 public: 149 static const DisplayId DEFAULT_DISPLAY_ID = 0; 150 static const std::string MAIN_WINDOW_ID; 151 152 private: 153 /** 154 * @param context the context of a main window 155 * @return the name of main window 156 */ 157 std::string GenerateMainWindowName(const std::shared_ptr<AbilityRuntime::Context>& context) const; 158 159 private: 160 sptr<Window> mainWindow_ = nullptr; 161 static inline std::atomic<uint32_t> count { 0 }; 162 DisplayId displayId_ = DEFAULT_DISPLAY_ID; 163 std::shared_ptr<AbilityRuntime::Context> context_ = nullptr; 164 }; 165 } // namespace Rosen 166 } // namespace OHOS 167 #endif // INTERFACES_INNERKITS_WINDOW_SCENE_H 168