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/checkbox/checkbox_model_ng.h"
17
18 #include "core/common/resource/resource_parse_utils.h"
19 #include "core/components/checkable/checkable_theme.h"
20 #include "core/components_ng/base/view_abstract.h"
21 #include "core/components_ng/pattern/checkbox/checkbox_pattern.h"
22 #include "core/pipeline_ng/pipeline_context.h"
23
24 namespace OHOS::Ace::NG {
25 constexpr float CHECK_BOX_MARK_SIZE_INVALID_VALUE = -1.0f;
26
Create(const std::optional<std::string> & name,const std::optional<std::string> & groupName,const std::string & tagName)27 void CheckBoxModelNG::Create(
28 const std::optional<std::string>& name, const std::optional<std::string>& groupName, const std::string& tagName)
29 {
30 auto* stack = ViewStackProcessor::GetInstance();
31 CHECK_NULL_VOID(stack);
32 int32_t nodeId = stack->ClaimNodeId();
33 ACE_LAYOUT_SCOPED_TRACE("Create[%s][self:%d]", tagName.c_str(), nodeId);
34 auto frameNode =
35 FrameNode::GetOrCreateFrameNode(tagName, nodeId, []() { return AceType::MakeRefPtr<CheckBoxPattern>(); });
36 ViewStackProcessor::GetInstance()->Push(frameNode);
37 CHECK_NULL_VOID(frameNode);
38 auto eventHub = frameNode->GetOrCreateEventHub<NG::CheckBoxEventHub>();
39 CHECK_NULL_VOID(eventHub);
40 if (name.has_value()) {
41 eventHub->SetName(name.value());
42 }
43 if (groupName.has_value()) {
44 eventHub->SetGroupName(groupName.value());
45 }
46 }
47
CreateFrameNode(int32_t nodeId)48 RefPtr<FrameNode> CheckBoxModelNG::CreateFrameNode(int32_t nodeId)
49 {
50 auto frameNode = FrameNode::CreateFrameNode(V2::CHECK_BOX_ETS_TAG, nodeId, AceType::MakeRefPtr<CheckBoxPattern>());
51 CHECK_NULL_RETURN(frameNode, nullptr);
52 return frameNode;
53 }
54
SetSelect(bool isSelected)55 void CheckBoxModelNG::SetSelect(bool isSelected)
56 {
57 auto* stack = ViewStackProcessor::GetInstance();
58 CHECK_NULL_VOID(stack);
59 const auto& frameNode = stack->GetMainFrameNode();
60 CHECK_NULL_VOID(frameNode);
61 auto eventHub = frameNode->GetOrCreateEventHub<CheckBoxEventHub>();
62 CHECK_NULL_VOID(eventHub);
63 eventHub->SetCurrentUIState(UI_STATE_SELECTED, isSelected);
64
65 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelect, isSelected, frameNode);
66 }
67
SetSelectedColor(const Color & color)68 void CheckBoxModelNG::SetSelectedColor(const Color& color)
69 {
70 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedColor, color);
71 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedColorFlagByUser, true);
72 }
73
SetUnSelectedColor(const Color & color)74 void CheckBoxModelNG::SetUnSelectedColor(const Color& color)
75 {
76 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxUnSelectedColor, color);
77 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxUnSelectedColorFlagByUser, true);
78 }
79
SetBuilder(std::optional<std::function<void (void)>> & buildFunc)80 void CheckBoxModelNG::SetBuilder(std::optional<std::function<void(void)>>& buildFunc)
81 {
82 auto* stack = ViewStackProcessor::GetInstance();
83 CHECK_NULL_VOID(stack);
84 const auto& frameNode = stack->GetMainFrameNode();
85 CHECK_NULL_VOID(frameNode);
86 auto checkBoxPattern = frameNode->GetPattern<CheckBoxPattern>();
87 CHECK_NULL_VOID(checkBoxPattern);
88 checkBoxPattern->SetIndicatorBuilder(buildFunc);
89 }
90
SetCheckboxStyle(CheckBoxStyle checkboxStyle)91 void CheckBoxModelNG::SetCheckboxStyle(CheckBoxStyle checkboxStyle)
92 {
93 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedStyle, checkboxStyle);
94 }
95
SetCheckMarkColor(const Color & color)96 void CheckBoxModelNG::SetCheckMarkColor(const Color& color)
97 {
98 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkColor, color);
99 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkColorFlagByUser, true);
100 }
101
SetCheckMarkSize(const Dimension & size)102 void CheckBoxModelNG::SetCheckMarkSize(const Dimension& size)
103 {
104 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkSize, size);
105 }
106
SetCheckMarkWidth(const Dimension & width)107 void CheckBoxModelNG::SetCheckMarkWidth(const Dimension& width)
108 {
109 ACE_UPDATE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkWidth, width);
110 }
111
SetOnChange(ChangeEvent && onChange)112 void CheckBoxModelNG::SetOnChange(ChangeEvent&& onChange)
113 {
114 auto* stack = ViewStackProcessor::GetInstance();
115 CHECK_NULL_VOID(stack);
116 auto frameNode = stack->GetMainFrameNode();
117 CHECK_NULL_VOID(frameNode);
118 auto eventHub = frameNode->GetOrCreateEventHub<CheckBoxEventHub>();
119 CHECK_NULL_VOID(eventHub);
120 eventHub->SetOnChange(std::move(onChange));
121 }
122
SetWidth(const Dimension & width)123 void CheckBoxModelNG::SetWidth(const Dimension& width)
124 {
125 NG::ViewAbstract::SetWidth(NG::CalcLength(width));
126 }
127
SetHeight(const Dimension & height)128 void CheckBoxModelNG::SetHeight(const Dimension& height)
129 {
130 NG::ViewAbstract::SetHeight(NG::CalcLength(height));
131 }
132
SetPadding(const NG::PaddingPropertyF & args,const NG::PaddingProperty & newArgs,bool flag)133 void CheckBoxModelNG::SetPadding(const NG::PaddingPropertyF& args, const NG::PaddingProperty& newArgs, bool flag)
134 {
135 NG::ViewAbstract::SetPadding(newArgs);
136 }
137
SetChangeEvent(ChangeEvent && changeEvent)138 void CheckBoxModelNG::SetChangeEvent(ChangeEvent&& changeEvent)
139 {
140 auto* stack = ViewStackProcessor::GetInstance();
141 CHECK_NULL_VOID(stack);
142 auto frameNode = stack->GetMainFrameNode();
143 CHECK_NULL_VOID(frameNode);
144 auto eventHub = frameNode->GetOrCreateEventHub<CheckBoxEventHub>();
145 CHECK_NULL_VOID(eventHub);
146 eventHub->SetChangeEvent(std::move(changeEvent));
147 }
148
SetResponseRegion(const std::vector<DimensionRect> & responseRegion)149 void CheckBoxModelNG::SetResponseRegion(const std::vector<DimensionRect>& responseRegion)
150 {
151 NG::ViewAbstract::SetResponseRegion(responseRegion);
152 auto* stack = ViewStackProcessor::GetInstance();
153 CHECK_NULL_VOID(stack);
154 auto frameNode = stack->GetMainFrameNode();
155 CHECK_NULL_VOID(frameNode);
156 auto pattern = frameNode->GetPattern<CheckBoxPattern>();
157 CHECK_NULL_VOID(pattern);
158 pattern->SetIsUserSetResponseRegion(true);
159 }
160
SetSelect(FrameNode * frameNode,bool isSelected)161 void CheckBoxModelNG::SetSelect(FrameNode* frameNode, bool isSelected)
162 {
163 CHECK_NULL_VOID(frameNode);
164 auto eventHub = frameNode->GetOrCreateEventHub<CheckBoxEventHub>();
165 CHECK_NULL_VOID(eventHub);
166 eventHub->SetCurrentUIState(UI_STATE_SELECTED, isSelected);
167 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelect, isSelected, frameNode);
168 }
169
SetSelectedColor(FrameNode * frameNode,const Color & color)170 void CheckBoxModelNG::SetSelectedColor(FrameNode* frameNode, const Color& color)
171 {
172 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedColor, color, frameNode);
173 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedColorFlagByUser, true, frameNode);
174 }
175
SetSelectedColorFlagByUser(FrameNode * frameNode,const bool isByUser)176 void CheckBoxModelNG::SetSelectedColorFlagByUser(FrameNode* frameNode, const bool isByUser)
177 {
178 CHECK_NULL_VOID(frameNode);
179 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedColorFlagByUser, isByUser, frameNode);
180 }
181
SetUnSelectedColor(FrameNode * frameNode,const Color & color)182 void CheckBoxModelNG::SetUnSelectedColor(FrameNode* frameNode, const Color& color)
183 {
184 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxUnSelectedColor, color, frameNode);
185 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxUnSelectedColorFlagByUser, true, frameNode);
186 }
187
SetCheckMarkColor(FrameNode * frameNode,const Color & color)188 void CheckBoxModelNG::SetCheckMarkColor(FrameNode* frameNode, const Color& color)
189 {
190 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkColor, color, frameNode);
191 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkColorFlagByUser, true, frameNode);
192 }
193
SetCheckMarkSize(FrameNode * frameNode,const Dimension & size)194 void CheckBoxModelNG::SetCheckMarkSize(FrameNode* frameNode, const Dimension& size)
195 {
196 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkSize, size, frameNode);
197 }
198
SetCheckMarkWidth(FrameNode * frameNode,const Dimension & width)199 void CheckBoxModelNG::SetCheckMarkWidth(FrameNode* frameNode, const Dimension& width)
200 {
201 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxCheckMarkWidth, width, frameNode);
202 }
203
SetHeight(FrameNode * frameNode,const Dimension & height)204 void CheckBoxModelNG::SetHeight(FrameNode* frameNode, const Dimension& height)
205 {
206 NG::ViewAbstract::SetHeight(frameNode, NG::CalcLength(height));
207 }
208
SetWidth(FrameNode * frameNode,const Dimension & width)209 void CheckBoxModelNG::SetWidth(FrameNode* frameNode, const Dimension& width)
210 {
211 NG::ViewAbstract::SetWidth(frameNode, NG::CalcLength(width));
212 }
213
SetPadding(FrameNode * frameNode,const NG::PaddingProperty & padding)214 void CheckBoxModelNG::SetPadding(FrameNode* frameNode, const NG::PaddingProperty& padding)
215 {
216 NG::ViewAbstract::SetPadding(frameNode, padding);
217 }
218
SetResponseRegion(FrameNode * frameNode,const std::vector<DimensionRect> & responseRegion)219 void CheckBoxModelNG::SetResponseRegion(FrameNode* frameNode, const std::vector<DimensionRect>& responseRegion)
220 {
221 NG::ViewAbstract::SetResponseRegion(responseRegion);
222 CHECK_NULL_VOID(frameNode);
223 auto pattern = frameNode->GetPattern<CheckBoxPattern>();
224 CHECK_NULL_VOID(pattern);
225 pattern->SetIsUserSetResponseRegion(true);
226 }
227
SetCheckboxStyle(FrameNode * frameNode,CheckBoxStyle checkboxStyle)228 void CheckBoxModelNG::SetCheckboxStyle(FrameNode* frameNode, CheckBoxStyle checkboxStyle)
229 {
230 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedStyle, checkboxStyle, frameNode);
231 }
232
SetCheckboxName(FrameNode * frameNode,const std::optional<std::string> & name)233 void CheckBoxModelNG::SetCheckboxName(FrameNode* frameNode, const std::optional<std::string>& name)
234 {
235 CHECK_NULL_VOID(frameNode);
236 auto eventHub = frameNode->GetOrCreateEventHub<NG::CheckBoxEventHub>();
237 CHECK_NULL_VOID(eventHub);
238 if (name.has_value()) {
239 eventHub->SetName(name.value());
240 }
241 }
242
SetCheckboxGroup(FrameNode * frameNode,const std::optional<std::string> & groupName)243 void CheckBoxModelNG::SetCheckboxGroup(FrameNode* frameNode, const std::optional<std::string>& groupName)
244 {
245 CHECK_NULL_VOID(frameNode);
246 auto eventHub = frameNode->GetOrCreateEventHub<NG::CheckBoxEventHub>();
247 CHECK_NULL_VOID(eventHub);
248 if (groupName.has_value()) {
249 eventHub->SetGroupName(groupName.value());
250 }
251 }
252
GetSelect(FrameNode * frameNode)253 bool CheckBoxModelNG::GetSelect(FrameNode* frameNode)
254 {
255 bool value = false;
256 CHECK_NULL_RETURN(frameNode, value);
257 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(CheckBoxPaintProperty, CheckBoxSelect, value, frameNode, value);
258 return value;
259 }
260
GetSelectedColor(FrameNode * frameNode)261 Color CheckBoxModelNG::GetSelectedColor(FrameNode* frameNode)
262 {
263 Color value;
264 CHECK_NULL_RETURN(frameNode, value);
265 auto pipelineContext = frameNode->GetContext();
266 CHECK_NULL_RETURN(pipelineContext, value);
267 auto theme = pipelineContext->GetTheme<CheckboxTheme>(frameNode->GetThemeScopeId());
268 CHECK_NULL_RETURN(theme, value);
269 value = theme->GetActiveColor();
270 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
271 CheckBoxPaintProperty, CheckBoxSelectedColor, value, frameNode, value);
272 return value;
273 }
274
GetUnSelectedColor(FrameNode * frameNode)275 Color CheckBoxModelNG::GetUnSelectedColor(FrameNode* frameNode)
276 {
277 Color value;
278 CHECK_NULL_RETURN(frameNode, value);
279 auto pipelineContext = frameNode->GetContext();
280 CHECK_NULL_RETURN(pipelineContext, value);
281 auto theme = pipelineContext->GetTheme<CheckboxTheme>(frameNode->GetThemeScopeId());
282 CHECK_NULL_RETURN(theme, value);
283 value = theme->GetInactiveColor();
284 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
285 CheckBoxPaintProperty, CheckBoxUnSelectedColor, value, frameNode, value);
286 return value;
287 }
288
GetCheckMarkColor(FrameNode * frameNode)289 Color CheckBoxModelNG::GetCheckMarkColor(FrameNode* frameNode)
290 {
291 Color value;
292 CHECK_NULL_RETURN(frameNode, value);
293 auto pipelineContext = frameNode->GetContext();
294 CHECK_NULL_RETURN(pipelineContext, value);
295 auto theme = pipelineContext->GetTheme<CheckboxTheme>(frameNode->GetThemeScopeId());
296 CHECK_NULL_RETURN(theme, value);
297 value = theme->GetPointColor();
298 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
299 CheckBoxPaintProperty, CheckBoxCheckMarkColor, value, frameNode, value);
300 return value;
301 }
302
GetCheckMarkSize(FrameNode * frameNode)303 Dimension CheckBoxModelNG::GetCheckMarkSize(FrameNode* frameNode)
304 {
305 Dimension value = Dimension(CHECK_BOX_MARK_SIZE_INVALID_VALUE);
306 CHECK_NULL_RETURN(frameNode, value);
307 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
308 CheckBoxPaintProperty, CheckBoxCheckMarkSize, value, frameNode, value);
309 return value;
310 }
311
GetCheckMarkWidth(FrameNode * frameNode)312 Dimension CheckBoxModelNG::GetCheckMarkWidth(FrameNode* frameNode)
313 {
314 Dimension value;
315 CHECK_NULL_RETURN(frameNode, value);
316 auto pipelineContext = frameNode->GetContext();
317 CHECK_NULL_RETURN(pipelineContext, value);
318 auto theme = pipelineContext->GetTheme<CheckboxTheme>();
319 CHECK_NULL_RETURN(theme, value);
320 value = theme->GetCheckStroke();
321 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
322 CheckBoxPaintProperty, CheckBoxCheckMarkWidth, value, frameNode, value);
323 return value;
324 }
325
GetCheckboxStyle(FrameNode * frameNode)326 CheckBoxStyle CheckBoxModelNG::GetCheckboxStyle(FrameNode* frameNode)
327 {
328 CheckBoxStyle value = CheckBoxStyle::CIRCULAR_STYLE;
329 CHECK_NULL_RETURN(frameNode, value);
330 ACE_GET_NODE_PAINT_PROPERTY_WITH_DEFAULT_VALUE(
331 CheckBoxPaintProperty, CheckBoxSelectedStyle, value, frameNode, value);
332 return value;
333 }
334
SetBuilderFunc(FrameNode * frameNode,NG::CheckBoxMakeCallback && makeFunc)335 void CheckBoxModelNG::SetBuilderFunc(FrameNode* frameNode, NG::CheckBoxMakeCallback&& makeFunc)
336 {
337 CHECK_NULL_VOID(frameNode);
338 auto pattern = frameNode->GetPattern<CheckBoxPattern>();
339 CHECK_NULL_VOID(pattern);
340 pattern->SetBuilderFunc(std::move(makeFunc));
341 }
342
SetChangeValue(FrameNode * frameNode,bool value)343 void CheckBoxModelNG::SetChangeValue(FrameNode* frameNode, bool value)
344 {
345 CHECK_NULL_VOID(frameNode);
346 auto pattern = frameNode->GetPattern<CheckBoxPattern>();
347 CHECK_NULL_VOID(pattern);
348 pattern->SetCheckBoxSelect(value);
349 }
350
SetOnChange(FrameNode * frameNode,ChangeEvent && onChange)351 void CheckBoxModelNG::SetOnChange(FrameNode* frameNode, ChangeEvent&& onChange)
352 {
353 CHECK_NULL_VOID(frameNode);
354 auto eventHub = frameNode->GetOrCreateEventHub<CheckBoxEventHub>();
355 CHECK_NULL_VOID(eventHub);
356 eventHub->SetOnChange(std::move(onChange));
357 }
358
GetCheckboxName(FrameNode * frameNode)359 std::string CheckBoxModelNG::GetCheckboxName(FrameNode* frameNode)
360 {
361 CHECK_NULL_RETURN(frameNode, "");
362 auto eventHub = frameNode->GetOrCreateEventHub<NG::CheckBoxEventHub>();
363 CHECK_NULL_RETURN(eventHub, "");
364 return eventHub->GetName();
365 }
366
GetCheckboxGroup(FrameNode * frameNode)367 std::string CheckBoxModelNG::GetCheckboxGroup(FrameNode* frameNode)
368 {
369 CHECK_NULL_RETURN(frameNode, "");
370 auto eventHub = frameNode->GetOrCreateEventHub<NG::CheckBoxEventHub>();
371 CHECK_NULL_RETURN(eventHub, "");
372 return eventHub->GetGroupName();
373 }
374
CreateWithColorResourceObj(const RefPtr<ResourceObject> & resObj,const CheckBoxColorType checkBoxColorType)375 void CheckBoxModelNG::CreateWithColorResourceObj(
376 const RefPtr<ResourceObject>& resObj, const CheckBoxColorType checkBoxColorType)
377 {
378 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
379 CHECK_NULL_VOID(frameNode);
380 CreateWithResourceObj(frameNode, checkBoxColorType, resObj);
381 }
382
ResetComponentColor(FrameNode * frameNode,const CheckBoxColorType type)383 void CheckBoxModelNG::ResetComponentColor(FrameNode* frameNode, const CheckBoxColorType type)
384 {
385 CHECK_NULL_VOID(frameNode);
386 auto pipelineContext = frameNode->GetContext();
387 CHECK_NULL_VOID(pipelineContext);
388 auto theme = pipelineContext->GetTheme<CheckboxTheme>(frameNode->GetThemeScopeId());
389 CHECK_NULL_VOID(theme);
390 Color color;
391 switch (type) {
392 case CheckBoxColorType::SELECTED_COLOR:
393 ResetSelectedColor(frameNode);
394 color = theme->GetActiveColor();
395 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxSelectedColor, color, frameNode);
396 break;
397 case CheckBoxColorType::UN_SELECTED_COLOR:
398 ResetUnSelectedColor(frameNode);
399 color = theme->GetInactiveColor();
400 ACE_UPDATE_NODE_PAINT_PROPERTY(CheckBoxPaintProperty, CheckBoxUnSelectedColor, color, frameNode);
401 break;
402 default:
403 break;
404 }
405 }
406
UpdateComponentColor(FrameNode * frameNode,const CheckBoxColorType type,const Color & color)407 void CheckBoxModelNG::UpdateComponentColor(FrameNode* frameNode, const CheckBoxColorType type, const Color& color)
408 {
409 CHECK_NULL_VOID(frameNode);
410 switch (type) {
411 case CheckBoxColorType::SELECTED_COLOR:
412 SetSelectedColor(frameNode, color);
413 break;
414 case CheckBoxColorType::UN_SELECTED_COLOR:
415 SetUnSelectedColor(frameNode, color);
416 break;
417 default:
418 break;
419 }
420 }
421
CreateWithResourceObj(FrameNode * frameNode,const CheckBoxColorType type,const RefPtr<ResourceObject> & resObj)422 void CheckBoxModelNG::CreateWithResourceObj(
423 FrameNode* frameNode, const CheckBoxColorType type, const RefPtr<ResourceObject>& resObj)
424 {
425 CHECK_NULL_VOID(frameNode);
426 auto pattern = frameNode->GetPattern<CheckBoxPattern>();
427 CHECK_NULL_VOID(pattern);
428 std::string key = "checkbox" + ColorTypeToString(type);
429 if (!resObj) {
430 pattern->RemoveResObj(key);
431 return;
432 }
433 auto&& updateFunc = [type, weak = AceType::WeakClaim(frameNode)](const RefPtr<ResourceObject>& resObj) {
434 CHECK_NULL_VOID(resObj);
435 auto frameNode = weak.Upgrade();
436 CHECK_NULL_VOID(frameNode);
437 Color result;
438 if (!ResourceParseUtils::ParseResColor(resObj, result)) {
439 ResetComponentColor(AceType::RawPtr(frameNode), type);
440 } else {
441 UpdateComponentColor(AceType::RawPtr(frameNode), type, result);
442 }
443 };
444 pattern->AddResObj(key, resObj, std::move(updateFunc));
445 }
446
ColorTypeToString(const CheckBoxColorType checkBoxColorType)447 std::string CheckBoxModelNG::ColorTypeToString(const CheckBoxColorType checkBoxColorType)
448 {
449 std::string rst;
450 switch (checkBoxColorType) {
451 case CheckBoxColorType::SELECTED_COLOR:
452 rst = "SelectedColor";
453 break;
454 case CheckBoxColorType::UN_SELECTED_COLOR:
455 rst = "UnSelectedColor";
456 break;
457 default:
458 rst = "Unknown";
459 break;
460 }
461 return rst;
462 }
463
ResetSelectedColor()464 void CheckBoxModelNG::ResetSelectedColor()
465 {
466 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(CheckBoxPaintProperty, CheckBoxSelectedColor, PROPERTY_UPDATE_RENDER);
467 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(CheckBoxPaintProperty, CheckBoxSelectedColorFlagByUser, PROPERTY_UPDATE_RENDER);
468 }
469
ResetSelectedColor(FrameNode * frameNode)470 void CheckBoxModelNG::ResetSelectedColor(FrameNode* frameNode)
471 {
472 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
473 CheckBoxPaintProperty, CheckBoxSelectedColor, PROPERTY_UPDATE_RENDER, frameNode);
474 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
475 CheckBoxPaintProperty, CheckBoxSelectedColorFlagByUser, PROPERTY_UPDATE_RENDER, frameNode);
476 }
477
ResetUnSelectedColor()478 void CheckBoxModelNG::ResetUnSelectedColor()
479 {
480 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(CheckBoxPaintProperty, CheckBoxUnSelectedColor, PROPERTY_UPDATE_RENDER);
481 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(
482 CheckBoxPaintProperty, CheckBoxUnSelectedColorFlagByUser, PROPERTY_UPDATE_RENDER);
483 }
484
ResetUnSelectedColor(FrameNode * frameNode)485 void CheckBoxModelNG::ResetUnSelectedColor(FrameNode* frameNode)
486 {
487 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
488 CheckBoxPaintProperty, CheckBoxUnSelectedColor, PROPERTY_UPDATE_RENDER, frameNode);
489 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
490 CheckBoxPaintProperty, CheckBoxUnSelectedColorFlagByUser, PROPERTY_UPDATE_RENDER, frameNode);
491 }
492
ResetCheckMarkColor()493 void CheckBoxModelNG::ResetCheckMarkColor()
494 {
495 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(CheckBoxPaintProperty, CheckBoxCheckMarkColor, PROPERTY_UPDATE_RENDER);
496 ACE_RESET_PAINT_PROPERTY_WITH_FLAG(CheckBoxPaintProperty, CheckBoxCheckMarkColorFlagByUser, PROPERTY_UPDATE_RENDER);
497 }
498
ResetCheckMarkColor(FrameNode * frameNode)499 void CheckBoxModelNG::ResetCheckMarkColor(FrameNode* frameNode)
500 {
501 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
502 CheckBoxPaintProperty, CheckBoxCheckMarkColor, PROPERTY_UPDATE_RENDER, frameNode);
503 ACE_RESET_NODE_PAINT_PROPERTY_WITH_FLAG(
504 CheckBoxPaintProperty, CheckBoxCheckMarkColorFlagByUser, PROPERTY_UPDATE_RENDER, frameNode);
505 }
506
SetIsUserSetMargin(bool isUserSet)507 void CheckBoxModelNG::SetIsUserSetMargin(bool isUserSet)
508 {
509 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
510 CHECK_NULL_VOID(frameNode);
511 SetIsUserSetMargin(frameNode, isUserSet);
512 }
513
SetIsUserSetMargin(FrameNode * frameNode,bool isUserSet)514 void CheckBoxModelNG::SetIsUserSetMargin(FrameNode* frameNode, bool isUserSet)
515 {
516 CHECK_NULL_VOID(frameNode);
517 auto pattern = frameNode->GetPattern<CheckBoxPattern>();
518 CHECK_NULL_VOID(pattern);
519 pattern->SetIsUserSetMargin(isUserSet);
520 }
521 } // namespace OHOS::Ace::NG
522