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_canvas_node.h> 27 #include <ui/rs_surface_node.h> 28 #include <ui/rs_ui_director.h> 29 #include "display_manager.h" 30 #include "singleton_container.h" 31 32 #include "common/include/window_session_property.h" 33 #include "display_info.h" 34 #include "future_callback.h" 35 #include "interfaces/include/ws_common.h" 36 #include "interfaces/include/ws_common_inner.h" 37 #include "session/container/include/zidl/session_stage_stub.h" 38 #include "session/host/include/zidl/session_interface.h" 39 #include "vsync_station.h" 40 #include "window.h" 41 #include "window_helper.h" 42 #include "window_option.h" 43 #include "wm_common.h" 44 #include "wm_common_inner.h" 45 #include "floating_ball_template_info.h" 46 #include "lifecycle_future_callback.h" 47 48 namespace OHOS { 49 namespace Rosen { 50 namespace { 51 template<typename T1, typename T2, typename Ret> 52 using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type; 53 54 /* 55 * DFX 56 */ 57 const std::string SET_UICONTENT_TIMEOUT_LISTENER_TASK_NAME = "SetUIContentTimeoutListener"; 58 constexpr int64_t SET_UICONTENT_TIMEOUT_TIME_MS = 4000; 59 constexpr int64_t SET_UICONTENT_TIMEOUT_TIME_AFTER_FREEZE_MS = 5000; 60 } 61 62 struct WindowTitleVisibleFlags { 63 bool isMaximizeVisible = true; 64 bool isMinimizeVisible = true; 65 bool isSplitVisible = true; 66 bool isCloseVisible = true; 67 }; 68 69 struct CursorInfo { 70 double left = -1.0; 71 double top = -1.0; 72 double width = -1.0; 73 double height = -1.0; 74 }; 75 76 using IKBWillShowListener = IKeyboardWillShowListener; 77 using IKBWillHideListener = IKeyboardWillHideListener; 78 79 class WindowSessionImpl : public Window, public virtual SessionStageStub { 80 public: 81 explicit WindowSessionImpl(const sptr<WindowOption>& option); 82 ~WindowSessionImpl(); 83 84 static sptr<Window> Find(const std::string& name); 85 static std::vector<sptr<Window>> GetSubWindow(int parentId); 86 static sptr<WindowSessionImpl> GetWindowWithId(uint32_t windowId); 87 88 virtual WMError Create(const std::shared_ptr<AbilityRuntime::Context>& context, 89 const sptr<Rosen::ISession>& iSession, 90 const std::string& identityToken = "", bool isModuleAbilityHookEnd = false) { return WMError::WM_OK; } 91 92 /* 93 * inherits from window 94 */ 95 WMError Show(uint32_t reason = 0, bool withAnimation = false, bool withFocus = true) override; 96 WMError Show(uint32_t reason, bool withAnimation, bool withFocus, bool waitAttach) override; 97 WMError Hide(uint32_t reason = 0, bool withAnimation = false, bool isFromInnerkits = true) override; 98 WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits, bool waitDetach) override; 99 WMError Destroy(uint32_t reason = 0) override; 100 virtual WMError Destroy(bool needNotifyServer, bool needClearListener = true, uint32_t reason = 0); 101 WMError NapiSetUIContent(const std::string& contentInfo, ani_env* env, ani_object storage, 102 BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override; 103 WMError NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage, 104 BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability) override; 105 WMError SetUIContentByName(const std::string& contentInfo, napi_env env, napi_value storage, 106 AppExecFwk::Ability* ability) override; 107 WMError SetUIContentByAbc(const std::string& abcPath, napi_env env, napi_value storage, 108 AppExecFwk::Ability* ability) override; 109 std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const override; 110 const std::shared_ptr<AbilityRuntime::Context> GetContext() const override; 111 void SetContext(const std::shared_ptr<AbilityRuntime::Context>& context); 112 Rect GetRequestRect() const override; 113 Rect GetGlobalDisplayRect() const override; 114 WMError ClientToGlobalDisplay(const Position& inPosition, Position& outPosition) const override; 115 WMError GlobalDisplayToClient(const Position& inPosition, Position& outPosition) const override; 116 WSError UpdateGlobalDisplayRectFromServer(const WSRect& rect, SizeChangeReason reason) override; 117 WindowType GetType() const override; 118 const std::string& GetWindowName() const override; 119 WindowState GetWindowState() const override; 120 WindowState GetRequestWindowState() const; 121 WMError SetFocusable(bool isFocusable) override; 122 WMError SetTouchable(bool isTouchable) override; 123 124 /* 125 * Window Hierarchy 126 */ 127 WMError SetTopmost(bool topmost) override; 128 bool IsTopmost() const override; 129 WMError SetMainWindowTopmost(bool isTopmost) override; 130 bool IsMainWindowTopmost() const override; 131 void SetSubWindowZLevelToProperty(); 132 int32_t GetSubWindowZLevelByFlags(WindowType type, uint32_t windowFlags, bool isTopmost); 133 WMError RaiseToAppTopOnDrag(); 134 bool IsApplicationModalSubWindowShowing(int32_t parentId); 135 136 WMError SetResizeByDragEnabled(bool dragEnabled) override; 137 WMError SetRaiseByClickEnabled(bool raiseEnabled) override; 138 WMError HideNonSystemFloatingWindows(bool shouldHide) override; 139 WMError SetSingleFrameComposerEnabled(bool enable) override; 140 bool IsFloatingWindowAppType() const override; 141 142 /* 143 * PC Window 144 */ 145 bool IsPcWindow() const override; 146 bool IsPadWindow() const override; 147 bool IsPcOrFreeMultiWindowCapabilityEnabled() const override; 148 bool IsPcOrPadFreeMultiWindowMode() const override; 149 bool IsPadAndNotFreeMutiWindowCompatibleMode() const override; 150 bool IsSceneBoardEnabled() const override; 151 bool GetCompatibleModeInPc() const override; 152 void HookCompatibleModeAvoidAreaNotify() override; 153 bool IsAdaptToCompatibleImmersive() const override; 154 WMError SetWindowDelayRaiseEnabled(bool isEnabled) override; 155 bool IsWindowDelayRaiseEnabled() const override; 156 WMError SetTitleButtonVisible(bool isMaximizeVisible, bool isMinimizeVisible, bool isSplitVisible, 157 bool isCloseVisible) override; 158 WMError SetSubWindowModal(bool isModal, ModalityType modalityType = ModalityType::WINDOW_MODALITY) override; 159 WMError SetWindowModal(bool isModal) override; 160 void SetTargetAPIVersion(uint32_t targetAPIVersion); 161 uint32_t GetTargetAPIVersion() const; 162 void NotifyClientWindowSize(); 163 bool IsFullScreenPcAppInPadMode() const; 164 sptr<WindowSessionProperty> GetPropertyByContext() const; 165 166 /* 167 * Compatible Mode 168 */ 169 bool IsAdaptToSimulationScale() const; 170 bool IsAdaptToProportionalScale() const; 171 bool IsInCompatScaleMode() const; 172 bool IsInCompatScaleStatus() const; 173 WMError UpdateCompatScaleInfo(const Transform& transform); 174 void SetCompatInfoInExtensionConfig(AAFwk::WantParams& want) const; 175 bool IsAdaptToSubWindow() const; 176 static void RegisterWindowScaleCallback(); 177 static WMError GetWindowScaleCoordinate(uint32_t windowId, CursorInfo& cursorInfo); 178 static sptr<WindowSessionImpl> GetScaleWindow(uint32_t windowId); 179 180 WMError SetWindowType(WindowType type) override; 181 WMError SetBrightness(float brightness) override; 182 virtual float GetBrightness() const override; 183 void SetRequestedOrientation(Orientation orientation, bool needAnimation = true) override; 184 WMError RegisterPreferredOrientationChangeListener( 185 const sptr<IPreferredOrientationChangeListener>& listener) override; 186 WMError UnregisterPreferredOrientationChangeListener( 187 const sptr<IPreferredOrientationChangeListener>& listener) override; 188 void NotifyPreferredOrientationChange(Orientation orientation) override; 189 WMError RegisterOrientationChangeListener(const sptr<IWindowOrientationChangeListener>& listener) override; 190 WMError UnregisterOrientationChangeListener(const sptr<IWindowOrientationChangeListener>& listener) override; 191 bool GetTouchable() const override; 192 uint32_t GetWindowId() const override; 193 uint64_t GetDisplayId() const override; 194 Rect GetRect() const override; 195 bool GetFocusable() const override; 196 std::string GetContentInfo(BackupAndRestoreType type = BackupAndRestoreType::CONTINUATION) override; 197 WMError SetRestoredRouterStack(const std::string& routerStack) override; 198 Ace::UIContent* GetUIContent() const override; 199 std::shared_ptr<Ace::UIContent> GetUIContentSharedPtr() const; 200 Ace::UIContent* GetUIContentWithId(uint32_t winId) const override; 201 void OnNewWant(const AAFwk::Want& want) override; 202 void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override; 203 int64_t GetVSyncPeriod() override; 204 void FlushFrameRate(uint32_t rate, int32_t animatorExpectedFrameRate, uint32_t rateType = 0) override; 205 void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 206 void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override; 207 void ConsumeBackEvent() override; 208 bool IsDialogSessionBackGestureEnabled() override; 209 bool PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override; 210 bool OnPointDown(int32_t eventId, int32_t posX, int32_t posY) override; 211 WMError SetIntentParam(const std::string& intentParam, const std::function<void()>& loadPageCallback, 212 bool isColdStart) override; 213 void SetForceSplitEnable(AppForceLandscapeConfig& config); 214 215 /* 216 * inherits from session stage 217 */ 218 WSError SetActive(bool active) override; 219 WSError UpdateRect(const WSRect& rect, SizeChangeReason reason, 220 const SceneAnimationConfig& config = { nullptr, ROTATE_ANIMATION_DURATION }, 221 const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}) override; 222 void UpdateDensity() override; 223 void SetUniqueVirtualPixelRatio(bool useUniqueDensity, float virtualPixelRatio) override; 224 WSError UpdateOrientation() override; 225 WSError UpdateDisplayId(uint64_t displayId) override; 226 WSError UpdateFocus(bool focus) override; 227 bool IsFocused() const override; 228 WMError RequestFocus() const override; 229 WMError RequestFocusByClient(bool isFocused) const override; 230 WSError UpdateWindowMode(WindowMode mode) override; GetTopNavDestinationName(std::string & topNavDestName)231 WSError GetTopNavDestinationName(std::string& topNavDestName) override { return WSError::WS_OK; } 232 WSError HandleBackEvent() override; 233 KeyboardAnimationConfig GetKeyboardAnimationConfig() override; 234 bool NotifyOnKeyPreImeEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override; 235 void NotifyPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 236 void NotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed, 237 bool notifyInputMethod = true) override; 238 void NotifyOccupiedAreaChangeInfoInner(sptr<OccupiedAreaChangeInfo> info); 239 void NotifyOccupiedAreaChangeInfo(sptr<OccupiedAreaChangeInfo> info, 240 const std::shared_ptr<RSTransaction>& rsTransaction, const Rect& callingSessionRect, 241 const std::map<AvoidAreaType, AvoidArea>& avoidAreas) override; 242 void NotifyKeyboardWillShow(const KeyboardAnimationInfo& keyboardAnimationInfo); 243 void NotifyKeyboardWillHide(const KeyboardAnimationInfo& keyboardAnimationInfo); 244 virtual void NotifyKeyboardDidShow(const KeyboardPanelInfo& keyboardPanelInfo); 245 virtual void NotifyKeyboardDidHide(const KeyboardPanelInfo& keyboardPanelInfo); 246 void NotifyKeyboardAnimationCompleted(const KeyboardPanelInfo& keyboardPanelInfo) override; 247 void NotifyKeyboardAnimationWillBegin(const KeyboardAnimationInfo& keyboardAnimationInfo, 248 const std::shared_ptr<RSTransaction>& rsTransaction) override; 249 void NotifyForegroundInteractiveStatus(bool interactive) override; 250 void NotifyDisplayMove(DisplayId from, DisplayId to) override; 251 void NotifyWindowCrossAxisChange(CrossAxisState state) override; 252 253 WMError RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override; 254 WMError UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override; 255 WMError RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override; 256 WMError UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override; 257 WMError RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override; 258 WMError UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override; 259 WMError RegisterWindowCrossAxisListener(const sptr<IWindowCrossAxisListener>& listener) override; 260 WMError UnregisterWindowCrossAxisListener(const sptr<IWindowCrossAxisListener>& listener) override; 261 void RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override; 262 void UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override; 263 WMError RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override; 264 WMError UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override; 265 WMError RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override; 266 WMError UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override; 267 WMError RegisterKeyboardWillShowListener(const sptr<IKBWillShowListener>& listener) override; 268 WMError UnregisterKeyboardWillShowListener(const sptr<IKBWillShowListener>& listener) override; 269 WMError RegisterKeyboardWillHideListener(const sptr<IKBWillHideListener>& listener) override; 270 WMError UnregisterKeyboardWillHideListener(const sptr<IKBWillHideListener>& listener) override; 271 WMError RegisterKeyboardDidShowListener(const sptr<IKeyboardDidShowListener>& listener) override; 272 WMError UnregisterKeyboardDidShowListener(const sptr<IKeyboardDidShowListener>& listener) override; 273 WMError RegisterKeyboardDidHideListener(const sptr<IKeyboardDidHideListener>& listener) override; 274 WMError UnregisterKeyboardDidHideListener(const sptr<IKeyboardDidHideListener>& listener) override; 275 WMError RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override; 276 WMError UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override; 277 WMError RegisterWindowVisibilityChangeListener(const IWindowVisibilityListenerSptr& listener) override; 278 WMError UnregisterWindowVisibilityChangeListener(const IWindowVisibilityListenerSptr& listener) override; 279 WMError RegisterDisplayIdChangeListener(const IDisplayIdChangeListenerSptr& listener) override; 280 WMError UnregisterDisplayIdChangeListener(const IDisplayIdChangeListenerSptr& listener) override; 281 WMError RegisterSystemDensityChangeListener(const ISystemDensityChangeListenerSptr& listener) override; 282 WMError UnregisterSystemDensityChangeListener(const ISystemDensityChangeListenerSptr& listener) override; 283 WMError RegisterAcrossDisplaysChangeListener(const IAcrossDisplaysChangeListenerSptr& listener) override; 284 WMError UnRegisterAcrossDisplaysChangeListener(const IAcrossDisplaysChangeListenerSptr& listener) override; 285 WMError RegisterWindowNoInteractionListener(const IWindowNoInteractionListenerSptr& listener) override; 286 WMError UnregisterWindowNoInteractionListener(const IWindowNoInteractionListenerSptr& listener) override; 287 WMError RegisterWindowStageLifeCycleListener(const sptr<IWindowStageLifeCycle>& listener) override; 288 WMError UnregisterWindowStageLifeCycleListener(const sptr<IWindowStageLifeCycle>& listener) override; 289 WMError RegisterSystemBarPropertyListener(const sptr<ISystemBarPropertyListener>& listener) override; 290 WMError UnregisterSystemBarPropertyListener(const sptr<ISystemBarPropertyListener>& listener) override; 291 void NotifySystemBarPropertyUpdate(WindowType type, const SystemBarProperty& property) override; 292 void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override; UnregisterWindowDestroyedListener()293 void UnregisterWindowDestroyedListener() override { notifyNativeFunc_ = nullptr; } 294 WMError RegisterScreenshotListener(const sptr<IScreenshotListener>& listener) override; 295 WMError UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener) override; 296 WMError RegisterScreenshotAppEventListener(const IScreenshotAppEventListenerSptr& listener) override; 297 WMError UnregisterScreenshotAppEventListener(const IScreenshotAppEventListenerSptr& listener) override; 298 void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) override; 299 void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) override; 300 void GetExtensionConfig(AAFwk::WantParams& want) const override; 301 WMError OnExtensionMessage(uint32_t code, int32_t persistentId, const AAFwk::Want& data) override; 302 virtual WMError HandleHostWindowRaise(uint32_t code, int32_t persistentId, const AAFwk::Want& data); 303 virtual WMError HandleRegisterHostWindowRectChangeListener(uint32_t code, int32_t persistentId, 304 const AAFwk::Want& data); 305 virtual WMError HandleUnregisterHostWindowRectChangeListener(uint32_t code, int32_t persistentId, 306 const AAFwk::Want& data); 307 virtual WMError HandleUIExtRegisterKeyboardDidShowListener(uint32_t code, int32_t persistentId, 308 const AAFwk::Want& data); 309 virtual WMError HandleUIExtUnregisterKeyboardDidShowListener(uint32_t code, int32_t persistentId, 310 const AAFwk::Want& data); 311 virtual WMError HandleUIExtRegisterKeyboardDidHideListener(uint32_t code, int32_t persistentId, 312 const AAFwk::Want& data); 313 virtual WMError HandleUIExtUnregisterKeyboardDidHideListener(uint32_t code, int32_t persistentId, 314 const AAFwk::Want& data); 315 316 WMError SetBackgroundColor(const std::string& color) override; 317 virtual Orientation GetRequestedOrientation() override; 318 319 int32_t GetParentId() const; 320 int32_t GetPersistentId() const override; 321 sptr<WindowSessionProperty> GetProperty() const; 322 SystemSessionConfig GetSystemSessionConfig() const; 323 sptr<ISession> GetHostSession() const; 324 int32_t GetFloatingWindowParentId(); 325 void NotifyAfterForeground(bool needNotifyListeners = true, 326 bool needNotifyUiContent = true, bool waitAttach = false); 327 void GetAttachStateSyncResult(bool waitAttachState, bool afterForeground) const; 328 void NotifyAfterBackground(bool needNotifyListeners = true, 329 bool needNotifyUiContent = true, bool waitDetach = false); 330 void NotifyAfterDidForeground(uint32_t reason = static_cast<uint32_t>(WindowStateChangeReason::NORMAL)); 331 void NotifyAfterDidBackground(uint32_t reason = static_cast<uint32_t>(WindowStateChangeReason::NORMAL)); 332 void NotifyForegroundFailed(WMError ret); 333 void NotifyBackgroundFailed(WMError ret); 334 WSError MarkProcessed(int32_t eventId) override; 335 void UpdateTitleButtonVisibility(); 336 void HideTitleButton(bool& hideSplitButton, bool& hideMaximizeButton, bool& hideMinimizeButton, 337 bool& hideCloseButton); 338 WSError NotifyDestroy() override; 339 WSError NotifyTransferComponentData(const AAFwk::WantParams& wantParams) override; 340 WSErrorCode NotifyTransferComponentDataSync(const AAFwk::WantParams& wantParams, 341 AAFwk::WantParams& reWantParams) override; 342 void NotifyTouchDialogTarget(int32_t posX = 0, int32_t posY = 0) override; 343 void NotifyScreenshot() override; 344 void DumpSessionElementInfo(const std::vector<std::string>& params) override; 345 // colorspace, gamut 346 virtual bool IsSupportWideGamut() override; 347 virtual void SetColorSpace(ColorSpace colorSpace) override; 348 virtual ColorSpace GetColorSpace() override; 349 WSError NotifyTouchOutside() override; 350 WMError SetLandscapeMultiWindow(bool isLandscapeMultiWindow) override; 351 WSError NotifyWindowVisibility(bool isVisible) override; 352 WSError NotifyNoInteractionTimeout(const IWindowNoInteractionListenerSptr& listener); 353 WMError TransferAccessibilityEvent(const Accessibility::AccessibilityEventInfo& info, 354 int64_t uiExtensionIdLevel) override; 355 WindowState state_ { WindowState::STATE_INITIAL }; 356 WindowState requestState_ { WindowState::STATE_INITIAL }; 357 WSError UpdateMaximizeMode(MaximizeMode mode) override; 358 void NotifySessionForeground(uint32_t reason, bool withAnimation) override; 359 void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; 360 WSError UpdateTitleInTargetPos(bool isShow, int32_t height) override; 361 WSError NotifyDialogStateChange(bool isForeground) override; 362 bool IsMainHandlerAvailable() const override; 363 364 /* 365 * PiP Window 366 */ 367 WSError NotifyCloseExistPipWindow() override; 368 WSError SetPipActionEvent(const std::string& action, int32_t status) override; 369 WSError SetPiPControlEvent(WsPiPControlType controlType, WsPiPControlStatus status) override; 370 WSError NotifyPipWindowSizeChange(double width, double height, double scale) override; 371 void UpdatePiPRect(const Rect& rect, WindowSizeChangeReason reason) override; 372 void UpdatePiPControlStatus(PiPControlType controlType, PiPControlStatus status) override; 373 void SetAutoStartPiP(bool isAutoStart, uint32_t priority, uint32_t width, uint32_t height) override; 374 void UpdatePiPTemplateInfo(PiPTemplateInfo& pipTemplateInfo) override; 375 WMError GetPiPSettingSwitchStatus(bool& switchStatus) const override; 376 377 WMError UpdateFloatingBall(const FloatingBallTemplateBaseInfo& fbTemplateBaseInfo, 378 const std::shared_ptr<Media::PixelMap>& icon) override; 379 void NotifyPrepareCloseFloatingBall() override; 380 WSError SendFbActionEvent(const std::string& action) override; 381 WMError RestoreFbMainWindow(const std::shared_ptr<AAFwk::Want>& want) override; 382 383 WMError GetFloatingBallWindowId(uint32_t& windowId) override; 384 385 void SetDrawingContentState(bool drawingContentState); 386 WMError RegisterWindowStatusChangeListener(const sptr<IWindowStatusChangeListener>& listener) override; 387 WMError UnregisterWindowStatusChangeListener(const sptr<IWindowStatusChangeListener>& listener) override; 388 WMError SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) override; 389 void SetLayoutTransform(const Transform& trans); 390 Transform GetLayoutTransform() const override; 391 392 /* 393 * Window Decor 394 */ 395 WMError SetDecorVisible(bool isVisible) override; 396 WMError GetDecorVisible(bool& isVisible) override; 397 WMError SetWindowTitleMoveEnabled(bool enable) override; 398 WMError SetDecorHeight(int32_t decorHeight) override; 399 WMError GetDecorHeight(int32_t& height) override; 400 WMError SetDecorButtonStyle(const DecorButtonStyle& decorButtonStyle) override; 401 WMError GetDecorButtonStyle(DecorButtonStyle& decorButtonStyle) override; 402 WMError GetTitleButtonArea(TitleButtonRect& titleButtonRect) override; 403 WMError SetAPPWindowLabel(const std::string& label) override; 404 WMError SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon) override; 405 WMError SetWindowContainerColor(const std::string& activeColor, const std::string& inactiveColor) override; 406 WMError SetWindowContainerModalColor(const std::string& activeColor, const std::string& inactiveColor) override; 407 nlohmann::json SetContainerButtonStyle(const DecorButtonStyle& decorButtonStyle); 408 void UpdateDecorEnable(bool needNotify = false, WindowMode mode = WindowMode::WINDOW_MODE_UNDEFINED); 409 410 /* 411 * Window Decor listener 412 */ 413 WMError RegisterWindowTitleButtonRectChangeListener( 414 const sptr<IWindowTitleButtonRectChangedListener>& listener) override; 415 WMError UnregisterWindowTitleButtonRectChangeListener( 416 const sptr<IWindowTitleButtonRectChangedListener>& listener) override; 417 void NotifyWindowTitleButtonRectChange(TitleButtonRect titleButtonRect); 418 WMError RegisterSubWindowCloseListeners(const sptr<ISubWindowCloseListener>& listener) override; 419 WMError UnregisterSubWindowCloseListeners(const sptr<ISubWindowCloseListener>& listener) override; 420 void NotifySubWindowClose(bool& terminateCloseProcess); 421 WMError RegisterMainWindowCloseListeners(const sptr<IMainWindowCloseListener>& listener) override; 422 WMError UnregisterMainWindowCloseListeners(const sptr<IMainWindowCloseListener>& listener) override; 423 WMError NotifyMainWindowClose(bool& terminateCloseProcess); 424 WMError RegisterWindowWillCloseListeners(const sptr<IWindowWillCloseListener>& listener) override; 425 WMError UnRegisterWindowWillCloseListeners(const sptr<IWindowWillCloseListener>& listener) override; 426 WMError NotifyWindowWillClose(sptr<Window> window); 427 428 WSError GetUIContentRemoteObj(sptr<IRemoteObject>& uiContentRemoteObj) override; 429 void RecoverSessionListener(); 430 void SetDefaultDisplayIdIfNeed(); 431 WMError RegisterWindowRectChangeListener(const sptr<IWindowRectChangeListener>& listener) override; 432 WMError UnregisterWindowRectChangeListener(const sptr<IWindowRectChangeListener>& listener) override; 433 WMError RegisterRectChangeInGlobalDisplayListener( 434 const sptr<IRectChangeInGlobalDisplayListener>& listener) override; 435 WMError UnregisterRectChangeInGlobalDisplayListener( 436 const sptr<IRectChangeInGlobalDisplayListener>& listener) override; 437 WMError RegisterExtensionSecureLimitChangeListener( 438 const sptr<IExtensionSecureLimitChangeListener>& listener) override; 439 WMError UnregisterExtensionSecureLimitChangeListener( 440 const sptr<IExtensionSecureLimitChangeListener>& listener) override; 441 virtual WMError GetCallingWindowWindowStatus(WindowStatus& windowStatus) const override; 442 virtual WMError GetCallingWindowRect(Rect& rect) const override; 443 virtual void SetUiDvsyncSwitch(bool dvsyncSwitch) override; 444 virtual void SetTouchEvent(int32_t touchType) override; 445 WMError SetContinueState(int32_t continueState) override; CheckAndModifyWindowRect(uint32_t & width,uint32_t & height)446 virtual WMError CheckAndModifyWindowRect(uint32_t& width, uint32_t& height) 447 { 448 return WMError::WM_ERROR_INVALID_PARAM; 449 } 450 451 /* 452 * Multi Window 453 */ 454 WSError SetSplitButtonVisible(bool isVisible) override; 455 WMError GetIsMidScene(bool& isMidScene) override; 456 WSError SendContainerModalEvent(const std::string& eventName, const std::string& eventValue) override; 457 458 /* 459 * Window Layout 460 */ 461 WMError EnableDrag(bool enableDrag) override; 462 WSError SetDragActivated(bool dragActivated) override; 463 WSError SetEnableDragBySystem(bool enableDrag) override; 464 bool IsWindowDraggable(); 465 float GetVirtualPixelRatio() override; 466 CrossAxisState GetCrossAxisState() override; 467 void RegisterKeyFrameCallback(); 468 WSError LinkKeyFrameCanvasNode(std::shared_ptr<RSCanvasNode>& rsCanvasNode) override; 469 WSError SetKeyFramePolicy(KeyFramePolicy& keyFramePolicy) override; 470 WMError SetDragKeyFramePolicy(const KeyFramePolicy& keyFramePolicy) override; 471 WMError RegisterWindowStatusDidChangeListener(const sptr<IWindowStatusDidChangeListener>& listener) override; 472 WMError UnregisterWindowStatusDidChangeListener(const sptr<IWindowStatusDidChangeListener>& listener) override; NotifyLayoutFinishAfterWindowModeChange(WindowMode mode)473 WSError NotifyLayoutFinishAfterWindowModeChange(WindowMode mode) override { return WSError::WS_OK; } UpdateWindowModeForUITest(int32_t updateMode)474 WMError UpdateWindowModeForUITest(int32_t updateMode) override { return WMError::WM_OK; } 475 void UpdateEnableDragWhenSwitchMultiWindow(bool enable); NotifyAppHookWindowInfoUpdated()476 WSError NotifyAppHookWindowInfoUpdated() override { return WSError::WS_DO_NOTHING; } 477 void SetNotifySizeChangeFlag(bool flag); 478 479 /* 480 * Free Multi Window 481 */ 482 WMError RegisterSwitchFreeMultiWindowListener(const sptr<ISwitchFreeMultiWindowListener>& listener) override; 483 WMError UnregisterSwitchFreeMultiWindowListener(const sptr<ISwitchFreeMultiWindowListener>& listener) override; SetFreeMultiWindowMode(bool enable)484 void SetFreeMultiWindowMode(bool enable) 485 { 486 windowSystemConfig_.freeMultiWindowEnable_ = enable; 487 } 488 void SwitchSubWindow(bool freeMultiWindowEnable, int32_t parentId); 489 490 /* 491 * Window Immersive 492 */ 493 WMError RegisterAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener) override; 494 WMError UnregisterAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener) override; 495 WMError SetAvoidAreaOption(uint32_t avoidAreaOption) override; 496 WMError GetAvoidAreaOption(uint32_t& avoidAreaOption) override; 497 void NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type); 498 WSError UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type) override; IsSystemWindow()499 bool IsSystemWindow() const override { return WindowHelper::IsSystemWindow(GetType()); } IsAppWindow()500 bool IsAppWindow() const override { return WindowHelper::IsAppWindow(GetType()); } GetRootHostWindowType()501 WindowType GetRootHostWindowType() const override { return rootHostWindowType_; } SetRootHostWindowType(WindowType & rootHostWindowType)502 void SetRootHostWindowType(WindowType& rootHostWindowType) override { rootHostWindowType_ = rootHostWindowType; } 503 WMError UpdateSystemBarProperties(const std::unordered_map<WindowType, SystemBarProperty>& systemBarProperties, 504 const std::unordered_map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags) override; 505 void UpdateSpecificSystemBarEnabled(bool systemBarEnable, bool systemBarEnableAnimation, 506 SystemBarProperty& property) override; 507 WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; 508 509 /* 510 * Window Property 511 */ 512 WMError SetWindowDefaultDensityEnabled(bool enabled) override; 513 void SetDefaultDensityEnabledValue(bool enabled); 514 WSError NotifyDisplayIdChange(DisplayId displayId); 515 WSError NotifyScreenshotAppEvent(ScreenshotEventType type) override; 516 bool IsDeviceFeatureCapableFor(const std::string& feature) const override; 517 bool IsDeviceFeatureCapableForFreeMultiWindow() const override; 518 bool IsAnco() const override; 519 520 /* 521 * Window Input Event 522 */ 523 WMError NotifyWatchGestureConsumeResult(int32_t keyCode, bool isConsumed); 524 WMError NotifyWatchFocusActiveChange(bool isActive); 525 WMError InjectTouchEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 526 void RegisterWatchFocusActiveChangeCallback(); 527 void NotifyConsumeResultToFloatWindow(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool isConsumed); 528 529 /* 530 * HightLight Window 531 */ 532 bool GetExclusivelyHighlighted() const; 533 WMError IsWindowHighlighted(bool& highlighted) const override; 534 WMError SetExclusivelyHighlighted(bool isExclusivelyHighlighted) override; 535 WMError RegisterWindowHighlightChangeListeners(const sptr<IWindowHighlightChangeListener>& listener) override; 536 WMError UnregisterWindowHighlightChangeListeners(const sptr<IWindowHighlightChangeListener>& listener) override; 537 WSError NotifyHighlightChange(bool isHighlight) override; 538 539 /* 540 * PC Fold Screen 541 */ 542 bool IsWaterfallModeEnabled() override; 543 WMError RegisterWaterfallModeChangeListener(const sptr<IWaterfallModeChangeListener>& listener) override; 544 WMError UnregisterWaterfallModeChangeListener(const sptr<IWaterfallModeChangeListener>& listener) override; 545 546 /* 547 * Window Rotation 548 */ 549 WMError RegisterWindowRotationChangeListener(const sptr<IWindowRotationChangeListener>& listener) override; 550 WMError UnregisterWindowRotationChangeListener(const sptr<IWindowRotationChangeListener>& listener) override; 551 RotationChangeResult NotifyRotationChange(const RotationChangeInfo& rotationChangeInfo) override; 552 WMError CheckMultiWindowRect(uint32_t& width, uint32_t& height); 553 WSError SetCurrentRotation(int32_t currentRotation) override; 554 void UpdateCurrentWindowOrientation(DisplayOrientation displayOrientation); 555 DisplayOrientation GetCurrentWindowOrientation() const; 556 Orientation ConvertUserOrientationToUserPageOrientation(Orientation orientation) const; 557 Orientation ConvertInvalidOrientation(); 558 void SetUserRequestedOrientation(Orientation orientation) override; 559 bool IsUserOrientation(Orientation orientation) const; 560 bool IsUserPageOrientation(Orientation orientation) const; 561 bool isNeededForciblySetOrientation(Orientation orientation) override; 562 WMError SetFollowScreenChange(bool isFollowScreenChange) override; 563 564 /* 565 * UIExtension 566 */ 567 WSError NotifyExtensionSecureLimitChange(bool isLimit) override; 568 569 /* 570 * RS Client Multi Instance 571 */ 572 std::shared_ptr<RSUIDirector> GetRSUIDirector() const override; 573 std::shared_ptr<RSUIContext> GetRSUIContext() const override; 574 575 /* 576 * Window LifeCycle 577 */ 578 void NotifyLifecyclePausedStatus() override; 579 void NotifyAppUseControlStatus(bool isUseControl) override; 580 void NotifyAfterLifecycleForeground(); 581 void NotifyAfterLifecycleBackground(); 582 void NotifyAfterLifecycleResumed(); 583 void NotifyAfterLifecyclePaused(); 584 WMError GetRouterStackInfo(std::string& routerStackInfo) override; 585 void SetNavDestinationInfo(const std::string& navDestinationInfo) override; 586 587 protected: 588 WMError Connect(); 589 bool IsWindowSessionInvalid() const; 590 void NotifyWindowAfterUnfocused(); 591 void NotifyWindowAfterFocused(); 592 void NotifyAfterActive(); 593 void NotifyAfterInactive(); 594 void NotifyBeforeDestroy(std::string windowName); 595 void NotifyAfterDestroy(); 596 template<typename T> WMError RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener); 597 template<typename T> WMError UnregisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener); 598 void ClearListenersById(int32_t persistentId); 599 600 /* 601 * Free Multi Window 602 */ 603 void ClearSwitchFreeMultiWindowListenersById(int32_t persistentId); 604 void NotifySwitchFreeMultiWindow(bool enable); 605 606 void ClearVsyncStation(); 607 WMError WindowSessionCreateCheck(); 608 void UpdateDecorEnableToAce(bool isDecorEnable); 609 void NotifyModeChange(WindowMode mode, bool hasDeco = true); 610 WMError UpdateProperty(WSPropertyChangeAction action); 611 WMError SetBackgroundColor(uint32_t color); 612 uint32_t GetBackgroundColor() const; 613 virtual WMError SetLayoutFullScreenByApiVersion(bool status); 614 virtual float GetVirtualPixelRatio(const sptr<DisplayInfo>& displayInfo); 615 void UpdateViewportConfig(const Rect& rect, WindowSizeChangeReason reason, 616 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr, 617 const sptr<DisplayInfo>& info = nullptr, 618 const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 619 void NotifySizeChange(Rect rect, WindowSizeChangeReason reason); 620 void NotifyGlobalDisplayRectChange(const Rect& rect, WindowSizeChangeReason reason); 621 void NotifyUIExtHostWindowRectChangeListeners(const Rect rect, const WindowSizeChangeReason reason); 622 static sptr<Window> FindWindowById(uint32_t winId); 623 void NotifyWindowStatusChange(WindowMode mode); 624 void NotifyTransformChange(const Transform& transForm) override; 625 void NotifySingleHandTransformChange(const SingleHandTransform& singleHandTransform) override; 626 bool IsKeyboardEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) const; 627 WMError HandleEscKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed); 628 void DispatchKeyEventCallback(const std::shared_ptr<MMI::KeyEvent>& keyEvent, bool& isConsumed); 629 bool IsVerticalOrientation(Orientation orientation) const; 630 bool IsHorizontalOrientation(Orientation orientation) const; 631 void CopyUniqueDensityParameter(sptr<WindowSessionImpl> parentWindow); 632 sptr<WindowSessionImpl> FindMainWindowWithContext() const; 633 sptr<WindowSessionImpl> FindExtensionWindowWithContext() const; 634 635 WMError RegisterExtensionAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener); 636 WMError UnregisterExtensionAvoidAreaChangeListener(const sptr<IAvoidAreaChangedListener>& listener); 637 638 void RefreshNoInteractionTimeoutMonitor(); 639 WindowStatus GetWindowStatusInner(WindowMode mode); 640 641 /* 642 * PC Event Filter 643 */ 644 bool FilterKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent); 645 bool FilterPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 646 WMError SetKeyEventFilter(KeyEventFilterFunc filter) override; 647 WMError ClearKeyEventFilter() override; 648 WMError SetMouseEventFilter(MouseEventFilterFunc filter) override; 649 WMError ClearMouseEventFilter() override; 650 WMError SetTouchEventFilter(TouchEventFilterFunc filter) override; 651 WMError ClearTouchEventFilter() override; 652 653 /* 654 * UIExtension 655 */ 656 std::unordered_set<int32_t> rectChangeUIExtListenerIds_; 657 std::unordered_set<int32_t> keyboardDidShowUIExtListenerIds_; 658 std::unordered_set<int32_t> keyboardDidHideUIExtListenerIds_; 659 std::unordered_map<int32_t, sptr<IKeyboardDidShowListener>> keyboardDidShowUIExtListeners_; 660 std::unordered_map<int32_t, sptr<IKeyboardDidHideListener>> keyboardDidHideUIExtListeners_; 661 void WriteKeyboardInfoToWant(AAFwk::Want& want, const KeyboardPanelInfo& keyboardPanelInfo) const; 662 void ReadKeyboardInfoFromWant(const AAFwk::Want& want, KeyboardPanelInfo& keyboardPanelInfo) const; 663 static std::set<sptr<WindowSessionImpl>>& GetWindowExtensionSessionSet(); 664 665 /* 666 * Sub Window 667 */ 668 void UpdateSubWindowStateAndNotify(int32_t parentPersistentId, const WindowState newState); 669 void DestroySubWindow(); 670 bool IsSubWindowMaximizeSupported() const override; 671 void UpdateSubWindowInfo(uint32_t subWindowLevel, const std::shared_ptr<AbilityRuntime::Context>& context); 672 void GetSubWindows(int32_t parentPersistentId, std::vector<sptr<WindowSessionImpl>>& subWindows); 673 void RemoveSubWindow(int32_t parentPersistentId); 674 675 sptr<WindowOption> windowOption_; 676 sptr<ISession> hostSession_; 677 mutable std::mutex hostSessionMutex_; 678 std::shared_ptr<Ace::UIContent> uiContent_; 679 mutable std::shared_mutex uiContentMutex_; 680 std::shared_ptr<AbilityRuntime::Context> context_; 681 mutable std::shared_mutex contextMutex_; 682 std::shared_ptr<RSSurfaceNode> surfaceNode_; 683 684 sptr<WindowSessionProperty> property_; 685 SystemSessionConfig windowSystemConfig_; 686 NotifyNativeWinDestroyFunc notifyNativeFunc_; 687 688 std::recursive_mutex mutex_; 689 static std::map<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>> windowSessionMap_; 690 // protect windowSessionMap_ 691 static std::shared_mutex windowSessionMutex_; 692 // protect g_windowExtensionSessionSet_ 693 static std::shared_mutex windowExtensionSessionMutex_; 694 bool isSystembarPropertiesSet_ = false; 695 bool isIgnoreSafeAreaNeedNotify_ = false; 696 bool isIgnoreSafeArea_ = false; 697 std::atomic_bool isFocused_ = false; 698 std::atomic_bool isHighlighted_ = false; 699 std::atomic_bool shouldReNotifyHighlight_ = false; 700 std::shared_ptr<AppExecFwk::EventHandler> handler_ = nullptr; 701 bool shouldReNotifyFocus_ = false; 702 std::shared_ptr<VsyncStation> vsyncStation_ = nullptr; 703 std::shared_ptr<IInputEventConsumer> inputEventConsumer_; 704 bool useUniqueDensity_ { false }; 705 float virtualPixelRatio_ { 1.0f }; 706 bool escKeyEventTriggered_ = false; 707 bool escKeyHasDown_ { false }; 708 // Check whether the UIExtensionAbility process is started 709 static bool isUIExtensionAbilityProcess_; 710 WSError SwitchFreeMultiWindow(bool enable) override; 711 std::string identityToken_ = { "" }; 712 void MakeSubOrDialogWindowDragableAndMoveble(); IsFreeMultiWindowMode()713 bool IsFreeMultiWindowMode() const 714 { 715 return windowSystemConfig_.IsFreeMultiWindowMode(); 716 } 717 718 /* 719 * Sub Window 720 */ 721 static std::recursive_mutex subWindowSessionMutex_; 722 static std::map<int32_t, std::vector<sptr<WindowSessionImpl>>> subWindowSessionMap_; 723 724 /* 725 * Compatible Mode 726 */ 727 float compatScaleX_ = 1.0f; 728 float compatScaleY_ = 1.0f; 729 730 /* 731 * DFX 732 */ 733 void SetUIContentComplete(); 734 void AddSetUIContentTimeoutCheck(); 735 void NotifySetUIContentComplete(); 736 std::atomic_bool setUIContentCompleted_ { false }; 737 void SetUIExtensionDestroyComplete(); 738 void SetUIExtensionDestroyCompleteInSubWindow(); 739 void AddSetUIExtensionDestroyTimeoutCheck(); 740 std::atomic_bool setUIExtensionDestroyCompleted_ { false }; 741 std::atomic_bool startUIExtensionDestroyTimer_ { false }; 742 enum TimeoutErrorCode : int32_t { 743 SET_UICONTENT_TIMEOUT = 1000, 744 SET_UIEXTENSION_DESTROY_TIMEOUT 745 }; 746 747 /* 748 * Window Lifecycle 749 */ 750 mutable std::mutex appUseControlMutex_; 751 bool hasFirstNotifyInteractive_ = false; 752 bool isAppUseControl_ = false; 753 bool interactive_ = true; 754 bool isDidForeground_ = false; 755 bool isInteractiveStateFlag_ = false; 756 std::string intentParam_; 757 std::function<void()> loadPageCallback_; 758 bool isColdStart_ = true; 759 bool isIntentColdStart_ = true; 760 std::string navDestinationInfo_; 761 sptr<LifecycleFutureCallback> lifecycleCallback_ = nullptr; 762 763 /* 764 * Window Layout 765 */ 766 std::atomic_bool isDragTaskPostDone_ = true; 767 void FlushLayoutSize(int32_t width, int32_t height) override; 768 sptr<FutureCallback> layoutCallback_ = nullptr; 769 sptr<FutureCallback> getTargetInfoCallback_ = nullptr; 770 sptr<FutureCallback> getRotationResultFuture_ = nullptr; 771 sptr<FutureCallback> updateRectCallback_ = nullptr; 772 void UpdateVirtualPixelRatio(const sptr<Display>& display); 773 WMError GetVirtualPixelRatio(float& vpr); 774 void SetCurrentTransform(const Transform& transform); 775 Transform GetCurrentTransform() const; 776 void NotifyAfterUIContentReady(); SetNeedRenotifyTransform(bool isNeedRenotify)777 void SetNeedRenotifyTransform(bool isNeedRenotify) { needRenotifyTransform_.store(isNeedRenotify); } IsNeedRenotifyTransform()778 bool IsNeedRenotifyTransform() const { return needRenotifyTransform_.load(); } 779 mutable std::recursive_mutex transformMutex_; 780 std::atomic<CrossAxisState> crossAxisState_ = CrossAxisState::STATE_INVALID; 781 bool IsValidCrossState(int32_t state) const; 782 template <typename T> 783 EnableIfSame<T, IWindowCrossAxisListener, std::vector<sptr<IWindowCrossAxisListener>>> GetListeners(); 784 void NotifyWindowStatusDidChange(WindowMode mode); 785 void NotifyFirstValidLayoutUpdate(const Rect& preRect, const Rect& newRect); 786 std::atomic_bool hasSetEnableDrag_ = false; 787 void HookWindowSizeByHookWindowInfo(Rect& rect); 788 void SetAppHookWindowInfo(const HookWindowInfo& hookWindowInfo); 789 HookWindowInfo GetAppHookWindowInfo(); GetAppHookWindowInfoFromServer(HookWindowInfo & hookWindowInfo)790 virtual WMError GetAppHookWindowInfoFromServer(HookWindowInfo& hookWindowInfo) { return WMError::WM_OK; } 791 792 /* 793 * Window Immersive 794 */ 795 std::map<AvoidAreaType, AvoidArea> lastAvoidAreaMap_; 796 uint32_t GetStatusBarHeight() const override; 797 WindowType rootHostWindowType_ = WindowType::APP_MAIN_WINDOW_BASE; 798 799 /* 800 * PC Fold Screen 801 */ 802 bool supportEnterWaterfallMode_ { false }; 803 std::atomic_bool isFullScreenWaterfallMode_ { false }; 804 std::atomic_bool isValidWaterfallMode_ { false }; 805 bool isAcrossDisplays_ = false; 806 WMError NotifyAcrossDisplaysChange(bool isAcrossDisplays); 807 void NotifyWaterfallModeChange(bool isWaterfallMode); 808 std::vector<sptr<IWaterfallModeChangeListener>> GetWaterfallModeChangeListeners(); 809 810 /* 811 * Window Pattern 812 */ 813 WMError NotifySnapshotUpdate() override; 814 815 /* 816 * Window Property 817 */ 818 std::unordered_set<std::string> containerColorList_; 819 float lastSystemDensity_ = UNDEFINED_DENSITY; 820 static std::atomic<bool> defaultDensityEnabledGlobalConfig_; 821 std::atomic<bool> isDefaultDensityEnabled_ = false; 822 WSError NotifySystemDensityChange(float density); 823 void RegisterWindowInspectorCallback(); 824 uint32_t GetTargetAPIVersionByApplicationInfo() const; 825 826 /* 827 * Window Input Event 828 */ 829 bool GetWatchGestureConsumed() const; 830 void SetWatchGestureConsumed(bool isWatchGestureConsumed); 831 bool dialogSessionBackGestureEnabled_ = false; 832 833 /* 834 * Window Rotation 835 */ 836 int16_t rotationAnimationCount_ { 0 }; 837 void NotifyRotationAnimationEnd(); 838 839 /* 840 * Keyboard 841 */ 842 sptr<OccupiedAreaChangeInfo> occupiedAreaInfo_ = nullptr; 843 844 /* 845 * Window Decor 846 */ 847 bool grayOutMaximizeButton_ = false; 848 849 private: 850 //Trans between colorGamut and colorSpace 851 static ColorSpace GetColorSpaceFromSurfaceGamut(GraphicColorGamut colorGamut); 852 static GraphicColorGamut GetSurfaceGamutFromColorSpace(ColorSpace colorSpace); 853 854 template<typename T> EnableIfSame<T, IWindowLifeCycle, std::vector<sptr<IWindowLifeCycle>>> GetListeners(); 855 template<typename T> 856 EnableIfSame<T, IWindowStageLifeCycle, std::vector<sptr<IWindowStageLifeCycle>>> GetListeners(); 857 template<typename T> EnableIfSame<T, IDisplayMoveListener, std::vector<sptr<IDisplayMoveListener>>> GetListeners(); 858 template<typename T> 859 EnableIfSame<T, IWindowChangeListener, std::vector<sptr<IWindowChangeListener>>> GetListeners(); 860 template<typename T> 861 EnableIfSame<T, IAvoidAreaChangedListener, std::vector<sptr<IAvoidAreaChangedListener>>> GetListeners(); 862 template<typename T> 863 EnableIfSame<T, IDialogDeathRecipientListener, std::vector<sptr<IDialogDeathRecipientListener>>> GetListeners(); 864 template<typename T> 865 EnableIfSame<T, IDialogTargetTouchListener, std::vector<sptr<IDialogTargetTouchListener>>> GetListeners(); 866 template<typename T> 867 EnableIfSame<T, IOccupiedAreaChangeListener, std::vector<sptr<IOccupiedAreaChangeListener>>> GetListeners(); 868 template<typename T> 869 EnableIfSame<T, IKeyboardDidShowListener, std::vector<sptr<IKeyboardDidShowListener>>> GetListeners(); 870 template<typename T> 871 EnableIfSame<T, IKeyboardDidHideListener, std::vector<sptr<IKeyboardDidHideListener>>> GetListeners(); 872 template<typename T> 873 EnableIfSame<T, IKBWillShowListener, std::vector<sptr<IKBWillShowListener>>> GetListeners(); 874 template<typename T> 875 EnableIfSame<T, IKBWillHideListener, std::vector<sptr<IKBWillHideListener>>> GetListeners(); 876 template<typename T> 877 EnableIfSame<T, IScreenshotListener, std::vector<sptr<IScreenshotListener>>> GetListeners(); 878 template<typename T> 879 EnableIfSame<T, IScreenshotAppEventListener, std::vector<IScreenshotAppEventListenerSptr>> GetListeners(); 880 template<typename T> 881 EnableIfSame<T, ITouchOutsideListener, std::vector<sptr<ITouchOutsideListener>>> GetListeners(); 882 template<typename T> 883 EnableIfSame<T, IWindowVisibilityChangedListener, std::vector<IWindowVisibilityListenerSptr>> GetListeners(); 884 template<typename T> 885 EnableIfSame<T, IDisplayIdChangeListener, std::vector<IDisplayIdChangeListenerSptr>> GetListeners(); 886 template<typename T> 887 EnableIfSame<T, ISystemDensityChangeListener, std::vector<ISystemDensityChangeListenerSptr>> GetListeners(); 888 template<typename T> 889 EnableIfSame<T, IAcrossDisplaysChangeListener, std::vector<IAcrossDisplaysChangeListenerSptr>> GetListeners(); 890 template<typename T> 891 EnableIfSame<T, IWindowNoInteractionListener, std::vector<IWindowNoInteractionListenerSptr>> GetListeners(); 892 template<typename T> void ClearUselessListeners(std::map<int32_t, T>& listeners, int32_t persistentId); 893 template<typename T> void ClearUselessListeners(std::unordered_map<int32_t, T>& listeners, int32_t persistentId); 894 RSSurfaceNode::SharedPtr CreateSurfaceNode(const std::string& name, WindowType type); 895 template<typename T> 896 EnableIfSame<T, IWindowStatusChangeListener, std::vector<sptr<IWindowStatusChangeListener>>> GetListeners(); 897 template<typename T> 898 EnableIfSame<T, IWindowStatusDidChangeListener, std::vector<sptr<IWindowStatusDidChangeListener>>> GetListeners(); 899 template<typename T> 900 EnableIfSame<T, IWindowRectChangeListener, std::vector<sptr<IWindowRectChangeListener>>> GetListeners(); 901 template<typename T> 902 EnableIfSame<T, IRectChangeInGlobalDisplayListener, std::vector<sptr<IRectChangeInGlobalDisplayListener>>> 903 GetListeners(); 904 template<typename T> 905 EnableIfSame<T, IExtensionSecureLimitChangeListener, std::vector<sptr<IExtensionSecureLimitChangeListener>>> 906 GetListeners(); 907 template<typename T> 908 EnableIfSame<T, IPreferredOrientationChangeListener, sptr<IPreferredOrientationChangeListener>> GetListeners(); 909 template<typename T> 910 EnableIfSame<T, IWindowOrientationChangeListener, sptr<IWindowOrientationChangeListener>> GetListeners(); 911 template<typename T> 912 EnableIfSame<T, ISwitchFreeMultiWindowListener, std::vector<sptr<ISwitchFreeMultiWindowListener>>> GetListeners(); 913 template<typename T> 914 EnableIfSame<T, IWindowHighlightChangeListener, std::vector<sptr<IWindowHighlightChangeListener>>> GetListeners(); 915 template<typename T> 916 EnableIfSame<T, ISystemBarPropertyListener, std::vector<sptr<ISystemBarPropertyListener>>> GetListeners(); 917 template<typename T> 918 EnableIfSame<T, IWindowRotationChangeListener, std::vector<sptr<IWindowRotationChangeListener>>> GetListeners(); 919 void NotifyAfterFocused(); 920 void NotifyUIContentFocusStatus(); 921 void NotifyAfterUnfocused(bool needNotifyUiContent = true); 922 void NotifyAfterResumed(); 923 void NotifyAfterPaused(); 924 void NotifyUIContentHighlightStatus(bool isHighlighted); 925 926 /* 927 * Window Decor listener 928 */ 929 template<typename T> 930 EnableIfSame<T, IWindowTitleButtonRectChangedListener, 931 std::vector<sptr<IWindowTitleButtonRectChangedListener>>> GetListeners(); 932 template<typename T> 933 EnableIfSame<T, ISubWindowCloseListener, sptr<ISubWindowCloseListener>> GetListeners(); 934 template<typename T> 935 EnableIfSame<T, IMainWindowCloseListener, sptr<IMainWindowCloseListener>> GetListeners(); 936 template<typename T> 937 EnableIfSame<T, IWindowWillCloseListener, std::vector<sptr<IWindowWillCloseListener>>> GetListeners(); 938 std::unique_ptr<Ace::UIContent> UIContentCreate(AppExecFwk::Ability* ability, void* env, int isAni); 939 Ace::UIContentErrorCode UIContentInitByName(Ace::UIContent*, const std::string&, void* storage, int isAni); 940 template<typename T> 941 Ace::UIContentErrorCode UIContentInit(Ace::UIContent*, T contentInfo, void* storage, int isAni); 942 Ace::UIContentErrorCode UIContentRestore(Ace::UIContent*, const std::string& contentInfo, void* storage, 943 Ace::ContentInfoType infoType, int isAni); 944 WMError InitUIContent(const std::string& contentInfo, void* env, void* storage, 945 WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability, 946 OHOS::Ace::UIContentErrorCode& aceRet, int isAni = 0); 947 void UpdateConfigWhenSetUIContent(); 948 WMError SetUIContentInner(const std::string& contentInfo, void* env, void* storage, 949 WindowSetUIContentType setUIContentType, BackupAndRestoreType restoreType, AppExecFwk::Ability* ability, 950 int isAni = 0); 951 std::shared_ptr<std::vector<uint8_t>> GetAbcContent(const std::string& abcPath); 952 void RegisterUIContenCallback(); 953 inline void DestroyExistUIContent(); 954 std::string GetRestoredRouterStack(); 955 956 bool CheckIfNeedCommitRsTransaction(WindowSizeChangeReason wmReason); 957 void UpdateRectForRotation(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason, 958 const SceneAnimationConfig& config, const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 959 void UpdateRectForPageRotation(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason, 960 const SceneAnimationConfig& config, const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 961 void UpdateRectForOtherReason(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason, 962 const std::shared_ptr<RSTransaction>& rsTransaction = nullptr, 963 const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 964 void UpdateRectForOtherReasonTask(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason, 965 const std::shared_ptr<RSTransaction>& rsTransaction, 966 const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 967 void UpdateRectForResizeWithAnimation(const Rect& wmRect, const Rect& preRect, WindowSizeChangeReason wmReason, 968 const RectAnimationConfig& rectAnimationConfig, const std::shared_ptr<RSTransaction>& rsTransaction = nullptr, 969 const std::map<AvoidAreaType, AvoidArea>& avoidAreas = {}); 970 void SubmitNoInteractionMonitorTask(int32_t eventId, const IWindowNoInteractionListenerSptr& listener); GetAppForceLandscapeConfig(AppForceLandscapeConfig & config)971 virtual WMError GetAppForceLandscapeConfig(AppForceLandscapeConfig& config) { return WMError::WM_OK; }; 972 WSError NotifyAppForceLandscapeConfigUpdated() override; 973 void SetFrameLayoutCallbackEnable(bool enable); 974 void UpdateFrameLayoutCallbackIfNeeded(WindowSizeChangeReason wmReason); 975 bool IsNotifyInteractiveDuplicative(bool interactive); 976 void SetUniqueVirtualPixelRatioForSub(bool useUniqueDensity, float virtualPixelRatio); 977 bool IsWindowShouldDrag(); 978 bool CheckCanDragWindowType(); 979 980 /* 981 * PC Window 982 */ 983 void GetTitleButtonVisible(bool& hideMaximizeButton, bool& hideMinimizeButton, bool& hideSplitButton, 984 bool& hideCloseButton); 985 986 /* 987 * PC Fold Screen 988 */ 989 bool waterfallModeWhenEnterBackground_ { false }; 990 static std::mutex waterfallModeChangeListenerMutex_; 991 static std::unordered_map<int32_t, std::vector<sptr<IWaterfallModeChangeListener>>> waterfallModeChangeListeners_; 992 bool InitWaterfallMode(); 993 994 static std::recursive_mutex lifeCycleListenerMutex_; 995 static std::recursive_mutex windowStageLifeCycleListenerMutex_; 996 static std::recursive_mutex windowChangeListenerMutex_; 997 static std::recursive_mutex windowCrossAxisListenerMutex_; 998 static std::recursive_mutex avoidAreaChangeListenerMutex_; 999 static std::recursive_mutex dialogDeathRecipientListenerMutex_; 1000 static std::recursive_mutex dialogTargetTouchListenerMutex_; 1001 static std::recursive_mutex occupiedAreaChangeListenerMutex_; 1002 static std::recursive_mutex keyboardWillShowListenerMutex_; 1003 static std::recursive_mutex keyboardWillHideListenerMutex_; 1004 static std::recursive_mutex keyboardDidShowListenerMutex_; 1005 static std::recursive_mutex keyboardDidHideListenerMutex_; 1006 static std::recursive_mutex screenshotListenerMutex_; 1007 static std::recursive_mutex touchOutsideListenerMutex_; 1008 static std::recursive_mutex windowVisibilityChangeListenerMutex_; 1009 static std::recursive_mutex windowNoInteractionListenerMutex_; 1010 static std::recursive_mutex windowStatusChangeListenerMutex_; 1011 static std::recursive_mutex windowStatusDidChangeListenerMutex_; 1012 static std::mutex displayMoveListenerMutex_; 1013 static std::mutex windowRectChangeListenerMutex_; 1014 static std::mutex rectChangeInGlobalDisplayListenerMutex_; 1015 static std::mutex secureLimitChangeListenerMutex_; 1016 static std::mutex switchFreeMultiWindowListenerMutex_; 1017 static std::mutex preferredOrientationChangeListenerMutex_; 1018 static std::mutex windowOrientationChangeListenerMutex_; 1019 static std::mutex highlightChangeListenerMutex_; 1020 static std::mutex systemBarPropertyListenerMutex_; 1021 static std::mutex windowRotationChangeListenerMutex_; 1022 static std::map<int32_t, std::vector<sptr<ISystemBarPropertyListener>>> systemBarPropertyListeners_; 1023 static std::map<int32_t, std::vector<sptr<IWindowLifeCycle>>> lifecycleListeners_; 1024 static std::map<int32_t, std::vector<sptr<IWindowStageLifeCycle>>> windowStageLifecycleListeners_; 1025 static std::map<int32_t, std::vector<sptr<IDisplayMoveListener>>> displayMoveListeners_; 1026 static std::map<int32_t, std::vector<sptr<IWindowChangeListener>>> windowChangeListeners_; 1027 static std::map<int32_t, std::vector<sptr<IWindowCrossAxisListener>>> windowCrossAxisListeners_; 1028 static std::map<int32_t, std::vector<sptr<IAvoidAreaChangedListener>>> avoidAreaChangeListeners_; 1029 static std::map<int32_t, std::vector<sptr<IDialogDeathRecipientListener>>> dialogDeathRecipientListeners_; 1030 static std::map<int32_t, std::vector<sptr<IDialogTargetTouchListener>>> dialogTargetTouchListener_; 1031 static std::map<int32_t, std::vector<sptr<IOccupiedAreaChangeListener>>> occupiedAreaChangeListeners_; 1032 static std::map<int32_t, std::vector<sptr<IKBWillShowListener>>> keyboardWillShowListeners_; 1033 static std::map<int32_t, std::vector<sptr<IKBWillHideListener>>> keyboardWillHideListeners_; 1034 static std::map<int32_t, std::vector<sptr<IKeyboardDidShowListener>>> keyboardDidShowListeners_; 1035 static std::map<int32_t, std::vector<sptr<IKeyboardDidHideListener>>> keyboardDidHideListeners_; 1036 static std::map<int32_t, std::vector<sptr<IScreenshotListener>>> screenshotListeners_; 1037 static std::recursive_mutex screenshotAppEventListenerMutex_; 1038 static std::unordered_map<int32_t, std::vector<IScreenshotAppEventListenerSptr>> screenshotAppEventListeners_; 1039 static std::map<int32_t, std::vector<sptr<ITouchOutsideListener>>> touchOutsideListeners_; 1040 static std::map<int32_t, std::vector<IWindowVisibilityListenerSptr>> windowVisibilityChangeListeners_; 1041 static std::mutex displayIdChangeListenerMutex_; 1042 static std::map<int32_t, std::vector<IDisplayIdChangeListenerSptr>> displayIdChangeListeners_; 1043 static std::mutex systemDensityChangeListenerMutex_; 1044 static std::unordered_map<int32_t, std::vector<ISystemDensityChangeListenerSptr>> systemDensityChangeListeners_; 1045 static std::recursive_mutex acrossDisplaysChangeListenerMutex_; 1046 static std::unordered_map<int32_t, std::vector<IAcrossDisplaysChangeListenerSptr>> 1047 acrossDisplaysChangeListeners_; 1048 static std::map<int32_t, std::vector<IWindowNoInteractionListenerSptr>> windowNoInteractionListeners_; 1049 static std::map<int32_t, std::vector<sptr<IWindowStatusChangeListener>>> windowStatusChangeListeners_; 1050 static std::map<int32_t, std::vector<sptr<IWindowStatusDidChangeListener>>> windowStatusDidChangeListeners_; 1051 static std::map<int32_t, std::vector<sptr<IWindowRectChangeListener>>> windowRectChangeListeners_; 1052 static std::map<int32_t, std::vector<sptr<IRectChangeInGlobalDisplayListener>>> rectChangeInGlobalDisplayListeners_; 1053 static std::map<int32_t, std::vector<sptr<IExtensionSecureLimitChangeListener>>> secureLimitChangeListeners_; 1054 static std::map<int32_t, std::vector<sptr<ISwitchFreeMultiWindowListener>>> switchFreeMultiWindowListeners_; 1055 static std::map<int32_t, sptr<IPreferredOrientationChangeListener>> preferredOrientationChangeListener_; 1056 static std::map<int32_t, sptr<IWindowOrientationChangeListener>> windowOrientationChangeListener_; 1057 static std::map<int32_t, std::vector<sptr<IWindowHighlightChangeListener>>> highlightChangeListeners_; 1058 static std::map<int32_t, std::vector<sptr<IWindowRotationChangeListener>>> windowRotationChangeListeners_; 1059 1060 // FA only 1061 sptr<IAceAbilityHandler> aceAbilityHandler_; 1062 1063 std::atomic<int32_t> lastInteractionEventId_ { 0 }; 1064 1065 bool isMainHandlerAvailable_ = true; 1066 1067 std::string subWindowTitle_ = { "" }; 1068 std::string dialogTitle_ = { "" }; 1069 WindowTitleVisibleFlags windowTitleVisibleFlags_; 1070 1071 std::string restoredRouterStack_; // It was set and get in same thread, which is js thread. 1072 1073 /* 1074 * Window Layout 1075 */ 1076 WSRect layoutRect_; 1077 std::atomic_bool windowSizeChanged_ = false; 1078 std::atomic_bool enableFrameLayoutFinishCb_ = false; 1079 std::atomic_bool dragActivated_ = true; 1080 WindowSizeChangeReason lastSizeChangeReason_ = WindowSizeChangeReason::END; 1081 bool postTaskDone_ = false; 1082 Transform layoutTransform_; 1083 SingleHandTransform singleHandTransform_; 1084 mutable std::mutex currentTransformMutex_; 1085 Transform currentTransform_; 1086 std::atomic_bool needRenotifyTransform_ = false; 1087 KeyFramePolicy keyFramePolicy_; 1088 std::atomic<WindowStatus> lastWindowStatus_ = WindowStatus::WINDOW_STATUS_UNDEFINED; 1089 std::atomic<WindowStatus> lastStatusWhenNotifyWindowStatusDidChange_ = WindowStatus::WINDOW_STATUS_UNDEFINED; 1090 std::atomic<bool> isFirstValidLayoutUpdate_ = true; 1091 SizeChangeReason globalDisplayRectSizeChangeReason_ = SizeChangeReason::END; 1092 std::shared_mutex hookWindowInfoMutex_; 1093 HookWindowInfo hookWindowInfo_; 1094 std::atomic_bool notifySizeChangeFlag_ = false; 1095 1096 /* 1097 * Window Decor 1098 */ 1099 DecorButtonStyle decorButtonStyle_; 1100 int32_t decorHeight_ = 0; 1101 1102 /* 1103 * Window Decor listener 1104 */ 1105 static std::recursive_mutex windowTitleButtonRectChangeListenerMutex_; 1106 static std::map<int32_t, std::vector<sptr<IWindowTitleButtonRectChangedListener>>> 1107 windowTitleButtonRectChangeListeners_; 1108 static std::mutex subWindowCloseListenersMutex_; 1109 static std::map<int32_t, sptr<ISubWindowCloseListener>> subWindowCloseListeners_; 1110 static std::mutex mainWindowCloseListenersMutex_; 1111 static std::map<int32_t, sptr<IMainWindowCloseListener>> mainWindowCloseListeners_; 1112 static std::recursive_mutex windowWillCloseListenersMutex_; 1113 static std::unordered_map<int32_t, std::vector<sptr<IWindowWillCloseListener>>> windowWillCloseListeners_; 1114 1115 /* 1116 * Multi Window 1117 */ 1118 bool isSplitButtonVisible_ = true; 1119 1120 /* 1121 * PC Window 1122 */ 1123 uint32_t targetAPIVersion_ = 0; 1124 1125 /* 1126 * Window Input Event 1127 */ 1128 bool isWatchGestureConsumed_ = false; 1129 1130 /* 1131 * PC Event Filter 1132 */ 1133 std::mutex keyEventFilterMutex_; 1134 KeyEventFilterFunc keyEventFilter_; 1135 std::mutex mouseEventFilterMutex_; 1136 MouseEventFilterFunc mouseEventFilter_; 1137 std::mutex touchEventFilterMutex_; 1138 TouchEventFilterFunc touchEventFilter_; 1139 1140 /* 1141 * Window Scene 1142 */ NotifyWindowAttachStateChange(bool isAttach)1143 WSError NotifyWindowAttachStateChange(bool isAttach) override { return WSError::WS_OK; } 1144 1145 /* 1146 * Window Rotation 1147 */ 1148 void NotifyClientOrientationChange(); 1149 void NotifyRotationChangeResult(RotationChangeResult rotationChangeResult) override; 1150 void NotifyRotationChangeResultInner(const RotationChangeInfo& rotationChangeInfo); 1151 DisplayOrientation windowOrientation_ = DisplayOrientation::UNKNOWN; 1152 1153 /* 1154 * RS Client Multi Instance 1155 */ 1156 std::shared_ptr<RSUIDirector> rsUIDirector_; 1157 }; 1158 } // namespace Rosen 1159 } // namespace OHOS 1160 1161 #endif // OHOS_ROSEN_WINDOW_SESSION_IMPL_H 1162