• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2023 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_NG_EVENT_GESTURE_EVENT_HUB_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_EVENT_HUB_H
18 
19 #include <list>
20 #include <vector>
21 
22 #include "base/geometry/ng/point_t.h"
23 #include "base/memory/referenced.h"
24 #include "core/common/interaction/interaction_data.h"
25 #include "core/components/common/layout/constants.h"
26 #include "core/components_ng/event/click_event.h"
27 #include "core/components_ng/event/drag_event.h"
28 #include "core/components_ng/event/long_press_event.h"
29 #include "core/components_ng/event/pan_event.h"
30 #include "core/components_ng/event/scrollable_event.h"
31 #include "core/components_ng/event/target_component.h"
32 #include "core/components_ng/event/touch_event.h"
33 #include "core/components_ng/gestures/gesture_info.h"
34 #include "core/components_ng/gestures/recognizers/exclusive_recognizer.h"
35 #include "core/components_ng/gestures/recognizers/parallel_recognizer.h"
36 #include "core/components_ng/manager/drag_drop/drag_drop_proxy.h"
37 #include "core/gestures/gesture_info.h"
38 
39 namespace OHOS::Ace {
40 struct DragNotifyMsg;
41 class UnifiedData;
42 }
43 
44 enum class MenuPreviewMode {
45     NONE,
46     IMAGE,
47     CUSTOM,
48 };
49 
50 enum class MenuBindingType {
51     LONG_PRESS,
52     RIGHT_CLICK,
53 };
54 namespace OHOS::Ace::NG {
55 
56 enum class HitTestMode {
57     /**
58      *  Both self and children respond to the hit test for touch events,
59      *  but block hit test of the other nodes which is masked by this node.
60      */
61     HTMDEFAULT = 0,
62 
63     /**
64      * Self respond to the hit test for touch events,
65      * but block hit test of children and other nodes which is masked by this node.
66      */
67     HTMBLOCK,
68 
69     /**
70      * Self and child respond to the hit test for touch events,
71      * and allow hit test of other nodes which is masked by this node.
72      */
73     HTMTRANSPARENT,
74 
75     /**
76      * Self not respond to the hit test for touch events,
77      * but children respond to the hit test for touch events.
78      */
79     HTMNONE,
80 
81     /**
82      * Self and child respond to the hit test for touch events,
83      * when self consumed allow hit test of other nodes which is masked by this node,
84      * when child consumed block hit test of other nodes.
85      */
86     HTMTRANSPARENT_SELF,
87 };
88 
89 using TouchInterceptFunc = std::function<NG::HitTestMode(TouchEventInfo&)>;
90 
91 using ShouldBuiltInRecognizerParallelWithFunc = std::function<RefPtr<NGGestureRecognizer>(
92     const RefPtr<NGGestureRecognizer>&, const std::vector<RefPtr<NGGestureRecognizer>>&)>;
93 
94 enum class TouchTestStrategy {
95     DEFAULT = 0,
96     FORWARD_COMPETITION,
97     FORWARD
98 };
99 
100 struct TouchTestInfo {
101     PointF windowPoint;
102     PointF currentCmpPoint;
103     PointF subCmpPoint;
104     RectF subRect;
105     std::string id;
106 };
107 
108 struct TouchResult {
109     TouchTestStrategy strategy;
110     std::string id;
111 };
112 
113 enum class HitTestResult {
114     // The touch point is located outside the current component area;
115     OUT_OF_REGION,
116     // node consumption events and prevent bubbling;
117     STOP_BUBBLING,
118     // node process events and bubble;
119     BUBBLING,
120     // node process events and bubble;
121     SELF_TRANSPARENT,
122 };
123 
124 struct DragDropBaseInfo {
125     RefPtr<AceType> node;
126     RefPtr<PixelMap> pixelMap;
127     std::string extraInfo;
128 };
129 
130 struct BindMenuStatus {
131     bool isBindCustomMenu = false;
132     bool isBindLongPressMenu = false;
133     bool isShow = false;
134     MenuPreviewMode isShowPreviewMode = MenuPreviewMode::NONE;
135     MenuPreviewMode longPressPreviewMode = MenuPreviewMode::NONE;
IsNotNeedShowPreviewBindMenuStatus136     bool IsNotNeedShowPreview() const
137     {
138         return (isBindCustomMenu && isShow) || isBindLongPressMenu;
139     }
140 };
141 
142 using OnDragStartFunc = std::function<DragDropBaseInfo(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>;
143 using OnDragDropFunc = std::function<void(const RefPtr<OHOS::Ace::DragEvent>&, const std::string&)>;
144 using OnChildTouchTestFunc = std::function<TouchResult(const std::vector<TouchTestInfo>& touchInfo)>;
145 using OnReponseRegionFunc = std::function<void(const std::vector<DimensionRect>&)>;
146 struct DragDropInfo {
147     RefPtr<UINode> customNode;
148     RefPtr<PixelMap> pixelMap;
149     std::string extraInfo;
150     // The inspectorId acts as a preview surrogate identifier which is used
151     // to retrieve a preview image for the item being dragged.
152     std::string inspectorId;
153     std::function<RefPtr<UINode>()> buildFunc;
154     bool onlyForLifting = false;
155     bool delayCreating = false;
156 };
157 
158 using DragNotifyMsgCore = OHOS::Ace::DragNotifyMsg;
159 using OnDragCallbackCore = std::function<void(const DragNotifyMsgCore&)>;
160 constexpr float PIXELMAP_WIDTH_RATE = -0.5f;
161 constexpr float PIXELMAP_HEIGHT_RATE = -0.2f;
162 constexpr float PIXELMAP_DEFALUT_LIMIT_SCALE = 0.5f;
163 constexpr float PIXELMAP_DRAG_WGR_TEXT_SCALE = 2.0f;
164 constexpr float PIXELMAP_DRAG_WGR_SCALE = 3.0f;
165 constexpr float DEFALUT_DRAG_PPIXELMAP_SCALE = 1.05f;
166 constexpr float PIXELMAP_DRAG_DEFAULT_HEIGHT = -28.0f;
167 
168 class EventHub;
169 
170 // The gesture event hub is mainly used to handle common gesture events.
171 class ACE_FORCE_EXPORT GestureEventHub : public Referenced {
172 public:
173     explicit GestureEventHub(const WeakPtr<EventHub>& eventHub);
174     ~GestureEventHub() override = default;
175 
AddGesture(const RefPtr<NG::Gesture> & gesture)176     void AddGesture(const RefPtr<NG::Gesture>& gesture)
177     {
178         if (!recreateGesture_) {
179             gestures_.clear();
180             backupGestures_.clear();
181         }
182         gestures_.emplace_back(gesture);
183         backupGestures_.emplace_back(gesture);
184         recreateGesture_ = true;
185     }
186 
187     // call by CAPI do distinguish with AddGesture called by ARKUI;
188     void ClearGesture();
AttachGesture(const RefPtr<NG::Gesture> & gesture)189     void AttachGesture(const RefPtr<NG::Gesture>& gesture)
190     {
191         modifierGestures_.emplace_back(gesture);
192         backupModifierGestures_.emplace_back(gesture);
193         recreateGesture_ = true;
194         OnModifyDone();
195     }
196 
RemoveGesture(const RefPtr<NG::Gesture> & gesture)197     void RemoveGesture(const RefPtr<NG::Gesture>& gesture)
198     {
199         modifierGestures_.remove(gesture);
200         backupModifierGestures_.remove(gesture);
201         recreateGesture_ = true;
202         OnModifyDone();
203     }
204 
205     void RemoveGesturesByTag(const std::string& gestureTag);
206 
207     void ClearModifierGesture();
208 
AddScrollableEvent(const RefPtr<ScrollableEvent> & scrollableEvent)209     void AddScrollableEvent(const RefPtr<ScrollableEvent>& scrollableEvent)
210     {
211         if (!scrollableActuator_) {
212             scrollableActuator_ = MakeRefPtr<ScrollableActuator>(WeakClaim(this));
213         }
214         scrollableActuator_->AddScrollableEvent(scrollableEvent);
215     }
216 
RemoveScrollableEvent(const RefPtr<ScrollableEvent> & scrollableEvent)217     void RemoveScrollableEvent(const RefPtr<ScrollableEvent>& scrollableEvent)
218     {
219         if (!scrollableActuator_) {
220             return;
221         }
222         scrollableActuator_->RemoveScrollableEvent(scrollableEvent);
223     }
224 
AddScrollEdgeEffect(const Axis & axis,RefPtr<ScrollEdgeEffect> & scrollEffect)225     void AddScrollEdgeEffect(const Axis& axis, RefPtr<ScrollEdgeEffect>& scrollEffect)
226     {
227         if (!scrollableActuator_) {
228             scrollableActuator_ = MakeRefPtr<ScrollableActuator>(WeakClaim(this));
229         }
230         scrollableActuator_->AddScrollEdgeEffect(axis, scrollEffect);
231     }
232 
RemoveScrollEdgeEffect(const RefPtr<ScrollEdgeEffect> & scrollEffect)233     void RemoveScrollEdgeEffect(const RefPtr<ScrollEdgeEffect>& scrollEffect)
234     {
235         if (!scrollableActuator_) {
236             return;
237         }
238         scrollableActuator_->RemoveScrollEdgeEffect(scrollEffect);
239     }
240 
AddPreviewMenuHandleDragEnd(GestureEventFunc && actionEnd)241     void AddPreviewMenuHandleDragEnd(GestureEventFunc&& actionEnd)
242     {
243         if (!scrollableActuator_) {
244             scrollableActuator_ = MakeRefPtr<ScrollableActuator>(WeakClaim(this));
245         }
246         scrollableActuator_->AddPreviewMenuHandleDragEnd(std::move(actionEnd));
247     }
248 
249     // Set by user define, which will replace old one.
SetTouchEvent(TouchEventFunc && touchEventFunc)250     void SetTouchEvent(TouchEventFunc&& touchEventFunc)
251     {
252         if (!touchEventActuator_) {
253             touchEventActuator_ = MakeRefPtr<TouchEventActuator>();
254         }
255         touchEventActuator_->ReplaceTouchEvent(std::move(touchEventFunc));
256     }
257 
258     // Set by node container.
259     void SetOnTouchEvent(TouchEventFunc&& touchEventFunc);
260     // Set by JS FrameNode.
261     void SetJSFrameNodeOnTouchEvent(TouchEventFunc&& touchEventFunc);
262 
AddTouchEvent(const RefPtr<TouchEventImpl> & touchEvent)263     void AddTouchEvent(const RefPtr<TouchEventImpl>& touchEvent)
264     {
265         if (!touchEventActuator_) {
266             touchEventActuator_ = MakeRefPtr<TouchEventActuator>();
267         }
268         touchEventActuator_->AddTouchEvent(touchEvent);
269     }
270 
AddTouchAfterEvent(const RefPtr<TouchEventImpl> & touchEvent)271     void AddTouchAfterEvent(const RefPtr<TouchEventImpl>& touchEvent)
272     {
273         if (!touchEventActuator_) {
274             touchEventActuator_ = MakeRefPtr<TouchEventActuator>();
275         }
276         touchEventActuator_->AddTouchAfterEvent(touchEvent);
277     }
278 
RemoveTouchEvent(const RefPtr<TouchEventImpl> & touchEvent)279     void RemoveTouchEvent(const RefPtr<TouchEventImpl>& touchEvent)
280     {
281         if (!touchEventActuator_) {
282             return;
283         }
284         touchEventActuator_->RemoveTouchEvent(touchEvent);
285     }
286 
287     void SetFocusClickEvent(GestureEventFunc&& clickEvent);
288 
IsClickable()289     bool IsClickable() const
290     {
291         return clickEventActuator_ != nullptr;
292     }
293 
IsUserClickable()294     bool IsUserClickable() const
295     {
296         return clickEventActuator_ != nullptr && clickEventActuator_->IsUserClickable();
297     }
298 
299     bool IsAccessibilityClickable();
300     bool IsAccessibilityLongClickable();
301 
302     bool ActClick(std::shared_ptr<JsonValue> secComphandle = nullptr);
303 
304     void CheckClickActuator();
305     // Set by user define, which will replace old one.
306     void SetUserOnClick(GestureEventFunc&& clickEvent,
307         double distanceThreshold = std::numeric_limits<double>::infinity());
308 
309      // Set by JS FrameNode.
310     void SetJSFrameNodeOnClick(GestureEventFunc&& clickEvent);
311 
312     void SetOnGestureJudgeBegin(GestureJudgeFunc&& gestureJudgeFunc);
313 
314     void SetOnTouchIntercept(TouchInterceptFunc&& touchInterceptFunc);
315 
316     TouchInterceptFunc GetOnTouchIntercept() const;
317 
318     void SetShouldBuildinRecognizerParallelWithFunc(ShouldBuiltInRecognizerParallelWithFunc&& parallelGestureToFunc);
319 
320     ShouldBuiltInRecognizerParallelWithFunc GetParallelInnerGestureToFunc() const;
321 
322     void SetOnGestureRecognizerJudgeBegin(GestureRecognizerJudgeFunc&& gestureRecognizerJudgeFunc);
323 
324     GestureRecognizerJudgeFunc GetOnGestureRecognizerJudgeBegin() const;
325 
326     void SetOnGestureJudgeNativeBegin(GestureJudgeFunc&& gestureJudgeFunc);
327 
GetOnGestureJudgeBeginCallback()328     GestureJudgeFunc GetOnGestureJudgeBeginCallback() const
329     {
330         return gestureJudgeFunc_;
331     }
332 
GetOnGestureJudgeNativeBeginCallback()333     GestureJudgeFunc GetOnGestureJudgeNativeBeginCallback() const
334     {
335         return gestureJudgeNativeFunc_;
336     }
337 
338     // When the event param is undefined, it will clear the callback.
339     void ClearUserOnClick();
340     void ClearUserOnTouch();
341 
342 
343     void ClearJSFrameNodeOnClick();
344     void ClearJSFrameNodeOnTouch();
345 
346     void AddClickEvent(const RefPtr<ClickEvent>& clickEvent,
347         double distanceThreshold = std::numeric_limits<double>::infinity());
348     void AddClickAfterEvent(const RefPtr<ClickEvent>& clickEvent);
349 
RemoveClickEvent(const RefPtr<ClickEvent> & clickEvent)350     void RemoveClickEvent(const RefPtr<ClickEvent>& clickEvent)
351     {
352         if (!clickEventActuator_) {
353             return;
354         }
355         clickEventActuator_->RemoveClickEvent(clickEvent);
356     }
357 
IsClickEventsEmpty()358     bool IsClickEventsEmpty() const
359     {
360         if (!clickEventActuator_) {
361             return true;
362         }
363         return clickEventActuator_->IsClickEventsEmpty();
364     }
365 
GetClickEvent()366     GestureEventFunc GetClickEvent()
367     {
368         if (!IsClickable()) {
369             return nullptr;
370         }
371         return clickEventActuator_->GetClickEvent();
372     }
373 
374     void BindMenu(GestureEventFunc&& showMenu);
375 
IsLongClickable()376     bool IsLongClickable() const
377     {
378         return longPressEventActuator_ != nullptr;
379     }
380 
SetRedirectClick(bool redirectClick)381     void SetRedirectClick(bool redirectClick)
382     {
383         redirectClick_ = redirectClick;
384     }
385 
386     bool ActLongClick();
387 
388     void SetLongPressEvent(const RefPtr<LongPressEvent>& event, bool isForDrag = false, bool isDisableMouseLeft = false,
389         int32_t duration = 500)
390     {
391         if (!longPressEventActuator_) {
392             longPressEventActuator_ = MakeRefPtr<LongPressEventActuator>(WeakClaim(this));
393             longPressEventActuator_->SetOnAccessibility(GetOnAccessibilityEventFunc());
394         }
395         longPressEventActuator_->SetLongPressEvent(event, isForDrag, isDisableMouseLeft);
396         longPressEventActuator_->SetDuration(duration);
397     }
398 
399     // Set by user define, which will replace old one.
SetPanEvent(const RefPtr<PanEvent> & panEvent,PanDirection direction,int32_t fingers,Dimension distance)400     void SetPanEvent(const RefPtr<PanEvent>& panEvent, PanDirection direction, int32_t fingers, Dimension distance)
401     {
402         if (!panEventActuator_) {
403             panEventActuator_ =
404                 MakeRefPtr<PanEventActuator>(WeakClaim(this), direction, fingers, distance.ConvertToPx());
405         }
406         panEventActuator_->ReplacePanEvent(panEvent);
407     }
408 
AddPanEvent(const RefPtr<PanEvent> & panEvent,PanDirection direction,int32_t fingers,Dimension distance)409     void AddPanEvent(const RefPtr<PanEvent>& panEvent, PanDirection direction, int32_t fingers, Dimension distance)
410     {
411         if (!panEventActuator_ || direction.type != panEventActuator_->GetDirection().type) {
412             panEventActuator_ =
413                 MakeRefPtr<PanEventActuator>(WeakClaim(this), direction, fingers, distance.ConvertToPx());
414         }
415         panEventActuator_->AddPanEvent(panEvent);
416     }
417 
RemovePanEvent(const RefPtr<PanEvent> & panEvent)418     void RemovePanEvent(const RefPtr<PanEvent>& panEvent)
419     {
420         if (!panEventActuator_) {
421             return;
422         }
423         panEventActuator_->RemovePanEvent(panEvent);
424     }
425 
SetPanEventType(GestureTypeName typeName)426     void SetPanEventType(GestureTypeName typeName)
427     {
428         CHECK_NULL_VOID(panEventActuator_);
429         panEventActuator_->SetPanEventType(typeName);
430     }
431 
432     // Set by user define, which will replace old one.
SetDragEvent(const RefPtr<DragEvent> & dragEvent,PanDirection direction,int32_t fingers,Dimension distance)433     void SetDragEvent(const RefPtr<DragEvent>& dragEvent, PanDirection direction, int32_t fingers, Dimension distance)
434     {
435         if (!dragEventActuator_) {
436             dragEventActuator_ =
437                 MakeRefPtr<DragEventActuator>(WeakClaim(this), direction, fingers, distance.ConvertToPx());
438         }
439         dragEventActuator_->ReplaceDragEvent(dragEvent);
440     }
441 
SetCustomDragEvent(const RefPtr<DragEvent> & dragEvent,PanDirection direction,int32_t fingers,Dimension distance)442     void SetCustomDragEvent(
443         const RefPtr<DragEvent>& dragEvent, PanDirection direction, int32_t fingers, Dimension distance)
444     {
445         if (!dragEventActuator_) {
446             dragEventActuator_ =
447                 MakeRefPtr<DragEventActuator>(WeakClaim(this), direction, fingers, distance.ConvertToPx());
448         }
449         dragEventActuator_->SetCustomDragEvent(dragEvent);
450     }
451 
HasDragEvent()452     bool HasDragEvent() const
453     {
454         return dragEventActuator_ && dragEventActuator_->HasDragEvent();
455     }
456 
457     // the return value means prevents event bubbling.
458     bool ProcessTouchTestHit(const OffsetF& coordinateOffset, const TouchRestrict& touchRestrict,
459         TouchTestResult& innerTargets, TouchTestResult& finalResult, int32_t touchId, const PointF& localPoint,
460         const RefPtr<TargetComponent>& targetComponent, ResponseLinkResult& responseLinkResult);
461 
462     RefPtr<FrameNode> GetFrameNode() const;
463 
OnContextAttached()464     void OnContextAttached() {}
465 
466     std::string GetHitTestModeStr() const;
467 
GetHitTestMode()468     HitTestMode GetHitTestMode() const
469     {
470         return hitTestMode_;
471     }
472 
SetHitTestMode(HitTestMode hitTestMode)473     void SetHitTestMode(HitTestMode hitTestMode)
474     {
475         hitTestMode_ = hitTestMode;
476     }
477 
RemoveDragEvent()478     void RemoveDragEvent()
479     {
480         if (!dragEventActuator_) {
481             return;
482         }
483         dragEventActuator_->ClearDragEvent();
484     }
485 
486     void CombineIntoExclusiveRecognizer(
487         const PointF& globalPoint, const PointF& localPoint, TouchTestResult& result, int32_t touchId);
488 
GetResponseRegion()489     const std::vector<DimensionRect>& GetResponseRegion() const
490     {
491         return responseRegion_;
492     }
493 
GetMouseResponseRegion()494     const std::vector<DimensionRect>& GetMouseResponseRegion() const
495     {
496         return mouseResponseRegion_;
497     }
498 
SetResponseRegionFunc(const OnReponseRegionFunc & func)499     void SetResponseRegionFunc(const OnReponseRegionFunc& func)
500     {
501         responseRegionFunc_ = func;
502     }
503 
504     void SetResponseRegion(const std::vector<DimensionRect>& responseRegion);
505 
SetOnTouchTestFunc(OnChildTouchTestFunc && callback)506     void SetOnTouchTestFunc(OnChildTouchTestFunc&& callback)
507     {
508         onChildTouchTestFunc_ = callback;
509     }
510 
GetOnTouchTestFunc()511     const OnChildTouchTestFunc& GetOnTouchTestFunc()
512     {
513         return onChildTouchTestFunc_;
514     }
515 
SetMouseResponseRegion(const std::vector<DimensionRect> & mouseResponseRegion)516     void SetMouseResponseRegion(const std::vector<DimensionRect>& mouseResponseRegion)
517     {
518         mouseResponseRegion_ = mouseResponseRegion;
519         if (!mouseResponseRegion_.empty()) {
520             isResponseRegion_ = true;
521         }
522     }
523 
AddResponseRect(const DimensionRect & responseRect)524     void AddResponseRect(const DimensionRect& responseRect)
525     {
526         responseRegion_.emplace_back(responseRect);
527         isResponseRegion_ = true;
528 
529         if (responseRegionFunc_) {
530             responseRegionFunc_(responseRegion_);
531         }
532     }
533 
534     void RemoveLastResponseRect();
535 
GetTouchable()536     bool GetTouchable() const
537     {
538         return touchable_;
539     }
540 
SetTouchable(bool touchable)541     void SetTouchable(bool touchable)
542     {
543         touchable_ = touchable;
544     }
545 
SetThumbnailCallback(std::function<void (Offset)> && callback)546     void SetThumbnailCallback(std::function<void(Offset)>&& callback)
547     {
548         if (dragEventActuator_) {
549             dragEventActuator_->SetThumbnailCallback(std::move(callback));
550         }
551     }
552 
553     bool IsDragForbidden() const;
554 
555     void SetDragForbiddenForcely(bool isDragForbidden);
556 
GetTextDraggable()557     bool GetTextDraggable() const
558     {
559         return textDraggable_;
560     }
561 
SetTextDraggable(bool draggable)562     void SetTextDraggable(bool draggable)
563     {
564         textDraggable_ = draggable;
565     }
566 
SetIsTextDraggable(bool isTextDraggable)567     void SetIsTextDraggable(bool isTextDraggable)
568     {
569         isTextDraggable_ = isTextDraggable;
570     }
571 
GetIsTextDraggable()572     bool GetIsTextDraggable()
573     {
574         return isTextDraggable_;
575     }
576 
SetPreviewMode(MenuPreviewMode mode)577     void SetPreviewMode(MenuPreviewMode mode)
578     {
579         previewMode_ = mode;
580     }
581 
GetPreviewMode()582     MenuPreviewMode GetPreviewMode()
583     {
584         return previewMode_;
585     }
586 
SetContextMenuShowStatus(bool contextMenuShowStatus)587     void SetContextMenuShowStatus(bool contextMenuShowStatus)
588     {
589         contextMenuShowStatus_ = contextMenuShowStatus;
590     }
591 
GetContextMenuShowStatus()592     bool GetContextMenuShowStatus()
593     {
594         return contextMenuShowStatus_;
595     }
596 
SetMenuBindingType(MenuBindingType menuBindingType)597     void SetMenuBindingType(MenuBindingType menuBindingType)
598     {
599         menuBindingType_ = menuBindingType;
600     }
601 
GetMenuBindingType()602     MenuBindingType GetMenuBindingType()
603     {
604         return menuBindingType_;
605     }
606 
SetPixelMap(RefPtr<PixelMap> pixelMap)607     void SetPixelMap(RefPtr<PixelMap> pixelMap)
608     {
609         pixelMap_ = pixelMap;
610     }
611 
GetPixelMap()612     RefPtr<PixelMap> GetPixelMap()
613     {
614         return pixelMap_;
615     }
616 
SetDragPreviewPixelMap(RefPtr<PixelMap> pixelMap)617     void SetDragPreviewPixelMap(RefPtr<PixelMap> pixelMap)
618     {
619         dragPreviewPixelMap_ = pixelMap;
620     }
621 
GetLongPressRecognizer()622     RefPtr<LongPressRecognizer> GetLongPressRecognizer() const
623     {
624         CHECK_NULL_RETURN(longPressEventActuator_, nullptr);
625         return longPressEventActuator_->GetLongPressRecognizer();
626     }
627 
SetIsAllowMouse(bool isAllowMouse)628     void SetIsAllowMouse(bool isAllowMouse) const
629     {
630         CHECK_NULL_VOID(panEventActuator_);
631         panEventActuator_->SetIsAllowMouse(isAllowMouse);
632     }
633 
GetUserClickEventActuator()634     const RefPtr<ClickEventActuator>& GetUserClickEventActuator()
635     {
636         return userParallelClickEventActuator_;
637     }
638 
639     int32_t SetDragData(const RefPtr<UnifiedData>& unifiedData, std::string& udKey);
640     OnDragCallbackCore GetDragCallback(const RefPtr<PipelineBase>& context, const WeakPtr<EventHub>& hub);
641 
642     void GenerateMousePixelMap(const GestureEvent& info);
643     OffsetF GetPixelMapOffset(const GestureEvent& info, const SizeF& size, const float scale = 1.0f,
644         bool isCalculateInSubwindow = false, const RectF& innerRect = RectF()) const;
645     RefPtr<PixelMap> GetPreScaledPixelMapIfExist(float targetScale, RefPtr<PixelMap> defaultPixelMap);
646     float GetPixelMapScale(const int32_t height, const int32_t width) const;
647     bool IsPixelMapNeedScale() const;
648     void InitDragDropEvent();
649     void HandleOnDragStart(const GestureEvent& info);
650     void HandleOnDragUpdate(const GestureEvent& info);
651     void HandleOnDragEnd(const GestureEvent& info);
652     void HandleOnDragCancel();
653 
654     void StartLongPressActionForWeb(bool isFloatImage = true);
655     void CancelDragForWeb();
656     void StartDragTaskForWeb();
657     void ResetDragActionForWeb();
658 
659     void OnModifyDone();
660     bool KeyBoardShortCutClick(const KeyEvent& event, const WeakPtr<NG::FrameNode>& node);
661     bool IsAllowedDrag(RefPtr<EventHub> eventHub);
662     void HandleNotallowDrag(const GestureEvent& info);
663     bool ParsePixelMapAsync(DragDropInfo& dragDropInfo, const DragDropInfo& dragPreviewInfo, const GestureEvent& info);
664 
GetDragEventActuator()665     RefPtr<DragEventActuator> GetDragEventActuator()
666     {
667         return dragEventActuator_;
668     }
669 
670     bool GetMonopolizeEvents() const;
671 
672     void SetMonopolizeEvents(bool monopolizeEvents);
673     virtual RefPtr<NGGestureRecognizer> PackInnerRecognizer(
674         const Offset& offset, std::list<RefPtr<NGGestureRecognizer>>& innerRecognizers, int32_t touchId,
675         const RefPtr<TargetComponent>& targetComponent);
676 
CleanExternalRecognizers()677     void CleanExternalRecognizers()
678     {
679         externalParallelRecognizer_.clear();
680         externalExclusiveRecognizer_.clear();
681     }
682 
CleanInnerRecognizer()683     void CleanInnerRecognizer()
684     {
685         innerExclusiveRecognizer_ = nullptr;
686     }
687 
CleanNodeRecognizer()688     void CleanNodeRecognizer()
689     {
690         nodeParallelRecognizer_ = nullptr;
691         nodeExclusiveRecognizer_ = nullptr;
692     }
693 
694     bool parallelCombineClick = false;
695     RefPtr<ParallelRecognizer> innerParallelRecognizer_;
696 
697     void CopyGestures(const RefPtr<GestureEventHub>& gestureEventHub);
698 
699     void CopyEvent(const RefPtr<GestureEventHub>& gestureEventHub);
700 
701     bool IsTextCategoryComponent(const std::string& frameTag);
702 
703     int32_t RegisterCoordinationListener(const RefPtr<PipelineBase>& context);
704 
705     DragDropInfo GetDragDropInfo(const GestureEvent& info, const RefPtr<FrameNode> frameNode,
706         DragDropInfo& dragPreviewInfo, const RefPtr<OHOS::Ace::DragEvent>& dragEvent);
707 
708     RefPtr<UnifiedData> GetUnifiedData(const std::string& frameTag, DragDropInfo& dragDropInfo,
709         const RefPtr<OHOS::Ace::DragEvent>& dragEvent);
710     int32_t GetSelectItemSize();
711 
712     bool IsNeedSwitchToSubWindow() const;
GetDragPreviewPixelMap()713     RefPtr<PixelMap> GetDragPreviewPixelMap()
714     {
715         return dragPreviewPixelMap_;
716     }
717     void SetDragGatherPixelMaps(const GestureEvent& info);
718     void SetMouseDragGatherPixelMaps();
719     void SetNotMouseDragGatherPixelMaps();
720     void FireCustomerOnDragEnd(const RefPtr<PipelineBase>& context, const WeakPtr<EventHub>& hub);
721     void SetMouseDragMonitorState(bool state);
722     void HideMenu();
723 #if defined(PIXEL_MAP_SUPPORTED)
724     static void PrintBuilderNode(const RefPtr<UINode>& customNode);
725     static void PrintIfImageNode(
726         const RefPtr<UINode>& builderNode, int32_t depth, bool& hasImageNode, std::list<RefPtr<FrameNode>>& imageNodes);
727     static void CheckImageDecode(std::list<RefPtr<FrameNode>>& imageNodes);
728     void StartDragForCustomBuilder(const GestureEvent& info, const RefPtr<PipelineBase>& pipeline,
729         const RefPtr<FrameNode> frameNode, DragDropInfo dragDropInfo, const RefPtr<OHOS::Ace::DragEvent>& event);
730 #endif
SetMenuPreviewScale(float menuPreviewScale)731     void SetMenuPreviewScale(float menuPreviewScale)
732     {
733         menuPreviewScale_ = menuPreviewScale;
734     }
735 
GetMenuPreviewScale()736     float GetMenuPreviewScale() const
737     {
738         return menuPreviewScale_;
739     }
740 
741     void SetBindMenuStatus(bool setIsShow, bool isShow, MenuPreviewMode previewMode);
GetBindMenuStatus()742     const BindMenuStatus& GetBindMenuStatus() const
743     {
744         return bindMenuStatus_;
745     }
746 
WillRecreateGesture()747     bool WillRecreateGesture() const
748     {
749         return recreateGesture_;
750     }
751 
752     bool IsGestureEmpty() const;
753 
754     bool IsPanEventEmpty() const;
755 
756     void DumpVelocityInfoFroPanEvent(int32_t fingerId);
757 private:
758     void ProcessTouchTestHierarchy(const OffsetF& coordinateOffset, const TouchRestrict& touchRestrict,
759         std::list<RefPtr<NGGestureRecognizer>>& innerRecognizers, TouchTestResult& finalResult, int32_t touchId,
760         const RefPtr<TargetComponent>& targetComponent, ResponseLinkResult& responseLinkResult);
761 
762     void UpdateGestureHierarchy();
763 
764     void AddGestureToGestureHierarchy(const RefPtr<NG::Gesture>& gesture);
765 
766     // old path.
767     void UpdateExternalNGGestureRecognizer();
768 
769     OnAccessibilityEventFunc GetOnAccessibilityEventFunc();
770 
771     void OnDragStart(const GestureEvent& info, const RefPtr<PipelineBase>& context, const RefPtr<FrameNode> frameNode,
772         DragDropInfo dragDropInfo, const RefPtr<OHOS::Ace::DragEvent>& dragEvent);
773     void UpdateExtraInfo(const RefPtr<FrameNode>& frameNode, std::unique_ptr<JsonValue>& arkExtraInfoJson,
774         float scale);
775 
776     template<typename T>
777     const RefPtr<T> GetAccessibilityRecognizer();
778 
779     template<typename T>
780     const RefPtr<T> AccessibilityRecursionSearchRecognizer(const RefPtr<NGGestureRecognizer>& recognizer);
781 
782     void ProcessParallelPriorityGesture(RefPtr<NGGestureRecognizer>& current,
783         std::list<RefPtr<NGGestureRecognizer>>& recognizers, int32_t& parallelIndex, const Offset& offset,
784         int32_t touchId, const RefPtr<TargetComponent>& targetComponent, const RefPtr<FrameNode>& host);
785 
786     void ProcessExternalExclusiveRecognizer(RefPtr<NGGestureRecognizer>& current,
787         std::list<RefPtr<NGGestureRecognizer>>& recognizers, int32_t& exclusiveIndex, const Offset& offset,
788         int32_t touchId, const RefPtr<TargetComponent>& targetComponent, const RefPtr<FrameNode>& host,
789         GesturePriority priority);
790 
791     WeakPtr<EventHub> eventHub_;
792     RefPtr<ScrollableActuator> scrollableActuator_;
793     RefPtr<TouchEventActuator> touchEventActuator_;
794     RefPtr<ClickEventActuator> clickEventActuator_;
795     RefPtr<ClickEventActuator> userParallelClickEventActuator_;
796     RefPtr<LongPressEventActuator> longPressEventActuator_;
797     RefPtr<PanEventActuator> panEventActuator_;
798     RefPtr<DragEventActuator> dragEventActuator_;
799     RefPtr<ExclusiveRecognizer> innerExclusiveRecognizer_;
800     RefPtr<ExclusiveRecognizer> nodeExclusiveRecognizer_;
801     RefPtr<ParallelRecognizer> nodeParallelRecognizer_;
802     std::vector<RefPtr<ExclusiveRecognizer>> externalExclusiveRecognizer_;
803     std::vector<RefPtr<ParallelRecognizer>> externalParallelRecognizer_;
804     RefPtr<DragDropProxy> dragDropProxy_;
805 
806     // Set by use gesture, priorityGesture and parallelGesture attribute function.
807     std::list<RefPtr<NG::Gesture>> gestures_;
808     // set by CAPI or modifier do distinguish with gestures_;
809     std::list<RefPtr<NG::Gesture>> modifierGestures_;
810     std::list<RefPtr<NG::Gesture>> backupGestures_;
811     std::list<RefPtr<NG::Gesture>> backupModifierGestures_;
812     std::list<RefPtr<NGGestureRecognizer>> gestureHierarchy_;
813 
814     // used in bindMenu, need to delete the old callback when bindMenu runs again
815     RefPtr<ClickEvent> showMenu_;
816 
817     HitTestMode hitTestMode_ = HitTestMode::HTMDEFAULT;
818     bool recreateGesture_ = true;
819     bool needRecollect_ = false;
820     bool isResponseRegion_ = false;
821     std::vector<DimensionRect> responseRegion_;
822     std::vector<DimensionRect> mouseResponseRegion_;
823     bool touchable_ = true;
824     RefPtr<PixelMap> pixelMap_;
825 
826     // Save dragPreview pixelMap of user setting, transfer to drag framework on drag start.
827     RefPtr<PixelMap> dragPreviewPixelMap_;
828 
829     OffsetF frameNodeOffset_;
830     SizeF frameNodeSize_;
831     std::shared_ptr<GestureEvent> gestureInfoForWeb_;
832     bool isReceivedDragGestureInfo_ = false;
833     OnChildTouchTestFunc onChildTouchTestFunc_;
834     OnReponseRegionFunc responseRegionFunc_;
835     bool redirectClick_  = false;
836 
837     GestureJudgeFunc gestureJudgeFunc_;
838     GestureJudgeFunc gestureJudgeNativeFunc_;
839 
840     TouchInterceptFunc touchInterceptFunc_;
841 
842     ShouldBuiltInRecognizerParallelWithFunc shouldBuildinRecognizerParallelWithFunc_;
843     GestureRecognizerJudgeFunc gestureRecognizerJudgeFunc_;
844 
845     MenuPreviewMode previewMode_ = MenuPreviewMode::NONE;
846     // the value from show parameter of context menu, which is controlled by caller manually
847     bool contextMenuShowStatus_  = false;
848     MenuBindingType menuBindingType_  = MenuBindingType::LONG_PRESS;
849     BindMenuStatus bindMenuStatus_;
850     // disable drag for the node itself and its all children
851     bool isDragForbiddenForWholeSubTree_ = false;
852     bool textDraggable_ = false;
853     bool isTextDraggable_ = false;
854     bool monopolizeEvents_ = false;
855     float menuPreviewScale_ = DEFALUT_DRAG_PPIXELMAP_SCALE;
856 };
857 
858 } // namespace OHOS::Ace::NG
859 
860 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_EVENT_GESTURE_EVENT_HUB_H
861