1 /*
2 * Copyright (c) 2021-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_column_split.h"
17
18 #include "bridge/declarative_frontend/jsview/js_shape_abstract.h"
19 #include "bridge/declarative_frontend/jsview/js_view_common_def.h"
20 #include "core/components_ng/pattern/linear_split/linear_split_model_ng.h"
21 #include "frameworks/bridge/declarative_frontend/jsview/js_linear_split.h"
22 #include "frameworks/bridge/declarative_frontend/view_stack_processor.h"
23
24 namespace OHOS::Ace::Framework {
25
Create()26 void JSColumnSplit::Create()
27 {
28 LinearSplitModel::GetInstance()->Create(NG::SplitType::COLUMN_SPLIT);
29 }
30
JsResizable(bool resizable)31 void JSColumnSplit::JsResizable(bool resizable)
32 {
33 LinearSplitModel::GetInstance()->SetResizable(NG::SplitType::COLUMN_SPLIT, resizable);
34 }
35
JsDivider(const JSCallbackInfo & args)36 void JSColumnSplit::JsDivider(const JSCallbackInfo& args)
37 {
38 if (args.Length() < 1 || !args[0]->IsObject()) {
39 return;
40 }
41
42 JSRef<JSObject> obj = JSRef<JSObject>::Cast(args[0]);
43 NG::ItemDivider divider;
44 ConvertFromJSValue(obj->GetProperty("startMargin"), divider.startMargin);
45 ConvertFromJSValue(obj->GetProperty("endMargin"), divider.endMargin);
46 LinearSplitModel::GetInstance()->SetDivider(NG::SplitType::COLUMN_SPLIT, divider);
47
48 args.ReturnSelf();
49 }
50
JsClip(const JSCallbackInfo & info)51 void JSColumnSplit::JsClip(const JSCallbackInfo& info)
52 {
53 if (info[0]->IsUndefined()) {
54 ViewAbstractModel::GetInstance()->SetClipEdge(true);
55 return;
56 }
57 if (info[0]->IsObject()) {
58 JSShapeAbstract* clipShape = JSRef<JSObject>::Cast(info[0])->Unwrap<JSShapeAbstract>();
59 if (clipShape == nullptr) {
60 return;
61 }
62 ViewAbstractModel::GetInstance()->SetClipShape(clipShape->GetBasicShape());
63 } else if (info[0]->IsBoolean()) {
64 ViewAbstractModel::GetInstance()->SetClipEdge(info[0]->ToBoolean());
65 }
66 }
67
JSBind(BindingTarget globalObj)68 void JSColumnSplit::JSBind(BindingTarget globalObj)
69 {
70 JSClass<JSColumnSplit>::Declare("ColumnSplit");
71 JSClass<JSColumnSplit>::StaticMethod("create", &JSColumnSplit::Create, MethodOptions::NONE);
72 JSClass<JSColumnSplit>::StaticMethod("resizeable", &JSColumnSplit::JsResizable, MethodOptions::NONE);
73 JSClass<JSColumnSplit>::StaticMethod("divider", &JSColumnSplit::JsDivider, MethodOptions::NONE);
74 JSClass<JSColumnSplit>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
75 JSClass<JSColumnSplit>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
76 JSClass<JSColumnSplit>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
77 JSClass<JSColumnSplit>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
78 JSClass<JSColumnSplit>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
79 JSClass<JSColumnSplit>::StaticMethod("onAttach", &JSInteractableView::JsOnAttach);
80 JSClass<JSColumnSplit>::StaticMethod("onAppear", &JSInteractableView::JsOnAppear);
81 JSClass<JSColumnSplit>::StaticMethod("onDetach", &JSInteractableView::JsOnDetach);
82 JSClass<JSColumnSplit>::StaticMethod("onDisAppear", &JSInteractableView::JsOnDisAppear);
83 JSClass<JSColumnSplit>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
84 JSClass<JSColumnSplit>::StaticMethod("clip", &JSColumnSplit::JsClip);
85 JSClass<JSColumnSplit>::InheritAndBind<JSContainerBase>(globalObj);
86 }
87
88 } // namespace OHOS::Ace::Framework
89