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_SCENE_SESSION_IMPL_H 17 #define OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H 18 19 #include "window_session_impl.h" 20 21 namespace OHOS { 22 namespace Rosen { 23 24 class WindowSceneSessionImpl : public WindowSessionImpl { 25 public: 26 explicit WindowSceneSessionImpl(const sptr<WindowOption>& option); 27 ~WindowSceneSessionImpl(); 28 WMError Create(const std::shared_ptr<AbilityRuntime::Context>& context, 29 const sptr<Rosen::ISession>& iSession, const std::string& identityToken = "") override; 30 WMError Show(uint32_t reason = 0, bool withAnimation = false, bool withFocus = true) override; 31 WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; 32 WMError Destroy(bool needNotifyServer, bool needClearListener = true) override; 33 WMError NotifyDrawingCompleted() override; 34 WMError NotifyRemoveStartingWindow() override; 35 WMError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override; 36 void PreProcessCreate(); 37 void SetDefaultProperty(); 38 WMError DisableAppWindowDecor() override; 39 bool IsDecorEnable() const override; 40 WMError Minimize() override; 41 WMError MaximizeFloating() override; 42 WMError Maximize() override; 43 WMError Maximize(MaximizePresentation presentation) override; 44 WMError Recover() override; 45 WMError Recover(uint32_t reason) override; 46 void StartMove() override; 47 bool IsStartMoving() override; 48 WmErrorCode StartMoveWindow() override; 49 WMError Close() override; 50 WindowMode GetMode() const override; 51 WMError MoveTo(int32_t x, int32_t y, bool isMoveToGlobal = false) override; 52 WMError MoveToAsync(int32_t x, int32_t y) override; 53 WMError MoveWindowToGlobal(int32_t x, int32_t y) override; 54 WMError GetGlobalScaledRect(Rect& globalScaledRect) override; 55 WMError Resize(uint32_t width, uint32_t height) override; 56 WMError ResizeAsync(uint32_t width, uint32_t height) override; 57 WMError RaiseToAppTop() override; 58 WMError RaiseAboveTarget(int32_t subWindowId) override; 59 void PerformBack() override; 60 WMError SetAspectRatio(float ratio) override; 61 WMError ResetAspectRatio() override; 62 WMError SetGlobalMaximizeMode(MaximizeMode mode) override; 63 MaximizeMode GetGlobalMaximizeMode() const override; 64 WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) override; 65 SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override; 66 WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override; 67 WMError SetLayoutFullScreen(bool status) override; 68 WMError SetFullScreen(bool status) override; 69 WMError BindDialogTarget(sptr<IRemoteObject> targetToken) override; 70 WMError SetDialogBackGestureEnabled(bool isEnabled) override; 71 WMError GetWindowLimits(WindowLimits& windowLimits) override; 72 WMError SetWindowLimits(WindowLimits& windowLimits) override; 73 static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 74 static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr); 75 static sptr<Window> GetTopWindowWithId(uint32_t mainWinId); 76 static sptr<Window> GetMainWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr); 77 static sptr<WindowSessionImpl> GetMainWindowWithId(uint32_t mainWinId); 78 static sptr<WindowSessionImpl> GetWindowWithId(uint32_t windId); 79 // only main window, sub window, dialog window can use 80 static int32_t GetParentMainWindowId(int32_t windowId); 81 virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override; 82 WMError NotifyMemoryLevel(int32_t level) override; 83 84 virtual WMError AddWindowFlag(WindowFlag flag) override; 85 virtual WMError RemoveWindowFlag(WindowFlag flag) override; 86 virtual WMError SetWindowFlags(uint32_t flags) override; 87 virtual uint32_t GetWindowFlags() const override; 88 89 // window effect 90 virtual WMError SetCornerRadius(float cornerRadius) override; 91 virtual WMError SetShadowRadius(float radius) override; 92 virtual WMError SetShadowColor(std::string color) override; 93 virtual WMError SetShadowOffsetX(float offsetX) override; 94 virtual WMError SetShadowOffsetY(float offsetY) override; 95 virtual WMError SetBlur(float radius) override; 96 virtual WMError SetBackdropBlur(float radius) override; 97 virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) override; 98 virtual WMError SetWindowMode(WindowMode mode) override; 99 virtual WMError SetGrayScale(float grayScale) override; 100 101 virtual WMError SetTransparent(bool isTransparent) override; 102 virtual WMError SetTurnScreenOn(bool turnScreenOn) override; 103 virtual WMError SetKeepScreenOn(bool keepScreenOn) override; 104 virtual WMError SetPrivacyMode(bool isPrivacyMode) override; 105 virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) override; 106 virtual WMError SetSnapshotSkip(bool isSkip) override; 107 virtual std::shared_ptr<Media::PixelMap> Snapshot() override; 108 WMError SetTouchHotAreas(const std::vector<Rect>& rects) override; 109 virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) override; 110 virtual WMError SetCallingWindow(uint32_t callingSessionId) override; 111 112 virtual bool IsTransparent() const override; 113 virtual bool IsTurnScreenOn() const override; 114 virtual bool IsKeepScreenOn() const override; 115 virtual bool IsPrivacyMode() const override; 116 virtual bool IsLayoutFullScreen() const override; 117 virtual bool IsFullScreen() const override; 118 WMError RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) override; 119 void SetNeedDefaultAnimation(bool needDefaultAnimation) override; 120 WMError SetTransform(const Transform& trans) override; 121 const Transform& GetTransform() const override; 122 WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override; 123 WMError SetAlpha(float alpha) override; 124 void DumpSessionElementInfo(const std::vector<std::string>& params) override; 125 WSError UpdateWindowMode(WindowMode mode) override; 126 WSError UpdateMaximizeMode(MaximizeMode mode) override; 127 WSError UpdateTitleInTargetPos(bool isShow, int32_t height) override; 128 void NotifySessionForeground(uint32_t reason, bool withAnimation) override; 129 void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits) override; 130 WMError NotifyPrepareClosePiPWindow() override; 131 void UpdateSubWindowState(const WindowType& type); 132 WMError SetSystemBarProperties(const std::map<WindowType, SystemBarProperty>& properties, 133 const std::map<WindowType, SystemBarPropertyFlag>& propertyFlags) override; 134 WMError GetSystemBarProperties(std::map<WindowType, SystemBarProperty>& properties) override; 135 WMError SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) override; 136 void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override; 137 bool PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override; 138 WSError NotifyDialogStateChange(bool isForeground) override; 139 WMError SetDefaultDensityEnabled(bool enabled) override; 140 bool GetDefaultDensityEnabled() override; 141 WMError HideNonSecureWindows(bool shouldHide) override; 142 virtual WMError SetWindowMask(const std::vector<std::vector<uint32_t>>& windowMask) override; 143 WSError NotifyCompatibleModeEnableInPad(bool enabled) override; 144 void UpdateDensity() override; 145 WSError UpdateOrientation() override; 146 WSError UpdateDisplayId(uint64_t displayId) override; 147 WMError AdjustKeyboardLayout(const KeyboardLayoutParams& params) override; 148 149 /* 150 * PC Window 151 */ 152 bool IsPcOrPadCapabilityEnabled() const override; 153 bool IsPcOrPadFreeMultiWindowMode() const override; 154 WMError Restore() override; 155 WMError SetTitleAndDockHoverShown(bool isTitleHoverShown = true, 156 bool isDockHoverShown = true) override; 157 WMError SetWindowRectAutoSave(bool enabled) override; 158 WMError IsWindowRectAutoSave(bool& enabled) override; 159 160 WSError SwitchFreeMultiWindow(bool enable) override; 161 virtual bool GetFreeMultiWindowModeEnabledState() override; 162 void NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) override; 163 virtual WMError SetImmersiveModeEnabledState(bool enable) override; 164 virtual bool GetImmersiveModeEnabledState() const override; 165 void NotifySessionFullScreen(bool fullScreen) override; 166 WMError GetWindowStatus(WindowStatus& windowStatus) override; 167 bool GetIsUIExtensionFlag() const override; 168 bool GetIsUIExtensionSubWindowFlag() const override; 169 170 /* 171 * Gesture Back 172 */ 173 WMError SetGestureBackEnabled(bool enable) override; 174 WMError GetGestureBackEnabled(bool& enable) override; 175 176 /* 177 * Window Property 178 */ 179 static void UpdateConfigurationSyncForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration); 180 void UpdateConfigurationSync(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override; 181 182 protected: 183 WMError CreateAndConnectSpecificSession(); 184 WMError CreateSystemWindow(WindowType type); 185 WMError RecoverAndConnectSpecificSession(); 186 WMError RecoverAndReconnectSceneSession(); 187 sptr<WindowSessionImpl> FindParentSessionByParentId(uint32_t parentId); 188 bool IsSessionMainWindow(uint32_t parentId); 189 bool VerifySubWindowLevel(uint32_t parentId); 190 void LimitWindowSize(uint32_t& width, uint32_t& height); 191 void LimitCameraFloatWindowMininumSize(uint32_t& width, uint32_t& height, float& vpr); 192 void UpdateFloatingWindowSizeBySizeLimits(uint32_t& width, uint32_t& height) const; 193 WMError NotifyWindowSessionProperty(); 194 WMError NotifyWindowNeedAvoid(bool status = false); 195 WMError SetLayoutFullScreenByApiVersion(bool status) override; 196 void UpdateWindowSizeLimits(); 197 WindowLimits GetSystemSizeLimits(uint32_t displayWidth, uint32_t displayHeight, float vpr); 198 void GetConfigurationFromAbilityInfo(); 199 float GetVirtualPixelRatio(sptr<DisplayInfo> displayInfo) override; 200 WMError NotifySpecificWindowSessionProperty(WindowType type, const SystemBarProperty& property); 201 using SessionMap = std::map<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>; 202 sptr<WindowSessionImpl> FindParentMainSession(uint32_t parentId, const SessionMap& sessionMap); 203 204 private: 205 WMError DestroyInner(bool needNotifyServer); 206 WMError MainWindowCloseInner(); 207 WMError SyncDestroyAndDisconnectSpecificSession(int32_t persistentId); 208 bool IsValidSystemWindowType(const WindowType& type); 209 WMError CheckParmAndPermission(); 210 static uint32_t maxFloatingWindowSize_; 211 void TransformSurfaceNode(const Transform& trans); 212 void AdjustWindowAnimationFlag(bool withAnimation = false); 213 void RegisterSessionRecoverListener(bool isSpecificSession); 214 WMError UpdateAnimationFlagProperty(bool withAnimation); 215 WMError UpdateWindowModeImmediately(WindowMode mode); 216 uint32_t UpdateConfigVal(uint32_t minVal, uint32_t maxVal, uint32_t configVal, uint32_t defaultVal, float vpr); 217 void UpdateWindowState(); 218 void UpdateNewSize(); 219 void fillWindowLimits(WindowLimits& windowLimits); 220 void ConsumePointerEventInner(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 221 MMI::PointerEvent::PointerItem& pointerItem); 222 void HandleEventForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 223 MMI::PointerEvent::PointerItem& pointerItem); 224 void HandleDownForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 225 MMI::PointerEvent::PointerItem& pointerItem); 226 void HandleMoveForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 227 MMI::PointerEvent::PointerItem& pointerItem); 228 void HandleUpForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 229 MMI::PointerEvent::PointerItem& pointerItem); 230 void ConvertPointForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 231 MMI::PointerEvent::PointerItem& pointerItem, int32_t transferX); 232 bool IsInMappingRegionForCompatibleMode(int32_t displayX, int32_t displayY); 233 bool CheckTouchSlop(int32_t pointerId, int32_t x, int32_t y, int32_t threshold); 234 void IgnoreClickEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 235 bool HandlePointDownEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent, 236 const MMI::PointerEvent::PointerItem& pointerItem, int32_t sourceType, float vpr, const WSRect& rect); 237 std::unique_ptr<Media::PixelMap> HandleWindowMask(const std::vector<std::vector<uint32_t>>& windowMask); 238 void CalculateNewLimitsByLimits( 239 WindowLimits& newLimits, WindowLimits& customizedLimits, float& virtualPixelRatio); 240 void CalculateNewLimitsByRatio(WindowLimits& newLimits, WindowLimits& customizedLimits); 241 void NotifyDisplayInfoChange(const sptr<DisplayInfo>& info = nullptr); 242 void UpdateDensityInner(const sptr<DisplayInfo>& info = nullptr); 243 244 /** 245 * Window Immersive 246 */ 247 void UpdateDefaultStatusBarColor(); 248 WMError MoveAndResizeKeyboard(const KeyboardLayoutParams& params); 249 bool userLimitsSet_ = false; 250 bool enableDefaultAnimation_ = true; 251 sptr<IAnimationTransitionController> animationTransitionController_; 252 uint32_t setSameSystembarPropertyCnt_ = 0; 253 std::atomic<bool> isDefaultDensityEnabled_ = false; 254 std::atomic<uint32_t> getAvoidAreaCnt_ = 0; 255 bool enableImmersiveMode_ = false; 256 bool titleHoverShowEnabled_ = true; 257 bool dockHoverShowEnabled_ = true; 258 void PreLayoutOnShow(WindowType type, const sptr<DisplayInfo>& info = nullptr); 259 260 /* 261 * Gesture Back 262 */ 263 bool gestureBackEnabled_ = true; 264 265 /* 266 * Window Property 267 */ 268 void InitSystemSessionDragEnable(); 269 270 /** 271 * Sub Window 272 */ 273 void AddSubWindowMapForExtensionWindow(); 274 WMError GetParentSessionAndVerify(bool isToast, sptr<WindowSessionImpl>& parentSession); 275 276 WMError RegisterKeyboardPanelInfoChangeListener(const sptr<IKeyboardPanelInfoChangeListener>& listener) override; 277 WMError UnregisterKeyboardPanelInfoChangeListener(const sptr<IKeyboardPanelInfoChangeListener>& listener) override; 278 static std::mutex keyboardPanelInfoChangeListenerMutex_; 279 sptr<IKeyboardPanelInfoChangeListener> keyboardPanelInfoChangeListeners_ = nullptr; 280 bool isOverTouchSlop_ = false; 281 bool isDown_ = false; 282 std::unordered_map<int32_t, std::vector<bool>> eventMapTriggerByDisplay_; 283 std::unordered_map<int32_t, std::vector<int32_t>> eventMapDeltaXByDisplay_; 284 std::unordered_map<int32_t, std::vector<PointInfo>> downPointerByDisplay_; 285 }; 286 } // namespace Rosen 287 } // namespace OHOS 288 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H