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