• 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_MANAGER_H
17 #define OHOS_ROSEN_WINDOW_MANAGER_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <refbase.h>
22 #include <vector>
23 #include <iremote_object.h>
24 #include "wm_single_instance.h"
25 #include "wm_common.h"
26 #include "focus_change_info.h"
27 #include "window_visibility_info.h"
28 
29 namespace OHOS {
30 namespace Rosen {
31 struct SystemBarRegionTint {
32     WindowType type_;
33     SystemBarProperty prop_;
34     Rect region_;
SystemBarRegionTintSystemBarRegionTint35     SystemBarRegionTint()
36         : type_(WindowType::WINDOW_TYPE_APP_MAIN_WINDOW), prop_(), region_{ 0, 0, 0, 0 } {}
SystemBarRegionTintSystemBarRegionTint37     SystemBarRegionTint(WindowType type, SystemBarProperty prop, Rect region)
38         : type_(type), prop_(prop), region_(region) {}
39 };
40 using SystemBarRegionTints = std::vector<SystemBarRegionTint>;
41 
42 /**
43  * @class IFocusChangedListener
44  *
45  * @brief Listener to observe focus changed.
46  */
47 class IFocusChangedListener : virtual public RefBase {
48 public:
49     /**
50      * @brief Notify caller when window get focus
51      *
52      * @param focusChangeInfo Window info while its focus status changed.
53      */
54     virtual void OnFocused(const sptr<FocusChangeInfo>& focusChangeInfo) = 0;
55     /**
56      * @brief Notify caller when window lose focus
57      *
58      * @param focusChangeInfo Window info while its focus status changed.
59      */
60     virtual void OnUnfocused(const sptr<FocusChangeInfo>& focusChangeInfo) = 0;
61 };
62 
63 /**
64  * @class ISystemBarChangedListener
65  *
66  * @brief Listener to observe systembar changed.
67  */
68 class ISystemBarChangedListener : virtual public RefBase {
69 public:
70     /**
71      * @brief Notify caller when system bar property changed
72      *
73      * @param displayId ID of display.
74      * @param tints Tint of system bar region.
75      */
76     virtual void OnSystemBarPropertyChange(DisplayId displayId, const SystemBarRegionTints& tints) = 0;
77 };
78 
79 /**
80  * @class IGestureNavigationEnabledChangedListener
81  *
82  * @brief Listener to observe GestureNavigationEnabled changed.
83  */
84 class IGestureNavigationEnabledChangedListener : virtual public RefBase {
85 public:
86     /**
87      * @brief Notify caller when GestureNavigationEnabled changed.
88      *
89      * @param enable True means set Gesture on, false means set Gesture off.
90      */
91     virtual void OnGestureNavigationEnabledUpdate(bool enable) = 0;
92 };
93 
94 
95 /**
96  * @class IVisibilityChangedListener
97  *
98  * @brief Listener to observe visibility changed.
99  */
100 class IVisibilityChangedListener : virtual public RefBase {
101 public:
102     /**
103      * @brief Notify caller when window visibility changed.
104      *
105      * @param windowVisibilityInfo Window visibility info.
106      */
107     virtual void OnWindowVisibilityChanged(const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfo) = 0;
108 };
109 
110 /**
111  * @class AccessibilityWindowInfo
112  *
113  * @brief Window info used for Accessibility.
114  */
115 class AccessibilityWindowInfo : public Parcelable {
116 public:
117     /**
118      * @brief Default construct of AccessibilityWindowInfo.
119      */
120     AccessibilityWindowInfo() = default;
121     /**
122      * @brief Default deconstruct of AccessibilityWindowInfo.
123      */
124     ~AccessibilityWindowInfo() = default;
125 
126     /**
127      * @brief Marshalling AccessibilityWindowInfo.
128      *
129      * @param parcel Package of AccessibilityWindowInfo.
130      * @return True means marshall success, false means marshall failed.
131      */
132     virtual bool Marshalling(Parcel& parcel) const override;
133     /**
134      * @brief Unmarshalling AccessibilityWindowInfo.
135      *
136      * @param parcel Package of AccessibilityWindowInfo.
137      * @return AccessibilityWindowInfo object.
138      */
139     static AccessibilityWindowInfo* Unmarshalling(Parcel& parcel);
140 
141     int32_t wid_;
142     int32_t innerWid_;
143     int32_t uiNodeId_;
144     Rect windowRect_;
145     bool focused_ { false };
146     bool isDecorEnable_ { false };
147     DisplayId displayId_;
148     uint32_t layer_;
149     WindowMode mode_;
150     WindowType type_;
151 };
152 
153 /**
154  * @class IWindowUpdateListener
155  *
156  * @brief Listener to observe window update.
157  */
158 class IWindowUpdateListener : virtual public RefBase {
159 public:
160     /**
161      * @brief Notify caller when AccessibilityWindowInfo update.
162      *
163      * @param infos Window info used for Accessibility.
164      * @param type Type for window update.
165      */
166     virtual void OnWindowUpdate(const std::vector<sptr<AccessibilityWindowInfo>>& infos, WindowUpdateType type) = 0;
167 };
168 
169 /**
170  * @class IWaterMarkFlagChangedListener
171  *
172  * @brief Listener to observe water mark flag changed.
173  */
174 class IWaterMarkFlagChangedListener : virtual public RefBase {
175 public:
176     /**
177      * @brief Notify caller when water mark flag changed.
178      *
179      * @param showWaterMark True means show water mark, false means the opposite.
180      */
181     virtual void OnWaterMarkFlagUpdate(bool showWaterMark) = 0;
182 };
183 
184 /**
185  * @class ICameraFloatWindowChangedListener
186  *
187  * @brief Listener to observe camera window changed.
188  */
189 class ICameraFloatWindowChangedListener : virtual public RefBase {
190 public:
191     /**
192      * @brief Notify caller when camera window changed.
193      *
194      * @param accessTokenId Token id of camera window.
195      * @param isShowing True means camera is shown, false means the opposite.
196      */
197     virtual void OnCameraFloatWindowChange(uint32_t accessTokenId, bool isShowing) = 0;
198 };
199 
200 /**
201  * @class WindowManager
202  *
203  * @brief WindowManager used to manage window.
204  */
205 class WindowManager {
206 WM_DECLARE_SINGLE_INSTANCE_BASE(WindowManager);
207 friend class WindowManagerAgent;
208 friend class WMSDeathRecipient;
209 public:
210     /**
211      * @brief Register focus changed listener.
212      *
213      * @param listener IFocusChangedListener.
214      * @return WM_OK means register success, others means register failed.
215      */
216     WMError RegisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
217     /**
218      * @brief Unregister focus changed listener.
219      *
220      * @param listener IFocusChangedListener.
221      * @return WM_OK means unregister success, others means unregister failed.
222      */
223     WMError UnregisterFocusChangedListener(const sptr<IFocusChangedListener>& listener);
224     /**
225      * @brief Register system bar changed listener.
226      *
227      * @param listener ISystemBarChangedListener.
228      * @return WM_OK means register success, others means register failed.
229      */
230     WMError RegisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
231     /**
232      * @brief Unregister system bar changed listener.
233      *
234      * @param listener ISystemBarChangedListener.
235      * @return WM_OK means unregister success, others means unregister failed.
236      */
237     WMError UnregisterSystemBarChangedListener(const sptr<ISystemBarChangedListener>& listener);
238     /**
239      * @brief Register window updated listener.
240      *
241      * @param listener IWindowUpdateListener.
242      * @return WM_OK means register success, others means register failed.
243      */
244     WMError RegisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
245     /**
246      * @brief Unregister window updated listener.
247      *
248      * @param listener IWindowUpdateListener.
249      * @return WM_OK means unregister success, others means unregister failed.
250      */
251     WMError UnregisterWindowUpdateListener(const sptr<IWindowUpdateListener>& listener);
252     /**
253      * @brief Register visibility changed listener.
254      *
255      * @param listener IVisibilityChangedListener.
256      * @return WM_OK means register success, others means register failed.
257      */
258     WMError RegisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
259     /**
260      * @brief Unregister visibility changed listener.
261      *
262      * @param listener IVisibilityChangedListener.
263      * @return WM_OK means unregister success, others means unregister failed.
264      */
265     WMError UnregisterVisibilityChangedListener(const sptr<IVisibilityChangedListener>& listener);
266     /**
267      * @brief Register camera float window changed listener.
268      *
269      * @param listener ICameraFloatWindowChangedListener.
270      * @return WM_OK means register success, others means register failed.
271      */
272     WMError RegisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener);
273     /**
274      * @brief Unregister camera float window changed listener.
275      *
276      * @param listener ICameraFloatWindowChangedListener.
277      * @return WM_OK means unregister success, others means unregister failed.
278      */
279     WMError UnregisterCameraFloatWindowChangedListener(const sptr<ICameraFloatWindowChangedListener>& listener);
280     /**
281      * @brief Register water mark flag changed listener.
282      *
283      * @param listener IWaterMarkFlagChangedListener.
284      * @return WM_OK means register success, others means register failed.
285      */
286     WMError RegisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener);
287     /**
288      * @brief Unregister water mark flag changed listener.
289      *
290      * @param listener IWaterMarkFlagChangedListener.
291      * @return WM_OK means unregister success, others means unregister failed.
292      */
293     WMError UnregisterWaterMarkFlagChangedListener(const sptr<IWaterMarkFlagChangedListener>& listener);
294     /**
295      * @brief Register gesture navigation enabled changed listener.
296      *
297      * @param listener IGestureNavigationEnabledChangedListener.
298      * @return WM_OK means register success, others means register failed.
299      */
300     WMError RegisterGestureNavigationEnabledChangedListener(
301         const sptr<IGestureNavigationEnabledChangedListener>& listener);
302     /**
303      * @brief Unregister gesture navigation enabled changed listener.
304      *
305      * @param listener IGestureNavigationEnabledChangedListener.
306      * @return WM_OK means unregister success, others means unregister failed.
307      */
308     WMError UnregisterGestureNavigationEnabledChangedListener(
309         const sptr<IGestureNavigationEnabledChangedListener>& listener);
310     /**
311      * @brief Minimize all app window.
312      *
313      * @param displayId Display id.
314      * @return WM_OK means minimize success, others means minimize failed.
315      */
316     WMError MinimizeAllAppWindows(DisplayId displayId);
317     /**
318      * @brief Toggle all app windows to the foreground.
319      *
320      * @return WM_OK means toggle success, others means toggle failed.
321      */
322     WMError ToggleShownStateForAllAppWindows();
323     /**
324      * @brief Set window layout mode.
325      *
326      * @param mode Window layout mode.
327      * @return WM_OK means set success, others means set failed.
328      */
329     WMError SetWindowLayoutMode(WindowLayoutMode mode);
330     /**
331      * @brief Get accessibility window info.
332      *
333      * @param infos WindowInfos used for Accessibility.
334      * @return WM_OK means get success, others means get failed.
335      */
336     WMError GetAccessibilityWindowInfo(std::vector<sptr<AccessibilityWindowInfo>>& infos) const;
337     /**
338      * @brief Get visibility window info.
339      *
340      * @param infos Visible window infos
341      * @return WM_OK means get success, others means get failed.
342      */
343     WMError GetVisibilityWindowInfo(std::vector<sptr<WindowVisibilityInfo>>& infos) const;
344     /**
345      * @brief Set gesture navigaion enabled.
346      *
347      * @param enable True means set gesture on, false means set gesture off.
348      * @return WM_OK means set success, others means set failed.
349      */
350     WMError SetGestureNavigaionEnabled(bool enable) const;
351 
352     /**
353      * @brief Get focus window.
354      *
355      * @param focusInfo Focus window info.
356      * @return FocusChangeInfo object about focus window.
357      */
358     void GetFocusWindowInfo(FocusChangeInfo& focusInfo);
359 
360 private:
361     WindowManager();
362     ~WindowManager();
363     std::recursive_mutex mutex_;
364     class Impl;
365     std::unique_ptr<Impl> pImpl_;
366     bool destroyed_ = false;
367 
368     void UpdateFocusStatus(uint32_t windowId, const sptr<IRemoteObject>& abilityToken, WindowType windowType,
369         DisplayId displayId, bool focused) const;
370     void UpdateFocusChangeInfo(const sptr<FocusChangeInfo>& focusChangeInfo, bool focused) const;
371     void UpdateSystemBarRegionTints(DisplayId displayId, const SystemBarRegionTints& tints) const;
372     void NotifyAccessibilityWindowInfo(const std::vector<sptr<AccessibilityWindowInfo>>& infos,
373         WindowUpdateType type) const;
374     void UpdateWindowVisibilityInfo(
375         const std::vector<sptr<WindowVisibilityInfo>>& windowVisibilityInfos) const;
376     void UpdateCameraFloatWindowStatus(uint32_t accessTokenId, bool isShowing) const;
377     void NotifyWaterMarkFlagChangedResult(bool showWaterMark) const;
378     void NotifyGestureNavigationEnabledResult(bool enable) const;
379     void OnRemoteDied();
380 };
381 } // namespace Rosen
382 } // namespace OHOS
383 
384 #endif // OHOS_ROSEN_WINDOW_MANAGER_H
385