• 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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_TOGGLE_BUTTON_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_TOGGLE_BUTTON_PATTERN_H
18 
19 #include <optional>
20 
21 #include "core/components/common/properties/color.h"
22 #include "core/components_ng/event/event_hub.h"
23 #include "core/components_ng/pattern/button/button_pattern.h"
24 #include "core/components_ng/pattern/button/toggle_button_accessibility_property.h"
25 #include "core/components_ng/pattern/button/toggle_button_event_hub.h"
26 #include "core/components_ng/pattern/button/toggle_button_paint_property.h"
27 
28 namespace OHOS::Ace::NG {
29 class ToggleButtonPattern : public ButtonPattern {
30     DECLARE_ACE_TYPE(ToggleButtonPattern, ButtonPattern);
31 
32 public:
33     ToggleButtonPattern() = default;
34 
35     ~ToggleButtonPattern() override = default;
36 
IsAtomicNode()37     bool IsAtomicNode() const override
38     {
39         return false;
40     }
41 
CreateEventHub()42     RefPtr<EventHub> CreateEventHub() override
43     {
44         return MakeRefPtr<ToggleButtonEventHub>();
45     }
46 
CreatePaintProperty()47     RefPtr<PaintProperty> CreatePaintProperty() override
48     {
49         return MakeRefPtr<ToggleButtonPaintProperty>();
50     }
51 
CreateAccessibilityProperty()52     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
53     {
54         return MakeRefPtr<ToggleButtonAccessibilityProperty>();
55     }
56     std::string ProvideRestoreInfo() override;
57     void OnRestoreInfo(const std::string& restoreInfo) override;
58     void OnClick();
59     void OnColorConfigurationUpdate() override;
60     void MarkIsSelected(bool isSelected);
61 
62 private:
63     void OnAttachToFrameNode() override;
64     void InitParameters();
65     void OnModifyDone() override;
66     void OnAfterModifyDone() override;
67     void HandleEnabled();
68     void InitClickEvent();
69     void InitButtonAndText();
70     void InitOnKeyEvent();
71     bool OnKeyEvent(const KeyEvent& event);
72     void SetAccessibilityAction();
73     void UpdateSelectStatus(bool isSelected);
74 
75     RefPtr<ClickEvent> clickListener_;
76     std::optional<bool> isOn_;
77     Color checkedColor_;
78     Color unCheckedColor_;
79     float disabledAlpha_ { 1.0f };
80     Dimension textMargin_;
81     Dimension buttonMargin_;
82     Dimension buttonHeight_;
83     Dimension buttonRadius_;
84     Dimension textFontSize_;
85     Color textColor_;
86 
87     ACE_DISALLOW_COPY_AND_MOVE(ToggleButtonPattern);
88 };
89 } // namespace OHOS::Ace::NG
90 
91 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_BUTTON_TOGGLE_BUTTON_PATTERN_H
92