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