• 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 };
41 
42 class WindowSceneSessionImpl : public WindowSessionImpl {
43 public:
44     explicit WindowSceneSessionImpl(const sptr<WindowOption>& option);
45     ~WindowSceneSessionImpl();
46     WMError Create(const std::shared_ptr<AbilityRuntime::Context>& context,
47         const sptr<Rosen::ISession>& iSession) override;
48     WMError Show(uint32_t reason = 0, bool withAnimation = false) override;
49     WMError Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits) override;
50     WMError Destroy(bool needNotifyServer, bool needClearListener = true) override;
51     void PreProcessCreate();
52     void SetDefaultProperty();
53     WSError SetActive(bool active) override;
54     WMError DisableAppWindowDecor() override;
55     bool IsDecorEnable() const override;
56     WMError Minimize() override;
57     WMError MaximizeFloating() override;
58     WMError Maximize() override;
59     WMError Recover() override;
60     WMError Recover(uint32_t reason) override;
61     void StartMove() override;
62     WMError Close() override;
63     WindowMode GetMode() const override;
64     WMError MoveTo(int32_t x, int32_t y) override;
65     WMError Resize(uint32_t width, uint32_t height) override;
66     WmErrorCode RaiseToAppTop() override;
67     WmErrorCode RaiseAboveTarget(int32_t subWindowId) override;
68     WSError HandleBackEvent() override;
69     void PerformBack() override;
70     WMError SetAspectRatio(float ratio) override;
71     WMError ResetAspectRatio() override;
72     WMError SetGlobalMaximizeMode(MaximizeMode mode) override;
73     MaximizeMode GetGlobalMaximizeMode() const override;
74     WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) override;
75     SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override;
76     WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override;
77     WMError SetLayoutFullScreen(bool status) override;
78     WMError SetFullScreen(bool status) override;
79     WMError BindDialogTarget(sptr<IRemoteObject> targetToken) override;
80     WMError GetWindowLimits(WindowLimits& windowLimits) override;
81     WMError SetWindowLimits(WindowLimits& windowLimits) override;
82     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
83     static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
84     static sptr<Window> GetTopWindowWithId(uint32_t mainWinId);
85     static sptr<WindowSessionImpl> GetMainWindowWithId(uint32_t mainWinId);
86     virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
87     WMError NotifyMemoryLevel(int32_t level) override;
88 
89     virtual WMError AddWindowFlag(WindowFlag flag) override;
90     virtual WMError RemoveWindowFlag(WindowFlag flag) override;
91     virtual WMError SetWindowFlags(uint32_t flags) override;
92     virtual uint32_t GetWindowFlags() const override;
93 
94     // window effect
95     virtual WMError SetCornerRadius(float cornerRadius) override;
96     virtual WMError SetShadowRadius(float radius) override;
97     virtual WMError SetShadowColor(std::string color) override;
98     virtual WMError SetShadowOffsetX(float offsetX) override;
99     virtual WMError SetShadowOffsetY(float offsetY) override;
100     virtual WMError SetBlur(float radius) override;
101     virtual WMError SetBackdropBlur(float radius) override;
102     virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) override;
103     virtual WMError SetWindowMode(WindowMode mode) override;
104 
105     virtual WMError SetTransparent(bool isTransparent) override;
106     virtual WMError SetTurnScreenOn(bool turnScreenOn) override;
107     virtual WMError SetKeepScreenOn(bool keepScreenOn) override;
108     virtual WMError SetPrivacyMode(bool isPrivacyMode) override;
109     virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) override;
110     virtual WMError SetSnapshotSkip(bool isSkip) override;
111     virtual std::shared_ptr<Media::PixelMap> Snapshot() override;
112     WMError SetTouchHotAreas(const std::vector<Rect>& rects) override;
113     virtual WmErrorCode KeepKeyboardOnFocus(bool keepKeyboardFlag) override;
114     virtual WMError SetCallingWindow(uint32_t callingWindowId) override;
115 
116     virtual bool IsTransparent() const override;
117     virtual bool IsTurnScreenOn() const override;
118     virtual bool IsKeepScreenOn() const override;
119     virtual bool IsPrivacyMode() const override;
120     virtual bool IsLayoutFullScreen() const override;
121     virtual bool IsFullScreen() const override;
122     WMError RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) override;
123     void SetNeedDefaultAnimation(bool needDefaultAnimation) override;
124     WMError SetTransform(const Transform& trans) override;
125     const Transform& GetTransform() const override;
126     WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override;
127     WMError SetAlpha(float alpha) override;
128     void DumpSessionElementInfo(const std::vector<std::string>& params) override;
129     WSError UpdateWindowMode(WindowMode mode) override;
130     WSError UpdateMaximizeMode(MaximizeMode mode) override;
131     WSError UpdateTitleInTargetPos(bool isShow, int32_t height) override;
132     void NotifySessionForeground(uint32_t reason, bool withAnimation) override;
133     void NotifySessionBackground(uint32_t reason, bool withAnimation, bool isFromInnerkits) override;
134     WMError NotifyPrepareClosePiPWindow() override;
135     WMError RecoveryPullPiPMainWindow(const Rect& rect) override;
136     void UpdateSubWindowState(const WindowType& type);
137     WMError SetSpecificBarProperty(WindowType type, const SystemBarProperty& property) override;
138     void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent) override;
139     WSError NotifyDialogStateChange(bool isForeground) override;
140 
141 protected:
142     void DestroySubWindow();
143     WMError CreateAndConnectSpecificSession();
144     WMError RecoverAndConnectSpecificSession();
145     WMError RecoverAndReconnectSceneSession();
146     sptr<WindowSessionImpl> FindParentSessionByParentId(uint32_t parentId);
147     sptr<WindowSessionImpl> FindMainWindowWithContext();
148     void UpdateSubWindowStateAndNotify(int32_t parentPersistentId, const WindowState& newState);
149     void LimitCameraFloatWindowMininumSize(uint32_t& width, uint32_t& height);
150     void UpdateFloatingWindowSizeBySizeLimits(uint32_t& width, uint32_t& height) const;
151     WMError NotifyWindowSessionProperty();
152     WMError NotifyWindowNeedAvoid(bool status = false);
153     WMError SetLayoutFullScreenByApiVersion(bool status) override;
154     void UpdateWindowSizeLimits();
155     WindowLimits GetSystemSizeLimits(uint32_t displayWidth, uint32_t displayHeight, float vpr);
156     void GetConfigurationFromAbilityInfo();
157     WMError NotifySpecificWindowSessionProperty(WindowType type, const SystemBarProperty& property);
158 
159 private:
160     WMError DestroyInner(bool needNotifyServer);
161     bool IsValidSystemWindowType(const WindowType& type);
162     WMError CheckParmAndPermission();
163     static uint32_t maxFloatingWindowSize_;
164     void TransformSurfaceNode(const Transform& trans);
165     void AdjustWindowAnimationFlag(bool withAnimation = false);
166     void RegisterSessionRecoverListener(bool isSpecificSession);
167     WMError UpdateAnimationFlagProperty(bool withAnimation);
168     WMError UpdateWindowModeImmediately(WindowMode mode);
169     uint32_t UpdateConfigVal(uint32_t minVal, uint32_t maxVal, uint32_t configVal, uint32_t defaultVal, float vpr);
170     void UpdateWindowState();
171     void UpdateNewSize();
172     void fillWindowLimits(WindowLimits& windowLimits);
173     void ConsumePointerEventInner(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
174         const MMI::PointerEvent::PointerItem& pointerItem);
175     bool HandlePointDownEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
176         const MMI::PointerEvent::PointerItem& pointerItem, int32_t sourceType, float vpr, const WSRect& rect);
177     bool enableDefaultAnimation_ = true;
178     sptr<IAnimationTransitionController> animationTransitionController_;
179 };
180 } // namespace Rosen
181 } // namespace OHOS
182 #endif // OHOS_ROSEN_WINDOW_SCENE_SESSION_IMPL_H
183