• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             LOGE("node component type is not label target");
41             return;
42         }
43         trigger_ = labelTarget->GetTrigger();
44     }
45 
GetLabelTrigger()46     RefPtr<LabelTrigger> GetLabelTrigger() const
47     {
48         return trigger_;
49     }
50 
GetEvent()51     std::function<void(const std::string&)> GetEvent()
52     {
53         return event_;
54     }
55 
56     RefPtr<Component> GetSpecializedComponent() override;
57 
58 protected:
59     void PrepareSpecializedComponent() override;
60 
61 private:
62     // click event
63     std::list<RefPtr<DOMNode>> children_;
64     RefPtr<TouchListenerComponent> labelComponent_;
65     RefPtr<LabelTrigger> trigger_;
66     std::function<void(const std::string&)> event_;
67     EventMarker clickMarker_;
68 };
69 
70 } // namespace OHOS::Ace::Framework
71 
72 #endif // FOUNDATION_ACE_FRAMEWORKS_BRIDGE_COMMON_DOM_DOM_LABEL_H
73