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