1/*
2 * Copyright (c) 2022-2024 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#include "window_impl.h"
17
18#include "dm_common.h"
19#include "window_manager_hilog.h"
20#include "window_helper.h"
21#include "window_option.h"
22#include "viewport_config.h"
23#include "singleton_container.h"
24
25namespace OHOS {
26namespace Rosen {
27namespace {
28constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_WINDOW, "WindowImpl"};
29}
30std::map<std::string, std::pair<uint32_t, sptr<Window>>> WindowImpl::windowMap_;
31std::map<uint32_t, std::vector<sptr<WindowImpl>>> WindowImpl::subWindowMap_;
32std::map<uint32_t, std::vector<sptr<IWindowSystemBarEnableListener>>> WindowImpl::systemBarEnableListeners_;
33std::map<uint32_t, std::vector<sptr<IIgnoreViewSafeAreaListener>>> WindowImpl::ignoreSafeAreaListeners_;
34std::map<uint32_t, std::vector<sptr<IAvoidAreaChangedListener>>> WindowImpl::avoidAreaChangeListeners_;
35std::mutex WindowImpl::globalMutex_;
36static int constructorCnt = 0;
37static int deConstructorCnt = 0;
38WindowImpl::WindowImpl(const sptr<WindowOption>& option)
39{
40    if (option != nullptr) {
41        name_ = option->GetWindowName();
42    } else {
43        name_ = "main_window";
44    }
45    WLOGFI("WindowImpl constructorCnt: %{public}d",
46        ++constructorCnt);
47}
48
49WindowImpl::~WindowImpl()
50{
51    WLOGFI("windowName: %{public}s, windowId: %{public}d, deConstructorCnt: %{public}d",
52        GetWindowName().c_str(), GetWindowId(), ++deConstructorCnt);
53    Destroy();
54}
55
56void WindowImpl::CreateSurfaceNode(const std::string name, const SendRenderDataCallback& callback)
57{
58    WLOGFI("CreateSurfaceNode");
59    struct RSSurfaceNodeConfig rsSurfaceNodeConfig;
60    rsSurfaceNodeConfig.SurfaceNodeName = name;
61    rsSurfaceNodeConfig.additionalData = reinterpret_cast<void*>(callback);
62    surfaceNode_ = RSSurfaceNode::Create(rsSurfaceNodeConfig);
63    if (surfaceNode_ != nullptr) {
64        vsyncStation_ = std::make_shared<VsyncStation>(surfaceNode_->GetId());
65    }
66}
67
68void WindowImpl::SetContentInfoCallback(const ContentInfoCallback& callback)
69{
70    contentInfoCallback_ = callback;
71}
72
73sptr<Window> WindowImpl::Find(const std::string& name)
74{
75    return nullptr;
76}
77
78const std::shared_ptr<AbilityRuntime::Context> WindowImpl::GetContext() const
79{
80    return nullptr;
81}
82
83sptr<Window> WindowImpl::FindWindowById(uint32_t windowId)
84{
85    std::lock_guard<std::mutex> lock(globalMutex_);
86    if (windowMap_.empty()) {
87        WLOGFE("Please create mainWindow First!");
88        return nullptr;
89    }
90    for (auto iter = windowMap_.begin(); iter != windowMap_.end(); iter++) {
91        if (windowId == iter->second.first) {
92            WLOGI("FindWindow id: %{public}u", windowId);
93            return iter->second.second;
94        }
95    }
96    WLOGFE("Cannot find Window!");
97    return nullptr;
98}
99
100sptr<Window> WindowImpl::GetTopWindowWithId(uint32_t mainWinId)
101{
102    return FindWindowById(mainWinId);
103}
104
105sptr<Window> WindowImpl::GetTopWindowWithContext(const std::shared_ptr<AbilityRuntime::Context>& context)
106{
107    return nullptr;
108}
109
110std::vector<sptr<Window>> WindowImpl::GetSubWindow(uint32_t parentId)
111{
112    return std::vector<sptr<Window>>();
113}
114
115void WindowImpl::UpdateConfigurationForAll(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
116{
117    std::lock_guard<std::mutex> lock(globalMutex_);
118    for (const auto& winPair : windowMap_) {
119        auto window = winPair.second.second;
120        window->UpdateConfiguration(configuration);
121    }
122}
123
124std::shared_ptr<RSSurfaceNode> WindowImpl::GetSurfaceNode() const
125{
126    return surfaceNode_;
127}
128
129Rect WindowImpl::GetRect() const
130{
131    return Rect{0, 0, 0, 0};
132}
133
134Rect WindowImpl::GetRequestRect() const
135{
136    return Rect{0, 0, 0, 0};
137}
138
139WindowType WindowImpl::GetType() const
140{
141    return WindowType::WINDOW_TYPE_APP_MAIN_WINDOW;
142}
143
144WindowMode WindowImpl::GetMode() const
145{
146    return windowMode_;
147}
148
149float WindowImpl::GetAlpha() const
150{
151    return 0.0;
152}
153
154WindowState WindowImpl::GetWindowState() const
155{
156    return state_;
157}
158
159WMError WindowImpl::SetFocusable(bool isFocusable)
160{
161    return WMError::WM_OK;
162}
163
164bool WindowImpl::GetFocusable() const
165{
166    return false;
167}
168
169WMError WindowImpl::SetTouchable(bool isTouchable)
170{
171    return WMError::WM_OK;
172}
173
174bool WindowImpl::GetTouchable() const
175{
176    return false;
177}
178
179const std::string& WindowImpl::GetWindowName() const
180{
181    return name_;
182}
183
184uint32_t WindowImpl::GetWindowId() const
185{
186    return windowId_;
187}
188
189uint64_t WindowImpl::GetDisplayId() const
190{
191    return DISPLAY_ID_INVALID;
192}
193
194uint32_t WindowImpl::GetWindowFlags() const
195{
196    return 0;
197}
198
199uint32_t WindowImpl::GetRequestModeSupportInfo() const
200{
201    return 0;
202}
203
204bool WindowImpl::IsMainHandlerAvailable() const
205{
206    return true;
207}
208
209SystemBarProperty WindowImpl::GetSystemBarPropertyByType(WindowType type) const
210{
211    std::lock_guard<std::mutex> lock(mutex_);
212    auto it = sysBarPropMap_.find(type);
213    if (it == sysBarPropMap_.end()) {
214        return SystemBarProperty(false, 0x0, 0x0);
215    }
216    return it->second;
217}
218
219WMError WindowImpl::GetAvoidAreaByType(AvoidAreaType type, AvoidArea& avoidArea)
220{
221    std::lock_guard<std::mutex> lock(mutex_);
222    auto avoidAreaPtr = avoidAreaMap_[type];
223    if (avoidAreaPtr == nullptr) {
224        return WMError::WM_OK;
225    }
226
227    avoidArea = *avoidAreaPtr;
228    return WMError::WM_OK;
229}
230
231WMError WindowImpl::SetWindowType(WindowType type)
232{
233    return WMError::WM_OK;
234}
235
236WMError WindowImpl::SetWindowMode(WindowMode mode)
237{
238    windowMode_ = mode;
239    return WMError::WM_OK;
240}
241
242WMError WindowImpl::SetAlpha(float alpha)
243{
244    return WMError::WM_OK;
245}
246
247WMError WindowImpl::SetTransform(const Transform& trans)
248{
249    return WMError::WM_OK;
250}
251
252const Transform& WindowImpl::GetTransform() const
253{
254    return transform_;
255}
256
257WMError WindowImpl::AddWindowFlag(WindowFlag flag)
258{
259    return WMError::WM_OK;
260}
261
262WMError WindowImpl::RemoveWindowFlag(WindowFlag flag)
263{
264    return WMError::WM_OK;
265}
266
267WMError WindowImpl::SetWindowFlags(uint32_t flags)
268{
269    return WMError::WM_OK;
270}
271
272void WindowImpl::OnNewWant(const AAFwk::Want& want)
273{
274    return;
275}
276
277WMError WindowImpl::NapiSetUIContent(const std::string& contentInfo, napi_env env, napi_value storage,
278    BackupAndRestoreType type, sptr<IRemoteObject> token, AppExecFwk::Ability* ability)
279{
280    WLOGFD("NapiSetUIContent: %{public}s", contentInfo.c_str());
281    if (uiContent_) {
282        uiContent_->Destroy();
283    }
284    std::unique_ptr<Ace::UIContent> uiContent;
285    if (ability != nullptr) {
286        uiContent = Ace::UIContent::Create(ability);
287    } else {
288        uiContent = Ace::UIContent::Create(context_.get(), reinterpret_cast<NativeEngine*>(env));
289    }
290    if (uiContent == nullptr) {
291        WLOGFE("fail to NapiSetUIContent");
292        return WMError::WM_ERROR_NULLPTR;
293    }
294    if (type != BackupAndRestoreType::NONE) {
295        uiContent->Restore(this, contentInfo, storage, type == BackupAndRestoreType::CONTINUATION ?
296            Ace::ContentInfoType::CONTINUATION : Ace::ContentInfoType::APP_RECOVERY);
297    } else {
298        uiContent->Initialize(this, contentInfo, storage);
299    }
300    uiContent_ = std::move(uiContent);
301    if (uiContent_ == nullptr) {
302        WLOGFE("uiContent_ is NULL");
303        return WMError::WM_ERROR_NULLPTR;
304    }
305    NotifySetIgnoreSafeArea(isIgnoreSafeArea_);
306    UpdateViewportConfig();
307    if (contentInfoCallback_) {
308        contentInfoCallback_(contentInfo);
309    }
310    return WMError::WM_OK;
311}
312
313
314Ace::UIContent* WindowImpl::GetUIContent() const
315{
316    WLOGFD("WindowImpl::GetUIContent");
317    return uiContent_.get();
318}
319
320std::string WindowImpl::GetContentInfo(BackupAndRestoreType type)
321{
322    return "";
323}
324
325bool WindowImpl::IsSupportWideGamut()
326{
327    return true;
328}
329
330void WindowImpl::SetColorSpace(ColorSpace colorSpace)
331{
332    return;
333}
334
335ColorSpace WindowImpl::GetColorSpace()
336{
337    return ColorSpace::COLOR_SPACE_DEFAULT;
338}
339
340std::shared_ptr<Media::PixelMap> WindowImpl::Snapshot()
341{
342    return nullptr;
343}
344
345void WindowImpl::DumpInfo(const std::vector<std::string>& params, std::vector<std::string>& info)
346{
347    return;
348}
349
350WMError WindowImpl::SetSystemBarProperty(WindowType type, const SystemBarProperty& property)
351{
352    return SetSpecificBarProperty(type, property);
353}
354
355WMError WindowImpl::SetSpecificBarProperty(WindowType type, const SystemBarProperty& property)
356{
357    WLOGI("Window %{public}u type %{public}u enable:%{public}u, bgColor:%{public}x, Color:%{public}x",
358        GetWindowId(), static_cast<uint32_t>(type), property.enable_,
359        property.backgroundColor_, property.contentColor_);
360
361    if (GetSystemBarPropertyByType(type) == property) {
362        return WMError::WM_OK;
363    }
364    {
365        std::lock_guard<std::mutex> lock(mutex_);
366        sysBarPropMap_[type] = property;
367    }
368    NotifySystemBarChange(type, property);
369    UpdateViewportConfig();
370    return WMError::WM_OK;
371}
372
373WMError WindowImpl::UpdateSystemBarProperty(bool status)
374{
375    bool enable = !status;
376    SystemBarProperty statusProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
377    if (statusProperty.enable_ != enable) {
378        statusProperty.enable_ = enable;
379        SetSystemBarProperty(WindowType::WINDOW_TYPE_STATUS_BAR, statusProperty);
380    }
381
382    SystemBarProperty naviProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
383    if (naviProperty.enable_ != enable) {
384        naviProperty.enable_ = enable;
385        SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_BAR, naviProperty);
386    }
387
388    SystemBarProperty naviIndicatorProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR);
389    if (naviIndicatorProperty.enable_ != enable) {
390        naviIndicatorProperty.enable_ = enable;
391        SetSystemBarProperty(WindowType::WINDOW_TYPE_NAVIGATION_INDICATOR, naviIndicatorProperty);
392    }
393
394    return WMError::WM_OK;
395}
396
397WMError WindowImpl::SetSystemBarProperties(const std::map<WindowType, SystemBarProperty>& properties,
398    const std::map<WindowType, SystemBarPropertyFlag>& propertyFlags)
399{
400    return WMError::WM_OK;
401}
402
403WMError WindowImpl::GetSystemBarProperties(std::map<WindowType, SystemBarProperty>& properties)
404{
405    return WMError::WM_OK;
406}
407
408WMError WindowImpl::SetLayoutFullScreen(bool status)
409{
410    isIgnoreSafeArea_ = status;
411    NotifySetIgnoreSafeArea(status);
412    UpdateViewportConfig();
413    return WMError::WM_OK;
414}
415
416WMError WindowImpl::SetFullScreen(bool status)
417{
418    WLOGI("status: %{public}d", status);
419    WMError ret = UpdateSystemBarProperty(status);
420    if (ret != WMError::WM_OK) {
421        WLOGFE("UpdateSystemBarProperty errCode:%{public}d", static_cast<int32_t>(ret));
422    }
423    ret = SetLayoutFullScreen(status);
424    if (ret != WMError::WM_OK) {
425        WLOGFE("SetLayoutFullScreen errCode:%{public}d", static_cast<int32_t>(ret));
426    }
427    return WMError::WM_OK;
428}
429
430WMError WindowImpl::Create(uint32_t parentId, const std::shared_ptr<AbilityRuntime::Context>& context)
431{
432    WLOGFI("[Client] Window [name:%{public}s] Create", name_.c_str());
433    context_ = context;
434    sptr<Window> self(this);
435    static std::atomic<uint32_t> tempWindowId = 0;
436    uint32_t windowId = tempWindowId++; // for test
437    windowId_ = windowId;
438    std::lock_guard<std::mutex> lock(globalMutex_);
439    windowMap_.insert(std::make_pair(name_, std::pair<uint32_t, sptr<Window>>(windowId, self)));
440    return WMError::WM_OK;
441}
442
443WMError WindowImpl::BindDialogTarget(sptr<IRemoteObject> targetToken)
444{
445    return WMError::WM_OK;
446}
447
448WMError WindowImpl::SetDialogBackGestureEnabled(bool isEnabled)
449{
450    return WMError::WM_OK;
451}
452
453WMError WindowImpl::Destroy()
454{
455    if (uiContent_) {
456        uiContent_->Destroy();
457    }
458    std::lock_guard<std::mutex> lock(globalMutex_);
459    windowMap_.erase(GetWindowName());
460    return WMError::WM_OK;
461}
462
463WMError WindowImpl::UpdateSurfaceNodeAfterCustomAnimation(bool isAdd)
464{
465    return WMError::WM_OK;
466}
467
468WMError WindowImpl::Show(uint32_t reason, bool withAnimation, bool withFocus)
469{
470    return WMError::WM_OK;
471}
472
473WMError WindowImpl::Hide(uint32_t reason, bool withAnimation, bool isFromInnerkits)
474{
475    return WMError::WM_OK;
476}
477
478WMError WindowImpl::MoveTo(int32_t x, int32_t y, bool isMoveToGlobal)
479{
480    return WMError::WM_OK;
481}
482
483WMError WindowImpl::Resize(uint32_t width, uint32_t height)
484{
485    return WMError::WM_OK;
486}
487
488WMError WindowImpl::SetWindowGravity(WindowGravity gravity, uint32_t percent)
489{
490    return WMError::WM_OK;
491}
492
493WMError WindowImpl::SetKeepScreenOn(bool keepScreenOn)
494{
495    return WMError::WM_OK;
496}
497
498bool WindowImpl::IsKeepScreenOn() const
499{
500    return false;
501}
502
503WMError WindowImpl::SetTurnScreenOn(bool turnScreenOn)
504{
505    return WMError::WM_OK;
506}
507
508bool WindowImpl::IsTurnScreenOn() const
509{
510    return false;
511}
512
513WMError WindowImpl::SetBackgroundColor(const std::string& color)
514{
515    return WMError::WM_OK;
516}
517
518WMError WindowImpl::SetTransparent(bool isTransparent)
519{
520    return WMError::WM_OK;
521}
522
523bool WindowImpl::IsTransparent() const
524{
525    return true;
526}
527
528WMError WindowImpl::SetBrightness(float brightness)
529{
530    return WMError::WM_OK;
531}
532
533float WindowImpl::GetBrightness() const
534{
535    return 0.0;
536}
537
538WMError WindowImpl::SetCallingWindow(uint32_t windowId)
539{
540    return WMError::WM_OK;
541}
542
543WMError WindowImpl::SetPrivacyMode(bool isPrivacyMode)
544{
545    return WMError::WM_OK;
546}
547
548bool WindowImpl::IsPrivacyMode() const
549{
550    return false;
551}
552
553void WindowImpl::SetSystemPrivacyMode(bool isSystemPrivacyMode)
554{
555}
556
557WMError WindowImpl::SetSnapshotSkip(bool isSkip)
558{
559    return WMError::WM_OK;
560}
561
562WMError WindowImpl::DisableAppWindowDecor()
563{
564    return WMError::WM_OK;
565}
566
567WMError WindowImpl::Maximize()
568{
569    return WMError::WM_OK;
570}
571
572WMError WindowImpl::Minimize()
573{
574    return WMError::WM_OK;
575}
576
577WMError WindowImpl::Recover()
578{
579    return WMError::WM_OK;
580}
581
582WMError WindowImpl::Close()
583{
584    return WMError::WM_OK;
585}
586
587void WindowImpl::StartMove()
588{
589    return;
590}
591
592WMError WindowImpl::RequestFocus() const
593{
594    return WMError::WM_OK;
595}
596
597bool WindowImpl::IsFocused() const
598{
599    return true;
600}
601
602void WindowImpl::SetInputEventConsumer(const std::shared_ptr<IInputEventConsumer>& inputEventConsumer)
603{
604    return;
605}
606
607WMError WindowImpl::RegisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener)
608{
609    return WMError::WM_OK;
610}
611
612WMError WindowImpl::RegisterWindowChangeListener(const sptr<IWindowChangeListener>& listener)
613{
614    return WMError::WM_OK;
615}
616
617WMError WindowImpl::UnregisterLifeCycleListener(const sptr<IWindowLifeCycle>& listener)
618{
619    return WMError::WM_OK;
620}
621
622WMError WindowImpl::UnregisterWindowChangeListener(const sptr<IWindowChangeListener>& listener)
623{
624    return WMError::WM_OK;
625}
626
627WMError WindowImpl::RegisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener)
628{
629    WLOGFD("Start register");
630    std::lock_guard<std::mutex> lock(globalMutex_);
631    WMError ret = RegisterListener(avoidAreaChangeListeners_[GetWindowId()], listener);
632    return ret;
633}
634
635WMError WindowImpl::UnregisterAvoidAreaChangeListener(sptr<IAvoidAreaChangedListener>& listener)
636{
637    WLOGFD("Start unregister");
638    std::lock_guard<std::mutex> lock(globalMutex_);
639    WMError ret = UnregisterListener(avoidAreaChangeListeners_[GetWindowId()], listener);
640    return ret;
641}
642
643WMError WindowImpl::RegisterDragListener(const sptr<IWindowDragListener>& listener)
644{
645    return WMError::WM_OK;
646}
647
648WMError WindowImpl::UnregisterDragListener(const sptr<IWindowDragListener>& listener)
649{
650    return WMError::WM_OK;
651}
652
653WMError WindowImpl::RegisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener)
654{
655    return WMError::WM_OK;
656}
657
658WMError WindowImpl::UnregisterDisplayMoveListener(sptr<IDisplayMoveListener>& listener)
659{
660    return WMError::WM_OK;
661}
662
663void WindowImpl::RegisterWindowDestroyedListener(const NotifyNativeWinDestroyFunc& func)
664{
665    return;
666}
667
668WMError WindowImpl::RegisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener)
669{
670    return WMError::WM_OK;
671}
672
673WMError WindowImpl::UnregisterOccupiedAreaChangeListener(const sptr<IOccupiedAreaChangeListener>& listener)
674{
675    return WMError::WM_OK;
676}
677
678WMError WindowImpl::RegisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener)
679{
680    return WMError::WM_OK;
681}
682
683WMError WindowImpl::UnregisterTouchOutsideListener(const sptr<ITouchOutsideListener>& listener)
684{
685    return WMError::WM_OK;
686}
687
688WMError WindowImpl::RegisterAnimationTransitionController(const sptr<IAnimationTransitionController>& listener)
689{
690    return WMError::WM_OK;
691}
692
693WMError WindowImpl::RegisterScreenshotListener(const sptr<IScreenshotListener>& listener)
694{
695    return WMError::WM_OK;
696}
697
698WMError WindowImpl::UnregisterScreenshotListener(const sptr<IScreenshotListener>& listener)
699{
700    return WMError::WM_OK;
701}
702
703WMError WindowImpl::RegisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener)
704{
705    return WMError::WM_OK;
706}
707
708WMError WindowImpl::UnregisterDialogTargetTouchListener(const sptr<IDialogTargetTouchListener>& listener)
709{
710    return WMError::WM_OK;
711}
712
713void WindowImpl::RegisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener)
714{
715    return;
716}
717
718void WindowImpl::UnregisterDialogDeathRecipientListener(const sptr<IDialogDeathRecipientListener>& listener)
719{
720    return;
721}
722
723WMError WindowImpl::RegisterSystemBarEnableListener(const sptr<IWindowSystemBarEnableListener>& listener)
724{
725    WLOGFI("Register");
726    std::lock_guard<std::mutex> lock(globalMutex_);
727    WMError ret = RegisterListener(systemBarEnableListeners_[GetWindowId()], listener);
728    return ret;
729}
730
731WMError WindowImpl::UnRegisterSystemBarEnableListener(const sptr<IWindowSystemBarEnableListener>& listener)
732{
733    WLOGFI("UnRegister");
734    std::lock_guard<std::mutex> lock(globalMutex_);
735    WMError ret = UnregisterListener(systemBarEnableListeners_[GetWindowId()], listener);
736    return ret;
737}
738
739WMError WindowImpl::RegisterIgnoreViewSafeAreaListener(const sptr<IIgnoreViewSafeAreaListener>& listener)
740{
741    WLOGFI("Register");
742    std::lock_guard<std::mutex> lock(globalMutex_);
743    WMError ret = RegisterListener(ignoreSafeAreaListeners_[GetWindowId()], listener);
744    return ret;
745}
746
747WMError WindowImpl::UnRegisterIgnoreViewSafeAreaListener(const sptr<IIgnoreViewSafeAreaListener>& listener)
748{
749    WLOGFI("UnRegister");
750    std::lock_guard<std::mutex> lock(globalMutex_);
751    WMError ret = UnregisterListener(ignoreSafeAreaListeners_[GetWindowId()], listener);
752    return ret;
753}
754
755template<typename T>
756WMError WindowImpl::RegisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener)
757{
758    if (listener == nullptr) {
759        WLOGFE("listener is nullptr");
760        return WMError::WM_ERROR_NULLPTR;
761    }
762    if (std::find(holder.begin(), holder.end(), listener) != holder.end()) {
763        WLOGFE("Listener already registered");
764        return WMError::WM_OK;
765    }
766    holder.emplace_back(listener);
767    return WMError::WM_OK;
768}
769
770template<typename T>
771WMError WindowImpl::UnregisterListener(std::vector<sptr<T>>& holder, const sptr<T>& listener)
772{
773    if (listener == nullptr) {
774        WLOGFE("listener could not be null");
775        return WMError::WM_ERROR_NULLPTR;
776    }
777    holder.erase(std::remove_if(holder.begin(), holder.end(),
778        [listener](sptr<T> registeredListener) {
779            return registeredListener == listener;
780        }), holder.end());
781    return WMError::WM_OK;
782}
783
784void WindowImpl::SetAceAbilityHandler(const sptr<IAceAbilityHandler>& handler)
785{
786    return;
787}
788
789void WindowImpl::SetRequestModeSupportInfo(uint32_t modeSupportInfo)
790{
791    return;
792}
793
794void WindowImpl::ConsumeKeyEvent(const std::shared_ptr<MMI::KeyEvent>& keyEvent)
795{
796    if (uiContent_ == nullptr) {
797        WLOGFE("ConsumeKeyEvent to uiContent failed,uiContent_ is null");
798        return;
799    }
800    uiContent_->ProcessKeyEvent(keyEvent);
801}
802
803void WindowImpl::ConsumePointerEvent(const std::shared_ptr<MMI::PointerEvent>& pointerEvent)
804{
805    if (uiContent_ == nullptr) {
806        WLOGFE("ConsumePointerEvent to uiContent failed,uiContent_ is null");
807        return;
808    }
809    (void)uiContent_->ProcessPointerEvent(pointerEvent);
810}
811
812
813void WindowImpl::RequestVsync(const std::shared_ptr<VsyncCallback>& vsyncCallback)
814{
815    if (vsyncStation_ == nullptr) {
816        TLOGE(WmsLogTag::WMS_MAIN, "failed, vsyncStation is null");
817        return;
818    }
819    vsyncStation_->RequestVsync(vsyncCallback);
820}
821
822int64_t WindowImpl::GetVSyncPeriod()
823{
824    return 0;
825}
826
827void WindowImpl::UpdateConfiguration(const std::shared_ptr<AppExecFwk::Configuration>& configuration)
828{
829    if (uiContent_ != nullptr) {
830        WLOGFD("notify ace winId:%{public}u", GetWindowId());
831        uiContent_->UpdateConfiguration(configuration);
832    }
833}
834
835void WindowImpl::UpdateAvoidArea(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
836{
837    if (!avoidArea) {
838        WLOGFE("invalid avoidArea");
839        return;
840    }
841
842    WLOGFI("type:%{public}d, top:{%{public}d,%{public}d,%{public}d,%{public}d}, "
843        "left:{%{public}d,%{public}d,%{public}d,%{public}d}, right:{%{public}d,%{public}d,%{public}d,%{public}d}, "
844        "bottom:{%{public}d,%{public}d,%{public}d,%{public}d}",
845        type, avoidArea->topRect_.posX_, avoidArea->topRect_.posY_, avoidArea->topRect_.width_,
846        avoidArea->topRect_.height_, avoidArea->leftRect_.posX_, avoidArea->leftRect_.posY_,
847        avoidArea->leftRect_.width_, avoidArea->leftRect_.height_, avoidArea->rightRect_.posX_,
848        avoidArea->rightRect_.posY_, avoidArea->rightRect_.width_, avoidArea->rightRect_.height_,
849        avoidArea->bottomRect_.posX_, avoidArea->bottomRect_.posY_, avoidArea->bottomRect_.width_,
850        avoidArea->bottomRect_.height_);
851
852    {
853        std::lock_guard<std::mutex> lock(mutex_);
854        avoidAreaMap_[type] = avoidArea;
855    }
856    NotifyAvoidAreaChange(avoidArea, type);
857}
858
859void WindowImpl::NotifySystemBarChange(WindowType type, const SystemBarProperty& property)
860{
861    auto systemBarEnableListeners = GetListeners<IWindowSystemBarEnableListener>();
862    for (auto& listener : systemBarEnableListeners) {
863        if (listener != nullptr) {
864            WLOGFD("type = %{public}u", type);
865            listener->OnSetSpecificBarProperty(type, property);
866        }
867    }
868}
869
870void WindowImpl::NotifySetIgnoreSafeArea(bool value)
871{
872    auto ignoreSafeAreaListeners = GetListeners<IIgnoreViewSafeAreaListener>();
873    for (auto& listener : ignoreSafeAreaListeners) {
874        if (listener != nullptr) {
875            WLOGFD("value = %{public}d", value);
876            listener->SetIgnoreViewSafeArea(value);
877        }
878    }
879}
880
881void WindowImpl::NotifyAvoidAreaChange(const sptr<AvoidArea>& avoidArea, AvoidAreaType type)
882{
883    auto avoidAreaChangeListeners = GetListeners<IAvoidAreaChangedListener>();
884    for (auto& listener : avoidAreaChangeListeners) {
885        if (listener != nullptr) {
886            WLOGFD("type = %{public}u", type);
887            listener->OnAvoidAreaChanged(*avoidArea, type);
888        }
889    }
890}
891
892void WindowImpl::NotifyTouchDialogTarget(int32_t posX, int32_t posY)
893{
894    return;
895}
896
897void WindowImpl::SetNeedRemoveWindowInputChannel(bool needRemoveWindowInputChannel)
898{
899    needRemoveWindowInputChannel_ = needRemoveWindowInputChannel;
900}
901
902bool WindowImpl::IsLayoutFullScreen() const
903{
904    return isIgnoreSafeArea_;
905}
906
907bool WindowImpl::IsFullScreen() const
908{
909    auto statusProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
910    auto naviProperty = GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
911    return (IsLayoutFullScreen() && !statusProperty.enable_ && !naviProperty.enable_);
912}
913
914void WindowImpl::SetRequestedOrientation(Orientation orientation)
915{
916}
917
918Orientation WindowImpl::GetRequestedOrientation()
919{
920    return Orientation::UNSPECIFIED;
921}
922
923WMError WindowImpl::SetTouchHotAreas(const std::vector<Rect>& rects)
924{
925    return WMError::WM_OK;
926}
927void WindowImpl::GetRequestedTouchHotAreas(std::vector<Rect>& rects) const
928{
929}
930
931WMError WindowImpl::SetAPPWindowLabel(const std::string& label)
932{
933    if (uiContent_ == nullptr) {
934        WLOGFE("uicontent is empty");
935        return WMError::WM_ERROR_NULLPTR;
936    }
937    uiContent_->SetAppWindowTitle(label);
938    return WMError::WM_OK;
939}
940
941WMError WindowImpl::SetAPPWindowIcon(const std::shared_ptr<Media::PixelMap>& icon)
942{
943    if (icon == nullptr) {
944        WLOGFE("window icon is empty");
945        return WMError::WM_ERROR_NULLPTR;
946    }
947    if (uiContent_ == nullptr) {
948        WLOGFE("uicontent is empty");
949        return WMError::WM_ERROR_NULLPTR;
950    }
951    uiContent_->SetAppWindowIcon(icon);
952    return WMError::WM_OK;
953}
954
955WMError WindowImpl::SetCornerRadius(float cornerRadius)
956{
957    return WMError::WM_OK;
958}
959
960WMError WindowImpl::SetShadowRadius(float radius)
961{
962    return WMError::WM_OK;
963}
964
965WMError WindowImpl::SetShadowColor(std::string color)
966{
967    return WMError::WM_OK;
968}
969
970WMError WindowImpl::SetShadowOffsetX(float offsetX)
971{
972    return WMError::WM_OK;
973}
974
975WMError WindowImpl::SetShadowOffsetY(float offsetY)
976{
977    return WMError::WM_OK;
978}
979
980WMError WindowImpl::SetBlur(float radius)
981{
982    return WMError::WM_OK;
983}
984
985WMError WindowImpl::SetBackdropBlur(float radius)
986{
987    return WMError::WM_OK;
988}
989
990WMError WindowImpl::SetBackdropBlurStyle(WindowBlurStyle blurStyle)
991{
992    return WMError::WM_OK;
993}
994
995WMError WindowImpl::NotifyMemoryLevel(int32_t level)
996{
997    return WMError::WM_OK;
998}
999
1000bool WindowImpl::IsAllowHaveSystemSubWindow()
1001{
1002    return true;
1003}
1004
1005/** @note @window.hierarchy */
1006WMError WindowImpl::RaiseToAppTop()
1007{
1008    return WMError::WM_OK;
1009}
1010
1011WMError WindowImpl::SetAspectRatio(float ratio)
1012{
1013    return WMError::WM_OK;
1014}
1015
1016WMError WindowImpl::ResetAspectRatio()
1017{
1018    return WMError::WM_OK;
1019}
1020
1021KeyboardAnimationConfig WindowImpl::GetKeyboardAnimationConfig()
1022{
1023    return keyboardAnimationConfig_;
1024}
1025
1026void WindowImpl::SetNeedDefaultAnimation(bool needDefaultAnimation)
1027{
1028    return;
1029}
1030
1031void WindowImpl::SetViewportConfig(const Ace::ViewportConfig& config)
1032{
1033    bool isUpdate = false;
1034    if (width_ != config.Width()) {
1035        width_ = config.Width();
1036        isUpdate = true;
1037    }
1038    if (height_ != config.Height()) {
1039        height_ = config.Height();
1040        isUpdate = true;
1041    }
1042    if (abs(density_ - config.Density()) >= 1e-6) {
1043        density_ = config.Density();
1044        isUpdate = true;
1045    }
1046    if (orientation_ != config.Orientation()) {
1047        orientation_ = config.Orientation();
1048        isUpdate = true;
1049    }
1050    if (isUpdate) {
1051        UpdateViewportConfig();
1052    }
1053}
1054
1055void WindowImpl::UpdateViewportConfig()
1056{
1057    Ace::ViewportConfig config;
1058    config.SetSize(width_, height_);
1059    config.SetPosition(0, 0);
1060    config.SetDensity(density_);
1061    config.SetOrientation(orientation_);
1062    if (uiContent_ != nullptr) {
1063        uiContent_->UpdateViewportConfig(config, WindowSizeChangeReason::UNDEFINED);
1064    }
1065}
1066
1067void WindowImpl::SetOrientation(Orientation orientation)
1068{
1069    WLOGFD("SetOrientation : orientation=%{public}d", static_cast<int32_t>(orientation));
1070    if (orientation_ == static_cast<int32_t>(orientation)) {
1071        return;
1072    }
1073    orientation_ = static_cast<int32_t>(orientation);
1074    UpdateViewportConfig();
1075}
1076
1077void WindowImpl::SetSize(int32_t width, int32_t height)
1078{
1079    WLOGFD("SetSize : width=%{public}d, height=%{public}d", width, height);
1080    if (width_ == width && height_ == height) {
1081        return;
1082    }
1083    width_ = width;
1084    height_ = height;
1085    UpdateViewportConfig();
1086}
1087
1088void WindowImpl::SetDensity(float density)
1089{
1090    WLOGFD("SetDensity : density=%{public}f", density);
1091    if (abs(density_ - density) <= 0.000001) { // 0.000001: near zero.
1092        return;
1093    }
1094    density_ = density;
1095    UpdateViewportConfig();
1096}
1097
1098WMError WindowImpl::SetResizeByDragEnabled(bool dragEnabled)
1099{
1100    return WMError::WM_OK;
1101}
1102
1103/** @note @window.hierarchy */
1104WMError WindowImpl::SetRaiseByClickEnabled(bool raiseEnabled)
1105{
1106    return WMError::WM_OK;
1107}
1108
1109/** @note @window.hierarchy */
1110WMError WindowImpl::RaiseAboveTarget(int32_t subWindowId)
1111{
1112    return WMError::WM_OK;
1113}
1114
1115WMError WindowImpl::HideNonSystemFloatingWindows(bool shouldHide)
1116{
1117    return WMError::WM_OK;
1118}
1119
1120WMError WindowImpl::RegisterWindowVisibilityChangeListener(const WindowVisibilityListenerSptr& listener)
1121{
1122    return WMError::WM_ERROR_DEVICE_NOT_SUPPORT;
1123}
1124
1125WMError WindowImpl::UnregisterWindowVisibilityChangeListener(const WindowVisibilityListenerSptr& listener)
1126{
1127    return WMError::WM_ERROR_DEVICE_NOT_SUPPORT;
1128}
1129
1130WmErrorCode WindowImpl::KeepKeyboardOnFocus(bool keepKeyboardFlag)
1131{
1132    return WmErrorCode::WM_ERROR_DEVICE_NOT_SUPPORT;
1133}
1134
1135WMError WindowImpl::SetSingleFrameComposerEnabled(bool enable)
1136{
1137    return WMError::WM_ERROR_DEVICE_NOT_SUPPORT;
1138}
1139
1140WMError WindowImpl::SetLandscapeMultiWindow(bool isLandscapeMultiWindow)
1141{
1142    return WMError::WM_OK;
1143}
1144
1145void WindowImpl::SetUiDvsyncSwitch(bool dvsyncSwitch)
1146{
1147}
1148
1149WMError WindowImpl::SetImmersiveModeEnabledState(bool enable)
1150{
1151    return WMError::WM_OK;
1152}
1153
1154bool WindowImpl::GetImmersiveModeEnabledState() const
1155{
1156    return true;
1157}
1158} // namespace Rosen
1159} // namespace OHOS
1160