/* * 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_ellipse.h" #include "bridge/declarative_frontend/jsview/models/ellipse_model_impl.h" #include "core/common/container.h" #include "core/components_ng/pattern/shape/ellipse_model.h" #include "core/components_ng/pattern/shape/ellipse_model_ng.h" namespace OHOS::Ace { std::unique_ptr EllipseModel::instance_ = nullptr; std::mutex EllipseModel::mutex_; EllipseModel* EllipseModel::GetInstance() { if (!instance_) { std::lock_guard lock(mutex_); if (!instance_) { #ifdef NG_BUILD instance_.reset(new NG::EllipseModelNG()); #else if (Container::IsCurrentUseNewPipeline()) { instance_.reset(new NG::EllipseModelNG()); } else { instance_.reset(new Framework::EllipseModelImpl()); } #endif } } return instance_.get(); } } // namespace OHOS::Ace namespace OHOS::Ace::Framework { void JSEllipse::Create(const JSCallbackInfo& info) { EllipseModel::GetInstance()->Create(); JSShapeAbstract::SetSize(info); } void JSEllipse::ConstructorCallback(const JSCallbackInfo& info) { auto ellipse = 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)) { ellipse->SetWidth(dimWidth); } if (ParseJsDimensionVp(height, dimHeight)) { ellipse->SetHeight(dimHeight); } } else { if (ParseJsDimensionVpNG(width, dimWidth) && dimWidth.IsValid()) { ellipse->SetWidth(dimWidth); } if (ParseJsDimensionVpNG(height, dimHeight) && dimHeight.IsValid()) { ellipse->SetHeight(dimHeight); } } } auto jsEllipse = AceType::MakeRefPtr(); jsEllipse->SetBasicShape(ellipse); jsEllipse->IncRefCount(); info.SetReturnValue(AceType::RawPtr(jsEllipse)); } void JSEllipse::DestructorCallback(JSEllipse* jsEllipse) { if (jsEllipse != nullptr) { jsEllipse->DecRefCount(); } } void JSEllipse::JSBind(BindingTarget globalObj) { JSClass::Declare("Ellipse"); MethodOptions opt = MethodOptions::NONE; JSClass::StaticMethod("create", &JSEllipse::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, JSEllipse::ConstructorCallback, JSEllipse::DestructorCallback); } } // namespace OHOS::Ace::Framework