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 "bridge/declarative_frontend/jsview/models/remote_window_model_impl.h"
19 #include "core/components_ng/pattern/remote_window/remote_window_model_ng.h"
20 #include "frameworks/bridge/declarative_frontend/jsview/js_utils.h"
21
22 namespace OHOS::Ace {
23 std::unique_ptr<RemoteWindowModel> RemoteWindowModel::instance_ = nullptr;
24 std::mutex RemoteWindowModel::mutex_;
25
GetInstance()26 RemoteWindowModel* RemoteWindowModel::GetInstance()
27 {
28 if (!instance_) {
29 std::lock_guard<std::mutex> lock(mutex_);
30 if (!instance_) {
31 #ifdef NG_BUILD
32 instance_.reset(new NG::RemoteWindowModelNG());
33 #else
34 if (Container::IsCurrentUseNewPipeline()) {
35 instance_.reset(new NG::RemoteWindowModelNG());
36 } else {
37 instance_.reset(new Framework::RemoteWindowModelImpl());
38 }
39 #endif
40 }
41 }
42 return instance_.get();
43 }
44 } // namespace OHOS::Ace
45
46 namespace OHOS::Ace::Framework {
Create(const JSCallbackInfo & info)47 void JSRemoteWindow::Create(const JSCallbackInfo& info)
48 {
49 std::shared_ptr<Rosen::RSNode> rsNode;
50 #ifdef ENABLE_ROSEN_BACKEND
51 if (info.Length() < 1) {
52 return;
53 }
54 rsNode = CreateRSNodeFromNapiValue(info[0]);
55 #endif
56 RemoteWindowModel::GetInstance()->Create(rsNode);
57 }
58
JSBind(BindingTarget globalObj)59 void JSRemoteWindow::JSBind(BindingTarget globalObj)
60 {
61 JSClass<JSRemoteWindow>::Declare("RemoteWindow");
62 MethodOptions opt = MethodOptions::NONE;
63 JSClass<JSRemoteWindow>::StaticMethod("create", &JSRemoteWindow::Create, opt);
64
65 JSClass<JSRemoteWindow>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
66 JSClass<JSRemoteWindow>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
67 JSClass<JSRemoteWindow>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
68 JSClass<JSRemoteWindow>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
69 JSClass<JSRemoteWindow>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
70
71 JSClass<JSRemoteWindow>::InheritAndBind<JSViewAbstract>(globalObj);
72 }
73 } // namespace OHOS::Ace::Framework
74