1 /*
2 * Copyright (c) 2022-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 "adapter/ohos/entrance/subwindow/subwindow_ohos.h"
17
18 #include "dm/display_manager.h"
19 #include "interfaces/inner_api/ace/viewport_config.h"
20 #include "render_service_client/core/ui/rs_surface_node.h"
21 #include "window.h"
22
23 #include "adapter/ohos/entrance/ace_application_info.h"
24 #include "base/geometry/rect.h"
25 #include "core/components/root/root_element.h"
26 #include "core/components_ng/base/ui_node.h"
27 #include "core/pipeline_ng/pipeline_context.h"
28 #if defined(ENABLE_ROSEN_BACKEND) and !defined(UPLOAD_GPU_DISABLED)
29 #include "adapter/ohos/entrance/ace_rosen_sync_task.h"
30 #endif
31
32 #include "adapter/ohos/entrance/ace_container.h"
33 #include "adapter/ohos/entrance/ace_view_ohos.h"
34 #include "adapter/ohos/entrance/dialog_container.h"
35 #include "adapter/ohos/entrance/utils.h"
36 #include "base/log/frame_report.h"
37 #include "base/utils/system_properties.h"
38 #include "base/utils/utils.h"
39 #include "core/common/connect_server_manager.h"
40 #include "core/common/container_scope.h"
41 #include "core/common/frontend.h"
42 #include "core/common/hdc_register.h"
43 #include "core/common/text_field_manager.h"
44 #include "core/components/bubble/bubble_component.h"
45 #include "core/components/popup/popup_component.h"
46 #ifdef ENABLE_DRAG_FRAMEWORK
47 #include "core/components_ng/render/adapter/rosen_render_context.h"
48 #endif // ENABLE_DRAG_FRAMEWORK
49 #include "core/components_ng/pattern/overlay/overlay_manager.h"
50 #include "core/components_ng/render/adapter/rosen_window.h"
51 #include "frameworks/bridge/common/utils/engine_helper.h"
52 #include "frameworks/bridge/declarative_frontend/declarative_frontend.h"
53
54 namespace OHOS::Ace {
55 namespace {
56 const Rect MIN_WINDOW_HOT_AREA = Rect(0.0f, 0.0f, 1.0f, 1.0f);
57 constexpr int32_t PLATFORM_VERSION_TEN = 10;
58 } // namespace
59
60 int32_t SubwindowOhos::id_ = 0;
61 static std::atomic<int32_t> gToastDialogId = 0;
CreateSubwindow(int32_t instanceId)62 RefPtr<Subwindow> Subwindow::CreateSubwindow(int32_t instanceId)
63 {
64 LOGI("Create Subwindow, parent container id is %{public}d", instanceId);
65 return AceType::MakeRefPtr<SubwindowOhos>(instanceId);
66 }
67
SubwindowOhos(int32_t instanceId)68 SubwindowOhos::SubwindowOhos(int32_t instanceId) : windowId_(id_), parentContainerId_(instanceId)
69 {
70 SetSubwindowId(windowId_);
71 id_++;
72 }
73
InitContainer()74 void SubwindowOhos::InitContainer()
75 {
76 LOGI("Subwindow start initialize container");
77 auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_);
78 CHECK_NULL_VOID(parentContainer);
79 if (!window_) {
80 LOGI("Window is null, need create a new window");
81 OHOS::sptr<OHOS::Rosen::WindowOption> windowOption = new OHOS::Rosen::WindowOption();
82 auto parentWindowName = parentContainer->GetWindowName();
83 auto parentWindowId = parentContainer->GetWindowId();
84 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
85 sptr<OHOS::Rosen::Window> parentWindow = parentContainer->GetUIWindow(parentContainerId_);
86 CHECK_NULL_VOID_NOLOG(parentWindow);
87 parentWindow_ = parentWindow;
88 auto windowType = parentWindow->GetType();
89 LOGI("Find parent window success, name: %{public}s, windowId: %{public}u, type: %{public}u",
90 parentWindow->GetWindowName().c_str(), parentWindow->GetWindowId(), static_cast<uint32_t>(windowType));
91 if (parentContainer->IsScenceBoardWindow() || windowType == Rosen::WindowType::WINDOW_TYPE_DESKTOP) {
92 windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_FLOAT);
93 } else if (windowType >= Rosen::WindowType::SYSTEM_WINDOW_BASE) {
94 windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_SYSTEM_SUB_WINDOW);
95 windowOption->SetParentId(parentWindowId);
96 } else if (GetAboveApps()) {
97 windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_TOAST);
98 } else {
99 windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_SUB_WINDOW);
100 windowOption->SetParentId(parentWindowId);
101 }
102 windowOption->SetWindowRect({ 0, 0, defaultDisplay->GetWidth(), defaultDisplay->GetHeight() });
103 windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FLOATING);
104 window_ = OHOS::Rosen::Window::Create("ARK_APP_SUBWINDOW_" + parentWindowName + std::to_string(windowId_),
105 windowOption, parentWindow->GetContext());
106 CHECK_NULL_VOID(window_);
107 }
108 std::string url = "";
109 auto subSurface = window_->GetSurfaceNode();
110 CHECK_NULL_VOID(subSurface);
111 subSurface->SetShadowElevation(0.0f);
112 window_->SetUIContent(url, nullptr, nullptr, false);
113 childContainerId_ = SubwindowManager::GetInstance()->GetContainerId(window_->GetWindowId());
114 SubwindowManager::GetInstance()->AddParentContainerId(childContainerId_, parentContainerId_);
115
116 auto container = Platform::AceContainer::GetContainer(childContainerId_);
117 CHECK_NULL_VOID(container);
118
119 container->SetParentId(parentContainerId_);
120 container->GetSettings().SetUsingSharedRuntime(true);
121 container->SetSharedRuntime(parentContainer->GetSharedRuntime());
122 container->Initialize();
123 container->SetAssetManager(parentContainer->GetAssetManager());
124 container->SetResourceConfiguration(parentContainer->GetResourceConfiguration());
125 container->SetPackagePathStr(parentContainer->GetPackagePathStr());
126 container->SetHapPath(parentContainer->GetHapPath());
127 container->SetIsSubContainer(true);
128 container->InitializeSubContainer(parentContainerId_);
129 ViewportConfig config;
130 // create ace_view
131 auto* aceView =
132 Platform::AceViewOhos::CreateView(childContainerId_, false, container->GetSettings().usePlatformAsUIThread);
133 Platform::AceViewOhos::SurfaceCreated(aceView, window_);
134
135 int32_t width = static_cast<int32_t>(window_->GetRequestRect().width_);
136 int32_t height = static_cast<int32_t>(window_->GetRequestRect().height_);
137 auto parentPipeline = parentContainer->GetPipelineContext();
138 CHECK_NULL_VOID(parentPipeline);
139 auto density = parentPipeline->GetDensity();
140 LOGI("UIContent Initialize: width: %{public}d, height: %{public}d, density: %{public}lf", width, height, density);
141
142 Ace::Platform::UIEnvCallback callback = nullptr;
143 // set view
144 Platform::AceContainer::SetView(aceView, density, width, height, window_, callback);
145 Platform::AceViewOhos::SurfaceChanged(aceView, width, height, config.Orientation());
146
147 #ifdef ENABLE_ROSEN_BACKEND
148 if (SystemProperties::GetRosenBackendEnabled()) {
149 rsUiDirector = OHOS::Rosen::RSUIDirector::Create();
150 if (rsUiDirector != nullptr) {
151 rsUiDirector->SetRSSurfaceNode(window_->GetSurfaceNode());
152 auto context = DynamicCast<PipelineContext>(container->GetPipelineContext());
153 if (context != nullptr) {
154 LOGI("Init RSUIDirector");
155 context->SetRSUIDirector(rsUiDirector);
156 }
157 rsUiDirector->Init();
158 LOGI("UIContent Init Rosen Backend");
159 }
160 }
161 #endif
162 if (container->IsCurrentUseNewPipeline()) {
163 auto subPipelineContextNG = AceType::DynamicCast<NG::PipelineContext>(
164 Platform::AceContainer::GetContainer(childContainerId_)->GetPipelineContext());
165 CHECK_NULL_VOID(subPipelineContextNG);
166 subPipelineContextNG->SetParentPipeline(parentContainer->GetPipelineContext());
167 subPipelineContextNG->SetupSubRootElement();
168 subPipelineContextNG->SetMinPlatformVersion(parentPipeline->GetMinPlatformVersion());
169 return;
170 }
171 auto subPipelineContext =
172 DynamicCast<PipelineContext>(Platform::AceContainer::GetContainer(childContainerId_)->GetPipelineContext());
173 CHECK_NULL_VOID(subPipelineContext);
174 subPipelineContext->SetParentPipeline(parentContainer->GetPipelineContext());
175 subPipelineContext->SetupSubRootElement();
176 subPipelineContext->SetMinPlatformVersion(parentPipeline->GetMinPlatformVersion());
177 }
178
GetChildPipelineContext() const179 RefPtr<PipelineBase> SubwindowOhos::GetChildPipelineContext() const
180 {
181 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
182 CHECK_NULL_RETURN(aceContainer, nullptr);
183 return aceContainer->GetPipelineContext();
184 }
185
ResizeWindow()186 void SubwindowOhos::ResizeWindow()
187 {
188 LOGI("SubwindowOhos::ResizeWindow");
189 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
190 CHECK_NULL_VOID(defaultDisplay);
191 auto ret = window_->Resize(defaultDisplay->GetWidth(), defaultDisplay->GetHeight());
192 if (ret != Rosen::WMError::WM_OK) {
193 LOGE("Resize window by default display failed with errCode: %{public}d", static_cast<int32_t>(ret));
194 return;
195 }
196 LOGI("SubwindowOhos window rect is resized to x: %{public}d, y: %{public}d, width: %{public}u, height: %{public}u",
197 window_->GetRect().posX_, window_->GetRect().posY_, window_->GetRect().width_, window_->GetRect().height_);
198 }
199
GetRect()200 NG::RectF SubwindowOhos::GetRect()
201 {
202 NG::RectF rect;
203 CHECK_NULL_RETURN(window_, rect);
204 rect.SetRect(
205 window_->GetRect().posX_, window_->GetRect().posY_, window_->GetRect().width_, window_->GetRect().height_);
206 return rect;
207 }
208
ShowPopup(const RefPtr<Component> & newComponent,bool disableTouchEvent)209 void SubwindowOhos::ShowPopup(const RefPtr<Component>& newComponent, bool disableTouchEvent)
210 {
211 ShowWindow();
212 auto stack = GetStack();
213 CHECK_NULL_VOID(stack);
214 auto popup = AceType::DynamicCast<TweenComponent>(newComponent);
215 CHECK_NULL_VOID(popup);
216 stack->PopPopup(popup->GetId());
217 stack->PushComponent(newComponent, disableTouchEvent);
218 auto bubble = AceType::DynamicCast<BubbleComponent>(popup->GetChild());
219 if (bubble) {
220 bubble->SetWeakStack(WeakClaim(RawPtr(stack)));
221 }
222 }
223
CancelPopup(const std::string & id)224 bool SubwindowOhos::CancelPopup(const std::string& id)
225 {
226 auto stack = GetStack();
227 CHECK_NULL_RETURN_NOLOG(stack, false);
228 stack->PopPopup(id);
229 auto context = stack->GetContext().Upgrade();
230 CHECK_NULL_RETURN_NOLOG(context, false);
231 context->FlushPipelineImmediately();
232 HideWindow();
233 return true;
234 }
235
ShowPopupNG(int32_t targetId,const NG::PopupInfo & popupInfo)236 void SubwindowOhos::ShowPopupNG(int32_t targetId, const NG::PopupInfo& popupInfo)
237 {
238 LOGI("Subwindow ShowPopup.");
239 popupTargetId_ = targetId;
240 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
241 CHECK_NULL_VOID(aceContainer);
242 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
243 CHECK_NULL_VOID(context);
244 auto overlayManager = context->GetOverlayManager();
245 CHECK_NULL_VOID(overlayManager);
246 ShowWindow(false);
247 ResizeWindow();
248 ContainerScope scope(childContainerId_);
249 overlayManager->ShowPopup(targetId, popupInfo);
250 }
251
HidePopupNG(int32_t targetId)252 void SubwindowOhos::HidePopupNG(int32_t targetId)
253 {
254 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
255 CHECK_NULL_VOID(aceContainer);
256 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
257 CHECK_NULL_VOID(context);
258 auto overlayManager = context->GetOverlayManager();
259 CHECK_NULL_VOID(overlayManager);
260 auto popupInfo = overlayManager->GetPopupInfo(targetId == -1 ? popupTargetId_ : targetId);
261 popupInfo.popupId = -1;
262 popupInfo.markNeedUpdate = true;
263 ContainerScope scope(childContainerId_);
264 overlayManager->HidePopup(targetId == -1 ? popupTargetId_ : targetId, popupInfo);
265 context->FlushPipelineImmediately();
266 }
267
GetPopupInfoNG(int32_t targetId,NG::PopupInfo & popupInfo)268 void SubwindowOhos::GetPopupInfoNG(int32_t targetId, NG::PopupInfo& popupInfo)
269 {
270 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
271 CHECK_NULL_VOID(aceContainer);
272 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
273 CHECK_NULL_VOID(context);
274 auto overlayManager = context->GetOverlayManager();
275 CHECK_NULL_VOID(overlayManager);
276 popupInfo = overlayManager->GetPopupInfo(targetId);
277 }
278
GetOverlayManager()279 const RefPtr<NG::OverlayManager> SubwindowOhos::GetOverlayManager()
280 {
281 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
282 CHECK_NULL_RETURN(aceContainer, nullptr);
283 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
284 CHECK_NULL_RETURN(context, nullptr);
285 return context->GetOverlayManager();
286 }
287
ShowWindow(bool needFocus)288 void SubwindowOhos::ShowWindow(bool needFocus)
289 {
290 CHECK_NULL_VOID(window_);
291 if (isShowed_) {
292 LOGI("subwindow id:%{public}u is on display", window_->GetWindowId());
293 if (needFocus) {
294 window_->SetFocusable(needFocus);
295 RequestFocus();
296 }
297 return;
298 }
299 LOGI("Show subwindow id:%{public}u", window_->GetWindowId());
300
301 // Set min window hot area so that sub window can transparent event.
302 std::vector<Rect> rects;
303 rects.emplace_back(MIN_WINDOW_HOT_AREA);
304 SetHotAreas(rects, -1);
305 window_->SetNeedDefaultAnimation(false);
306 auto ret = window_->SetFocusable(needFocus);
307 if (ret != OHOS::Rosen::WMError::WM_OK) {
308 LOGE("subwindow id:%{public}u set focusable %{public}d failed with WMError: %{public}d", window_->GetWindowId(),
309 needFocus, static_cast<int32_t>(ret));
310 }
311 ret = window_->Show();
312 if (ret != OHOS::Rosen::WMError::WM_OK) {
313 LOGE("Show subwindow id:%{public}u failed with WMError: %{public}d", window_->GetWindowId(),
314 static_cast<int32_t>(ret));
315 return;
316 }
317 if (needFocus) {
318 RequestFocus();
319 }
320 LOGI("Show subwindow id:%{public}u successfully.", window_->GetWindowId());
321
322 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
323 CHECK_NULL_VOID(aceContainer);
324 auto context = aceContainer->GetPipelineContext();
325 CHECK_NULL_VOID(context);
326 AccessibilityEvent event;
327 event.type = AccessibilityEventType::PAGE_CHANGE;
328 event.windowId = context->GetWindowId();
329 event.windowChangeTypes = WINDOW_UPDATE_ADDED;
330 context->SendEventToAccessibility(event);
331 isShowed_ = true;
332 SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this));
333 }
334
HideWindow()335 void SubwindowOhos::HideWindow()
336 {
337 CHECK_NULL_VOID(window_);
338 LOGI("Hide the subwindow %{public}s", window_->GetWindowName().c_str());
339
340 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
341 CHECK_NULL_VOID(aceContainer);
342
343 if (Container::IsCurrentUseNewPipeline()) {
344 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
345 CHECK_NULL_VOID(context);
346 auto rootNode = context->GetRootElement();
347 CHECK_NULL_VOID(rootNode);
348 if (!rootNode->GetChildren().empty()) {
349 LOGD("there are still nodes mounted on root in subwindow");
350 auto lastChildId = rootNode->GetLastChild()->GetId();
351 if (hotAreasMap_.find(lastChildId) != hotAreasMap_.end()) {
352 auto hotAreaRect = hotAreasMap_[lastChildId];
353 OHOS::Rosen::WMError ret = window_->SetTouchHotAreas(hotAreaRect);
354 if (ret != OHOS::Rosen::WMError::WM_OK) {
355 LOGW("Set hot areas failed with errCode: %{public}d", static_cast<int32_t>(ret));
356 }
357 }
358 return;
359 }
360 auto focusHub = rootNode->GetFocusHub();
361 CHECK_NULL_VOID(focusHub);
362 focusHub->SetIsDefaultHasFocused(false);
363 } else {
364 auto context = DynamicCast<PipelineContext>(aceContainer->GetPipelineContext());
365 CHECK_NULL_VOID(context);
366 auto rootNode = context->GetRootElement();
367 CHECK_NULL_VOID(rootNode);
368 rootNode->SetIsDefaultHasFocused(false);
369 }
370
371 if (window_->IsFocused()) {
372 auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_);
373 CHECK_NULL_VOID(parentContainer);
374 auto parentWindowName = parentContainer->GetWindowName();
375 sptr<OHOS::Rosen::Window> parentWindow = OHOS::Rosen::Window::Find(parentWindowName);
376 CHECK_NULL_VOID(parentWindow);
377 parentWindow->RequestFocus();
378 }
379
380 OHOS::Rosen::WMError ret = window_->Hide();
381 auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_);
382 CHECK_NULL_VOID(parentContainer);
383 if (parentContainer->IsScenceBoardWindow()) {
384 window_->SetTouchable(true);
385 }
386
387 if (ret != OHOS::Rosen::WMError::WM_OK) {
388 LOGE("Hide window failed with errCode: %{public}d", static_cast<int32_t>(ret));
389 return;
390 }
391 isShowed_ = false;
392 LOGI("Hide the subwindow successfully.");
393 auto context = aceContainer->GetPipelineContext();
394 CHECK_NULL_VOID(context);
395 AccessibilityEvent event;
396 event.type = AccessibilityEventType::PAGE_CHANGE;
397 event.windowId = context->GetWindowId();
398 event.windowChangeTypes = WINDOW_UPDATE_REMOVED;
399 context->SendEventToAccessibility(event);
400 }
401
AddMenu(const RefPtr<Component> & newComponent)402 void SubwindowOhos::AddMenu(const RefPtr<Component>& newComponent)
403 {
404 LOGI("Subwindow push new component start.");
405 auto stack = GetStack();
406 CHECK_NULL_VOID(stack);
407 // Push the component
408 stack->PopMenu();
409 stack->PushComponent(newComponent);
410 popup_ = AceType::DynamicCast<SelectPopupComponent>(newComponent);
411 if (!popup_) {
412 LOGE("Add menu failed, this is not a popup component.");
413 }
414 LOGI("Subwindow push new component end.");
415 }
416
ClearMenu()417 void SubwindowOhos::ClearMenu()
418 {
419 LOGI("Subwindow Clear menu start.");
420 auto stack = GetStack();
421 CHECK_NULL_VOID(stack);
422 // Pop the component
423 stack->PopMenu();
424 auto context = stack->GetContext().Upgrade();
425 CHECK_NULL_VOID(context);
426 context->FlushPipelineImmediately();
427 HideWindow();
428 LOGI("Subwindow clear menu end.");
429 }
430
ShowMenuNG(const RefPtr<NG::FrameNode> menuNode,int32_t targetId,const NG::OffsetF & offset)431 void SubwindowOhos::ShowMenuNG(const RefPtr<NG::FrameNode> menuNode, int32_t targetId, const NG::OffsetF& offset)
432 {
433 LOGI("SubwindowOhos::ShowMenuNG");
434 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
435 CHECK_NULL_VOID(aceContainer);
436 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
437 CHECK_NULL_VOID(context);
438 auto overlay = context->GetOverlayManager();
439 CHECK_NULL_VOID(overlay);
440 ShowWindow();
441 ResizeWindow();
442 overlay->ShowMenuInSubWindow(targetId, offset, menuNode);
443 }
444
HideMenuNG()445 void SubwindowOhos::HideMenuNG()
446 {
447 if (!isShowed_) {
448 return;
449 }
450 isShowed_ = false;
451 LOGI("SubwindowOhos::HideMenuNG");
452 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
453 CHECK_NULL_VOID(aceContainer);
454 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
455 CHECK_NULL_VOID(context);
456 auto overlay = context->GetOverlayManager();
457 CHECK_NULL_VOID(overlay);
458 ContainerScope scope(childContainerId_);
459 overlay->HideMenuInSubWindow();
460 }
461
HideMenuNG(const RefPtr<NG::FrameNode> & menu,int32_t targetId)462 void SubwindowOhos::HideMenuNG(const RefPtr<NG::FrameNode>& menu, int32_t targetId)
463 {
464 if (!isShowed_) {
465 return;
466 }
467 isShowed_ = false;
468 LOGI("SubwindowOhos::HideMenuNG for target id %{public}d", targetId);
469 targetId_ = targetId;
470 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
471 CHECK_NULL_VOID(aceContainer);
472 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
473 CHECK_NULL_VOID(context);
474 auto overlay = context->GetOverlayManager();
475 CHECK_NULL_VOID(overlay);
476 overlay->HideMenuInSubWindow(menu, targetId_);
477 #ifdef ENABLE_DRAG_FRAMEWORK
478 HideEventColumn();
479 HidePixelMap(false, 0, 0, false);
480 HideFilter();
481 #endif // ENABLE_DRAG_FRAMEWORK
482 }
483
ClearMenuNG(bool inWindow)484 void SubwindowOhos::ClearMenuNG(bool inWindow)
485 {
486 LOGI("SubwindowOhos::ClearMenuNG");
487 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
488 CHECK_NULL_VOID(aceContainer);
489 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
490 CHECK_NULL_VOID(context);
491 auto overlay = context->GetOverlayManager();
492 CHECK_NULL_VOID(overlay);
493 overlay->CleanMenuInSubWindow();
494 HideWindow();
495 context->FlushPipelineImmediately();
496 #ifdef ENABLE_DRAG_FRAMEWORK
497 if (inWindow) {
498 HideEventColumn();
499 }
500 HidePixelMap();
501 HideFilter();
502 #endif // ENABLE_DRAG_FRAMEWORK
503 }
504
ShowMenu(const RefPtr<Component> & newComponent)505 void SubwindowOhos::ShowMenu(const RefPtr<Component>& newComponent)
506 {
507 LOGI("Show the menu");
508 ShowWindow();
509 AddMenu(newComponent);
510 }
511
CloseMenu()512 void SubwindowOhos::CloseMenu()
513 {
514 LOGI("Close the menu");
515 if (!isShowed_) {
516 LOGW("Subwindow is not showed.");
517 return;
518 }
519 if (popup_) {
520 popup_->CloseContextMenu();
521 }
522 }
523
GetStack()524 RefPtr<StackElement> SubwindowOhos::GetStack()
525 {
526 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
527 CHECK_NULL_RETURN(aceContainer, nullptr);
528
529 auto context = DynamicCast<PipelineContext>(aceContainer->GetPipelineContext());
530 CHECK_NULL_RETURN(context, nullptr);
531 return context->GetLastStack();
532 }
533
SetHotAreas(const std::vector<Rect> & rects,int32_t overlayId)534 void SubwindowOhos::SetHotAreas(const std::vector<Rect>& rects, int32_t overlayId)
535 {
536 LOGI("Set hot areas for window.");
537 CHECK_NULL_VOID(window_);
538
539 std::vector<Rosen::Rect> hotAreas;
540 Rosen::Rect rosenRect {};
541 for (const auto& rect : rects) {
542 RectConverter(rect, rosenRect);
543 hotAreas.emplace_back(rosenRect);
544 }
545 if (overlayId >= 0) {
546 hotAreasMap_[overlayId] = hotAreas;
547 }
548
549 OHOS::Rosen::WMError ret = window_->SetTouchHotAreas(hotAreas);
550 if (ret != OHOS::Rosen::WMError::WM_OK) {
551 LOGE("Set hot areas failed with errCode: %{public}d", static_cast<int32_t>(ret));
552 return;
553 }
554 LOGI("Set hot areas successfully.");
555 }
556
RectConverter(const Rect & rect,Rosen::Rect & rosenRect)557 void SubwindowOhos::RectConverter(const Rect& rect, Rosen::Rect& rosenRect)
558 {
559 rosenRect.posX_ = static_cast<int>(rect.GetOffset().GetX());
560 rosenRect.posY_ = static_cast<int>(rect.GetOffset().GetY());
561 rosenRect.width_ = static_cast<uint32_t>(rect.GetSize().Width());
562 rosenRect.height_ = static_cast<uint32_t>(rect.GetSize().Height());
563 LOGI("Convert rect to rosenRect, x is %{public}d, y is %{public}d, width is %{public}d, height is %{public}d",
564 rosenRect.posX_, rosenRect.posY_, rosenRect.width_, rosenRect.height_);
565 }
566
ShowDialogNG(const DialogProperties & dialogProps,std::function<void ()> && buildFunc)567 RefPtr<NG::FrameNode> SubwindowOhos::ShowDialogNG(
568 const DialogProperties& dialogProps, std::function<void()>&& buildFunc)
569 {
570 LOGI("SubwindowOhos::ShowDialogNG");
571 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
572 CHECK_NULL_RETURN(aceContainer, nullptr);
573 auto context = DynamicCast<NG::PipelineContext>(aceContainer->GetPipelineContext());
574 CHECK_NULL_RETURN(context, nullptr);
575 auto overlay = context->GetOverlayManager();
576 CHECK_NULL_RETURN(overlay, nullptr);
577 ShowWindow();
578 window_->SetFullScreen(true);
579 ResizeWindow();
580 ContainerScope scope(childContainerId_);
581 return overlay->ShowDialog(dialogProps, std::move(buildFunc));
582 }
583
HideSubWindowNG()584 void SubwindowOhos::HideSubWindowNG()
585 {
586 LOGI("SubwindowOhos::HideDialogNG");
587 auto container = Container::Current();
588 CHECK_NULL_VOID(container);
589 if (container->IsDialogContainer()) {
590 if (IsToastWindow()) {
591 Platform::DialogContainer::HideWindow(Container::CurrentId());
592 } else {
593 Platform::DialogContainer::CloseWindow(Container::CurrentId());
594 Platform::DialogContainer::DestroyContainer(Container::CurrentId());
595 }
596 } else {
597 HideWindow();
598 }
599 }
600
GetToastDialogWindowProperty(int32_t & width,int32_t & height,int32_t & posX,int32_t & posY,float & density) const601 void SubwindowOhos::GetToastDialogWindowProperty(
602 int32_t& width, int32_t& height, int32_t& posX, int32_t& posY, float& density) const
603 {
604 auto defaultDisplay = Rosen::DisplayManager::GetInstance().GetDefaultDisplay();
605 if (defaultDisplay) {
606 posX = 0;
607 posY = 0;
608 width = defaultDisplay->GetWidth();
609 height = defaultDisplay->GetHeight();
610 density = defaultDisplay->GetVirtualPixelRatio();
611 }
612 LOGI("Toast posX: %{public}d, posY: %{public}d, width: %{public}d, height: %{public}d, density: %{public}f", posX,
613 posY, width, height, density);
614 }
615
InitToastDialogWindow(int32_t width,int32_t height,int32_t posX,int32_t posY,bool isToast)616 bool SubwindowOhos::InitToastDialogWindow(int32_t width, int32_t height, int32_t posX, int32_t posY, bool isToast)
617 {
618 OHOS::sptr<OHOS::Rosen::WindowOption> windowOption = new OHOS::Rosen::WindowOption();
619 if (isToast) {
620 windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_TOAST);
621 } else {
622 windowOption->SetWindowType(Rosen::WindowType::WINDOW_TYPE_APP_MAIN_WINDOW);
623 }
624 windowOption->SetWindowRect({ posX, posY, width, height });
625 windowOption->SetWindowMode(Rosen::WindowMode::WINDOW_MODE_FULLSCREEN);
626 windowOption->SetFocusable(!isToast);
627 int32_t dialogId = gToastDialogId.fetch_add(1, std::memory_order_relaxed);
628 std::string windowName = "ARK_APP_SUBWINDOW_TOAST_DIALOG_" + std::to_string(dialogId);
629 dialogWindow_ = OHOS::Rosen::Window::Create(windowName, windowOption);
630 CHECK_NULL_RETURN(dialogWindow_, false);
631 dialogWindow_->SetLayoutFullScreen(true);
632 LOGI("SubwindowOhos::InitToastDialogWindow end");
633 return true;
634 }
635
InitToastDialogView(int32_t width,int32_t height,float density)636 bool SubwindowOhos::InitToastDialogView(int32_t width, int32_t height, float density)
637 {
638 LOGI("SubwindowOhos::InitToastDialogView begin");
639 dialogWindow_->SetUIContent("", nullptr, nullptr, false);
640 childContainerId_ = SubwindowManager::GetInstance()->GetContainerId(dialogWindow_->GetWindowId());
641 SubwindowManager::GetInstance()->AddParentContainerId(childContainerId_, parentContainerId_);
642 ContainerScope scope(childContainerId_);
643
644 auto container = Platform::DialogContainer::GetContainer(childContainerId_);
645 CHECK_NULL_RETURN(container, false);
646 // create ace_view
647 auto* aceView = Platform::AceViewOhos::CreateView(childContainerId_, true, true);
648 Platform::AceViewOhos::SurfaceCreated(aceView, dialogWindow_);
649 // set view
650 Platform::DialogContainer::SetView(aceView, density, width, height, dialogWindow_);
651 Ace::Platform::DialogContainer::SetUIWindow(childContainerId_, dialogWindow_);
652 ViewportConfig config(width, height, density);
653 Platform::AceViewOhos::SetViewportMetrics(aceView, config);
654 Platform::AceViewOhos::SurfaceChanged(aceView, width, height, 0);
655
656 #ifdef ENABLE_ROSEN_BACKEND
657 if (SystemProperties::GetRosenBackendEnabled()) {
658 rsUiDirector = OHOS::Rosen::RSUIDirector::Create();
659 if (rsUiDirector != nullptr) {
660 rsUiDirector->SetRSSurfaceNode(dialogWindow_->GetSurfaceNode());
661 auto context = DynamicCast<PipelineContext>(container->GetPipelineContext());
662 if (context != nullptr) {
663 LOGI("Init RSUIDirector");
664 context->SetRSUIDirector(rsUiDirector);
665 }
666 rsUiDirector->Init();
667 LOGI("UIContent Init Rosen Backend");
668 }
669 }
670 #endif
671
672 auto pipelineContext = container->GetPipelineContext();
673 CHECK_NULL_RETURN(pipelineContext, false);
674 pipelineContext->SetupRootElement();
675 auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_);
676 if (parentContainer) {
677 auto parentPipeline = parentContainer->GetPipelineContext();
678 CHECK_NULL_RETURN(parentPipeline, false);
679 pipelineContext->SetMinPlatformVersion(parentPipeline->GetMinPlatformVersion());
680 } else {
681 pipelineContext->SetMinPlatformVersion(PLATFORM_VERSION_TEN);
682 }
683 LOGI("SubwindowOhos::InitToastDialogView end");
684 return true;
685 }
686
CreateEventRunner()687 bool SubwindowOhos::CreateEventRunner()
688 {
689 if (!eventLoop_) {
690 eventLoop_ = AppExecFwk::EventRunner::Create("Subwindow_Toast_Dialog");
691 CHECK_NULL_RETURN_NOLOG(eventLoop_, false);
692 handler_ = std::make_shared<AppExecFwk::EventHandler>(eventLoop_);
693 CHECK_NULL_RETURN_NOLOG(handler_, false);
694 }
695 return true;
696 }
697
ShowToastForAbility(const std::string & message,int32_t duration,const std::string & bottom)698 void SubwindowOhos::ShowToastForAbility(const std::string& message, int32_t duration, const std::string& bottom)
699 {
700 LOGI("SubwindowOhos::ShowToastForAbility Show the toast");
701 SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this));
702
703 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
704 if (!aceContainer) {
705 LOGE("Get container failed, it is null");
706 return;
707 }
708
709 auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId());
710 auto delegate = engine->GetFrontend();
711 if (!delegate) {
712 LOGE("can not get delegate.");
713 return;
714 }
715 ContainerScope scope(childContainerId_);
716 auto parentContainer = Platform::AceContainer::GetContainer(parentContainerId_);
717 CHECK_NULL_VOID(parentContainer);
718 if (parentContainer->IsScenceBoardWindow()) {
719 ShowWindow(false);
720 ResizeWindow();
721 window_->SetTouchable(false);
722 }
723 delegate->ShowToast(message, duration, bottom);
724 }
725
ShowToastForService(const std::string & message,int32_t duration,const std::string & bottom)726 void SubwindowOhos::ShowToastForService(const std::string& message, int32_t duration, const std::string& bottom)
727 {
728 LOGI("SubwindowOhos::ShowToastForService begin");
729 bool ret = CreateEventRunner();
730 if (!ret) {
731 return;
732 }
733
734 SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this));
735 auto showDialogCallback = [message, duration, bottom]() {
736 int32_t posX = 0;
737 int32_t posY = 0;
738 int32_t width = 0;
739 int32_t height = 0;
740 float density = 1.0f;
741 auto subwindowOhos =
742 AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow());
743 CHECK_NULL_VOID(subwindowOhos);
744 subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density);
745 auto childContainerId = subwindowOhos->GetChildContainerId();
746 auto window = Platform::DialogContainer::GetUIWindow(childContainerId);
747 auto dialogWindow = subwindowOhos->GetDialogWindow();
748 if (!dialogWindow || !window || !subwindowOhos->IsToastWindow()) {
749 bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY, true);
750 if (!ret) {
751 return;
752 }
753 ret = subwindowOhos->InitToastDialogView(width, height, density);
754 if (!ret) {
755 return;
756 }
757 subwindowOhos->SetIsToastWindow(true);
758 }
759 childContainerId = subwindowOhos->GetChildContainerId();
760 ContainerScope scope(childContainerId);
761 subwindowOhos->UpdateAceView(width, height, density, childContainerId);
762
763 Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height, true);
764 Platform::DialogContainer::ShowToast(childContainerId, message, duration, bottom);
765 };
766 if (!handler_->PostTask(showDialogCallback)) {
767 LOGE("Post sync task error");
768 return;
769 }
770 LOGI("SubwindowOhos::ShowToastForService end");
771 }
772
ShowToast(const std::string & message,int32_t duration,const std::string & bottom)773 void SubwindowOhos::ShowToast(const std::string& message, int32_t duration, const std::string& bottom)
774 {
775 if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) {
776 ShowToastForService(message, duration, bottom);
777 } else {
778 ShowToastForAbility(message, duration, bottom);
779 }
780 }
781
ShowDialogForAbility(const std::string & title,const std::string & message,const std::vector<ButtonInfo> & buttons,bool autoCancel,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)782 void SubwindowOhos::ShowDialogForAbility(const std::string& title, const std::string& message,
783 const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
784 const std::set<std::string>& callbacks)
785 {
786 LOGI("Show the dialog");
787 SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this));
788
789 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
790 if (!aceContainer) {
791 LOGE("Get container failed, it is null");
792 return;
793 }
794
795 auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId());
796 auto delegate = engine->GetFrontend();
797 if (!delegate) {
798 LOGE("can not get delegate.");
799 return;
800 }
801 delegate->ShowDialog(title, message, buttons, autoCancel, std::move(callback), callbacks);
802 }
803
ShowDialogForService(const std::string & title,const std::string & message,const std::vector<ButtonInfo> & buttons,bool autoCancel,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)804 void SubwindowOhos::ShowDialogForService(const std::string& title, const std::string& message,
805 const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
806 const std::set<std::string>& callbacks)
807 {
808 LOGI("SubwindowOhos::ShowDialogForService begin");
809 bool ret = CreateEventRunner();
810 if (!ret) {
811 return;
812 }
813
814 SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this));
815 auto showDialogCallback = [title, message, &buttons, autoCancel, callbackParam = std::move(callback),
816 &callbacks]() {
817 int32_t posX = 0;
818 int32_t posY = 0;
819 int32_t width = 0;
820 int32_t height = 0;
821 float density = 1.0f;
822 auto subwindowOhos =
823 AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow());
824 CHECK_NULL_VOID(subwindowOhos);
825 subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density);
826 bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY);
827 if (!ret) {
828 return;
829 }
830 ret = subwindowOhos->InitToastDialogView(width, height, density);
831 if (!ret) {
832 return;
833 }
834 auto childContainerId = subwindowOhos->GetChildContainerId();
835 ContainerScope scope(childContainerId);
836 Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height);
837 Platform::DialogContainer::ShowDialog(childContainerId, title, message, buttons, autoCancel,
838 std::move(const_cast<std::function<void(int32_t, int32_t)>&&>(callbackParam)), callbacks);
839 };
840 isToastWindow_ = false;
841 if (!handler_->PostTask(showDialogCallback)) {
842 LOGE("Post sync task error");
843 return;
844 }
845 LOGI("SubwindowOhos::ShowDialogForService end");
846 }
847
ShowDialogForAbility(const PromptDialogAttr & dialogAttr,const std::vector<ButtonInfo> & buttons,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)848 void SubwindowOhos::ShowDialogForAbility(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
849 std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks)
850 {
851 LOGI("Show the dialog");
852 SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this));
853
854 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
855 if (!aceContainer) {
856 LOGE("Get container failed, it is null");
857 return;
858 }
859
860 auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId());
861 auto delegate = engine->GetFrontend();
862 if (!delegate) {
863 LOGE("can not get delegate.");
864 return;
865 }
866 delegate->ShowDialog(dialogAttr, buttons, std::move(callback), callbacks);
867 }
868
ShowDialogForService(const PromptDialogAttr & dialogAttr,const std::vector<ButtonInfo> & buttons,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)869 void SubwindowOhos::ShowDialogForService(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
870 std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks)
871 {
872 LOGI("SubwindowOhos::ShowDialogForService begin");
873 bool ret = CreateEventRunner();
874 if (!ret) {
875 return;
876 }
877
878 SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this));
879 auto showDialogCallback = [dialogAttr, &buttons, callbackParam = std::move(callback),
880 &callbacks]() {
881 int32_t posX = 0;
882 int32_t posY = 0;
883 int32_t width = 0;
884 int32_t height = 0;
885 float density = 1.0f;
886 auto subwindowOhos =
887 AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow());
888 CHECK_NULL_VOID(subwindowOhos);
889 subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density);
890 bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY);
891 if (!ret) {
892 return;
893 }
894 ret = subwindowOhos->InitToastDialogView(width, height, density);
895 if (!ret) {
896 return;
897 }
898 auto childContainerId = subwindowOhos->GetChildContainerId();
899 ContainerScope scope(childContainerId);
900 Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height);
901 Platform::DialogContainer::ShowDialog(childContainerId, dialogAttr, buttons,
902 std::move(const_cast<std::function<void(int32_t, int32_t)>&&>(callbackParam)), callbacks);
903 };
904 isToastWindow_ = false;
905 if (!handler_->PostTask(showDialogCallback)) {
906 LOGE("Post sync task error");
907 return;
908 }
909 LOGI("SubwindowOhos::ShowDialogForService end");
910 }
911
ShowDialog(const std::string & title,const std::string & message,const std::vector<ButtonInfo> & buttons,bool autoCancel,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)912 void SubwindowOhos::ShowDialog(const std::string& title, const std::string& message,
913 const std::vector<ButtonInfo>& buttons, bool autoCancel, std::function<void(int32_t, int32_t)>&& callback,
914 const std::set<std::string>& callbacks)
915 {
916 if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) {
917 ShowDialogForService(title, message, buttons, autoCancel, std::move(callback), callbacks);
918 } else {
919 ShowDialogForAbility(title, message, buttons, autoCancel, std::move(callback), callbacks);
920 }
921 }
922
ShowDialog(const PromptDialogAttr & dialogAttr,const std::vector<ButtonInfo> & buttons,std::function<void (int32_t,int32_t)> && callback,const std::set<std::string> & callbacks)923 void SubwindowOhos::ShowDialog(const PromptDialogAttr& dialogAttr, const std::vector<ButtonInfo>& buttons,
924 std::function<void(int32_t, int32_t)>&& callback, const std::set<std::string>& callbacks)
925 {
926 if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) {
927 ShowDialogForService(dialogAttr, buttons, std::move(callback), callbacks);
928 } else {
929 ShowDialogForAbility(dialogAttr, buttons, std::move(callback), callbacks);
930 }
931 }
932
ShowActionMenuForAbility(const std::string & title,const std::vector<ButtonInfo> & button,std::function<void (int32_t,int32_t)> && callback)933 void SubwindowOhos::ShowActionMenuForAbility(
934 const std::string& title, const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback)
935 {
936 LOGI("Show the action menu");
937 SubwindowManager::GetInstance()->SetCurrentSubwindow(AceType::Claim(this));
938
939 auto aceContainer = Platform::AceContainer::GetContainer(childContainerId_);
940 if (!aceContainer) {
941 LOGE("Get container failed, it is null");
942 return;
943 }
944
945 auto engine = EngineHelper::GetEngine(aceContainer->GetInstanceId());
946 auto delegate = engine->GetFrontend();
947 if (!delegate) {
948 LOGE("can not get delegate.");
949 return;
950 }
951 delegate->ShowActionMenu(title, button, std::move(callback));
952 }
953
ShowActionMenuForService(const std::string & title,const std::vector<ButtonInfo> & button,std::function<void (int32_t,int32_t)> && callback)954 void SubwindowOhos::ShowActionMenuForService(
955 const std::string& title, const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback)
956 {
957 LOGI("SubwindowOhos::ShowActionMenu begin");
958 bool ret = CreateEventRunner();
959 if (!ret) {
960 return;
961 }
962
963 SubwindowManager::GetInstance()->SetCurrentDialogSubwindow(AceType::Claim(this));
964 auto showDialogCallback = [title, &button, callbackParam = std::move(callback)]() {
965 int32_t posX = 0;
966 int32_t posY = 0;
967 int32_t width = 0;
968 int32_t height = 0;
969 float density = 1.0f;
970 auto subwindowOhos =
971 AceType::DynamicCast<SubwindowOhos>(SubwindowManager::GetInstance()->GetCurrentDialogWindow());
972 CHECK_NULL_VOID(subwindowOhos);
973 subwindowOhos->GetToastDialogWindowProperty(width, height, posX, posY, density);
974 bool ret = subwindowOhos->InitToastDialogWindow(width, height, posX, posY);
975 if (!ret) {
976 return;
977 }
978 ret = subwindowOhos->InitToastDialogView(width, height, density);
979 if (!ret) {
980 return;
981 }
982 auto childContainerId = subwindowOhos->GetChildContainerId();
983 ContainerScope scope(childContainerId);
984 Platform::DialogContainer::ShowToastDialogWindow(childContainerId, posX, posY, width, height);
985 Platform::DialogContainer::ShowActionMenu(childContainerId, title, button,
986 std::move(const_cast<std::function<void(int32_t, int32_t)>&&>(callbackParam)));
987 };
988 isToastWindow_ = false;
989 if (!handler_->PostTask(showDialogCallback)) {
990 LOGE("Post sync task error");
991 return;
992 }
993 LOGI("SubwindowOhos::ShowActionMenu end");
994 }
995
CloseDialog(int32_t instanceId)996 void SubwindowOhos::CloseDialog(int32_t instanceId)
997 {
998 Platform::DialogContainer::CloseWindow(instanceId);
999 }
1000
UpdateAceView(int32_t width,int32_t height,float density,int32_t containerId)1001 void SubwindowOhos::UpdateAceView(int32_t width, int32_t height, float density, int32_t containerId)
1002 {
1003 auto container = Platform::DialogContainer::GetContainer(containerId);
1004 CHECK_NULL_VOID(container);
1005 auto aceView = static_cast<Platform::AceViewOhos*>(container->GetView());
1006 CHECK_NULL_VOID(aceView);
1007 if (aceView->GetWidth() != width || aceView->GetHeight() != height) {
1008 ViewportConfig config(width, height, density);
1009 Platform::AceViewOhos::SetViewportMetrics(aceView, config);
1010 Platform::AceViewOhos::SurfaceChanged(aceView, width, height, 0);
1011 }
1012 }
1013
ShowActionMenu(const std::string & title,const std::vector<ButtonInfo> & button,std::function<void (int32_t,int32_t)> && callback)1014 void SubwindowOhos::ShowActionMenu(
1015 const std::string& title, const std::vector<ButtonInfo>& button, std::function<void(int32_t, int32_t)>&& callback)
1016 {
1017 if (parentContainerId_ >= MIN_PA_SERVICE_ID || parentContainerId_ < 0) {
1018 ShowActionMenuForService(title, button, std::move(callback));
1019 } else {
1020 ShowActionMenuForAbility(title, button, std::move(callback));
1021 }
1022 }
1023
GetParentWindowRect() const1024 Rect SubwindowOhos::GetParentWindowRect() const
1025 {
1026 Rect rect;
1027 CHECK_NULL_RETURN(parentWindow_, rect);
1028 auto parentWindowRect = parentWindow_->GetRect();
1029 return Rect(parentWindowRect.posX_, parentWindowRect.posY_, parentWindowRect.width_, parentWindowRect.height_);
1030 }
1031
RequestFocus()1032 void SubwindowOhos::RequestFocus()
1033 {
1034 if (window_->IsFocused()) {
1035 LOGI("subwindow id:%{public}u already focused", window_->GetWindowId());
1036 // already focused, no need to focus
1037 return;
1038 }
1039 OHOS::Rosen::WMError ret = window_->RequestFocus();
1040 if (ret != OHOS::Rosen::WMError::WM_OK) {
1041 LOGE("subindow id:%{public}u request focus failed with WMError: %{public}d", window_->GetWindowId(),
1042 static_cast<int32_t>(ret));
1043 return;
1044 }
1045 LOGI("subwindow id:%{public}u request focus successfully.", window_->GetWindowId());
1046 }
1047
1048 #ifdef ENABLE_DRAG_FRAMEWORK
HideFilter()1049 void SubwindowOhos::HideFilter()
1050 {
1051 auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_);
1052 CHECK_NULL_VOID(parentAceContainer);
1053 auto parentPipeline = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext());
1054 CHECK_NULL_VOID(parentPipeline);
1055 auto manager = parentPipeline->GetOverlayManager();
1056 CHECK_NULL_VOID(manager);
1057 ContainerScope scope(parentContainerId_);
1058 manager->RemoveFilter();
1059 }
1060
HidePixelMap(bool startDrag,double x,double y,bool showAnimation)1061 void SubwindowOhos::HidePixelMap(bool startDrag, double x, double y, bool showAnimation)
1062 {
1063 auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_);
1064 CHECK_NULL_VOID(parentAceContainer);
1065 auto parentPipeline = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext());
1066 CHECK_NULL_VOID(parentPipeline);
1067 auto manager = parentPipeline->GetOverlayManager();
1068 CHECK_NULL_VOID(manager);
1069 ContainerScope scope(parentContainerId_);
1070 if (showAnimation) {
1071 manager->RemovePixelMapAnimation(startDrag, x, y);
1072 } else {
1073 manager->RemovePixelMap();
1074 }
1075 }
1076
HideEventColumn()1077 void SubwindowOhos::HideEventColumn()
1078 {
1079 auto parentAceContainer = Platform::AceContainer::GetContainer(parentContainerId_);
1080 CHECK_NULL_VOID(parentAceContainer);
1081 auto parentPipeline = DynamicCast<NG::PipelineContext>(parentAceContainer->GetPipelineContext());
1082 CHECK_NULL_VOID(parentPipeline);
1083 auto manager = parentPipeline->GetOverlayManager();
1084 CHECK_NULL_VOID(manager);
1085 ContainerScope scope(parentContainerId_);
1086 manager->RemoveEventColumn();
1087 }
1088 #endif // ENABLE_DRAG_FRAMEWORK
1089 } // namespace OHOS::Ace
1090