1 /*
2  * Copyright (c) 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 "bridge/cj_frontend/interfaces/cj_ffi/cj_context_menu_ffi.h"
17 
18 #include "base/subwindow/subwindow.h"
19 #include "base/subwindow/subwindow_manager.h"
20 #include "bridge/common/utils/engine_helper.h"
21 #include "core/common/container.h"
22 
23 using namespace OHOS::Ace;
24 
25 extern "C" {
FfiOHOSAceFrameworkContextMenuClose()26 void FfiOHOSAceFrameworkContextMenuClose()
27 {
28 #if defined(MULTIPLE_WINDOW_SUPPORTED)
29     SubwindowManager::GetInstance()->HideMenuNG();
30 #endif
31     // Close context menu.
32     auto container = Container::CurrentSafely();
33     if (!container) {
34         return;
35     }
36     auto context = AceType::DynamicCast<PipelineContext>(container->GetPipelineContext());
37     auto executor = container->GetTaskExecutor();
38     if (!executor) {
39         return;
40     }
41     executor->PostTask(
42         [context]() {
43             if (context) {
44                 context->CloseContextMenu();
45             }
46         },
47         TaskExecutor::TaskType::UI, "FfiOHOSAceFrameworkContextMenuClose");
48 }
49 }
50