• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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 #ifndef FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CHECKBOX_CHECKBOX_THEME_WRAPPER_H
17 #define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_CHECKBOX_CHECKBOX_THEME_WRAPPER_H
18 
19 #include <memory>
20 
21 #include "base/memory/ace_type.h"
22 #include "core/components/checkable/checkable_theme.h"
23 #include "core/components_ng/token_theme/token_theme_wrapper.h"
24 
25 namespace OHOS::Ace::NG {
26 
27 /**
28  * CheckboxThemeWrapper defines colors and styles for both Checkbox and CheckboxGroup component
29  * basing on TokenTheme's data.
30  * CheckboxThemeWrapper should be built using CheckboxThemeWrapper::WrapperBuilder.
31  */
32 class CheckboxThemeWrapper : public CheckboxTheme, public TokenThemeWrapper {
33     DECLARE_ACE_TYPE(CheckboxThemeWrapper, CheckboxTheme);
34 
35 public:
36     class WrapperBuilder : public Builder {
37     public:
38         WrapperBuilder() = default;
39         ~WrapperBuilder() = default;
40 
BuildWrapper(const RefPtr<ThemeConstants> & themeConstants)41         RefPtr<TokenThemeWrapper> BuildWrapper(const RefPtr<ThemeConstants>& themeConstants) const
42         {
43             auto wrapper = AceType::Claim(new CheckboxThemeWrapper());
44             if (!themeConstants) {
45                 return wrapper;
46             }
47             ParsePattern(themeConstants, AceType::DynamicCast<CheckboxTheme>(wrapper));
48             return wrapper;
49         }
50     };
51 
52     ~CheckboxThemeWrapper() override = default;
53 
ApplyTokenTheme(const TokenTheme & theme)54     void ApplyTokenTheme(const TokenTheme& theme) override
55     {
56         if (auto colors = theme.Colors(); colors) {
57             // CheckMarkColor in CheckBoxModel, MarkStyle.strokeColor in TS
58             pointColor_ = colors->IconOnPrimary();
59             // UnSelectedColor in CheckBoxModel
60             inactiveColor_ = colors->IconFourth();
61             // SelectedColor in CheckBoxModel
62             activeColor_ = colors->CompBackgroundEmphasize();
63         }
64     }
65 
66 protected:
67     CheckboxThemeWrapper() = default;
68 };
69 
70 } // namespace
71 #endif