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_CORE_COMPONENTS_NAVIGATOR_RENDER_NAVIGATOR_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATOR_RENDER_NAVIGATOR_H
18 
19 #include "core/components/navigator/navigator_component.h"
20 #include "core/gestures/click_recognizer.h"
21 #include "core/pipeline/base/render_node.h"
22 
23 namespace OHOS::Ace {
24 
25 class RenderNavigator : public RenderNode {
26     DECLARE_ACE_TYPE(RenderNavigator, RenderNode);
27 
28 public:
29     RenderNavigator();
30     ~RenderNavigator() override = default;
31 
32     static RefPtr<RenderNode> Create();
33 
34     void Update(const RefPtr<Component>& component) override;
35 
36     void PerformLayout() override;
37 
38     void NavigatePage();
39 
40     void SetTargetContainer(const WeakPtr<StageElement>& targetContainer, bool useSubStage = false)
41     {
42         targetContainer_ = targetContainer;
43         useSubStage_ = useSubStage;
44         if (useSubStage_) {
45             // for navigation case, use replace flag.
46             if (type_ == NavigatorType::DEFAULT || type_ == NavigatorType::PUSH) {
47                 type_ = NavigatorType::REPLACE;
48             }
49         }
50     }
51 
GetActive()52     bool GetActive() const
53     {
54         return active_;
55     }
56 
GetTarget()57     const std::string& GetTarget() const
58     {
59         return uri_;
60     }
61 
GetType()62     NavigatorType GetType() const
63     {
64         return type_;
65     }
66 
GetParam()67     const std::string& GetParam() const
68     {
69         return params_;
70     }
71 
72 private:
73     void OnTouchTestHit(
74         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
75     void Initialize();
76     void HandleClickEvent(const ClickInfo& info);
77     void HandleClickEvent();
78     void SetAccessibilityClickImpl();
79 
80     RefPtr<ClickRecognizer> clickRecognizer_;
81 
82     WeakPtr<StageElement> targetContainer_;
83     std::string uri_;
84     std::string params_;
85     NavigatorType type_ = NavigatorType::DEFAULT;
86     bool active_ = false;
87     bool isDefHeight_ = false;
88     bool isDefWidth_ = false;
89     std::function<void(const ClickInfo&)> onClickWithInfo_;
90     std::function<void()> onClick_;
91 
92     bool useSubStage_ = false;
93 };
94 
95 } // namespace OHOS::Ace
96 
97 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NAVIGATOR_RENDER_NAVIGATOR_H
98