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