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 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/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 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 rect. 45 * 46 * @param rect The rect of window to set window position and size. 47 */ 48 void SetWindowRect(const struct Rect& rect); 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 mode. 59 * 60 * @param mode The mode of window. 61 */ 62 void SetWindowMode(WindowMode mode); 63 64 /** 65 * @brief Set window focusable. 66 * 67 * @param isFocusable True means the window can be focused, otherwise not. 68 */ 69 void SetFocusable(bool isFocusable); 70 71 /** 72 * @brief Set window touchable. 73 * 74 * @param isTouchable True means the window can be touched, otherwise not. 75 */ 76 void SetTouchable(bool isTouchable); 77 78 /** 79 * @brief Set display id. 80 * 81 * @param displayId The display id of window. 82 */ 83 void SetDisplayId(DisplayId displayId); 84 85 /** 86 * @brief Set parent id. 87 * 88 * @param parentId The parent window id. 89 */ 90 void SetParentId(uint32_t parentId); 91 92 /** 93 * @brief Set window name. 94 * 95 * @param windowName The window name. 96 */ 97 void SetWindowName(const std::string& windowName); 98 99 /** 100 * @brief Set bundle name. 101 * 102 * @param bundleName The bundle name. 103 */ 104 void SetBundleName(const std::string bundleName); 105 106 /** 107 * @brief Add window flag. 108 * 109 * @param flag The flag value added. 110 */ 111 void AddWindowFlag(WindowFlag flag); 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 Set window flags. 122 * 123 * @param flags The flag value. 124 */ 125 void SetWindowFlags(uint32_t flags); 126 127 /** 128 * @brief Set system bar property. 129 * 130 * @param type The system bar window type. 131 * @param property The system bar property. 132 */ 133 void SetSystemBarProperty(WindowType type, const SystemBarProperty& property); 134 135 /** 136 * @brief Set hit offset. 137 * 138 * @param x The position x of hit offset. 139 * @param y The position y of hit offset. 140 */ 141 void SetHitOffset(int32_t x, int32_t y); 142 /** 143 * @brief Set window tag. 144 * 145 * @param windowTag The tag of window. 146 */ 147 void SetWindowTag(WindowTag windowTag); 148 149 /** 150 * @brief Set window session type. 151 * 152 * @param sessionType The session type of window. 153 */ 154 void SetWindowSessionType(WindowSessionType sessionType); 155 156 /** 157 * @brief Set keep screen on. 158 * 159 * @param keepScreenOn The window keep screen on or not. 160 */ 161 void SetKeepScreenOn(bool keepScreenOn); 162 163 /** 164 * @brief Is keep screen on. 165 * 166 * @return Return true means the window would keep screen on, otherwise not. 167 */ 168 bool IsKeepScreenOn() const; 169 170 /** 171 * @brief Set screen on. 172 * 173 * @param turnScreenOn mark the window to turn the screen on or not. 174 */ 175 void SetTurnScreenOn(bool turnScreenOn); 176 177 /** 178 * @brief Is turned screen on. 179 * 180 * @return The window is marked to turn the screen on or not. 181 */ 182 bool IsTurnScreenOn() const; 183 184 /** 185 * @brief Set window brightness. 186 * 187 * @param brightness The brightness of screen. the value is between 0.0 ~ 1.0. 188 */ 189 void SetBrightness(float brightness); 190 191 /** 192 * @brief Set window requested orientation. 193 * 194 * @param orientation The requested orientation of window. 195 */ 196 void SetRequestedOrientation(Orientation orientation); 197 198 /** 199 * @brief Set window calling window id. 200 * 201 * @param windowId The window id of calling window. 202 */ 203 void SetCallingWindow(uint32_t windowId); 204 205 /** 206 * @brief Set window main handler available. 207 * 208 * @param isMainHandlerAvailable is window main handler available. 209 */ 210 void SetMainHandlerAvailable(bool isMainHandlerAvailable); 211 212 /** 213 * @brief Set subwindow title. 214 * 215 * @param subWindowTitle the subwindow title. 216 */ 217 void SetSubWindowTitle(const std::string& subWindowTitle); 218 219 /** 220 * @brief Set subwindow decor enable. 221 * 222 * @param subWindowDecorEnable the subwindow decor enable. 223 */ 224 void SetSubWindowDecorEnable(bool subWindowDecorEnable); 225 226 /** 227 * @brief Set only sceneboard supported. 228 * 229 * @param onlySupportSceneBoard only sceneboard supported. 230 */ 231 void SetOnlySupportSceneBoard(bool onlySupportSceneBoard); 232 233 /** 234 * @brief Get window rect. 235 * 236 * @return The rect of window. 237 */ 238 Rect GetWindowRect() const; 239 240 /** 241 * @brief Get window type. 242 * 243 * @return The type of window. 244 */ 245 WindowType GetWindowType() const; 246 247 /** 248 * @brief Get window mode. 249 * 250 * @return The mode of window. 251 */ 252 WindowMode GetWindowMode() const; 253 254 /** 255 * @brief Get window focusable. 256 * 257 * @return Return true means the window is focusable, otherwise not. 258 */ 259 bool GetFocusable() const; 260 261 /** 262 * @brief Get window touchable. 263 * 264 * @return Return true means the window is touchable, otherwise not. 265 */ 266 bool GetTouchable() const; 267 268 /** 269 * @brief Get display id. 270 * 271 * @return Return diplay id. 272 */ 273 DisplayId GetDisplayId() const; 274 275 /** 276 * @brief Get parent id. 277 * 278 * @return Return parent window id. 279 */ 280 uint32_t GetParentId() const; 281 282 /** 283 * @brief Get window name. 284 * 285 * @return Return the window name. 286 */ 287 const std::string& GetWindowName() const; 288 289 /** 290 * @brief Get bundle name. 291 * 292 * @return Return the bundle name. 293 */ 294 const std::string GetBundleName() const; 295 296 /** 297 * @brief Get window flags. 298 * 299 * @return Return the window flags. 300 */ 301 uint32_t GetWindowFlags() const; 302 303 /** 304 * @brief Get system bar property. 305 * 306 * @return Return system bar property map. 307 */ 308 const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const; 309 310 /** 311 * @brief Get window hit offset. 312 * 313 * @return Return hit offset value as PointInfo. 314 */ 315 const PointInfo& GetHitOffset() const; 316 317 /** 318 * @brief Get window tag. 319 * 320 * @return Return window tag. 321 */ 322 WindowTag GetWindowTag() const; 323 324 /** 325 * @brief Get window session type. 326 * 327 * @return Return window session type. 328 */ 329 WindowSessionType GetWindowSessionType() const; 330 331 /** 332 * @brief Get window brightness. 333 * 334 * @return Return screen brightness. 335 */ 336 float GetBrightness() const; 337 338 /** 339 * @brief Get window request orientation. 340 * 341 * @return Return window requested orientation. 342 */ 343 Orientation GetRequestedOrientation() const; 344 345 /** 346 * @brief Get calling window id. 347 * 348 * @return Return the calling window id of window. 349 */ 350 uint32_t GetCallingWindow() const; 351 352 /** 353 * @brief Get main handler available 354 * 355 * @return Return true means the main handler available, otherwise not. 356 */ 357 bool GetMainHandlerAvailable() const; 358 359 /** 360 * @brief Get subwindow title 361 * 362 * @return Return the subwindow title 363 */ 364 std::string GetSubWindowTitle() const; 365 366 /** 367 * @brief Get subwindow decor enable 368 * 369 * @return Return ture means the subwindow decor enabled, otherwise not. 370 */ 371 bool GetSubWindowDecorEnable() const; 372 373 /** 374 * @brief Get only sceneboard supported 375 * 376 * @return Return ture means only sceneboard supported, otherwise not. 377 */ 378 bool GetOnlySupportSceneBoard() const; 379 380 private: 381 Rect windowRect_ { 0, 0, 0, 0 }; 382 WindowType type_ { WindowType::WINDOW_TYPE_APP_MAIN_WINDOW }; 383 WindowMode mode_ { WindowMode::WINDOW_MODE_UNDEFINED }; 384 bool focusable_ { true }; 385 bool touchable_ { true }; 386 DisplayId displayId_ { DISPLAY_ID_INVALID }; 387 uint32_t parentId_ = INVALID_WINDOW_ID; 388 std::string windowName_ { "" }; 389 std::string bundleName_ { "" }; 390 uint32_t flags_ { 0 }; 391 PointInfo hitOffset_ { 0, 0 }; 392 WindowTag windowTag_; 393 WindowSessionType sessionType_ { WindowSessionType::SCENE_SESSION }; 394 bool keepScreenOn_ = false; 395 bool turnScreenOn_ = false; 396 bool isMainHandlerAvailable_ = true; 397 float brightness_ = UNDEFINED_BRIGHTNESS; 398 uint32_t callingWindow_ = INVALID_WINDOW_ID; 399 std::unordered_map<WindowType, SystemBarProperty> sysBarPropMap_ { 400 { WindowType::WINDOW_TYPE_STATUS_BAR, SystemBarProperty() }, 401 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, SystemBarProperty() }, 402 }; 403 Orientation requestedOrientation_ { Orientation::UNSPECIFIED }; 404 std::string subWindowTitle_ = { "" }; 405 bool subWindowDecorEnable_ = false; 406 bool onlySupportSceneBoard_ = false; 407 }; 408 } // namespace Rosen 409 } // namespace OHOS 410 #endif // OHOS_ROSEN_WINDOW_OPTION_H 411