1 /*
2  * Copyright (c) 2021-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_NODE_H
17 #define OHOS_ROSEN_WINDOW_NODE_H
18 
19 #include <ipc_skeleton.h>
20 #include <refbase.h>
21 #include <ui/rs_surface_node.h>
22 #include "zidl/window_interface.h"
23 #include "window_manager_hilog.h"
24 #include "window_node_state_machine.h"
25 #include "window_visibility_info.h"
26 
27 #ifdef POWER_MANAGER_ENABLE
28 #include <running_lock.h>
29 #endif
30 
31 namespace OHOS {
32 namespace Rosen {
33 class WindowNode : public RefBase {
34 public:
WindowNode(const sptr<WindowProperty> & property,const sptr<IWindow> & window,std::shared_ptr<RSSurfaceNode> surfaceNode)35     WindowNode(const sptr<WindowProperty>& property, const sptr<IWindow>& window,
36         std::shared_ptr<RSSurfaceNode> surfaceNode)
37         : surfaceNode_(surfaceNode), property_(property), windowToken_(window)
38     {
39         if (property != nullptr) {
40             abilityInfo_ = property->GetAbilityInfo();
41         }
42     }
WindowNode(const sptr<WindowProperty> & property,const sptr<IWindow> & window,std::shared_ptr<RSSurfaceNode> surfaceNode,int32_t pid,int32_t uid)43     WindowNode(const sptr<WindowProperty>& property, const sptr<IWindow>& window,
44         std::shared_ptr<RSSurfaceNode> surfaceNode, int32_t pid, int32_t uid)
45         : surfaceNode_(surfaceNode), property_(property), windowToken_(window), callingPid_(pid), callingUid_(uid)
46     {
47         inputCallingPid_ = pid;
48         if (property != nullptr) {
49             abilityInfo_ = property->GetAbilityInfo();
50         }
51     }
WindowNode()52     WindowNode() : property_(new WindowProperty())
53     {
54     }
WindowNode(const sptr<WindowProperty> & property)55     explicit WindowNode(const sptr<WindowProperty>& property) : property_(property)
56     {
57     }
58     ~WindowNode();
59 
60     void SetDisplayId(DisplayId displayId);
61     void SetEntireWindowTouchHotArea(const Rect& rect);
62     void SetEntireWindowPointerHotArea(const Rect& rect);
63     void SetWindowRect(const Rect& rect);
64     void SetDecorEnable(bool decorEnable);
65     void SetDecoStatus(bool decoStatus);
66     void SetRequestRect(const Rect& rect);
67     void SetWindowProperty(const sptr<WindowProperty>& property);
68     void SetSystemBarProperty(WindowType type, const SystemBarProperty& property);
69     void SetWindowMode(WindowMode mode);
70     void SetBrightness(float brightness);
71     void SetFocusable(bool focusable);
72     void SetTouchable(bool touchable);
73     void SetTurnScreenOn(bool turnScreenOn);
74     void SetKeepScreenOn(bool keepScreenOn);
75     void SetCallingWindow(uint32_t windowId);
76     void SetInputEventCallingPid(int32_t pid);
77     void SetCallingPid(int32_t pid);
78     void SetCallingUid(int32_t uid);
79     void SetWindowToken(sptr<IWindow> window);
80     uint32_t GetCallingWindow() const;
81     void SetWindowSizeChangeReason(WindowSizeChangeReason reason);
82     void SetRequestedOrientation(Orientation orientation);
83     void SetShowingDisplays(const std::vector<DisplayId>& displayIdVec);
84     void SetWindowModeSupportType(uint32_t windowModeSupportType);
85     void SetDragType(DragType dragType);
86     void SetOriginRect(const Rect& rect);
87     void SetTouchHotAreas(const std::vector<Rect>& rects);
88     void SetPointerHotAreas(const std::vector<Rect>& rects);
89     void SetWindowSizeLimits(const WindowLimits& sizeLimits);
90     void SetWindowUpdatedSizeLimits(const WindowLimits& sizeLimits);
91     void ComputeTransform();
92     void SetTransform(const Transform& trans);
93     void SetSnapshot(std::shared_ptr<Media::PixelMap> pixelMap);
94     std::shared_ptr<Media::PixelMap> GetSnapshot();
95     Transform GetZoomTransform() const;
96     void UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn);
97     void SetAspectRatio(float ratio);
98     void SetWindowGravity(WindowGravity gravity, uint32_t percent);
99     void SetVisibilityState(WindowVisibilityState state);
100 
101     const sptr<IWindow>& GetWindowToken() const;
102     uint32_t GetWindowId() const;
103     uint32_t GetParentId() const;
104     const std::string& GetWindowName() const;
105     DisplayId GetDisplayId() const;
106     Rect GetEntireWindowTouchHotArea() const;
107     Rect GetEntireWindowPointerHotArea() const;
108     Rect GetWindowRect() const;
109     bool GetDecoStatus() const;
110     Rect GetRequestRect() const;
111     WindowType GetWindowType() const;
112     WindowMode GetWindowMode() const;
113     float GetBrightness() const;
114     bool IsTurnScreenOn() const;
115     bool IsKeepScreenOn() const;
116     uint32_t GetWindowFlags() const;
117     const sptr<WindowProperty>& GetWindowProperty() const;
118     int32_t GetInputEventCallingPid() const;
119     int32_t GetCallingPid() const;
120     int32_t GetCallingUid() const;
121     const std::unordered_map<WindowType, SystemBarProperty>& GetSystemBarProperty() const;
122     bool IsSplitMode() const;
123     WindowSizeChangeReason GetWindowSizeChangeReason() const;
124     Orientation GetRequestedOrientation() const;
125     std::vector<DisplayId> GetShowingDisplays() const;
126     uint32_t GetWindowModeSupportType() const;
127     DragType GetDragType() const;
128     bool GetStretchable() const;
129     const Rect& GetOriginRect() const;
130     void ResetWindowSizeChangeReason();
131     void GetTouchHotAreas(std::vector<Rect>& rects) const;
132     void GetPointerHotAreas(std::vector<Rect>& rects) const;
133     uint32_t GetAccessTokenId() const;
134     WindowLimits GetWindowSizeLimits() const;
135     WindowLimits GetWindowUpdatedSizeLimits() const;
136     float GetAspectRatio() const;
137     void GetWindowGravity(WindowGravity& gravity, uint32_t& percent) const;
138     WindowVisibilityState GetVisibilityState() const;
139     bool GetTouchable() const;
140 
141     bool EnableDefaultAnimation(bool animationPlayed);
142     sptr<WindowNode> parent_;
143     std::vector<sptr<WindowNode>> children_;
144     std::shared_ptr<RSSurfaceNode> surfaceNode_;
145     std::shared_ptr<RSSurfaceNode> leashWinSurfaceNode_ = nullptr;
146     std::shared_ptr<RSSurfaceNode> startingWinSurfaceNode_ = nullptr;
147     std::shared_ptr<RSSurfaceNode> closeWinSurfaceNode_ = nullptr;
148     sptr<IRemoteObject> dialogTargetToken_ = nullptr;
149     sptr<IRemoteObject> abilityToken_ = nullptr;
150 
151 #ifdef POWER_MANAGER_ENABLE
152     std::shared_ptr<PowerMgr::RunningLock> keepScreenLock_ = nullptr;
153 #endif
154 
155     int32_t priority_ { 0 };
156     uint32_t zOrder_ { 0 };
157     bool requestedVisibility_ { false };
158     bool currentVisibility_ { false };
159     WindowVisibilityState visibilityState_ { WINDOW_LAYER_STATE_MAX };
160     bool isAppCrash_ { false };
161     bool isPlayAnimationShow_ { false }; // delete when enable state machine
162     bool isPlayAnimationHide_ { false }; // delete when enable state machine
163     bool startingWindowShown_ { false };
164     bool firstFrameAvailable_ { false };
165     bool isShowingOnMultiDisplays_ { false };
166     std::vector<DisplayId> showingDisplays_;
167     AbilityInfo abilityInfo_;
168     WindowNodeStateMachine stateMachine_;
169     bool isFocused_ { false };
170 private:
171     sptr<WindowProperty> property_ = nullptr;
172     sptr<IWindow> windowToken_ = nullptr;
173     Rect entireWindowTouchHotArea_ { 0, 0, 0, 0 };
174     Rect entireWindowPointerHotArea_ { 0, 0, 0, 0 };
175     std::vector<Rect> touchHotAreas_; // coordinates relative to display.
176     std::vector<Rect> pointerHotAreas_; // coordinates relative to display.
177     std::shared_ptr<Media::PixelMap> snapshot_;
178     int32_t callingPid_ = { 0 };
179     int32_t inputCallingPid_ = { 0 };
180     int32_t callingUid_ = { 0 };
181     WindowSizeChangeReason windowSizeChangeReason_ {WindowSizeChangeReason::UNDEFINED};
182 };
183 } // Rosen
184 } // OHOS
185 #endif // OHOS_ROSEN_WINDOW_NODE_H
186