1 /*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "core/components_ng/pattern/slider/slider_model_ng.h"
17
18 #include "core/components/slider/slider_theme.h"
19 #include "core/components_ng/base/view_stack_processor.h"
20 #include "core/components_ng/pattern/slider/slider_layout_property.h"
21 #include "core/components_ng/pattern/slider/slider_paint_property.h"
22 #include "core/components_ng/pattern/slider/slider_pattern.h"
23 #include "core/components_v2/inspector/inspector_constants.h"
24 #include "core/pipeline/pipeline_base.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26
27 namespace OHOS::Ace::NG {
28 const float DEFAULT_STEP = 1.0f;
29 const float DEFAULT_MIN_VALUE = 0.0f;
30 const float DEFAULT_MAX_VALUE = 100.0f;
31 constexpr uint32_t BLOCK_COLOR = 0xffffffff;
32 constexpr uint32_t TRACK_COLOR = 0x19182431;
33 constexpr uint32_t SELECTED_COLOR = 0xff007dff;
34
Create(float value,float step,float min,float max)35 void SliderModelNG::Create(float value, float step, float min, float max)
36 {
37 auto* stack = ViewStackProcessor::GetInstance();
38 auto nodeId = stack->ClaimNodeId();
39 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", V2::SLIDER_ETS_TAG, nodeId);
40 auto frameNode = FrameNode::GetOrCreateFrameNode(
41 V2::SLIDER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<SliderPattern>(); });
42 stack->Push(frameNode);
43 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, Step, step);
44 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, Min, min);
45 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, Max, max);
46 SetSliderValue(value);
47 }
SetSliderValue(float value)48 void SliderModelNG::SetSliderValue(float value)
49 {
50 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
51 CHECK_NULL_VOID(frameNode);
52 auto pattern = frameNode->GetPattern<SliderPattern>();
53 CHECK_NULL_VOID(pattern);
54 pattern->UpdateValue(value);
55 auto sliderEventHub = frameNode->GetEventHub<SliderEventHub>();
56 CHECK_NULL_VOID(sliderEventHub);
57 sliderEventHub->SetValue(value);
58 }
SetSliderMode(const SliderMode & value)59 void SliderModelNG::SetSliderMode(const SliderMode& value)
60 {
61 ACE_UPDATE_LAYOUT_PROPERTY(SliderLayoutProperty, SliderMode, value);
62 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, SliderMode, value);
63 }
SetDirection(Axis value)64 void SliderModelNG::SetDirection(Axis value)
65 {
66 ACE_UPDATE_LAYOUT_PROPERTY(SliderLayoutProperty, Direction, value);
67 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, Direction, value);
68 }
SetReverse(bool value)69 void SliderModelNG::SetReverse(bool value)
70 {
71 ACE_UPDATE_LAYOUT_PROPERTY(SliderLayoutProperty, Reverse, value);
72 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, Reverse, value);
73 }
SetBlockColor(const Color & value)74 void SliderModelNG::SetBlockColor(const Color& value)
75 {
76 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockColor, value);
77 }
SetTrackBackgroundColor(const Gradient & value,bool isResourceColor)78 void SliderModelNG::SetTrackBackgroundColor(const Gradient& value, bool isResourceColor)
79 {
80 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, TrackBackgroundColor, value);
81 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, TrackBackgroundIsResourceColor, isResourceColor);
82 }
SetSelectColor(const Color & value)83 void SliderModelNG::SetSelectColor(const Color& value)
84 {
85 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, SelectColor, value);
86 }
SetSelectColor(const Gradient & value,bool isResourceColor)87 void SliderModelNG::SetSelectColor(const Gradient& value, bool isResourceColor)
88 {
89 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, SelectGradientColor, value);
90 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, SelectIsResourceColor, isResourceColor);
91 }
SetMinLabel(float value)92 void SliderModelNG::SetMinLabel(float value)
93 {
94 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, Min, value);
95 }
SetMaxLabel(float value)96 void SliderModelNG::SetMaxLabel(float value)
97 {
98 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, Max, value);
99 }
SetMinResponsiveDistance(float value)100 void SliderModelNG::SetMinResponsiveDistance(float value)
101 {
102 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
103 CHECK_NULL_VOID(frameNode);
104 auto layoutProperty = frameNode->GetPaintProperty<SliderPaintProperty>();
105 CHECK_NULL_VOID(layoutProperty);
106 auto minResponse = 0.0f;
107 auto minValue = layoutProperty->GetMinValue(0.0f);
108 auto maxValue = layoutProperty->GetMaxValue(100.0f);
109 auto diff = maxValue - minValue;
110 if (LessOrEqual(value, diff) && GreatNotEqual(value, minResponse)) {
111 minResponse = value;
112 }
113 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, MinResponsiveDistance, minResponse);
114 }
115
SetValidSlideRange(float from,float to)116 void SliderModelNG::SetValidSlideRange(float from, float to)
117 {
118 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
119 SliderModelNG::SetValidSlideRange(frameNode, from, to);
120 }
121
SetShowSteps(bool value)122 void SliderModelNG::SetShowSteps(bool value)
123 {
124 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, ShowSteps, value);
125 }
SetSliderInteractionMode(SliderInteraction mode)126 void SliderModelNG::SetSliderInteractionMode(SliderInteraction mode)
127 {
128 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, SliderInteractionMode, mode);
129 }
SetShowTips(bool value,const std::optional<std::string> & content)130 void SliderModelNG::SetShowTips(bool value, const std::optional<std::string>& content)
131 {
132 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, ShowTips, value);
133 if (content.has_value()) {
134 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, CustomContent, content.value());
135 } else {
136 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, CustomContent, PROPERTY_UPDATE_RENDER);
137 }
138 }
SetThickness(const Dimension & value)139 void SliderModelNG::SetThickness(const Dimension& value)
140 {
141 if (value.IsNonPositive()) {
142 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
143 CHECK_NULL_VOID(frameNode);
144 auto layoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
145 CHECK_NULL_VOID(layoutProperty);
146 auto pipeline = frameNode->GetContext();
147 CHECK_NULL_VOID(pipeline);
148 auto theme = pipeline->GetTheme<SliderTheme>();
149 CHECK_NULL_VOID(theme);
150 auto sliderMode = layoutProperty->GetSliderModeValue(SliderModel::SliderMode::OUTSET);
151 Dimension themeTrackThickness;
152 if (sliderMode == SliderModel::SliderMode::OUTSET) {
153 themeTrackThickness = theme->GetOutsetTrackThickness();
154 } else if (sliderMode == SliderModel::SliderMode::INSET) {
155 themeTrackThickness = theme->GetInsetTrackThickness();
156 } else {
157 themeTrackThickness = theme->GetNoneTrackThickness();
158 }
159 ACE_UPDATE_LAYOUT_PROPERTY(SliderLayoutProperty, Thickness, themeTrackThickness);
160 } else {
161 ACE_UPDATE_LAYOUT_PROPERTY(SliderLayoutProperty, Thickness, value);
162 }
163 }
SetBlockBorderColor(const Color & value)164 void SliderModelNG::SetBlockBorderColor(const Color& value)
165 {
166 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockBorderColor, value);
167 }
SetBlockBorderWidth(const Dimension & value)168 void SliderModelNG::SetBlockBorderWidth(const Dimension& value)
169 {
170 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockBorderWidth, value);
171 }
SetStepColor(const Color & value)172 void SliderModelNG::SetStepColor(const Color& value)
173 {
174 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, StepColor, value);
175 }
SetTrackBorderRadius(const Dimension & value)176 void SliderModelNG::SetTrackBorderRadius(const Dimension& value)
177 {
178 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, TrackBorderRadius, value);
179 }
SetSelectedBorderRadius(const Dimension & value)180 void SliderModelNG::SetSelectedBorderRadius(const Dimension& value)
181 {
182 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, SelectedBorderRadius, value);
183 }
SetBlockSize(const Dimension & width,const Dimension & height)184 void SliderModelNG::SetBlockSize(const Dimension& width, const Dimension& height)
185 {
186 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
187 CHECK_NULL_VOID(frameNode);
188 auto layoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
189 CHECK_NULL_VOID(layoutProperty);
190 auto pipeline = PipelineBase::GetCurrentContext();
191 CHECK_NULL_VOID(pipeline);
192 SizeT<Dimension> blockSize;
193 auto theme = pipeline->GetTheme<SliderTheme>();
194 if (theme != nullptr) {
195 auto mode = layoutProperty->GetSliderModeValue(SliderMode::OUTSET);
196 auto themeBlockSize = mode == SliderMode::OUTSET ? theme->GetOutsetBlockSize() : theme->GetInsetBlockSize();
197 blockSize = layoutProperty->GetBlockSizeValue(SizeT<Dimension>(themeBlockSize, themeBlockSize));
198 }
199
200 if (LessOrEqual(width.Value(), 0.0) || LessOrEqual(height.Value(), 0.0)) {
201 ResetBlockSize();
202 } else {
203 blockSize.SetWidth(width);
204 blockSize.SetHeight(height);
205 ACE_UPDATE_LAYOUT_PROPERTY(SliderLayoutProperty, BlockSize, blockSize);
206 }
207 }
SetBlockType(BlockStyleType value)208 void SliderModelNG::SetBlockType(BlockStyleType value)
209 {
210 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockType, value);
211 }
SetBlockImage(const std::string & value,const std::string & bundleName,const std::string & moduleName)212 void SliderModelNG::SetBlockImage(
213 const std::string& value, const std::string& bundleName, const std::string& moduleName)
214 {
215 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockImage, value);
216 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockImageBundleName, bundleName);
217 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockImageModuleName, moduleName);
218 }
SetBlockShape(const RefPtr<BasicShape> & value)219 void SliderModelNG::SetBlockShape(const RefPtr<BasicShape>& value)
220 {
221 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, BlockShape, value);
222 }
SetStepSize(const Dimension & value)223 void SliderModelNG::SetStepSize(const Dimension& value)
224 {
225 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, StepSize, value);
226 }
227 #ifdef SUPPORT_DIGITAL_CROWN
SetDigitalCrownSensitivity(CrownSensitivity sensitivity)228 void SliderModelNG::SetDigitalCrownSensitivity(CrownSensitivity sensitivity)
229 {
230 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, DigitalCrownSensitivity, sensitivity);
231 }
232 #endif
SetOnChange(SliderOnChangeEvent && eventOnChange)233 void SliderModelNG::SetOnChange(SliderOnChangeEvent&& eventOnChange)
234 {
235 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
236 CHECK_NULL_VOID(frameNode);
237 auto eventHub = frameNode->GetEventHub<SliderEventHub>();
238 CHECK_NULL_VOID(eventHub);
239 eventHub->SetOnChange(std::move(eventOnChange));
240 }
241
SetOnChangeEvent(SliderOnValueChangeEvent && onChangeEvent)242 void SliderModelNG::SetOnChangeEvent(SliderOnValueChangeEvent&& onChangeEvent)
243 {
244 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
245 CHECK_NULL_VOID(frameNode);
246 auto eventHub = frameNode->GetEventHub<SliderEventHub>();
247 CHECK_NULL_VOID(eventHub);
248 eventHub->SetOnChangeEvent(std::move(onChangeEvent));
249 }
250
ResetBlockBorderColor()251 void SliderModelNG::ResetBlockBorderColor()
252 {
253 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockBorderColor, PROPERTY_UPDATE_RENDER);
254 }
255
ResetBlockBorderWidth()256 void SliderModelNG::ResetBlockBorderWidth()
257 {
258 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockBorderWidth, PROPERTY_UPDATE_RENDER);
259 }
260
ResetStepColor()261 void SliderModelNG::ResetStepColor()
262 {
263 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, StepColor, PROPERTY_UPDATE_RENDER);
264 }
265
ResetTrackBorderRadius()266 void SliderModelNG::ResetTrackBorderRadius()
267 {
268 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, TrackBorderRadius, PROPERTY_UPDATE_RENDER);
269 }
270
ResetSelectedBorderRadius()271 void SliderModelNG::ResetSelectedBorderRadius()
272 {
273 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, SelectedBorderRadius, PROPERTY_UPDATE_RENDER);
274 }
275
ResetBlockSize()276 void SliderModelNG::ResetBlockSize()
277 {
278 ACE_RESET_LAYOUT_PROPERTY_WITH_FLAG(SliderLayoutProperty, BlockSize, PROPERTY_UPDATE_MEASURE);
279 }
280
ResetBlockType()281 void SliderModelNG::ResetBlockType()
282 {
283 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockType, PROPERTY_UPDATE_RENDER);
284 }
285
ResetBlockImage()286 void SliderModelNG::ResetBlockImage()
287 {
288 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockImage, PROPERTY_UPDATE_RENDER);
289 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockImageBundleName, PROPERTY_UPDATE_RENDER);
290 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockImageModuleName, PROPERTY_UPDATE_RENDER);
291 }
292
ResetBlockShape()293 void SliderModelNG::ResetBlockShape()
294 {
295 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockShape, PROPERTY_UPDATE_RENDER);
296 }
297
ResetStepSize()298 void SliderModelNG::ResetStepSize()
299 {
300 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, StepSize, PROPERTY_UPDATE_RENDER);
301 }
302
ResetSliderInteractionMode()303 void SliderModelNG::ResetSliderInteractionMode()
304 {
305 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, SliderInteractionMode, PROPERTY_UPDATE_RENDER);
306 }
307
ResetMinResponsiveDistance()308 void SliderModelNG::ResetMinResponsiveDistance()
309 {
310 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, MinResponsiveDistance, PROPERTY_UPDATE_RENDER);
311 }
312
ResetValidSlideRange()313 void SliderModelNG::ResetValidSlideRange()
314 {
315 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, ValidSlideRange, PROPERTY_UPDATE_RENDER);
316 }
317
318 #ifdef SUPPORT_DIGITAL_CROWN
ResetDigitalCrownSensitivity()319 void SliderModelNG::ResetDigitalCrownSensitivity()
320 {
321 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, DigitalCrownSensitivity, PROPERTY_UPDATE_RENDER);
322 }
323
ResetDigitalCrownSensitivity(FrameNode * frameNode)324 void SliderModelNG::ResetDigitalCrownSensitivity(FrameNode* frameNode)
325 {
326 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
327 SliderPaintProperty, DigitalCrownSensitivity, PROPERTY_UPDATE_RENDER, frameNode);
328 }
329 #endif
330
SetShowTips(FrameNode * frameNode,bool value,const std::optional<std::string> & content)331 void SliderModelNG::SetShowTips(FrameNode* frameNode, bool value, const std::optional<std::string>& content)
332 {
333 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, ShowTips, value, frameNode);
334 if (content.has_value()) {
335 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, CustomContent, content.value(), frameNode);
336 } else {
337 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, CustomContent, PROPERTY_UPDATE_RENDER, frameNode);
338 }
339 }
340
SetThickness(FrameNode * frameNode,const Dimension & value)341 void SliderModelNG::SetThickness(FrameNode* frameNode, const Dimension& value)
342 {
343 if (value.IsNonPositive()) {
344 CHECK_NULL_VOID(frameNode);
345 auto layoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
346 CHECK_NULL_VOID(layoutProperty);
347 auto pipeline = frameNode->GetContext();
348 CHECK_NULL_VOID(pipeline);
349 auto theme = pipeline->GetTheme<SliderTheme>();
350 CHECK_NULL_VOID(theme);
351 auto sliderMode = layoutProperty->GetSliderModeValue(SliderModel::SliderMode::OUTSET);
352 Dimension themeTrackThickness;
353 if (sliderMode == SliderModel::SliderMode::OUTSET) {
354 themeTrackThickness = theme->GetOutsetTrackThickness();
355 } else if (sliderMode == SliderModel::SliderMode::INSET) {
356 themeTrackThickness = theme->GetInsetTrackThickness();
357 } else {
358 themeTrackThickness = theme->GetNoneTrackThickness();
359 }
360 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SliderLayoutProperty, Thickness, themeTrackThickness, frameNode);
361 } else {
362 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SliderLayoutProperty, Thickness, value, frameNode);
363 }
364 }
SetStepSize(FrameNode * frameNode,const Dimension & value)365 void SliderModelNG::SetStepSize(FrameNode* frameNode, const Dimension& value)
366 {
367 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, StepSize, value, frameNode);
368 }
SetBlockType(FrameNode * frameNode,BlockStyleType value)369 void SliderModelNG::SetBlockType(FrameNode* frameNode, BlockStyleType value)
370 {
371 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockType, value, frameNode);
372 }
SetBlockShape(FrameNode * frameNode,const RefPtr<BasicShape> & value)373 void SliderModelNG::SetBlockShape(FrameNode* frameNode, const RefPtr<BasicShape>& value)
374 {
375 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockShape, value, frameNode);
376 }
SetBlockSize(FrameNode * frameNode,const Dimension & width,const Dimension & height)377 void SliderModelNG::SetBlockSize(FrameNode* frameNode, const Dimension& width, const Dimension& height)
378 {
379 CHECK_NULL_VOID(frameNode);
380 auto layoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
381 CHECK_NULL_VOID(layoutProperty);
382 auto pipeline = frameNode->GetContext();
383 CHECK_NULL_VOID(pipeline);
384 SizeT<Dimension> blockSize;
385 auto theme = pipeline->GetTheme<SliderTheme>();
386 if (theme != nullptr) {
387 auto mode = layoutProperty->GetSliderModeValue(SliderMode::OUTSET);
388 auto themeBlockSize = mode == SliderMode::OUTSET ? theme->GetOutsetBlockSize() : theme->GetInsetBlockSize();
389 blockSize = layoutProperty->GetBlockSizeValue(SizeT<Dimension>(themeBlockSize, themeBlockSize));
390 }
391
392 if (LessOrEqual(width.Value(), 0.0) || LessOrEqual(height.Value(), 0.0)) {
393 ResetBlockSize(frameNode);
394 } else {
395 blockSize.SetWidth(width);
396 blockSize.SetHeight(height);
397 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SliderLayoutProperty, BlockSize, blockSize, frameNode);
398 }
399 }
SetTrackBorderRadius(FrameNode * frameNode,const Dimension & value)400 void SliderModelNG::SetTrackBorderRadius(FrameNode* frameNode, const Dimension& value)
401 {
402 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, TrackBorderRadius, value, frameNode);
403 }
SetStepColor(FrameNode * frameNode,const Color & value)404 void SliderModelNG::SetStepColor(FrameNode* frameNode, const Color& value)
405 {
406 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, StepColor, value, frameNode);
407 }
SetBlockBorderColor(FrameNode * frameNode,const Color & value)408 void SliderModelNG::SetBlockBorderColor(FrameNode* frameNode, const Color& value)
409 {
410 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockBorderColor, value, frameNode);
411 }
SetBlockBorderWidth(FrameNode * frameNode,const Dimension & value)412 void SliderModelNG::SetBlockBorderWidth(FrameNode* frameNode, const Dimension& value)
413 {
414 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockBorderWidth, value, frameNode);
415 }
SetBlockColor(FrameNode * frameNode,const Color & value)416 void SliderModelNG::SetBlockColor(FrameNode* frameNode, const Color& value)
417 {
418 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockColor, value, frameNode);
419 }
SetTrackBackgroundColor(FrameNode * frameNode,const Gradient & value,bool isResourceColor)420 void SliderModelNG::SetTrackBackgroundColor(FrameNode* frameNode, const Gradient& value, bool isResourceColor)
421 {
422 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, TrackBackgroundColor, value, frameNode);
423 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, TrackBackgroundIsResourceColor, isResourceColor, frameNode);
424 }
SetSelectColor(FrameNode * frameNode,const Gradient & value,bool isResourceColor)425 void SliderModelNG::SetSelectColor(FrameNode* frameNode, const Gradient& value, bool isResourceColor)
426 {
427 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, SelectGradientColor, value, frameNode);
428 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, SelectIsResourceColor, isResourceColor, frameNode);
429 }
SetShowSteps(FrameNode * frameNode,bool value)430 void SliderModelNG::SetShowSteps(FrameNode* frameNode, bool value)
431 {
432 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, ShowSteps, value, frameNode);
433 }
SetSliderInteractionMode(FrameNode * frameNode,SliderInteraction mode)434 void SliderModelNG::SetSliderInteractionMode(FrameNode* frameNode, SliderInteraction mode)
435 {
436 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, SliderInteractionMode, mode, frameNode);
437 }
SetMinResponsiveDistance(FrameNode * frameNode,float value)438 void SliderModelNG::SetMinResponsiveDistance(FrameNode* frameNode, float value)
439 {
440 CHECK_NULL_VOID(frameNode);
441 auto layoutProperty = frameNode->GetPaintProperty<SliderPaintProperty>();
442 CHECK_NULL_VOID(layoutProperty);
443 auto minResponse = 0.0f;
444 auto minValue = layoutProperty->GetMinValue(0.0f);
445 auto maxValue = layoutProperty->GetMaxValue(100.0f);
446 auto diff = maxValue - minValue;
447 if (LessOrEqual(value, diff) && GreatOrEqual(value, minResponse)) {
448 minResponse = value;
449 }
450 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, MinResponsiveDistance, minResponse, frameNode);
451 }
452
453 #ifdef SUPPORT_DIGITAL_CROWN
SetDigitalCrownSensitivity(FrameNode * frameNode,CrownSensitivity sensitivity)454 void SliderModelNG::SetDigitalCrownSensitivity(FrameNode* frameNode, CrownSensitivity sensitivity)
455 {
456 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, DigitalCrownSensitivity, sensitivity, frameNode);
457 }
458 #endif
459
SetBlockImage(FrameNode * frameNode,const std::string & value,const std::string & bundleName,const std::string & moduleName)460 void SliderModelNG::SetBlockImage(
461 FrameNode* frameNode, const std::string& value, const std::string& bundleName, const std::string& moduleName)
462 {
463 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockImage, value, frameNode);
464 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockImageBundleName, bundleName, frameNode);
465 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockImageModuleName, moduleName, frameNode);
466 }
467
ResetStepSize(FrameNode * frameNode)468 void SliderModelNG::ResetStepSize(FrameNode* frameNode)
469 {
470 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, StepSize, PROPERTY_UPDATE_RENDER, frameNode);
471 }
472
ResetBlockType(FrameNode * frameNode)473 void SliderModelNG::ResetBlockType(FrameNode* frameNode)
474 {
475 ACE_RESET_NODE_PAINT_PROPERTY(SliderPaintProperty, BlockType, frameNode);
476 }
477
ResetBlockShape(FrameNode * frameNode)478 void SliderModelNG::ResetBlockShape(FrameNode* frameNode)
479 {
480 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockShape, PROPERTY_UPDATE_RENDER, frameNode);
481 }
482
ResetBlockSize(FrameNode * frameNode)483 void SliderModelNG::ResetBlockSize(FrameNode* frameNode)
484 {
485 ACE_RESET_NODE_LAYOUT_PROPERTY_WITH_FLAG(SliderLayoutProperty, BlockSize, PROPERTY_UPDATE_MEASURE, frameNode);
486 }
487
ResetTrackBorderRadius(FrameNode * frameNode)488 void SliderModelNG::ResetTrackBorderRadius(FrameNode* frameNode)
489 {
490 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, TrackBorderRadius, PROPERTY_UPDATE_RENDER, frameNode);
491 }
492
ResetStepColor(FrameNode * frameNode)493 void SliderModelNG::ResetStepColor(FrameNode* frameNode)
494 {
495 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, StepColor, PROPERTY_UPDATE_RENDER, frameNode);
496 }
497
ResetBlockBorderColor(FrameNode * frameNode)498 void SliderModelNG::ResetBlockBorderColor(FrameNode* frameNode)
499 {
500 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockBorderColor, PROPERTY_UPDATE_RENDER, frameNode);
501 }
502
ResetBlockBorderWidth(FrameNode * frameNode)503 void SliderModelNG::ResetBlockBorderWidth(FrameNode* frameNode)
504 {
505 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockBorderWidth, PROPERTY_UPDATE_RENDER, frameNode);
506 }
507
ResetBlockColor(FrameNode * frameNode)508 void SliderModelNG::ResetBlockColor(FrameNode* frameNode)
509 {
510 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, BlockColor, PROPERTY_UPDATE_RENDER, frameNode);
511 }
512
ResetBlockImage(FrameNode * frameNode)513 void SliderModelNG::ResetBlockImage(FrameNode* frameNode)
514 {
515 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
516 SliderPaintProperty, BlockImage, PROPERTY_UPDATE_RENDER, frameNode);
517 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
518 SliderPaintProperty, BlockImageBundleName, PROPERTY_UPDATE_RENDER, frameNode);
519 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
520 SliderPaintProperty, BlockImageModuleName, PROPERTY_UPDATE_RENDER, frameNode);
521 }
522
ResetValidSlideRange(FrameNode * frameNode)523 void SliderModelNG::ResetValidSlideRange(FrameNode* frameNode)
524 {
525 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(SliderPaintProperty, ValidSlideRange, PROPERTY_UPDATE_RENDER, frameNode);
526 }
527
CreateFrameNode(int32_t nodeId)528 RefPtr<FrameNode> SliderModelNG::CreateFrameNode(int32_t nodeId)
529 {
530 auto frameNode = FrameNode::GetOrCreateFrameNode(
531 V2::SLIDER_ETS_TAG, nodeId, []() { return AceType::MakeRefPtr<SliderPattern>(); });
532
533 SetMinLabel(AceType::RawPtr(frameNode), DEFAULT_MIN_VALUE);
534 SetMaxLabel(AceType::RawPtr(frameNode), DEFAULT_MAX_VALUE);
535 SetStep(AceType::RawPtr(frameNode), DEFAULT_STEP);
536 SetSliderValue(AceType::RawPtr(frameNode), DEFAULT_MIN_VALUE);
537
538 return frameNode;
539 }
540
SetOnChange(FrameNode * frameNode,SliderOnChangeEvent && eventOnChange)541 void SliderModelNG::SetOnChange(FrameNode* frameNode, SliderOnChangeEvent&& eventOnChange)
542 {
543 CHECK_NULL_VOID(frameNode);
544 auto eventHub = frameNode->GetEventHub<SliderEventHub>();
545 CHECK_NULL_VOID(eventHub);
546 eventHub->SetOnChange(std::move(eventOnChange));
547 }
548
SetSliderValue(FrameNode * frameNode,float value)549 void SliderModelNG::SetSliderValue(FrameNode* frameNode, float value)
550 {
551 CHECK_NULL_VOID(frameNode);
552 auto pattern = frameNode->GetPattern<SliderPattern>();
553 CHECK_NULL_VOID(pattern);
554 pattern->UpdateValue(value);
555 }
556
SetMinLabel(FrameNode * frameNode,float value)557 void SliderModelNG::SetMinLabel(FrameNode* frameNode, float value)
558 {
559 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, Min, value, frameNode);
560 }
SetMaxLabel(FrameNode * frameNode,float value)561 void SliderModelNG::SetMaxLabel(FrameNode* frameNode, float value)
562 {
563 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, Max, value, frameNode);
564 }
565
SetSliderMode(FrameNode * frameNode,const SliderMode & value)566 void SliderModelNG::SetSliderMode(FrameNode* frameNode, const SliderMode& value)
567 {
568 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SliderLayoutProperty, SliderMode, value, frameNode);
569 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, SliderMode, value, frameNode);
570 }
SetDirection(FrameNode * frameNode,Axis value)571 void SliderModelNG::SetDirection(FrameNode* frameNode, Axis value)
572 {
573 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SliderLayoutProperty, Direction, value, frameNode);
574 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, Direction, value, frameNode);
575 }
SetReverse(FrameNode * frameNode,bool value)576 void SliderModelNG::SetReverse(FrameNode* frameNode, bool value)
577 {
578 ACE_UPDATE_NODE_LAYOUT_PROPERTY(SliderLayoutProperty, Reverse, value, frameNode);
579 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, Reverse, value, frameNode);
580 }
SetStep(FrameNode * frameNode,float value)581 void SliderModelNG::SetStep(FrameNode* frameNode, float value)
582 {
583 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, Step, value, frameNode);
584 }
585
SetValidSlideRange(FrameNode * frameNode,float from,float to)586 void SliderModelNG::SetValidSlideRange(FrameNode* frameNode, float from, float to)
587 {
588 if (std::isnan(from) || std::isnan(to)) {
589 return SliderModelNG::ResetValidSlideRange(frameNode);
590 }
591 CHECK_NULL_VOID(frameNode);
592 auto paintProperty = frameNode->GetPaintProperty<SliderPaintProperty>();
593 CHECK_NULL_VOID(paintProperty);
594 auto minValue = paintProperty->GetMinValue(0.0f);
595 auto maxValue = paintProperty->GetMaxValue(100.0f);
596 auto step = paintProperty->GetStepValue(1.0f);
597 float fromValue = minValue;
598 float toValue = maxValue;
599 if (std::isfinite(from)) {
600 fromValue = from;
601 }
602 if (std::isfinite(to)) {
603 toValue = to;
604 }
605 if (GreatOrEqual(fromValue, minValue) && LessOrEqual(toValue, maxValue) && LessOrEqual(fromValue, toValue) &&
606 GreatNotEqual(step, 0.0f)) {
607 auto toValueCorrection = NearEqual(toValue - step * std::floor(toValue / step), 0) ? 0 : 1;
608 fromValue = LessOrEqual(fromValue, minValue) ? minValue : std::floor(fromValue / step) * step;
609 toValue = GreatOrEqual(toValue, maxValue) ?
610 maxValue : (std::floor(toValue / step) + toValueCorrection) * step;
611 auto sliderValue = std::clamp(paintProperty->GetValueValue(fromValue), fromValue, toValue);
612 RefPtr<SliderModel::SliderValidRange> rangeValue =
613 AceType::MakeRefPtr<SliderModel::SliderValidRange>(fromValue, toValue);
614 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, Value, sliderValue, frameNode);
615 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, ValidSlideRange, rangeValue, frameNode);
616 } else {
617 SliderModelNG::ResetValidSlideRange(frameNode);
618 }
619 }
620
GetBlockColor(FrameNode * frameNode)621 Color SliderModelNG::GetBlockColor(FrameNode* frameNode)
622 {
623 Color value;
624 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
625 SliderPaintProperty, BlockColor, value, frameNode, Color(BLOCK_COLOR));
626 return value;
627 }
628
GetTrackBackgroundColor(FrameNode * frameNode)629 Gradient SliderModelNG::GetTrackBackgroundColor(FrameNode* frameNode)
630 {
631 Gradient value;
632 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
633 SliderPaintProperty, TrackBackgroundColor, value, frameNode,
634 SliderModelNG::CreateSolidGradient(Color(TRACK_COLOR)));
635 return value;
636 }
637
GetSelectColor(FrameNode * frameNode)638 Gradient SliderModelNG::GetSelectColor(FrameNode* frameNode)
639 {
640 Gradient value;
641 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
642 SliderPaintProperty, SelectGradientColor, value, frameNode,
643 SliderModelNG::CreateSolidGradient(Color(SELECTED_COLOR)));
644 return value;
645 }
646
GetShowSteps(FrameNode * frameNode)647 bool SliderModelNG::GetShowSteps(FrameNode* frameNode)
648 {
649 bool value = false;
650 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
651 SliderPaintProperty, ShowSteps, value, frameNode, false);
652 return value;
653 }
654
GetBlockType(FrameNode * frameNode)655 SliderModel::BlockStyleType SliderModelNG::GetBlockType(FrameNode* frameNode)
656 {
657 SliderModel::BlockStyleType value = SliderModel::BlockStyleType::DEFAULT;
658 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
659 SliderPaintProperty, BlockType, value, frameNode, SliderModel::BlockStyleType::DEFAULT);
660 return value;
661 }
662
GetSliderValue(FrameNode * frameNode)663 float SliderModelNG::GetSliderValue(FrameNode* frameNode)
664 {
665 float value = DEFAULT_MIN_VALUE;
666 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
667 SliderPaintProperty, Value, value, frameNode, DEFAULT_MIN_VALUE);
668 return value;
669 }
670
GetMinLabel(FrameNode * frameNode)671 float SliderModelNG::GetMinLabel(FrameNode* frameNode)
672 {
673 float value = DEFAULT_MIN_VALUE;
674 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
675 SliderPaintProperty, Min, value, frameNode, DEFAULT_MIN_VALUE);
676 return value;
677 }
GetMaxLabel(FrameNode * frameNode)678 float SliderModelNG::GetMaxLabel(FrameNode* frameNode)
679 {
680 float value = DEFAULT_MAX_VALUE;
681 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
682 SliderPaintProperty, Max, value, frameNode, DEFAULT_MAX_VALUE);
683 return value;
684 }
685
GetSliderMode(FrameNode * frameNode)686 SliderModel::SliderMode SliderModelNG::GetSliderMode(FrameNode* frameNode)
687 {
688 SliderModel::SliderMode value = SliderModel::SliderMode::OUTSET;
689 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
690 SliderPaintProperty, SliderMode, value, frameNode, SliderModel::SliderMode::OUTSET);
691 return value;
692 }
GetDirection(FrameNode * frameNode)693 OHOS::Ace::Axis SliderModelNG::GetDirection(FrameNode* frameNode)
694 {
695 OHOS::Ace::Axis value = OHOS::Ace::Axis::HORIZONTAL;
696 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
697 SliderPaintProperty, Direction, value, frameNode, OHOS::Ace::Axis::HORIZONTAL);
698 return value;
699 }
GetReverse(FrameNode * frameNode)700 bool SliderModelNG::GetReverse(FrameNode* frameNode)
701 {
702 bool value = false;
703 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
704 SliderPaintProperty, Reverse, value, frameNode, false);
705 return value;
706 }
GetStep(FrameNode * frameNode)707 float SliderModelNG::GetStep(FrameNode* frameNode)
708 {
709 float value = DEFAULT_STEP;
710 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
711 SliderPaintProperty, Step, value, frameNode, DEFAULT_STEP);
712 return value;
713 }
714
GetBlockImageValue(FrameNode * frameNode)715 std::string SliderModelNG::GetBlockImageValue(FrameNode* frameNode)
716 {
717 std::string value = "";
718 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
719 SliderPaintProperty, BlockImage, value, frameNode, value);
720 return value;
721 }
722
GetBlockShape(FrameNode * frameNode)723 RefPtr<BasicShape> SliderModelNG::GetBlockShape(FrameNode* frameNode)
724 {
725 RefPtr<BasicShape> value = AceType::MakeRefPtr<BasicShape>();
726 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(SliderPaintProperty, BlockShape, value, frameNode, value);
727 return value;
728 }
729
GetValidSlideRange(FrameNode * frameNode)730 RefPtr<SliderModel::SliderValidRange> SliderModelNG::GetValidSlideRange(FrameNode* frameNode)
731 {
732 RefPtr<SliderModel::SliderValidRange> value = AceType::MakeRefPtr<SliderModel::SliderValidRange>();
733 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(SliderPaintProperty, ValidSlideRange, value, frameNode, value);
734 return value;
735 }
736
737 #ifdef SUPPORT_DIGITAL_CROWN
GetDigitalCrownSensitivity(FrameNode * frameNode)738 CrownSensitivity SliderModelNG::GetDigitalCrownSensitivity(FrameNode* frameNode)
739 {
740 CrownSensitivity sensitivity = CrownSensitivity::MEDIUM;
741 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
742 SliderPaintProperty, DigitalCrownSensitivity, sensitivity, frameNode, sensitivity);
743 return sensitivity;
744 }
745 #endif
746
CreateSolidGradient(Color value)747 Gradient SliderModelNG::CreateSolidGradient(Color value)
748 {
749 Gradient gradient;
750 GradientColor gradientColorBegin;
751 gradientColorBegin.SetLinearColor(LinearColor(value));
752 gradientColorBegin.SetDimension(Dimension(0.0f));
753 gradient.AddColor(gradientColorBegin);
754 OHOS::Ace::NG::GradientColor gradientColorEnd;
755 gradientColorEnd.SetLinearColor(LinearColor(value));
756 gradientColorEnd.SetDimension(Dimension(1.0f));
757 gradient.AddColor(gradientColorEnd);
758 return gradient;
759 }
760
SetBuilderFunc(FrameNode * frameNode,SliderMakeCallback && makeFunc)761 void SliderModelNG::SetBuilderFunc(FrameNode* frameNode, SliderMakeCallback&& makeFunc)
762 {
763 CHECK_NULL_VOID(frameNode);
764 auto pattern = frameNode->GetPattern<SliderPattern>();
765 CHECK_NULL_VOID(pattern);
766 pattern->SetBuilderFunc(std::move(makeFunc));
767 }
768
SetChangeValue(FrameNode * frameNode,double value,int32_t mode)769 void SliderModelNG::SetChangeValue(FrameNode* frameNode, double value, int32_t mode)
770 {
771 auto pattern = frameNode->GetPattern<SliderPattern>();
772 CHECK_NULL_VOID(pattern);
773 pattern->SetSliderValue(value, mode);
774 }
775
GetEnableHapticFeedback(FrameNode * frameNode)776 bool SliderModelNG::GetEnableHapticFeedback(FrameNode* frameNode)
777 {
778 CHECK_NULL_RETURN(frameNode, true);
779 auto sliderPattern = frameNode->GetPattern<SliderPattern>();
780 CHECK_NULL_RETURN(sliderPattern, true);
781 return sliderPattern->GetEnableHapticFeedback();
782 }
783
SetEnableHapticFeedback(bool isEnableHapticFeedback)784 void SliderModelNG::SetEnableHapticFeedback(bool isEnableHapticFeedback)
785 {
786 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
787 CHECK_NULL_VOID(frameNode);
788 SetEnableHapticFeedback(frameNode, isEnableHapticFeedback);
789 }
790
SetEnableHapticFeedback(FrameNode * frameNode,bool isEnableHapticFeedback)791 void SliderModelNG::SetEnableHapticFeedback(FrameNode* frameNode, bool isEnableHapticFeedback)
792 {
793 CHECK_NULL_VOID(frameNode);
794 auto sliderPattern = frameNode->GetPattern<SliderPattern>();
795 CHECK_NULL_VOID(sliderPattern);
796 sliderPattern->SetEnableHapticFeedback(isEnableHapticFeedback);
797 ACE_UPDATE_PAINT_PROPERTY(SliderPaintProperty, EnableHapticFeedback, isEnableHapticFeedback);
798 }
799
GetThickness(FrameNode * frameNode)800 Dimension SliderModelNG::GetThickness(FrameNode* frameNode)
801 {
802 Dimension defaultTrackThickness = Dimension(0.0f);
803 CHECK_NULL_RETURN(frameNode, defaultTrackThickness);
804 auto layoutProperty = frameNode->GetLayoutProperty<SliderLayoutProperty>();
805 CHECK_NULL_RETURN(layoutProperty, defaultTrackThickness);
806 auto pipeline = frameNode->GetContext();
807 CHECK_NULL_RETURN(pipeline, defaultTrackThickness);
808 auto theme = pipeline->GetTheme<SliderTheme>();
809 CHECK_NULL_RETURN(theme, defaultTrackThickness);
810 auto sliderMode = layoutProperty->GetSliderModeValue(SliderModel::SliderMode::OUTSET);
811 if (sliderMode == SliderModel::SliderMode::OUTSET) {
812 defaultTrackThickness = theme->GetOutsetTrackThickness();
813 } else if (sliderMode == SliderModel::SliderMode::INSET) {
814 defaultTrackThickness = theme->GetInsetTrackThickness();
815 } else {
816 defaultTrackThickness = theme->GetNoneTrackThickness();
817 }
818
819 Dimension trackThickness = Dimension(0.0f);
820 ACE_GET_NODE_LAYOUT_PROPERTY_WITH_DEFAULT_VALUE(
821 SliderLayoutProperty, Thickness, trackThickness, frameNode, defaultTrackThickness);
822 return trackThickness;
823 }
824
SetSelectedBorderRadius(FrameNode * frameNode,const Dimension & value)825 void SliderModelNG::SetSelectedBorderRadius(FrameNode* frameNode, const Dimension& value)
826 {
827 ACE_UPDATE_NODE_PAINT_PROPERTY(SliderPaintProperty, SelectedBorderRadius, value, frameNode);
828 }
829
ResetSelectedBorderRadius(FrameNode * frameNode)830 void SliderModelNG::ResetSelectedBorderRadius(FrameNode* frameNode)
831 {
832 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
833 SliderPaintProperty, SelectedBorderRadius, PROPERTY_UPDATE_RENDER, frameNode);
834 }
835
ResetSliderInteractionMode(FrameNode * frameNode)836 void SliderModelNG::ResetSliderInteractionMode(FrameNode* frameNode)
837 {
838 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
839 SliderPaintProperty, SliderInteractionMode, PROPERTY_UPDATE_RENDER, frameNode);
840 }
841
ResetMinResponsiveDistance(FrameNode * frameNode)842 void SliderModelNG::ResetMinResponsiveDistance(FrameNode* frameNode)
843 {
844 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
845 SliderPaintProperty, MinResponsiveDistance, PROPERTY_UPDATE_RENDER, frameNode);
846 }
847 } // namespace OHOS::Ace::NG
848