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_circle_shape.h"
17
18 namespace OHOS::Ace::Framework {
19
ConstructorCallback(const JSCallbackInfo & info)20 void JSCircleShape::ConstructorCallback(const JSCallbackInfo& info)
21 {
22 auto circle = AceType::MakeRefPtr<Circle>();
23
24 if (info.Length() == 1 && info[0]->IsObject()) {
25 JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
26 JSRef<JSVal> width = params->GetProperty("width");
27 CalcDimension dimWidth;
28
29 if (ParseJsDimensionVpNG(width, dimWidth) && dimWidth.IsValid()) {
30 circle->SetWidth(dimWidth);
31 }
32
33 JSRef<JSVal> height = params->GetProperty("height");
34 CalcDimension dimHeight;
35
36 if (ParseJsDimensionVpNG(height, dimHeight) && dimHeight.IsValid()) {
37 circle->SetHeight(dimHeight);
38 }
39 }
40
41 auto jsCircle = AceType::MakeRefPtr<JSCircleShape>();
42 jsCircle->SetBasicShape(circle);
43 jsCircle->IncRefCount();
44 info.SetReturnValue(AceType::RawPtr(jsCircle));
45 }
46
DestructorCallback(JSCircleShape * jsCircleShape)47 void JSCircleShape::DestructorCallback(JSCircleShape* jsCircleShape)
48 {
49 if (jsCircleShape != nullptr) {
50 jsCircleShape->DecRefCount();
51 }
52 }
53
JSBind(BindingTarget globalObj)54 void JSCircleShape::JSBind(BindingTarget globalObj)
55 {
56 JSClass<JSCircleShape>::Declare("__CircleShape__");
57
58 JSClass<JSCircleShape>::CustomMethod("width", &JSShapeAbstract::ObjectWidth);
59 JSClass<JSCircleShape>::CustomMethod("height", &JSShapeAbstract::ObjectHeight);
60 JSClass<JSCircleShape>::CustomMethod("size", &JSShapeAbstract::ObjectSize);
61 JSClass<JSCircleShape>::CustomMethod("offset", &JSShapeAbstract::ObjectOffset);
62 JSClass<JSCircleShape>::CustomMethod("fill", &JSShapeAbstract::ObjectFill);
63 JSClass<JSCircleShape>::CustomMethod("position", &JSShapeAbstract::ObjectPosition);
64
65 JSClass<JSCircleShape>::InheritAndBind<JSShapeAbstract>(
66 globalObj, JSCircleShape::ConstructorCallback, JSCircleShape::DestructorCallback);
67 }
68
69 } // namespace OHOS::Ace::Framework
70