• 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 
16 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_native_hyperlink_bridge.h"
17 #include "bridge/declarative_frontend/engine/jsi/nativeModule/arkts_utils.h"
18 
19 namespace OHOS::Ace::NG {
20 namespace {
21 constexpr int NUM_0 = 0;
22 constexpr int NUM_1 = 1;
23 constexpr int NUM_2 = 2;
24 } // namespace
SetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)25 ArkUINativeModuleValue HyperlinkBridge::SetColor(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     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
32     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
33     Color color;
34     RefPtr<ResourceObject> resourceObject;
35     auto nodeInfo = ArkTSUtils::MakeNativeNodeInfo(nativeNode);
36     if (!ArkTSUtils::ParseJsColorAlpha(vm, secondArg, color, resourceObject, nodeInfo)) {
37         GetArkUINodeModifiers()->getHyperlinkModifier()->resetHyperlinkColor(nativeNode);
38     } else {
39         GetArkUINodeModifiers()->getHyperlinkModifier()->setHyperlinkColor(
40             nativeNode, color.GetValue(), AceType::RawPtr(resourceObject));
41     }
42     return panda::JSValueRef::Undefined(vm);
43 }
44 
ResetColor(ArkUIRuntimeCallInfo * runtimeCallInfo)45 ArkUINativeModuleValue HyperlinkBridge::ResetColor(ArkUIRuntimeCallInfo* runtimeCallInfo)
46 {
47     EcmaVM* vm = runtimeCallInfo->GetVM();
48     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
49     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
50     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
51     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
52     GetArkUINodeModifiers()->getHyperlinkModifier()->resetHyperlinkColor(nativeNode);
53     return panda::JSValueRef::Undefined(vm);
54 }
55 
SetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)56 ArkUINativeModuleValue HyperlinkBridge::SetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
57 {
58     EcmaVM* vm = runtimeCallInfo->GetVM();
59     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
60     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
61     Local<JSValueRef> draggableArg = runtimeCallInfo->GetCallArgRef(1);
62     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
63     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
64     if (draggableArg->IsBoolean()) {
65         bool boolValue = draggableArg->ToBoolean(vm)->Value();
66         GetArkUINodeModifiers()->getHyperlinkModifier()->setHyperlinkDraggable(nativeNode, boolValue);
67     } else {
68         GetArkUINodeModifiers()->getHyperlinkModifier()->resetHyperlinkDraggable(nativeNode);
69     }
70     return panda::JSValueRef::Undefined(vm);
71 }
72 
ResetDraggable(ArkUIRuntimeCallInfo * runtimeCallInfo)73 ArkUINativeModuleValue HyperlinkBridge::ResetDraggable(ArkUIRuntimeCallInfo* runtimeCallInfo)
74 {
75     EcmaVM* vm = runtimeCallInfo->GetVM();
76     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
77     Local<JSValueRef> nodeArg = runtimeCallInfo->GetCallArgRef(0);
78     CHECK_NULL_RETURN(nodeArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
79     auto nativeNode = nodePtr(nodeArg->ToNativePointer(vm)->Value());
80     GetArkUINodeModifiers()->getHyperlinkModifier()->resetHyperlinkDraggable(nativeNode);
81     return panda::JSValueRef::Undefined(vm);
82 }
83 
SetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)84 ArkUINativeModuleValue HyperlinkBridge::SetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
85 {
86     EcmaVM* vm = runtimeCallInfo->GetVM();
87     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
88     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(NUM_0);
89     Local<JSValueRef> secondArg = runtimeCallInfo->GetCallArgRef(NUM_1);
90     Local<JSValueRef> thirdArg = runtimeCallInfo->GetCallArgRef(NUM_2);
91     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
92     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
93     int32_t length = thirdArg->Int32Value(vm);
94     ArkUI_Float32 regionArray[length];
95     int32_t regionUnits[length];
96     if (!ArkTSUtils::ParseResponseRegion(vm, secondArg, regionArray, regionUnits, length)) {
97         GetArkUINodeModifiers()->getHyperlinkModifier()->resetHyperlinkResponseRegion(nativeNode);
98         return panda::JSValueRef::Undefined(vm);
99     }
100     GetArkUINodeModifiers()->getHyperlinkModifier()->setHyperlinkResponseRegion(
101         nativeNode, regionArray, regionUnits, length);
102     return panda::JSValueRef::Undefined(vm);
103 }
104 
ResetResponseRegion(ArkUIRuntimeCallInfo * runtimeCallInfo)105 ArkUINativeModuleValue HyperlinkBridge::ResetResponseRegion(ArkUIRuntimeCallInfo* runtimeCallInfo)
106 {
107     EcmaVM* vm = runtimeCallInfo->GetVM();
108     CHECK_NULL_RETURN(vm, panda::NativePointerRef::New(vm, nullptr));
109     Local<JSValueRef> firstArg = runtimeCallInfo->GetCallArgRef(0);
110     CHECK_NULL_RETURN(firstArg->IsNativePointer(vm), panda::JSValueRef::Undefined(vm));
111     auto nativeNode = nodePtr(firstArg->ToNativePointer(vm)->Value());
112     GetArkUINodeModifiers()->getHyperlinkModifier()->resetHyperlinkResponseRegion(nativeNode);
113     return panda::JSValueRef::Undefined(vm);
114 }
115 } // namespace OHOS::Ace::NG