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