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/.
8 /* Description of TouchManager class.
9 * Incapsulate code related with work of touch events.
12 #ifndef TouchManager_h_
13 #define TouchManager_h_
16 #include "mozilla/BasicEvents.h"
17 #include "mozilla/dom/Touch.h"
18 #include "mozilla/StaticPtr.h"
19 #include "mozilla/TouchEvents.h"
20 #include "nsRefPtrHashtable.h"
28 // Initialize and release static variables
29 static void InitializeStatics();
30 static void ReleaseStatics();
32 void Init(PresShell
* aPresShell
, dom::Document
* aDocument
);
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
);
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
47 * @param aEvent A touch event to be checked.
49 * @return The targeted frame of aEvent.
51 static nsIFrame
* SuppressInvalidPointsAndGetTargetedFrame(
52 WidgetTouchEvent
* aEvent
);
54 bool PreHandleEvent(mozilla::WidgetEvent
* aEvent
, nsEventStatus
* aStatus
,
56 nsCOMPtr
<nsIContent
>& aCurrentEventContent
);
57 void PostHandleEvent(const mozilla::WidgetEvent
* aEvent
,
58 const nsEventStatus
* aStatus
);
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
);
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
);
73 void EvictTouches(dom::Document
* aLimitToDocument
= nullptr);
74 static void EvictTouchPoint(RefPtr
<dom::Touch
>& aTouch
,
75 dom::Document
* aLimitToDocument
);
76 static void AppendToTouchList(WidgetTouchEvent::TouchArrayBase
* aTouchList
);
78 RefPtr
<PresShell
> mPresShell
;
79 RefPtr
<dom::Document
> mDocument
;
82 RefPtr
<mozilla::dom::Touch
> mTouch
;
83 nsCOMPtr
<nsIContent
> mNonAnonymousTarget
;
84 bool mConvertToPointer
;
87 static StaticAutoPtr
<nsTHashMap
<nsUint32HashKey
, TouchInfo
>>
89 static layers::LayersId sCaptureTouchLayersId
;
90 // The last start of a single tap. This will be set to "Null" if the tap is
91 // consumed or becomes not a single tap.
92 static TimeStamp sSingleTouchStartTimeStamp
;
93 // The last start point of the single tap tracked with
94 // sSingleTouchStartTimeStamp.
95 static LayoutDeviceIntPoint sSingleTouchStartPoint
;
98 } // namespace mozilla
100 #endif /* !defined(TouchManager_h_) */