• 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 std::mutex EllipseModel::mutex_;
27 
GetInstance()28 EllipseModel* EllipseModel::GetInstance()
29 {
30     if (!instance_) {
31         std::lock_guard<std::mutex> lock(mutex_);
32         if (!instance_) {
33 #ifdef NG_BUILD
34             instance_.reset(new NG::EllipseModelNG());
35 #else
36             if (Container::IsCurrentUseNewPipeline()) {
37                 instance_.reset(new NG::EllipseModelNG());
38             } else {
39                 instance_.reset(new Framework::EllipseModelImpl());
40             }
41 #endif
42         }
43     }
44     return instance_.get();
45 }
46 
47 } // namespace OHOS::Ace
48 
49 namespace OHOS::Ace::Framework {
50 
Create(const JSCallbackInfo & info)51 void JSEllipse::Create(const JSCallbackInfo& info)
52 {
53     EllipseModel::GetInstance()->Create();
54     JSShapeAbstract::SetSize(info);
55 }
56 
ConstructorCallback(const JSCallbackInfo & info)57 void JSEllipse::ConstructorCallback(const JSCallbackInfo& info)
58 {
59     auto ellipse = AceType::MakeRefPtr<Ellipse>();
60     if (info.Length() == 1 && info[0]->IsObject()) {
61         JSRef<JSObject> params = JSRef<JSObject>::Cast(info[0]);
62         JSRef<JSVal> width = params->GetProperty("width");
63         CalcDimension dimWidth;
64         if (ParseJsDimensionVp(width, dimWidth)) {
65             ellipse->SetWidth(dimWidth);
66         }
67         JSRef<JSVal> height = params->GetProperty("height");
68         CalcDimension dimHeight;
69         if (ParseJsDimensionVp(height, dimHeight)) {
70             ellipse->SetHeight(dimHeight);
71         }
72     }
73     auto jsEllipse = AceType::MakeRefPtr<JSEllipse>();
74     jsEllipse->SetBasicShape(ellipse);
75     jsEllipse->IncRefCount();
76     info.SetReturnValue(AceType::RawPtr(jsEllipse));
77 }
78 
DestructorCallback(JSEllipse * jsEllipse)79 void JSEllipse::DestructorCallback(JSEllipse* jsEllipse)
80 {
81     if (jsEllipse != nullptr) {
82         jsEllipse->DecRefCount();
83     }
84 }
85 
JSBind(BindingTarget globalObj)86 void JSEllipse::JSBind(BindingTarget globalObj)
87 {
88     JSClass<JSEllipse>::Declare("Ellipse");
89     MethodOptions opt = MethodOptions::NONE;
90     JSClass<JSEllipse>::StaticMethod("create", &JSEllipse::Create, opt);
91 
92     JSClass<JSEllipse>::CustomMethod("width", &JSShapeAbstract::ObjectWidth);
93     JSClass<JSEllipse>::CustomMethod("height", &JSShapeAbstract::ObjectHeight);
94     JSClass<JSEllipse>::CustomMethod("size", &JSShapeAbstract::ObjectSize);
95     JSClass<JSEllipse>::CustomMethod("offset", &JSShapeAbstract::ObjectOffset);
96     JSClass<JSEllipse>::CustomMethod("fill", &JSShapeAbstract::ObjectFill);
97     JSClass<JSEllipse>::CustomMethod("position", &JSShapeAbstract::ObjectPosition);
98 
99     JSClass<JSEllipse>::StaticMethod("onTouch", &JSInteractableView::JsOnTouch);
100     JSClass<JSEllipse>::StaticMethod("onHover", &JSInteractableView::JsOnHover);
101     JSClass<JSEllipse>::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey);
102     JSClass<JSEllipse>::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete);
103     JSClass<JSEllipse>::StaticMethod("onClick", &JSInteractableView::JsOnClick);
104     JSClass<JSEllipse>::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage);
105 
106     JSClass<JSEllipse>::InheritAndBind<JSShapeAbstract>(
107         globalObj, JSEllipse::ConstructorCallback, JSEllipse::DestructorCallback);
108 }
109 
110 } // namespace OHOS::Ace::Framework
111