1 /* 2 * Copyright (c) 2021 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_BADGE_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_BADGE_H 18 19 #include "core/components/badge/badge_component.h" 20 #include "core/components/badge/badge_theme.h" 21 #include "frameworks/bridge/common/dom/dom_node.h" 22 #include "frameworks/bridge/common/dom/dom_type.h" 23 24 namespace OHOS::Ace::Framework { 25 26 struct BadgeConfig { 27 std::pair<Color, bool> badgeColor { Color::RED, false}; 28 std::pair<Color, bool> textColor{ Color::WHITE, false}; 29 std::pair<Dimension, bool> badgeSize { 0.0_px, false}; 30 std::pair<Dimension, bool> textSize { 0.0_px, false}; 31 }; 32 33 class DOMBadge final : public DOMNode { 34 DECLARE_ACE_TYPE(DOMBadge, DOMNode); 35 36 public: 37 DOMBadge(NodeId nodeId, const std::string& nodeName); 38 ~DOMBadge() override = default; 39 40 void SetBadgeConfig(const BadgeConfig& badgeConfig); 41 GetSpecializedComponent()42 RefPtr<Component> GetSpecializedComponent() override 43 { 44 return badgeChild_; 45 } 46 47 protected: 48 void PrepareSpecializedComponent() override; 49 void ResetInitializedStyle() override; 50 void OnChildNodeAdded(const RefPtr<DOMNode>& child, int32_t slot) override; 51 void OnChildNodeRemoved(const RefPtr<DOMNode>& child) override; 52 53 private: 54 RefPtr<BadgeComponent> badgeChild_; 55 }; 56 57 } // namespace OHOS::Ace::Framework 58 59 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_BADGE_H 60