• 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 "core/interfaces/native/node/hyperlink_modifier.h"
17 #include "core/components/hyperlink/hyperlink_theme.h"
18 #include "core/components_ng/pattern/hyperlink/hyperlink_model_ng.h"
19 #include "core/pipeline_ng/pipeline_context.h"
20 
21 namespace OHOS::Ace::NG {
22 namespace {
23 constexpr int NUM_0 = 0;
24 constexpr int NUM_1 = 1;
25 constexpr int NUM_2 = 2;
26 constexpr int NUM_3 = 3;
27 constexpr int NUM_4 = 4;
28 } // namespace
SetHyperlinkColor(ArkUINodeHandle node,uint32_t color,void * colorRawPtr)29 void SetHyperlinkColor(ArkUINodeHandle node, uint32_t color, void* colorRawPtr)
30 {
31     auto* frameNode = reinterpret_cast<FrameNode*>(node);
32     CHECK_NULL_VOID(frameNode);
33     HyperlinkModelNG::SetColor(frameNode, Color(color));
34     auto pattern = frameNode->GetPattern();
35     CHECK_NULL_VOID(pattern);
36     if (SystemProperties::ConfigChangePerform() && colorRawPtr) {
37         auto resObj = AceType::Claim(reinterpret_cast<ResourceObject*>(colorRawPtr));
38         pattern->RegisterResource<Color>("Color", resObj, Color(color));
39     } else {
40         pattern->UnRegisterResource("Color");
41     }
42 }
43 
ResetHyperlinkColor(ArkUINodeHandle node)44 void ResetHyperlinkColor(ArkUINodeHandle node)
45 {
46     auto* frameNode = reinterpret_cast<FrameNode*>(node);
47     CHECK_NULL_VOID(frameNode);
48     auto context = frameNode->GetContext();
49     CHECK_NULL_VOID(context);
50     auto themeManager = context->GetThemeManager();
51     CHECK_NULL_VOID(themeManager);
52     auto hyperlinkTheme = themeManager->GetTheme<HyperlinkTheme>();
53     CHECK_NULL_VOID(hyperlinkTheme);
54     auto pattern = frameNode->GetPattern();
55     CHECK_NULL_VOID(pattern);
56     pattern->UnRegisterResource("Color");
57     HyperlinkModelNG::SetColor(frameNode, Color(hyperlinkTheme->GetTextColor()));
58 }
59 
SetHyperlinkDraggable(ArkUINodeHandle node,ArkUI_Bool draggable)60 void SetHyperlinkDraggable(ArkUINodeHandle node, ArkUI_Bool draggable)
61 {
62     auto* frameNode = reinterpret_cast<FrameNode*>(node);
63     CHECK_NULL_VOID(frameNode);
64     HyperlinkModelNG::SetDraggable(frameNode, draggable);
65 }
66 
ResetHyperlinkDraggable(ArkUINodeHandle node)67 void ResetHyperlinkDraggable(ArkUINodeHandle node)
68 {
69     auto* frameNode = reinterpret_cast<FrameNode*>(node);
70     CHECK_NULL_VOID(frameNode);
71     HyperlinkModelNG::SetDraggable(frameNode, false);
72 }
73 
SetHyperlinkResponseRegion(ArkUINodeHandle node,const ArkUI_Float32 * values,const ArkUI_Int32 * units,ArkUI_Int32 length)74 void SetHyperlinkResponseRegion(
75     ArkUINodeHandle node, const ArkUI_Float32* values, const ArkUI_Int32* units, ArkUI_Int32 length)
76 {
77     auto* frameNode = reinterpret_cast<FrameNode*>(node);
78     CHECK_NULL_VOID(frameNode);
79     std::vector<DimensionRect> region;
80     for (int32_t i = 0; i < length / NUM_4; i++) {
81         CalcDimension xDimen =
82             CalcDimension(values[i * NUM_4 + NUM_0], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_0]));
83         CalcDimension yDimen =
84             CalcDimension(values[i * NUM_4 + NUM_1], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_1]));
85         CalcDimension widthDimen =
86             CalcDimension(values[i * NUM_4 + NUM_2], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_2]));
87         CalcDimension heightDimen =
88             CalcDimension(values[i * NUM_4 + NUM_3], static_cast<DimensionUnit>(units[i * NUM_4 + NUM_3]));
89         DimensionOffset offsetDimen(xDimen, yDimen);
90         DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
91         region.emplace_back(dimenRect);
92     }
93     HyperlinkModelNG::SetResponseRegion(frameNode, region, true);
94 }
95 
ResetHyperlinkResponseRegion(ArkUINodeHandle node)96 void ResetHyperlinkResponseRegion(ArkUINodeHandle node)
97 {
98     auto *frameNode = reinterpret_cast<FrameNode *>(node);
99     CHECK_NULL_VOID(frameNode);
100     std::vector<DimensionRect> region;
101     CalcDimension xDimen = CalcDimension(0.0, DimensionUnit::VP);
102     CalcDimension yDimen = CalcDimension(0.0, DimensionUnit::VP);
103     CalcDimension widthDimen = CalcDimension(1, DimensionUnit::PERCENT);
104     CalcDimension heightDimen = CalcDimension(1, DimensionUnit::PERCENT);
105     DimensionOffset offsetDimen(xDimen, yDimen);
106     DimensionRect dimenRect(widthDimen, heightDimen, offsetDimen);
107     region.emplace_back(dimenRect);
108     HyperlinkModelNG::SetResponseRegion(frameNode, region, false);
109 }
110 
111 namespace NodeModifier {
GetHyperlinkModifier()112 const ArkUIHyperlinkModifier* GetHyperlinkModifier()
113 {
114     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
115     static const ArkUIHyperlinkModifier modifier = {
116         .setHyperlinkColor = SetHyperlinkColor,
117         .resetHyperlinkColor = ResetHyperlinkColor,
118         .setHyperlinkDraggable = SetHyperlinkDraggable,
119         .resetHyperlinkDraggable = ResetHyperlinkDraggable,
120         .setHyperlinkResponseRegion = SetHyperlinkResponseRegion,
121         .resetHyperlinkResponseRegion = ResetHyperlinkResponseRegion,
122     };
123     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
124 
125     return &modifier;
126 }
127 
GetCJUIHyperlinkModifier()128 const CJUIHyperlinkModifier* GetCJUIHyperlinkModifier()
129 {
130     CHECK_INITIALIZED_FIELDS_BEGIN(); // don't move this line
131     static const CJUIHyperlinkModifier modifier = {
132         .setHyperlinkColor = SetHyperlinkColor,
133         .resetHyperlinkColor = ResetHyperlinkColor,
134         .setHyperlinkDraggable = SetHyperlinkDraggable,
135         .resetHyperlinkDraggable = ResetHyperlinkDraggable,
136     };
137     CHECK_INITIALIZED_FIELDS_END(modifier, 0, 0, 0); // don't move this line
138 
139     return &modifier;
140 }
141 } // namespace NodeModifier
142 } // namespace OHOS::Ace::NG
143