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 #include "frameworks/bridge/common/dom/dom_label.h" 17 18 #include "core/components/checkable/checkable_component.h" 19 #include "core/components/common/layout/constants.h" 20 #include "core/components/common/properties/text_style.h" 21 #include "core/components/gesture_listener/gesture_listener_component.h" 22 #include "core/components/text_span/text_span_component.h" 23 #include "frameworks/bridge/common/dom/input/dom_radio_util.h" 24 #include "frameworks/bridge/common/utils/utils.h" 25 26 namespace OHOS::Ace::Framework { 27 DOMLabel(NodeId nodeId,const std::string & nodeName)28DOMLabel::DOMLabel(NodeId nodeId, const std::string& nodeName) : DOMText(nodeId, nodeName) {} 29 ~DOMLabel()30DOMLabel::~DOMLabel() 31 { 32 BackEndEventManager<void(const TouchEventInfo&)>::GetInstance().RemoveBackEndEvent(clickMarker_); 33 } 34 PrepareSpecializedComponent()35void DOMLabel::PrepareSpecializedComponent() 36 { 37 DOMText::PrepareSpecializedComponent(); 38 if (!labelComponent_) { 39 labelComponent_ = AceType::MakeRefPtr<TouchListenerComponent>(textChild_); 40 } 41 42 clickMarker_ = BackEndEventManager<void(const TouchEventInfo&)>::GetInstance().GetAvailableMarker(); 43 BackEndEventManager<void(const TouchEventInfo&)>::GetInstance().BindBackendEvent( 44 clickMarker_, [weak = WeakClaim(this)](const TouchEventInfo& info) { 45 auto labelComponent = weak.Upgrade(); 46 if (!labelComponent) { 47 return; 48 } 49 auto trigger = labelComponent->GetLabelTrigger(); 50 if (!trigger) { 51 return; 52 } 53 trigger->Click(); 54 }); 55 labelComponent_->SetOnTouchDownId(clickMarker_); 56 } 57 GetSpecializedComponent()58RefPtr<Component> DOMLabel::GetSpecializedComponent() 59 { 60 return labelComponent_; 61 } 62 63 } // namespace OHOS::Ace::Framework 64