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_CORE_COMPONENTS_HYPERLINK_RENDER_HYPERLINK_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_HYPERLINK_RENDER_HYPERLINK_H
18 
19 #include "base/mousestyle/mouse_style.h"
20 #include "core/components/common/properties/color.h"
21 #include "core/components/flex/render_flex.h"
22 #include "core/components/hyperlink/hyperlink_component.h"
23 #include "core/components/hyperlink/hyperlink_resources.h"
24 #include "core/gestures/click_recognizer.h"
25 #include "core/pipeline/base/render_node.h"
26 
27 namespace OHOS::Ace {
28 
29 class RenderHyperlink : public RenderNode {
30     DECLARE_ACE_TYPE(RenderHyperlink, RenderNode);
31 
32 public:
33     RenderHyperlink();
34     ~RenderHyperlink() override = default;
35 
36     static RefPtr<RenderNode> Create();
37 
38     void Update(const RefPtr<Component>& component) override;
39 
40     void PerformLayout() override;
41 
GetHyperlinkComponent()42     RefPtr<HyperlinkComponent> GetHyperlinkComponent() const
43     {
44         return hyperlinkComponent_;
45     }
GetColor()46     const Color& GetColor() const
47     {
48         return color_;
49     }
50 
51     bool HandleMouseEvent(const MouseEvent& event) override;
52     void HandleMouseHoverEvent(MouseState mouseState) override;
53 
54 private:
55     void OnTouchTestHit(
56         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
57     void Initialize();
58     void JumpToAddress();
59     void PerformAddress();
60     void SetChildMainColor(Color color);
61     void SetImageChildColor(const RefPtr<Component> node);
62 
63     RefPtr<ClickRecognizer> clickRecognizer_;
64     RefPtr<HyperlinkResources> hyperlinkResources_;
65     RefPtr<HyperlinkComponent> hyperlinkComponent_;
66     std::string address_;
67     Color color_ = Color::TRANSPARENT;
68 };
69 
70 } // namespace OHOS::Ace
71 
72 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_HYPERLINK_RENDER_HYPERLINK_H
73