• 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/common/resource/resource_object.h"
36 #include "core/common/resource/resource_parse_utils.h"
37 
38 namespace OHOS::Ace::NG {
39 namespace {
40 constexpr float PICKER_MAXFONTSCALE = 1.0f;
41 constexpr bool DEFAULT_ENABLE_HAPTIC_FEEDBACK = true;
42 const int32_t BUFFER_NODE_NUMBER = 2;
43 
SetDialogProperties(DialogProperties & properties,TextPickerDialog & textPickerDialog,const RefPtr<DialogTheme> & theme)44 void SetDialogProperties(DialogProperties& properties, TextPickerDialog& textPickerDialog,
45                          const RefPtr<DialogTheme>& theme)
46 {
47     if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
48         properties.alignment = theme->GetAlignment();
49     }
50     if (textPickerDialog.alignment.has_value()) {
51         properties.alignment = textPickerDialog.alignment.value();
52     }
53 
54     if (textPickerDialog.backgroundColor.has_value()) {
55         properties.backgroundColor = textPickerDialog.backgroundColor.value();
56     }
57     if (textPickerDialog.backgroundBlurStyle.has_value()) {
58         properties.backgroundBlurStyle = textPickerDialog.backgroundBlurStyle.value();
59     }
60     if (textPickerDialog.blurStyleOption.has_value()) {
61         properties.blurStyleOption = textPickerDialog.blurStyleOption.value();
62     }
63     if (textPickerDialog.effectOption.has_value()) {
64         properties.effectOption = textPickerDialog.effectOption.value();
65     }
66     if (textPickerDialog.shadow.has_value()) {
67         properties.shadow = textPickerDialog.shadow.value();
68     }
69     properties.customStyle = false;
70     if (Container::LessThanAPIVersion(PlatformVersion::VERSION_ELEVEN)) {
71         properties.offset = DimensionOffset(Offset(0, -theme->GetMarginBottom().ConvertToPx()));
72     }
73     if (textPickerDialog.offset.has_value()) {
74         properties.offset = textPickerDialog.offset.value();
75     }
76 
77     properties.maskRect = textPickerDialog.maskRect;
78     properties.enableHoverMode = textPickerDialog.enableHoverMode;
79     if (textPickerDialog.hoverModeArea.has_value()) {
80         properties.hoverModeArea = textPickerDialog.hoverModeArea.value();
81     }
82 }
83 
84 using TextPickerGetTextStyleFunc = const std::unique_ptr<FontStyle>& (TextPickerLayoutProperty::*)() const;
ResetTextPickerTextStyleColor(FrameNode * frameNode,TextPickerGetTextStyleFunc getTextStyleFunc)85 void ResetTextPickerTextStyleColor(FrameNode* frameNode, TextPickerGetTextStyleFunc getTextStyleFunc)
86 {
87     CHECK_NULL_VOID(frameNode);
88     auto property = frameNode->GetLayoutPropertyPtr<TextPickerLayoutProperty>();
89     CHECK_NULL_VOID(property);
90     auto& textStyle = (property->*getTextStyleFunc)();
91     CHECK_NULL_VOID(textStyle);
92     if (textStyle->HasTextColor()) {
93         textStyle->ResetTextColor();
94         property->UpdatePropertyChangeFlag(PROPERTY_UPDATE_MEASURE_SELF);
95     }
96 }
97 }
98 
Create(RefPtr<PickerTheme> pickerTheme,uint32_t columnKind)99 void TextPickerModelNG::Create(RefPtr<PickerTheme> pickerTheme, uint32_t columnKind)
100 {
101     auto* stack = ViewStackProcessor::GetInstance();
102     auto nodeId = stack->ClaimNodeId();
103     ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::TEXT_PICKER_ETS_TAG, nodeId);
104     auto textPickerNode = FrameNode::GetOrCreateFrameNode(
105         V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
106     auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
107     CHECK_NULL_VOID(textPickerPattern);
108     textPickerPattern->SetColumnsKind(columnKind);
109     auto pipeline = PipelineBase::GetCurrentContext();
110     CHECK_NULL_VOID(pipeline);
111     auto dialogTheme = pipeline->GetTheme<DialogTheme>();
112     CHECK_NULL_VOID(dialogTheme);
113     textPickerPattern->SetBackgroundColor(dialogTheme->GetBackgroundColor());
114     CHECK_NULL_VOID(pickerTheme);
115     uint32_t showCount = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
116 
117     if (textPickerNode->GetChildren().empty()) {
118         auto columnNode = CreateColumnNode(columnKind, showCount);
119         auto stackNode = CreateStackNode();
120         auto buttonNode = CreateButtonNode();
121         auto columnBlendNode = CreateColumnNode();
122         buttonNode->MountToParent(stackNode);
123         columnNode->MountToParent(columnBlendNode);
124         columnBlendNode->MountToParent(stackNode);
125         columnNode->MarkModifyDone();
126         columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
127         auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
128         layoutProperty->UpdateAlignment(Alignment::CENTER);
129         stackNode->MountToParent(textPickerNode);
130     }
131     stack->Push(textPickerNode);
132     if (pickerTheme->IsCircleDial()) {
133         auto renderContext = textPickerNode->GetRenderContext();
134         renderContext->UpdateBackgroundColor(pickerTheme->GetBackgroundColor());
135     }
136 }
137 
SetDefaultAttributes(const RefPtr<PickerTheme> & pickerTheme)138 void TextPickerModelNG::SetDefaultAttributes(const RefPtr<PickerTheme>& pickerTheme)
139 {
140     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
141     CHECK_NULL_VOID(frameNode);
142     CHECK_NULL_VOID(pickerTheme);
143     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
144     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
145         ConvertFontScaleValue(selectedStyle.GetFontSize()));
146     ResetTextPickerTextStyleColor(frameNode, &TextPickerLayoutProperty::GetSelectedTextStyle);
147     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedWeight, selectedStyle.GetFontWeight());
148     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontFamily, selectedStyle.GetFontFamilies());
149     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontStyle, selectedStyle.GetFontStyle());
150 
151     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
152     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
153         ConvertFontScaleValue(disappearStyle.GetFontSize()));
154     ResetTextPickerTextStyleColor(frameNode, &TextPickerLayoutProperty::GetDisappearTextStyle);
155     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearWeight, disappearStyle.GetFontWeight());
156     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontFamily, disappearStyle.GetFontFamilies());
157     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontStyle, disappearStyle.GetFontStyle());
158 
159     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
160     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
161         ConvertFontScaleValue(normalStyle.GetFontSize()));
162     ResetTextPickerTextStyleColor(frameNode, &TextPickerLayoutProperty::GetTextStyle);
163     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Weight, normalStyle.GetFontWeight());
164     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontFamily, normalStyle.GetFontFamilies());
165     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontStyle, normalStyle.GetFontStyle());
166     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, true);
167     ACE_UPDATE_LAYOUT_PROPERTY(
168         TextPickerLayoutProperty, DigitalCrownSensitivity, pickerTheme->GetDigitalCrownSensitivity());
169 }
170 
CreateColumnNode(uint32_t columnKind,uint32_t showCount)171 RefPtr<FrameNode> TextPickerModelNG::CreateColumnNode(uint32_t columnKind, uint32_t showCount)
172 {
173     auto columnNode =
174         FrameNode::GetOrCreateFrameNode(V2::COLUMN_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
175         []() { return AceType::MakeRefPtr<TextPickerColumnPattern>(); });
176     if (columnKind == ICON) {
177         for (uint32_t index = 0; index < showCount; index++) {
178             auto row = FrameNode::CreateFrameNode(
179                 V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
180                 AceType::MakeRefPtr<LinearLayoutPattern>(false));
181             CHECK_NULL_RETURN(row, nullptr);
182             auto layoutProps = row->GetLayoutProperty<LinearLayoutProperty>();
183             CHECK_NULL_RETURN(layoutProps, nullptr);
184             layoutProps->UpdateMainAxisAlign(FlexAlign::CENTER);
185             layoutProps->UpdateCrossAxisAlign(FlexAlign::CENTER);
186 
187             auto imageNode = FrameNode::CreateFrameNode(
188                 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
189                 AceType::MakeRefPtr<ImagePattern>());
190             CHECK_NULL_RETURN(imageNode, nullptr);
191             imageNode->MountToParent(row);
192             row->MountToParent(columnNode);
193         }
194     } else if (columnKind == TEXT) {
195         for (uint32_t index = 0; index < showCount; index++) {
196             auto textNode = FrameNode::CreateFrameNode(
197                 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
198                 AceType::MakeRefPtr<TextPattern>());
199             CHECK_NULL_RETURN(textNode, nullptr);
200             textNode->MountToParent(columnNode);
201         }
202     } else if (columnKind == MIXTURE) {
203         for (uint32_t index = 0; index < showCount; index++) {
204             auto row = FrameNode::CreateFrameNode(
205                 V2::ROW_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
206                 AceType::MakeRefPtr<LinearLayoutPattern>(false));
207             CHECK_NULL_RETURN(row, nullptr);
208 
209             auto imageNode = FrameNode::CreateFrameNode(
210                 V2::IMAGE_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
211                 AceType::MakeRefPtr<ImagePattern>());
212             CHECK_NULL_RETURN(imageNode, nullptr);
213             imageNode->MountToParent(row);
214 
215             auto textNode = FrameNode::CreateFrameNode(
216                 V2::TEXT_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
217                 AceType::MakeRefPtr<TextPattern>());
218             CHECK_NULL_RETURN(textNode, nullptr);
219             textNode->MountToParent(row);
220             row->MountToParent(columnNode);
221         }
222     }
223     return columnNode;
224 }
225 
CreateStackNode()226 RefPtr<FrameNode> TextPickerModelNG::CreateStackNode()
227 {
228     auto stackId = ElementRegister::GetInstance()->MakeUniqueId();
229     return FrameNode::GetOrCreateFrameNode(
230         V2::STACK_ETS_TAG, stackId, []() { return AceType::MakeRefPtr<StackPattern>(); });
231 }
232 
CreateColumnNode()233 RefPtr<FrameNode> TextPickerModelNG::CreateColumnNode()
234 {
235     auto columnId = ElementRegister::GetInstance()->MakeUniqueId();
236     return FrameNode::GetOrCreateFrameNode(
237         V2::COLUMN_ETS_TAG, columnId, []() { return AceType::MakeRefPtr<LinearLayoutPattern>(true); });
238 }
239 
CreateButtonNode()240 RefPtr<FrameNode> TextPickerModelNG::CreateButtonNode()
241 {
242     auto buttonId = ElementRegister::GetInstance()->MakeUniqueId();
243     return FrameNode::GetOrCreateFrameNode(
244         V2::BUTTON_ETS_TAG, buttonId, []() { return AceType::MakeRefPtr<ButtonPattern>(); });
245 }
246 
CreateFrameNode(int32_t nodeId)247 RefPtr<FrameNode> TextPickerModelNG::CreateFrameNode(int32_t nodeId)
248 {
249     auto textPickerNode = FrameNode::GetOrCreateFrameNode(
250         V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
251     auto pipeline = PipelineBase::GetCurrentContextSafely();
252     CHECK_NULL_RETURN(pipeline, textPickerNode);
253     auto pickerTheme = pipeline->GetTheme<PickerTheme>(textPickerNode->GetThemeScopeId());
254     CHECK_NULL_RETURN(pickerTheme, textPickerNode);
255     std::lock_guard<std::shared_mutex> lock(showCountMutex_);
256     showCount_ = BUFFER_NODE_NUMBER + pickerTheme->GetShowOptionCount();
257     SetDefaultAttributes(textPickerNode, pickerTheme);
258     return textPickerNode;
259 }
260 
SetSelected(uint32_t value)261 void TextPickerModelNG::SetSelected(uint32_t value)
262 {
263     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
264     CHECK_NULL_VOID(frameNode);
265     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
266     textPickerPattern->SetSelected(value);
267     std::vector<uint32_t> values;
268     values.emplace_back(value);
269     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selected, value);
270     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values);
271 }
272 
SetColumnWidths(const std::vector<Dimension> & widths)273 void TextPickerModelNG::SetColumnWidths(const std::vector<Dimension>& widths)
274 {
275     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
276     CHECK_NULL_VOID(frameNode);
277     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
278     textPickerPattern->SetColumnWidths(widths);
279 }
280 
SetColumnWidths(FrameNode * frameNode,const std::vector<Dimension> & widths)281 void TextPickerModelNG::SetColumnWidths(FrameNode* frameNode, const std::vector<Dimension>& widths)
282 {
283     CHECK_NULL_VOID(frameNode);
284     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
285     textPickerPattern->SetColumnWidths(widths);
286 }
287 
GetColumnWidths(FrameNode * frameNode)288 std::vector<Dimension> TextPickerModelNG::GetColumnWidths(FrameNode* frameNode)
289 {
290     std::vector<Dimension> columnWidths;
291     CHECK_NULL_RETURN(frameNode, columnWidths);
292     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
293     columnWidths = textPickerPattern->GetColumnWidths();
294     return columnWidths;
295 }
296 
SetRange(const std::vector<NG::RangeContent> & value)297 void TextPickerModelNG::SetRange(const std::vector<NG::RangeContent>& value)
298 {
299     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
300     CHECK_NULL_VOID(frameNode);
301     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
302     textPickerPattern->SetRange(value);
303 }
304 
SetDefaultPickerItemHeight(const Dimension & value)305 void TextPickerModelNG::SetDefaultPickerItemHeight(const Dimension& value)
306 {
307     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultPickerItemHeight, value);
308 }
309 
SetGradientHeight(const Dimension & value)310 void TextPickerModelNG::SetGradientHeight(const Dimension& value)
311 {
312     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
313     CHECK_NULL_VOID(frameNode);
314     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
315     CHECK_NULL_VOID(textPickerPattern);
316     textPickerPattern->SetGradientHeight(value);
317     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, value);
318 }
319 
SetCanLoop(const bool value)320 void TextPickerModelNG::SetCanLoop(const bool value)
321 {
322     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
323     CHECK_NULL_VOID(frameNode);
324     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
325     CHECK_NULL_VOID(textPickerPattern);
326     textPickerPattern->SetCanLoop(value);
327     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, value);
328 }
329 
SetBackgroundColor(const Color & color)330 void TextPickerModelNG::SetBackgroundColor(const Color& color)
331 {
332     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
333     CHECK_NULL_VOID(frameNode);
334     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
335     CHECK_NULL_VOID(textPickerPattern);
336     textPickerPattern->SetBackgroundColor(color);
337 }
338 
SetDisableTextStyleAnimation(const bool value)339 void TextPickerModelNG::SetDisableTextStyleAnimation(const bool value)
340 {
341     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
342     CHECK_NULL_VOID(frameNode);
343     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
344     CHECK_NULL_VOID(textPickerPattern);
345     textPickerPattern->SetDisableTextStyleAnimation(value);
346     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisableTextStyleAnimation, value);
347 }
348 
SetDisappearTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)349 void TextPickerModelNG::SetDisappearTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
350 {
351     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
352     CHECK_NULL_VOID(frameNode);
353     CHECK_NULL_VOID(pickerTheme);
354     if (SystemProperties::ConfigChangePerform()) {
355         ParseDisappearTextStyleResObj(value);
356     }
357 
358     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
359     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
360         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
361             ConvertFontScaleValue(value.fontSize.value()));
362     } else {
363         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearFontSize,
364             ConvertFontScaleValue(disappearStyle.GetFontSize()));
365     }
366     if (value.textColor.has_value()) {
367         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearColor, value.textColor.value());
368     } else {
369         ResetTextPickerTextStyleColor(frameNode, &TextPickerLayoutProperty::GetDisappearTextStyle);
370     }
371     ACE_UPDATE_LAYOUT_PROPERTY(
372         TextPickerLayoutProperty, DisappearWeight, value.fontWeight.value_or(disappearStyle.GetFontWeight()));
373     ACE_UPDATE_LAYOUT_PROPERTY(
374         TextPickerLayoutProperty, DisappearFontFamily, value.fontFamily.value_or(disappearStyle.GetFontFamilies()));
375     ACE_UPDATE_LAYOUT_PROPERTY(
376         TextPickerLayoutProperty, DisappearFontStyle, value.fontStyle.value_or(disappearStyle.GetFontStyle()));
377 
378     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
379         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMinFontSize,
380             ConvertFontScaleValue(value.minFontSize.value()));
381     } else {
382         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMinFontSize, Dimension());
383     }
384     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
385         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMaxFontSize,
386             ConvertFontScaleValue(value.maxFontSize.value()));
387     } else {
388         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMaxFontSize, Dimension());
389     }
390     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearTextOverflow,
391         value.textOverflow.value_or(TextOverflow::CLIP));
392     ACE_UPDATE_LAYOUT_PROPERTY(
393         TextPickerLayoutProperty, DisappearTextColorSetByUser, value.textColorSetByUser);
394 }
395 
SetNormalTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)396 void TextPickerModelNG::SetNormalTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
397 {
398     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
399     CHECK_NULL_VOID(frameNode);
400     CHECK_NULL_VOID(pickerTheme);
401     if (SystemProperties::ConfigChangePerform()) {
402         ParseNormalTextStyleResObj(value);
403     }
404 
405     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
406     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
407         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
408             ConvertFontScaleValue(value.fontSize.value()));
409     } else {
410         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
411             ConvertFontScaleValue(normalStyle.GetFontSize()));
412     }
413     if (value.textColor.has_value()) {
414         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Color, value.textColor.value());
415     } else {
416         ResetTextPickerTextStyleColor(frameNode, &TextPickerLayoutProperty::GetTextStyle);
417     }
418     ACE_UPDATE_LAYOUT_PROPERTY(
419         TextPickerLayoutProperty, Weight, value.fontWeight.value_or(normalStyle.GetFontWeight()));
420     ACE_UPDATE_LAYOUT_PROPERTY(
421         TextPickerLayoutProperty, FontFamily, value.fontFamily.value_or(normalStyle.GetFontFamilies()));
422     ACE_UPDATE_LAYOUT_PROPERTY(
423         TextPickerLayoutProperty, FontStyle, value.fontStyle.value_or(normalStyle.GetFontStyle()));
424 
425     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
426         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MinFontSize,
427             ConvertFontScaleValue(value.minFontSize.value()));
428     } else {
429         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MinFontSize, Dimension());
430     }
431     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
432         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MaxFontSize,
433             ConvertFontScaleValue(value.maxFontSize.value()));
434     } else {
435         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MaxFontSize, Dimension());
436     }
437     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, TextOverflow,
438         value.textOverflow.value_or(TextOverflow::CLIP));
439     ACE_UPDATE_LAYOUT_PROPERTY(
440         TextPickerLayoutProperty, NormalTextColorSetByUser, value.textColorSetByUser);
441 }
442 
SetSelectedTextStyle(const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)443 void TextPickerModelNG::SetSelectedTextStyle(const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
444 {
445     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
446     CHECK_NULL_VOID(frameNode);
447     CHECK_NULL_VOID(pickerTheme);
448     if (SystemProperties::ConfigChangePerform()) {
449         ParseSelectedTextStyleResObj(value);
450     }
451 
452     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
453     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
454         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
455             ConvertFontScaleValue(value.fontSize.value()));
456     } else {
457         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
458             ConvertFontScaleValue(selectedStyle.GetFontSize()));
459     }
460     if (value.textColor.has_value()) {
461         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedColor, value.textColor.value());
462     } else {
463         ResetTextPickerTextStyleColor(frameNode, &TextPickerLayoutProperty::GetSelectedTextStyle);
464     }
465     ACE_UPDATE_LAYOUT_PROPERTY(
466         TextPickerLayoutProperty, SelectedWeight, value.fontWeight.value_or(selectedStyle.GetFontWeight()));
467     ACE_UPDATE_LAYOUT_PROPERTY(
468         TextPickerLayoutProperty, SelectedFontFamily, value.fontFamily.value_or(selectedStyle.GetFontFamilies()));
469     ACE_UPDATE_LAYOUT_PROPERTY(
470         TextPickerLayoutProperty, SelectedFontStyle, value.fontStyle.value_or(selectedStyle.GetFontStyle()));
471 
472     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
473         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMinFontSize,
474             ConvertFontScaleValue(value.minFontSize.value()));
475     } else {
476         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMinFontSize, Dimension());
477     }
478     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
479         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMaxFontSize,
480             ConvertFontScaleValue(value.maxFontSize.value()));
481     } else {
482         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMaxFontSize, Dimension());
483     }
484     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedTextOverflow,
485         value.textOverflow.value_or(TextOverflow::CLIP));
486     ACE_UPDATE_LAYOUT_PROPERTY(
487         TextPickerLayoutProperty, SelectedTextColorSetByUser, value.textColorSetByUser);
488 }
489 
SetDefaultTextStyle(const RefPtr<TextTheme> & textTheme,const NG::PickerTextStyle & value)490 void TextPickerModelNG::SetDefaultTextStyle(const RefPtr<TextTheme>& textTheme, const NG::PickerTextStyle& value)
491 {
492     CHECK_NULL_VOID(textTheme);
493     if (SystemProperties::ConfigChangePerform()) {
494         ParseDefaultTextStyleResObj(value);
495     }
496     auto textStyle = textTheme->GetTextStyle();
497 
498     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
499         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontSize,
500             ConvertFontScaleValue(value.fontSize.value()));
501     } else {
502         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontSize,
503             ConvertFontScaleValue(textStyle.GetFontSize()));
504     }
505     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultColor,
506         value.textColor.value_or(textStyle.GetTextColor()));
507     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultWeight,
508         value.fontWeight.value_or(textStyle.GetFontWeight()));
509     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontFamily,
510         value.fontFamily.value_or(textStyle.GetFontFamilies()));
511     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontStyle,
512         value.fontStyle.value_or(textStyle.GetFontStyle()));
513     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
514         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMinFontSize,
515             ConvertFontScaleValue(value.minFontSize.value()));
516     } else {
517         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMinFontSize, Dimension());
518     }
519     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
520         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMaxFontSize,
521             ConvertFontScaleValue(value.maxFontSize.value()));
522     } else {
523         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMaxFontSize, Dimension());
524     }
525     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultTextOverflow,
526         value.textOverflow.value_or(textStyle.GetTextOverflow()));
527     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultTextColorSetByUser, value.textColorSetByUser);
528 }
529 
HasUserDefinedDisappearFontFamily(bool isUserDefined)530 void TextPickerModelNG::HasUserDefinedDisappearFontFamily(bool isUserDefined)
531 {
532     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
533     CHECK_NULL_VOID(frameNode);
534     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
535     CHECK_NULL_VOID(textPickerPattern);
536     textPickerPattern->HasUserDefinedDisappearFontFamily(isUserDefined);
537 }
538 
HasUserDefinedNormalFontFamily(bool isUserDefined)539 void TextPickerModelNG::HasUserDefinedNormalFontFamily(bool isUserDefined)
540 {
541     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
542     CHECK_NULL_VOID(frameNode);
543     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
544     CHECK_NULL_VOID(textPickerPattern);
545     textPickerPattern->HasUserDefinedNormalFontFamily(isUserDefined);
546 }
547 
HasUserDefinedSelectedFontFamily(bool isUserDefined)548 void TextPickerModelNG::HasUserDefinedSelectedFontFamily(bool isUserDefined)
549 {
550     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
551     CHECK_NULL_VOID(frameNode);
552     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
553     CHECK_NULL_VOID(textPickerPattern);
554     textPickerPattern->HasUserDefinedSelectedFontFamily(isUserDefined);
555 }
556 
SetOnCascadeChange(TextCascadeChangeEvent && onChange)557 void TextPickerModelNG::SetOnCascadeChange(TextCascadeChangeEvent&& onChange)
558 {
559     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
560     CHECK_NULL_VOID(frameNode);
561     auto eventHub = frameNode->GetOrCreateEventHub<TextPickerEventHub>();
562     CHECK_NULL_VOID(eventHub);
563     eventHub->SetOnChange(std::move(onChange));
564 }
565 
SetOnScrollStop(TextCascadeChangeEvent && onScrollStop)566 void TextPickerModelNG::SetOnScrollStop(TextCascadeChangeEvent&& onScrollStop)
567 {
568     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
569     CHECK_NULL_VOID(frameNode);
570     auto eventHub = frameNode->GetOrCreateEventHub<TextPickerEventHub>();
571     CHECK_NULL_VOID(eventHub);
572     eventHub->SetOnScrollStop(std::move(onScrollStop));
573 }
574 
SetOnEnterSelectedArea(TextCascadeChangeEvent && onEnterSelectedArea)575 void TextPickerModelNG::SetOnEnterSelectedArea(TextCascadeChangeEvent&& onEnterSelectedArea)
576 {
577     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
578     CHECK_NULL_VOID(frameNode);
579     auto eventHub = frameNode->GetOrCreateEventHub<TextPickerEventHub>();
580     CHECK_NULL_VOID(eventHub);
581     eventHub->SetOnEnterSelectedArea(std::move(onEnterSelectedArea));
582 }
583 
SetValue(const std::string & value)584 void TextPickerModelNG::SetValue(const std::string& value)
585 {
586     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Value, value);
587 }
588 
getDisappearTextStyle(FrameNode * frameNode)589 PickerTextStyle TextPickerModelNG::getDisappearTextStyle(FrameNode* frameNode)
590 {
591     PickerTextStyle pickerTextStyle;
592     CHECK_NULL_RETURN(frameNode, pickerTextStyle);
593     auto context = frameNode->GetContext();
594     CHECK_NULL_RETURN(context, pickerTextStyle);
595     auto theme = context->GetTheme<PickerTheme>();
596     CHECK_NULL_RETURN(theme, pickerTextStyle);
597     auto style = theme->GetDisappearOptionStyle();
598     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
599         TextPickerLayoutProperty, DisappearFontSize, pickerTextStyle.fontSize, frameNode, style.GetFontSize());
600     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
601         TextPickerLayoutProperty, DisappearColor, pickerTextStyle.textColor, frameNode, style.GetTextColor());
602     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
603         TextPickerLayoutProperty, DisappearWeight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
604     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, DisappearFontFamily,
605         pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
606     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, DisappearFontStyle,
607         pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
608     return pickerTextStyle;
609 }
610 
getNormalTextStyle(FrameNode * frameNode)611 PickerTextStyle TextPickerModelNG::getNormalTextStyle(FrameNode* frameNode)
612 {
613     PickerTextStyle pickerTextStyle;
614     CHECK_NULL_RETURN(frameNode, pickerTextStyle);
615     auto context = frameNode->GetContext();
616     CHECK_NULL_RETURN(context, pickerTextStyle);
617     auto theme = context->GetTheme<PickerTheme>();
618     CHECK_NULL_RETURN(theme, pickerTextStyle);
619     auto style = theme->GetOptionStyle(false, false);
620     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
621         TextPickerLayoutProperty, FontSize, pickerTextStyle.fontSize, frameNode, style.GetFontSize());
622     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
623         TextPickerLayoutProperty, Color, pickerTextStyle.textColor, frameNode, style.GetTextColor());
624     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
625         TextPickerLayoutProperty, Weight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
626     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, FontFamily,
627         pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
628     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, FontStyle,
629         pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
630     return pickerTextStyle;
631 }
632 
getSelectedTextStyle(FrameNode * frameNode)633 PickerTextStyle TextPickerModelNG::getSelectedTextStyle(FrameNode* frameNode)
634 {
635     PickerTextStyle pickerTextStyle;
636     CHECK_NULL_RETURN(frameNode, pickerTextStyle);
637     auto context = frameNode->GetContext();
638     CHECK_NULL_RETURN(context, pickerTextStyle);
639     auto theme = context->GetTheme<PickerTheme>();
640     CHECK_NULL_RETURN(theme, pickerTextStyle);
641     auto style = theme->GetOptionStyle(true, false);
642     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
643         TextPickerLayoutProperty, SelectedFontSize, pickerTextStyle.fontSize, frameNode, style.GetFontSize());
644     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
645         TextPickerLayoutProperty, SelectedColor, pickerTextStyle.textColor, frameNode, style.GetTextColor());
646     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
647         TextPickerLayoutProperty, SelectedWeight, pickerTextStyle.fontWeight, frameNode, style.GetFontWeight());
648     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedFontFamily,
649         pickerTextStyle.fontFamily, frameNode, style.GetFontFamilies());
650     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedFontStyle,
651         pickerTextStyle.fontStyle, frameNode, style.GetFontStyle());
652     return pickerTextStyle;
653 }
654 
getTextPickerSelectedIndex(FrameNode * frameNode)655 int32_t TextPickerModelNG::getTextPickerSelectedIndex(FrameNode* frameNode)
656 {
657     CHECK_NULL_RETURN(frameNode, 0);
658     return frameNode->GetLayoutProperty<TextPickerLayoutProperty>()->GetSelectedValue(0);
659 }
660 
MultiInit(const RefPtr<PickerTheme> pickerTheme)661 void TextPickerModelNG::MultiInit(const RefPtr<PickerTheme> pickerTheme)
662 {
663     auto* stack = ViewStackProcessor::GetInstance();
664     auto nodeId = stack->ClaimNodeId();
665     auto textPickerNode = FrameNode::GetOrCreateFrameNode(
666         V2::TEXT_PICKER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<TextPickerPattern>(); });
667     auto textPickerPattern = textPickerNode->GetPattern<TextPickerPattern>();
668 
669     CHECK_NULL_VOID(pickerTheme);
670     std::lock_guard<std::shared_mutex> lock(showCountMutex_);
671     showCount_ = pickerTheme->GetShowOptionCount() + BUFFER_NODE_NUMBER;
672     stack->Push(textPickerNode);
673 
674     if (pickerTheme->IsCircleDial()) {
675         auto renderContext = textPickerNode->GetRenderContext();
676         renderContext->UpdateBackgroundColor(pickerTheme->GetBackgroundColor());
677     }
678 }
679 
SetIsCascade(bool isCascade)680 void TextPickerModelNG::SetIsCascade(bool isCascade)
681 {
682     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
683     CHECK_NULL_VOID(frameNode);
684     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
685     CHECK_NULL_VOID(textPickerPattern);
686     textPickerPattern->SetIsCascade(isCascade);
687 }
688 
SetHasSelectAttr(bool value)689 void TextPickerModelNG::SetHasSelectAttr(bool value)
690 {
691     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
692     CHECK_NULL_VOID(frameNode);
693     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
694     CHECK_NULL_VOID(textPickerPattern);
695     textPickerPattern->SetHasSelectAttr(value);
696 }
697 
SetUnCascadeColumns(const std::vector<NG::TextCascadePickerOptions> & options)698 void TextPickerModelNG::SetUnCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options)
699 {
700     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
701     CHECK_NULL_VOID(frameNode);
702     if (frameNode->GetChildren().empty()) {
703         std::lock_guard<std::shared_mutex> lock(showCountMutex_);
704         for (uint32_t i = 0; i < options.size(); i++) {
705             auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
706             auto stackNode = CreateStackNode();
707             auto buttonNode = CreateButtonNode();
708             auto columnBlendNode = CreateColumnNode();
709             buttonNode->MountToParent(stackNode);
710             columnNode->MountToParent(columnBlendNode);
711             columnBlendNode->MountToParent(stackNode);
712             columnNode->MarkModifyDone();
713             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
714             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
715             layoutProperty->UpdateAlignment(Alignment::CENTER);
716             stackNode->MountToParent(AceType::Claim(frameNode));
717         }
718     }
719 
720     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
721     CHECK_NULL_VOID(textPickerPattern);
722     textPickerPattern->SetCascadeOptions(options, options);
723 }
724 
SetCascadeColumns(const std::vector<NG::TextCascadePickerOptions> & options)725 void TextPickerModelNG::SetCascadeColumns(const std::vector<NG::TextCascadePickerOptions>& options)
726 {
727     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
728     CHECK_NULL_VOID(frameNode);
729     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
730     CHECK_NULL_VOID(textPickerPattern);
731     std::vector<NG::TextCascadePickerOptions> reOptions;
732     // Caculate max depth
733     size_t columnCount = options.empty()? 0 : 1;
734     for (size_t i = 0; i < options.size(); i++) {
735         size_t tmp  = textPickerPattern->ProcessCascadeOptionDepth(options[i]);
736         if (tmp > columnCount) {
737             columnCount = tmp;
738         }
739     }
740 
741     // Create Node
742     if (frameNode->GetChildren().empty()) {
743         std::lock_guard<std::shared_mutex> lock(showCountMutex_);
744         for (size_t i = 0; i < columnCount; i++) {
745             auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
746             auto stackNode = CreateStackNode();
747             auto buttonNode = CreateButtonNode();
748             auto columnBlendNode = CreateColumnNode();
749             buttonNode->MountToParent(stackNode);
750             columnNode->MountToParent(columnBlendNode);
751             columnBlendNode->MountToParent(stackNode);
752             columnNode->MarkModifyDone();
753             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
754             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
755             layoutProperty->UpdateAlignment(Alignment::CENTER);
756             stackNode->MountToParent(AceType::Claim<NG::FrameNode>(frameNode));
757         }
758     }
759 
760     textPickerPattern->ProcessCascadeOptions(options, reOptions, 0);
761     if (reOptions.size() < columnCount) {
762         auto differ = columnCount - reOptions.size();
763         for (uint32_t i = 0; i < differ; i++) {
764             NG::TextCascadePickerOptions differOption;
765             memset_s(&differOption, sizeof(differOption), 0, sizeof(differOption));
766             reOptions.emplace_back(differOption);
767         }
768     }
769     textPickerPattern->SetCascadeOptions(options, reOptions);
770 }
771 
SetColumns(const std::vector<NG::TextCascadePickerOptions> & options)772 void TextPickerModelNG::SetColumns(const std::vector<NG::TextCascadePickerOptions>& options)
773 {
774     if (!IsCascade()) {
775         SetUnCascadeColumns(options);
776     } else {
777         SetCascadeColumns(options);
778     }
779 }
780 
IsSingle()781 bool TextPickerModelNG::IsSingle()
782 {
783     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
784     CHECK_NULL_RETURN(frameNode, false);
785     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
786     CHECK_NULL_RETURN(textPickerPattern, false);
787     return textPickerPattern->GetRange().size() > 0;
788 }
789 
IsSingle(FrameNode * frameNode)790 bool TextPickerModelNG::IsSingle(FrameNode* frameNode)
791 {
792     CHECK_NULL_RETURN(frameNode, false);
793     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
794     CHECK_NULL_RETURN(textPickerPattern, false);
795     return textPickerPattern->GetRange().size() > 0;
796 }
797 
GetSingleRange(std::vector<NG::RangeContent> & rangeValue)798 bool TextPickerModelNG::GetSingleRange(std::vector<NG::RangeContent>& rangeValue)
799 {
800     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
801     CHECK_NULL_RETURN(frameNode, false);
802     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
803     CHECK_NULL_RETURN(textPickerPattern, false);
804     rangeValue = textPickerPattern->GetRange();
805     return true;
806 }
807 
GetSingleRange(FrameNode * frameNode,std::vector<NG::RangeContent> & rangeValue)808 bool TextPickerModelNG::GetSingleRange(FrameNode* frameNode, std::vector<NG::RangeContent>& rangeValue)
809 {
810     rangeValue.clear();
811     CHECK_NULL_RETURN(frameNode, false);
812     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
813     CHECK_NULL_RETURN(textPickerPattern, false);
814     for (auto& item : textPickerPattern->GetRange()) {
815         rangeValue.emplace_back(std::move(item));
816     }
817     return true;
818 }
819 
IsCascade(FrameNode * frameNode)820 bool TextPickerModelNG::IsCascade(FrameNode* frameNode)
821 {
822     CHECK_NULL_RETURN(frameNode, false);
823     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
824     CHECK_NULL_RETURN(textPickerPattern, false);
825     return textPickerPattern->GetIsCascade();
826 }
827 
GetMultiOptions(std::vector<NG::TextCascadePickerOptions> & options)828 bool TextPickerModelNG::GetMultiOptions(std::vector<NG::TextCascadePickerOptions>& options)
829 {
830     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
831     CHECK_NULL_RETURN(frameNode, false);
832     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
833     CHECK_NULL_RETURN(textPickerPattern, false);
834     options = textPickerPattern->GetMultiOptions();
835     return true;
836 }
837 
GetMultiOptions(FrameNode * frameNode,std::vector<NG::TextCascadePickerOptions> & options)838 bool TextPickerModelNG::GetMultiOptions(FrameNode* frameNode, std::vector<NG::TextCascadePickerOptions>& options)
839 {
840     options.clear();
841     CHECK_NULL_RETURN(frameNode, false);
842     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
843     CHECK_NULL_RETURN(textPickerPattern, false);
844     for (auto& item : textPickerPattern->GetMultiOptions()) {
845         options.emplace_back(std::move(item));
846     }
847     return true;
848 }
849 
GetMaxCount(FrameNode * frameNode)850 uint32_t TextPickerModelNG::GetMaxCount(FrameNode* frameNode)
851 {
852     return 1;
853 }
854 
SetValues(const std::vector<std::string> & values)855 void TextPickerModelNG::SetValues(const std::vector<std::string>& values)
856 {
857     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
858     CHECK_NULL_VOID(frameNode);
859     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
860     CHECK_NULL_VOID(textPickerPattern);
861     textPickerPattern->SetValues(values);
862     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Values, values);
863 }
864 
SetSelecteds(const std::vector<uint32_t> & values)865 void TextPickerModelNG::SetSelecteds(const std::vector<uint32_t>& values)
866 {
867     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
868     CHECK_NULL_VOID(frameNode);
869     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
870     CHECK_NULL_VOID(textPickerPattern);
871     textPickerPattern->SetSelecteds(values);
872     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selecteds, values);
873     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values);
874 }
875 
SetOnValueChangeEvent(TextCascadeValueChangeEvent && onValueChangeEvent)876 void TextPickerModelNG::SetOnValueChangeEvent(TextCascadeValueChangeEvent&& onValueChangeEvent)
877 {
878     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
879     CHECK_NULL_VOID(frameNode);
880     auto eventHub = frameNode->GetOrCreateEventHub<TextPickerEventHub>();
881     CHECK_NULL_VOID(eventHub);
882     eventHub->SetOnValueChangeEvent(std::move(onValueChangeEvent));
883 }
884 
SetOnSelectedChangeEvent(TextCascadeSelectedChangeEvent && onSelectedChangeEvent)885 void TextPickerModelNG::SetOnSelectedChangeEvent(TextCascadeSelectedChangeEvent&& onSelectedChangeEvent)
886 {
887     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
888     CHECK_NULL_VOID(frameNode);
889     auto eventHub = frameNode->GetOrCreateEventHub<TextPickerEventHub>();
890     CHECK_NULL_VOID(eventHub);
891     eventHub->SetOnSelectedChangeEvent(std::move(onSelectedChangeEvent));
892 }
893 
CreateObject()894 RefPtr<AceType> TextPickerDialogModelNG::CreateObject()
895 {
896     return nullptr;
897 }
898 
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,std::function<void (const std::string &)> && onEnterSelectedArea,TextPickerDialog & textPickerDialog,TextPickerDialogEvent & textPickerDialogEvent,const std::vector<ButtonInfo> & buttonInfos)899 void TextPickerDialogModelNG::SetTextPickerDialogShow(RefPtr<AceType>& PickerText,
900     NG::TextPickerSettingData& settingData, std::function<void()>&& onCancel,
901     std::function<void(const std::string&)>&& onAccept, std::function<void(const std::string&)>&& onChange,
902     std::function<void(const std::string&)>&& onScrollStop,
903     std::function<void(const std::string&)>&& onEnterSelectedArea, TextPickerDialog& textPickerDialog,
904     TextPickerDialogEvent& textPickerDialogEvent, const std::vector<ButtonInfo>& buttonInfos)
905 {
906     auto container = Container::Current();
907     if (!container) {
908         return;
909     }
910     auto pipelineContext = AccessibilityManager::DynamicCast<NG::PipelineContext>(container->GetPipelineContext());
911     if (!pipelineContext) {
912         return;
913     }
914     auto executor = pipelineContext->GetTaskExecutor();
915     if (!executor) {
916         return;
917     }
918     auto pipeline = PipelineBase::GetCurrentContext();
919     CHECK_NULL_VOID(pipeline);
920     auto theme = pipeline->GetTheme<DialogTheme>();
921     CHECK_NULL_VOID(theme);
922 
923     std::map<std::string, NG::DialogTextEvent> dialogEvent;
924     std::map<std::string, NG::DialogCancelEvent> dialogLifeCycleEvent;
925     std::map<std::string, NG::DialogGestureEvent> dialogCancelEvent;
926     dialogEvent["acceptId"] = onAccept;
927     dialogEvent["changeId"] = onChange;
928     dialogEvent["scrollStopId"] = onScrollStop;
929     dialogEvent["enterSelectedAreaId"] = onEnterSelectedArea;
930     auto func = [onCancel](const GestureEvent& /* info */) {
931         if (onCancel) {
932             onCancel();
933         }
934     };
935     dialogCancelEvent["cancelId"] = func;
936     dialogLifeCycleEvent["didAppearId"] = textPickerDialogEvent.onDidAppear;
937     dialogLifeCycleEvent["didDisappearId"] = textPickerDialogEvent.onDidDisappear;
938     dialogLifeCycleEvent["willAppearId"] = textPickerDialogEvent.onWillAppear;
939     dialogLifeCycleEvent["willDisappearId"] = textPickerDialogEvent.onWillDisappear;
940     DialogProperties properties;
941     SetDialogProperties(properties, textPickerDialog, theme);
942 
943     auto context = AccessibilityManager::DynamicCast<NG::PipelineContext>(pipelineContext);
944     auto overlayManager = context ? context->GetOverlayManager() : nullptr;
945     executor->PostTask(
946         [properties, settingData, dialogEvent, dialogCancelEvent, dialogLifeCycleEvent, buttonInfos,
947             weak = WeakPtr<NG::OverlayManager>(overlayManager)] {
948             auto overlayManager = weak.Upgrade();
949             CHECK_NULL_VOID(overlayManager);
950             overlayManager->ShowTextDialog(
951                 properties, settingData, dialogEvent, dialogCancelEvent, dialogLifeCycleEvent, buttonInfos);
952         },
953         TaskExecutor::TaskType::UI, "ArkUITextPickerShowTextDialog",
954         TaskExecutor::GetPriorityTypeWithCheck(PriorityType::VIP));
955 }
956 
SetCanLoop(FrameNode * frameNode,const bool value)957 void TextPickerModelNG::SetCanLoop(FrameNode* frameNode, const bool value)
958 {
959     CHECK_NULL_VOID(frameNode);
960     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
961     CHECK_NULL_VOID(textPickerPattern);
962     textPickerPattern->SetCanLoop(value);
963     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, value, frameNode);
964 }
965 
GetCanLoop(FrameNode * frameNode)966 int32_t TextPickerModelNG::GetCanLoop(FrameNode* frameNode)
967 {
968     CHECK_NULL_RETURN(frameNode, 1);
969     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
970     CHECK_NULL_RETURN(textPickerPattern, 1);
971     return textPickerPattern->GetCanLoop();
972 }
973 
SetDigitalCrownSensitivity(int32_t crownSensitivity)974 void TextPickerModelNG::SetDigitalCrownSensitivity(int32_t crownSensitivity)
975 {
976     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
977     CHECK_NULL_VOID(frameNode);
978     SetDigitalCrownSensitivity(frameNode, crownSensitivity);
979 }
980 
SetDigitalCrownSensitivity(FrameNode * frameNode,int32_t crownSensitivity)981 void TextPickerModelNG::SetDigitalCrownSensitivity(FrameNode* frameNode, int32_t crownSensitivity)
982 {
983     if (crownSensitivity < CROWN_SENSITIVITY_MIN || crownSensitivity > CROWN_SENSITIVITY_MAX) {
984         return;
985     }
986     CHECK_NULL_VOID(frameNode);
987     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
988     CHECK_NULL_VOID(textPickerPattern);
989     textPickerPattern->SetDigitalCrownSensitivity(crownSensitivity);
990     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DigitalCrownSensitivity, crownSensitivity, frameNode);
991 }
992 
SetSelecteds(FrameNode * frameNode,const std::vector<uint32_t> & values)993 void TextPickerModelNG::SetSelecteds(FrameNode* frameNode, const std::vector<uint32_t>& values)
994 {
995     CHECK_NULL_VOID(frameNode);
996     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
997     CHECK_NULL_VOID(textPickerPattern);
998     textPickerPattern->SetSelecteds(values);
999     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selecteds, values, frameNode);
1000     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values, frameNode);
1001 }
SetSelected(FrameNode * frameNode,uint32_t value)1002 void TextPickerModelNG::SetSelected(FrameNode* frameNode, uint32_t value)
1003 {
1004     CHECK_NULL_VOID(frameNode);
1005     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1006     textPickerPattern->SetSelected(value);
1007     std::vector<uint32_t> values;
1008     values.emplace_back(value);
1009     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selected, value, frameNode);
1010     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values, frameNode);
1011 }
SetHasSelectAttr(FrameNode * frameNode,bool value)1012 void TextPickerModelNG::SetHasSelectAttr(FrameNode* frameNode, bool value)
1013 {
1014     CHECK_NULL_VOID(frameNode);
1015     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1016     CHECK_NULL_VOID(textPickerPattern);
1017     textPickerPattern->SetHasSelectAttr(value);
1018 }
1019 
SetIsCascade(FrameNode * frameNode,bool isCascade)1020 void TextPickerModelNG::SetIsCascade(FrameNode* frameNode, bool isCascade)
1021 {
1022     CHECK_NULL_VOID(frameNode);
1023     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1024     CHECK_NULL_VOID(textPickerPattern);
1025     textPickerPattern->SetIsCascade(isCascade);
1026 }
1027 
SetColumnKind(FrameNode * frameNode,uint32_t columnKind)1028 void TextPickerModelNG::SetColumnKind(FrameNode* frameNode, uint32_t columnKind)
1029 {
1030     CHECK_NULL_VOID(frameNode);
1031     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1032     CHECK_NULL_VOID(textPickerPattern);
1033     columnKind_ = columnKind;
1034     textPickerPattern->SetColumnsKind(columnKind);
1035 }
1036 
SetNormalTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)1037 void TextPickerModelNG::SetNormalTextStyle(
1038     FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
1039 {
1040     CHECK_NULL_VOID(frameNode);
1041     CHECK_NULL_VOID(pickerTheme);
1042     if (SystemProperties::ConfigChangePerform()) {
1043         ParseNormalTextStyleResObj(value);
1044     }
1045 
1046     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
1047     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
1048         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
1049             ConvertFontScaleValue(value.fontSize.value()), frameNode);
1050     } else {
1051         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
1052             ConvertFontScaleValue(normalStyle.GetFontSize()), frameNode);
1053     }
1054     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1055         TextPickerLayoutProperty, Color, value.textColor.value_or(normalStyle.GetTextColor()), frameNode);
1056     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1057         TextPickerLayoutProperty, Weight, value.fontWeight.value_or(normalStyle.GetFontWeight()), frameNode);
1058     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1059         TextPickerLayoutProperty, FontFamily, value.fontFamily.value_or(normalStyle.GetFontFamilies()), frameNode);
1060     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1061         TextPickerLayoutProperty, FontStyle, value.fontStyle.value_or(normalStyle.GetFontStyle()), frameNode);
1062 
1063     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
1064         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MinFontSize,
1065             ConvertFontScaleValue(value.minFontSize.value()), frameNode);
1066     } else {
1067         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MinFontSize, Dimension(), frameNode);
1068     }
1069     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
1070         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MaxFontSize,
1071             ConvertFontScaleValue(value.maxFontSize.value()), frameNode);
1072     } else {
1073         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, MaxFontSize, Dimension(), frameNode);
1074     }
1075     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, TextOverflow,
1076         value.textOverflow.value_or(TextOverflow::CLIP), frameNode);
1077     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1078         TextPickerLayoutProperty, NormalTextColorSetByUser, value.textColorSetByUser, frameNode);
1079 }
1080 
SetSelectedTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)1081 void TextPickerModelNG::SetSelectedTextStyle(
1082     FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
1083 {
1084     CHECK_NULL_VOID(frameNode);
1085     CHECK_NULL_VOID(pickerTheme);
1086     if (SystemProperties::ConfigChangePerform()) {
1087         ParseSelectedTextStyleResObj(value);
1088     }
1089 
1090     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
1091     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
1092         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1093             TextPickerLayoutProperty, SelectedFontSize,
1094             ConvertFontScaleValue(value.fontSize.value()), frameNode);
1095     } else {
1096         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1097             TextPickerLayoutProperty, SelectedFontSize,
1098             ConvertFontScaleValue(selectedStyle.GetFontSize()), frameNode);
1099     }
1100     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1101         TextPickerLayoutProperty, SelectedColor,
1102         value.textColor.value_or(selectedStyle.GetTextColor()), frameNode);
1103 
1104     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1105         TextPickerLayoutProperty, SelectedWeight,
1106         value.fontWeight.value_or(selectedStyle.GetFontWeight()), frameNode);
1107     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1108         TextPickerLayoutProperty, SelectedFontFamily,
1109         value.fontFamily.value_or(selectedStyle.GetFontFamilies()), frameNode);
1110     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1111         TextPickerLayoutProperty, SelectedFontStyle, value.fontStyle.value_or(selectedStyle.GetFontStyle()), frameNode);
1112 
1113     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
1114         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMinFontSize,
1115             ConvertFontScaleValue(value.minFontSize.value()), frameNode);
1116     } else {
1117         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMinFontSize, Dimension(), frameNode);
1118     }
1119     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
1120         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMaxFontSize,
1121             ConvertFontScaleValue(value.maxFontSize.value()), frameNode);
1122     } else {
1123         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedMaxFontSize, Dimension(), frameNode);
1124     }
1125     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedTextOverflow,
1126         value.textOverflow.value_or(TextOverflow::CLIP), frameNode);
1127     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1128         TextPickerLayoutProperty, SelectedTextColorSetByUser, value.textColorSetByUser, frameNode);
1129 }
1130 
SetDisappearTextStyle(FrameNode * frameNode,const RefPtr<PickerTheme> & pickerTheme,const NG::PickerTextStyle & value)1131 void TextPickerModelNG::SetDisappearTextStyle(
1132     FrameNode* frameNode, const RefPtr<PickerTheme>& pickerTheme, const NG::PickerTextStyle& value)
1133 {
1134     CHECK_NULL_VOID(frameNode);
1135     CHECK_NULL_VOID(pickerTheme);
1136     if (SystemProperties::ConfigChangePerform()) {
1137         ParseDisappearTextStyleResObj(value);
1138     }
1139     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
1140     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
1141         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1142             TextPickerLayoutProperty, DisappearFontSize,
1143             ConvertFontScaleValue(value.fontSize.value()), frameNode);
1144     } else {
1145         ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1146             TextPickerLayoutProperty, DisappearFontSize,
1147             ConvertFontScaleValue(disappearStyle.GetFontSize()), frameNode);
1148     }
1149     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1150         TextPickerLayoutProperty, DisappearColor, value.textColor.value_or(disappearStyle.GetTextColor()), frameNode);
1151     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1152         TextPickerLayoutProperty, DisappearWeight,
1153         value.fontWeight.value_or(disappearStyle.GetFontWeight()), frameNode);
1154     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1155         TextPickerLayoutProperty, DisappearFontFamily,
1156         value.fontFamily.value_or(disappearStyle.GetFontFamilies()), frameNode);
1157     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1158         TextPickerLayoutProperty, DisappearFontStyle,
1159         value.fontStyle.value_or(disappearStyle.GetFontStyle()), frameNode);
1160 
1161     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
1162         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMinFontSize,
1163             ConvertFontScaleValue(value.minFontSize.value()), frameNode);
1164     } else {
1165         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMinFontSize, Dimension(), frameNode);
1166     }
1167     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
1168         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMaxFontSize,
1169             ConvertFontScaleValue(value.maxFontSize.value()), frameNode);
1170     } else {
1171         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearMaxFontSize, Dimension(), frameNode);
1172     }
1173     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisappearTextOverflow,
1174         value.textOverflow.value_or(TextOverflow::CLIP), frameNode);
1175     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1176         TextPickerLayoutProperty, DisappearTextColorSetByUser, value.textColorSetByUser, frameNode);
1177 }
1178 
SetDefaultPickerItemHeight(FrameNode * frameNode,const Dimension & value)1179 void TextPickerModelNG::SetDefaultPickerItemHeight(FrameNode* frameNode, const Dimension& value)
1180 {
1181     CHECK_NULL_VOID(frameNode);
1182     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultPickerItemHeight, value, frameNode);
1183 }
1184 
GetDefaultPickerItemHeight(FrameNode * frameNode)1185 Dimension TextPickerModelNG::GetDefaultPickerItemHeight(FrameNode* frameNode)
1186 {
1187     Dimension value = Dimension(0.0f);
1188     CHECK_NULL_RETURN(frameNode, value);
1189     auto layoutProperty = frameNode->GetLayoutProperty<TextPickerLayoutProperty>();
1190     CHECK_NULL_RETURN(layoutProperty, value);
1191     return layoutProperty->HasDefaultPickerItemHeight() ? layoutProperty->GetDefaultPickerItemHeightValue() : value;
1192 }
1193 
SetBackgroundColor(FrameNode * frameNode,const Color & color)1194 void TextPickerModelNG::SetBackgroundColor(FrameNode* frameNode, const Color& color)
1195 {
1196     CHECK_NULL_VOID(frameNode);
1197     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1198     CHECK_NULL_VOID(textPickerPattern);
1199     textPickerPattern->SetBackgroundColor(color);
1200 }
1201 
SetRange(FrameNode * frameNode,const std::vector<NG::RangeContent> & value)1202 void TextPickerModelNG::SetRange(FrameNode* frameNode, const std::vector<NG::RangeContent>& value)
1203 {
1204     CHECK_NULL_VOID(frameNode);
1205     if (frameNode->GetChildren().empty()) {
1206         std::lock_guard<std::shared_mutex> lock(showCountMutex_);
1207         RefPtr<FrameNode> columnNode = nullptr;
1208         if (columnKind_ == TEXT) {
1209             columnNode = CreateColumnNode(TEXT, showCount_);
1210         } else if (columnKind_ == MIXTURE) {
1211             columnNode = CreateColumnNode(MIXTURE, showCount_);
1212         }
1213         auto stackNode = CreateStackNode();
1214         auto buttonNode = CreateButtonNode();
1215         auto columnBlendNode = CreateColumnNode();
1216         buttonNode->MountToParent(stackNode);
1217         columnNode->MountToParent(columnBlendNode);
1218         columnBlendNode->MountToParent(stackNode);
1219         columnNode->MarkModifyDone();
1220         columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1221         auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
1222         layoutProperty->UpdateAlignment(Alignment::CENTER);
1223         stackNode->MountToParent(AceType::Claim(frameNode));
1224     }
1225     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1226     textPickerPattern->SetRange(value);
1227 }
1228 
SetColumns(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)1229 void TextPickerModelNG::SetColumns(FrameNode* frameNode, const std::vector<NG::TextCascadePickerOptions>& options)
1230 {
1231     if (!IsCascade(frameNode)) {
1232         SetUnCascadeColumnsNode(frameNode, options);
1233     } else {
1234         SetCascadeColumnsNode(frameNode, options);
1235     }
1236 }
1237 
SetUnCascadeColumnsNode(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)1238 void TextPickerModelNG::SetUnCascadeColumnsNode(FrameNode* frameNode,
1239     const std::vector<NG::TextCascadePickerOptions>& options)
1240 {
1241     CHECK_NULL_VOID(frameNode);
1242     if (frameNode->GetChildren().empty()) {
1243         std::lock_guard<std::shared_mutex> lock(showCountMutex_);
1244         for (uint32_t i = 0; i < options.size(); i++) {
1245             auto columnNode = CreateColumnNode(TEXT, showCount_);
1246             auto stackNode = CreateStackNode();
1247             auto buttonNode = CreateButtonNode();
1248             auto columnBlendNode = CreateColumnNode();
1249             buttonNode->MountToParent(stackNode);
1250             columnNode->MountToParent(columnBlendNode);
1251             columnBlendNode->MountToParent(stackNode);
1252             columnNode->MarkModifyDone();
1253             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1254             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
1255             layoutProperty->UpdateAlignment(Alignment::CENTER);
1256             stackNode->MountToParent(AceType::Claim(frameNode));
1257         }
1258     }
1259 
1260     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1261     CHECK_NULL_VOID(textPickerPattern);
1262     textPickerPattern->SetCascadeOptions(options, options);
1263 }
1264 
SetCascadeColumnsNode(FrameNode * frameNode,const std::vector<NG::TextCascadePickerOptions> & options)1265 void TextPickerModelNG::SetCascadeColumnsNode(FrameNode* frameNode,
1266     const std::vector<NG::TextCascadePickerOptions>& options)
1267 {
1268     CHECK_NULL_VOID(frameNode);
1269     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1270     CHECK_NULL_VOID(textPickerPattern);
1271     std::vector<NG::TextCascadePickerOptions> reOptions;
1272     // Caculate max depth
1273     size_t columnCount = options.empty()? 0 : 1;
1274     for (size_t i = 0; i < options.size(); i++) {
1275         size_t tmp  = textPickerPattern->ProcessCascadeOptionDepth(options[i]);
1276         if (tmp > columnCount) {
1277             columnCount = tmp;
1278         }
1279     }
1280 
1281     // Create Node
1282     if (frameNode->GetChildren().empty()) {
1283         std::lock_guard<std::shared_mutex> lock(showCountMutex_);
1284         for (size_t i = 0; i < columnCount; i++) {
1285             auto columnNode = CreateColumnNode(NG::TEXT, showCount_);
1286             auto stackNode = CreateStackNode();
1287             auto buttonNode = CreateButtonNode();
1288             auto columnBlendNode = CreateColumnNode();
1289             buttonNode->MountToParent(stackNode);
1290             columnNode->MountToParent(columnBlendNode);
1291             columnBlendNode->MountToParent(stackNode);
1292             columnNode->MarkModifyDone();
1293             columnNode->MarkDirtyNode(PROPERTY_UPDATE_MEASURE);
1294             auto layoutProperty = stackNode->GetLayoutProperty<LayoutProperty>();
1295             layoutProperty->UpdateAlignment(Alignment::CENTER);
1296             stackNode->MountToParent(AceType::Claim(frameNode));
1297         }
1298     }
1299 
1300     textPickerPattern->ProcessCascadeOptions(options, reOptions, 0);
1301     if (reOptions.size() < columnCount) {
1302         auto differ = columnCount - reOptions.size();
1303         for (uint32_t i = 0; i < differ; i++) {
1304             NG::TextCascadePickerOptions differOption;
1305             memset_s(&differOption, sizeof(differOption), 0, sizeof(differOption));
1306             reOptions.emplace_back(differOption);
1307         }
1308     }
1309     textPickerPattern->SetCascadeOptions(options, reOptions);
1310 }
1311 
SetValue(FrameNode * frameNode,const std::string & value)1312 void TextPickerModelNG::SetValue(FrameNode* frameNode, const std::string& value)
1313 {
1314     CHECK_NULL_VOID(frameNode);
1315     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Value, value, frameNode);
1316     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1317     CHECK_NULL_VOID(textPickerPattern);
1318     auto rangeValue = textPickerPattern->GetRange();
1319     auto valueIterator = std::find_if(rangeValue.begin(), rangeValue.end(),
1320         [&value](const NG::RangeContent& range) { return range.text_ == value; });
1321     if (valueIterator != rangeValue.end()) {
1322         TextPickerModelNG::SetSelected(frameNode, std::distance(rangeValue.begin(), valueIterator));
1323     }
1324 }
1325 
SetValues(FrameNode * frameNode,const std::vector<std::string> & values)1326 void TextPickerModelNG::SetValues(FrameNode* frameNode, const std::vector<std::string>& values)
1327 {
1328     CHECK_NULL_VOID(frameNode);
1329     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1330     CHECK_NULL_VOID(textPickerPattern);
1331     std::vector<std::string> selectedValues;
1332     std::vector<uint32_t> valuesIndex;
1333     auto options = textPickerPattern->GetMultiOptions();
1334     for (uint32_t i = 0; i < options.size(); i++) {
1335         if (values.size() > 0 && values.size() < i + 1) {
1336             if (options[i].rangeResult.size() > 0) {
1337                 selectedValues.emplace_back(options[i].rangeResult[0]);
1338             } else {
1339                 selectedValues.emplace_back("");
1340             }
1341             valuesIndex.emplace_back(0);
1342         } else {
1343             auto valueIterator = std::find(options[i].rangeResult.begin(), options[i].rangeResult.end(), values[i]);
1344             if (valueIterator == options[i].rangeResult.end()) {
1345                 selectedValues[i] = options[i].rangeResult.front();
1346                 valuesIndex.emplace_back(0);
1347             } else {
1348                 selectedValues.emplace_back(values[i]);
1349                 valuesIndex.emplace_back(std::distance(options[i].rangeResult.begin(), valueIterator));
1350             }
1351         }
1352     }
1353     TextPickerModelNG::SetSelecteds(frameNode, valuesIndex);
1354     textPickerPattern->SetValues(selectedValues);
1355     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Values, selectedValues, frameNode);
1356 }
1357 
SetDefaultAttributes(RefPtr<FrameNode> & frameNode,const RefPtr<PickerTheme> & pickerTheme)1358 void TextPickerModelNG::SetDefaultAttributes(RefPtr<FrameNode>& frameNode, const RefPtr<PickerTheme>& pickerTheme)
1359 {
1360     auto selectedStyle = pickerTheme->GetOptionStyle(true, false);
1361     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedFontSize,
1362         ConvertFontScaleValue(selectedStyle.GetFontSize()), frameNode);
1363     ResetTextPickerTextStyleColor(Referenced::RawPtr(frameNode), &TextPickerLayoutProperty::GetSelectedTextStyle);
1364     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedWeight, selectedStyle.GetFontWeight(), frameNode);
1365     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1366         TextPickerLayoutProperty, SelectedFontFamily, selectedStyle.GetFontFamilies(), frameNode);
1367     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1368         TextPickerLayoutProperty, SelectedFontStyle, selectedStyle.GetFontStyle(), frameNode);
1369 
1370     auto disappearStyle = pickerTheme->GetDisappearOptionStyle();
1371     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1372         TextPickerLayoutProperty, DisappearFontSize,
1373         ConvertFontScaleValue(disappearStyle.GetFontSize()), frameNode);
1374     ResetTextPickerTextStyleColor(Referenced::RawPtr(frameNode), &TextPickerLayoutProperty::GetDisappearTextStyle);
1375     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1376         TextPickerLayoutProperty, DisappearWeight, disappearStyle.GetFontWeight(), frameNode);
1377     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1378         TextPickerLayoutProperty, DisappearFontFamily, disappearStyle.GetFontFamilies(), frameNode);
1379     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1380         TextPickerLayoutProperty, DisappearFontStyle, disappearStyle.GetFontStyle(), frameNode);
1381 
1382     auto normalStyle = pickerTheme->GetOptionStyle(false, false);
1383     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontSize,
1384         ConvertFontScaleValue(normalStyle.GetFontSize()), frameNode);
1385     ResetTextPickerTextStyleColor(Referenced::RawPtr(frameNode), &TextPickerLayoutProperty::GetTextStyle);
1386     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Weight, normalStyle.GetFontWeight(), frameNode);
1387     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontFamily, normalStyle.GetFontFamilies(), frameNode);
1388     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, FontStyle, normalStyle.GetFontStyle(), frameNode);
1389 
1390     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, CanLoop, true, frameNode);
1391     ACE_UPDATE_NODE_LAYOUT_PROPERTY(
1392         TextPickerLayoutProperty, DigitalCrownSensitivity, pickerTheme->GetDigitalCrownSensitivity(), frameNode);
1393 }
1394 
SetDefaultTextStyle(FrameNode * frameNode,const RefPtr<TextTheme> & textTheme,const NG::PickerTextStyle & value)1395 void TextPickerModelNG::SetDefaultTextStyle(
1396     FrameNode* frameNode, const RefPtr<TextTheme>& textTheme, const NG::PickerTextStyle& value)
1397 {
1398     CHECK_NULL_VOID(frameNode);
1399     CHECK_NULL_VOID(textTheme);
1400     if (SystemProperties::ConfigChangePerform()) {
1401         ParseDefaultTextStyleResObj(value);
1402     }
1403 
1404     auto textStyle = textTheme->GetTextStyle();
1405     if (value.fontSize.has_value() && value.fontSize->IsValid()) {
1406         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontSize,
1407             ConvertFontScaleValue(value.fontSize.value()), frameNode);
1408     } else {
1409         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontSize,
1410             ConvertFontScaleValue(textStyle.GetFontSize()), frameNode);
1411     }
1412     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultColor,
1413         value.textColor.value_or(textStyle.GetTextColor()), frameNode);
1414     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultWeight,
1415         value.fontWeight.value_or(textStyle.GetFontWeight()), frameNode);
1416     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontFamily,
1417         value.fontFamily.value_or(textStyle.GetFontFamilies()), frameNode);
1418     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultFontStyle,
1419         value.fontStyle.value_or(textStyle.GetFontStyle()), frameNode);
1420     if (value.minFontSize.has_value() && value.minFontSize->IsValid()) {
1421         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMinFontSize,
1422             ConvertFontScaleValue(value.minFontSize.value()), frameNode);
1423     } else {
1424         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMinFontSize, Dimension(), frameNode);
1425     }
1426     if (value.maxFontSize.has_value() && value.maxFontSize->IsValid()) {
1427         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMaxFontSize,
1428             ConvertFontScaleValue(value.maxFontSize.value()), frameNode);
1429     } else {
1430         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultMaxFontSize, Dimension(), frameNode);
1431     }
1432     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultTextOverflow,
1433         value.textOverflow.value_or(textStyle.GetTextOverflow()), frameNode);
1434     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DefaultTextColorSetByUser,
1435         value.textColorSetByUser, frameNode);
1436 }
1437 
getTextPickerValue(FrameNode * frameNode)1438 std::string TextPickerModelNG::getTextPickerValue(FrameNode* frameNode)
1439 {
1440     CHECK_NULL_RETURN(frameNode, "");
1441     return frameNode->GetLayoutProperty<TextPickerLayoutProperty>()->GetValueValue("");
1442 }
1443 
getTextPickerRange(FrameNode * frameNode)1444 std::string TextPickerModelNG::getTextPickerRange(FrameNode* frameNode)
1445 {
1446     CHECK_NULL_RETURN(frameNode, "");
1447     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1448     CHECK_NULL_RETURN(textPickerPattern, "");
1449     return textPickerPattern->GetTextPickerRange();
1450 }
1451 
SetDivider(const ItemDivider & divider)1452 void TextPickerModelNG::SetDivider(const ItemDivider& divider)
1453 {
1454     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1455     CHECK_NULL_VOID(frameNode);
1456     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1457     CHECK_NULL_VOID(textPickerPattern);
1458     ParseDividerResObj(frameNode, divider);
1459     textPickerPattern->SetDivider(divider);
1460     textPickerPattern->SetCustomDividerFlag(true);
1461     ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, divider);
1462 }
1463 
SetDivider(FrameNode * frameNode,const ItemDivider & divider)1464 void TextPickerModelNG::SetDivider(FrameNode* frameNode, const ItemDivider& divider)
1465 {
1466     CHECK_NULL_VOID(frameNode);
1467     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1468     CHECK_NULL_VOID(textPickerPattern);
1469     ParseDividerResObj(frameNode, divider);
1470     textPickerPattern->SetDivider(divider);
1471     textPickerPattern->SetCustomDividerFlag(true);
1472     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, divider, frameNode);
1473 }
1474 
SetGradientHeight(FrameNode * frameNode,const Dimension & value)1475 void TextPickerModelNG::SetGradientHeight(FrameNode* frameNode, const Dimension& value)
1476 {
1477     CHECK_NULL_VOID(frameNode);
1478     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1479     CHECK_NULL_VOID(textPickerPattern);
1480     textPickerPattern->SetGradientHeight(value);
1481     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, value, frameNode);
1482 }
1483 
SetDisableTextStyleAnimation(FrameNode * frameNode,const bool value)1484 void TextPickerModelNG::SetDisableTextStyleAnimation(FrameNode* frameNode, const bool value)
1485 {
1486     CHECK_NULL_VOID(frameNode);
1487     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1488     CHECK_NULL_VOID(textPickerPattern);
1489     textPickerPattern->SetDisableTextStyleAnimation(value);
1490     ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, DisableTextStyleAnimation, value, frameNode);
1491 }
1492 
SetOnCascadeChange(FrameNode * frameNode,TextCascadeChangeEvent && onChange)1493 void TextPickerModelNG::SetOnCascadeChange(FrameNode* frameNode, TextCascadeChangeEvent&& onChange)
1494 {
1495     CHECK_NULL_VOID(frameNode);
1496     auto eventHub = frameNode->GetOrCreateEventHub<TextPickerEventHub>();
1497     CHECK_NULL_VOID(eventHub);
1498     eventHub->SetOnChange(std::move(onChange));
1499 }
1500 
SetOnScrollStop(FrameNode * frameNode,TextCascadeChangeEvent && onScrollStop)1501 void TextPickerModelNG::SetOnScrollStop(FrameNode* frameNode, TextCascadeChangeEvent&& onScrollStop)
1502 {
1503     CHECK_NULL_VOID(frameNode);
1504     auto eventHub = frameNode->GetOrCreateEventHub<TextPickerEventHub>();
1505     CHECK_NULL_VOID(eventHub);
1506     eventHub->SetOnScrollStop(std::move(onScrollStop));
1507 }
1508 
GetSelectedSize(FrameNode * frameNode)1509 int32_t TextPickerModelNG::GetSelectedSize(FrameNode* frameNode)
1510 {
1511     CHECK_NULL_RETURN(frameNode, 0);
1512     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1513     CHECK_NULL_RETURN(textPickerPattern, 0);
1514     return textPickerPattern->GetSelecteds().size();
1515 }
1516 
GetColumnWidthsSize(FrameNode * frameNode)1517 int32_t TextPickerModelNG::GetColumnWidthsSize(FrameNode* frameNode)
1518 {
1519     CHECK_NULL_RETURN(frameNode, 0);
1520     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1521     CHECK_NULL_RETURN(textPickerPattern, 0);
1522     return textPickerPattern->GetColumnWidths().size();
1523 }
1524 
getTextPickerValues(FrameNode * frameNode)1525 std::string TextPickerModelNG::getTextPickerValues(FrameNode* frameNode)
1526 {
1527     CHECK_NULL_RETURN(frameNode, "");
1528     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1529     CHECK_NULL_RETURN(textPickerPattern, "");
1530     auto values = textPickerPattern->GetValues();
1531     std::string result;
1532     for (auto& valueRet : values) {
1533         result.append(valueRet + ';');
1534     }
1535     const size_t length = result.length();
1536     result = result.substr(0, length > 0 ? length - 1 : 0);
1537     return result;
1538 }
1539 
getTextPickerSelecteds(FrameNode * frameNode)1540 std::vector<uint32_t> TextPickerModelNG::getTextPickerSelecteds(FrameNode* frameNode)
1541 {
1542     std::vector<uint32_t> defaultValue = { 0 };
1543     CHECK_NULL_RETURN(frameNode, defaultValue);
1544     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1545     CHECK_NULL_RETURN(textPickerPattern, defaultValue);
1546     return textPickerPattern->GetSelecteds();
1547 }
1548 
SetTextPickerRangeType(FrameNode * frameNode,int32_t rangeType)1549 void TextPickerModelNG::SetTextPickerRangeType(FrameNode* frameNode, int32_t rangeType)
1550 {
1551     CHECK_NULL_VOID(frameNode);
1552     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1553     CHECK_NULL_VOID(textPickerPattern);
1554     textPickerPattern->SetRangeType(rangeType);
1555 }
1556 
GetTextPickerRangeType(FrameNode * frameNode)1557 int32_t TextPickerModelNG::GetTextPickerRangeType(FrameNode* frameNode)
1558 {
1559     CHECK_NULL_RETURN(frameNode, 0);
1560     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1561     CHECK_NULL_RETURN(textPickerPattern, 0);
1562     return textPickerPattern->GetRangeType();
1563 }
1564 
ConvertFontScaleValue(const Dimension & fontSizeValue)1565 const Dimension TextPickerModelNG::ConvertFontScaleValue(const Dimension& fontSizeValue)
1566 {
1567     auto pipeline = PipelineContext::GetCurrentContext();
1568     CHECK_NULL_RETURN(pipeline, fontSizeValue);
1569     auto maxAppFontScale = pipeline->GetMaxAppFontScale();
1570     auto follow = pipeline->IsFollowSystem();
1571     float fontScale = pipeline->GetFontScale();
1572     if (NearZero(fontScale) || (fontSizeValue.Unit() == DimensionUnit::VP)) {
1573         return fontSizeValue;
1574     }
1575     if (GreatOrEqualCustomPrecision(fontScale, PICKER_MAXFONTSCALE) && follow) {
1576         fontScale = std::clamp(fontScale, 0.0f, maxAppFontScale);
1577         if (fontScale != 0.0f) {
1578             return Dimension(fontSizeValue / fontScale);
1579         }
1580     }
1581     return fontSizeValue;
1582 }
1583 
HasUserDefinedOpacity()1584 void TextPickerModelNG::HasUserDefinedOpacity()
1585 {
1586     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1587     CHECK_NULL_VOID(frameNode);
1588     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1589     CHECK_NULL_VOID(textPickerPattern);
1590     auto renderContext = frameNode->GetRenderContext();
1591     CHECK_NULL_VOID(renderContext);
1592     textPickerPattern->SetUserDefinedOpacity(renderContext->GetOpacityValue(1.0));
1593 }
1594 
SetEnableHapticFeedback(bool isEnableHapticFeedback)1595 void TextPickerModelNG::SetEnableHapticFeedback(bool isEnableHapticFeedback)
1596 {
1597     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1598     SetEnableHapticFeedback(frameNode, isEnableHapticFeedback);
1599 }
1600 
SetEnableHapticFeedback(FrameNode * frameNode,bool isEnableHapticFeedback)1601 void TextPickerModelNG::SetEnableHapticFeedback(FrameNode* frameNode, bool isEnableHapticFeedback)
1602 {
1603     CHECK_NULL_VOID(frameNode);
1604     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1605     CHECK_NULL_VOID(textPickerPattern);
1606     textPickerPattern->SetIsEnableHaptic(isEnableHapticFeedback);
1607 }
1608 
GetEnableHapticFeedback(FrameNode * frameNode)1609 bool TextPickerModelNG::GetEnableHapticFeedback(FrameNode* frameNode)
1610 {
1611     CHECK_NULL_RETURN(frameNode, DEFAULT_ENABLE_HAPTIC_FEEDBACK);
1612     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1613     CHECK_NULL_RETURN(textPickerPattern, DEFAULT_ENABLE_HAPTIC_FEEDBACK);
1614     return textPickerPattern->GetIsEnableHaptic();
1615 }
1616 
SetSelectedBackgroundStyle(const NG::PickerBackgroundStyle & value)1617 void TextPickerModelNG::SetSelectedBackgroundStyle(const NG::PickerBackgroundStyle& value)
1618 {
1619     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1620     CHECK_NULL_VOID(frameNode);
1621     ParseBackgroundStyleColorResObj(frameNode, value);
1622     ParseBackgroundStyleRadiusResObj(frameNode, value);
1623     if (value.color.has_value()) {
1624         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor,
1625             value.color.value());
1626     }
1627     if (value.borderRadius.has_value()) {
1628         ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBorderRadius,
1629             value.borderRadius.value());
1630     }
1631 }
1632 
SetSelectedBackgroundStyle(FrameNode * frameNode,const NG::PickerBackgroundStyle & value)1633 void TextPickerModelNG::SetSelectedBackgroundStyle(FrameNode* frameNode, const NG::PickerBackgroundStyle& value)
1634 {
1635     CHECK_NULL_VOID(frameNode);
1636     ParseBackgroundStyleColorResObj(frameNode, value);
1637     ParseBackgroundStyleRadiusResObj(frameNode, value);
1638     if (value.color.has_value()) {
1639         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor,
1640             value.color.value(), frameNode);
1641     }
1642     if (value.borderRadius.has_value()) {
1643         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBorderRadius,
1644             value.borderRadius.value(), frameNode);
1645     }
1646 }
1647 
GetSelectedBackgroundStyle(FrameNode * frameNode)1648 PickerBackgroundStyle TextPickerModelNG::GetSelectedBackgroundStyle(FrameNode* frameNode)
1649 {
1650     PickerBackgroundStyle pickerBgStyle;
1651     CHECK_NULL_RETURN(frameNode, pickerBgStyle);
1652     auto context = frameNode->GetContext();
1653     CHECK_NULL_RETURN(context, pickerBgStyle);
1654     auto theme = context->GetTheme<PickerTheme>();
1655     CHECK_NULL_RETURN(theme, pickerBgStyle);
1656     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedBackgroundColor,
1657         pickerBgStyle.color, frameNode, theme->GetSelectedBackgroundColor());
1658     ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(TextPickerLayoutProperty, SelectedBorderRadius,
1659         pickerBgStyle.borderRadius, frameNode, theme->GetSelectedBorderRadius());
1660     return pickerBgStyle;
1661 }
1662 
IsCascade()1663 bool TextPickerModelNG::IsCascade()
1664 {
1665     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1666     CHECK_NULL_RETURN(frameNode, false);
1667     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1668     CHECK_NULL_RETURN(textPickerPattern, false);
1669     return textPickerPattern->GetIsCascade();
1670 }
1671 
SetSingleRange(bool isSingleRange)1672 void TextPickerModelNG::SetSingleRange(bool isSingleRange)
1673 {
1674     std::lock_guard<std::shared_mutex> lock(isSingleMutex_);
1675     isSingleRange_ = isSingleRange;
1676     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1677     CHECK_NULL_VOID(frameNode);
1678     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1679     CHECK_NULL_VOID(textPickerPattern);
1680     textPickerPattern->SetSingleRange(isSingleRange);
1681 }
1682 
UpdateUserSetSelectColor()1683 void TextPickerModelNG::UpdateUserSetSelectColor()
1684 {
1685     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1686     CHECK_NULL_VOID(frameNode);
1687     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1688     CHECK_NULL_VOID(textPickerPattern);
1689     textPickerPattern->UpdateUserSetSelectColor();
1690 }
1691 
ParseGradientHeight(const RefPtr<ResourceObject> & resObj)1692 void TextPickerModelNG::ParseGradientHeight(const RefPtr<ResourceObject>& resObj)
1693 {
1694     CHECK_NULL_VOID(resObj);
1695     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1696     CHECK_NULL_VOID(frameNode);
1697     ParseGradientHeight(frameNode, resObj);
1698 }
1699 
ParseGradientHeight(FrameNode * frameNode,const RefPtr<ResourceObject> & resObj)1700 void TextPickerModelNG::ParseGradientHeight(FrameNode* frameNode, const RefPtr<ResourceObject>& resObj)
1701 {
1702     if (!SystemProperties::ConfigChangePerform()) {
1703         return;
1704     }
1705 
1706     CHECK_NULL_VOID(frameNode);
1707     CHECK_NULL_VOID(resObj);
1708     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1709     CHECK_NULL_VOID(textPickerPattern);
1710 
1711     auto&& updateFunc = [frameNode](const RefPtr<ResourceObject>& resObj) {
1712         CalcDimension height;
1713         if (!resObj || !ResourceParseUtils::ParseResDimensionFp(resObj, height)) {
1714             return;
1715         }
1716         auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1717         CHECK_NULL_VOID(textPickerPattern);
1718         textPickerPattern->SetGradientHeight(height);
1719         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, GradientHeight, height, frameNode);
1720     };
1721     textPickerPattern->AddResObj("textPicker.gradientHeight", resObj, std::move(updateFunc));
1722 }
1723 
ParseDividerResObj(FrameNode * frameNode,const NG::ItemDivider & divider)1724 void TextPickerModelNG::ParseDividerResObj(FrameNode* frameNode, const NG::ItemDivider& divider)
1725 {
1726     if (!SystemProperties::ConfigChangePerform()) {
1727         return;
1728     }
1729 
1730     CHECK_NULL_VOID(frameNode);
1731     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1732     CHECK_NULL_VOID(textPickerPattern);
1733 
1734     if (!divider.strokeWidthResObj && !divider.colorResObj && !divider.startMarginResObj && !divider.endMarginResObj) {
1735         textPickerPattern->RemoveResObj("textPicker.divider");
1736         return;
1737     }
1738 
1739     auto&& updateFunc = [frameNode, divider](const RefPtr<ResourceObject>& resObj) {
1740         auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1741         CHECK_NULL_VOID(textPickerPattern);
1742         auto context = frameNode->GetContext();
1743         CHECK_NULL_VOID(context);
1744         auto pickerTheme = context->GetTheme<PickerTheme>();
1745         CHECK_NULL_VOID(pickerTheme);
1746 
1747         NG::ItemDivider& curDivider = const_cast<NG::ItemDivider&>(divider);
1748         CalcDimension strokeWidth = pickerTheme->GetDividerThickness();
1749         curDivider.strokeWidth = strokeWidth;
1750         if (curDivider.strokeWidthResObj &&
1751             ResourceParseUtils::ParseResDimensionFpNG(curDivider.strokeWidthResObj, strokeWidth)) {
1752             curDivider.strokeWidth = strokeWidth;
1753         }
1754 
1755         Color color = pickerTheme->GetDividerColor();
1756         curDivider.color = color;
1757         if (curDivider.colorResObj && ResourceParseUtils::ParseResColor(curDivider.colorResObj, color)) {
1758             curDivider.color = color;
1759         }
1760 
1761         CalcDimension startMargin = 0.0_vp;
1762         curDivider.startMargin = startMargin;
1763         if (curDivider.startMarginResObj &&
1764             ResourceParseUtils::ParseResDimensionFpNG(curDivider.startMarginResObj, startMargin)) {
1765             curDivider.startMargin = startMargin;
1766         }
1767 
1768         CalcDimension endMargin = 0.0_vp;
1769         curDivider.endMargin = endMargin;
1770         if (curDivider.endMarginResObj &&
1771             ResourceParseUtils::ParseResDimensionFpNG(curDivider.endMarginResObj, endMargin)) {
1772             curDivider.endMargin = endMargin;
1773         }
1774 
1775         textPickerPattern->SetDivider(curDivider);
1776         textPickerPattern->SetCustomDividerFlag(true);
1777         ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Divider, curDivider, frameNode);
1778     };
1779     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
1780     textPickerPattern->RemoveResObj("textPicker.divider");
1781     textPickerPattern->AddResObj("textPicker.divider", resObj, std::move(updateFunc));
1782 }
1783 
ParseResTextStyle(const PickerTextStyle & textStyleOpt,const std::string & textStyleType,std::function<void (const PickerTextStyle &)> updateTextStyleFunc)1784 void TextPickerModelNG::ParseResTextStyle(const PickerTextStyle& textStyleOpt, const std::string& textStyleType,
1785     std::function<void(const PickerTextStyle&)> updateTextStyleFunc)
1786 {
1787     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1788     CHECK_NULL_VOID(frameNode);
1789 
1790     auto pickerPattern = frameNode->GetPattern<TextPickerPattern>();
1791     CHECK_NULL_VOID(pickerPattern);
1792 
1793     if (!textStyleOpt.textColorResObj && !textStyleOpt.fontSizeResObj && !textStyleOpt.fontFamilyResObj &&
1794         !textStyleOpt.minFontSizeResObj && !textStyleOpt.maxFontSizeResObj) {
1795         pickerPattern->RemoveResObj(textStyleType);
1796         return;
1797     }
1798 
1799     auto&& updateFunc = [textStyleOpt, frameNode, updateTextStyleFunc](const RefPtr<ResourceObject> resObj) {
1800         PickerTextStyle textStyle;
1801         Color color;
1802         CalcDimension fontSize;
1803         std::vector<std::string> families;
1804 
1805         if (textStyleOpt.textColorResObj &&
1806             ResourceParseUtils::ParseResColor(textStyleOpt.textColorResObj, color)) {
1807             textStyle.textColor = color;
1808         }
1809 
1810         if (textStyleOpt.fontSizeResObj &&
1811             ResourceParseUtils::ParseResDimensionFp(textStyleOpt.fontSizeResObj, fontSize)) {
1812             textStyle.fontSize = fontSize;
1813         }
1814 
1815         if (textStyleOpt.fontFamilyResObj &&
1816             ResourceParseUtils::ParseResFontFamilies(textStyleOpt.fontFamilyResObj, families)) {
1817             textStyle.fontFamily = families;
1818         }
1819 
1820         CalcDimension minFontSize;
1821         if (textStyleOpt.minFontSizeResObj &&
1822             ResourceParseUtils::ParseResDimensionFp(textStyleOpt.minFontSizeResObj, minFontSize)) {
1823             textStyle.minFontSize = minFontSize;
1824         }
1825 
1826         CalcDimension maxFontSize;
1827         if (textStyleOpt.maxFontSizeResObj &&
1828             ResourceParseUtils::ParseResDimensionFp(textStyleOpt.maxFontSizeResObj, maxFontSize)) {
1829             textStyle.maxFontSize = maxFontSize;
1830         }
1831 
1832         updateTextStyleFunc(textStyle);
1833     };
1834     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
1835     pickerPattern->AddResObj(textStyleType, resObj, std::move(updateFunc));
1836 }
1837 
ParseDisappearTextStyleResObj(const PickerTextStyle & textStyleOpt)1838 void TextPickerModelNG::ParseDisappearTextStyleResObj(const PickerTextStyle& textStyleOpt)
1839 {
1840     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1841     CHECK_NULL_VOID(frameNode);
1842 
1843     auto pickerPattern = frameNode->GetPattern<TextPickerPattern>();
1844     CHECK_NULL_VOID(pickerPattern);
1845 
1846     ParseResTextStyle(
1847         textStyleOpt,
1848         "TextPickerDisappearTextStyle",
1849         [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateDisappearTextStyle(textStyle); }
1850     );
1851 }
1852 
ParseSelectedTextStyleResObj(const PickerTextStyle & textStyleOpt)1853 void TextPickerModelNG::ParseSelectedTextStyleResObj(const PickerTextStyle& textStyleOpt)
1854 {
1855     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1856     CHECK_NULL_VOID(frameNode);
1857 
1858     auto pickerPattern = frameNode->GetPattern<TextPickerPattern>();
1859     CHECK_NULL_VOID(pickerPattern);
1860 
1861     ParseResTextStyle(
1862         textStyleOpt,
1863         "TextPickerSelectedTextStyle",
1864         [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateSelectedTextStyle(textStyle); }
1865     );
1866 }
1867 
ParseNormalTextStyleResObj(const PickerTextStyle & textStyleOpt)1868 void TextPickerModelNG::ParseNormalTextStyleResObj(const PickerTextStyle& textStyleOpt)
1869 {
1870     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1871     CHECK_NULL_VOID(frameNode);
1872 
1873     auto pickerPattern = frameNode->GetPattern<TextPickerPattern>();
1874     CHECK_NULL_VOID(pickerPattern);
1875 
1876     ParseResTextStyle(
1877         textStyleOpt,
1878         "TextPickerNormalTextStyle",
1879         [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateNormalTextStyle(textStyle); }
1880     );
1881 }
1882 
ParseDefaultTextStyleResObj(const PickerTextStyle & textStyleOpt)1883 void TextPickerModelNG::ParseDefaultTextStyleResObj(const PickerTextStyle& textStyleOpt)
1884 {
1885     if (!SystemProperties::ConfigChangePerform()) {
1886         return;
1887     }
1888 
1889     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1890     CHECK_NULL_VOID(frameNode);
1891 
1892     auto pickerPattern = frameNode->GetPattern<TextPickerPattern>();
1893     CHECK_NULL_VOID(pickerPattern);
1894 
1895     ParseResTextStyle(
1896         textStyleOpt,
1897         "TextPickerDefaultTextStyle",
1898         [pickerPattern](const PickerTextStyle& textStyle) { pickerPattern->UpdateDefaultTextStyle(textStyle); }
1899     );
1900 }
1901 
ParseSingleRangeResourceObj(const RefPtr<ResourceObject> & resultResObj,const RefPtr<ResourceObject> & valueResObj)1902 void TextPickerModelNG::ParseSingleRangeResourceObj(const RefPtr<ResourceObject>& resultResObj,
1903     const RefPtr<ResourceObject>& valueResObj)
1904 {
1905     if (!SystemProperties::ConfigChangePerform()) {
1906         return;
1907     }
1908 
1909     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1910     CHECK_NULL_VOID(frameNode);
1911     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1912     CHECK_NULL_VOID(textPickerPattern);
1913 
1914     auto&& updateFunc = [frameNode, resultResObj, valueResObj](const RefPtr<ResourceObject> resObj) {
1915         auto pickerPattern = frameNode->GetPattern<TextPickerPattern>();
1916         CHECK_NULL_VOID(pickerPattern);
1917 
1918         std::vector<NG::RangeContent> rangeVector = pickerPattern->GetRange();
1919         std::vector<std::string> getRangeVector;
1920 
1921         if (resultResObj && ResourceParseUtils::ParseResStrArray(resultResObj, getRangeVector)) {
1922             rangeVector.clear();
1923             for (const auto& text : getRangeVector) {
1924                 NG::RangeContent content;
1925                 content.icon_ = "";
1926                 content.text_ = text;
1927                 rangeVector.emplace_back(content);
1928             }
1929             pickerPattern->SetRange(rangeVector);
1930         }
1931 
1932         if (pickerPattern->GetHasSelectAttr()) {
1933             return;
1934         }
1935 
1936         std::string result;
1937         if (!valueResObj || !ResourceParseUtils::ParseResString(valueResObj, result)) {
1938             return;
1939         }
1940         for (uint32_t index = 0; index < rangeVector.size(); index++) {
1941             if (rangeVector[index].text_ == result) {
1942                 pickerPattern->SetSelected(index);
1943                 std::vector<uint32_t> values;
1944                 values.emplace_back(index);
1945                 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Value, result);
1946                 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, Selected, index);
1947                 ACE_UPDATE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedIndex, values);
1948                 break;
1949             }
1950         }
1951     };
1952     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
1953     textPickerPattern->AddResObj("TextPicker.singleRange", resObj, std::move(updateFunc));
1954 }
1955 
ParseColumnWidthsResourceObj(const std::vector<RefPtr<ResourceObject>> & widthResObjs)1956 void TextPickerModelNG::ParseColumnWidthsResourceObj(const std::vector<RefPtr<ResourceObject>>& widthResObjs)
1957 {
1958     if (!SystemProperties::ConfigChangePerform() || (widthResObjs.size() <= 0)) {
1959         return;
1960     }
1961 
1962     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1963     CHECK_NULL_VOID(frameNode);
1964     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1965     CHECK_NULL_VOID(textPickerPattern);
1966 
1967     auto&& updateFunc = [frameNode, textPickerPattern, widthResObjs](const RefPtr<ResourceObject> resObj) {
1968         std::vector<Dimension> widths;
1969         for (auto& widthResObj : widthResObjs) {
1970             CalcDimension calc;
1971             ResourceParseUtils::ParseResDimensionVpNG(widthResObj, calc);
1972             widths.emplace_back(calc);
1973         }
1974         textPickerPattern->SetColumnWidths(widths);
1975     };
1976     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
1977     textPickerPattern->AddResObj("TextPicker.columnWidths", resObj, std::move(updateFunc));
1978 }
1979 
ParseSingleIconTextResourceObj(const std::vector<NG::RangeContent> & value)1980 void TextPickerModelNG::ParseSingleIconTextResourceObj(const std::vector<NG::RangeContent>& value)
1981 {
1982     if (!SystemProperties::ConfigChangePerform()) {
1983         return;
1984     }
1985 
1986     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1987     CHECK_NULL_VOID(frameNode);
1988     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1989     CHECK_NULL_VOID(textPickerPattern);
1990 
1991     auto&& updateFunc = [frameNode, value](const RefPtr<ResourceObject> resObj) {
1992         auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
1993         CHECK_NULL_VOID(textPickerPattern);
1994         std::vector<NG::RangeContent> rangeVector;
1995         std::vector<NG::RangeContent> oldRangeVector = textPickerPattern->GetRange();
1996         uint32_t index = 0;
1997         rangeVector.clear();
1998         for (auto& item : value) {
1999             std::string icon;
2000             std::string text;
2001             NG::RangeContent content;
2002             if (item.iconResObj_) {
2003                 ResourceParseUtils::ParseResMedia(item.iconResObj_, icon);
2004                 content.icon_ = icon;
2005             } else {
2006                 content.icon_ = index < oldRangeVector.size() ? oldRangeVector[index].icon_ : "";
2007             }
2008 
2009             if (item.textResObj_) {
2010                 ResourceParseUtils::ParseResString(item.textResObj_, text);
2011                 content.text_ = text;
2012             } else {
2013                 content.text_ = index < oldRangeVector.size() ? oldRangeVector[index].text_ : "";
2014             }
2015 
2016             rangeVector.emplace_back(content);
2017             index++;
2018         }
2019         uint32_t selectedIndex = textPickerPattern->GetSelected();
2020         textPickerPattern->SetSelected(selectedIndex);
2021         textPickerPattern->SetRange(rangeVector);
2022         textPickerPattern->UpdateMeasureOnColorModeChange();
2023     };
2024     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
2025     textPickerPattern->AddResObj("TextPicker.singleIconText", resObj, std::move(updateFunc));
2026 }
2027 
ParseCascadeResourceObj(const std::vector<NG::TextCascadePickerOptions> & options,const std::vector<RefPtr<ResourceObject>> & valueArrResObj)2028 void TextPickerModelNG::ParseCascadeResourceObj(const std::vector<NG::TextCascadePickerOptions>& options,
2029     const std::vector<RefPtr<ResourceObject>>& valueArrResObj)
2030 {
2031     if (!SystemProperties::ConfigChangePerform() || (options.size() <= 0)) {
2032         return;
2033     }
2034 
2035     auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2036     CHECK_NULL_VOID(frameNode);
2037     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
2038     CHECK_NULL_VOID(textPickerPattern);
2039 
2040     auto&& updateFunc = [frameNode, options, valueArrResObj](const RefPtr<ResourceObject> resObj) {
2041         auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
2042         CHECK_NULL_VOID(textPickerPattern);
2043 
2044         std::vector<NG::TextCascadePickerOptions>& rangeOptions =
2045             const_cast<std::vector<NG::TextCascadePickerOptions>&>(options);
2046         textPickerPattern->GetAndUpdateRealSelectedArr(rangeOptions, valueArrResObj);
2047 
2048         // Calcalate max depth
2049         size_t depth = rangeOptions.empty() ? 0 : 1;
2050         for (size_t i = 0; i < rangeOptions.size(); i++) {
2051             size_t tmp = textPickerPattern->ProcessCascadeOptionDepth(rangeOptions[i]);
2052             if (tmp > depth) {
2053                 depth = tmp;
2054             }
2055         }
2056 
2057         std::vector<NG::TextCascadePickerOptions> reOptions;
2058         textPickerPattern->ProcessCascadeOptions(rangeOptions, reOptions, 0);
2059         if (reOptions.size() < depth) {
2060             auto differ = depth - reOptions.size();
2061             for (uint32_t i = 0; i < differ; i++) {
2062                 NG::TextCascadePickerOptions differOption;
2063                 memset_s(&differOption, sizeof(differOption), 0, sizeof(differOption));
2064                 reOptions.emplace_back(differOption);
2065             }
2066         }
2067         textPickerPattern->SetCascadeOptions(rangeOptions, reOptions);
2068     };
2069     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
2070     textPickerPattern->AddResObj("TextPicker.CascadeRange", resObj, std::move(updateFunc));
2071 }
2072 
TextPickerRemoveResObj(FrameNode * frameNode,const std::string & key)2073 void TextPickerModelNG::TextPickerRemoveResObj(FrameNode* frameNode, const std::string& key)
2074 {
2075     if (!SystemProperties::ConfigChangePerform()) {
2076         return;
2077     }
2078 
2079     CHECK_NULL_VOID(frameNode);
2080     auto pickerPattern = frameNode->GetPattern<TextPickerPattern>();
2081     CHECK_NULL_VOID(pickerPattern);
2082     pickerPattern->RemoveResObj(key);
2083 }
2084 
ParseBackgroundStyleColorResObj(FrameNode * frameNode,const NG::PickerBackgroundStyle & value)2085 void TextPickerModelNG::ParseBackgroundStyleColorResObj(FrameNode* frameNode, const NG::PickerBackgroundStyle& value)
2086 {
2087     if (!SystemProperties::ConfigChangePerform() || !frameNode) {
2088         return;
2089     }
2090 
2091     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
2092     CHECK_NULL_VOID(textPickerPattern);
2093     textPickerPattern->RemoveResObj("TextPicker.BackgroundStyle.color");
2094 
2095     auto&& updateColorFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
2096         auto node = weak.Upgrade();
2097         CHECK_NULL_VOID(node);
2098 
2099         NG::PickerBackgroundStyle& backgroundValue = const_cast<NG::PickerBackgroundStyle&>(value);
2100         Color color = backgroundValue.color.value();
2101         if (value.colorResObj && ResourceParseUtils::ParseResColor(backgroundValue.colorResObj, color)) {
2102             ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor, color, node);
2103         } else if (!value.textColorSetByUser) {
2104             auto context = node->GetContext();
2105             CHECK_NULL_VOID(context);
2106             auto theme = context->GetTheme<PickerTheme>();
2107             if (theme) {
2108                 color = theme->GetSelectedBackgroundColor();
2109                 ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBackgroundColor, color, node);
2110             }
2111         }
2112     };
2113     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
2114     textPickerPattern->AddResObj("TextPicker.BackgroundStyle.color", resObj, std::move(updateColorFunc));
2115 }
2116 
ParseBackgroundStyleRadiusResObj(FrameNode * frameNode,const NG::PickerBackgroundStyle & value)2117 void TextPickerModelNG::ParseBackgroundStyleRadiusResObj(FrameNode* frameNode, const NG::PickerBackgroundStyle& value)
2118 {
2119     if (!SystemProperties::ConfigChangePerform() || !frameNode) {
2120         return;
2121     }
2122 
2123     auto textPickerPattern = frameNode->GetPattern<TextPickerPattern>();
2124     CHECK_NULL_VOID(textPickerPattern);
2125     textPickerPattern->RemoveResObj("TextPicker.BackgroundStyle.borderRadius");
2126 
2127     if (!value.borderRadiusResObj && !value.borderRadius->HasResources()) {
2128         return;
2129     }
2130 
2131     auto&& updateRadiusFunc = [value, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
2132         auto node = weak.Upgrade();
2133         CHECK_NULL_VOID(node);
2134 
2135         NG::PickerBackgroundStyle& backgroundValue = const_cast<NG::PickerBackgroundStyle&>(value);
2136         if (backgroundValue.borderRadius->HasResources()) {
2137             backgroundValue.borderRadius->ReloadResources();
2138             NG::BorderRadiusProperty& borderRadiusValue = backgroundValue.borderRadius.value();
2139             ACE_UPDATE_NODE_LAYOUT_PROPERTY(TextPickerLayoutProperty, SelectedBorderRadius, borderRadiusValue, node);
2140         } else if (backgroundValue.borderRadiusResObj) {
2141             CalcDimension calcDimension;
2142             ResourceParseUtils::ParseResDimensionVpNG(backgroundValue.borderRadiusResObj, calcDimension);
2143             if (GreatOrEqual(calcDimension.Value(), 0.0f)) {
2144                 NG::BorderRadiusProperty borderRadiusValue = NG::BorderRadiusProperty(calcDimension);
2145                 ACE_UPDATE_NODE_LAYOUT_PROPERTY(
2146                     TextPickerLayoutProperty, SelectedBorderRadius, borderRadiusValue, node);
2147             }
2148         }
2149     };
2150     RefPtr<ResourceObject> resObj = AceType::MakeRefPtr<ResourceObject>();
2151     textPickerPattern->AddResObj("TextPicker.BackgroundStyle.borderRadius", resObj, std::move(updateRadiusFunc));
2152 }
2153 
2154 } // namespace OHOS::Ace::NG
2155