1 /*
2 * Copyright (c) 2023 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 "session/host/include/sub_session.h"
17
18 #include "window_manager_hilog.h"
19
20 namespace OHOS::Rosen {
21 namespace {
22 constexpr HiviewDFX::HiLogLabel LABEL = { LOG_CORE, HILOG_DOMAIN_WINDOW, "SubSession" };
23 } // namespace
24
SubSession(const SessionInfo & info,const sptr<SpecificSessionCallback> & specificCallback)25 SubSession::SubSession(const SessionInfo& info, const sptr<SpecificSessionCallback>& specificCallback)
26 : SceneSession(info, specificCallback)
27 {
28 moveDragController_ = new (std::nothrow) MoveDragController(GetPersistentId());
29 SetMoveDragCallback();
30 WLOGFD("[WMSLife] Create SubSession");
31 }
32
~SubSession()33 SubSession::~SubSession()
34 {
35 WLOGD("[WMSLife] ~SubSession, id: %{public}d", GetPersistentId());
36 }
37
Show(sptr<WindowSessionProperty> property)38 WSError SubSession::Show(sptr<WindowSessionProperty> property)
39 {
40 auto task = [weakThis = wptr(this), property]() {
41 auto session = weakThis.promote();
42 if (!session) {
43 WLOGFE("[WMSSub] session is null");
44 return WSError::WS_ERROR_DESTROYED_OBJECT;
45 }
46 WLOGFI("[WMSLife] Show session, id: %{public}d", session->GetPersistentId());
47
48 // use property from client
49 if (property && property->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
50 session->GetSessionProperty()->SetAnimationFlag(static_cast<uint32_t>(WindowAnimation::CUSTOM));
51 session->NotifyIsCustomAnimationPlaying(true);
52 }
53 auto ret = session->SceneSession::Foreground(property);
54 return ret;
55 };
56 PostTask(task, "Show");
57 return WSError::WS_OK;
58 }
59
Hide()60 WSError SubSession::Hide()
61 {
62 auto task = [weakThis = wptr(this)]() {
63 auto session = weakThis.promote();
64 if (!session) {
65 WLOGFE("[WMSSub] session is null");
66 return WSError::WS_ERROR_DESTROYED_OBJECT;
67 }
68 WLOGFI("[WMSLife] Hide session, id: %{public}d", session->GetPersistentId());
69 auto ret = session->SetActive(false);
70 if (ret != WSError::WS_OK) {
71 return ret;
72 }
73 // background will remove surfaceNode, custom not execute
74 // not animation playing when already background; inactive may be animation playing
75 if (session->GetSessionProperty() &&
76 session->GetSessionProperty()->GetAnimationFlag() == static_cast<uint32_t>(WindowAnimation::CUSTOM)) {
77 session->NotifyIsCustomAnimationPlaying(true);
78 return WSError::WS_OK;
79 }
80 ret = session->SceneSession::Background();
81 return ret;
82 };
83 PostTask(task, "Hide");
84 return WSError::WS_OK;
85 }
86
ProcessPointDownSession(int32_t posX,int32_t posY)87 WSError SubSession::ProcessPointDownSession(int32_t posX, int32_t posY)
88 {
89 const auto& id = GetPersistentId();
90 WLOGFI("id: %{public}d, type: %{public}d", id, GetWindowType());
91 if (parentSession_ && parentSession_->CheckDialogOnForeground()) {
92 WLOGFI("Has dialog foreground, id: %{public}d, type: %{public}d", id, GetWindowType());
93 return WSError::WS_OK;
94 }
95 if (GetSessionProperty() && GetSessionProperty()->GetRaiseEnabled()) {
96 RaiseToAppTopForPointDown();
97 }
98 PresentFocusIfPointDown();
99 return SceneSession::ProcessPointDownSession(posX, posY);
100 }
101 } // namespace OHOS::Rosen
102