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