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_SESSION_IMPL_H 17 #define OHOS_ROSEN_WINDOW_SESSION_IMPL_H 18 19 #include <atomic> 20 21 #include <shared_mutex> 22 #include <ability_context.h> 23 #include <event_handler.h> 24 #include <i_input_event_consumer.h> 25 #include <ui_content.h> 26 #include <ui/rs_surface_node.h> 27 #include "display_manager.h" 28 #include "singleton_container.h" 29 30 #include "common/include/window_session_property.h" 31 #include "display_info.h" 32 #include "future_callback.h" 33 #include "interfaces/include/ws_common.h" 34 #include "interfaces/include/ws_common_inner.h" 35 #include "session/container/include/zidl/session_stage_stub.h" 36 #include "session/host/include/zidl/session_interface.h" 37 #include "vsync_station.h" 38 #include "window.h" 39 #include "window_option.h" 40 #include "wm_common.h" 41 42 namespace OHOS { 43 namespace Rosen { 44 namespace { 45 template<typename T1, typename T2, typename Ret> 46 using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type; 47 48 /* 49 * DFX 50 */ 51 const std::string SET_UICONTENT_TIMEOUT_LISTENER_TASK_NAME = "SetUIContentTimeoutListener"; 52 constexpr int64_t SET_UICONTENT_TIMEOUT_TIME_MS = 4000; 53 } 54 55 struct WindowTitleVisibleFlags { 56 bool isMaximizeVisible = true; 57 bool isMinimizeVisible = true; 58 bool isSplitVisible = true; 59 bool isCloseVisible = true; 60 }; 61 62 class WindowSessionImpl : public Window, public virtual SessionStageStub { 63 public: 64 explicit WindowSessionImpl(const sptr<WindowOption>& option); 65 ~WindowSessionImpl(); 66 67 static sptr<Window> Find(const std::string& name); 68 static std::vector<sptr<Window>> GetSubWindow(int parentId); 69 Create(const std::shared_ptr<AbilityRuntime::Context>& context, const sptr<Rosen::ISession>& iSession, const std::string& identityToken = �)70 virtual WMError Create(const std::shared_ptr<AbilityRuntime::Context>& context, 71 const sptr<Rosen::ISession>& iSession, 72 const std::string& identityToken = "") { return WMError::WM_OK; } 73 74 /* 75 * inherits from window 76 */ 77 WMError Show(uint32_t reason = 0, bool withAnimation = false, bool withFocus = true) override; 78 WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) override; 79 WMError Destroy() override; 80 virtual WMError Destroy(bool needNotifyServer, bool needClearListener = true); 81 WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage, 82 BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override; 83 WMError SetUIContentByName(const std::string& contentInfo, napi_env env, napi_value storage, 84 AppExecFwk::Ability* ability) override; 85 WMError SetUIContentByAbc(const std::string& abcPath, napi_env env, napi_value storage, 86 AppExecFwk::Ability* ability) override; 87 std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const override; 88 const std::shared_ptr<AbilityRuntime::Context> GetContext() const override; 89 Rect GetRequestRect() const override; 90 WindowType GetType() const override; 91 const std::string& GetWindowName() const override; 92 WindowState GetWindowState() const override; 93 WindowState GetRequestWindowState() const; 94 WMError SetFocusable(bool isFocusable) override; 95 WMError SetTouchable(bool isTouchable) override; 96 97 /* 98 * Window Hierarchy 99 */ 100 WMError SetTopmost(bool topmost) override; 101 bool IsTopmost() const override; 102 WMError SetMainWindowTopmost(bool isTopmost) override; 103 bool IsMainWindowTopmost() const override; 104 105 WMError SetResizeByDragEnabled(bool dragEnabled) override; 106 WMError SetRaiseByClickEnabled(bool raiseEnabled) override; 107 WMError HideNonSystemFloatingWindows(bool shouldHide) override; 108 WMError SetSingleFrameComposerEnabled(bool enable) override; 109 bool IsFloatingWindowAppType() const override; 110 111 /* 112 * PC Window 113 */ 114 bool IsPcOrPadCapabilityEnabled() const override; 115 bool IsPcOrPadFreeMultiWindowMode() const override; 116 117 WMError SetWindowType(WindowType type) override; 118 WMError SetBrightness(float brightness) override; 119 virtual float GetBrightness() const override; 120 void SetRequestedOrientation(Orientation orientation) override; 121 bool GetTouchable() const override; 122 uint32_t GetWindowId() const override; 123 uint64_t GetDisplayId() const override; 124 Rect GetRect() const override; 125 bool GetFocusable() const override; 126 std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) override; 127 WMError SetRestoredRouterStack(const std::string& routerStack) override; 128 Ace::UIContent* GetUIContent() const override; 129 std::shared_ptr<Ace::UIContent> GetUIContentSharedPtr() const; 130 Ace::UIContent* GetUIContentWithId(uint32_t winId) const override; 131 void OnNewWant(const AAFwk::Want& want) override; 132 WMError SetAPPWindowLabel(const std::string& label) override; 133 WMError SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon) override; 134 void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override; 135 int64_t GetVSyncPeriod() override; 136 void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override; 137 void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 138 void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override; 139 bool PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override; 140 141 /* 142 * inherits from session stage 143 */ 144 WSError SetActive(bool active) override; 145 WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, 146 const SceneAnimationConfig& config = { nullptr, ROTATE_ANIMATION_DURATION }) override; 147 void UpdateDensity() override; 148 void SetUniqueVirtualPixelRatio(bool useUniqueDensity, float virtualPixelRatio) override; 149 WSError UpdateOrientation() override; 150 WSError UpdateDisplayId(uint64_t displayId) override; 151 WSError UpdateFocus(bool focus) override; 152 bool IsFocused() const override; 153 WMError RequestFocus() const override; 154 WMError RequestFocusByClient(bool isFocused) const override; 155 WSError UpdateWindowMode(WindowMode mode) override; 156 WSError HandleBackEvent() override; 157 WMError SetWindowGravity(WindowGravity gravity, uint32_t percent) override; 158 WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; 159 KeyboardAnimationConfig GetKeyboardAnimationConfig() override; 160 bool NotifyOnKeyPreImeEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override; 161 void NotifyPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 162 void NotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed, 163 bool notifyInputMethod = true) override; 164 void NotifyOccupiedAreaChangeInfoInner(sptr<OccupiedAreaChangeInfo> info); 165 void NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info, 166 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr) override; 167 void NotifyForegroundInteractiveStatus(bool interactive) override; 168 void NotifyDisplayMove(DisplayId from, DisplayId to) override; 169 170 WMError RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override; 171 WMError UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override; 172 WMError RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override; 173 WMError UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override; 174 WMError RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override; 175 WMError UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override; 176 WMError RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override; 177 WMError UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override; 178 void RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override; 179 void UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override; 180 WMError RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override; 181 WMError UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override; 182 WMError RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override; 183 WMError UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override; 184 WMError RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override; 185 WMError UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override; 186 WMError RegisterWindowVisibilityChangeListener(const IWindowVisibilityListenerSptr& listener) override; 187 WMError UnregisterWindowVisibilityChangeListener(const IWindowVisibilityListenerSptr& listener) override; 188 WMError RegisterWindowNoInteractionListener(const IWindowNoInteractionListenerSptr& listener) override; 189 WMError UnregisterWindowNoInteractionListener(const IWindowNoInteractionListenerSptr& listener) override; 190 void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override; 191 void UnregisterWindowDestroyedListener() override { notifyNativeFunc_ = nullptr; } 192 WMError RegisterScreenshotListener(const sptr<IScreenshotListener>& listener) override; 193 WMError UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener) override; 194 void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) override; 195 void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) override; 196 WMError SetTitleButtonVisible(bool isMaximizeVisible, bool isMinimizeVisible, bool isSplitVisible, 197 bool isCloseVisible) override; 198 199 WMError SetBackgroundColor(const std::string& color) override; 200 WMError SetWindowContainerColor(const std::string& activeColor, const std::string& inactiveColor) override; 201 virtual Orientation GetRequestedOrientation() override; 202 203 int32_t GetParentId() const; 204 int32_t GetPersistentId() const override; 205 sptr<WindowSessionProperty> GetProperty() const; 206 SystemSessionConfig GetSystemSessionConfig() const; 207 sptr<ISession> GetHostSession() const; 208 int32_t GetFloatingWindowParentId(); 209 void NotifyAfterForeground(bool needNotifyListeners = true, bool needNotifyUiContent = true); 210 void NotifyAfterBackground(bool needNotifyListeners = true, bool needNotifyUiContent = true); 211 void NotifyForegroundFailed(WMError ret); 212 void NotifyBackgroundFailed(WMError ret); 213 WSError MarkProcessed(int32_t eventId) override; 214 void UpdateTitleButtonVisibility(); 215 WSError NotifyDestroy() override; 216 WSError NotifyTransferComponentData(const AAFwk::WantParams& wantParams) override; 217 WSErrorCode NotifyTransferComponentDataSync(const AAFwk::WantParams& wantParams, 218 AAFwk::WantParams& reWantParams) override; 219 void NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type); 220 WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override; 221 void NotifyTouchDialogTarget(int32_t posX = 0, int32_t posY = 0) override; 222 void NotifyScreenshot() override; 223 void DumpSessionElementInfo(const std::vector<std::string>& params) override; 224 // colorspace, gamut 225 virtual bool IsSupportWideGamut() override; 226 virtual void SetColorSpace(ColorSpace colorSpace) override; 227 virtual ColorSpace GetColorSpace() override; 228 WSError NotifyTouchOutside() override; 229 WMError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) override; 230 WSError NotifyWindowVisibility(bool isVisible) override; 231 WSError NotifyNoInteractionTimeout(const IWindowNoInteractionListenerSptr& listener); 232 WMError TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, 233 int64_t uiExtensionIdLevel) override; 234 WindowState state_ { WindowState::STATE_INITIAL }; 235 WindowState requestState_ { WindowState::STATE_INITIAL }; 236 WSError UpdateMaximizeMode(MaximizeMode mode) override; 237 void NotifySessionForeground(uint32_t reason, bool withAnimation) override; 238 void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; 239 WSError UpdateTitleInTargetPos(bool isShow, int32_t height) override; 240 WSError NotifyDialogStateChange(bool isForeground) override; 241 bool IsMainHandlerAvailable() const override; 242 243 /* 244 * PiP Window 245 */ 246 WSError NotifyCloseExistPipWindow() override; 247 WSError SetPipActionEvent(const std::string& action, int32_t status) override; 248 WSError SetPiPControlEvent(WsPiPControlType controlType, WsPiPControlStatus status) override; 249 void UpdatePiPRect(const Rect& rect, WindowSizeChangeReason reason) override; 250 void UpdatePiPControlStatus(PiPControlType controlType, PiPControlStatus status) override; 251 void SetAutoStartPiP(bool isAutoStart) override; 252 253 void SetDrawingContentState(bool drawingContentState); 254 WMError RegisterWindowStatusChangeListener(const sptr<IWindowStatusChangeListener>& listener) override; 255 WMError UnregisterWindowStatusChangeListener(const sptr<IWindowStatusChangeListener>& listener) override; 256 WMError SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) override; 257 virtual WMError SetSubWindowModal(bool isModal, ModalityType modalityType = ModalityType::WINDOW_MODALITY) override; 258 virtual WMError SetDecorVisible(bool isVisible) override; 259 virtual WMError SetDecorHeight(int32_t decorHeight) override; 260 virtual WMError GetDecorHeight(int32_t& height) override; 261 virtual WMError GetTitleButtonArea(TitleButtonRect& titleButtonRect) override; 262 WSError GetUIContentRemoteObj(sptr<IRemoteObject>& uiContentRemoteObj) override; 263 virtual WMError RegisterWindowTitleButtonRectChangeListener( 264 const sptr<IWindowTitleButtonRectChangedListener>& listener) override; 265 virtual WMError UnregisterWindowTitleButtonRectChangeListener( 266 const sptr<IWindowTitleButtonRectChangedListener>& listener) override; 267 void NotifyWindowTitleButtonRectChange(TitleButtonRect titleButtonRect); 268 void RecoverSessionListener(); 269 void SetDefaultDisplayIdIfNeed(); 270 WMError RegisterWindowRectChangeListener(const sptr<IWindowRectChangeListener>& listener) override; 271 WMError UnregisterWindowRectChangeListener(const sptr<IWindowRectChangeListener>& listener) override; 272 WMError RegisterSubWindowCloseListeners(const sptr<ISubWindowCloseListener>& listener) override; 273 WMError UnregisterSubWindowCloseListeners(const sptr<ISubWindowCloseListener>& listener) override; 274 WMError RegisterMainWindowCloseListeners(const sptr<IMainWindowCloseListener>& listener) override; 275 WMError UnregisterMainWindowCloseListeners(const sptr<IMainWindowCloseListener>& listener) override; 276 WMError RegisterSwitchFreeMultiWindowListener(const sptr<ISwitchFreeMultiWindowListener>& listener) override; 277 WMError UnregisterSwitchFreeMultiWindowListener(const sptr<ISwitchFreeMultiWindowListener>& listener) override; 278 virtual WMError GetCallingWindowWindowStatus(WindowStatus& windowStatus) const override; 279 virtual WMError GetCallingWindowRect(Rect& rect) const override; 280 virtual void SetUiDvsyncSwitch(bool dvsyncSwitch) override; 281 virtual WMError EnableDrag(bool enableDrag) override; 282 WMError SetContinueState(int32_t continueState) override; 283 284 /* 285 * Multi Window 286 */ 287 WSError SetSplitButtonVisible(bool isVisible) override; 288 289 protected: 290 WMError Connect(); 291 bool IsWindowSessionInvalid() const; 292 void NotifyWindowAfterUnfocused(); 293 void NotifyWindowAfterFocused(); 294 void NotifyAfterActive(); 295 void NotifyAfterInactive(); 296 void NotifyBeforeDestroy(std::string windowName); 297 void NotifyAfterDestroy(); 298 void ClearListenersById(int32_t persistentId); 299 void ClearSwitchFreeMultiWindowListenersById(int32_t persistentId); 300 void ClearVsyncStation(); 301 WMError WindowSessionCreateCheck(); 302 void UpdateDecorEnableToAce(bool isDecorEnable); 303 void UpdateDecorEnable(bool needNotify = false, WindowMode mode = WindowMode::WINDOW_MODE_UNDEFINED); 304 void NotifyModeChange(WindowMode mode, bool hasDeco = true); 305 WMError UpdateProperty(WSPropertyChangeAction action); 306 WMError SetBackgroundColor(uint32_t color); 307 uint32_t GetBackgroundColor() const; 308 virtual WMError SetLayoutFullScreenByApiVersion(bool status); 309 float GetVirtualPixelRatio() override; 310 virtual float GetVirtualPixelRatio(sptr<DisplayInfo> displayInfo); 311 void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason, 312 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr, 313 const sptr<DisplayInfo>& info = nullptr, 314 const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 315 void NotifySizeChange(Rect rect, WindowSizeChangeReason reason); 316 void NotifySubWindowClose(bool& terminateCloseProcess); 317 WMError NotifyMainWindowClose(bool& terminateCloseProcess); 318 void NotifySwitchFreeMultiWindow(bool enable); 319 static sptr<Window> FindWindowById(uint32_t winId); 320 void NotifyWindowStatusChange(WindowMode mode); 321 void NotifyTransformChange(const Transform& transForm) override; 322 bool IsKeyboardEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const; 323 void DispatchKeyEventCallback(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed); 324 bool FilterKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent); 325 void RegisterFrameLayoutCallback(); 326 bool IsVerticalOrientation(Orientation orientation) const; 327 void CopyUniqueDensityParameter(sptr<WindowSessionImpl> parentWindow); 328 sptr<WindowSessionImpl> FindMainWindowWithContext(); 329 sptr<WindowSessionImpl> FindExtensionWindowWithContext(); 330 331 WMError RegisterExtensionAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener); 332 WMError UnregisterExtensionAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener); 333 334 void RefreshNoInteractionTimeoutMonitor(); 335 WindowStatus GetWindowStatusInner(WindowMode mode); 336 337 /** 338 * Sub Window 339 */ 340 void UpdateSubWindowStateAndNotify(int32_t parentPersistentId, const WindowState newState); 341 void DestroySubWindow(); 342 343 sptr<ISession> hostSession_; 344 mutable std::mutex hostSessionMutex_; 345 std::shared_ptr<Ace::UIContent> uiContent_; 346 mutable std::shared_mutex uiContentMutex_; 347 std::shared_ptr<AbilityRuntime::Context> context_; 348 std::shared_ptr<RSSurfaceNode> surfaceNode_; 349 350 sptr<WindowSessionProperty> property_; 351 SystemSessionConfig windowSystemConfig_; 352 NotifyNativeWinDestroyFunc notifyNativeFunc_; 353 354 std::recursive_mutex mutex_; 355 static std::map<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>> windowSessionMap_; 356 // protect windowSessionMap_ 357 static std::shared_mutex windowSessionMutex_; 358 static std::set<sptr<WindowSessionImpl>> windowExtensionSessionSet_; 359 // protect windowExtensionSessionSet_ 360 static std::shared_mutex windowExtensionSessionMutex_; 361 static std::map<int32_t, std::vector<sptr<WindowSessionImpl>>> subWindowSessionMap_; 362 bool isSystembarPropertiesSet_ = false; 363 bool isIgnoreSafeAreaNeedNotify_ = false; 364 bool isIgnoreSafeArea_ = false; 365 std::atomic_bool isFocused_ = false; 366 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 367 bool shouldReNotifyFocus_ = false; 368 std::shared_ptr<VsyncStation> vsyncStation_ = nullptr; 369 std::shared_ptr<IInputEventConsumer> inputEventConsumer_; 370 bool useUniqueDensity_ { false }; 371 float virtualPixelRatio_ { 1.0f }; 372 bool escKeyEventTriggered_ = false; 373 // Check whether the UIExtensionAbility process is started 374 static bool isUIExtensionAbilityProcess_; 375 virtual WMError SetKeyEventFilter(KeyEventFilterFunc filter) override; 376 virtual WMError ClearKeyEventFilter() override; 377 WSError SwitchFreeMultiWindow(bool enable) override; 378 std::string identityToken_ = { "" }; 379 void MakeSubOrDialogWindowDragableAndMoveble(); IsFreeMultiWindowMode() const380 bool IsFreeMultiWindowMode() const 381 { 382 return windowSystemConfig_.IsFreeMultiWindowMode(); 383 } 384 385 /* 386 * DFX 387 */ 388 void SetUIContentComplete(); 389 void AddSetUIContentTimeoutCheck(); 390 void NotifySetUIContentComplete(); 391 std::atomic_bool setUIContentCompleted_ { false }; 392 enum TimeoutErrorCode : int32_t { 393 SET_UICONTENT_TIMEOUT = 1000 394 }; 395 396 /* 397 * Window Lifecycle 398 */ 399 bool hasFirstNotifyInteractive_ = false; 400 bool interactive_ = true; 401 402 /* 403 * Window Layout 404 */ 405 sptr<FutureCallback> layoutCallback_ = nullptr; 406 407 private: 408 //Trans between colorGamut and colorSpace 409 static ColorSpace GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut); 410 static GraphicColorGamut GetSurfaceGamutFromColorSpace(ColorSpace colorSpace); 411 412 template<typename T> WMError RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener); 413 template<typename T> WMError UnregisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener); 414 template<typename T> EnableIfSame<T, IWindowLifeCycle, std::vector<sptr<IWindowLifeCycle>>> GetListeners(); 415 template<typename T> EnableIfSame<T, IDisplayMoveListener, std::vector<sptr<IDisplayMoveListener>>> GetListeners(); 416 template<typename T> 417 EnableIfSame<T, IWindowChangeListener, std::vector<sptr<IWindowChangeListener>>> GetListeners(); 418 template<typename T> 419 EnableIfSame<T, IAvoidAreaChangedListener, std::vector<sptr<IAvoidAreaChangedListener>>> GetListeners(); 420 template<typename T> 421 EnableIfSame<T, IDialogDeathRecipientListener, std::vector<sptr<IDialogDeathRecipientListener>>> GetListeners(); 422 template<typename T> 423 EnableIfSame<T, IDialogTargetTouchListener, std::vector<sptr<IDialogTargetTouchListener>>> GetListeners(); 424 template<typename T> 425 EnableIfSame<T, IOccupiedAreaChangeListener, std::vector<sptr<IOccupiedAreaChangeListener>>> GetListeners(); 426 template<typename T> 427 EnableIfSame<T, IScreenshotListener, std::vector<sptr<IScreenshotListener>>> GetListeners(); 428 template<typename T> 429 EnableIfSame<T, ITouchOutsideListener, std::vector<sptr<ITouchOutsideListener>>> GetListeners(); 430 template<typename T> 431 EnableIfSame<T, IWindowVisibilityChangedListener, std::vector<IWindowVisibilityListenerSptr>> GetListeners(); 432 template<typename T> 433 EnableIfSame<T, IWindowNoInteractionListener, std::vector<IWindowNoInteractionListenerSptr>> GetListeners(); 434 template<typename T> 435 EnableIfSame<T, IWindowTitleButtonRectChangedListener, 436 std::vector<sptr<IWindowTitleButtonRectChangedListener>>> GetListeners(); 437 template<typename T> void ClearUselessListeners(std::map<int32_t, T>& listeners, int32_t persistentId); 438 RSSurfaceNode::SharedPtr CreateSurfaceNode(const std::string& name, WindowType type); 439 template<typename T> 440 EnableIfSame<T, IWindowStatusChangeListener, std::vector<sptr<IWindowStatusChangeListener>>> GetListeners(); 441 template<typename T> 442 EnableIfSame<T, IWindowRectChangeListener, std::vector<sptr<IWindowRectChangeListener>>> GetListeners(); 443 template<typename T> 444 EnableIfSame<T, ISubWindowCloseListener, sptr<ISubWindowCloseListener>> GetListeners(); 445 template<typename T> 446 EnableIfSame<T, IMainWindowCloseListener, sptr<IMainWindowCloseListener>> GetListeners(); 447 template<typename T> 448 EnableIfSame<T, ISwitchFreeMultiWindowListener, std::vector<sptr<ISwitchFreeMultiWindowListener>>> GetListeners(); 449 void NotifyAfterFocused(); 450 void NotifyUIContentFocusStatus(); 451 void NotifyAfterUnfocused(bool needNotifyUiContent = true); 452 void NotifyAfterResumed(); 453 void NotifyAfterPaused(); 454 455 WMError InitUIContent(const std::string& contentInfo, napi_env env, napi_value storage, 456 WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability, 457 OHOS::Ace::UIContentErrorCode& aceRet); 458 WMError SetUIContentInner(const std::string& contentInfo, napi_env env, napi_value storage, 459 WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability); 460 std::shared_ptr<std::vector<uint8_t>> GetAbcContent(const std::string& abcPath); 461 inline void DestroyExistUIContent(); 462 std::string GetRestoredRouterStack(); 463 464 bool CheckIfNeedCommitRsTransaction(WindowSizeChangeReason wmReason); 465 void UpdateRectForRotation(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason, 466 const SceneAnimationConfig& config); 467 void UpdateRectForOtherReason(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason, 468 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr); 469 void NotifyRotationAnimationEnd(); 470 void SubmitNoInteractionMonitorTask(int32_t eventId, const IWindowNoInteractionListenerSptr& listener); 471 bool IsUserOrientation(Orientation orientation) const; 472 void GetTitleButtonVisible(bool isPC, bool& hideMaximizeButton, bool& hideMinimizeButton, bool& hideSplitButton, 473 bool& hideCloseButton); 474 WMError GetAppForceLandscapeConfig(AppForceLandscapeConfig& config); 475 void SetForceSplitEnable(bool isForceSplit, const std::string& homePage = ""); 476 void SetFrameLayoutCallbackEnable(bool enable); 477 void UpdateFrameLayoutCallbackIfNeeded(WindowSizeChangeReason wmReason); 478 bool IsNotifyInteractiveDuplicative(bool interactive); 479 void SetUniqueVirtualPixelRatioForSub(bool useUniqueDensity, float virtualPixelRatio); 480 481 static std::recursive_mutex lifeCycleListenerMutex_; 482 static std::recursive_mutex windowChangeListenerMutex_; 483 static std::recursive_mutex avoidAreaChangeListenerMutex_; 484 static std::recursive_mutex dialogDeathRecipientListenerMutex_; 485 static std::recursive_mutex dialogTargetTouchListenerMutex_; 486 static std::recursive_mutex occupiedAreaChangeListenerMutex_; 487 static std::recursive_mutex screenshotListenerMutex_; 488 static std::recursive_mutex touchOutsideListenerMutex_; 489 static std::recursive_mutex windowVisibilityChangeListenerMutex_; 490 static std::recursive_mutex windowNoInteractionListenerMutex_; 491 static std::recursive_mutex windowStatusChangeListenerMutex_; 492 static std::recursive_mutex windowTitleButtonRectChangeListenerMutex_; 493 static std::mutex displayMoveListenerMutex_; 494 static std::mutex windowRectChangeListenerMutex_; 495 static std::mutex subWindowCloseListenersMutex_; 496 static std::mutex mainWindowCloseListenersMutex_; 497 static std::mutex switchFreeMultiWindowListenerMutex_; 498 static std::map<int32_t, std::vector<sptr<IWindowLifeCycle>>> lifecycleListeners_; 499 static std::map<int32_t, std::vector<sptr<IDisplayMoveListener>>> displayMoveListeners_; 500 static std::map<int32_t, std::vector<sptr<IWindowChangeListener>>> windowChangeListeners_; 501 static std::map<int32_t, std::vector<sptr<IAvoidAreaChangedListener>>> avoidAreaChangeListeners_; 502 static std::map<int32_t, std::vector<sptr<IDialogDeathRecipientListener>>> dialogDeathRecipientListeners_; 503 static std::map<int32_t, std::vector<sptr<IDialogTargetTouchListener>>> dialogTargetTouchListener_; 504 static std::map<int32_t, std::vector<sptr<IOccupiedAreaChangeListener>>> occupiedAreaChangeListeners_; 505 static std::map<int32_t, std::vector<sptr<IScreenshotListener>>> screenshotListeners_; 506 static std::map<int32_t, std::vector<sptr<ITouchOutsideListener>>> touchOutsideListeners_; 507 static std::map<int32_t, std::vector<IWindowVisibilityListenerSptr>> windowVisibilityChangeListeners_; 508 static std::map<int32_t, std::vector<IWindowNoInteractionListenerSptr>> windowNoInteractionListeners_; 509 static std::map<int32_t, std::vector<sptr<IWindowStatusChangeListener>>> windowStatusChangeListeners_; 510 static std::map<int32_t, std::vector<sptr<IWindowTitleButtonRectChangedListener>>> 511 windowTitleButtonRectChangeListeners_; 512 static std::map<int32_t, std::vector<sptr<IWindowRectChangeListener>>> windowRectChangeListeners_; 513 static std::map<int32_t, sptr<ISubWindowCloseListener>> subWindowCloseListeners_; 514 static std::map<int32_t, sptr<IMainWindowCloseListener>> mainWindowCloseListeners_; 515 static std::map<int32_t, std::vector<sptr<ISwitchFreeMultiWindowListener>>> switchFreeMultiWindowListeners_; 516 517 // FA only 518 sptr<IAceAbilityHandler> aceAbilityHandler_; 519 520 std::atomic<int32_t> lastInteractionEventId_ { 0 }; 521 522 bool isMainHandlerAvailable_ = true; 523 524 std::string subWindowTitle_ = { "" }; 525 std::string dialogTitle_ = { "" }; 526 std::shared_mutex keyEventFilterMutex_; 527 KeyEventFilterFunc keyEventFilter_; 528 WindowTitleVisibleFlags windowTitleVisibleFlags_; 529 sptr<WindowOption> windowOption_; 530 531 std::string restoredRouterStack_; // It was set and get in same thread, which is js thread. 532 533 /* 534 * Window Layout 535 */ 536 std::atomic_bool windowSizeChanged_ = true; 537 std::atomic_bool enableFrameLayoutFinishCb_ = false; 538 WindowSizeChangeReason lastSizeChangeReason_ = WindowSizeChangeReason::END; 539 bool postTaskDone_ = false; 540 int16_t rotationAnimationCount_ { 0 }; 541 542 /* 543 * Multi Window 544 */ 545 bool isSplitButtonVisible_ = true; 546 }; 547 } // namespace Rosen 548 } // namespace OHOS 549 550 #endif // OHOS_ROSEN_WINDOW_SESSION_IMPL_H 551