1 /* 2 * Copyright (c) 2021-2022 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_BRIDGE_COMMON_DOM_DOM_TOGGLE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TOGGLE_H 18 19 #include "core/components/padding/padding_component.h" 20 #include "core/components/text/text_component.h" 21 #include "core/components/toggle/toggle_component.h" 22 #include "core/components/toggle/toggle_theme.h" 23 #include "frameworks/bridge/common/dom/dom_node.h" 24 #include "frameworks/bridge/common/dom/dom_type.h" 25 26 namespace OHOS::Ace::Framework { 27 28 class DOMToggle final : public DOMNode { 29 DECLARE_ACE_TYPE(DOMToggle, DOMNode); 30 31 public: 32 DOMToggle(NodeId nodeId, const std::string& nodeName); 33 ~DOMToggle() override = default; 34 35 void InitializeStyle() override; 36 GetSpecializedComponent()37 RefPtr<Component> GetSpecializedComponent() override 38 { 39 return toggleChild_; 40 } 41 42 protected: 43 bool SetSpecializedAttr(const std::pair<std::string, std::string>& attr) override; 44 bool SetSpecializedStyle(const std::pair<std::string, std::string>& style) override; 45 bool AddSpecializedEvent(int32_t pageId, const std::string& event) override; 46 void PrepareSpecializedComponent() override; 47 void ResetInitializedStyle() override; 48 49 private: 50 void PrepareDisabledStyle(); 51 void ResetColorStyle(); 52 53 RefPtr<ToggleComponent> toggleChild_; 54 RefPtr<TextComponent> textChild_; 55 RefPtr<PaddingComponent> paddingChild_; 56 RefPtr<ToggleTheme> toggleTheme_; 57 58 TextStyle textStyle_; 59 Color backgroundColor_; 60 Color checkedColor_; 61 Color textColor_; 62 double blendOpacity_ = 1.0; 63 bool colorChanged_ = false; 64 }; 65 66 } // namespace OHOS::Ace::Framework 67 68 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_TOGGLE_H 69