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_ellipse_shape.h"
17
18 namespace OHOS::Ace::Framework {
19
ConstructorCallback(const JSCallbackInfo & info)20 void JSEllipseShape::ConstructorCallback(const JSCallbackInfo& info)
21 {
22 auto ellipse = AceType::MakeRefPtr<Ellipse>();
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 if (ParseJsDimensionVpNG(width, dimWidth) && dimWidth.IsValid()) {
29 ellipse->SetWidth(dimWidth);
30 }
31 JSRef<JSVal> height = params->GetProperty("height");
32 CalcDimension dimHeight;
33 if (ParseJsDimensionVpNG(height, dimHeight) && dimHeight.IsValid()) {
34 ellipse->SetHeight(dimHeight);
35 }
36 }
37
38 auto jsEllipse = AceType::MakeRefPtr<JSEllipseShape>();
39 jsEllipse->SetBasicShape(ellipse);
40 jsEllipse->IncRefCount();
41 info.SetReturnValue(AceType::RawPtr(jsEllipse));
42 }
43
DestructorCallback(JSEllipseShape * jsEllipseShape)44 void JSEllipseShape::DestructorCallback(JSEllipseShape* jsEllipseShape)
45 {
46 if (jsEllipseShape != nullptr) {
47 jsEllipseShape->DecRefCount();
48 }
49 }
50
JSBind(BindingTarget globalObj)51 void JSEllipseShape::JSBind(BindingTarget globalObj)
52 {
53 JSClass<JSEllipseShape>::Declare("__EllipseShape__");
54
55 JSClass<JSEllipseShape>::CustomMethod("width", &JSShapeAbstract::ObjectWidth);
56 JSClass<JSEllipseShape>::CustomMethod("height", &JSShapeAbstract::ObjectHeight);
57 JSClass<JSEllipseShape>::CustomMethod("size", &JSShapeAbstract::ObjectSize);
58 JSClass<JSEllipseShape>::CustomMethod("offset", &JSShapeAbstract::ObjectOffset);
59 JSClass<JSEllipseShape>::CustomMethod("fill", &JSShapeAbstract::ObjectFill);
60 JSClass<JSEllipseShape>::CustomMethod("position", &JSShapeAbstract::ObjectPosition);
61
62 JSClass<JSEllipseShape>::InheritAndBind<JSShapeAbstract>(
63 globalObj, JSEllipseShape::ConstructorCallback, JSEllipseShape::DestructorCallback);
64 }
65
66 } // namespace OHOS::Ace::Framework
67