Lines Matching refs:node

136 WMError WindowNodeContainer::AddWindowNodeOnWindowTree(sptr<WindowNode>& node, const sptr<WindowNode>& parentNode)
138 sptr<WindowNode> root = FindRoot(node->GetWindowType());
139 if (root == nullptr && !(WindowHelper::IsSystemSubWindow(node->GetWindowType()) &&
144 node->requestedVisibility_ = true;
146 if (WindowHelper::IsSystemSubWindow(node->GetWindowType()) ||
147 node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
165 node->currentVisibility_ = parentNode->currentVisibility_;
166 node->parent_ = parentNode;
168 node->parent_ = root;
169 node->currentVisibility_ = true;
170 for (auto& child : node->children_) {
173 if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) {
174 displayGroupController_->sysBarNodeMaps_[node->GetDisplayId()][node->GetWindowType()] = node;
180 WMError WindowNodeContainer::ShowStartingWindow(sptr<WindowNode>& node)
182 if (node->currentVisibility_) {
183 WLOGFE("current window is visible, windowId: %{public}u", node->GetWindowId());
187 WMError res = AddWindowNodeOnWindowTree(node, nullptr);
191 UpdateWindowTree(node);
192 displayGroupController_->PreProcessWindowNode(node, WindowUpdateType::WINDOW_UPDATE_ADDED);
193 StartingWindow::AddNodeOnRSTree(node, layoutPolicy_->IsMultiDisplay());
195 layoutPolicy_->PerformWindowLayout(node, WindowUpdateType::WINDOW_UPDATE_ADDED);
196 WLOGI("ShowStartingWindow windowId: %{public}u end", node->GetWindowId());
200 WMError WindowNodeContainer::IsTileRectSatisfiedWithSizeLimits(sptr<WindowNode>& node)
203 !layoutPolicy_->IsTileRectSatisfiedWithSizeLimits(node)) {
205 node->GetWindowId());
216 void WindowNodeContainer::LayoutWhenAddWindowNode(sptr<WindowNode>& node, bool afterAnimation)
219 layoutPolicy_->PerformWindowLayout(node, WindowUpdateType::WINDOW_UPDATE_ADDED);
223 node->GetWindowId(), static_cast<uint32_t>(node->stateMachine_.GetCurrentState()));
224 if (WindowHelper::IsMainWindow(node->GetWindowType()) &&
225 RemoteAnimation::IsRemoteAnimationEnabledAndFirst(node->GetDisplayId()) &&
226 node->stateMachine_.IsShowAnimationPlaying()) {
228 auto winRect = node->GetWindowRect();
229 if (node->surfaceNode_) {
230 node->surfaceNode_->SetBounds(0, 0, winRect.width_, winRect.height_);
232 node->GetWindowId(), winRect.posX_, winRect.posY_, winRect.width_, winRect.height_);
233 layoutPolicy_->NotifyClientAndAnimation(node, winRect, WindowSizeChangeReason::UNDEFINED);
236 if (node->GetWindowProperty()->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::CUSTOM) &&
237 WindowHelper::IsSystemWindow(node->GetWindowType())) {
238 node->SetWindowSizeChangeReason(WindowSizeChangeReason::CUSTOM_ANIMATION_SHOW);
240 layoutPolicy_->PerformWindowLayout(node, WindowUpdateType::WINDOW_UPDATE_ADDED);
244 WMError WindowNodeContainer::AddWindowNode(sptr<WindowNode>& node, sptr<WindowNode>& parentNode, bool afterAnimation)
246 if (!node->startingWindowShown_) { // window except main Window
247 WMError res = AddWindowNodeOnWindowTree(node, parentNode);
251 UpdateWindowTree(node);
252 displayGroupController_->PreProcessWindowNode(node, WindowUpdateType::WINDOW_UPDATE_ADDED);
253 // add node on RSTree
254 for (auto& displayId : node->GetShowingDisplays()) {
255 AddNodeOnRSTree(node, displayId, displayId, WindowUpdateType::WINDOW_UPDATE_ADDED,
256 node->isPlayAnimationShow_);
259 node->isPlayAnimationShow_ = false;
260 node->startingWindowShown_ = false;
261 AddAppSurfaceNodeOnRSTree(node);
262 ReZOrderShowWhenLockedWindowIfNeeded(node);
263 RaiseZOrderForAppWindow(node, parentNode);
265 auto windowPair = displayGroupController_->GetWindowPairByDisplayId(node->GetDisplayId());
270 windowPair->UpdateIfSplitRelated(node);
271 if (node->IsSplitMode()) {
273 RaiseSplitRelatedWindowToTop(node);
278 MinimizeOldestMainFloatingWindow(node->GetWindowId());
280 LayoutWhenAddWindowNode(node, afterAnimation);
281 NotifyIfAvoidAreaChanged(node, AvoidControlType::AVOID_NODE_ADD);
282 DumpScreenWindowTreeByWinId(node->GetWindowId());
283 UpdateCameraFloatWindowStatus(node, true);
284 if (WindowHelper::IsMainWindow(node->GetWindowType())) {
288 if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) {
290 SetBelowScreenlockVisible(node, false);
292 if (node->GetWindowType() == WindowType::WINDOW_TYPE_WALLPAPER) {
293 RemoteAnimation::NotifyAnimationUpdateWallpaper(node);
295 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) {
298 WLOGI("AddWindowNode Id: %{public}u end", node->GetWindowId());
301 if (node->GetWindowProperty()->GetPrivacyMode()) {
304 if (WindowHelper::IsMainWindow(node->GetWindowType())) {
305 WindowInfoReporter::GetInstance().InsertShowReportInfo(node->abilityInfo_.bundleName_);
310 void WindowNodeContainer::UpdateRSTreeWhenShowingDisplaysChange(sptr<WindowNode>& node,
318 auto curShowingDisplays = node->GetShowingDisplays();
321 RemoveNodeFromRSTree(node, displayId, *(curShowingDisplays.begin()),
329 AddNodeOnRSTree(node, displayId, displayId, WindowUpdateType::WINDOW_UPDATE_ACTIVE);
335 WMError WindowNodeContainer::UpdateWindowNode(sptr<WindowNode>& node, WindowUpdateReason reason)
338 auto lastShowingDisplays = node->GetShowingDisplays();
340 // PreProcess window node and layout node
341 displayGroupController_->PreProcessWindowNode(node, WindowUpdateType::WINDOW_UPDATE_ACTIVE);
342 if (WindowHelper::IsMainWindow(node->GetWindowType()) && WindowHelper::IsSwitchCascadeReason(reason)) {
343 SwitchLayoutPolicy(WindowLayoutMode::CASCADE, node->GetDisplayId());
345 layoutPolicy_->PerformWindowLayout(node, WindowUpdateType::WINDOW_UPDATE_ACTIVE);
346 displayGroupController_->PostProcessWindowNode(node);
348 UpdateRSTreeWhenShowingDisplaysChange(node, lastShowingDisplays);
349 NotifyIfAvoidAreaChanged(node, AvoidControlType::AVOID_NODE_UPDATE);
350 WLOGD("UpdateNode Id: %{public}u end", node->GetWindowId());
354 void WindowNodeContainer::RemoveWindowNodeFromWindowTree(sptr<WindowNode>& node)
356 // remove this node from parent
357 auto iter = std::find(node->parent_->children_.begin(), node->parent_->children_.end(), node);
358 if (iter != node->parent_->children_.end()) {
359 node->parent_->children_.erase(iter);
361 WLOGFE("can't find this node in parent");
363 node->parent_ = nullptr;
366 void WindowNodeContainer::RemoveFromRsTreeWhenRemoveWindowNode(sptr<WindowNode>& node, bool fromAnimation)
368 if (fromAnimation || (RemoteAnimation::IsRemoteAnimationEnabledAndFirst(node->GetDisplayId()) &&
369 node->stateMachine_.IsHideAnimationPlaying())) {
370 WLOGFD("not remove from rs tree id:%{public}u", node->GetWindowId());
373 // When RemoteAnimation exists, remove node from rs tree after animation
374 WLOGFD("Id:%{public}u, isPlayAnimationHide_:%{public}u", node->GetWindowId(),
375 static_cast<uint32_t>(node->isPlayAnimationHide_));
377 for (auto& displayId : node->GetShowingDisplays()) {
378 RemoveNodeFromRSTree(node, displayId, displayId, WindowUpdateType::WINDOW_UPDATE_REMOVED,
379 node->isPlayAnimationHide_);
383 void WindowNodeContainer::SetSurfaceNodeVisible(sptr<WindowNode>& node, int32_t topPriority, bool visible)
385 if (node == nullptr) {
388 if (node->parent_ != nullptr && node->currentVisibility_) {
389 if (node->priority_ < topPriority && !WindowHelper::IsShowWhenLocked(node->GetWindowFlags()) &&
390 !WindowHelper::IsShowWhenLocked(node->parent_->GetWindowFlags())) {
391 auto surfaceNode = node->leashWinSurfaceNode_ != nullptr ? node->leashWinSurfaceNode_ : node->surfaceNode_;
397 for (auto& childNode : node->children_) {
402 void WindowNodeContainer::SetBelowScreenlockVisible(sptr<WindowNode>& node, bool visible)
406 for (auto& node : rootNodes) {
407 SetSurfaceNodeVisible(node, topPriority, visible);
411 WMError WindowNodeContainer::RemoveWindowNode(sptr<WindowNode>& node, bool fromAnimation)
413 if (node == nullptr) {
414 WLOGFE("window node or surface node is nullptr, invalid");
417 if (node->parent_ == nullptr) {
418 WLOGFW("can't find parent of this node");
420 RemoveWindowNodeFromWindowTree(node);
423 node->requestedVisibility_ = false;
424 node->currentVisibility_ = false;
425 RemoveFromRsTreeWhenRemoveWindowNode(node, fromAnimation);
426 node->isPlayAnimationHide_ = false;
428 layoutPolicy_->PerformWindowLayout(node, WindowUpdateType::WINDOW_UPDATE_REMOVED);
429 WindowMode lastMode = node->GetWindowMode();
430 if (HandleRemoveWindow(node) != WMError::WM_OK) {
434 NotifyDockWindowStateChanged(node, true);
436 NotifyIfAvoidAreaChanged(node, AvoidControlType::AVOID_NODE_REMOVE);
437 DumpScreenWindowTreeByWinId(node->GetWindowId());
438 UpdateCameraFloatWindowStatus(node, false);
439 if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) {
441 SetBelowScreenlockVisible(node, true);
443 WLOGI("Remove Id: %{public}u end", node->GetWindowId());
447 if (node->GetWindowProperty()->GetPrivacyMode()) {
450 if (WindowHelper::IsMainWindow(node->GetWindowType())) {
451 WindowInfoReporter::GetInstance().InsertHideReportInfo(node->abilityInfo_.bundleName_);
453 HandleRemoveWindowDisplayOrientation(node, fromAnimation);
457 void WindowNodeContainer::HandleRemoveWindowDisplayOrientation(sptr<WindowNode>& node, bool fromAnimation)
459 if (node->GetWindowMode() != WindowMode::WINDOW_MODE_FULLSCREEN) {
464 auto nextRotatableWindow = GetNextRotatableWindow(node->GetWindowId());
471 if (node->stateMachine_.IsHideAnimationPlaying()) {
475 auto nextRotatableWindow = GetNextRotatableWindow(node->GetWindowId());
495 void WindowNodeContainer::SetDisplayOrientationFromWindow(sptr<WindowNode>& node, bool withAnimation)
497 DisplayManagerServiceInner::GetInstance().SetOrientationFromWindow(node->GetDisplayId(),
498 node->GetRequestedOrientation(), withAnimation);
518 for (const auto& node : windowNodes) {
519 if (node->GetWindowProperty()->GetPrivacyMode()) {
605 for (auto& node : tempWindows) {
606 UpdateWindowTree(node);
610 WMError WindowNodeContainer::HandleRemoveWindow(sptr<WindowNode>& node)
613 auto windowPair = displayGroupController_->GetWindowPairByDisplayId(node->GetDisplayId());
618 windowPair->HandleRemoveWindow(node);
620 auto type = node->GetWindowType();
629 WMError WindowNodeContainer::DestroyWindowNode(sptr<WindowNode>& node, std::vector<uint32_t>& windowIds)
631 WMError ret = RemoveWindowNode(node);
636 StartingWindow::ReleaseStartWinSurfaceNode(node);
637 node->surfaceNode_ = nullptr;
638 windowIds.push_back(node->GetWindowId());
639 for (auto& child : node->children_) { // destroy sub window if exists
650 node->children_.swap(emptyVector);
651 if (node->GetWindowType() == WindowType::WINDOW_TYPE_WALLPAPER) {
654 if (WindowHelper::IsMainWindow(node->GetWindowType())) {
655 WindowInfoReporter::GetInstance().InsertDestroyReportInfo(node->abilityInfo_.bundleName_);
658 UpdateAvoidAreaListener(node, false);
659 WLOGI("DestroyNode Id: %{public}u end", node->GetWindowId());
663 void WindowNodeContainer::UpdateSizeChangeReason(sptr<WindowNode>& node, WindowSizeChangeReason reason)
665 if (!node->GetWindowToken()) {
669 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
678 layoutPolicy_->NotifyClientAndAnimation(node, node->GetWindowRect(), reason);
680 "reason: %{public}u", node->GetWindowId(), reason);
684 void WindowNodeContainer::UpdateWindowTree(sptr<WindowNode>& node)
687 node->priority_ = zorderPolicy_->GetWindowPriority(node->GetWindowType());
688 RaiseInputMethodWindowPriorityIfNeeded(node);
689 RaiseShowWhenLockedWindowIfNeeded(node);
690 ResetMainFloatingWindowPriorityIfNeeded(node);
691 auto parentNode = node->parent_;
693 WLOGI("Current window node has no parent: %{public}u", node->GetWindowId());
696 auto iter = std::find(parentNode->children_.begin(), parentNode->children_.end(), node);
698 WLOGI("node %{public}u already on window tree, not update!", node->GetWindowId());
704 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE && splitWindowCnt == SPLIT_WINDOWS_CNT) {
711 if ((*child)->priority_ > node->priority_) {
716 parentNode->children_.insert(position, node);
719 bool WindowNodeContainer::AddAppSurfaceNodeOnRSTree(sptr<WindowNode>& node)
726 HITRACE_METER_FMT(HITRACE_TAG_WINDOW_MANAGER, "AddAppSurfaceNodeOnRSTree(%u)", node->GetWindowId());
727 if (!WindowHelper::IsMainWindow(node->GetWindowType())) {
728 WLOGFE("id:%{public}u not main app window but has start window", node->GetWindowId());
731 if (!node->leashWinSurfaceNode_ || !node->surfaceNode_) {
732 WLOGFE("id:%{public}u leashWinSurfaceNode or surfaceNode is null but has start window!", node->GetWindowId());
735 WLOGI("AddAppSurfaceNodeOnRSTree Id: %{public}d", node->GetWindowId());
736 if (!node->currentVisibility_) {
737 WLOGI("id: %{public}d is invisible, no need update RS tree", node->GetWindowId());
740 node->leashWinSurfaceNode_->AddChild(node->surfaceNode_, -1);
784 bool WindowNodeContainer::AddNodeOnRSTree(sptr<WindowNode>& node, DisplayId displayId, DisplayId parentDisplayId,
788 if (node->GetWindowProperty()->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::CUSTOM) ||
789 node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
796 node->GetWindowId(), displayId, parentDisplayId, isMultiDisplay, animationPlayed);
798 if (!node->currentVisibility_) {
799 WLOGI("id: %{public}d invisible, no need update RS tree", node->GetWindowId());
803 if (IsWindowFollowParent(node->GetWindowType())) {
804 auto& parentNode = node->parent_;
806 node->surfaceNode_ != nullptr) {
807 node->surfaceNode_->SetTranslateX(node->GetWindowRect().posX_ - parentNode->GetWindowRect().posX_);
808 node->surfaceNode_->SetTranslateY(node->GetWindowRect().posY_ - parentNode->GetWindowRect().posY_);
809 node->surfaceNode_->SetVisible(true);
810 parentNode->surfaceNode_->AddChild(node->surfaceNode_, -1);
816 auto& surfaceNode = node->leashWinSurfaceNode_ != nullptr ? node->leashWinSurfaceNode_ : node->surfaceNode_;
818 for (auto& child : node->children_) {
832 node->GetWindowGravity(windowGravity, percent);
833 if (node->EnableDefaultAnimation(animationPlayed)) {
834 WLOGFD("Add node with animation");
835 StartTraceArgs(HITRACE_TAG_WINDOW_MANAGER, "Animate(%u)", node->GetWindowId());
839 } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT &&
847 WLOGFD("add node without animation");
853 bool WindowNodeContainer::RemoveNodeFromRSTree(sptr<WindowNode>& node, DisplayId displayId, DisplayId parentDisplayId,
857 if (node->GetWindowProperty()->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::CUSTOM) ||
858 node->GetWindowType() == WindowType::WINDOW_TYPE_APP_COMPONENT) {
865 node->GetWindowId(), displayId, isMultiDisplay, parentDisplayId, animationPlayed);
867 if (IsWindowFollowParent(node->GetWindowType())) {
868 const auto& parentNode = node->parent_;
870 node->surfaceNode_ != nullptr) {
871 node->surfaceNode_->SetVisible(false);
872 parentNode->surfaceNode_->RemoveChild(node->surfaceNode_);
878 auto& surfaceNode = node->leashWinSurfaceNode_ != nullptr ? node->leashWinSurfaceNode_ : node->surfaceNode_;
880 for (auto& child : node->children_) {
894 node->GetWindowGravity(windowGravity, percent);
895 if (node->EnableDefaultAnimation(animationPlayed)) {
897 StartTraceArgs(HITRACE_TAG_WINDOW_MANAGER, "Animate(%u)", node->GetWindowId());
898 if (node->surfaceNode_) {
899 node->surfaceNode_->SetFreeze(true);
901 wptr<WindowNode> weakNode(node);
910 } else if (node->GetWindowType() == WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT &&
928 for (auto& node : belowAppWindowNode_->children_) {
929 DestroyWindowNode(node, removedIds_);
931 for (auto& node : appWindowNode_->children_) {
932 DestroyWindowNode(node, removedIds_);
934 for (auto& node : aboveAppWindowNode_->children_) {
935 DestroyWindowNode(node, removedIds_);
960 for (auto& node : rootNode->children_) {
961 if (node->GetWindowId() == id) {
962 return node;
964 for (auto& subNode : node->children_) {
976 auto node = FindWindowNodeById(id);
977 if (node == nullptr) {
982 focusedPid_ = node->GetCallingPid();
984 node->isFocused_ = focused;
986 WindowSystemEffect::SetWindowShadow(node);
987 if (node->GetCallingPid() == 0) {
992 if (focused && node->GetWindowProperty() != nullptr) {
993 AbilityInfo info = node->GetWindowProperty()->GetAbilityInfo();
996 node->GetWindowProperty()->GetWindowName().c_str(), info.bundleName_.c_str(), info.abilityName_.c_str(),
997 node->GetCallingPid(), node->GetCallingUid());
999 if (node->surfaceNode_ == nullptr) {
1002 focusNodeId = node->surfaceNode_->GetId();
1005 { node->GetCallingPid(), node->GetCallingUid(), info.bundleName_, info.abilityName_, focusNodeId };
1008 if (node->GetWindowToken()) {
1009 node->GetWindowToken()->UpdateFocusStatus(focused);
1011 if (node->abilityToken_ == nullptr) {
1014 sptr<FocusChangeInfo> focusChangeInfo = new FocusChangeInfo(node->GetWindowId(), node->GetDisplayId(),
1015 node->GetCallingPid(), node->GetCallingUid(), node->GetWindowType(), node->abilityToken_);
1022 auto node = FindWindowNodeById(id);
1023 if (node == nullptr) {
1028 activePid_ = node->GetCallingPid();
1030 if (node->GetWindowToken()) {
1031 node->GetWindowToken()->UpdateActiveStatus(isActive);
1037 auto node = FindWindowNodeById(id);
1038 if (node == nullptr) {
1044 if (!WindowHelper::IsAppWindow(node->GetWindowType())) {
1048 WLOGI("Brightness: [%{public}f, %{public}f]", GetDisplayBrightness(), node->GetBrightness());
1049 if (std::fabs(node->GetBrightness() - UNDEFINED_BRIGHTNESS) < std::numeric_limits<float>::min()) {
1050 if (GetDisplayBrightness() != node->GetBrightness()) {
1059 if (GetDisplayBrightness() != node->GetBrightness()) {
1060 WLOGI("adjust brightness with value: %{public}u", ToOverrideBrightness(node->GetBrightness()));
1063 ToOverrideBrightness(node->GetBrightness()));
1065 SetDisplayBrightness(node->GetBrightness());
1067 SetBrightnessWindow(node->GetWindowId());
1074 WindowNodeOperationFunc func = [this](sptr<WindowNode> node) {
1075 if (!node->leashWinSurfaceNode_ && !node->surfaceNode_ && !node->startingWinSurfaceNode_) {
1077 WLOGFE("Id: %{public}u has no surface nodes", node->GetWindowId());
1080 if (node->leashWinSurfaceNode_ != nullptr) {
1082 node->leashWinSurfaceNode_->SetPositionZ(zOrder_);
1085 if (node->surfaceNode_ != nullptr) {
1087 node->surfaceNode_->SetPositionZ(zOrder_);
1088 node->zOrder_ = zOrder_;
1091 if (node->startingWinSurfaceNode_ != nullptr) {
1093 node->startingWinSurfaceNode_->SetPositionZ(zOrder_);
1196 void WindowNodeContainer::HandleKeepScreenOn(const sptr<WindowNode>& node, bool requireLock)
1199 if (requireLock && node->keepScreenLock_ == nullptr) {
1202 node->keepScreenLock_ = PowerMgr::PowerMgrClient::GetInstance().CreateRunningLock(node->GetWindowName(),
1207 if (node->keepScreenLock_ == nullptr) {
1210 WLOGI("keep screen on: [%{public}s, %{public}d]", node->GetWindowName().c_str(), requireLock);
1212 node->GetWindowName().c_str(), requireLock);
1217 res = node->keepScreenLock_->Lock();
1219 res = node->keepScreenLock_->UnLock();
1229 bool WindowNodeContainer::IsAboveSystemBarNode(sptr<WindowNode> node) const
1231 int32_t curPriority = zorderPolicy_->GetWindowPriority(node->GetWindowType());
1239 bool WindowNodeContainer::IsSplitImmersiveNode(sptr<WindowNode> node) const
1241 auto type = node->GetWindowType();
1242 return node->IsSplitMode() || type == WindowType::WINDOW_TYPE_DOCK_SLICE;
1258 for (const auto& node : rootNodes) {
1259 for (auto iter = node->children_.rbegin(); iter < node->children_.rend(); ++iter) {
1297 void WindowNodeContainer::NotifyIfAvoidAreaChanged(const sptr<WindowNode>& node,
1300 auto checkFunc = [this](sptr<WindowNode> node) {
1301 return CheckWindowNodeWhetherInWindowTree(node);
1303 avoidController_->ProcessWindowChange(node, avoidType, checkFunc);
1304 if (WindowHelper::IsSystemBarWindow(node->GetWindowType())) {
1305 NotifyIfSystemBarRegionChanged(node->GetDisplayId());
1307 NotifyIfSystemBarTintChanged(node->GetDisplayId());
1310 NotifyIfKeyboardRegionChanged(node, avoidType);
1321 auto checkFunc = [this](sptr<WindowNode> node) {
1322 return CheckWindowNodeWhetherInWindowTree(node);
1324 WindowNodeOperationFunc func = [avoidController = avoidController_, &checkFunc](sptr<WindowNode> node) {
1325 avoidController->ProcessWindowChange(node, AvoidControlType::AVOID_NODE_UPDATE, checkFunc);
1397 void WindowNodeContainer::NotifyIfKeyboardRegionChanged(const sptr<WindowNode>& node,
1402 node->GetWindowGravity(windowGravity, percent);
1403 if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT ||
1405 WLOGFD("windowType: %{public}u", node->GetWindowType());
1409 auto callingWindow = FindWindowNodeById(node->GetCallingWindow());
1411 WLOGD("callingWindow: %{public}u does not be set", node->GetCallingWindow());
1422 const Rect keyRect = node->GetWindowRect();
1434 if (node->GetWindowProperty() != nullptr) {
1435 textFieldPositionY = node->GetWindowProperty()->GetTextFieldPositionY();
1436 textFieldHeight = node->GetWindowProperty()->GetTextFieldHeight();
1483 void WindowNodeContainer::NotifyDockWindowStateChanged(sptr<WindowNode>& node, bool isEnable)
1489 if (windowNode->GetWindowId() == node->GetWindowId()) {
1504 WindowManagerAgentController::GetInstance().UpdateSystemBarRegionTints(node->GetDisplayId(), tints);
1537 WLOGFE("root does not have any node");
1540 auto node = *(rootNode->children_.rbegin());
1541 if (node == nullptr) {
1542 WLOGFE("window tree does not have any node");
1546 for (auto iter = node->children_.rbegin(); iter < node->children_.rend(); iter++) {
1553 return node->GetWindowId() == windowId;
1582 [windowId](sptr<WindowNode> node) {
1583 return node->GetWindowId() == windowId;
1585 // raise app node window to top
1587 sptr<WindowNode> node = *iter;
1589 UpdateWindowTree(node);
1590 WLOGD("raise window to top %{public}u", node->GetWindowId());
1596 for (auto& node : belowAppWindowNode_->children_) {
1597 TraverseWindowNode(node, windowNodes);
1599 for (auto& node : appWindowNode_->children_) {
1600 TraverseWindowNode(node, windowNodes);
1602 for (auto& node : aboveAppWindowNode_->children_) {
1603 TraverseWindowNode(node, windowNodes);
1608 void WindowNodeContainer::TraverseWindowNode(sptr<WindowNode>& node, std::vector<sptr<WindowNode>>& windowNodes) const
1610 if (node == nullptr) {
1613 auto iter = node->children_.begin();
1614 for (; iter < node->children_.end(); ++iter) {
1621 windowNodes.emplace_back(node);
1622 for (; iter < node->children_.end(); ++iter) {
1627 AvoidArea WindowNodeContainer::GetAvoidAreaByType(const sptr<WindowNode>& node, AvoidAreaType avoidAreaType) const
1629 if (CheckWindowNodeWhetherInWindowTree(node)) {
1630 return avoidController_->GetAvoidAreaByType(node, avoidAreaType);
1635 bool WindowNodeContainer::CheckWindowNodeWhetherInWindowTree(const sptr<WindowNode>& node) const
1638 WindowNodeOperationFunc func = [&node, &isInWindowTree](sptr<WindowNode> windowNode) {
1639 if (node->GetWindowId() == windowNode->GetWindowId()) {
1654 WindowNodeOperationFunc func = [&zOrder, &winid](sptr<WindowNode> node) {
1655 Rect rect = node->GetWindowRect();
1656 uint32_t windowId = node->GetWindowId();
1657 const std::string& windowName = node->GetWindowName().size() < WINDOW_NAME_MAX_LENGTH ?
1658 node->GetWindowName() : node->GetWindowName().substr(0, WINDOW_NAME_MAX_LENGTH);
1662 windowName.c_str(), node->GetWindowId(), node->GetWindowType(), node->GetWindowMode(),
1667 windowName.c_str(), node->GetWindowId(), node->GetWindowType(), node->GetWindowMode(),
1681 WindowNodeOperationFunc func = [&zOrder](sptr<WindowNode> node) {
1682 Rect rect = node->GetWindowRect();
1683 const std::string& windowName = node->GetWindowName().size() < WINDOW_NAME_MAX_LENGTH ?
1684 node->GetWindowName() : node->GetWindowName().substr(0, WINDOW_NAME_MAX_LENGTH);
1687 windowName.c_str(), node->GetDisplayId(), node->GetWindowId(), node->GetWindowType(), node->GetWindowMode(),
1688 node->GetWindowFlags(), --zOrder, static_cast<uint32_t>(node->GetRequestedOrientation()),
1689 node->firstFrameAvailable_, rect.posX_, rect.posY_, rect.width_, rect.height_);
1718 for (auto& node : rootNodes) {
1719 UpdateWindowState(node, topPriority, state);
1723 void WindowNodeContainer::UpdateWindowState(sptr<WindowNode> node, int32_t topPriority, WindowState state)
1725 if (node == nullptr) {
1728 if (node->parent_ != nullptr && node->currentVisibility_) {
1729 if (node->priority_ < topPriority && !WindowHelper::IsShowWhenLocked(node->GetWindowFlags()) &&
1730 !WindowHelper::IsShowWhenLocked(node->parent_->GetWindowFlags())) {
1731 if (node->GetWindowToken()) {
1732 node->GetWindowToken()->UpdateWindowState(state);
1734 HandleKeepScreenOn(node, state);
1737 for (auto& childNode : node->children_) {
1742 void WindowNodeContainer::HandleKeepScreenOn(const sptr<WindowNode>& node, WindowState state)
1744 if (node == nullptr) {
1749 HandleKeepScreenOn(node, false);
1751 HandleKeepScreenOn(node, node->IsKeepScreenOn());
1767 void WindowNodeContainer::RaiseSplitRelatedWindowToTop(sptr<WindowNode>& node)
1769 if (node == nullptr) {
1772 auto windowPair = displayGroupController_->GetWindowPairByDisplayId(node->GetDisplayId());
1777 std::vector<sptr<WindowNode>> orderedPair = windowPair->GetOrderedPair(node);
1783 WMError WindowNodeContainer::RaiseZOrderForAppWindow(sptr<WindowNode>& node, sptr<WindowNode>& parentNode)
1785 if (node == nullptr) {
1788 if (IsTopWindow(node->GetWindowId(), appWindowNode_) || IsTopWindow(node->GetWindowId(), aboveAppWindowNode_)) {
1789 WLOGE("Window %{public}u is already at top", node->GetWindowId());
1793 if (WindowHelper::IsSubWindow(node->GetWindowType()) ||
1794 (node->GetWindowType() == WindowType::WINDOW_TYPE_DIALOG)) {
1799 RaiseWindowToTop(node->GetWindowId(), parentNode->children_); // raise itself
1805 } else if (WindowHelper::IsMainWindow(node->GetWindowType())) {
1806 if (node->IsSplitMode()) {
1807 RaiseSplitRelatedWindowToTop(node);
1810 if (node->parent_ == nullptr) {
1811 WLOGFW("node parent is nullptr");
1814 RaiseWindowToTop(node->GetWindowId(), node->parent_->children_);
1822 DumpScreenWindowTreeByWinId(node->GetWindowId());
1831 sptr<WindowNode> node) {
1832 if (previousFocusedWindowFound && node->GetWindowProperty()->GetFocusable() && node->currentVisibility_) {
1833 nextFocusableWindow = node;
1836 if (node->GetWindowId() == windowId) {
1849 sptr<WindowNode> node) {
1850 if (windowId != node->GetWindowId() &&
1851 WindowHelper::IsRotatableWindow(node->GetWindowType(), node->GetWindowMode())) {
1852 nextRotatableWindow = node;
1870 for (auto& node : appWindowNode_->children_) {
1871 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DOCK_SLICE) {
1874 return node;
1876 for (auto& node : belowAppWindowNode_->children_) {
1877 if (node->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) {
1878 return node;
1884 auto iter = std::find_if(windowNodes.begin(), windowNodes.end(), [windowId](sptr<WindowNode>& node) {
1885 return node->GetWindowId() == windowId;
1956 WindowNodeOperationFunc findDeskTopFunc = [this, &deskTop](sptr<WindowNode> node) {
1957 if (node->GetWindowProperty()->GetWindowType() == WindowType::WINDOW_TYPE_DESKTOP) {
1958 deskTop = node;
1971 for (const auto& node : windowNodes) {
1972 if (node && node->GetVisibilityState() < WINDOW_VISIBILITY_STATE_TOTALLY_OCCUSION &&
1973 node->GetWindowProperty()->GetPrivacyMode()) {
1974 WLOGI("window name %{public}s", node->GetWindowName().c_str());
1984 for (auto& node : appWindowNode_->children_) {
1985 TraverseWindowNode(node, windowNodes);
1987 for (const auto& node : windowNodes) {
1988 if (node->currentVisibility_ &&
1989 WindowHelper::IsMainFullScreenWindow(node->GetWindowType(), node->GetWindowMode())) {
2045 for (auto node : aboveAppWindowNode_->children_) {
2046 if (node->GetWindowType() == WindowType::WINDOW_TYPE_LAUNCHER_RECENT &&
2047 node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN && restore) {
2175 WMError WindowNodeContainer::MinimizeStructuredAppWindowsExceptSelf(const sptr<WindowNode>& node)
2177 std::vector<uint32_t> exceptionalIds = { node->GetWindowId() };
2216 void WindowNodeContainer::UpdateModeSupportInfoWhenKeyguardChange(const sptr<WindowNode>& node, bool up)
2218 if (!WindowHelper::IsWindowModeSupported(node->GetWindowProperty()->GetRequestModeSupportInfo(),
2220 WLOGFD("window doesn't support split mode, winId: %{public}d", node->GetWindowId());
2225 modeSupportInfo = node->GetModeSupportInfo() & (~WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY);
2227 modeSupportInfo = node->GetModeSupportInfo() | WindowModeSupport::WINDOW_MODE_SUPPORT_SPLIT_PRIMARY;
2229 node->SetModeSupportInfo(modeSupportInfo);
2230 if (node->GetWindowToken() != nullptr) {
2231 node->GetWindowToken()->UpdateWindowModeSupportInfo(modeSupportInfo);
2235 void WindowNodeContainer::RaiseInputMethodWindowPriorityIfNeeded(const sptr<WindowNode>& node) const
2237 if (node->GetWindowType() != WindowType::WINDOW_TYPE_INPUT_METHOD_FLOAT) {
2242 node->priority_ = zorderPolicy_->GetWindowPriority(
2248 auto callingWindowId = node->GetCallingWindow();
2255 node->priority_ = (inputMethodPriority < callingWindowPriority) ?
2257 WLOGFD("Reset input method float window priority to %{public}d.", node->priority_);
2263 node->priority_ = zorderPolicy_->GetWindowPriority(WindowType::WINDOW_TYPE_PANEL) + 1;
2324 void WindowNodeContainer::ReZOrderShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node)
2326 if (!(node->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED)) ||
2332 WLOGI("ShowWhenLocked window %{public}u re-zorder to up", node->GetWindowId());
2335 void WindowNodeContainer::RaiseShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node)
2338 if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) {
2344 if (!(node->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED)) ||
2349 node->priority_ = zorderPolicy_->GetWindowPriority(WindowType::WINDOW_TYPE_KEYGUARD) + 1;
2350 node->parent_ = aboveAppWindowNode_;
2351 if (WindowHelper::IsSplitWindowMode(node->GetWindowMode())) {
2352 node->GetWindowProperty()->ResumeLastWindowMode();
2354 WindowSystemEffect::SetWindowEffect(node);
2355 if (node->GetWindowToken() != nullptr) {
2356 node->GetWindowToken()->UpdateWindowMode(node->GetWindowMode());
2359 WLOGI("ShowWhenLocked window %{public}u raise itself", node->GetWindowId());
2362 void WindowNodeContainer::DropShowWhenLockedWindowIfNeeded(const sptr<WindowNode>& node)
2365 if (node->GetWindowType() == WindowType::WINDOW_TYPE_KEYGUARD) {
2378 for (const auto& node : rootNodes) {
2380 for (auto iter = node->children_.rbegin(); iter != node->children_.rend(); ++iter) {
2386 for (auto iter = node->children_.begin(); iter != node->children_.end(); ++iter) {
2395 bool WindowNodeContainer::TraverseFromTopToBottom(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const
2397 if (node == nullptr) {
2400 auto iterBegin = node->children_.rbegin();
2401 for (; iterBegin != node->children_.rend(); ++iterBegin) {
2409 if (func(node)) {
2412 for (; iterBegin != node->children_.rend(); ++iterBegin) {
2420 bool WindowNodeContainer::TraverseFromBottomToTop(sptr<WindowNode> node, const WindowNodeOperationFunc& func) const
2422 if (node == nullptr) {
2425 auto iterBegin = node->children_.begin();
2426 for (; iterBegin != node->children_.end(); ++iterBegin) {
2434 if (func(node)) {
2437 for (; iterBegin != node->children_.end(); ++iterBegin) {
2450 void WindowNodeContainer::UpdateSizeChangeReason(sptr<WindowNode>& node, WindowMode srcMode, WindowMode dstMode)
2453 node->SetWindowSizeChangeReason(WindowSizeChangeReason::RECOVER);
2455 node->SetWindowSizeChangeReason(WindowSizeChangeReason::MAXIMIZE);
2457 node->SetRequestRect(node->GetWindowRect());
2460 node->SetWindowSizeChangeReason(WindowSizeChangeReason::FULL_TO_SPLIT);
2462 node->SetWindowSizeChangeReason(WindowSizeChangeReason::SPLIT_TO_FULL);
2464 node->SetWindowSizeChangeReason(WindowSizeChangeReason::RESIZE);
2468 WMError WindowNodeContainer::SetWindowMode(sptr<WindowNode>& node, WindowMode dstMode)
2470 if (node == nullptr) {
2474 WindowMode srcMode = node->GetWindowMode();
2476 (node->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED))) {
2480 auto windowPair = displayGroupController_->GetWindowPairByDisplayId(node->GetDisplayId());
2487 // when status is single primary or single secondary, split node is abandoned to set mode
2488 if (node->IsSplitMode() && (status == WindowPairStatus::SINGLE_PRIMARY ||
2493 UpdateSizeChangeReason(node, srcMode, dstMode);
2494 node->SetWindowMode(dstMode);
2495 windowPair->UpdateIfSplitRelated(node);
2497 if (WindowHelper::IsMainWindow(node->GetWindowType())) {
2498 if (WindowHelper::IsFloatingWindow(node->GetWindowMode())) {
2499 NotifyDockWindowStateChanged(node, true);
2501 NotifyDockWindowStateChanged(node, false);
2505 if (node->GetWindowMode() == WindowMode::WINDOW_MODE_FULLSCREEN &&
2506 WindowHelper::IsAppWindow(node->GetWindowType())) {
2508 res = MinimizeStructuredAppWindowsExceptSelf(node);
2514 WindowSystemEffect::SetWindowEffect(node);
2517 ResetWindowZOrderPriorityWhenSetMode(node, dstMode, srcMode);
2518 MinimizeOldestMainFloatingWindow(node->GetWindowId());
2520 if (node->GetWindowToken() != nullptr) {
2521 node->GetWindowToken()->UpdateWindowMode(node->GetWindowMode());
2523 res = UpdateWindowNode(node, WindowUpdateReason::UPDATE_MODE);
2525 WLOGFE("Set window mode failed, update node failed");
2531 void WindowNodeContainer::ResetWindowZOrderPriorityWhenSetMode(sptr<WindowNode>& node,
2538 // reset node zorder priority.
2539 if (WindowHelper::IsMainFloatingWindow(node->GetWindowType(), srcMode)) {
2540 auto basePriority = zorderPolicy_->GetWindowPriority(node->GetWindowType());
2542 (node->GetWindowFlags() & static_cast<uint32_t>(WindowFlag::WINDOW_FLAG_SHOW_WHEN_LOCKED))) {
2545 node->priority_ = basePriority;
2548 if (!WindowHelper::IsMainFloatingWindow(node->GetWindowType(), srcMode) &&
2549 !WindowHelper::IsMainFloatingWindow(node->GetWindowType(), dstMode) &&
2556 ResetAllMainFloatingWindowZOrder(node->parent_);
2557 if (node->parent_ != nullptr && node->GetWindowId() == focusedWindow_ &&
2558 WindowHelper::IsMainFloatingWindow(node->GetWindowType(), dstMode)) {
2559 // if current node is mainFloatingWIndow and foucsedWindow, it should be raised to top.
2560 RaiseWindowToTop(node->GetWindowId(), node->parent_->children_);
2581 void WindowNodeContainer::UpdateCameraFloatWindowStatus(const sptr<WindowNode>& node, bool isShowing)
2583 if (node->GetWindowType() == WindowType::WINDOW_TYPE_FLOAT_CAMERA) {
2584 WindowManagerAgentController::GetInstance().UpdateCameraFloatWindowStatus(node->GetAccessTokenId(), isShowing);