1 /*
2 * Copyright (c) 2022-2024 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/components_ng/pattern/text_picker/textpicker_model_ng.h"
17
18 #include <securec.h>
19
20 #include "base/geometry/dimension.h"
21 #include "base/geometry/ng/size_t.h"
22 #include "base/utils/utils.h"
23 #include "core/components_ng/base/frame_node.h"
24 #include "core/components_ng/base/view_stack_processor.h"
25 #include "core/components_ng/pattern/button/button_pattern.h"
26 #include "core/components_ng/pattern/image/image_pattern.h"
27 #include "core/components_ng/pattern/picker/picker_type_define.h"
28 #include "core/components_ng/pattern/stack/stack_pattern.h"
29 #include "core/components_ng/pattern/text/text_pattern.h"
30 #include "core/components_ng/pattern/text_picker/textpicker_column_pattern.h"
31 #include "core/components_ng/pattern/text_picker/textpicker_event_hub.h"
32 #include "core/components_ng/pattern/text_picker/textpicker_layout_property.h"
33 #include "core/components_ng/pattern/text_picker/textpicker_pattern.h"
34 #include "core/components_v2/inspector/inspector_constants.h"
35 #include "core/pipeline_ng/pipeline_context.h"
36
37 namespace OHOS::Ace::NG {
38 namespace {
39 constexpr float PICKER_MAXFONTSCALE = 1.0f;
40 const int32_t BUFFER_NODE_NUMBER = 2;
41
SetDialogProperties(DialogProperties & properties,TextPickerDialog & textPickerDialog,const RefPtr<DialogTheme> & theme)42 void SetDialogProperties(DialogProperties& properties, TextPickerDialog& textPickerDialog,
43 const RefPtr<DialogTheme>& theme)
44 {
45 if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
46 properties.alignment = theme->GetAlignment();
47 }
48 if (textPickerDialog.alignment.has_value()) {
49 properties.alignment = textPickerDialog.alignment.value();
50 }
51
52 if (textPickerDialog.backgroundColor.has_value()) {
53 properties.backgroundColor = textPickerDialog.backgroundColor.value();
54 }
55 if (textPickerDialog.backgroundBlurStyle.has_value()) {
56 properties.backgroundBlurStyle = textPickerDialog.backgroundBlurStyle.value();
57 }
58 if (textPickerDialog.shadow.has_value()) {
59 properties.shadow = textPickerDialog.shadow.value();
60 }
61 properties.customStyle = false;
62 if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
63 properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
64 }
65 if (textPickerDialog.offset.has_value()) {
66 properties.offset = textPickerDialog.offset.value();
67 }
68
69 properties.maskRect = textPickerDialog.maskRect;
70 properties.enableHoverMode = textPickerDialog.enableHoverMode;
71 if (textPickerDialog.hoverModeArea.has_value()) {
72 properties.hoverModeArea = textPickerDialog.hoverModeArea.value();
73 }
74 }
75 }
76
Create(RefPtr<PickerTheme> pickerTheme,uint32_t columnKind)77 void TextPickerModelNG::Create(RefPtr<PickerTheme> pickerTheme, uint32_t columnKind)
78 {
79 auto* stack = ViewStackProcessor::GetInstance();
80 auto nodeId = stack->ClaimNodeId();
81 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::TEXT_PICKER_ETS_TAG, nodeId);
82 auto textPickerNode = FrameNode::GetOrCreateFrameNode(
83 V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
84 auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
85 CHECK_NULL_VOID(textPickerPattern);
86 textPickerPattern->SetColumnsKind(columnKind);
87 auto pipeline = PipelineBase::GetCurrentContext();
88 CHECK_NULL_VOID(pipeline);
89 auto dialogTheme = pipeline->GetTheme<DialogTheme>();
90 CHECK_NULL_VOID(dialogTheme);
91 textPickerPattern->SetBackgroundColor(dialogTheme->GetBackgroundColor());
92 CHECK_NULL_VOID(pickerTheme);
93 uint32_t showCount = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
94
95 if (textPickerNode->GetChildren().empty()) {
96 auto columnNode = CreateColumnNode(columnKind, showCount);
97 auto stackNode = CreateStackNode();
98 auto buttonNode = CreateButtonNode();
99 auto columnBlendNode = CreateColumnNode();
100 buttonNode->MountToParent(stackNode);
101 columnNode->MountToParent(columnBlendNode);
102 columnBlendNode->MountToParent(stackNode);
103 columnNode->MarkModifyDone();
104 columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
105 auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
106 layoutProperty->UpdateAlignment(Alignment::CENTER);
107 stackNode->MountToParent(textPickerNode);
108 }
109 stack->Push(textPickerNode);
110 options_.clear();
111 }
112
SetDefaultAttributes(const RefPtr<PickerTheme> & pickerTheme)113 void TextPickerModelNG::SetDefaultAttributes(const RefPtr<PickerTheme>& pickerTheme)
114 {
115 CHECK_NULL_VOID(pickerTheme);
116 auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
117 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize, selectedStyle.GetFontSize());
118 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedColor, selectedStyle.GetTextColor());
119 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedWeight, selectedStyle.GetFontWeight());
120 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontFamily, selectedStyle.GetFontFamilies());
121 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontStyle, selectedStyle.GetFontStyle());
122
123 auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
124 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
125 ConvertFontScaleValue(disappearStyle.GetFontSize()));
126 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearColor, disappearStyle.GetTextColor());
127 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearWeight, disappearStyle.GetFontWeight());
128 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontFamily, disappearStyle.GetFontFamilies());
129 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontStyle, disappearStyle.GetFontStyle());
130
131 auto normalStyle = pickerTheme->GetOptionStyle(false, false);
132 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
133 ConvertFontScaleValue(normalStyle.GetFontSize()));
134 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Color, normalStyle.GetTextColor());
135 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Weight, normalStyle.GetFontWeight());
136 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontFamily, normalStyle.GetFontFamilies());
137 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontStyle, normalStyle.GetFontStyle());
138
139 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, true);
140 }
141
CreateColumnNode(uint32_t columnKind,uint32_t showCount)142 RefPtr<FrameNode> TextPickerModelNG::CreateColumnNode(uint32_t columnKind, uint32_t showCount)
143 {
144 auto columnNode =
145 FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
146 []() { return AceType::MakeRefPtr<TextPickerColumnPattern>(); });
147 if (columnKind == ICON) {
148 for (uint32_t index = 0; index < showCount; index++) {
149 auto row = FrameNode::CreateFrameNode(
150 V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
151 AceType::MakeRefPtr<LinearLayoutPattern>(false));
152 CHECK_NULL_RETURN(row, nullptr);
153 auto layoutProps = row->GetLayoutProperty<LinearLayoutProperty>();
154 CHECK_NULL_RETURN(layoutProps, nullptr);
155 layoutProps->UpdateMainAxisAlign(FlexAlign::CENTER);
156 layoutProps->UpdateCrossAxisAlign(FlexAlign::CENTER);
157
158 auto imageNode = FrameNode::CreateFrameNode(
159 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
160 AceType::MakeRefPtr<ImagePattern>());
161 CHECK_NULL_RETURN(imageNode, nullptr);
162 imageNode->MountToParent(row);
163 row->MountToParent(columnNode);
164 }
165 } else if (columnKind == TEXT) {
166 for (uint32_t index = 0; index < showCount; index++) {
167 auto textNode = FrameNode::CreateFrameNode(
168 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
169 AceType::MakeRefPtr<TextPattern>());
170 CHECK_NULL_RETURN(textNode, nullptr);
171 textNode->MountToParent(columnNode);
172 }
173 } else if (columnKind == MIXTURE) {
174 for (uint32_t index = 0; index < showCount; index++) {
175 auto row = FrameNode::CreateFrameNode(
176 V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
177 AceType::MakeRefPtr<LinearLayoutPattern>(false));
178 CHECK_NULL_RETURN(row, nullptr);
179
180 auto imageNode = FrameNode::CreateFrameNode(
181 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
182 AceType::MakeRefPtr<ImagePattern>());
183 CHECK_NULL_RETURN(imageNode, nullptr);
184 imageNode->MountToParent(row);
185
186 auto textNode = FrameNode::CreateFrameNode(
187 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
188 AceType::MakeRefPtr<TextPattern>());
189 CHECK_NULL_RETURN(textNode, nullptr);
190 textNode->MountToParent(row);
191 row->MountToParent(columnNode);
192 }
193 }
194 return columnNode;
195 }
196
CreateStackNode()197 RefPtr<FrameNode> TextPickerModelNG::CreateStackNode()
198 {
199 auto stackId = ElementRegister::GetInstance()->MakeUniqueId();
200 return FrameNode::GetOrCreateFrameNode(
201 V2::STACK_ETS_TAG, stackId, []() { return AceType::MakeRefPtr<StackPattern>(); });
202 }
203
CreateColumnNode()204 RefPtr<FrameNode> TextPickerModelNG::CreateColumnNode()
205 {
206 auto columnId = ElementRegister::GetInstance()->MakeUniqueId();
207 return FrameNode::GetOrCreateFrameNode(
208 V2::COLUMN_ETS_TAG, columnId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
209 }
210
CreateButtonNode()211 RefPtr<FrameNode> TextPickerModelNG::CreateButtonNode()
212 {
213 auto buttonId = ElementRegister::GetInstance()->MakeUniqueId();
214 return FrameNode::GetOrCreateFrameNode(
215 V2::BUTTON_ETS_TAG, buttonId, []() { return AceType::MakeRefPtr<ButtonPattern>(); });
216 }
217
CreateFrameNode(int32_t nodeId)218 RefPtr<FrameNode> TextPickerModelNG::CreateFrameNode(int32_t nodeId)
219 {
220 auto textPickerNode = FrameNode::GetOrCreateFrameNode(
221 V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
222 auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
223 textPickerPattern->SetColumnsKind(TEXT);
224 auto pipeline = PipelineBase::GetCurrentContextSafely();
225 CHECK_NULL_RETURN(pipeline, textPickerNode);
226 auto pickerTheme = pipeline->GetTheme<PickerTheme>();
227 CHECK_NULL_RETURN(pickerTheme, textPickerNode);
228 showCount_ = BUFFER_NODE_NUMBER + pickerTheme->GetShowOptionCount();
229 rangeValue_.clear();
230 SetDefaultAttributes(textPickerNode, pickerTheme);
231 return textPickerNode;
232 }
233
SetSelected(uint32_t value)234 void TextPickerModelNG::SetSelected(uint32_t value)
235 {
236 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
237 CHECK_NULL_VOID(frameNode);
238 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
239 textPickerPattern->SetSelected(value);
240 std::vector<uint32_t> values;
241 values.emplace_back(value);
242 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selected, value);
243 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values);
244 }
245
SetRange(const std::vector<NG::RangeContent> & value)246 void TextPickerModelNG::SetRange(const std::vector<NG::RangeContent>& value)
247 {
248 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
249 CHECK_NULL_VOID(frameNode);
250 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
251 textPickerPattern->SetRange(value);
252 for (auto& range : value) {
253 rangeValue_.emplace_back(std::move(range));
254 }
255 }
256
SetDefaultPickerItemHeight(const Dimension & value)257 void TextPickerModelNG::SetDefaultPickerItemHeight(const Dimension& value)
258 {
259 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultPickerItemHeight, value);
260 }
261
SetGradientHeight(const Dimension & value)262 void TextPickerModelNG::SetGradientHeight(const Dimension& value)
263 {
264 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
265 CHECK_NULL_VOID(frameNode);
266 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
267 CHECK_NULL_VOID(textPickerPattern);
268 textPickerPattern->SetGradientHeight(value);
269 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, value);
270 }
271
SetCanLoop(const bool value)272 void TextPickerModelNG::SetCanLoop(const bool value)
273 {
274 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
275 CHECK_NULL_VOID(frameNode);
276 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
277 CHECK_NULL_VOID(textPickerPattern);
278 textPickerPattern->SetCanLoop(value);
279 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, value);
280 }
281
SetBackgroundColor(const Color & color)282 void TextPickerModelNG::SetBackgroundColor(const Color& color)
283 {
284 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
285 CHECK_NULL_VOID(frameNode);
286 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
287 CHECK_NULL_VOID(textPickerPattern);
288 textPickerPattern->SetBackgroundColor(color);
289 }
290
SetDisappearTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)291 void TextPickerModelNG::SetDisappearTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
292 {
293 CHECK_NULL_VOID(pickerTheme);
294 auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
295 if (value.fontSize.has_value() && value.fontSize->IsValid()) {
296 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
297 ConvertFontScaleValue(value.fontSize.value()));
298 } else {
299 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
300 ConvertFontScaleValue(disappearStyle.GetFontSize()));
301 }
302 ACE_UPDATE_LAYOUT_PROPERTY(
303 TextPickerLayoutProperty, DisappearColor, value.textColor.value_or(disappearStyle.GetTextColor()));
304 ACE_UPDATE_LAYOUT_PROPERTY(
305 TextPickerLayoutProperty, DisappearWeight, value.fontWeight.value_or(disappearStyle.GetFontWeight()));
306 ACE_UPDATE_LAYOUT_PROPERTY(
307 TextPickerLayoutProperty, DisappearFontFamily, value.fontFamily.value_or(disappearStyle.GetFontFamilies()));
308 ACE_UPDATE_LAYOUT_PROPERTY(
309 TextPickerLayoutProperty, DisappearFontStyle, value.fontStyle.value_or(disappearStyle.GetFontStyle()));
310 }
311
SetNormalTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)312 void TextPickerModelNG::SetNormalTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
313 {
314 CHECK_NULL_VOID(pickerTheme);
315 auto normalStyle = pickerTheme->GetOptionStyle(false, false);
316 if (value.fontSize.has_value() && value.fontSize->IsValid()) {
317 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
318 ConvertFontScaleValue(value.fontSize.value()));
319 } else {
320 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
321 ConvertFontScaleValue(normalStyle.GetFontSize()));
322 }
323 ACE_UPDATE_LAYOUT_PROPERTY(
324 TextPickerLayoutProperty, Color, value.textColor.value_or(normalStyle.GetTextColor()));
325 ACE_UPDATE_LAYOUT_PROPERTY(
326 TextPickerLayoutProperty, Weight, value.fontWeight.value_or(normalStyle.GetFontWeight()));
327 ACE_UPDATE_LAYOUT_PROPERTY(
328 TextPickerLayoutProperty, FontFamily, value.fontFamily.value_or(normalStyle.GetFontFamilies()));
329 ACE_UPDATE_LAYOUT_PROPERTY(
330 TextPickerLayoutProperty, FontStyle, value.fontStyle.value_or(normalStyle.GetFontStyle()));
331 }
332
SetSelectedTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)333 void TextPickerModelNG::SetSelectedTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
334 {
335 CHECK_NULL_VOID(pickerTheme);
336 auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
337 if (value.fontSize.has_value() && value.fontSize->IsValid()) {
338 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
339 ConvertFontScaleValue(value.fontSize.value()));
340 } else {
341 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
342 ConvertFontScaleValue(selectedStyle.GetFontSize()));
343 }
344 ACE_UPDATE_LAYOUT_PROPERTY(
345 TextPickerLayoutProperty, SelectedColor, value.textColor.value_or(selectedStyle.GetTextColor()));
346 ACE_UPDATE_LAYOUT_PROPERTY(
347 TextPickerLayoutProperty, SelectedWeight, value.fontWeight.value_or(selectedStyle.GetFontWeight()));
348 ACE_UPDATE_LAYOUT_PROPERTY(
349 TextPickerLayoutProperty, SelectedFontFamily, value.fontFamily.value_or(selectedStyle.GetFontFamilies()));
350 ACE_UPDATE_LAYOUT_PROPERTY(
351 TextPickerLayoutProperty, SelectedFontStyle, value.fontStyle.value_or(selectedStyle.GetFontStyle()));
352 }
353
HasUserDefinedDisappearFontFamily(bool isUserDefined)354 void TextPickerModelNG::HasUserDefinedDisappearFontFamily(bool isUserDefined)
355 {
356 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
357 CHECK_NULL_VOID(frameNode);
358 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
359 CHECK_NULL_VOID(textPickerPattern);
360 textPickerPattern->HasUserDefinedDisappearFontFamily(isUserDefined);
361 }
362
HasUserDefinedNormalFontFamily(bool isUserDefined)363 void TextPickerModelNG::HasUserDefinedNormalFontFamily(bool isUserDefined)
364 {
365 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
366 CHECK_NULL_VOID(frameNode);
367 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
368 CHECK_NULL_VOID(textPickerPattern);
369 textPickerPattern->HasUserDefinedNormalFontFamily(isUserDefined);
370 }
371
HasUserDefinedSelectedFontFamily(bool isUserDefined)372 void TextPickerModelNG::HasUserDefinedSelectedFontFamily(bool isUserDefined)
373 {
374 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
375 CHECK_NULL_VOID(frameNode);
376 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
377 CHECK_NULL_VOID(textPickerPattern);
378 textPickerPattern->HasUserDefinedSelectedFontFamily(isUserDefined);
379 }
380
SetOnCascadeChange(TextCascadeChangeEvent && onChange)381 void TextPickerModelNG::SetOnCascadeChange(TextCascadeChangeEvent&& onChange)
382 {
383 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
384 CHECK_NULL_VOID(frameNode);
385 auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
386 CHECK_NULL_VOID(eventHub);
387 eventHub->SetOnChange(std::move(onChange));
388 }
389
SetOnScrollStop(TextCascadeChangeEvent && onScrollStop)390 void TextPickerModelNG::SetOnScrollStop(TextCascadeChangeEvent&& onScrollStop)
391 {
392 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
393 CHECK_NULL_VOID(frameNode);
394 auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
395 CHECK_NULL_VOID(eventHub);
396 eventHub->SetOnScrollStop(std::move(onScrollStop));
397 }
398
SetValue(const std::string & value)399 void TextPickerModelNG::SetValue(const std::string& value)
400 {
401 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Value, value);
402 }
403
MultiInit(const RefPtr<PickerTheme> pickerTheme)404 void TextPickerModelNG::MultiInit(const RefPtr<PickerTheme> pickerTheme)
405 {
406 auto* stack = ViewStackProcessor::GetInstance();
407 auto nodeId = stack->ClaimNodeId();
408 auto textPickerNode = FrameNode::GetOrCreateFrameNode(
409 V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
410 auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
411
412 CHECK_NULL_VOID(pickerTheme);
413 showCount_ = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
414 stack->Push(textPickerNode);
415 rangeValue_.clear();
416 }
417
SetIsCascade(bool isCascade)418 void TextPickerModelNG::SetIsCascade(bool isCascade)
419 {
420 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
421 CHECK_NULL_VOID(frameNode);
422 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
423 CHECK_NULL_VOID(textPickerPattern);
424 isCascade_ = isCascade;
425 textPickerPattern->SetIsCascade(isCascade_);
426 }
427
SetHasSelectAttr(bool value)428 void TextPickerModelNG::SetHasSelectAttr(bool value)
429 {
430 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
431 CHECK_NULL_VOID(frameNode);
432 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
433 CHECK_NULL_VOID(textPickerPattern);
434 textPickerPattern->SetHasSelectAttr(value);
435 }
436
SetUnCascadeColumns(const std::vector<NG::TextCascadePickerOptions> & options)437 void TextPickerModelNG::SetUnCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options)
438 {
439 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
440 CHECK_NULL_VOID(frameNode);
441 if (frameNode->GetChildren().empty()) {
442 for (uint32_t i = 0; i < options.size(); i++) {
443 auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
444 auto stackNode = CreateStackNode();
445 auto buttonNode = CreateButtonNode();
446 auto columnBlendNode = CreateColumnNode();
447 buttonNode->MountToParent(stackNode);
448 columnNode->MountToParent(columnBlendNode);
449 columnBlendNode->MountToParent(stackNode);
450 columnNode->MarkModifyDone();
451 columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
452 auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
453 layoutProperty->UpdateAlignment(Alignment::CENTER);
454 stackNode->MountToParent(AceType::Claim(frameNode));
455 }
456 }
457
458 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
459 CHECK_NULL_VOID(textPickerPattern);
460 textPickerPattern->SetCascadeOptions(options, options);
461 }
462
SetCascadeColumns(const std::vector<NG::TextCascadePickerOptions> & options)463 void TextPickerModelNG::SetCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options)
464 {
465 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
466 CHECK_NULL_VOID(frameNode);
467 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
468 CHECK_NULL_VOID(textPickerPattern);
469 std::vector<NG::TextCascadePickerOptions> reOptions;
470 // Caculate max depth
471 size_t columnCount = options.empty()? 0 : 1;
472 for (size_t i = 0; i < options.size(); i++) {
473 size_t tmp = textPickerPattern->ProcessCascadeOptionDepth(options[i]);
474 if (tmp > columnCount) {
475 columnCount = tmp;
476 }
477 }
478
479 // Create Node
480 if (frameNode->GetChildren().empty()) {
481 for (size_t i = 0; i < columnCount; i++) {
482 auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
483 auto stackNode = CreateStackNode();
484 auto buttonNode = CreateButtonNode();
485 auto columnBlendNode = CreateColumnNode();
486 buttonNode->MountToParent(stackNode);
487 columnNode->MountToParent(columnBlendNode);
488 columnBlendNode->MountToParent(stackNode);
489 columnNode->MarkModifyDone();
490 columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
491 auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
492 layoutProperty->UpdateAlignment(Alignment::CENTER);
493 stackNode->MountToParent(AceType::Claim<NG::FrameNode>(frameNode));
494 }
495 }
496
497 textPickerPattern->ProcessCascadeOptions(options, reOptions, 0);
498 if (reOptions.size() < columnCount) {
499 auto differ = columnCount - reOptions.size();
500 for (uint32_t i = 0; i < differ; i++) {
501 NG::TextCascadePickerOptions differOption;
502 memset_s(&differOption, sizeof(differOption), 0, sizeof(differOption));
503 reOptions.emplace_back(differOption);
504 }
505 }
506 textPickerPattern->SetCascadeOptions(options, reOptions);
507 }
508
SetColumns(const std::vector<NG::TextCascadePickerOptions> & options)509 void TextPickerModelNG::SetColumns(const std::vector<NG::TextCascadePickerOptions>& options)
510 {
511 options_.clear();
512 for (auto& option : options) {
513 options_.emplace_back(std::move(option));
514 }
515 if (!isCascade_) {
516 SetUnCascadeColumns(options);
517 } else {
518 SetCascadeColumns(options);
519 }
520 }
521
IsSingle()522 bool TextPickerModelNG::IsSingle()
523 {
524 return rangeValue_.size() > 0;
525 }
526
IsSingle(FrameNode * frameNode)527 bool TextPickerModelNG::IsSingle(FrameNode* frameNode)
528 {
529 CHECK_NULL_RETURN(frameNode, false);
530 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
531 CHECK_NULL_RETURN(textPickerPattern, false);
532 return textPickerPattern->GetRange().size() > 0;
533 }
534
GetSingleRange(std::vector<NG::RangeContent> & rangeValue)535 bool TextPickerModelNG::GetSingleRange(std::vector<NG::RangeContent>& rangeValue)
536 {
537 rangeValue.clear();
538 for (auto& item : rangeValue_) {
539 rangeValue.emplace_back(std::move(item));
540 }
541 return true;
542 }
543
GetSingleRange(FrameNode * frameNode,std::vector<NG::RangeContent> & rangeValue)544 bool TextPickerModelNG::GetSingleRange(FrameNode* frameNode, std::vector<NG::RangeContent>& rangeValue)
545 {
546 rangeValue.clear();
547 CHECK_NULL_RETURN(frameNode, false);
548 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
549 CHECK_NULL_RETURN(textPickerPattern, false);
550 for (auto& item : textPickerPattern->GetRange()) {
551 rangeValue.emplace_back(std::move(item));
552 }
553 return true;
554 }
555
IsCascade(FrameNode * frameNode)556 bool TextPickerModelNG::IsCascade(FrameNode* frameNode)
557 {
558 CHECK_NULL_RETURN(frameNode, false);
559 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
560 CHECK_NULL_RETURN(textPickerPattern, false);
561 return textPickerPattern->GetIsCascade();
562 }
563
GetMultiOptions(std::vector<NG::TextCascadePickerOptions> & options)564 bool TextPickerModelNG::GetMultiOptions(std::vector<NG::TextCascadePickerOptions>& options)
565 {
566 options.clear();
567 for (auto& item : options_) {
568 options.emplace_back(std::move(item));
569 }
570 return true;
571 }
572
GetMultiOptions(FrameNode * frameNode,std::vector<NG::TextCascadePickerOptions> & options)573 bool TextPickerModelNG::GetMultiOptions(FrameNode* frameNode, std::vector<NG::TextCascadePickerOptions>& options)
574 {
575 options.clear();
576 CHECK_NULL_RETURN(frameNode, false);
577 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
578 CHECK_NULL_RETURN(textPickerPattern, false);
579 for (auto& item : textPickerPattern->GetMultiOptions()) {
580 options.emplace_back(std::move(item));
581 }
582 return true;
583 }
584
GetMaxCount(FrameNode * frameNode)585 uint32_t TextPickerModelNG::GetMaxCount(FrameNode* frameNode)
586 {
587 return 1;
588 }
589
SetValues(const std::vector<std::string> & values)590 void TextPickerModelNG::SetValues(const std::vector<std::string>& values)
591 {
592 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
593 CHECK_NULL_VOID(frameNode);
594 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
595 CHECK_NULL_VOID(textPickerPattern);
596 textPickerPattern->SetValues(values);
597 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Values, values);
598 }
599
SetSelecteds(const std::vector<uint32_t> & values)600 void TextPickerModelNG::SetSelecteds(const std::vector<uint32_t>& values)
601 {
602 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
603 CHECK_NULL_VOID(frameNode);
604 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
605 CHECK_NULL_VOID(textPickerPattern);
606 textPickerPattern->SetSelecteds(values);
607 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selecteds, values);
608 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values);
609 }
610
SetOnValueChangeEvent(TextCascadeValueChangeEvent && onValueChangeEvent)611 void TextPickerModelNG::SetOnValueChangeEvent(TextCascadeValueChangeEvent&& onValueChangeEvent)
612 {
613 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
614 CHECK_NULL_VOID(frameNode);
615 auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
616 CHECK_NULL_VOID(eventHub);
617 eventHub->SetOnValueChangeEvent(std::move(onValueChangeEvent));
618 }
619
SetOnSelectedChangeEvent(TextCascadeSelectedChangeEvent && onSelectedChangeEvent)620 void TextPickerModelNG::SetOnSelectedChangeEvent(TextCascadeSelectedChangeEvent&& onSelectedChangeEvent)
621 {
622 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
623 CHECK_NULL_VOID(frameNode);
624 auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
625 CHECK_NULL_VOID(eventHub);
626 eventHub->SetOnSelectedChangeEvent(std::move(onSelectedChangeEvent));
627 }
628
CreateObject()629 RefPtr<AceType> TextPickerDialogModelNG::CreateObject()
630 {
631 return nullptr;
632 }
633
SetTextPickerDialogShow(RefPtr<AceType> & PickerText,NG::TextPickerSettingData & settingData,std::function<void ()> && onCancel,std::function<void (const std::string &)> && onAccept,std::function<void (const std::string &)> && onChange,std::function<void (const std::string &)> && onScrollStop,TextPickerDialog & textPickerDialog,TextPickerDialogEvent & textPickerDialogEvent,const std::vector<ButtonInfo> & buttonInfos)634 void TextPickerDialogModelNG::SetTextPickerDialogShow(RefPtr<AceType>& PickerText,
635 NG::TextPickerSettingData& settingData, std::function<void()>&& onCancel,
636 std::function<void(const std::string&)>&& onAccept, std::function<void(const std::string&)>&& onChange,
637 std::function<void(const std::string&)>&& onScrollStop, TextPickerDialog& textPickerDialog,
638 TextPickerDialogEvent& textPickerDialogEvent, const std::vector<ButtonInfo>& buttonInfos)
639 {
640 auto container = Container::Current();
641 if (!container) {
642 return;
643 }
644 auto pipelineContext = AccessibilityManager::DynamicCast<NG::PipelineContext>(container->GetPipelineContext());
645 if (!pipelineContext) {
646 return;
647 }
648 auto executor = pipelineContext->GetTaskExecutor();
649 if (!executor) {
650 return;
651 }
652 auto pipeline = PipelineBase::GetCurrentContext();
653 CHECK_NULL_VOID(pipeline);
654 auto theme = pipeline->GetTheme<DialogTheme>();
655 CHECK_NULL_VOID(theme);
656
657 std::map<std::string, NG::DialogTextEvent> dialogEvent;
658 std::map<std::string, NG::DialogCancelEvent> dialogLifeCycleEvent;
659 std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent;
660 dialogEvent["acceptId"] = onAccept;
661 dialogEvent["changeId"] = onChange;
662 dialogEvent["scrollStopId"] = onScrollStop;
663 auto func = [onCancel](const GestureEvent& /* info */) {
664 if (onCancel) {
665 onCancel();
666 }
667 };
668 dialogCancelEvent["cancelId"] = func;
669 dialogLifeCycleEvent["didAppearId"] = textPickerDialogEvent.onDidAppear;
670 dialogLifeCycleEvent["didDisappearId"] = textPickerDialogEvent.onDidDisappear;
671 dialogLifeCycleEvent["willAppearId"] = textPickerDialogEvent.onWillAppear;
672 dialogLifeCycleEvent["willDisappearId"] = textPickerDialogEvent.onWillDisappear;
673 DialogProperties properties;
674 SetDialogProperties(properties, textPickerDialog, theme);
675
676 auto context = AccessibilityManager::DynamicCast<NG::PipelineContext>(pipelineContext);
677 auto overlayManager = context ? context->GetOverlayManager() : nullptr;
678 executor->PostTask(
679 [properties, settingData, dialogEvent, dialogCancelEvent, dialogLifeCycleEvent, buttonInfos,
680 weak = WeakPtr<NG::OverlayManager>(overlayManager)] {
681 auto overlayManager = weak.Upgrade();
682 CHECK_NULL_VOID(overlayManager);
683 overlayManager->ShowTextDialog(
684 properties, settingData, dialogEvent, dialogCancelEvent, dialogLifeCycleEvent, buttonInfos);
685 },
686 TaskExecutor::TaskType::UI, "ArkUITextPickerShowTextDialog");
687 }
688
SetCanLoop(FrameNode * frameNode,const bool value)689 void TextPickerModelNG::SetCanLoop(FrameNode* frameNode, const bool value)
690 {
691 CHECK_NULL_VOID(frameNode);
692 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
693 CHECK_NULL_VOID(textPickerPattern);
694 textPickerPattern->SetCanLoop(value);
695 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, value, frameNode);
696 }
697
GetCanLoop(FrameNode * frameNode)698 int32_t TextPickerModelNG::GetCanLoop(FrameNode* frameNode)
699 {
700 CHECK_NULL_RETURN(frameNode, 1);
701 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
702 CHECK_NULL_RETURN(textPickerPattern, 1);
703 return textPickerPattern->GetCanLoop();
704 }
705
SetSelecteds(FrameNode * frameNode,const std::vector<uint32_t> & values)706 void TextPickerModelNG::SetSelecteds(FrameNode* frameNode, const std::vector<uint32_t>& values)
707 {
708 CHECK_NULL_VOID(frameNode);
709 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
710 CHECK_NULL_VOID(textPickerPattern);
711 textPickerPattern->SetSelecteds(values);
712 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selecteds, values, frameNode);
713 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values, frameNode);
714 }
SetSelected(FrameNode * frameNode,uint32_t value)715 void TextPickerModelNG::SetSelected(FrameNode* frameNode, uint32_t value)
716 {
717 CHECK_NULL_VOID(frameNode);
718 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
719 textPickerPattern->SetSelected(value);
720 std::vector<uint32_t> values;
721 values.emplace_back(value);
722 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selected, value, frameNode);
723 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values, frameNode);
724 }
SetHasSelectAttr(FrameNode * frameNode,bool value)725 void TextPickerModelNG::SetHasSelectAttr(FrameNode* frameNode, bool value)
726 {
727 CHECK_NULL_VOID(frameNode);
728 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
729 CHECK_NULL_VOID(textPickerPattern);
730 textPickerPattern->SetHasSelectAttr(value);
731 }
SetNormalTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)732 void TextPickerModelNG::SetNormalTextStyle(
733 FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
734 {
735 CHECK_NULL_VOID(frameNode);
736 CHECK_NULL_VOID(pickerTheme);
737 auto normalStyle = pickerTheme->GetOptionStyle(false, false);
738 if (value.fontSize.has_value() && value.fontSize->IsValid()) {
739 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
740 ConvertFontScaleValue(value.fontSize.value()), frameNode);
741 } else {
742 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
743 ConvertFontScaleValue(normalStyle.GetFontSize()), frameNode);
744 }
745 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
746 TextPickerLayoutProperty, Color, value.textColor.value_or(normalStyle.GetTextColor()), frameNode);
747 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
748 TextPickerLayoutProperty, Weight, value.fontWeight.value_or(normalStyle.GetFontWeight()), frameNode);
749 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
750 TextPickerLayoutProperty, FontFamily, value.fontFamily.value_or(normalStyle.GetFontFamilies()), frameNode);
751 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
752 TextPickerLayoutProperty, FontStyle, value.fontStyle.value_or(normalStyle.GetFontStyle()), frameNode);
753 }
754
SetSelectedTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)755 void TextPickerModelNG::SetSelectedTextStyle(
756 FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
757 {
758 CHECK_NULL_VOID(frameNode);
759 CHECK_NULL_VOID(pickerTheme);
760 auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
761 if (value.fontSize.has_value() && value.fontSize->IsValid()) {
762 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
763 TextPickerLayoutProperty, SelectedFontSize,
764 ConvertFontScaleValue(value.fontSize.value()), frameNode);
765 } else {
766 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
767 TextPickerLayoutProperty, SelectedFontSize,
768 ConvertFontScaleValue(selectedStyle.GetFontSize()), frameNode);
769 }
770 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
771 TextPickerLayoutProperty, SelectedColor,
772 value.textColor.value_or(selectedStyle.GetTextColor()), frameNode);
773 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
774 TextPickerLayoutProperty, SelectedWeight,
775 value.fontWeight.value_or(selectedStyle.GetFontWeight()), frameNode);
776 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
777 TextPickerLayoutProperty, SelectedFontFamily,
778 value.fontFamily.value_or(selectedStyle.GetFontFamilies()), frameNode);
779 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
780 TextPickerLayoutProperty, SelectedFontStyle, value.fontStyle.value_or(selectedStyle.GetFontStyle()), frameNode);
781 }
782
SetDisappearTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)783 void TextPickerModelNG::SetDisappearTextStyle(
784 FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
785 {
786 CHECK_NULL_VOID(frameNode);
787 CHECK_NULL_VOID(pickerTheme);
788 auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
789 if (value.fontSize.has_value() && value.fontSize->IsValid()) {
790 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
791 TextPickerLayoutProperty, DisappearFontSize,
792 ConvertFontScaleValue(value.fontSize.value()), frameNode);
793 } else {
794 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
795 TextPickerLayoutProperty, DisappearFontSize,
796 ConvertFontScaleValue(disappearStyle.GetFontSize()), frameNode);
797 }
798 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
799 TextPickerLayoutProperty, DisappearColor, value.textColor.value_or(disappearStyle.GetTextColor()), frameNode);
800 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
801 TextPickerLayoutProperty, DisappearWeight,
802 value.fontWeight.value_or(disappearStyle.GetFontWeight()), frameNode);
803 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
804 TextPickerLayoutProperty, DisappearFontFamily,
805 value.fontFamily.value_or(disappearStyle.GetFontFamilies()), frameNode);
806 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
807 TextPickerLayoutProperty, DisappearFontStyle,
808 value.fontStyle.value_or(disappearStyle.GetFontStyle()), frameNode);
809 }
810
SetDefaultPickerItemHeight(FrameNode * frameNode,const Dimension & value)811 void TextPickerModelNG::SetDefaultPickerItemHeight(FrameNode* frameNode, const Dimension& value)
812 {
813 CHECK_NULL_VOID(frameNode);
814 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultPickerItemHeight, value, frameNode);
815 }
816
GetDefaultPickerItemHeight(FrameNode * frameNode)817 Dimension TextPickerModelNG::GetDefaultPickerItemHeight(FrameNode* frameNode)
818 {
819 Dimension value = Dimension(0.0f);
820 CHECK_NULL_RETURN(frameNode, value);
821 auto layoutProperty = frameNode->GetLayoutProperty<TextPickerLayoutProperty>();
822 CHECK_NULL_RETURN(layoutProperty, value);
823 return layoutProperty->HasDefaultPickerItemHeight() ? layoutProperty->GetDefaultPickerItemHeightValue() : value;
824 }
825
SetBackgroundColor(FrameNode * frameNode,const Color & color)826 void TextPickerModelNG::SetBackgroundColor(FrameNode* frameNode, const Color& color)
827 {
828 CHECK_NULL_VOID(frameNode);
829 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
830 CHECK_NULL_VOID(textPickerPattern);
831 textPickerPattern->SetBackgroundColor(color);
832 }
833
getDisappearTextStyle(FrameNode * frameNode)834 PickerTextStyle TextPickerModelNG::getDisappearTextStyle(FrameNode* frameNode)
835 {
836 PickerTextStyle pickerTextStyle;
837 CHECK_NULL_RETURN(frameNode, pickerTextStyle);
838 auto context = frameNode->GetContext();
839 CHECK_NULL_RETURN(context, pickerTextStyle);
840 auto theme = context->GetTheme<PickerTheme>();
841 CHECK_NULL_RETURN(theme, pickerTextStyle);
842 auto style = theme->GetDisappearOptionStyle();
843 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
844 TextPickerLayoutProperty, DisappearFontSize, pickerTextStyle.fontSize, frameNode,
845 ConvertFontScaleValue(style.GetFontSize()));
846 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
847 TextPickerLayoutProperty, DisappearColor, pickerTextStyle.textColor, frameNode, style.GetTextColor());
848 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
849 TextPickerLayoutProperty, DisappearWeight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
850 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, DisappearFontFamily,
851 pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
852 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, DisappearFontStyle,
853 pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
854 return pickerTextStyle;
855 }
856
getNormalTextStyle(FrameNode * frameNode)857 PickerTextStyle TextPickerModelNG::getNormalTextStyle(FrameNode* frameNode)
858 {
859 PickerTextStyle pickerTextStyle;
860 CHECK_NULL_RETURN(frameNode, pickerTextStyle);
861 auto context = frameNode->GetContext();
862 CHECK_NULL_RETURN(context, pickerTextStyle);
863 auto theme = context->GetTheme<PickerTheme>();
864 CHECK_NULL_RETURN(theme, pickerTextStyle);
865 auto style = theme->GetOptionStyle(false, false);
866 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
867 TextPickerLayoutProperty, FontSize, pickerTextStyle.fontSize, frameNode,
868 ConvertFontScaleValue(style.GetFontSize()));
869 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
870 TextPickerLayoutProperty, Color, pickerTextStyle.textColor, frameNode, style.GetTextColor());
871 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
872 TextPickerLayoutProperty, Weight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
873 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, FontFamily,
874 pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
875 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, FontStyle,
876 pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
877 return pickerTextStyle;
878 }
879
getSelectedTextStyle(FrameNode * frameNode)880 PickerTextStyle TextPickerModelNG::getSelectedTextStyle(FrameNode* frameNode)
881 {
882 PickerTextStyle pickerTextStyle;
883 CHECK_NULL_RETURN(frameNode, pickerTextStyle);
884 auto context = frameNode->GetContext();
885 CHECK_NULL_RETURN(context, pickerTextStyle);
886 auto theme = context->GetTheme<PickerTheme>();
887 CHECK_NULL_RETURN(theme, pickerTextStyle);
888 auto style = theme->GetOptionStyle(true, false);
889 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
890 TextPickerLayoutProperty, SelectedFontSize, pickerTextStyle.fontSize, frameNode,
891 ConvertFontScaleValue(style.GetFontSize()));
892 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
893 TextPickerLayoutProperty, SelectedColor, pickerTextStyle.textColor, frameNode, style.GetTextColor());
894 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
895 TextPickerLayoutProperty, SelectedWeight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
896 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedFontFamily,
897 pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
898 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedFontStyle,
899 pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
900 return pickerTextStyle;
901 }
902
getTextPickerSelectedIndex(FrameNode * frameNode)903 int32_t TextPickerModelNG::getTextPickerSelectedIndex(FrameNode* frameNode)
904 {
905 CHECK_NULL_RETURN(frameNode, 0);
906 return frameNode->GetLayoutProperty<TextPickerLayoutProperty>()->GetSelectedValue(0);
907 }
908
SetRange(FrameNode * frameNode,const std::vector<NG::RangeContent> & value)909 void TextPickerModelNG::SetRange(FrameNode* frameNode, const std::vector<NG::RangeContent>& value)
910 {
911 CHECK_NULL_VOID(frameNode);
912 if (frameNode->GetChildren().empty()) {
913 auto columnNode = CreateColumnNode(TEXT, showCount_);
914 auto stackNode = CreateStackNode();
915 auto buttonNode = CreateButtonNode();
916 auto columnBlendNode = CreateColumnNode();
917 buttonNode->MountToParent(stackNode);
918 columnNode->MountToParent(columnBlendNode);
919 columnBlendNode->MountToParent(stackNode);
920 columnNode->MarkModifyDone();
921 columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
922 auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
923 layoutProperty->UpdateAlignment(Alignment::CENTER);
924 stackNode->MountToParent(AceType::Claim(frameNode));
925 }
926 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
927 textPickerPattern->SetRange(value);
928 rangeValue_.clear();
929 for (auto& range : value) {
930 rangeValue_.emplace_back(std::move(range));
931 }
932 }
933
SetColumns(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)934 void TextPickerModelNG::SetColumns(FrameNode* frameNode, const std::vector<NG::TextCascadePickerOptions>& options)
935 {
936 options_.clear();
937 for (auto& option : options) {
938 options_.emplace_back(std::move(option));
939 }
940 if (!isCascade_) {
941 SetUnCascadeColumnsNode(frameNode, options);
942 } else {
943 SetCascadeColumnsNode(frameNode, options);
944 }
945 }
946
SetUnCascadeColumnsNode(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)947 void TextPickerModelNG::SetUnCascadeColumnsNode(FrameNode* frameNode,
948 const std::vector<NG::TextCascadePickerOptions>& options)
949 {
950 CHECK_NULL_VOID(frameNode);
951 if (frameNode->GetChildren().empty()) {
952 for (uint32_t i = 0; i < options.size(); i++) {
953 auto columnNode = CreateColumnNode(TEXT, showCount_);
954 auto stackNode = CreateStackNode();
955 auto buttonNode = CreateButtonNode();
956 auto columnBlendNode = CreateColumnNode();
957 buttonNode->MountToParent(stackNode);
958 columnNode->MountToParent(columnBlendNode);
959 columnBlendNode->MountToParent(stackNode);
960 columnNode->MarkModifyDone();
961 columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
962 auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
963 layoutProperty->UpdateAlignment(Alignment::CENTER);
964 stackNode->MountToParent(AceType::Claim(frameNode));
965 }
966 }
967
968 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
969 CHECK_NULL_VOID(textPickerPattern);
970 textPickerPattern->SetCascadeOptions(options, options);
971 }
972
SetCascadeColumnsNode(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)973 void TextPickerModelNG::SetCascadeColumnsNode(FrameNode* frameNode,
974 const std::vector<NG::TextCascadePickerOptions>& options)
975 {
976 CHECK_NULL_VOID(frameNode);
977 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
978 CHECK_NULL_VOID(textPickerPattern);
979 std::vector<NG::TextCascadePickerOptions> reOptions;
980 // Caculate max depth
981 size_t columnCount = options.empty()? 0 : 1;
982 for (size_t i = 0; i < options.size(); i++) {
983 size_t tmp = textPickerPattern->ProcessCascadeOptionDepth(options[i]);
984 if (tmp > columnCount) {
985 columnCount = tmp;
986 }
987 }
988
989 // Create Node
990 if (frameNode->GetChildren().empty()) {
991 for (size_t i = 0; i < columnCount; i++) {
992 auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
993 auto stackNode = CreateStackNode();
994 auto buttonNode = CreateButtonNode();
995 auto columnBlendNode = CreateColumnNode();
996 buttonNode->MountToParent(stackNode);
997 columnNode->MountToParent(columnBlendNode);
998 columnBlendNode->MountToParent(stackNode);
999 columnNode->MarkModifyDone();
1000 columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1001 auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
1002 layoutProperty->UpdateAlignment(Alignment::CENTER);
1003 stackNode->MountToParent(AceType::Claim(frameNode));
1004 }
1005 }
1006
1007 textPickerPattern->ProcessCascadeOptions(options, reOptions, 0);
1008 if (reOptions.size() < columnCount) {
1009 auto differ = columnCount - reOptions.size();
1010 for (uint32_t i = 0; i < differ; i++) {
1011 NG::TextCascadePickerOptions differOption;
1012 memset_s(&differOption, sizeof(differOption), 0, sizeof(differOption));
1013 reOptions.emplace_back(differOption);
1014 }
1015 }
1016 textPickerPattern->SetCascadeOptions(options, reOptions);
1017 }
1018
SetValue(FrameNode * frameNode,const std::string & value)1019 void TextPickerModelNG::SetValue(FrameNode* frameNode, const std::string& value)
1020 {
1021 CHECK_NULL_VOID(frameNode);
1022 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Value, value, frameNode);
1023 auto valueIterator = std::find_if(rangeValue_.begin(), rangeValue_.end(),
1024 [&value](const NG::RangeContent& range) { return range.text_ == value; });
1025 if (valueIterator != rangeValue_.end()) {
1026 TextPickerModelNG::SetSelected(frameNode, std::distance(rangeValue_.begin(), valueIterator));
1027 }
1028 }
1029
SetValues(FrameNode * frameNode,const std::vector<std::string> & values)1030 void TextPickerModelNG::SetValues(FrameNode* frameNode, const std::vector<std::string>& values)
1031 {
1032 CHECK_NULL_VOID(frameNode);
1033 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1034 CHECK_NULL_VOID(textPickerPattern);
1035 std::vector<std::string> selectedValues;
1036 std::vector<uint32_t> valuesIndex;
1037 for (uint32_t i = 0; i < options_.size(); i++) {
1038 if (values.size() > 0 && values.size() < i + 1) {
1039 if (options_[i].rangeResult.size() > 0) {
1040 selectedValues.emplace_back(options_[i].rangeResult[0]);
1041 } else {
1042 selectedValues.emplace_back("");
1043 }
1044 valuesIndex.emplace_back(0);
1045 } else {
1046 auto valueIterator = std::find(options_[i].rangeResult.begin(), options_[i].rangeResult.end(), values[i]);
1047 if (valueIterator == options_[i].rangeResult.end()) {
1048 selectedValues[i] = options_[i].rangeResult.front();
1049 valuesIndex.emplace_back(0);
1050 } else {
1051 selectedValues.emplace_back(values[i]);
1052 valuesIndex.emplace_back(std::distance(options_[i].rangeResult.begin(), valueIterator));
1053 }
1054 }
1055 }
1056 TextPickerModelNG::SetSelecteds(frameNode, valuesIndex);
1057 textPickerPattern->SetValues(selectedValues);
1058 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Values, selectedValues, frameNode);
1059 }
1060
SetDefaultAttributes(RefPtr<FrameNode> & frameNode,const RefPtr<PickerTheme> & pickerTheme)1061 void TextPickerModelNG::SetDefaultAttributes(RefPtr<FrameNode>& frameNode, const RefPtr<PickerTheme>& pickerTheme)
1062 {
1063 auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
1064 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
1065 ConvertFontScaleValue(selectedStyle.GetFontSize()), frameNode);
1066 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedColor, selectedStyle.GetTextColor(), frameNode);
1067 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedWeight, selectedStyle.GetFontWeight(), frameNode);
1068 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1069 TextPickerLayoutProperty, SelectedFontFamily, selectedStyle.GetFontFamilies(), frameNode);
1070 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1071 TextPickerLayoutProperty, SelectedFontStyle, selectedStyle.GetFontStyle(), frameNode);
1072
1073 auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
1074 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1075 TextPickerLayoutProperty, DisappearFontSize,
1076 ConvertFontScaleValue(disappearStyle.GetFontSize()), frameNode);
1077 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1078 TextPickerLayoutProperty, DisappearColor, disappearStyle.GetTextColor(), frameNode);
1079 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1080 TextPickerLayoutProperty, DisappearWeight, disappearStyle.GetFontWeight(), frameNode);
1081 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1082 TextPickerLayoutProperty, DisappearFontFamily, disappearStyle.GetFontFamilies(), frameNode);
1083 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1084 TextPickerLayoutProperty, DisappearFontStyle, disappearStyle.GetFontStyle(), frameNode);
1085
1086 auto normalStyle = pickerTheme->GetOptionStyle(false, false);
1087 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
1088 ConvertFontScaleValue(normalStyle.GetFontSize()), frameNode);
1089 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Color, normalStyle.GetTextColor(), frameNode);
1090 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Weight, normalStyle.GetFontWeight(), frameNode);
1091 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontFamily, normalStyle.GetFontFamilies(), frameNode);
1092 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontStyle, normalStyle.GetFontStyle(), frameNode);
1093
1094 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, true, frameNode);
1095 }
1096
getTextPickerValue(FrameNode * frameNode)1097 std::string TextPickerModelNG::getTextPickerValue(FrameNode* frameNode)
1098 {
1099 CHECK_NULL_RETURN(frameNode, "");
1100 return frameNode->GetLayoutProperty<TextPickerLayoutProperty>()->GetValueValue("");
1101 }
1102
getTextPickerRange(FrameNode * frameNode)1103 std::string TextPickerModelNG::getTextPickerRange(FrameNode* frameNode)
1104 {
1105 CHECK_NULL_RETURN(frameNode, "");
1106 std::string result;
1107 if (isSingleRange_) {
1108 for (auto range : rangeValue_) {
1109 result.append(range.text_ + ";");
1110 }
1111 if (result.length() > 0) {
1112 result = result.substr(0, result.length() > 0 ? result.length() - 1 : 0);
1113 }
1114 } else {
1115 for (auto option : options_) {
1116 for (auto range : option.rangeResult) {
1117 result.append(range + ",");
1118 }
1119 result = result.substr(0, result.length() > 0 ? result.length() - 1 : 0);
1120 result.append(";");
1121 }
1122 if (result.length() > 0) {
1123 result = result.substr(0, result.length() - 1);
1124 }
1125 }
1126 return result;
1127 }
1128
SetDivider(const ItemDivider & divider)1129 void TextPickerModelNG::SetDivider(const ItemDivider& divider)
1130 {
1131 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1132 CHECK_NULL_VOID(frameNode);
1133 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1134 CHECK_NULL_VOID(textPickerPattern);
1135 textPickerPattern->SetDivider(divider);
1136 textPickerPattern->SetCustomDividerFlag(true);
1137 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, divider);
1138 }
1139
SetDivider(FrameNode * frameNode,const ItemDivider & divider)1140 void TextPickerModelNG::SetDivider(FrameNode* frameNode, const ItemDivider& divider)
1141 {
1142 CHECK_NULL_VOID(frameNode);
1143 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1144 CHECK_NULL_VOID(textPickerPattern);
1145 textPickerPattern->SetDivider(divider);
1146 textPickerPattern->SetCustomDividerFlag(true);
1147 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, divider, frameNode);
1148 }
1149
SetGradientHeight(FrameNode * frameNode,const Dimension & value)1150 void TextPickerModelNG::SetGradientHeight(FrameNode* frameNode, const Dimension& value)
1151 {
1152 CHECK_NULL_VOID(frameNode);
1153 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1154 CHECK_NULL_VOID(textPickerPattern);
1155 textPickerPattern->SetGradientHeight(value);
1156 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, value, frameNode);
1157 }
1158
SetOnCascadeChange(FrameNode * frameNode,TextCascadeChangeEvent && onChange)1159 void TextPickerModelNG::SetOnCascadeChange(FrameNode* frameNode, TextCascadeChangeEvent&& onChange)
1160 {
1161 CHECK_NULL_VOID(frameNode);
1162 auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
1163 CHECK_NULL_VOID(eventHub);
1164 eventHub->SetOnChange(std::move(onChange));
1165 }
1166
SetOnScrollStop(FrameNode * frameNode,TextCascadeChangeEvent && onScrollStop)1167 void TextPickerModelNG::SetOnScrollStop(FrameNode* frameNode, TextCascadeChangeEvent&& onScrollStop)
1168 {
1169 CHECK_NULL_VOID(frameNode);
1170 auto eventHub = frameNode->GetEventHub<TextPickerEventHub>();
1171 CHECK_NULL_VOID(eventHub);
1172 eventHub->SetOnScrollStop(std::move(onScrollStop));
1173 }
1174
GetSelectedSize(FrameNode * frameNode)1175 int32_t TextPickerModelNG::GetSelectedSize(FrameNode* frameNode)
1176 {
1177 CHECK_NULL_RETURN(frameNode, 0);
1178 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1179 CHECK_NULL_RETURN(textPickerPattern, 0);
1180 return textPickerPattern->GetSelecteds().size();
1181 }
1182
getTextPickerValues(FrameNode * frameNode)1183 std::string TextPickerModelNG::getTextPickerValues(FrameNode* frameNode)
1184 {
1185 CHECK_NULL_RETURN(frameNode, "");
1186 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1187 CHECK_NULL_RETURN(textPickerPattern, "");
1188 auto values = textPickerPattern->GetValues();
1189 std::string result;
1190 for (auto& valueRet : values) {
1191 result.append(valueRet + ';');
1192 }
1193 const size_t length = result.length();
1194 result = result.substr(0, length > 0 ? length - 1 : 0);
1195 return result;
1196 }
1197
getTextPickerSelecteds(FrameNode * frameNode)1198 std::vector<uint32_t> TextPickerModelNG::getTextPickerSelecteds(FrameNode* frameNode)
1199 {
1200 std::vector<uint32_t> defaultValue = { 0 };
1201 CHECK_NULL_RETURN(frameNode, defaultValue);
1202 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1203 CHECK_NULL_RETURN(textPickerPattern, defaultValue);
1204 return textPickerPattern->GetSelecteds();
1205 }
1206
SetTextPickerRangeType(FrameNode * frameNode,int32_t rangeType)1207 void TextPickerModelNG::SetTextPickerRangeType(FrameNode* frameNode, int32_t rangeType)
1208 {
1209 CHECK_NULL_VOID(frameNode);
1210 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1211 CHECK_NULL_VOID(textPickerPattern);
1212 textPickerPattern->SetRangeType(rangeType);
1213 }
1214
GetTextPickerRangeType(FrameNode * frameNode)1215 int32_t TextPickerModelNG::GetTextPickerRangeType(FrameNode* frameNode)
1216 {
1217 CHECK_NULL_RETURN(frameNode, 0);
1218 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1219 CHECK_NULL_RETURN(textPickerPattern, 0);
1220 return textPickerPattern->GetRangeType();
1221 }
1222
ConvertFontScaleValue(const Dimension & fontSizeValue)1223 const Dimension TextPickerModelNG::ConvertFontScaleValue(const Dimension& fontSizeValue)
1224 {
1225 auto pipeline = PipelineContext::GetCurrentContext();
1226 CHECK_NULL_RETURN(pipeline, fontSizeValue);
1227
1228 float fontScaleValue = pipeline->GetFontScale();
1229 if (fontScaleValue == 0) {
1230 return fontSizeValue;
1231 }
1232
1233 if (GreatOrEqualCustomPrecision(fontScaleValue, PICKER_MAXFONTSCALE)) {
1234 if (fontSizeValue.Unit() != DimensionUnit::VP) {
1235 return Dimension(fontSizeValue / fontScaleValue);
1236 }
1237 }
1238 return fontSizeValue;
1239 }
1240
HasUserDefinedOpacity()1241 void TextPickerModelNG::HasUserDefinedOpacity()
1242 {
1243 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1244 CHECK_NULL_VOID(frameNode);
1245 auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1246 CHECK_NULL_VOID(textPickerPattern);
1247 auto renderContext = frameNode->GetRenderContext();
1248 CHECK_NULL_VOID(renderContext);
1249 textPickerPattern->SetUserDefinedOpacity(renderContext->GetOpacityValue(1.0));
1250 }
1251
1252 } // namespace OHOS::Ace::NG
1253