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_DIALOG_TWEEN_RENDER_DIALOG_TWEEN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIALOG_TWEEN_RENDER_DIALOG_TWEEN_H
18 
19 #include "core/animation/animator.h"
20 #include "core/components/common/layout/grid_layout_info.h"
21 #include "core/components/common/layout/grid_system_manager.h"
22 #include "core/components/dialog_tween/dialog_tween_component.h"
23 #include "core/components/slider/render_slider.h"
24 #include "core/gestures/click_recognizer.h"
25 #include "core/gestures/drag_recognizer.h"
26 #include "core/pipeline/base/render_node.h"
27 
28 namespace OHOS::Ace {
29 
30 class RenderDialogTween : public RenderNode {
31     DECLARE_ACE_TYPE(RenderDialogTween, RenderNode);
32 
33 public:
34     RenderDialogTween();
35     ~RenderDialogTween() override;
36 
37     static RefPtr<RenderNode> Create();
38     void Update(const RefPtr<Component>& component) override;
39     void PerformLayout() override;
40     void OnPaintFinish() override;
41     bool PopDialog();
42     void SetAnimator(const RefPtr<Animator>& animator_);
43     bool HandleMouseEvent(const MouseEvent& event) override;
44 
45 protected:
46     void OnTouchTestHit(
47         const Offset& coordinateOffset, const TouchRestrict& touchRestrict, TouchTestResult& result) override;
48     void HandleClick(const Offset& clickPosition);
49     void UpdateTouchRegion(const Offset& topLeftPoint, const Size& maxSize, const Size& childSize);
50     double GetMaxWidthBasedOnGridType(const RefPtr<GridColumnInfo>& info, GridSizeType type, DeviceType deviceType);
51     void Initialize();
52 
53     bool autoCancel_ = true;
54     RefPtr<ClickRecognizer> clickDetector_;
55     RefPtr<DragRecognizer> dragDetector_;
56     TouchRegion maskTouchRegion_;
57 
58 private:
59     void CallOnSuccess(int32_t successType);
60     void InitAccessibilityEventListener();
61     void RemoveAccessibilityNode();
62     void RemoveBackendEvent(const RefPtr<DialogTweenComponent>& component);
63     void BindButtonEvent(const RefPtr<DialogTweenComponent>& component);
64     void ComputeInnerLayoutParam(LayoutParam& innerLayout);
65     Offset ComputeChildPosition(const Size& childSize) const;
66     void HandleDragUpdate(const Offset& currentPoint);
67     bool SetAlignmentSwitch(const Size& maxSize, const Size& childSize, Offset& topLeftPoint) const;
68 
69     std::function<void(int32_t)> onSuccess_;
70     std::function<void()> onCancel_;
71     std::function<void()> onComplete_;
72     std::function<void()> onPop_;
73     std::function<void(bool)> onStatusChanged_;
74 
75     std::string data_;
76     int32_t dialogId_ = -1;
77     int32_t composedId_ = 0;
78     // used for inspector node in PC preview
79     int32_t customDialogId_ = -1;
80     int32_t gridCount_ = 0;
81     double dragStart_ = 0.0;
82     double dragX_ = 0.0;
83     double dragY_ = 0.0;
84     const double DRAG_BAR_HEIGHT = 50.0;
85     double lastPositionX_ = 1.0;
86     double lastPositionY_ = 1.0;
87     RefPtr<Animator> animator_;
88     bool isLimit_ = true;
89     Edge margin_;
90     bool isSetMargin_ = false;
91     bool isDragable_ = false;
92     bool isDragging_ = false;
93     bool init_ = true;
94     bool popDialog_ = false;
95     Offset topLeftPoint_;
96     TouchRegion maskDragRegion_;
97     WeakPtr<DialogTweenComponent> weakDialogTweenComponent_;
98 
99     DialogAlignment alignment_ = DialogAlignment::DEFAULT;
100     DimensionOffset offset_;
101 };
102 
103 } // namespace OHOS::Ace
104 
105 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIALOG_TWEEN_RENDER_DIALOG_TWEEN_H
106