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_LABEL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_LABEL_H 18 19 #include "base/utils/label_target.h" 20 #include "core/components/text/text_component.h" 21 #include "core/pipeline/base/component.h" 22 #include "frameworks/bridge/common/dom/dom_node.h" 23 #include "frameworks/bridge/common/dom/dom_text.h" 24 #include "frameworks/bridge/common/dom/dom_type.h" 25 #include "frameworks/bridge/js_frontend/frontend_delegate_impl.h" 26 27 namespace OHOS::Ace::Framework { 28 29 class DOMLabel : public DOMText { 30 DECLARE_ACE_TYPE(DOMLabel, DOMText); 31 32 public: 33 DOMLabel(NodeId nodeId, const std::string& nodeName); 34 ~DOMLabel(); 35 SetTargetNode(const RefPtr<DOMNode> & node)36 void SetTargetNode(const RefPtr<DOMNode>& node) 37 { 38 auto labelTarget = AceType::DynamicCast<LabelTarget>(node->GetBoxComponent()->GetChild()); 39 if (!labelTarget) { 40 return; 41 } 42 trigger_ = labelTarget->GetTrigger(); 43 } 44 GetLabelTrigger()45 RefPtr<LabelTrigger> GetLabelTrigger() const 46 { 47 return trigger_; 48 } 49 GetEvent()50 std::function<void(const std::string&)> GetEvent() 51 { 52 return event_; 53 } 54 55 RefPtr<Component> GetSpecializedComponent() override; 56 57 protected: 58 void PrepareSpecializedComponent() override; 59 60 private: 61 // click event 62 std::list<RefPtr<DOMNode>> children_; 63 RefPtr<TouchListenerComponent> labelComponent_; 64 RefPtr<LabelTrigger> trigger_; 65 std::function<void(const std::string&)> event_; 66 EventMarker clickMarker_; 67 }; 68 69 } // namespace OHOS::Ace::Framework 70 71 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_LABEL_H 72