• 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_IMPL_H
17 #define OHOS_ROSEN_WINDOW_IMPL_H
18 
19 #include <map>
20 
21 #include <ability_context.h>
22 #include <i_input_event_consumer.h>
23 #include <key_event.h>
24 #include <refbase.h>
25 #include <string>
26 #include <ui_content.h>
27 #include <ui/rs_surface_node.h>
28 #include <struct_multimodal.h>
29 
30 #include "input_transfer_station.h"
31 #include "vsync_station.h"
32 #include "window.h"
33 #include "window_property.h"
34 #include "window_transition_info.h"
35 #include "wm_common_inner.h"
36 #include "wm_common.h"
37 
38 using OHOS::AppExecFwk::DisplayOrientation;
39 
40 namespace OHOS {
41 namespace Rosen {
42 union ColorParam {
43 #if BIG_ENDIANNESS
44     struct {
45         uint8_t alpha;
46         uint8_t red;
47         uint8_t green;
48         uint8_t blue;
49     } argb;
50 #else
51     struct {
52         uint8_t blue;
53         uint8_t green;
54         uint8_t red;
55         uint8_t alpha;
56     } argb;
57 #endif
58     uint32_t value;
59 };
60 
61 const std::map<DisplayOrientation, Orientation> ABILITY_TO_WMS_ORIENTATION_MAP {
62     {DisplayOrientation::UNSPECIFIED,                           Orientation::UNSPECIFIED                        },
63     {DisplayOrientation::LANDSCAPE,                             Orientation::HORIZONTAL                         },
64     {DisplayOrientation::PORTRAIT,                              Orientation::VERTICAL                           },
65     {DisplayOrientation::FOLLOWRECENT,                          Orientation::UNSPECIFIED                        },
66     {DisplayOrientation::LANDSCAPE_INVERTED,                    Orientation::REVERSE_HORIZONTAL                 },
67     {DisplayOrientation::PORTRAIT_INVERTED,                     Orientation::REVERSE_VERTICAL                   },
68     {DisplayOrientation::AUTO_ROTATION,                         Orientation::SENSOR                             },
69     {DisplayOrientation::AUTO_ROTATION_LANDSCAPE,               Orientation::SENSOR_HORIZONTAL                  },
70     {DisplayOrientation::AUTO_ROTATION_PORTRAIT,                Orientation::SENSOR_VERTICAL                    },
71     {DisplayOrientation::AUTO_ROTATION_RESTRICTED,              Orientation::AUTO_ROTATION_RESTRICTED           },
72     {DisplayOrientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED,    Orientation::AUTO_ROTATION_LANDSCAPE_RESTRICTED },
73     {DisplayOrientation::AUTO_ROTATION_PORTRAIT_RESTRICTED,     Orientation::AUTO_ROTATION_PORTRAIT_RESTRICTED  },
74     {DisplayOrientation::LOCKED,                                Orientation::LOCKED                             },
75 };
76 
77 class WindowImpl : public Window {
78 #define CALL_LIFECYCLE_LISTENER(windowLifecycleCb, listeners) \
79     do {                                                      \
80         for (auto& listener : (listeners)) {                  \
81             if (listener.GetRefPtr() != nullptr) {            \
82                 listener.GetRefPtr()->windowLifecycleCb();    \
83             }                                                 \
84         }                                                     \
85     } while (0)
86 
87 #define CALL_LIFECYCLE_LISTENER_WITH_PARAM(windowLifecycleCb, listeners, param) \
88     do {                                                                        \
89         for (auto& listener : (listeners)) {                                    \
90             if (listener.GetRefPtr() != nullptr) {                              \
91                 listener.GetRefPtr()->windowLifecycleCb(param);                 \
92             }                                                                   \
93         }                                                                       \
94     } while (0)
95 
96 #define CALL_UI_CONTENT(uiContentCb)                          \
97     do {                                                      \
98         if (uiContent_ != nullptr) {                          \
99             uiContent_->uiContentCb();                        \
100         }                                                     \
101     } while (0)
102 
103 public:
104     explicit WindowImpl(const sptr<WindowOption>& option);
105     ~WindowImpl();
106 
107     static sptr<Window> Find(const std::string& id);
108     static sptr<Window> GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
109     static sptr<Window> GetTopWindowWithId(uint32_t mainWinId);
110     static std::vector<sptr<Window>> GetSubWindow(uint32_t parantId);
111     static void UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration);
112     virtual std::shared_ptr<RSSurfaceNode> GetSurfaceNode() const override;
113     virtual Rect GetRect() const override;
114     virtual Rect GetRequestRect() const override;
115     virtual WindowType GetType() const override;
116     virtual WindowMode GetMode() const override;
117     virtual float GetAlpha() const override;
118     virtual WindowState GetWindowState() const override;
119     virtual WMError SetFocusable(bool isFocusable) override;
120     virtual bool GetFocusable() const override;
121     virtual WMError SetTouchable(bool isTouchable) override;
122     virtual bool GetTouchable() const override;
123     virtual const std::string& GetWindowName() const override;
124     virtual uint32_t GetWindowId() const override;
125     virtual uint32_t GetWindowFlags() const override;
126     uint32_t GetRequestModeSupportInfo() const override;
127     bool IsMainHandlerAvailable() const override;
GetNativeDestroyCallback()128     inline NotifyNativeWinDestroyFunc GetNativeDestroyCallback()
129     {
130         return notifyNativefunc_;
131     }
132     virtual SystemBarProperty GetSystemBarPropertyByType(WindowType type) const override;
133     virtual bool IsFullScreen() const override;
134     virtual bool IsLayoutFullScreen() const override;
135     virtual WMError SetWindowType(WindowType type) override;
136     virtual WMError SetWindowMode(WindowMode mode) override;
137     virtual void SetAlpha(float alpha) override;
138     virtual void SetTransform(const Transform& trans) override;
139     virtual WMError AddWindowFlag(WindowFlag flag) override;
140     virtual WMError RemoveWindowFlag(WindowFlag flag) override;
141     virtual WMError SetWindowFlags(uint32_t flags) override;
142     virtual WMError SetSystemBarProperty(WindowType type, const SystemBarProperty& property) override;
143     virtual WMError UpdateSystemBarProperty(bool status);
144     virtual WMError SetLayoutFullScreen(bool status) override;
145     virtual WMError SetFullScreen(bool status) override;
146     virtual const Transform& GetTransform() const override;
147     virtual const Transform& GetZoomTransform() const;
148     virtual WMError UpdateSurfaceNodeAfterCustomAnimation(bool isAdd) override;
SetWindowState(WindowState state)149     inline void SetWindowState(WindowState state)
150     {
151         state_ = state;
152     }
153     virtual WMError GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea) override;
154 
155     WMError Create(uint32_t parentId,
156         const std::shared_ptr<AbilityRuntime::Context>& context = nullptr);
157     virtual WMError Destroy() override;
158     virtual WMError Show(uint32_t reason = 0, bool withAnimation = false) override;
159     virtual WMError Hide(uint32_t reason = 0, bool withAnimation = false) override;
160     virtual WMError MoveTo(int32_t x, int32_t y) override;
161     virtual WMError Resize(uint32_t width, uint32_t height) override;
162     virtual WMError SetKeepScreenOn(bool keepScreenOn) override;
163     virtual bool IsKeepScreenOn() const override;
164     virtual WMError SetTurnScreenOn(bool turnScreenOn) override;
165     virtual bool IsTurnScreenOn() const override;
166     virtual WMError SetBackgroundColor(const std::string& color) override;
167     virtual WMError SetTransparent(bool isTransparent) override;
168     virtual bool IsTransparent() const override;
169     virtual WMError SetBrightness(float brightness) override;
170     virtual float GetBrightness() const override;
171     virtual WMError SetCallingWindow(uint32_t windowId) override;
172     virtual void SetPrivacyMode(bool isPrivacyMode) override;
173     virtual bool IsPrivacyMode() const override;
174     virtual void SetSystemPrivacyMode(bool isSystemPrivacyMode) override;
175     virtual void DisableAppWindowDecor() override;
176     virtual WMError BindDialogTarget(sptr<IRemoteObject> targetToken) override;
177     virtual void SetSnapshotSkip(bool isSkip) override;
178 
179     // window effect
180     virtual WMError SetCornerRadius(float cornerRadius) override;
181     virtual WMError SetShadowRadius(float radius) override;
182     virtual WMError SetShadowColor(std::string color) override;
183     virtual void SetShadowOffsetX(float offsetX) override;
184     virtual void SetShadowOffsetY(float offsetY) override;
185     virtual WMError SetBlur(float radius) override;
186     virtual WMError SetBackdropBlur(float radius) override;
187     virtual WMError SetBackdropBlurStyle(WindowBlurStyle blurStyle) override;
188 
189     virtual bool IsDecorEnable() const override;
190     virtual WMError Maximize() override;
191     virtual WMError Minimize() override;
192     virtual WMError Recover() override;
193     virtual WMError Close() override;
194     virtual void StartMove() override;
195 
196     virtual WMError RequestFocus() const override;
197     virtual void SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer) override;
198 
199     virtual bool RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override;
200     virtual bool RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override;
201     virtual bool UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener) override;
202     virtual bool UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener) override;
203     virtual bool RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override;
204     virtual bool UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener) override;
205     virtual bool RegisterDragListener(const sptr<IWindowDragListener>& listener) override;
206     virtual bool UnregisterDragListener(const sptr<IWindowDragListener>& listener) override;
207     virtual bool RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override;
208     virtual bool UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener) override;
209     virtual void RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func) override;
210     virtual bool RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
211     virtual bool UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener) override;
212     virtual bool RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override;
213     virtual bool UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener) override;
214     virtual bool RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener) override;
215     virtual bool RegisterScreenshotListener(const sptr<IScreenshotListener>& listener) override;
216     virtual bool UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener) override;
217     virtual bool RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override;
218     virtual bool UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener) override;
219     virtual void RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override;
220     virtual void UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener) override;
221     virtual void SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler) override;
222     virtual void SetRequestModeSupportInfo(uint32_t modeSupportInfo) override;
223     void UpdateRect(const struct Rect& rect, bool decoStatus, WindowSizeChangeReason reason);
224     void UpdateMode(WindowMode mode);
225     void UpdateModeSupportInfo(uint32_t modeSupportInfo);
226     virtual void ConsumeKeyEvent(std::shared_ptr<MMI::KeyEvent>& inputEvent) override;
227     virtual void ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& inputEvent) override;
228     virtual void RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback) override;
229     void UpdateFocusStatus(bool focused);
230     virtual bool IsFocused() const override;
231     virtual void UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration) override;
232     void UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type);
233     void UpdateWindowState(WindowState state);
234     sptr<WindowProperty> GetWindowProperty();
235     void UpdateDragEvent(const PointInfo& point, DragEvent event);
236     void UpdateDisplayId(DisplayId from, DisplayId to);
237     void UpdateOccupiedAreaChangeInfo(const sptr<OccupiedAreaChangeInfo>& info);
238     void UpdateActiveStatus(bool isActive);
239     void NotifyTouchOutside();
240     void NotifyScreenshot();
241     void NotifyTouchDialogTarget() override;
242     void NotifyDestroy();
243     void NotifyForeground();
244     void NotifyBackground();
245     void UpdateZoomTransform(const Transform& trans, bool isDisplayZoomOn);
246 
247     virtual WMError SetUIContent(const std::string& contentInfo, NativeEngine* engine,
248         NativeValue* storage, bool isdistributed, AppExecFwk::Ability* ability) override;
249     virtual std::string GetContentInfo() override;
250     virtual const std::shared_ptr<AbilityRuntime::Context> GetContext() const override;
251     virtual Ace::UIContent* GetUIContent() const override;
252     virtual void OnNewWant(const AAFwk::Want& want) override;
253     virtual void SetRequestedOrientation(Orientation) override;
254     virtual Orientation GetRequestedOrientation() override;
255     virtual void SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel) override;
256     virtual WMError SetTouchHotAreas(const std::vector<Rect>& rects) override;
257     virtual void GetRequestedTouchHotAreas(std::vector<Rect>& rects) const override;
258     virtual WMError SetAPPWindowLabel(const std::string& label) override;
259     virtual WMError SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon) override;
260 
261     // colorspace, gamut
262     virtual bool IsSupportWideGamut() override;
263     virtual void SetColorSpace(ColorSpace colorSpace) override;
264     virtual ColorSpace GetColorSpace() override;
265 
266     virtual void DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info) override;
267     virtual std::shared_ptr<Media::PixelMap> Snapshot() override;
268     virtual WMError NotifyMemoryLevel(int32_t level) const override;
269     virtual bool IsAllowHaveSystemSubWindow() override;
270     void RestoreSplitWindowMode(uint32_t mode);
271 private:
272     template<typename T1, typename T2, typename Ret>
273     using EnableIfSame = typename std::enable_if<std::is_same_v<T1, T2>, Ret>::type;
274     template<typename T> bool RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener);
275     template<typename T> bool UnregisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener);
ClearUselessListeners(std::map<uint32_t,T> & listeners,uint32_t winId)276     template<typename T> void ClearUselessListeners(std::map<uint32_t, T>& listeners, uint32_t winId)
277     {
278         listeners.erase(winId);
279     }
280     template<typename T>
GetListeners()281     inline EnableIfSame<T, IWindowLifeCycle, std::vector<wptr<IWindowLifeCycle>>> GetListeners()
282     {
283         std::vector<wptr<IWindowLifeCycle>> lifecycleListeners;
284         {
285             std::lock_guard<std::recursive_mutex> lock(globalMutex_);
286             for (auto& listener : lifecycleListeners_[GetWindowId()]) {
287                 lifecycleListeners.push_back(listener);
288             }
289         }
290         return lifecycleListeners;
291     }
292     template<typename T>
GetListeners()293     inline EnableIfSame<T, IWindowChangeListener, std::vector<wptr<IWindowChangeListener>>> GetListeners()
294     {
295         std::vector<wptr<IWindowChangeListener>> windowChangeListeners;
296         {
297             std::lock_guard<std::recursive_mutex> lock(globalMutex_);
298             for (auto& listener : windowChangeListeners_[GetWindowId()]) {
299                 windowChangeListeners.push_back(listener);
300             }
301         }
302         return windowChangeListeners;
303     }
304     template<typename T>
GetListeners()305     inline EnableIfSame<T, IAvoidAreaChangedListener, std::vector<wptr<IAvoidAreaChangedListener>>> GetListeners()
306     {
307         std::vector<wptr<IAvoidAreaChangedListener>> avoidAreaChangeListeners;
308         {
309             std::lock_guard<std::recursive_mutex> lock(globalMutex_);
310             for (auto& listener : avoidAreaChangeListeners_[GetWindowId()]) {
311                 avoidAreaChangeListeners.push_back(listener);
312             }
313         }
314         return avoidAreaChangeListeners;
315     }
316     template<typename T>
GetListeners()317     inline EnableIfSame<T, IDisplayMoveListener, std::vector<wptr<IDisplayMoveListener>>> GetListeners()
318     {
319         std::vector<wptr<IDisplayMoveListener>> displayMoveListeners;
320         {
321             std::lock_guard<std::recursive_mutex> lock(mutex_);
322             for (auto& listener : displayMoveListeners_) {
323                 displayMoveListeners.push_back(listener);
324             }
325         }
326         return displayMoveListeners;
327     }
328     template<typename T>
GetListeners()329     inline EnableIfSame<T, IScreenshotListener, std::vector<wptr<IScreenshotListener>>> GetListeners()
330     {
331         std::vector<wptr<IScreenshotListener>> screenshotListeners;
332         {
333             std::lock_guard<std::recursive_mutex> lock(globalMutex_);
334             for (auto& listener : screenshotListeners_[GetWindowId()]) {
335                 screenshotListeners.push_back(listener);
336             }
337         }
338         return screenshotListeners;
339     }
340     template<typename T>
GetListeners()341     inline EnableIfSame<T, ITouchOutsideListener, std::vector<wptr<ITouchOutsideListener>>> GetListeners()
342     {
343         std::vector<wptr<ITouchOutsideListener>> touchOutsideListeners;
344         {
345             std::lock_guard<std::recursive_mutex> lock(globalMutex_);
346             for (auto& listener : touchOutsideListeners_[GetWindowId()]) {
347                 touchOutsideListeners.push_back(listener);
348             }
349         }
350         return touchOutsideListeners;
351     }
352     template<typename T>
GetListeners()353     inline EnableIfSame<T, IDialogTargetTouchListener, std::vector<wptr<IDialogTargetTouchListener>>> GetListeners()
354     {
355         std::vector<wptr<IDialogTargetTouchListener>> dialogTargetTouchListeners;
356         {
357             std::lock_guard<std::recursive_mutex> lock(globalMutex_);
358             for (auto& listener : dialogTargetTouchListeners_[GetWindowId()]) {
359                 dialogTargetTouchListeners.push_back(listener);
360             }
361         }
362         return dialogTargetTouchListeners;
363     }
364     template<typename T>
GetListeners()365     inline EnableIfSame<T, IWindowDragListener, std::vector<wptr<IWindowDragListener>>> GetListeners()
366     {
367         std::vector<wptr<IWindowDragListener>> windowDragListeners;
368         {
369             std::lock_guard<std::recursive_mutex> lock(mutex_);
370             for (auto& listener : windowDragListeners_) {
371                 windowDragListeners.push_back(listener);
372             }
373         }
374         return windowDragListeners;
375     }
376     template<typename T>
GetListeners()377     inline EnableIfSame<T, IOccupiedAreaChangeListener, std::vector<wptr<IOccupiedAreaChangeListener>>> GetListeners()
378     {
379         std::vector<wptr<IOccupiedAreaChangeListener>> occupiedAreaChangeListeners;
380         {
381             std::lock_guard<std::recursive_mutex> lock(globalMutex_);
382             for (auto& listener : occupiedAreaChangeListeners_[GetWindowId()]) {
383                 occupiedAreaChangeListeners.push_back(listener);
384             }
385         }
386         return occupiedAreaChangeListeners;
387     }
388     template<typename T>
GetListener()389     inline EnableIfSame<T, IDialogDeathRecipientListener, wptr<IDialogDeathRecipientListener>> GetListener()
390     {
391         std::lock_guard<std::recursive_mutex> lock(globalMutex_);
392         return dialogDeathRecipientListener_[GetWindowId()];
393     }
394     inline void NotifyAfterForeground(bool needNotifyUiContent = true)
395     {
396         auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
397         CALL_LIFECYCLE_LISTENER(AfterForeground, lifecycleListeners);
398         if (needNotifyUiContent) {
399             CALL_UI_CONTENT(Foreground);
400         }
401     }
NotifyAfterBackground()402     inline void NotifyAfterBackground()
403     {
404         auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
405         CALL_LIFECYCLE_LISTENER(AfterBackground, lifecycleListeners);
406         CALL_UI_CONTENT(Background);
407     }
NotifyAfterFocused()408     inline void NotifyAfterFocused()
409     {
410         auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
411         CALL_LIFECYCLE_LISTENER(AfterFocused, lifecycleListeners);
412         CALL_UI_CONTENT(Focus);
413     }
414     inline void NotifyAfterUnfocused(bool needNotifyUiContent = true)
415     {
416         auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
417         // use needNotifyUinContent to separate ui content callbacks
418         CALL_LIFECYCLE_LISTENER(AfterUnfocused, lifecycleListeners);
419         if (needNotifyUiContent) {
420             CALL_UI_CONTENT(UnFocus);
421         }
422     }
NotifyBeforeDestroy(std::string windowName)423     inline void NotifyBeforeDestroy(std::string windowName)
424     {
425         std::lock_guard<std::recursive_mutex> lock(mutex_);
426         if (uiContent_ != nullptr) {
427             auto uiContent = std::move(uiContent_);
428             uiContent_ = nullptr;
429             uiContent->Destroy();
430         }
431         if (notifyNativefunc_) {
432             notifyNativefunc_(windowName);
433         }
434     }
NotifyBeforeSubWindowDestroy(sptr<WindowImpl> window)435     inline void NotifyBeforeSubWindowDestroy(sptr<WindowImpl> window)
436     {
437         auto uiContent = window->GetUIContent();
438         if (uiContent != nullptr) {
439             uiContent->Destroy();
440         }
441         if (window->GetNativeDestroyCallback()) {
442             window->GetNativeDestroyCallback()(window->GetWindowName());
443         }
444     }
NotifyAfterActive()445     inline void NotifyAfterActive()
446     {
447         auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
448         CALL_LIFECYCLE_LISTENER(AfterActive, lifecycleListeners);
449     }
NotifyAfterInactive()450     inline void NotifyAfterInactive()
451     {
452         auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
453         CALL_LIFECYCLE_LISTENER(AfterInactive, lifecycleListeners);
454     }
NotifyForegroundFailed(WMError ret)455     inline void NotifyForegroundFailed(WMError ret)
456     {
457         auto lifecycleListeners = GetListeners<IWindowLifeCycle>();
458         CALL_LIFECYCLE_LISTENER_WITH_PARAM(ForegroundFailed, lifecycleListeners, static_cast<int32_t>(ret));
459     }
IsStretchableReason(WindowSizeChangeReason reason)460     inline bool IsStretchableReason(WindowSizeChangeReason reason)
461     {
462         return reason == WindowSizeChangeReason::DRAG || reason == WindowSizeChangeReason::DRAG_END ||
463             reason == WindowSizeChangeReason::DRAG_START || reason == WindowSizeChangeReason::RECOVER ||
464             reason == WindowSizeChangeReason::MOVE || reason == WindowSizeChangeReason::UNDEFINED;
465     }
466     void ClearListenersById(uint32_t winId);
467     void NotifySizeChange(Rect rect, WindowSizeChangeReason reason);
468     void NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type);
469     void NotifyDisplayMoveChange(DisplayId from, DisplayId to);
470     void NotifyOccupiedAreaChange(const sptr<OccupiedAreaChangeInfo>& info);
471     void NotifyModeChange(WindowMode mode);
472     void NotifyDragEvent(const PointInfo& point, DragEvent event);
473     void DestroyDialogWindow();
474     void DestroyFloatingWindow();
475     void DestroySubWindow();
476     void SetDefaultOption(); // for api7
477     bool IsWindowValid() const;
478     static sptr<Window> FindTopWindow(uint32_t topWinId);
479     void TransferPointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
480     void ConsumeMoveOrDragEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
481     void ReadyToMoveOrDragWindow(const std::shared_ptr<MMI::PointerEvent>& pointerEvent,
482         const MMI::PointerEvent::PointerItem& pointerItem);
483     void EndMoveOrDragWindow(int32_t posX, int32_t posY, int32_t pointId, int32_t sourceType);
484     void ResetMoveOrDragState();
485     bool IsPointerEventConsumed();
486     bool IsPointInDragHotZone(int32_t startPointPosX, int32_t startPointPosY);
487     void AdjustWindowAnimationFlag(bool withAnimation = false);
488     void MapFloatingWindowToAppIfNeeded();
489     void MapDialogWindowToAppIfNeeded();
490     WMError UpdateProperty(PropertyChangeAction action);
491     WMError Destroy(bool needNotifyServer, bool needClearListener = true);
492     WMError SetBackgroundColor(uint32_t color);
493     uint32_t GetBackgroundColor() const;
494     void InitAbilityInfo();
495     std::shared_ptr<AppExecFwk::AbilityInfo> GetOriginalAbilityInfo() const;
496     void RecordLifeCycleExceptionEvent(LifeCycleEvent event, WMError errCode) const;
497     std::string TransferLifeCycleEventToString(LifeCycleEvent type) const;
498     Rect GetSystemAlarmWindowDefaultSize(Rect defaultRect);
499     void HandleModeChangeHotZones(int32_t posX, int32_t posY);
500     WMError NotifyWindowTransition(TransitionReason reason);
501     void UpdatePointerEventForStretchableWindow(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
502     void UpdateDragType(int32_t startPointPosX, int32_t startPointPosY);
503     void HandleBackKeyPressedEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent);
504     bool CheckCameraFloatingWindowMultiCreated(WindowType type);
505     void GetConfigurationFromAbilityInfo();
506     void UpdateTitleButtonVisibility();
507     void SetModeSupportInfo(uint32_t modeSupportInfo);
508     uint32_t GetModeSupportInfo() const;
509     WMError PreProcessShow(uint32_t reason, bool withAnimation);
510     bool NeedToStopShowing();
511     void CalculateStartRectExceptHotZone(float virtualPixelRatio);
512     void SetSystemConfig();
513     void TransformSurfaceNode(const Transform& trans);
514     bool IsAppMainOrSunOrFloatingWindow();
515     void SetWindowCornerRadiusAccordingToSystemConfig();
516     bool IsAppMainOrSubOrFloatingWindow();
517     void UpdateWindowShadowAccordingToSystemConfig();
518     bool WindowCreateCheck(uint32_t parentId);
519     uint32_t CalculatePointerDirection(int32_t pointerX, int32_t pointerY);
520     void HandlePointerStyle(const std::shared_ptr<MMI::PointerEvent>& pointerEvent);
521     RSSurfaceNode::SharedPtr CreateSurfaceNode(std::string name, WindowType type);
522     void UpdateWindowStateUnfrozen();
523     void UpdateViewportConfig(const Rect& rect, const sptr<class Display>& display, WindowSizeChangeReason reason);
524 
525     // colorspace, gamut
526     using ColorSpaceConvertMap = struct {
527         ColorSpace colorSpace;
528         ColorGamut surfaceColorGamut;
529     };
530     static const ColorSpaceConvertMap colorSpaceConvertMap[];
531     static ColorSpace GetColorSpaceFromSurfaceGamut(ColorGamut ColorGamut);
532     static ColorGamut GetSurfaceGamutFromColorSpace(ColorSpace colorSpace);
533 
534     static std::map<std::string, std::pair<uint32_t, sptr<Window>>> windowMap_;
535     static std::map<uint32_t, std::vector<sptr<WindowImpl>>> subWindowMap_;
536     static std::map<uint32_t, std::vector<sptr<WindowImpl>>> appFloatingWindowMap_;
537     static std::map<uint32_t, std::vector<sptr<WindowImpl>>> appDialogWindowMap_;
538     sptr<WindowProperty> property_;
539     WindowState state_ { WindowState::STATE_INITIAL };
540     WindowTag windowTag_;
541     sptr<IAceAbilityHandler> aceAbilityHandler_;
542     static std::map<uint32_t, std::vector<sptr<IScreenshotListener>>> screenshotListeners_;
543     static std::map<uint32_t, std::vector<sptr<ITouchOutsideListener>>> touchOutsideListeners_;
544     static std::map<uint32_t, std::vector<sptr<IDialogTargetTouchListener>>> dialogTargetTouchListeners_;
545     static std::map<uint32_t, std::vector<sptr<IWindowLifeCycle>>> lifecycleListeners_;
546     static std::map<uint32_t, std::vector<sptr<IWindowChangeListener>>> windowChangeListeners_;
547     static std::map<uint32_t, std::vector<sptr<IAvoidAreaChangedListener>>> avoidAreaChangeListeners_;
548     std::vector<sptr<IWindowDragListener>> windowDragListeners_;
549     std::vector<sptr<IDisplayMoveListener>> displayMoveListeners_;
550     static std::map<uint32_t, std::vector<sptr<IOccupiedAreaChangeListener>>> occupiedAreaChangeListeners_;
551     static std::map<uint32_t, sptr<IDialogDeathRecipientListener>> dialogDeathRecipientListener_;
552     std::shared_ptr<IInputEventConsumer> inputEventConsumer_;
553     sptr<IAnimationTransitionController> animationTransitionController_;
554     NotifyNativeWinDestroyFunc notifyNativefunc_;
555     std::shared_ptr<RSSurfaceNode> surfaceNode_;
556     std::string name_;
557     std::unique_ptr<Ace::UIContent> uiContent_;
558     std::shared_ptr<AbilityRuntime::Context> context_;
559     std::recursive_mutex mutex_;
560     static std::recursive_mutex globalMutex_;
561     const float SYSTEM_ALARM_WINDOW_WIDTH_RATIO = 0.8;
562     const float SYSTEM_ALARM_WINDOW_HEIGHT_RATIO = 0.3;
563     WindowSizeChangeReason lastSizeChangeReason_ = WindowSizeChangeReason::END;
564 
565     sptr<MoveDragProperty> moveDragProperty_;
566     bool isAppDecorEnable_ = true;
567     SystemConfig windowSystemConfig_ ;
568     bool isOriginRectSet_ = false;
569     bool needRemoveWindowInputChannel_ = false;
570     bool isMainHandlerAvailable_ = true;
571     bool isAppFloatingWindow_ = false;
572     bool isFocused_ = false;
573     uint32_t mouseStyleID_ = 0;
574     bool isPointerStyleChanged_ = false;
575     const std::map<DragType, uint32_t> STYLEID_MAP = {
576         {DragType::DRAG_UNDEFINED, MMI::MOUSE_ICON::DEFAULT},
577         {DragType::DRAG_BOTTOM_OR_TOP, MMI::MOUSE_ICON::NORTH_SOUTH},
578         {DragType::DRAG_LEFT_OR_RIGHT, MMI::MOUSE_ICON::WEST_EAST},
579         {DragType::DRAG_LEFT_TOP_CORNER, MMI::MOUSE_ICON::NORTH_WEST_SOUTH_EAST},
580         {DragType::DRAG_RIGHT_TOP_CORNER, MMI::MOUSE_ICON::NORTH_EAST_SOUTH_WEST}
581     };
582 };
583 } // namespace Rosen
584 } // namespace OHOS
585 #endif // OHOS_ROSEN_WINDOW_IMPL_H
586