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