1/* 2 * Copyright (c) 2023-2024 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_H 17#define OHOS_ROSEN_WINDOW_H 18 19#include <parcel.h> 20#include <refbase.h> 21#include <pixel_map.h> 22#include <iremote_object.h> 23 24#include "wm_common.h" 25#include "window_option.h" 26 27typedef struct napi_env__* napi_env; 28typedef struct napi_value__* napi_value; 29 30namespace OHOS::MMI { 31class PointerEvent; 32class KeyEvent; 33class AxisEvent; 34} 35 36namespace OHOS::AppExecFwk { 37class Configuration; 38class Ability; 39} 40 41namespace OHOS::AbilityRuntime { 42class AbilityContext; 43class Context; 44} 45 46namespace OHOS::Ace { 47class UIContent; 48class ViewportConfig; 49} 50 51namespace OHOS::AAFwk { 52class Want; 53} 54 55namespace OHOS { 56namespace Rosen { 57class RSSurfaceNode; 58class RSTransaction; 59using NotifyNativeWinDestroyFunc = std::function<void(std::string windowName)>; 60using SendRenderDataCallback = bool (*)(const void*, const size_t, const int32_t, const int32_t, const uint64_t); 61using ContentInfoCallback = std::function<void(std::string contentInfo)>; 62 63class IWindowLifeCycle : virtual public RefBase { 64}; 65class IWindowChangeListener : virtual public RefBase { 66}; 67class IWindowSystemBarEnableListener : virtual public RefBase { 68public: 69 virtual WMError OnSetSpecificBarProperty(WindowType type, const SystemBarProperty& property) = 0; 70}; 71class IIgnoreViewSafeAreaListener : virtual public RefBase { 72public: 73 virtual void SetIgnoreViewSafeArea(bool ignoreViewSafeArea) = 0; 74}; 75class IAvoidAreaChangedListener : virtual public RefBase { 76public: 77 virtual void OnAvoidAreaChanged(const AvoidArea avoidArea, AvoidAreaType type) {} 78}; 79class IWindowDragListener : virtual public RefBase { 80}; 81class IDisplayMoveListener : virtual public RefBase { 82}; 83class IDispatchInputEventListener : virtual public RefBase { 84}; 85class OccupiedAreaChangeInfo : public Parcelable { 86public: 87 virtual bool Marshalling(Parcel& parcel) const override; 88 static OccupiedAreaChangeInfo* Unmarshalling(Parcel& parcel); 89}; 90class IOccupiedAreaChangeListener : virtual public RefBase { 91}; 92class IAceAbilityHandler : virtual public RefBase { 93}; 94class IInputEventConsumer { 95}; 96class ITouchOutsideListener : virtual public RefBase { 97}; 98class IAnimationTransitionController : virtual public RefBase { 99public: 100 virtual void AnimationForShown() = 0; 101 virtual void AnimationForHidden() = 0; 102}; 103class IScreenshotListener : virtual public RefBase { 104}; 105class IDialogTargetTouchListener : virtual public RefBase { 106}; 107class IDialogDeathRecipientListener : virtual public RefBase { 108}; 109class IWindowTitleButtonRectChangedListener : virtual public RefBase { 110}; 111class IWindowVisibilityChangedListener : virtual public RefBase { 112}; 113 114using WindowVisibilityListenerSptr = sptr<IWindowVisibilityChangedListener>; 115 116class IWindowNoInteractionListener : virtual public RefBase { 117}; 118using IWindowNoInteractionListenerSptr = sptr<IWindowNoInteractionListener>; 119 120static WMError DefaultCreateErrCode = WMError::WM_OK; 121class WINDOW_EXPORT Window : public RefBase { 122public: 123 static sptr<Window> Create(const std::string& windowName, 124 sptr<WindowOption>& option, const std::shared_ptr<AbilityRuntime::Context>& context = nullptr, 125 WMError& errCode = DefaultCreateErrCode); 126 static sptr<Window> Find(const std::string& windowName); 127 static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr); 128 static sptr<Window> GetTopWindowWithId(uint32_t mainWinId); 129 static std::vector<sptr<Window>> GetSubWindow(uint32_t parentId); 130 static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 131 virtual std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const = 0; 132 virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const = 0; 133 virtual Rect GetRect() const = 0; 134 virtual Rect GetRequestRect() const = 0; 135 virtual WindowType GetType() const = 0; 136 virtual WindowMode GetMode() const = 0; 137 virtual float GetAlpha() const = 0; 138 virtual const std::string& GetWindowName() const = 0; 139 virtual uint32_t GetWindowId() const = 0; 140 virtual uint64_t GetDisplayId() const = 0; 141 virtual uint32_t GetWindowFlags() const = 0; 142 virtual WindowState GetWindowState() const = 0; 143 virtual WMError SetFocusable(bool isFocusable) = 0; 144 virtual bool GetFocusable() const = 0; 145 virtual WMError SetTouchable(bool isTouchable) = 0; 146 virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const = 0; 147 virtual bool GetTouchable() const = 0; 148 virtual bool IsLayoutFullScreen() const = 0; 149 virtual bool IsFullScreen() const = 0; 150 virtual WMError SetWindowMode(WindowMode mode) = 0; 151 virtual WMError SetWindowType(WindowType type) = 0; 152 virtual WMError SetAlpha(float alpha) = 0; 153 virtual WMError SetTransform(const Transform& trans) = 0; 154 virtual const Transform& GetTransform() const = 0; 155 virtual WMError RemoveWindowFlag(WindowFlag flag) = 0; 156 virtual WMError AddWindowFlag(WindowFlag flag) = 0; 157 virtual WMError SetWindowFlags(uint32_t flags) = 0; 158 virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) = 0; 159 virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) = 0; 160 virtual WMError SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) = 0; 161 virtual WMError SetSystemBarProperties(const std::map<WindowType, SystemBarProperty>& properties, 162 const std::map<WindowType, SystemBarPropertyFlag>& propertyFlags) = 0; 163 virtual WMError GetSystemBarProperties(std::map<WindowType, SystemBarProperty>& properties) = 0; 164 virtual WMError SetFullScreen(bool status) = 0; 165 virtual WMError SetLayoutFullScreen(bool status) = 0; 166 virtual WMError SetTitleAndDockHoverShown(bool titleHoverShowEnabled = true, 167 bool dockHoverShowEnabled = true) 168 { 169 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 170 } 171 virtual WMError Destroy() = 0; 172 virtual WMError Show(uint32_t reason = 0, bool withAnimation = false, bool withFocus = true) = 0; 173 virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) = 0; 174 virtual WMError MoveTo(int32_t x, int32_t y, bool isMoveToGlobal = false) = 0; 175 virtual WMError MoveToAsync(int32_t x, int32_t y) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 176 virtual WMError Resize(uint32_t width, uint32_t height) = 0; 177 virtual WMError ResizeAsync(uint32_t width, uint32_t height) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 178 virtual WMError SetWindowGravity(WindowGravity gravity, uint32_t percent) = 0; 179 virtual WMError SetKeepScreenOn(bool keepScreenOn) = 0; 180 virtual bool IsKeepScreenOn() const = 0; 181 virtual WMError SetTurnScreenOn(bool turnScreenOn) = 0; 182 virtual bool IsTurnScreenOn() const = 0; 183 virtual WMError SetBackgroundColor(const std::string& color) = 0; 184 virtual WMError SetTransparent(bool isTransparent) = 0; 185 virtual bool IsTransparent() const = 0; 186 virtual WMError SetBrightness(float brightness) = 0; 187 virtual float GetBrightness() const = 0; 188 virtual WMError SetCallingWindow(uint32_t windowId) = 0; 189 virtual WMError SetPrivacyMode(bool isPrivacyMode) = 0; 190 virtual bool IsPrivacyMode() const = 0; 191 virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) = 0; 192 virtual WMError BindDialogTarget(sptr<IRemoteObject> targetToken) = 0; 193 virtual WMError SetDialogBackGestureEnabled(bool isEnabled) = 0; 194 virtual WMError RaiseToAppTop() = 0; 195 virtual WMError SetSnapshotSkip(bool isSkip) = 0; 196 virtual WMError SetCornerRadius(float cornerRadius) = 0; 197 virtual WMError SetShadowRadius(float radius) = 0; 198 virtual WMError SetShadowColor(std::string color) = 0; 199 virtual WMError SetShadowOffsetX(float offsetX) = 0; 200 virtual WMError SetShadowOffsetY(float offsetY) = 0; 201 virtual WMError SetBlur(float radius) = 0; 202 virtual WMError SetBackdropBlur(float radius) = 0; 203 virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) = 0; 204 virtual WMError RequestFocus() const = 0; 205 virtual WMError RequestFocusByClient(bool isFocused) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 206 virtual bool IsFocused() const = 0; 207 virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) = 0; 208 virtual void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) = 0; 209 virtual void ConsumeKeyEvent(const std::shared_ptr<MMI::KeyEvent>& inputEvent) = 0; 210 virtual void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& inputEvent) = 0; 211 virtual void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) = 0; 212 virtual int64_t GetVSyncPeriod() = 0; 213 virtual void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType) {} 214 virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) = 0; 215 virtual WMError RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) = 0; 216 virtual WMError UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) = 0; 217 virtual WMError RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) = 0; 218 virtual WMError UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) = 0; 219 virtual WMError RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0; 220 virtual WMError UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) = 0; 221 virtual WMError RegisterDragListener(const sptr<IWindowDragListener>& listener) = 0; 222 virtual WMError UnregisterDragListener(const sptr<IWindowDragListener>& listener) = 0; 223 virtual WMError RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0; 224 virtual WMError UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) = 0; 225 virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) = 0; 226 virtual void UnregisterWindowDestroyedListener() {} 227 virtual WMError RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0; 228 virtual WMError UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) = 0; 229 virtual WMError RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) = 0; 230 virtual WMError UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) = 0; 231 virtual WMError RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) = 0; 232 virtual WMError RegisterScreenshotListener(const sptr<IScreenshotListener>& listener) = 0; 233 virtual WMError UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener) = 0; 234 virtual WMError RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) = 0; 235 virtual WMError UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) = 0; 236 virtual void RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) = 0; 237 virtual void UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) = 0; 238 virtual WMError RegisterSystemBarEnableListener(const sptr<IWindowSystemBarEnableListener>& listener) = 0; 239 virtual WMError UnRegisterSystemBarEnableListener(const sptr<IWindowSystemBarEnableListener>& listener) = 0; 240 virtual WMError RegisterIgnoreViewSafeAreaListener(const sptr<IIgnoreViewSafeAreaListener>& listener) = 0; 241 virtual WMError UnRegisterIgnoreViewSafeAreaListener(const sptr<IIgnoreViewSafeAreaListener>& listener) = 0; 242 virtual void NotifyTouchDialogTarget(int32_t posX = 0, int32_t posY = 0) = 0; 243 virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) = 0; 244 virtual WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage, 245 BackupAndRestoreType type = BackupAndRestoreType::NONE, sptr<IRemoteObject> token = nullptr, 246 AppExecFwk::Ability* ability = nullptr) = 0; 247 virtual WMError SetUIContentByName(const std::string& contentInfo, napi_env env, napi_value storage, 248 AppExecFwk::Ability* ability = nullptr) 249 { 250 return WMError::WM_OK; 251 } 252 virtual WMError SetUIContentByAbc(const std::string& abcPath, napi_env env, napi_value storage, 253 AppExecFwk::Ability* ability = nullptr) 254 { 255 return WMError::WM_OK; 256 } 257 virtual std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) = 0; 258 virtual Ace::UIContent* GetUIContent() const = 0; 259 virtual void OnNewWant(const AAFwk::Want& want) = 0; 260 virtual void SetRequestedOrientation(Orientation) = 0; 261 virtual Orientation GetRequestedOrientation() = 0; 262 virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) = 0; 263 virtual uint32_t GetRequestModeSupportInfo() const = 0; 264 virtual WMError SetTouchHotAreas(const std::vector<Rect>& rects) = 0; 265 virtual void GetRequestedTouchHotAreas(std::vector<Rect>& rects) const = 0; 266 virtual bool IsMainHandlerAvailable() const = 0; 267 virtual WMError SetAPPWindowLabel(const std::string& label) = 0; 268 virtual WMError SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon) = 0; 269 virtual WMError DisableAppWindowDecor() = 0; 270 virtual WMError Minimize() = 0; 271 virtual WMError Maximize() = 0; 272 virtual WMError Recover() = 0; 273 virtual WMError Restore() { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 274 virtual void StartMove() = 0; 275 virtual WmErrorCode StartMoveSystemWindow() { return WmErrorCode::WM_OK; }; 276 virtual WMError Close() = 0; 277 virtual void SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel) = 0; 278 virtual bool IsSupportWideGamut() = 0; 279 virtual void SetColorSpace(ColorSpace colorSpace) = 0; 280 virtual ColorSpace GetColorSpace() = 0; 281 virtual void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) = 0; 282 virtual std::shared_ptr<Media::PixelMap> Snapshot() = 0; 283 virtual WMError NotifyMemoryLevel(int32_t level) = 0; 284 virtual bool IsAllowHaveSystemSubWindow() = 0; 285 virtual WMError SetAspectRatio(float ratio) = 0; 286 virtual WMError ResetAspectRatio() = 0; 287 virtual KeyboardAnimationConfig GetKeyboardAnimationConfig() = 0; 288 virtual void SetNeedDefaultAnimation(bool needDefaultAnimation) = 0; 289 290 virtual void SetViewportConfig(const Ace::ViewportConfig& config) = 0; 291 virtual void UpdateViewportConfig() = 0; 292 virtual void SetOrientation(Orientation orientation) = 0; 293 virtual void SetSize(int32_t width, int32_t height) = 0; 294 virtual void SetDensity(float density) = 0; 295 virtual WMError SetDefaultDensityEnabled(bool enabled) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 296 virtual bool GetDefaultDensityEnabled() { return false; } 297 virtual float GetVirtualPixelRatio() { return 0.0f; } 298 virtual void UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type); 299 virtual void CreateSurfaceNode(const std::string name, const SendRenderDataCallback& callback) = 0; 300 virtual void SetContentInfoCallback(const ContentInfoCallback& callback) = 0; 301 virtual WMError SetResizeByDragEnabled(bool dragEnabled) = 0; 302 virtual WMError SetRaiseByClickEnabled(bool raiseEnabled) = 0; 303 virtual WMError RaiseAboveTarget(int32_t subWindowId) = 0; 304 virtual WMError SetTopmost(bool topmost) { return WMError::WM_OK; } 305 virtual bool IsTopmost() const { return false; } 306 virtual WMError SetMainWindowTopmost(bool isTopmost) { return WMError::WM_OK; } 307 virtual bool IsMainWindowTopmost() const { return false; } 308 virtual WMError HideNonSystemFloatingWindows(bool shouldHide) = 0; 309 virtual bool IsFloatingWindowAppType() const { return false; } 310 virtual bool IsPcOrPadCapabilityEnabled() const { return false; } 311 virtual bool IsPcOrPadFreeMultiWindowMode() const { return false; } 312 virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) = 0; 313 virtual WMError RegisterWindowVisibilityChangeListener(const WindowVisibilityListenerSptr& listener) = 0; 314 virtual WMError UnregisterWindowVisibilityChangeListener(const WindowVisibilityListenerSptr& listener) = 0; 315 virtual WMError SetWindowLimits(WindowLimits& windowLimits) { return WMError::WM_OK; }; 316 virtual WMError GetWindowLimits(WindowLimits& windowLimits) { return WMError::WM_OK; }; 317 virtual WMError EnableDrag(bool enableDrag) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; }; 318 virtual WMError RegisterWindowNoInteractionListener(const IWindowNoInteractionListenerSptr& listener) 319 { 320 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 321 } 322 virtual WMError UnregisterWindowNoInteractionListener(const IWindowNoInteractionListenerSptr& listener) 323 { 324 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 325 } 326 virtual WMError SetSingleFrameComposerEnabled(bool enable) = 0; 327 virtual WMError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) = 0; 328 virtual WMError SetDecorVisible(bool isVisible) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 329 virtual WMError SetTitleButtonVisible(bool isMaximizeVisible, bool isMinimizeVisible, bool isSplitVisible, 330 bool isCloseVisible) 331 { 332 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 333 } 334 virtual WMError SetDecorHeight(int32_t decorHeight) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 335 virtual WMError GetDecorHeight(int32_t& height) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 336 virtual WMError GetTitleButtonArea(TitleButtonRect& titleButtonRect) 337 { 338 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 339 } 340 virtual WMError SetWindowContainerColor(const std::string& activeColor, const std::string& inactiveColor) 341 { 342 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 343 } 344 virtual WMError RegisterWindowTitleButtonRectChangeListener( 345 const sptr<IWindowTitleButtonRectChangedListener>& listener) 346 { 347 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 348 } 349 virtual WMError UnregisterWindowTitleButtonRectChangeListener( 350 const sptr<IWindowTitleButtonRectChangedListener>& listener) 351 { 352 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 353 } 354 /** 355 * @brief Set the modality of window. 356 * 357 * @param isModal bool. 358 * @param modalityType ModalityType. 359 * @return WMError 360 */ 361 virtual WMError SetSubWindowModal(bool isModal, ModalityType modalityType = ModalityType::WINDOW_MODALITY) 362 { 363 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 364 } 365 virtual WMError Recover(uint32_t reason = 0) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; }; 366 367 virtual WMError Maximize(MaximizePresentation present) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 368 369 virtual WMError SetWindowMask(const std::vector<std::vector<uint32_t>>& windowMask) 370 { 371 return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; 372 } 373 374 virtual WMError SetGrayScale(float grayScale) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 375 376 /** 377 * @brief Set the Dvsync object 378 * 379 * @param dvsyncSwitch bool. 380 * @return * void 381 */ 382 virtual void SetUiDvsyncSwitch(bool dvsyncSwitch) {} 383 384 virtual WMError SetImmersiveModeEnabledState(bool enable) { return WMError::WM_OK; } 385 386 virtual bool GetImmersiveModeEnabledState() const { return true; } 387 388 virtual WMError GetWindowStatus(WindowStatus& windowStatus) { return WMError::WM_ERROR_DEVICE_NOT_SUPPORT; } 389 390 virtual void NotifyExtensionTimeout(int32_t errorCode) {} 391 392 /** 393 * @brief Set whether to enable gesture back. 394 * @param enable the value true means to enable gesture back, and false means the opposite. 395 * @return WM_OK means set success, others means set failed. 396 */ 397 virtual WMError SetGestureBackEnabled(bool enable) { return WMError::WM_OK; } 398 399 /** 400 * @brief Get whether the gesture back is enabled or not. 401 * 402 * @return the value true means to enable gesture back, and false means the opposite. 403 */ 404 virtual bool GetGestureBackEnabled() const { return true; } 405}; 406} 407} 408#endif // OHOS_ROSEN_WINDOW_H 409