• 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 "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_marquee_bridge.h"
16 
17 #include "base/geometry/dimension.h"
18 #include "core/interfaces/native/node/api.h"
19 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
20 #include "core/components/common/properties/text_style.h"
21 
22 static const std::string DEFAULT_FONT_WEIGHT = "400";
23 
24 namespace OHOS::Ace::NG {
SetAllowScale(ArkUIRuntimeCallInfo * runtimeCallInfo)25 ArkUINativeModuleValue MarqueeBridge::SetAllowScale(ArkUIRuntimeCallInfo* runtimeCallInfo)
26 {
27     EcmaVM* vm = runtimeCallInfo->GetVM();
28     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
29     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
30     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
31     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
32     bool allowScale = secondArg->ToBoolean(vm)->Value();
33     GetArkUIInternalNodeAPI()->GetMarqueeModifier().SetMarqueeAllowScale(nativeNode, allowScale);
34     return panda::JSValueRef::Undefined(vm);
35 }
36 
ResetAllowScale(ArkUIRuntimeCallInfo * runtimeCallInfo)37 ArkUINativeModuleValue MarqueeBridge::ResetAllowScale(ArkUIRuntimeCallInfo* runtimeCallInfo)
38 {
39     EcmaVM* vm = runtimeCallInfo->GetVM();
40     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
41     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
42     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
43     GetArkUIInternalNodeAPI()->GetMarqueeModifier().ResetMarqueeAllowScale(nativeNode);
44     return panda::JSValueRef::Undefined(vm);
45 }
46 
SetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)47 ArkUINativeModuleValue MarqueeBridge::SetFontWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
48 {
49     EcmaVM* vm = runtimeCallInfo->GetVM();
50     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
51     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
52     Local<JSValueRef> weightArg = runtimeCallInfo->GetCallArgRef(1);
53     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
54     std::string weight = DEFAULT_FONT_WEIGHT;
55     if (!weightArg->IsNull()) {
56         if (weightArg->IsNumber()) {
57             weight = std::to_string(weightArg->Int32Value(vm));
58         } else if (weightArg->IsString()) {
59             weight = weightArg->ToString(vm)->ToString();
60         }
61     }
62     GetArkUIInternalNodeAPI()->GetMarqueeModifier().SetMarqueeFontWeight(nativeNode, weight.c_str());
63     return panda::JSValueRef::Undefined(vm);
64 }
65 
ResetFontWeight(ArkUIRuntimeCallInfo * runtimeCallInfo)66 ArkUINativeModuleValue MarqueeBridge::ResetFontWeight(ArkUIRuntimeCallInfo* runtimeCallInfo)
67 {
68     EcmaVM* vm = runtimeCallInfo->GetVM();
69     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
70     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
71     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
72     GetArkUIInternalNodeAPI()->GetMarqueeModifier().ResetMarqueeFontWeight(nativeNode);
73     return panda::JSValueRef::Undefined(vm);
74 }
75 
SetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)76 ArkUINativeModuleValue MarqueeBridge::SetFontFamily(ArkUIRuntimeCallInfo* runtimeCallInfo)
77 {
78     EcmaVM* vm = runtimeCallInfo->GetVM();
79     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
80     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
81     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
82     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
83     if (!secondArg->IsString()) {
84         return panda::JSValueRef::Undefined(vm);
85     }
86     std::string families = secondArg->ToString(vm)->ToString();
87     GetArkUIInternalNodeAPI()->GetMarqueeModifier().SetMarqueeFontFamily(nativeNode, families.c_str());
88     return panda::JSValueRef::Undefined(vm);
89 }
90 
ResetFontFamily(ArkUIRuntimeCallInfo * runtimeCallInfo)91 ArkUINativeModuleValue MarqueeBridge::ResetFontFamily(ArkUIRuntimeCallInfo* runtimeCallInfo)
92 {
93     EcmaVM* vm = runtimeCallInfo->GetVM();
94     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
95     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
96     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
97     GetArkUIInternalNodeAPI()->GetMarqueeModifier().ResetMarqueeFontFamily(nativeNode);
98     return panda::JSValueRef::Undefined(vm);
99 }
100 
SetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)101 ArkUINativeModuleValue MarqueeBridge::SetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
102 {
103     EcmaVM* vm = runtimeCallInfo->GetVM();
104     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
105     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
106     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
107     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
108     CalcDimension fontSize;
109     if (!ArkTSUtils::ParseJsDimensionFp(vm, secondArg, fontSize) || fontSize.IsNegative()
110         || fontSize.Unit() == DimensionUnit::PERCENT) {
111         GetArkUIInternalNodeAPI()->GetMarqueeModifier().ResetMarqueeFontSize(nativeNode);
112     } else {
113         GetArkUIInternalNodeAPI()->GetMarqueeModifier().SetMarqueeFontSize(
114             nativeNode, fontSize.Value(), static_cast<int>(fontSize.Unit()));
115     }
116     return panda::JSValueRef::Undefined(vm);
117 }
118 
ResetFontSize(ArkUIRuntimeCallInfo * runtimeCallInfo)119 ArkUINativeModuleValue MarqueeBridge::ResetFontSize(ArkUIRuntimeCallInfo* runtimeCallInfo)
120 {
121     EcmaVM* vm = runtimeCallInfo->GetVM();
122     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
123     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
124     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
125     GetArkUIInternalNodeAPI()->GetMarqueeModifier().ResetMarqueeFontSize(nativeNode);
126     return panda::JSValueRef::Undefined(vm);
127 }
128 
SetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)129 ArkUINativeModuleValue MarqueeBridge::SetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
130 {
131     EcmaVM* vm = runtimeCallInfo->GetVM();
132     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
133     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
134     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(1);
135     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
136     Color color;
137     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color)) {
138         GetArkUIInternalNodeAPI()->GetMarqueeModifier().ResetMarqueeFontColor(nativeNode);
139     } else {
140         GetArkUIInternalNodeAPI()->GetMarqueeModifier().SetMarqueeFontColor(nativeNode, color.GetValue());
141     }
142     return panda::JSValueRef::Undefined(vm);
143 }
144 
ResetFontColor(ArkUIRuntimeCallInfo * runtimeCallInfo)145 ArkUINativeModuleValue MarqueeBridge::ResetFontColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
146 {
147     EcmaVM* vm = runtimeCallInfo->GetVM();
148     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
149     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
150     void* nativeNode = firstArg->ToNativePointer(vm)->Value();
151     GetArkUIInternalNodeAPI()->GetMarqueeModifier().ResetMarqueeFontColor(nativeNode);
152     return panda::JSValueRef::Undefined(vm);
153 }
154 } // namespace OHOS::Ace::NG