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, 53 const Rect& rect = Rect::EMPTY_RECT) const; 54 WMError GetTopWindowId(uint32_t mainWinId, uint32_t& topWinId); 55 void NotifyDisplayStateChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 56 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 57 WMError NotifyServerReadyToMoveOrDrag(uint32_t windowId, sptr<MoveDragProperty>& moveDragProperty); 58 WMError ProcessPointDown(uint32_t windowId, bool isPointDown); 59 std::shared_ptr<Media::PixelMap> GetSnapshot(int32_t windowId); 60 WMError ProcessPointUp(uint32_t windowId); 61 void MinimizeAllAppWindows(DisplayId displayId); 62 WMError ToggleShownStateForAllAppWindows(); 63 WMError SetWindowLayoutMode(WindowLayoutMode mode); 64 WMError NotifyScreenshotEvent(ScreenshotEventType type); 65 WMError UpdateProperty(sptr<WindowProperty>& property, PropertyChangeAction action); 66 WMError SetWindowGravity(uint32_t windowId, WindowGravity gravity, uint32_t percent); 67 void NotifySystemBarTints(); 68 WMError SetWindowAnimationController(const sptr<RSIWindowAnimationController>& controller); 69 WMError GetModeChangeHotZones(DisplayId displayId, 70 ModeChangeHotZones& hotZones, const ModeChangeHotZonesConfig& config); 71 void StartingWindow(sptr<WindowTransitionInfo> info, std::shared_ptr<Media::PixelMap> pixelMap, 72 uint32_t bkgColor, bool isColdStart); 73 void CancelStartingWindow(sptr<IRemoteObject> abilityToken); 74 void MinimizeWindowsByLauncher(std::vector<uint32_t>& windowIds, bool isAnimated, 75 sptr<RSIWindowAnimationFinishedCallback>& finishCallback); 76 void OnScreenshot(DisplayId displayId); 77 WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const; 78 WMError GetUnreliableWindowInfo(int32_t windowId, std::vector<sptr<UnreliableWindowInfo>>& infos) const; 79 WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const; 80 void SetAnchorAndScale(int32_t x, int32_t y, float scale); 81 void SetAnchorOffset(int32_t deltaX, int32_t deltaY); 82 void OffWindowZoom(); 83 WMError BindDialogTarget(uint32_t& windowId, sptr<IRemoteObject> targetToken); 84 WMError InterceptInputEventToServer(uint32_t windowId); 85 WMError RecoverInputEventToClient(uint32_t windowId); 86 WMError NotifyWindowClientPointUp(uint32_t windowId, const std::shared_ptr<MMI::PointerEvent>& pointerEvent); 87 WMError ChangeMouseStyle(uint32_t windowId, sptr<MoveDragProperty>& moveDragProperty); 88 void RecoverDefaultMouseStyle(uint32_t windowId); 89 WMError RaiseToAppTop(uint32_t windowId); 90 void DispatchKeyEvent(uint32_t windowId, std::shared_ptr<MMI::KeyEvent> event); 91 WMError SetAspectRatio(uint32_t windowId, float ratio); 92 void FlushWindowInfo(uint32_t windowId); 93 void SetDragFrameGravity(int32_t dragGravity); 94 95 private: 96 uint32_t GenWindowId(); 97 void FlushWindowInfoWithDisplayId(DisplayId displayId); 98 void UpdateWindowAnimation(const sptr<WindowNode>& node); 99 void ProcessDisplayChange(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo, 100 const std::map<DisplayId, sptr<DisplayInfo>>& displayInfoMap, DisplayStateChangeType type); 101 void StopBootAnimationIfNeed(const sptr<WindowNode>& node); 102 void RecordBootAnimationEvent() const; 103 WMError SetWindowType(uint32_t windowId, WindowType type); 104 WMError SetWindowFlags(uint32_t windowId, uint32_t flags, bool isSystemCalling); 105 WMError SetSystemBarProperty(uint32_t windowId, WindowType type, const SystemBarProperty& property); 106 WMError ResizeRect(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason); 107 WMError ResizeRectAndFlush(uint32_t windowId, const Rect& rect, WindowSizeChangeReason reason); 108 WMError SetWindowMode(uint32_t windowId, WindowMode dstMode); 109 void ResizeSoftInputCallingWindowIfNeed(const sptr<WindowNode>& node); 110 void RestoreCallingWindowSizeIfNeed(); 111 void HandleTurnScreenOn(const sptr<WindowNode>& node); 112 WMError UpdateTouchHotAreas(const sptr<WindowNode>& node, const std::vector<Rect>& rects); 113 WMError UpdateTransform(uint32_t windowId); 114 void NotifyTouchOutside(const sptr<WindowNode>& node); 115 uint32_t GetEmbedNodeId(const std::vector<sptr<WindowNode>>& windowNodes, const sptr<WindowNode>& node); 116 void NotifyWindowPropertyChanged(const sptr<WindowNode>& node); 117 WMError GetFocusWindowNode(DisplayId displayId, sptr<WindowNode>& windowNode); 118 void SetDefaultDisplayInfo(DisplayId defaultDisplayId, sptr<DisplayInfo> displayInfo); 119 void ProcessDisplayCompression(DisplayId defaultDisplayId, const sptr<DisplayInfo>& displayInfo); 120 void NotifyAfterAddWindow(sptr<WindowNode>& node); 121 bool GetNavigationBarHeight(DisplayId displayId, uint32_t& navigationBarHeight); 122 void RelayoutKeyboard(const sptr<WindowNode>& node); 123 bool CheckParentWindowValid(const sptr<WindowProperty>& property); 124 void UpdatePrivateStateAndNotify(const sptr<WindowNode>& node); 125 void UpdateFocusIfNeededWhenRaiseWindow(const sptr<WindowNode>& node); 126 void NotifyInputCallingWindowRectAndOccupiedAreaChange(const sptr<WindowNode>& callingWindow, const Rect& rect, 127 const Rect& occupiedArea); 128 129 sptr<WindowRoot> windowRoot_; 130 sptr<InputWindowMonitor> inputWindowMonitor_; 131 sptr<AccessibilityConnection> accessibilityConnection_; 132 sptr<DisplayZoomController> displayZoomController_; 133 std::atomic<uint32_t> windowId_ { INVALID_WINDOW_ID }; 134 // Remove 'sysBarWinId_' after SystemUI resize 'systembar', systemBar only exist on default display currently 135 std::unordered_map<WindowType, uint32_t> sysBarWinId_ { 136 { WindowType::WINDOW_TYPE_STATUS_BAR, INVALID_WINDOW_ID }, 137 { WindowType::WINDOW_TYPE_NAVIGATION_BAR, INVALID_WINDOW_ID }, 138 }; 139 bool isScreenLocked_ { false }; 140 Rect callingWindowRestoringRect_ { 0, 0, 0, 0 }; 141 uint32_t callingWindowId_ = 0u; 142 Rect defaultDisplayRect_ = { 0, 0, 0, 0 }; 143 bool isBootAnimationStopped_ = false; 144 std::shared_ptr<RSSurfaceNode> maskingSurfaceNode_ = nullptr; 145 const std::map<DragType, uint32_t> STYLEID_MAP = { 146 {DragType::DRAG_UNDEFINED, MMI::MOUSE_ICON::DEFAULT}, 147 {DragType::DRAG_BOTTOM_OR_TOP, MMI::MOUSE_ICON::NORTH_SOUTH}, 148 {DragType::DRAG_LEFT_OR_RIGHT, MMI::MOUSE_ICON::WEST_EAST}, 149 {DragType::DRAG_LEFT_TOP_CORNER, MMI::MOUSE_ICON::NORTH_WEST_SOUTH_EAST}, 150 {DragType::DRAG_RIGHT_TOP_CORNER, MMI::MOUSE_ICON::NORTH_EAST_SOUTH_WEST} 151 }; 152 const int32_t INVALID_GRAVITY = -1; 153 int32_t dragFrameGravity_ = INVALID_GRAVITY; 154 }; 155 } // Rosen 156 } // OHOS 157 #endif // OHOS_ROSEN_WINDOW_CONTROLLER_H 158