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_CONTROLLER_H 17 #define OHOS_ROSEN_WINDOW_CONTROLLER_H 18 19 #include <refbase.h> 20 #include <rs_iwindow_animation_controller.h> 21 22 #include "accessibility_connection.h" 23 #include "display_zoom_controller.h" 24 #include "input_window_monitor.h" 25 #include "zidl/window_manager_agent_interface.h" 26 #include "window_root.h" 27 #include "window_transition_info.h" 28 #include "wm_common.h" 29 #include "wm_occlusion_region.h" 30 #include "struct_multimodal.h" 31 32 namespace OHOS { 33 namespace Rosen { 34 class WindowController : public RefBase { 35 public: WindowController(sptr<WindowRoot> & root,sptr<InputWindowMonitor> inputWindowMonitor)36 WindowController(sptr<WindowRoot>& root, sptr<InputWindowMonitor> inputWindowMonitor) : windowRoot_(root), 37 inputWindowMonitor_(inputWindowMonitor), accessibilityConnection_(new AccessibilityConnection(windowRoot_)), 38 displayZoomController_(new DisplayZoomController(root)) {} 39 ~WindowController() = default; 40 41 WMError CreateWindow(sptr<IWindow>& window, sptr<WindowProperty>& property, 42 const std::shared_ptr<RSSurfaceNode>& surfaceNode, 43 uint32_t& windowId, sptr<IRemoteObject> token, int32_t pid, int32_t uid); 44 WMError AddWindowNode(sptr<WindowProperty>& property); 45 WMError RemoveWindowNode(uint32_t windowId, bool fromAnimation = false); 46 WMError NotifyWindowTransition(sptr<WindowTransitionInfo>& fromInfo, sptr<WindowTransitionInfo>& toInfo); 47 WMError GetFocusWindowInfo(sptr<IRemoteObject>& abilityToken); 48 WMError GetFocusWindowInfo(FocusChangeInfo& focusInfo); 49 WMError DestroyWindow(uint32_t windowId, bool onlySelf); 50 WMError RequestFocus(uint32_t windowId); 51 WMError SetAlpha(uint32_t windowId, float alpha); 52 AvoidArea GetAvoidAreaByType(uint32_t windowId, AvoidAreaType avoidAreaType) const; 53 WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); 54 void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 55 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 56 WMError NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<MoveDragProperty>& moveDragProperty); 57 WMError ProcessPointDown(uint32_t windowId, bool isPointDown); 58 std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId); 59 WMError ProcessPointUp(uint32_t windowId); 60 void MinimizeAllAppWindows(DisplayId displayId); 61 WMError ToggleShownStateForAllAppWindows(); 62 WMError SetWindowLayoutMode(WindowLayoutMode mode); 63 WMError UpdateProperty(sptr<WindowProperty>& property, PropertyChangeAction action); 64 WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent); 65 void NotifySystemBarTints(); 66 WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller); 67 WMError GetModeChangeHotZones(DisplayId displayId, 68 ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config); 69 void StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap, 70 uint32_t bkgColor, bool isColdStart); 71 void CancelStartingWindow(sptr<IRemoteObject> abilityToken); 72 void MinimizeWindowsByLauncher(std::vector<uint32_t>& windowIds, bool isAnimated, 73 sptr<RSIWindowAnimationFinishedCallback>& finishCallback); 74 void OnScreenshot(DisplayId displayId); 75 WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const; 76 WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos) const; 77 WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const; 78 void SetAnchorAndScale(int32_t x, int32_t y, float scale); 79 void SetAnchorOffset(int32_t deltaX, int32_t deltaY); 80 void OffWindowZoom(); 81 WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken); 82 WMError InterceptInputEventToServer(uint32_t windowId); 83 WMError RecoverInputEventToClient(uint32_t windowId); 84 WMError NotifyWindowClientPointUp(uint32_t windowId, const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 85 WMError ChangeMouseStyle(uint32_t windowId, sptr<MoveDragProperty>& moveDragProperty); 86 void RecoverDefaultMouseStyle(uint32_t windowId); 87 WMError RaiseToAppTop(uint32_t windowId); 88 void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event); 89 WMError SetAspectRatio(uint32_t windowId, float ratio); 90 void FlushWindowInfo(uint32_t windowId); 91 void SetDragFrameGravity(int32_t dragGravity); 92 93 private: 94 uint32_t GenWindowId(); 95 void FlushWindowInfoWithDisplayId(DisplayId displayId); 96 void UpdateWindowAnimation(const sptr<WindowNode>& node); 97 void ProcessDisplayChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 98 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 99 void StopBootAnimationIfNeed(const sptr<WindowNode>& node); 100 void RecordBootAnimationEvent() const; 101 WMError SetWindowType(uint32_t windowId, WindowType type); 102 WMError SetWindowFlags(uint32_t windowId, uint32_t flags, bool isSystemCalling); 103 WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); 104 WMError ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason); 105 WMError ResizeRectAndFlush(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason); 106 WMError SetWindowMode(uint32_t windowId, WindowMode dstMode); 107 void ResizeSoftInputCallingWindowIfNeed(const sptr<WindowNode>& node); 108 void RestoreCallingWindowSizeIfNeed(); 109 void HandleTurnScreenOn(const sptr<WindowNode>& node); 110 WMError UpdateTouchHotAreas(const sptr<WindowNode>& node, const std::vector<Rect>& rects); 111 WMError UpdateTransform(uint32_t windowId); 112 void NotifyTouchOutside(const sptr<WindowNode>& node); 113 uint32_t GetEmbedNodeId(const std::vector<sptr<WindowNode>>& windowNodes, const sptr<WindowNode>& node); 114 void NotifyWindowPropertyChanged(const sptr<WindowNode>& node); 115 WMError GetFocusWindowNode(DisplayId displayId, sptr<WindowNode>& windowNode); 116 void SetDefaultDisplayInfo(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo); 117 void ProcessDisplayCompression(DisplayId defaultDisplayId, const sptr<DisplayInfo>& displayInfo); 118 void NotifyAfterAddWindow(sptr<WindowNode>& node); 119 bool GetNavigationBarHeight(DisplayId displayId, uint32_t& navigationBarHeight); 120 void RelayoutKeyboard(const sptr<WindowNode>& node); 121 bool CheckParentWindowValid(const sptr<WindowProperty>& property); 122 void UpdatePrivateStateAndNotify(const sptr<WindowNode>& node); 123 void UpdateFocusIfNeededWhenRaiseWindow(const sptr<WindowNode>& node); 124 void NotifyInputCallingWindowRectAndOccupiedAreaChange(const sptr<WindowNode>& callingWindow, const Rect& rect, 125 const Rect& occupiedArea); 126 127 sptr<WindowRoot> windowRoot_; 128 sptr<InputWindowMonitor> inputWindowMonitor_; 129 sptr<AccessibilityConnection> accessibilityConnection_; 130 sptr<DisplayZoomController> displayZoomController_; 131 std::atomic<uint32_t> windowId_ { INVALID_WINDOW_ID }; 132 // Remove 'sysBarWinId_' after SystemUI resize 'systembar', systemBar only exist on default display currently 133 std::unordered_map<WindowType, uint32_t> sysBarWinId_ { 134 { WindowType::WINDOW_TYPE_STATUS_BAR, INVALID_WINDOW_ID }, 135 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID }, 136 }; 137 bool isScreenLocked_ { false }; 138 Rect callingWindowRestoringRect_ { 0, 0, 0, 0 }; 139 uint32_t callingWindowId_ = 0u; 140 Rect defaultDisplayRect_ = { 0, 0, 0, 0 }; 141 bool isBootAnimationStopped_ = false; 142 std::shared_ptr<RSSurfaceNode> maskingSurfaceNode_ = nullptr; 143 const std::map<DragType, uint32_t> STYLEID_MAP = { 144 {DragType::DRAG_UNDEFINED, MMI::MOUSE_ICON::DEFAULT}, 145 {DragType::DRAG_BOTTOM_OR_TOP, MMI::MOUSE_ICON::NORTH_SOUTH}, 146 {DragType::DRAG_LEFT_OR_RIGHT, MMI::MOUSE_ICON::WEST_EAST}, 147 {DragType::DRAG_LEFT_TOP_CORNER, MMI::MOUSE_ICON::NORTH_WEST_SOUTH_EAST}, 148 {DragType::DRAG_RIGHT_TOP_CORNER, MMI::MOUSE_ICON::NORTH_EAST_SOUTH_WEST} 149 }; 150 const int32_t INVALID_GRAVITY = -1; 151 int32_t dragFrameGravity_ = INVALID_GRAVITY; 152 }; 153 } // Rosen 154 } // OHOS 155 #endif // OHOS_ROSEN_WINDOW_CONTROLLER_H 156