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