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