• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 #include "core/interfaces/native/node/api.h"
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_image_span_bridge.h"
17 
18 namespace OHOS::Ace::NG {
19 
SetVerticalAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)20 ArkUINativeModuleValue ImageSpanBridge::SetVerticalAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
21 {
22     EcmaVM* vm = runtimeCallInfo->GetVM();
23     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
24     Local<JSValueRef> node = runtimeCallInfo->GetCallArgRef(0);
25     Local<JSValueRef> verticalAlign = runtimeCallInfo->GetCallArgRef(1);
26     void* nativeNode = node->ToNativePointer(vm)->Value();
27     int32_t value = static_cast<int32_t>(VerticalAlign::BOTTOM);
28     if (verticalAlign->IsNumber()) {
29         value = verticalAlign->Int32Value(vm);
30         auto align = static_cast<VerticalAlign>(value);
31         if (align < VerticalAlign::TOP || align > VerticalAlign::NONE) {
32             align = VerticalAlign::BOTTOM;
33         }
34         value = static_cast<int32_t>(align);
35     }
36     GetArkUIInternalNodeAPI()->GetImageSpanModifier().SetImageSpanVerticalAlign(nativeNode, value);
37     return panda::JSValueRef::Undefined(vm);
38 }
39 
ResetVerticalAlign(ArkUIRuntimeCallInfo * runtimeCallInfo)40 ArkUINativeModuleValue ImageSpanBridge::ResetVerticalAlign(ArkUIRuntimeCallInfo* runtimeCallInfo)
41 {
42     EcmaVM* vm = runtimeCallInfo->GetVM();
43     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
44     Local<JSValueRef> node = runtimeCallInfo->GetCallArgRef(0);
45     void* nativeNode = node->ToNativePointer(vm)->Value();
46     GetArkUIInternalNodeAPI()->GetImageSpanModifier().ResetImageSpanVerticalAlign(nativeNode);
47     return panda::JSValueRef::Undefined(vm);
48 }
49 
SetObjectFit(ArkUIRuntimeCallInfo * runtimeCallInfo)50 ArkUINativeModuleValue ImageSpanBridge::SetObjectFit(ArkUIRuntimeCallInfo* runtimeCallInfo)
51 {
52     EcmaVM* vm = runtimeCallInfo->GetVM();
53     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
54     Local<JSValueRef> node = runtimeCallInfo->GetCallArgRef(0);
55     Local<JSValueRef> objectFit = runtimeCallInfo->GetCallArgRef(1);
56     void* nativeNode = node->ToNativePointer(vm)->Value();
57     int32_t value = static_cast<int32_t>(ImageFit::COVER);
58     if (objectFit->IsNumber()) {
59         value = objectFit->Int32Value(vm);
60         auto fit = static_cast<ImageFit>(value);
61         if (fit < ImageFit::FILL || fit > ImageFit::SCALE_DOWN) {
62             fit = ImageFit::COVER;
63         }
64         value = static_cast<int32_t>(fit);
65     }
66     GetArkUIInternalNodeAPI()->GetImageSpanModifier().SetImageSpanObjectFit(nativeNode, value);
67     return panda::JSValueRef::Undefined(vm);
68 }
69 
ResetObjectFit(ArkUIRuntimeCallInfo * runtimeCallInfo)70 ArkUINativeModuleValue ImageSpanBridge::ResetObjectFit(ArkUIRuntimeCallInfo* runtimeCallInfo)
71 {
72     EcmaVM* vm = runtimeCallInfo->GetVM();
73     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
74     Local<JSValueRef> node = runtimeCallInfo->GetCallArgRef(0);
75     void* nativeNode = node->ToNativePointer(vm)->Value();
76     GetArkUIInternalNodeAPI()->GetImageSpanModifier().ResetImageSpanObjectFit(nativeNode);
77     return panda::JSValueRef::Undefined(vm);
78 }
79 } // namespace OHOS::Ace::NG
80