/* * Copyright (c) 2021-2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "frameworks/bridge/declarative_frontend/jsview/js_circle.h" #include #include "bridge/declarative_frontend/jsview/models/circle_model_impl.h" #include "core/common/container.h" #include "core/components_ng/pattern/shape/circle_model.h" #include "core/components_ng/pattern/shape/circle_model_ng.h" namespace OHOS::Ace { std::unique_ptr CircleModel::instance_ = nullptr; std::mutex CircleModel::mutex_; CircleModel* CircleModel::GetInstance() { if (!instance_) { std::lock_guard lock(mutex_); if (!instance_) { #ifdef NG_BUILD instance_.reset(new NG::CircleModelNG()); #else if (Container::IsCurrentUseNewPipeline()) { instance_.reset(new NG::CircleModelNG()); } else { instance_.reset(new Framework::CircleModelImpl()); } #endif } } return instance_.get(); } } // namespace OHOS::Ace namespace OHOS::Ace::Framework { void JSCircle::Create(const JSCallbackInfo& info) { CircleModel::GetInstance()->Create(); JSShapeAbstract::SetSize(info); } void JSCircle::ConstructorCallback(const JSCallbackInfo& info) { auto circle = AceType::MakeRefPtr(); if (info.Length() == 1 && info[0]->IsObject()) { JSRef params = JSRef::Cast(info[0]); JSRef width = params->GetProperty("width"); CalcDimension dimWidth; JSRef height = params->GetProperty("height"); CalcDimension dimHeight; if (Container::LessThanAPITargetVersion(PlatformVersion::VERSION_TWELVE)) { if (ParseJsDimensionVp(width, dimWidth)) { circle->SetWidth(dimWidth); } if (ParseJsDimensionVp(height, dimHeight)) { circle->SetHeight(dimHeight); } } else { if (ParseJsDimensionVpNG(width, dimWidth) && dimWidth.IsValid()) { circle->SetWidth(dimWidth); } if (ParseJsDimensionVpNG(height, dimHeight) && dimHeight.IsValid()) { circle->SetHeight(dimHeight); } } } auto jsCircle = AceType::MakeRefPtr(); jsCircle->SetBasicShape(circle); jsCircle->IncRefCount(); info.SetReturnValue(AceType::RawPtr(jsCircle)); } void JSCircle::DestructorCallback(JSCircle* jsCircle) { if (jsCircle != nullptr) { jsCircle->DecRefCount(); } } void JSCircle::JSBind(BindingTarget globalObj) { JSClass::Declare("Circle"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSCircle::Create, opt); JSClass::CustomMethod("width", &JSShapeAbstract::ObjectWidth); JSClass::CustomMethod("height", &JSShapeAbstract::ObjectHeight); JSClass::CustomMethod("size", &JSShapeAbstract::ObjectSize); JSClass::CustomMethod("offset", &JSShapeAbstract::ObjectOffset); JSClass::CustomMethod("fill", &JSShapeAbstract::ObjectFill); JSClass::CustomMethod("position", &JSShapeAbstract::ObjectPosition); JSClass::StaticMethod("onTouch", &JSInteractableView::JsOnTouch); JSClass::StaticMethod("onHover", &JSInteractableView::JsOnHover); JSClass::StaticMethod("onKeyEvent", &JSInteractableView::JsOnKey); JSClass::StaticMethod("onDeleteEvent", &JSInteractableView::JsOnDelete); JSClass::StaticMethod("onClick", &JSInteractableView::JsOnClick); JSClass::StaticMethod("remoteMessage", &JSInteractableView::JsCommonRemoteMessage); JSClass::InheritAndBind( globalObj, JSCircle::ConstructorCallback, JSCircle::DestructorCallback); } } // namespace OHOS::Ace::Framework