1 /*
2 * Copyright (c) 2022 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 "frameworks/bridge/declarative_frontend/jsview/js_remote_window.h"
17
18 #include "core/components/remote_window/remote_window_component.h"
19 #include "core/components_ng/pattern/remote_window/remote_window_view.h"
20 #include "frameworks/bridge/declarative_frontend/jsview/js_utils.h"
21 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
22
23 namespace OHOS::Ace::Framework {
Create(const JSCallbackInfo & info)24 void JSRemoteWindow::Create(const JSCallbackInfo& info)
25 {
26 std::shared_ptr<Rosen::RSNode> rsNode;
27 #ifdef ENABLE_ROSEN_BACKEND
28 if (info.Length() < 1) {
29 LOGE("The arg is wrong, it is supposed to have atleast 1 arguments");
30 return;
31 }
32 rsNode = CreateRSNodeFromNapiValue(info[0]);
33 #endif
34
35 if (Container::IsCurrentUseNewPipeline()) {
36 NG::RemoteWindowView::Create(rsNode);
37 return;
38 }
39
40 // specialized component should be firstly pushed.
41 auto specializedComponent = AceType::MakeRefPtr<OHOS::Ace::RemoteWindowComponent>();
42 ViewStackProcessor::GetInstance()->Push(specializedComponent);
43 specializedComponent->SetExternalRSNode(rsNode);
44 }
45
JSBind(BindingTarget globalObj)46 void JSRemoteWindow::JSBind(BindingTarget globalObj)
47 {
48 JSClass<JSRemoteWindow>::Declare("RemoteWindow");
49 MethodOptions opt = MethodOptions::NONE;
50 JSClass<JSRemoteWindow>::StaticMethod("create", &JSRemoteWindow::Create, opt);
51
52 JSClass<JSRemoteWindow>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
53 JSClass<JSRemoteWindow>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
54 JSClass<JSRemoteWindow>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
55 JSClass<JSRemoteWindow>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
56 JSClass<JSRemoteWindow>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
57
58 JSClass<JSRemoteWindow>::Inherit<JSViewAbstract>();
59 JSClass<JSRemoteWindow>::Bind<>(globalObj);
60 }
61 } // namespace OHOS::Ace::Framework
62