TouchManager.h (4511B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 6 */ 7 8 /* Description of TouchManager class. 9 * Incapsulate code related with work of touch events. 10 */ 11 12 #ifndef TouchManager_h_ 13 #define TouchManager_h_ 14 15 #include "Units.h" 16 #include "mozilla/BasicEvents.h" 17 #include "mozilla/StaticPtr.h" 18 #include "mozilla/TouchEvents.h" 19 #include "mozilla/dom/Touch.h" 20 #include "nsRefPtrHashtable.h" 21 22 namespace mozilla { 23 class PresShell; 24 class TimeStamp; 25 26 class TouchManager { 27 public: 28 // Initialize and release static variables 29 static void InitializeStatics(); 30 static void ReleaseStatics(); 31 32 void Init(PresShell* aPresShell, dom::Document* aDocument); 33 void Destroy(); 34 35 // Perform hit test and setup the event targets for touchstart. Other touch 36 // events are dispatched to the same target as touchstart. 37 static nsIFrame* SetupTarget(WidgetTouchEvent* aEvent, nsIFrame* aFrame); 38 39 /** 40 * This function checks whether all touch points hit elements in the same 41 * document. If not, we try to find its cross document parent which is in the 42 * same document of the existing target as the event target. We mark the 43 * touch point as suppressed if can't find it. The suppressed touch points are 44 * removed in TouchManager::PreHandleEvent so that we don't dispatch them to 45 * content. 46 * 47 * @param aEvent A touch event to be checked. 48 * 49 * @return The targeted frame of aEvent. 50 */ 51 static nsIFrame* SuppressInvalidPointsAndGetTargetedFrame( 52 WidgetTouchEvent* aEvent); 53 54 bool PreHandleEvent(mozilla::WidgetEvent* aEvent, nsEventStatus* aStatus, 55 bool& aTouchIsNew, 56 nsCOMPtr<nsIContent>& aCurrentEventContent); 57 void PostHandleEvent(const mozilla::WidgetEvent* aEvent, 58 const nsEventStatus* aStatus); 59 60 static already_AddRefed<nsIContent> GetAnyCapturedTouchTarget(); 61 static bool HasCapturedTouch(int32_t aId); 62 static already_AddRefed<dom::Touch> GetCapturedTouch(int32_t aId); 63 static bool ShouldConvertTouchToPointer(const dom::Touch* aTouch, 64 const WidgetTouchEvent* aEvent); 65 66 // This should be called after PostHandleEvent() is called. Note that this 67 // cannot check touches outside this process. So, this should not be used for 68 // actual user input handling. This is designed for a fallback path to 69 // dispatch mouse events for touch events synthesized without APZ. 70 static bool IsSingleTapEndToDoDefault(const WidgetTouchEvent* aTouchEndEvent); 71 72 // Returns true if the preceding `pointerdown` was consumed by content of 73 // the last active pointers of touches. 74 static bool IsPrecedingTouchPointerDownConsumedByContent(); 75 76 private: 77 void EvictTouches(dom::Document* aLimitToDocument = nullptr); 78 static void EvictTouchPoint(RefPtr<dom::Touch>& aTouch, 79 dom::Document* aLimitToDocument); 80 static void AppendToTouchList(WidgetTouchEvent::TouchArrayBase* aTouchList); 81 82 RefPtr<PresShell> mPresShell; 83 RefPtr<dom::Document> mDocument; 84 85 struct TouchInfo { 86 RefPtr<mozilla::dom::Touch> mTouch; 87 nsCOMPtr<nsIContent> mNonAnonymousTarget; 88 bool mConvertToPointer; 89 }; 90 91 static StaticAutoPtr<nsTHashMap<nsUint32HashKey, TouchInfo>> 92 sCaptureTouchList; 93 static layers::LayersId sCaptureTouchLayersId; 94 // The last start of a single tap. This will be set to "Null" if the tap is 95 // consumed or becomes not a single tap. 96 // NOTE: This is used for touches without APZ, i.e., if they are synthesized 97 // in-process for tests. 98 static TimeStamp sSingleTouchStartTimeStamp; 99 // The last start point of the single tap tracked with 100 // sSingleTouchStartTimeStamp. 101 // NOTE: This is used for touches without APZ, i.e., if they are synthesized 102 // in-process for tests. 103 static LayoutDeviceIntPoint sSingleTouchStartPoint; 104 // Whether the preceding `pointerdown` of the last active touches is consumed 105 // by content or not. If APZ is enabled, same state is managed by 106 // APZEventState. 107 // NOTE: This is used for touches without APZ, i.e., if they are synthesized 108 // in-process for tests. 109 static bool sPrecedingTouchPointerDownConsumedByContent; 110 }; 111 112 } // namespace mozilla 113 114 #endif /* !defined(TouchManager_h_) */