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