• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "core/components_ng/pattern/checkboxgroup/checkboxgroup_pattern.h"
16 #include "core/components/checkable/checkable_component.h"
17 #include "core/components_ng/pattern/checkbox/checkbox_paint_property.h"
18 #include "core/components_ng/pattern/checkbox/checkbox_pattern.h"
19 #include "core/components_ng/pattern/checkboxgroup/checkboxgroup_paint_property.h"
20 #include "core/components_ng/pattern/stage/page_event_hub.h"
21 #include "core/components_ng/property/calc_length.h"
22 #include "core/components_ng/property/property.h"
23 #include "core/components_v2/inspector/inspector_constants.h"
24 #include "core/event/touch_event.h"
25 #include "core/pipeline_ng/pipeline_context.h"
26 
27 namespace OHOS::Ace::NG {
OnAttachToFrameNode()28 void CheckBoxGroupPattern::OnAttachToFrameNode()
29 {
30     auto host = GetHost();
31     CHECK_NULL_VOID(host);
32     host->GetLayoutProperty()->UpdateAlignment(Alignment::CENTER);
33 }
34 
OnDetachFromFrameNode(FrameNode * frameNode)35 void CheckBoxGroupPattern::OnDetachFromFrameNode(FrameNode* frameNode)
36 {
37     CHECK_NULL_VOID(frameNode);
38     auto pipelineContext = PipelineContext::GetCurrentContext();
39     CHECK_NULL_VOID(pipelineContext);
40     auto stageManager = pipelineContext->GetStageManager();
41     CHECK_NULL_VOID(stageManager);
42     auto pageNode = stageManager->GetLastPage();
43     CHECK_NULL_VOID(pageNode);
44     auto pageEventHub = pageNode->GetEventHub<NG::PageEventHub>();
45     CHECK_NULL_VOID(pageEventHub);
46     auto checkBoxGroupEventHub = frameNode->GetEventHub<NG::CheckBoxGroupEventHub>();
47     CHECK_NULL_VOID(checkBoxGroupEventHub);
48     pageEventHub->RemoveCheckBoxFromGroup(checkBoxGroupEventHub->GetGroupName(), frameNode->GetId());
49 }
50 
OnModifyDone()51 void CheckBoxGroupPattern::OnModifyDone()
52 {
53     Pattern::OnModifyDone();
54     UpdateState();
55     auto host = GetHost();
56     CHECK_NULL_VOID(host);
57     auto pipeline = PipelineBase::GetCurrentContext();
58     CHECK_NULL_VOID(pipeline);
59     auto checkBoxTheme = pipeline->GetTheme<CheckboxTheme>();
60     CHECK_NULL_VOID(checkBoxTheme);
61     auto layoutProperty = host->GetLayoutProperty();
62     CHECK_NULL_VOID(layoutProperty);
63     if (!layoutProperty->GetMarginProperty()) {
64         MarginProperty margin;
65         margin.left = CalcLength(checkBoxTheme->GetHotZoneHorizontalPadding().Value());
66         margin.right = CalcLength(checkBoxTheme->GetHotZoneHorizontalPadding().Value());
67         margin.top = CalcLength(checkBoxTheme->GetHotZoneVerticalPadding().Value());
68         margin.bottom = CalcLength(checkBoxTheme->GetHotZoneVerticalPadding().Value());
69         layoutProperty->UpdateMargin(margin);
70     }
71     hotZoneHorizontalPadding_ = checkBoxTheme->GetHotZoneHorizontalPadding();
72     hotZoneVerticalPadding_ = checkBoxTheme->GetHotZoneVerticalPadding();
73     InitClickEvent();
74     InitTouchEvent();
75     InitMouseEvent();
76     auto focusHub = host->GetFocusHub();
77     CHECK_NULL_VOID(focusHub);
78     InitOnKeyEvent(focusHub);
79 }
80 
InitClickEvent()81 void CheckBoxGroupPattern::InitClickEvent()
82 {
83     if (clickListener_) {
84         return;
85     }
86     auto host = GetHost();
87     CHECK_NULL_VOID(host);
88     auto gesture = host->GetOrCreateGestureEventHub();
89     CHECK_NULL_VOID(gesture);
90     auto clickCallback = [weak = WeakClaim(this)](GestureEvent& info) {
91         auto checkboxPattern = weak.Upgrade();
92         CHECK_NULL_VOID(checkboxPattern);
93         checkboxPattern->OnClick();
94     };
95     clickListener_ = MakeRefPtr<ClickEvent>(std::move(clickCallback));
96     gesture->AddClickEvent(clickListener_);
97 }
98 
InitTouchEvent()99 void CheckBoxGroupPattern::InitTouchEvent()
100 {
101     if (touchListener_) {
102         return;
103     }
104     auto host = GetHost();
105     CHECK_NULL_VOID(host);
106     auto gesture = host->GetOrCreateGestureEventHub();
107     CHECK_NULL_VOID(gesture);
108     auto touchCallback = [weak = WeakClaim(this)](const TouchEventInfo& info) {
109         auto checkboxPattern = weak.Upgrade();
110         CHECK_NULL_VOID(checkboxPattern);
111         if (info.GetTouches().front().GetTouchType() == TouchType::DOWN) {
112             checkboxPattern->OnTouchDown();
113         }
114         if (info.GetTouches().front().GetTouchType() == TouchType::UP ||
115             info.GetTouches().front().GetTouchType() == TouchType::CANCEL) {
116             checkboxPattern->OnTouchUp();
117         }
118     };
119     touchListener_ = MakeRefPtr<TouchEventImpl>(std::move(touchCallback));
120     gesture->AddTouchEvent(touchListener_);
121 }
122 
InitMouseEvent()123 void CheckBoxGroupPattern::InitMouseEvent()
124 {
125     if (mouseEvent_) {
126         return;
127     }
128     auto host = GetHost();
129     CHECK_NULL_VOID(host);
130     auto gesture = host->GetOrCreateGestureEventHub();
131     CHECK_NULL_VOID(gesture);
132     auto eventHub = host->GetEventHub<CheckBoxGroupEventHub>();
133     auto inputHub = eventHub->GetOrCreateInputEventHub();
134 
135     auto mouseTask = [weak = WeakClaim(this)](bool isHover) {
136         auto pattern = weak.Upgrade();
137         if (pattern) {
138             pattern->HandleMouseEvent(isHover);
139         }
140     };
141     mouseEvent_ = MakeRefPtr<InputEvent>(std::move(mouseTask));
142     inputHub->AddOnHoverEvent(mouseEvent_);
143 }
144 
HandleMouseEvent(bool isHover)145 void CheckBoxGroupPattern::HandleMouseEvent(bool isHover)
146 {
147     isHover_ = isHover;
148     if (isHover) {
149         touchHoverType_ = TouchHoverAnimationType::HOVER;
150     } else {
151         touchHoverType_ = TouchHoverAnimationType::NONE;
152     }
153     auto host = GetHost();
154     CHECK_NULL_VOID(host);
155     host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
156 }
157 
OnClick()158 void CheckBoxGroupPattern::OnClick()
159 {
160     auto host = GetHost();
161     CHECK_NULL_VOID(host);
162     auto paintProperty = host->GetPaintProperty<CheckBoxGroupPaintProperty>();
163     CHECK_NULL_VOID(paintProperty);
164     bool isSelected = false;
165     auto status = paintProperty->GetSelectStatus();
166     isSelected = status == CheckBoxGroupPaintProperty::SelectStatus::NONE;
167     paintProperty->UpdateCheckBoxGroupSelect(isSelected);
168     isClick_ = true;
169     UpdateState();
170 }
171 
OnTouchDown()172 void CheckBoxGroupPattern::OnTouchDown()
173 {
174     if (isHover_) {
175         touchHoverType_ = TouchHoverAnimationType::HOVER_TO_PRESS;
176     } else {
177         touchHoverType_ = TouchHoverAnimationType::PRESS;
178     }
179     auto host = GetHost();
180     CHECK_NULL_VOID(host);
181     host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
182 }
183 
OnTouchUp()184 void CheckBoxGroupPattern::OnTouchUp()
185 {
186     if (isHover_) {
187         touchHoverType_ = TouchHoverAnimationType::PRESS_TO_HOVER;
188     } else {
189         touchHoverType_ = TouchHoverAnimationType::NONE;
190     }
191     auto host = GetHost();
192     CHECK_NULL_VOID(host);
193     host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
194 }
195 
UpdateUnSelect()196 void CheckBoxGroupPattern::UpdateUnSelect()
197 {
198     auto host = GetHost();
199     CHECK_NULL_VOID(host);
200     auto paintProperty = host->GetPaintProperty<CheckBoxGroupPaintProperty>();
201     CHECK_NULL_VOID(paintProperty);
202     if (paintProperty->GetSelectStatus() == CheckBoxGroupPaintProperty::SelectStatus::NONE) {
203         uiStatus_ = UIStatus::UNSELECTED;
204         host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
205     }
206 }
207 
UpdateUIStatus(bool check)208 void CheckBoxGroupPattern::UpdateUIStatus(bool check)
209 {
210     auto host = GetHost();
211     CHECK_NULL_VOID(host);
212     auto paintProperty = host->GetPaintProperty<CheckBoxGroupPaintProperty>();
213     CHECK_NULL_VOID(paintProperty);
214     auto selectStatus = paintProperty->GetSelectStatus();
215     if (selectStatus == CheckBoxGroupPaintProperty::SelectStatus::PART) {
216         uiStatus_ = check ? UIStatus::PART_TO_ON : UIStatus::PART_TO_OFF;
217     } else {
218         uiStatus_ = check ? UIStatus::OFF_TO_ON : UIStatus::ON_TO_OFF;
219     }
220     host->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
221 }
222 
UpdateState()223 void CheckBoxGroupPattern::UpdateState()
224 {
225     auto host = GetHost();
226     CHECK_NULL_VOID(host);
227     auto pattern = host->GetPattern<CheckBoxGroupPattern>();
228     CHECK_NULL_VOID(pattern);
229     auto eventHub = host->GetEventHub<CheckBoxGroupEventHub>();
230     CHECK_NULL_VOID(eventHub);
231 
232     auto pipelineContext = PipelineContext::GetCurrentContext();
233     CHECK_NULL_VOID(pipelineContext);
234     auto stageManager = pipelineContext->GetStageManager();
235     CHECK_NULL_VOID(stageManager);
236     auto pageNode = stageManager->GetLastPage();
237     CHECK_NULL_VOID(pageNode);
238     auto pageEventHub = pageNode->GetEventHub<NG::PageEventHub>();
239     CHECK_NULL_VOID(pageEventHub);
240 
241     auto preGroup = pattern->GetPreGroup();
242     auto group = eventHub->GetGroupName();
243     if (!preGroup.has_value()) {
244         pageEventHub->AddCheckBoxGroupToGroup(group, host->GetId());
245         auto paintProperty = host->GetPaintProperty<CheckBoxGroupPaintProperty>();
246         CHECK_NULL_VOID(paintProperty);
247         if (paintProperty->HasCheckBoxGroupSelect() && paintProperty->GetCheckBoxGroupSelectValue()) {
248             auto selectAll = paintProperty->GetCheckBoxGroupSelectValue();
249             if (selectAll) {
250                 paintProperty->SetSelectStatus(CheckBoxGroupPaintProperty::SelectStatus::ALL);
251             }
252             if (selectAll || (!selectAll && !isFirstCreated_)) {
253                 UpdateUIStatus(selectAll);
254             }
255         }
256         isFirstCreated_ = false;
257         pattern->SetPreGroup(group);
258         return;
259     }
260     if (preGroup.value() != group) {
261         pageEventHub->RemoveCheckBoxFromGroup(preGroup.value(), host->GetId());
262         pageEventHub->AddCheckBoxGroupToGroup(group, host->GetId());
263         pattern->SetPreGroup(group);
264         return;
265     }
266     auto paintProperty = host->GetPaintProperty<CheckBoxGroupPaintProperty>();
267     CHECK_NULL_VOID(paintProperty);
268     if (!paintProperty->HasCheckBoxGroupSelect()) {
269         return;
270     }
271     bool isSelected = paintProperty->GetCheckBoxGroupSelectValue();
272     paintProperty->ResetCheckBoxGroupSelect();
273 
274     // Setting selectAll to false when clicked requires processing, changing selectAll to false dynamically does
275     // not require processing
276     if (isClick_ || isSelected) {
277         if (pattern->GetIsAddToMap()) {
278             UpdateGroupCheckStatus(host, isSelected);
279         } else {
280             UpdateRepeatedGroupStatus(host, isSelected);
281         }
282     }
283     isClick_ = false;
284 }
285 
UpdateGroupCheckStatus(const RefPtr<FrameNode> & frameNode,bool select)286 void CheckBoxGroupPattern::UpdateGroupCheckStatus(const RefPtr<FrameNode>& frameNode, bool select)
287 {
288     auto paintProperty = frameNode->GetPaintProperty<CheckBoxGroupPaintProperty>();
289     CHECK_NULL_VOID(paintProperty);
290     auto pattern = frameNode->GetPattern<CheckBoxGroupPattern>();
291     CHECK_NULL_VOID(pattern);
292     pattern->UpdateUIStatus(select);
293     if (select) {
294         paintProperty->SetSelectStatus(CheckBoxGroupPaintProperty::SelectStatus::ALL);
295     } else {
296         paintProperty->SetSelectStatus(CheckBoxGroupPaintProperty::SelectStatus::NONE);
297     }
298     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
299     auto pipelineContext = PipelineContext::GetCurrentContext();
300     CHECK_NULL_VOID(pipelineContext);
301     auto stageManager = pipelineContext->GetStageManager();
302     CHECK_NULL_VOID(stageManager);
303     auto pageNode = stageManager->GetLastPage();
304     CHECK_NULL_VOID(pageNode);
305     auto pageEventHub = pageNode->GetEventHub<NG::PageEventHub>();
306     CHECK_NULL_VOID(pageEventHub);
307     auto checkBoxGroupEventHub = GetEventHub<CheckBoxGroupEventHub>();
308     CHECK_NULL_VOID(checkBoxGroupEventHub);
309     auto checkBoxGroupMap = pageEventHub->GetCheckBoxGroupMap();
310     auto group = checkBoxGroupEventHub->GetGroupName();
311     UpdateCheckBoxStatus(frameNode, checkBoxGroupMap, group, select);
312 }
313 
UpdateCheckBoxStatus(const RefPtr<FrameNode> & frameNode,std::unordered_map<std::string,std::list<WeakPtr<FrameNode>>> checkBoxGroupMap,const std::string & group,bool select)314 void CheckBoxGroupPattern::UpdateCheckBoxStatus(const RefPtr<FrameNode>& frameNode,
315     std::unordered_map<std::string, std::list<WeakPtr<FrameNode>>> checkBoxGroupMap, const std::string& group,
316     bool select)
317 {
318     std::vector<std::string> vec;
319     auto status =
320         select ? CheckBoxGroupPaintProperty::SelectStatus::ALL : CheckBoxGroupPaintProperty::SelectStatus::NONE;
321     const auto& list = checkBoxGroupMap[group];
322     for (auto&& item : list) {
323         auto node = item.Upgrade();
324         if (node == frameNode) {
325             continue;
326         }
327         if (!node) {
328             continue;
329         }
330         if (node->GetTag() == V2::CHECKBOXGROUP_ETS_TAG) {
331             continue;
332         }
333         auto paintProperty = node->GetPaintProperty<CheckBoxPaintProperty>();
334         CHECK_NULL_VOID(paintProperty);
335         auto eventHub = node->GetEventHub<CheckBoxEventHub>();
336         CHECK_NULL_VOID(eventHub);
337         if (select) {
338             vec.push_back(eventHub->GetName());
339         }
340     }
341     CheckboxGroupResult groupResult(vec, int(status));
342     auto eventHub = frameNode->GetEventHub<CheckBoxGroupEventHub>();
343     eventHub->UpdateChangeEvent(&groupResult);
344     for (auto&& item : list) {
345         auto node = item.Upgrade();
346         if (node == frameNode) {
347             continue;
348         }
349         if (!node) {
350             continue;
351         }
352         if (node->GetTag() == V2::CHECKBOXGROUP_ETS_TAG) {
353             continue;
354         } else {
355             auto paintProperty = node->GetPaintProperty<CheckBoxPaintProperty>();
356             CHECK_NULL_VOID(paintProperty);
357             auto eventHub = node->GetEventHub<CheckBoxEventHub>();
358             CHECK_NULL_VOID(eventHub);
359 
360             if (!paintProperty->HasCheckBoxSelect()) {
361                 if (select) {
362                     paintProperty->UpdateCheckBoxSelect(select);
363                     auto pattern = node->GetPattern<CheckBoxPattern>();
364                     pattern->UpdateUIStatus(select);
365                     pattern->SetLastSelect(select);
366                     eventHub->UpdateChangeEvent(select);
367                 }
368             }
369             if (paintProperty->HasCheckBoxSelect() && paintProperty->GetCheckBoxSelectValue() != select) {
370                 paintProperty->UpdateCheckBoxSelect(select);
371                 auto pattern = node->GetPattern<CheckBoxPattern>();
372                 pattern->UpdateUIStatus(select);
373                 pattern->SetLastSelect(select);
374                 eventHub->UpdateChangeEvent(select);
375             }
376         }
377     }
378 }
379 
UpdateRepeatedGroupStatus(const RefPtr<FrameNode> & frameNode,bool select)380 void CheckBoxGroupPattern::UpdateRepeatedGroupStatus(const RefPtr<FrameNode>& frameNode, bool select)
381 {
382     std::vector<std::string> vec;
383     auto status =
384         select ? CheckBoxGroupPaintProperty::SelectStatus::ALL : CheckBoxGroupPaintProperty::SelectStatus::NONE;
385     auto pattern = frameNode->GetPattern<CheckBoxGroupPattern>();
386     CHECK_NULL_VOID(pattern);
387     pattern->UpdateUIStatus(select);
388     auto paintProperty = frameNode->GetPaintProperty<CheckBoxGroupPaintProperty>();
389     CHECK_NULL_VOID(paintProperty);
390     paintProperty->SetSelectStatus(
391         select ? CheckBoxGroupPaintProperty::SelectStatus::ALL : CheckBoxGroupPaintProperty::SelectStatus::NONE);
392     auto checkBoxGroupEventHub = GetEventHub<CheckBoxGroupEventHub>();
393     CHECK_NULL_VOID(checkBoxGroupEventHub);
394     frameNode->MarkDirtyNode(PROPERTY_UPDATE_RENDER);
395     CheckboxGroupResult groupResult(vec, int(status));
396     auto eventHub = frameNode->GetEventHub<CheckBoxGroupEventHub>();
397     eventHub->UpdateChangeEvent(&groupResult);
398 }
399 
InitOnKeyEvent(const RefPtr<FocusHub> & focusHub)400 void CheckBoxGroupPattern::InitOnKeyEvent(const RefPtr<FocusHub>& focusHub)
401 {
402     auto getInnerPaintRectCallback = [wp = WeakClaim(this)](RoundRect& paintRect) {
403         auto pattern = wp.Upgrade();
404         if (pattern) {
405             pattern->GetInnerFocusPaintRect(paintRect);
406         }
407     };
408     focusHub->SetInnerFocusPaintRectCallback(getInnerPaintRectCallback);
409 }
410 
GetInnerFocusPaintRect(RoundRect & paintRect)411 void CheckBoxGroupPattern::GetInnerFocusPaintRect(RoundRect& paintRect)
412 {
413     auto pipelineContext = PipelineBase::GetCurrentContext();
414     CHECK_NULL_VOID(pipelineContext);
415     auto checkBoxTheme = pipelineContext->GetTheme<CheckboxTheme>();
416     CHECK_NULL_VOID(checkBoxTheme);
417     auto borderRadius = checkBoxTheme->GetFocusRadius().ConvertToPx();
418     auto focusPaintPadding = checkBoxTheme->GetFocusPaintPadding().ConvertToPx();
419     float originX = offset_.GetX() - focusPaintPadding;
420     float originY = offset_.GetY() - focusPaintPadding;
421     float width = size_.Width() + 2 * focusPaintPadding;
422     float height = size_.Height() + 2 * focusPaintPadding;
423     paintRect.SetRect({ originX, originY, width, height });
424     paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_LEFT_POS, borderRadius, borderRadius);
425     paintRect.SetCornerRadius(RoundRect::CornerPos::TOP_RIGHT_POS, borderRadius, borderRadius);
426     paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_LEFT_POS, borderRadius, borderRadius);
427     paintRect.SetCornerRadius(RoundRect::CornerPos::BOTTOM_RIGHT_POS, borderRadius, borderRadius);
428 }
429 
GetFocusPattern() const430 FocusPattern CheckBoxGroupPattern::GetFocusPattern() const
431 {
432     auto pipeline = PipelineBase::GetCurrentContext();
433     CHECK_NULL_RETURN(pipeline, FocusPattern());
434     auto checkBoxTheme = pipeline->GetTheme<CheckboxTheme>();
435     CHECK_NULL_RETURN(checkBoxTheme, FocusPattern());
436     auto activeColor = checkBoxTheme->GetActiveColor();
437     FocusPaintParam focusPaintParam;
438     focusPaintParam.SetPaintColor(activeColor);
439     return { FocusType::NODE, true, FocusStyleType::CUSTOM_REGION, focusPaintParam };
440 }
441 
442 // Set the default hot zone for the component.
AddHotZoneRect()443 void CheckBoxGroupPattern::AddHotZoneRect()
444 {
445     hotZoneOffset_.SetX(offset_.GetX() - hotZoneHorizontalPadding_.ConvertToPx());
446     hotZoneOffset_.SetY(offset_.GetY() - hotZoneVerticalPadding_.ConvertToPx());
447     hotZoneSize_.SetWidth(size_.Width() + 2 * hotZoneHorizontalPadding_.ConvertToPx());
448     hotZoneSize_.SetHeight(size_.Height() + 2 * hotZoneVerticalPadding_.ConvertToPx());
449     DimensionRect hotZoneRegion;
450     hotZoneRegion.SetSize(DimensionSize(Dimension(hotZoneSize_.Width()), Dimension(hotZoneSize_.Height())));
451     hotZoneRegion.SetOffset(DimensionOffset(Dimension(hotZoneOffset_.GetX()), Dimension(hotZoneOffset_.GetY())));
452     auto host = GetHost();
453     CHECK_NULL_VOID(host);
454     auto gestureHub = host->GetOrCreateGestureEventHub();
455     CHECK_NULL_VOID(gestureHub);
456     std::vector<DimensionRect> hotZoneRegions;
457     hotZoneRegions.emplace_back(hotZoneRegion);
458     gestureHub->SetResponseRegion(hotZoneRegions);
459 }
460 
RemoveLastHotZoneRect() const461 void CheckBoxGroupPattern::RemoveLastHotZoneRect() const
462 {
463     auto host = GetHost();
464     CHECK_NULL_VOID(host);
465     host->RemoveLastHotZoneRect();
466 }
467 
InitializeModifierParam(CheckBoxGroupModifier::Parameters & paintParameters)468 void CheckBoxGroupPattern::InitializeModifierParam(CheckBoxGroupModifier::Parameters& paintParameters)
469 {
470     auto pipeline = PipelineBase::GetCurrentContext();
471     CHECK_NULL_VOID(pipeline);
472     auto checkBoxTheme = pipeline->GetTheme<CheckboxTheme>();
473     CHECK_NULL_VOID(checkBoxTheme);
474     paintParameters.borderWidth = checkBoxTheme->GetBorderWidth().ConvertToPx();
475     paintParameters.borderRadius = checkBoxTheme->GetBorderRadius().ConvertToPx();
476     paintParameters.checkStroke = checkBoxTheme->GetCheckStroke().ConvertToPx();
477     paintParameters.pointColor = checkBoxTheme->GetPointColor();
478     paintParameters.activeColor = checkBoxTheme->GetActiveColor();
479     paintParameters.inactiveColor = checkBoxTheme->GetInactiveColor();
480     paintParameters.inactivePointColor = checkBoxTheme->GetInactivePointColor();
481     paintParameters.shadowColor = checkBoxTheme->GetShadowColor();
482     paintParameters.clickEffectColor = checkBoxTheme->GetClickEffectColor();
483     paintParameters.hoverColor = checkBoxTheme->GetHoverColor();
484     paintParameters.hoverRadius = checkBoxTheme->GetHoverRadius();
485     paintParameters.hotZoneHorizontalPadding = checkBoxTheme->GetHotZoneHorizontalPadding();
486     paintParameters.hotZoneVerticalPadding = checkBoxTheme->GetHotZoneVerticalPadding();
487     paintParameters.shadowWidth = checkBoxTheme->GetShadowWidth();
488     paintParameters.checkMarkPaintSize = checkBoxTheme->GetDefaultWidth().ConvertToPx();
489     paintParameters.hoverDuration = checkBoxTheme->GetHoverDuration();
490     paintParameters.hoverToTouchDuration = checkBoxTheme->GetHoverToTouchDuration();
491     paintParameters.uiStatus = UIStatus::UNSELECTED;
492     paintParameters.status = CheckBoxGroupPaintProperty::SelectStatus::NONE;
493 }
494 
UpdateModifierParam(CheckBoxGroupModifier::Parameters & paintParameters)495 void CheckBoxGroupPattern::UpdateModifierParam(CheckBoxGroupModifier::Parameters& paintParameters)
496 {
497     auto host = GetHost();
498     CHECK_NULL_VOID(host);
499     auto paintProperty = host->GetPaintProperty<CheckBoxGroupPaintProperty>();
500     CHECK_NULL_VOID(paintProperty);
501     auto geometryNode = host->GetGeometryNode();
502     CHECK_NULL_VOID(geometryNode);
503     auto contentSize = geometryNode->GetContentSize();
504 
505     if (paintProperty->HasCheckBoxGroupSelectedColor()) {
506         paintParameters.activeColor = paintProperty->GetCheckBoxGroupSelectedColorValue();
507     }
508     if (paintProperty->HasCheckBoxGroupUnSelectedColor()) {
509         paintParameters.inactiveColor = paintProperty->GetCheckBoxGroupUnSelectedColorValue();
510     }
511     if (paintProperty->HasCheckBoxGroupCheckMarkColor()) {
512         paintParameters.pointColor = paintProperty->GetCheckBoxGroupCheckMarkColorValue();
513     }
514     if (paintProperty->HasCheckBoxGroupCheckMarkSize()) {
515         if (paintProperty->GetCheckBoxGroupCheckMarkSizeValue().ConvertToPx() >= 0) {
516             paintParameters.checkMarkPaintSize = paintProperty->GetCheckBoxGroupCheckMarkSizeValue().ConvertToPx();
517         } else {
518             paintParameters.checkMarkPaintSize = contentSize.Width();
519         }
520     }
521     if (paintProperty->HasCheckBoxGroupCheckMarkWidth()) {
522         paintParameters.checkStroke =
523             static_cast<float>(paintProperty->GetCheckBoxGroupCheckMarkWidthValue().ConvertToPx());
524     }
525 }
526 
OnColorConfigurationUpdate()527 void CheckBoxGroupPattern::OnColorConfigurationUpdate()
528 {
529     auto host = GetHost();
530     CHECK_NULL_VOID(host);
531     auto pipeline = PipelineBase::GetCurrentContext();
532     CHECK_NULL_VOID(pipeline);
533     auto checkBoxTheme = pipeline->GetTheme<CheckboxTheme>();
534     CHECK_NULL_VOID(checkBoxTheme);
535     auto renderContext = host->GetRenderContext();
536     auto checkBoxGroupPaintProperty = host->GetPaintProperty<CheckBoxGroupPaintProperty>();
537     CHECK_NULL_VOID(checkBoxGroupPaintProperty);
538     checkBoxGroupPaintProperty->UpdateCheckBoxGroupSelectedColor(checkBoxTheme->GetActiveColor());
539     checkBoxGroupPaintProperty->UpdateCheckBoxGroupUnSelectedColor(checkBoxTheme->GetInactiveColor());
540     checkBoxGroupPaintProperty->UpdateCheckBoxGroupCheckMarkColor(checkBoxTheme->GetPointColor());
541     host->MarkModifyDone();
542     host->MarkDirtyNode();
543 }
544 
545 } // namespace OHOS::Ace::NG
546