• 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 SetTextFieldAvoidInfo(double textFieldPositionY, double textFieldHeight) override;
36     void PreProcessCreate();
37     void SetDefaultProperty();
38     WMError Minimize() override;
39     void StartMove() override;
40     bool IsStartMoving() override;
41     WindowMode GetWindowMode() const override;
42     void Resume() override;
43 
44     /*
45      * Window Layout
46      */
47     WMError MoveTo(int32_t x, int32_t y, bool isMoveToGlobal = false,
48         MoveConfiguration moveConfiguration = {}) override;
49     WMError MoveToAsync(int32_t x, int32_t y, MoveConfiguration moveConfiguration = {}) override;
50     WMError MoveWindowToGlobal(int32_t x, int32_t y, MoveConfiguration moveConfiguration = {}) override;
51     WMError GetGlobalScaledRect(Rect& globalScaledRect) override;
52     WMError Resize(uint32_t width, uint32_t height,
53         const RectAnimationConfig& rectAnimationConfig = {}) override;
54     WMError ResizeAsync(uint32_t width, uint32_t height,
55         const RectAnimationConfig& rectAnimationConfig = {}) override;
56     WMError SetFollowParentWindowLayoutEnabled(bool isFollow) override;
57 
58     /*
59      * Window Hierarchy
60      */
61     WMError RaiseToAppTop() override;
62     WMError RaiseAboveTarget(int32_t subWindowId) override;
63     WMError SetSubWindowZLevel(int32_t zLevel) override;
64     WMError GetSubWindowZLevel(int32_t& zLevel) override;
65 
66     void PerformBack() override;
67     WMError SetAspectRatio(float ratio) override;
68     WMError ResetAspectRatio() override;
69     WMError SetGlobalMaximizeMode(MaximizeMode mode) override;
70     MaximizeMode GetGlobalMaximizeMode() const override;
71 
72     WMError BindDialogTarget(sptr<IRemoteObject> targetToken) override;
73     WMError SetDialogBackGestureEnabled(bool isEnabled) override;
74     WMError GetWindowLimits(WindowLimits& windowLimits) override;
75     WMError SetWindowLimits(WindowLimits& windowLimits, bool isForce) override;
76     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration,
77         const std::vector<std::shared_ptr<AbilityRuntime::Context>>& ignoreWindowContexts = {});
78     static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
79     static sptr<Window> GetTopWindowWithId(uint32_t mainWinId);
80     static sptr<Window> GetMainWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
81     static sptr<WindowSessionImpl> GetMainWindowWithId(uint32_t mainWinId);
82     static sptr<WindowSessionImpl> GetWindowWithId(uint32_t windId);
83     // only main window, sub window, dialog window can use
84     static int32_t GetParentMainWindowId(int32_t windowId);
85     virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
86     void UpdateConfigurationForSpecified(const std::shared_ptr<AppExecFwk::Configuration>& configuration,
87         const std::shared_ptr<Global::Resource::ResourceManager>& resourceManager) override;
88     WMError NotifyMemoryLevel(int32_t level) override;
89 
90     virtual WMError AddWindowFlag(WindowFlag flag) override;
91     virtual WMError RemoveWindowFlag(WindowFlag flag) override;
92     virtual WMError SetWindowFlags(uint32_t flags) override;
93     virtual uint32_t GetWindowFlags() const override;
94 
95     virtual WMError SetTransparent(bool isTransparent) override;
96     virtual WMError SetTurnScreenOn(bool turnScreenOn) override;
97     virtual WMError SetKeepScreenOn(bool keepScreenOn) override;
98     virtual WMError SetViewKeepScreenOn(bool keepScreenOn) override;
99     virtual WMError SetPrivacyMode(bool isPrivacyMode) override;
100     virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) override;
101     virtual WMError SetSnapshotSkip(bool isSkip) override;
102     virtual std::shared_ptr<Media::PixelMap> Snapshot() override;
103     WMError SnapshotIgnorePrivacy(std::shared_ptr<Media::PixelMap>& pixelMap) override;
104     WMError SetTouchHotAreas(const std::vector<Rect>& rects) override;
105     WMError SetKeyboardTouchHotAreas(const KeyboardTouchHotAreas& hotAreas) override;
106     virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) override;
107     virtual WMError SetCallingWindow(uint32_t callingSessionId) override;
108     WMError ChangeKeyboardViewMode(KeyboardViewMode mode) override;
109 
110     virtual bool IsTransparent() const override;
111     virtual bool IsTurnScreenOn() const override;
112     virtual bool IsKeepScreenOn() const override;
113     virtual bool IsViewKeepScreenOn() const override;
114     virtual bool IsPrivacyMode() const override;
115     virtual bool IsLayoutFullScreen() const override;
116     virtual bool IsFullScreen() const override;
117     WMError RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) override;
118     void SetNeedDefaultAnimation(bool needDefaultAnimation) override;
119     WMError SetTransform(const Transform& trans) override;
120     const Transform& GetTransform() const override;
121     WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override;
122     WMError SetAlpha(float alpha) override;
123     void DumpSessionElementInfo(const std::vector<std::string>& params) override;
124     WSError UpdateWindowMode(WindowMode mode) override;
125     WSError UpdateTitleInTargetPos(bool isShow, int32_t height) override;
126     void NotifySessionForeground(uint32_t reason, bool withAnimation) override;
127     void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits) override;
128     WMError NotifyPrepareClosePiPWindow() override;
129     void UpdateSubWindowState(const WindowType& type);
130     WMError SetSystemBarProperties(const std::map<WindowType, SystemBarProperty>& properties,
131         const std::map<WindowType, SystemBarPropertyFlag>& propertyFlags) override;
132     WMError GetSystemBarProperties(std::map<WindowType, SystemBarProperty>& properties) override;
133     WMError SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) override;
134     void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
135     bool PreNotifyKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent) override;
136     WSError NotifyDialogStateChange(bool isForeground) override;
137     WMError SetDefaultDensityEnabled(bool enabled) override;
138     bool GetDefaultDensityEnabled() override;
139     WMError HideNonSecureWindows(bool shouldHide) override;
140     void UpdateDensity() override;
141     WSError UpdateOrientation() override;
142     WSError UpdateDisplayId(uint64_t displayId) override;
143     WMError AdjustKeyboardLayout(const KeyboardLayoutParams params) override;
144 
145     /*
146      * Sub Window
147      */
148     WMError SetParentWindow(int32_t newParentWindowId) override;
149     WMError GetParentWindow(sptr<Window>& parentWindow) override;
150 
151     /*
152      * PC Window
153      */
154     WMError SetWindowMask(const std::vector<std::vector<uint32_t>>& windowMask) override;
155     WMError SetFollowParentMultiScreenPolicy(bool enabled) override;
156 
157     /*
158      * PC Window Layout
159      */
160     WMError Restore() override;
161     WMError SetTitleAndDockHoverShown(bool isTitleHoverShown = true,
162         bool isDockHoverShown = true) override;
163     WMError SetWindowRectAutoSave(bool enabled, bool isSaveBySpecifiedFlag = false) override;
164     WMError IsWindowRectAutoSave(bool& enabled) override;
165     WMError MaximizeFloating() override;
166     WMError Maximize() override;
167     WMError Maximize(MaximizePresentation presentation) override;
168     WMError Recover() override;
169     WMError Recover(uint32_t reason) override;
170     WSError UpdateMaximizeMode(MaximizeMode mode) override;
171     WMError SetSupportedWindowModes(const std::vector<AppExecFwk::SupportWindowMode>& supportedWindowModes) override;
172     WmErrorCode StartMoveWindow() override;
173     WmErrorCode StartMoveWindowWithCoordinate(int32_t offsetX, int32_t offsetY) override;
174     WmErrorCode StopMoveWindow() override;
175     WMError SetSupportedWindowModesInner(const std::vector<AppExecFwk::SupportWindowMode>& supportedWindowModes);
176 
177     /*
178      * Compatible Mode
179      */
180     WSError NotifyCompatibleModeEnableInPad(bool enabled) override;
181     WSError CompatibleFullScreenRecover() override;
182     WSError CompatibleFullScreenMinimize() override;
183     WSError CompatibleFullScreenClose() override;
184     void HookDecorButtonStyleInCompatibleMode(uint32_t contentColor);
185     WSError PcAppInPadNormalClose() override;
186 
187     /*
188      * Free Multi Window
189      */
190     WSError SwitchFreeMultiWindow(bool enable) override;
191     virtual bool GetFreeMultiWindowModeEnabledState() override;
192 
193     void NotifyKeyboardPanelInfoChange(const KeyboardPanelInfo& keyboardPanelInfo) override;
194     virtual WMError SetImmersiveModeEnabledState(bool enable) override;
195     virtual bool GetImmersiveModeEnabledState() const override;
196     void NotifySessionFullScreen(bool fullScreen) override;
197     WMError GetWindowStatus(WindowStatus& windowStatus) override;
198     bool GetIsUIExtFirstSubWindow() const override;
199     bool GetIsUIExtAnySubWindow() const override;
200 
201     /*
202      * Gesture Back
203      */
204     WMError SetGestureBackEnabled(bool enable) override;
205     WMError GetGestureBackEnabled(bool& enable) override;
206 
207     /*
208      * PC Fold Screen
209      */
210     WSError SetFullScreenWaterfallMode(bool isWaterfallMode) override;
211     WSError SetSupportEnterWaterfallMode(bool isSupportEnter) override;
212     WMError OnContainerModalEvent(const std::string& eventName, const std::string& value) override;
213 
214     /*
215      * Window Property
216      */
217     WMError SetCornerRadius(float cornerRadius) override;
218     WMError SetWindowCornerRadius(float cornerRadius) override;
219     WMError GetWindowCornerRadius(float& cornerRadius) override;
220     WMError SetShadowRadius(float radius) override;
221     WMError SetShadowColor(std::string color) override;
222     WMError SetShadowOffsetX(float offsetX) override;
223     WMError SetShadowOffsetY(float offsetY) override;
224     WMError SetBlur(float radius) override;
225     WMError SetBackdropBlur(float radius) override;
226     WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) override;
227     WMError SetWindowMode(WindowMode mode) override;
228     WMError SetGrayScale(float grayScale) override;
229     WMError SetWindowShadowRadius(float radius) override;
230     static void UpdateConfigurationSyncForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
231     void UpdateConfigurationSync(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
232     float GetCustomDensity() const override;
233     WMError SetCustomDensity(float density) override;
234     WMError GetWindowDensityInfo(WindowDensityInfo& densityInfo) override;
235 
236     /*
237      * Window Decor
238      */
239     WMError SetWindowTitle(const std::string& title) override;
240     WMError DisableAppWindowDecor() override;
241     bool IsDecorEnable() const override;
242     WMError Close() override;
243     WMError CloseDirectly() override;
244 
245     /*
246      * Starting Window
247      */
248     WMError NotifyRemoveStartingWindow() override;
249 
250     /*
251      * Window Scene
252      */
253     WMError RegisterWindowAttachStateChangeListener(
254         const sptr<IWindowAttachStateChangeListner>& listener) override;
255     WMError UnregisterWindowAttachStateChangeListener() override;
256 
257     /*
258      * Window Immersive
259      */
260     WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea, const Rect& rect = Rect::EMPTY_RECT,
261         int32_t apiVersion = API_VERSION_INVALID) override;
262     SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override;
263     WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override;
264     WMError SetLayoutFullScreen(bool status) override;
265     WMError SetFullScreen(bool status) override;
266     WMError UpdateSystemBarProperties(const std::unordered_map<WindowType, SystemBarProperty>& systemBarProperties,
267         const std::unordered_map<WindowType, SystemBarPropertyFlag>& systemBarPropertyFlags) override;
268 
269 protected:
270     WMError CreateAndConnectSpecificSession();
271     WMError CreateSystemWindow(WindowType type);
272     sptr<WindowSessionImpl> FindParentSessionByParentId(uint32_t parentId);
273     bool IsSessionMainWindow(uint32_t parentId);
274     void LimitWindowSize(uint32_t& width, uint32_t& height);
275     void LimitCameraFloatWindowMininumSize(uint32_t& width, uint32_t& height, float& vpr);
276     void UpdateFloatingWindowSizeBySizeLimits(uint32_t& width, uint32_t& height) const;
277     WMError NotifyWindowSessionProperty();
278     WMError NotifyWindowNeedAvoid(bool status = false);
279     WMError SetLayoutFullScreenByApiVersion(bool status) override;
280     void UpdateWindowSizeLimits();
281     WindowLimits GetSystemSizeLimits(uint32_t displayWidth, uint32_t displayHeight, float vpr);
282     void GetConfigurationFromAbilityInfo();
283     float GetVirtualPixelRatio(const sptr<DisplayInfo>& displayInfo) override;
284     WMError NotifySpecificWindowSessionProperty(WindowType type, const SystemBarProperty& property);
285     using SessionMap = std::map<std::string, std::pair<int32_t, sptr<WindowSessionImpl>>>;
286     sptr<WindowSessionImpl> FindParentMainSession(uint32_t parentId, const SessionMap& sessionMap);
287 
288     /*
289      * Window Recover
290      */
291     WMError RecoverAndConnectSpecificSession();
292     WMError RecoverAndReconnectSceneSession();
293 
294 private:
295     WMError DestroyInner(bool needNotifyServer);
296     WMError MainWindowCloseInner();
297     WMError SyncDestroyAndDisconnectSpecificSession(int32_t persistentId);
298     bool IsValidSystemWindowType(const WindowType& type);
299     WMError CheckParmAndPermission();
300     static uint32_t maxFloatingWindowSize_;
301     void TransformSurfaceNode(const Transform& trans);
302     void AdjustWindowAnimationFlag(bool withAnimation = false);
303     WMError UpdateAnimationFlagProperty(bool withAnimation);
304     WMError UpdateWindowModeImmediately(WindowMode mode);
305     uint32_t UpdateConfigVal(uint32_t minVal, uint32_t maxVal, uint32_t configVal, uint32_t defaultVal, float vpr);
306     void UpdateWindowState();
307     void UpdateNewSize();
308     void fillWindowLimits(WindowLimits& windowLimits);
309     void ConsumePointerEventInner(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
310         MMI::PointerEvent::PointerItem& pointerItem, bool isHitTargetDraggable = false);
311     void HandleEventForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
312         MMI::PointerEvent::PointerItem& pointerItem);
313     void HandleDownForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
314         MMI::PointerEvent::PointerItem& pointerItem);
315     void HandleMoveForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
316         MMI::PointerEvent::PointerItem& pointerItem);
317     void HandleUpForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
318         MMI::PointerEvent::PointerItem& pointerItem);
319     void ConvertPointForCompatibleMode(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
320         MMI::PointerEvent::PointerItem& pointerItem, int32_t transferX);
321     bool IsInMappingRegionForCompatibleMode(int32_t displayX, int32_t displayY);
322     bool CheckTouchSlop(int32_t pointerId, int32_t x, int32_t y, int32_t threshold);
323     void IgnoreClickEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
324     bool HandlePointDownEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
325         const MMI::PointerEvent::PointerItem& pointerItem, int32_t sourceType, float vpr, const WSRect& rect);
326     std::unique_ptr<Media::PixelMap> HandleWindowMask(const std::vector<std::vector<uint32_t>>& windowMask);
327     void CalculateNewLimitsByLimits(
328         WindowLimits& newLimits, WindowLimits& customizedLimits, float& virtualPixelRatio);
329     void CalculateNewLimitsByRatio(WindowLimits& newLimits, WindowLimits& customizedLimits);
330     void NotifyDisplayInfoChange(const sptr<DisplayInfo>& info = nullptr);
331     void UpdateDensityInner(const sptr<DisplayInfo>& info = nullptr);
332 
333     /*
334      * Window Input Event
335      */
336     void ResetSuperFoldDisplayY(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
337 
338     /*
339      * Window Recover
340      */
341     void RegisterSessionRecoverListener(bool isSpecificSession);
342 
343     /*
344      * Window Layout
345      */
346     void CheckMoveConfiguration(MoveConfiguration& moveConfiguration);
347 
348     /*
349      * PC Window Layout
350      */
351     std::shared_ptr<MMI::PointerEvent> lastPointerEvent_ = nullptr;
352 
353     /*
354      * Window Immersive
355      */
356     void UpdateDefaultStatusBarColor();
357     WMError MoveAndResizeKeyboard(const KeyboardLayoutParams& params);
358     bool userLimitsSet_ = false;
359     bool forceLimits_ = false;
360     bool enableDefaultAnimation_ = true;
361     sptr<IAnimationTransitionController> animationTransitionController_;
362     uint32_t setSameSystembarPropertyCnt_ = 0;
363     std::atomic<bool> isDefaultDensityEnabled_ = false;
364     std::atomic<uint32_t> getAvoidAreaCnt_ = 0;
365     bool enableImmersiveMode_ = false;
366     bool titleHoverShowEnabled_ = true;
367     bool dockHoverShowEnabled_ = true;
368     void PreLayoutOnShow(WindowType type, const sptr<DisplayInfo>& info = nullptr);
369 
370     /*
371      * Gesture Back
372      */
373     bool gestureBackEnabled_ = true;
374 
375     /*
376      * Window Property
377      */
378     void InitSystemSessionDragEnable();
379     bool IsSystemDensityChanged(const sptr<DisplayInfo>& displayInfo);
380     bool IsDefaultDensityEnabled();
381     float GetMainWindowCustomDensity();
382     float customDensity_ = UNDEFINED_DENSITY;
383     std::string specifiedColorMode_;
384 
385     /*
386      * Sub Window
387      */
388     void AddSubWindowMapForExtensionWindow();
389     WMError GetParentSessionAndVerify(bool isToast, sptr<WindowSessionImpl>& parentSession);
390     WMError SetParentWindowInner(int32_t oldParentWindowId, const sptr<WindowSessionImpl>& newParentWindow);
391 
392     WMError RegisterKeyboardPanelInfoChangeListener(const sptr<IKeyboardPanelInfoChangeListener>& listener) override;
393     WMError UnregisterKeyboardPanelInfoChangeListener(const sptr<IKeyboardPanelInfoChangeListener>& listener) override;
394     static std::mutex keyboardPanelInfoChangeListenerMutex_;
395     sptr<IKeyboardPanelInfoChangeListener> keyboardPanelInfoChangeListeners_ = nullptr;
396     bool isOverTouchSlop_ = false;
397     bool isDown_ = false;
398     std::unordered_map<int32_t, std::vector<bool>> eventMapTriggerByDisplay_;
399     std::unordered_map<int32_t, std::vector<int32_t>> eventMapDeltaXByDisplay_;
400     std::unordered_map<int32_t, std::vector<PointInfo>> downPointerByDisplay_;
401 
402     /*
403      * PC Fold Screen
404      */
405     std::atomic_bool isFullScreenWaterfallMode_ { false };
406     std::atomic_bool isWaterfallToMaximize_ { false };
407     std::atomic<WindowMode> lastWindowModeBeforeWaterfall_ { WindowMode::WINDOW_MODE_UNDEFINED };
408 
409     /*
410      * Move Drag
411      */
412     bool CalcWindowShouldMove();
413 
414     /*
415      * PC Window
416      */
417     /* whether in process of delay raise during cross window drag and drop
418      * only used when delay raise is enabled and hit draggable component
419      */
420     bool isExecuteDelayRaise_ = false;
421 
422     /*
423      * Window Input Event
424      */
425     int32_t superFoldOffsetY_ = -1; // calculate the total height of the display_B area and crease area.
426 
427     /*
428      * Window Scene
429      */
430     static std::mutex windowAttachStateChangeListenerMutex_;
431     sptr<IWindowAttachStateChangeListner> windowAttachStateChangeListener_;
432     WSError NotifyWindowAttachStateChange(bool isAttach) override;
433 
434     /*
435      * Window Lifecycle
436      */
437     bool isColdStart_ = true;
438     void NotifyFreeMultiWindowModeResume();
439     std::string TransferLifeCycleEventToString(LifeCycleEvent type) const;
440     void RecordLifeCycleExceptionEvent(LifeCycleEvent event, WMError erCode) const;
441 };
442 } // namespace Rosen
443 } // namespace OHOS
444 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H
445