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 "frameworks/bridge/declarative_frontend/jsview/js_path_shape.h"
17
18 namespace OHOS::Ace::Framework {
19
ConstructorCallback(const JSCallbackInfo & info)20 void JSPathShape::ConstructorCallback(const JSCallbackInfo& info)
21 {
22 auto jsPath = AceType::MakeRefPtr<JSPathShape>();
23 auto path = AceType::MakeRefPtr<Path>();
24
25 if (info.Length() > 0 && info[0]->IsObject()) {
26 JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
27 JSRef<JSVal> commands = params->GetProperty("commands");
28
29 if (commands->IsString()) {
30 path->SetValue(commands->ToString());
31 }
32 }
33
34 jsPath->SetBasicShape(path);
35 jsPath->IncRefCount();
36 info.SetReturnValue(AceType::RawPtr(jsPath));
37 }
38
DestructorCallback(JSPathShape * jsPathShape)39 void JSPathShape::DestructorCallback(JSPathShape* jsPathShape)
40 {
41 if (jsPathShape != nullptr) {
42 jsPathShape->DecRefCount();
43 }
44 }
45
ObjectCommands(const JSCallbackInfo & info)46 void JSPathShape::ObjectCommands(const JSCallbackInfo& info)
47 {
48 info.ReturnSelf();
49 if (info.Length() > 0 && info[0]->IsString()) {
50 auto path = AceType::DynamicCast<Path>(basicShape_);
51 if (path) {
52 path->SetValue(info[0]->ToString());
53 }
54 }
55 }
56
JSBind(BindingTarget globalObj)57 void JSPathShape::JSBind(BindingTarget globalObj)
58 {
59 JSClass<JSPathShape>::Declare("__PathShape__");
60
61 JSClass<JSPathShape>::CustomMethod("commands", &JSPathShape::ObjectCommands);
62 JSClass<JSPathShape>::CustomMethod("offset", &JSShapeAbstract::ObjectOffset);
63 JSClass<JSPathShape>::CustomMethod("fill", &JSShapeAbstract::ObjectFill);
64 JSClass<JSPathShape>::CustomMethod("position", &JSShapeAbstract::ObjectPosition);
65
66 JSClass<JSPathShape>::InheritAndBind<JSShapeAbstract>(
67 globalObj, JSPathShape::ConstructorCallback, JSPathShape::DestructorCallback);
68 }
69
70 } // namespace OHOS::Ace::Framework
71