• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 const std::map<OHOS::AppExecFwk::DisplayOrientation, Orientation> ABILITY_TO_SESSION_ORIENTATION_MAP {
25     {OHOS::AppExecFwk::DisplayOrientation::UNSPECIFIED,                         Orientation::UNSPECIFIED},
26     {OHOS::AppExecFwk::DisplayOrientation::LANDSCAPE,                           Orientation::HORIZONTAL},
27     {OHOS::AppExecFwk::DisplayOrientation::PORTRAIT,                            Orientation::VERTICAL},
28     {OHOS::AppExecFwk::DisplayOrientation::FOLLOWRECENT,                        Orientation::LOCKED},
29     {OHOS::AppExecFwk::DisplayOrientation::LANDSCAPE_INVERTED,                  Orientation::REVERSE_HORIZONTAL},
30     {OHOS::AppExecFwk::DisplayOrientation::PORTRAIT_INVERTED,                   Orientation::REVERSE_VERTICAL},
31     {OHOS::AppExecFwk::DisplayOrientation::AUTO_ROTATION,                       Orientation::SENSOR},
32     {OHOS::AppExecFwk::DisplayOrientation::AUTO_ROTATION_LANDSCAPE,             Orientation::SENSOR_HORIZONTAL},
33     {OHOS::AppExecFwk::DisplayOrientation::AUTO_ROTATION_PORTRAIT,              Orientation::SENSOR_VERTICAL},
34     {OHOS::AppExecFwk::DisplayOrientation::AUTO_ROTATION_RESTRICTED,            Orientation::AUTO_ROTATION_RESTRICTED},
35     {OHOS::AppExecFwk::DisplayOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED,
36         Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED},
37     {OHOS::AppExecFwk::DisplayOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED,
38         Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED},
39     {OHOS::AppExecFwk::DisplayOrientation::LOCKED,                              Orientation::LOCKED},
40     {OHOS::AppExecFwk::DisplayOrientation::AUTO_ROTATION_UNSPECIFIED,           Orientation::AUTO_ROTATION_UNSPECIFIED},
41     {OHOS::AppExecFwk::DisplayOrientation::FOLLOW_DESKTOP,                      Orientation::FOLLOW_DESKTOP},
42 };
43 
44 class WindowSceneSessionImpl : public WindowSessionImpl {
45 public:
46     explicit WindowSceneSessionImpl(const sptr<WindowOption>& option);
47     ~WindowSceneSessionImpl();
48     WMError Create(const std::shared_ptr<AbilityRuntime::Context>& context,
49         const sptr<Rosen::ISession>& iSession, const std::string& identityToken = "") override;
50     WMError Show(uint32_t reason = 0, bool withAnimation = false, bool withFocus = true) override;
51     WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) override;
52     WMError Destroy(bool needNotifyServer, bool needClearListener = true) override;
53     WMError NotifyDrawingCompleted() override;
54     WMError SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override;
55     void PreProcessCreate();
56     void SetDefaultProperty();
57     WMError DisableAppWindowDecor() override;
58     bool IsDecorEnable() const override;
59     WMError Minimize() override;
60     WMError MaximizeFloating() override;
61     WMError Maximize() override;
62     WMError Maximize(MaximizePresentation presentation) override;
63     WMError Recover() override;
64     WMError Recover(uint32_t reason) override;
65     void StartMove() override;
66     WMError Close() override;
67     WindowMode GetMode() const override;
68     WMError MoveTo(int32_t x, int32_t y, bool isMoveToGlobal = false) override;
69     WMError MoveToAsync(int32_t x, int32_t y) override;
70     WMError MoveWindowToGlobal(int32_t x, int32_t y) override;
71     WMError GetGlobalScaledRect(Rect& globalScaledRect) override;
72     WMError Resize(uint32_t width, uint32_t height) override;
73     WMError ResizeAsync(uint32_t width, uint32_t height) override;
74     WMError RaiseToAppTop() override;
75     WMError RaiseAboveTarget(int32_t subWindowId) override;
76     void PerformBack() override;
77     WMError SetAspectRatio(float ratio) override;
78     WMError ResetAspectRatio() override;
79     WMError SetGlobalMaximizeMode(MaximizeMode mode) override;
80     MaximizeMode GetGlobalMaximizeMode() const override;
81     WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) override;
82     SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override;
83     WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override;
84     WMError SetLayoutFullScreen(bool status) override;
85     WMError SetFullScreen(bool status) override;
86     WMError BindDialogTarget(sptr<IRemoteObject> targetToken) override;
87     WMError SetDialogBackGestureEnabled(bool isEnabled) override;
88     WMError GetWindowLimits(WindowLimits& windowLimits) override;
89     WMError SetWindowLimits(WindowLimits& windowLimits) override;
90     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
91     static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
92     static sptr<Window> GetTopWindowWithId(uint32_t mainWinId);
93     static sptr<Window> GetMainWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
94     static sptr<WindowSessionImpl> GetMainWindowWithId(uint32_t mainWinId);
95     static sptr<WindowSessionImpl> GetWindowWithId(uint32_t windId);
96     // only main window, sub window, dialog window can use
97     static int32_t GetParentMainWindowId(int32_t windowId);
98     virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
99     WMError NotifyMemoryLevel(int32_t level) override;
100 
101     virtual WMError AddWindowFlag(WindowFlag flag) override;
102     virtual WMError RemoveWindowFlag(WindowFlag flag) override;
103     virtual WMError SetWindowFlags(uint32_t flags) override;
104     virtual uint32_t GetWindowFlags() const override;
105 
106     // window effect
107     virtual WMError SetCornerRadius(float cornerRadius) override;
108     virtual WMError SetShadowRadius(float radius) override;
109     virtual WMError SetShadowColor(std::string color) override;
110     virtual WMError SetShadowOffsetX(float offsetX) override;
111     virtual WMError SetShadowOffsetY(float offsetY) override;
112     virtual WMError SetBlur(float radius) override;
113     virtual WMError SetBackdropBlur(float radius) override;
114     virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) override;
115     virtual WMError SetWindowMode(WindowMode mode) override;
116     virtual WMError SetGrayScale(float grayScale) override;
117 
118     virtual WMError SetTransparent(bool isTransparent) override;
119     virtual WMError SetTurnScreenOn(bool turnScreenOn) override;
120     virtual WMError SetKeepScreenOn(bool keepScreenOn) override;
121     virtual WMError SetPrivacyMode(bool isPrivacyMode) override;
122     virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) override;
123     virtual WMError SetSnapshotSkip(bool isSkip) override;
124     virtual std::shared_ptr<Media::PixelMap> Snapshot() override;
125     WMError SetTouchHotAreas(const std::vector<Rect>& rects) override;
126     virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) override;
127     virtual WMError SetCallingWindow(uint32_t callingSessionId) override;
128 
129     virtual bool IsTransparent() const override;
130     virtual bool IsTurnScreenOn() const override;
131     virtual bool IsKeepScreenOn() const override;
132     virtual bool IsPrivacyMode() const override;
133     virtual bool IsLayoutFullScreen() const override;
134     virtual bool IsFullScreen() const override;
135     WMError RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) override;
136     void SetNeedDefaultAnimation(bool needDefaultAnimation) override;
137     WMError SetTransform(const Transform& trans) override;
138     const Transform& GetTransform() const override;
139     WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override;
140     WMError SetAlpha(float alpha) override;
141     void DumpSessionElementInfo(const std::vector<std::string>& params) override;
142     WSError UpdateWindowMode(WindowMode mode) override;
143     WSError UpdateMaximizeMode(MaximizeMode mode) override;
144     WSError UpdateTitleInTargetPos(bool isShow, int32_t height) override;
145     void NotifySessionForeground(uint32_t reason, bool withAnimation) override;
146     void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits) override;
147     WMError NotifyPrepareClosePiPWindow() override;
148     void UpdateSubWindowState(const WindowType& type);
149     WMError SetSystemBarProperties(const std::map<WindowType, SystemBarProperty>& properties,
150         const std::map<WindowType, SystemBarPropertyFlag>& propertyFlags) override;
151     WMError GetSystemBarProperties(std::map<WindowType, SystemBarProperty>& properties) override;
152     WMError SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) override;
153     void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
154     bool PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override;
155     WSError NotifyDialogStateChange(bool isForeground) override;
156     WMError SetDefaultDensityEnabled(bool enabled) override;
157     bool GetDefaultDensityEnabled() override;
158     WMError HideNonSecureWindows(bool shouldHide) override;
159     virtual WMError SetWindowMask(const std::vector<std::vector<uint32_t>>& windowMask) override;
160     WSError NotifyCompatibleModeEnableInPad(bool enabled) override;
161     void UpdateDensity() override;
162     WSError UpdateOrientation() override;
163     WSError UpdateDisplayId(uint64_t displayId) override;
164     WMError AdjustKeyboardLayout(const KeyboardLayoutParams& params) override;
165     bool IsPcOrPadCapabilityEnabled() const override;
166 
167     WSError SwitchFreeMultiWindow(bool enable) override;
168     virtual bool GetFreeMultiWindowModeEnabledState() override;
169     void NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) override;
170     virtual WMError SetImmersiveModeEnabledState(bool enable) override;
171     virtual bool GetImmersiveModeEnabledState() const override;
172     void NotifySessionFullScreen(bool fullScreen) override;
173     WMError GetWindowStatus(WindowStatus& windowStatus) override;
174     bool GetIsUIExtensionFlag() const override;
175     bool GetIsUIExtensionSubWindowFlag() const override;
176 
177     /*
178      * Gesture Back
179      */
180     WMError SetGestureBackEnabled(bool enable) override;
181     WMError GetGestureBackEnabled(bool& enable) override;
182 
183 protected:
184     WMError CreateAndConnectSpecificSession();
185     WMError CreateSystemWindow(WindowType type);
186     WMError RecoverAndConnectSpecificSession();
187     WMError RecoverAndReconnectSceneSession();
188     sptr<WindowSessionImpl> FindParentSessionByParentId(uint32_t parentId);
189     bool IsSessionMainWindow(uint32_t parentId);
190     bool VerifySubWindowLevel(uint32_t parentId);
191     void LimitWindowSize(uint32_t& width, uint32_t& height);
192     void LimitCameraFloatWindowMininumSize(uint32_t& width, uint32_t& height, float& vpr);
193     void UpdateFloatingWindowSizeBySizeLimits(uint32_t& width, uint32_t& height) const;
194     WMError NotifyWindowSessionProperty();
195     WMError NotifyWindowNeedAvoid(bool status = false);
196     WMError SetLayoutFullScreenByApiVersion(bool status) override;
197     void UpdateWindowSizeLimits();
198     WindowLimits GetSystemSizeLimits(uint32_t displayWidth, uint32_t displayHeight, float vpr);
199     void GetConfigurationFromAbilityInfo();
200     float GetVirtualPixelRatio(sptr<DisplayInfo> displayInfo) override;
201     WMError NotifySpecificWindowSessionProperty(WindowType type, const SystemBarProperty& property);
202     using SessionMap = std::map<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>;
203     sptr<WindowSessionImpl> FindParentMainSession(uint32_t parentId, const SessionMap& sessionMap);
204 
205 private:
206     WMError DestroyInner(bool needNotifyServer);
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     void PreLayoutOnShow(WindowType type, const sptr<DisplayInfo>& info = nullptr);
257 
258     /*
259      * Gesture Back
260      */
261     bool gestureBackEnabled_ = true;
262 
263     /**
264      * Sub Window
265      */
266     void AddSubWindowMapForExtensionWindow();
267     WMError GetParentSessionAndVerify(bool isToast, sptr<WindowSessionImpl>& parentSession);
268 
269     WMError RegisterKeyboardPanelInfoChangeListener(const sptr<IKeyboardPanelInfoChangeListener>& listener) override;
270     WMError UnregisterKeyboardPanelInfoChangeListener(const sptr<IKeyboardPanelInfoChangeListener>& listener) override;
271     static std::mutex keyboardPanelInfoChangeListenerMutex_;
272     sptr<IKeyboardPanelInfoChangeListener> keyboardPanelInfoChangeListeners_ = nullptr;
273     bool isOverTouchSlop_ = false;
274     bool isDown_ = false;
275     std::unordered_map<int32_t, std::vector<bool>> eventMapTriggerByDisplay_;
276     std::unordered_map<int32_t, std::vector<int32_t>> eventMapDeltaXByDisplay_;
277     std::unordered_map<int32_t, std::vector<PointInfo>> downPointerByDisplay_;
278 };
279 } // namespace Rosen
280 } // namespace OHOS
281 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H