• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ellipse.h"
17 
18 #include "bridge/declarative_frontend/jsview/models/ellipse_model_impl.h"
19 #include "core/common/container.h"
20 #include "core/components_ng/pattern/shape/ellipse_model.h"
21 #include "core/components_ng/pattern/shape/ellipse_model_ng.h"
22 
23 namespace OHOS::Ace {
24 
25 std::unique_ptr<EllipseModel> EllipseModel::instance_ = nullptr;
26 
GetInstance()27 EllipseModel* EllipseModel::GetInstance()
28 {
29     if (!instance_) {
30 #ifdef NG_BUILD
31         instance_.reset(new NG::EllipseModelNG());
32 #else
33         if (Container::IsCurrentUseNewPipeline()) {
34             instance_.reset(new NG::EllipseModelNG());
35         } else {
36             instance_.reset(new Framework::EllipseModelImpl());
37         }
38 #endif
39     }
40     return instance_.get();
41 }
42 
43 } // namespace OHOS::Ace
44 
45 namespace OHOS::Ace::Framework {
46 
Create(const JSCallbackInfo & info)47 void JSEllipse::Create(const JSCallbackInfo& info)
48 {
49     EllipseModel::GetInstance()->Create();
50     JSShapeAbstract::SetSize(info);
51 }
52 
ConstructorCallback(const JSCallbackInfo & info)53 void JSEllipse::ConstructorCallback(const JSCallbackInfo& info)
54 {
55     if (info.Length() < 1) {
56         LOGE("The arg is wrong, it is supposed to have at least 1 argument");
57         return;
58     }
59     if (!info[0]->IsObject()) {
60         LOGE("The arg is not Object");
61         return;
62     }
63     auto ellipse = AceType::MakeRefPtr<Ellipse>();
64     JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
65     JSRef<JSVal> width = params->GetProperty("width");
66     Dimension dimWidth;
67     if (ParseJsDimensionVp(width, dimWidth)) {
68         ellipse->SetWidth(dimWidth);
69     }
70     JSRef<JSVal> height = params->GetProperty("height");
71     Dimension dimHeight;
72     if (ParseJsDimensionVp(height, dimHeight)) {
73         ellipse->SetHeight(dimHeight);
74     }
75 
76     auto jsEllipse = AceType::MakeRefPtr<JSEllipse>();
77     jsEllipse->SetBasicShape(ellipse);
78     jsEllipse->IncRefCount();
79     info.SetReturnValue(AceType::RawPtr(jsEllipse));
80 }
81 
DestructorCallback(JSEllipse * jsEllipse)82 void JSEllipse::DestructorCallback(JSEllipse* jsEllipse)
83 {
84     if (jsEllipse != nullptr) {
85         jsEllipse->DecRefCount();
86     }
87 }
88 
JSBind(BindingTarget globalObj)89 void JSEllipse::JSBind(BindingTarget globalObj)
90 {
91     JSClass<JSEllipse>::Declare("Ellipse");
92     MethodOptions opt = MethodOptions::NONE;
93     JSClass<JSEllipse>::StaticMethod("create", &JSEllipse::Create, opt);
94 
95     JSClass<JSEllipse>::CustomMethod("width", &JSShapeAbstract::ObjectWidth);
96     JSClass<JSEllipse>::CustomMethod("height", &JSShapeAbstract::ObjectHeight);
97     JSClass<JSEllipse>::CustomMethod("size", &JSShapeAbstract::ObjectSize);
98     JSClass<JSEllipse>::CustomMethod("offset", &JSShapeAbstract::ObjectOffset);
99     JSClass<JSEllipse>::CustomMethod("fill", &JSShapeAbstract::ObjectFill);
100 
101     JSClass<JSEllipse>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
102     JSClass<JSEllipse>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
103     JSClass<JSEllipse>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
104     JSClass<JSEllipse>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
105     JSClass<JSEllipse>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
106     JSClass<JSEllipse>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
107 
108     JSClass<JSEllipse>::Inherit<JSShapeAbstract>();
109     JSClass<JSEllipse>::Bind(globalObj, JSEllipse::ConstructorCallback, JSEllipse::DestructorCallback);
110 }
111 
112 } // namespace OHOS::Ace::Framework
113