Bug 1869043 allow a device to be specified with MediaTrackGraph::NotifyWhenDeviceStar...
[gecko.git] / layout / base / TouchManager.h
blob0e12c25c7df43813229771a15bb3c9b31c43d3ec
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 */
8 /* Description of TouchManager class.
9 * Incapsulate code related with work of touch events.
12 #ifndef TouchManager_h_
13 #define TouchManager_h_
15 #include "mozilla/BasicEvents.h"
16 #include "mozilla/dom/Touch.h"
17 #include "mozilla/StaticPtr.h"
18 #include "mozilla/TouchEvents.h"
19 #include "nsRefPtrHashtable.h"
21 namespace mozilla {
22 class PresShell;
24 class TouchManager {
25 public:
26 // Initialize and release static variables
27 static void InitializeStatics();
28 static void ReleaseStatics();
30 void Init(PresShell* aPresShell, dom::Document* aDocument);
31 void Destroy();
33 // Perform hit test and setup the event targets for touchstart. Other touch
34 // events are dispatched to the same target as touchstart.
35 static nsIFrame* SetupTarget(WidgetTouchEvent* aEvent, nsIFrame* aFrame);
37 /**
38 * This function checks whether all touch points hit elements in the same
39 * document. If not, we try to find its cross document parent which is in the
40 * same document of the existing target as the event target. We mark the
41 * touch point as suppressed if can't find it. The suppressed touch points are
42 * removed in TouchManager::PreHandleEvent so that we don't dispatch them to
43 * content.
45 * @param aEvent A touch event to be checked.
47 * @return The targeted frame of aEvent.
49 static nsIFrame* SuppressInvalidPointsAndGetTargetedFrame(
50 WidgetTouchEvent* aEvent);
52 bool PreHandleEvent(mozilla::WidgetEvent* aEvent, nsEventStatus* aStatus,
53 bool& aTouchIsNew,
54 nsCOMPtr<nsIContent>& aCurrentEventContent);
56 static already_AddRefed<nsIContent> GetAnyCapturedTouchTarget();
57 static bool HasCapturedTouch(int32_t aId);
58 static already_AddRefed<dom::Touch> GetCapturedTouch(int32_t aId);
59 static bool ShouldConvertTouchToPointer(const dom::Touch* aTouch,
60 const WidgetTouchEvent* aEvent);
62 private:
63 void EvictTouches(dom::Document* aLimitToDocument = nullptr);
64 static void EvictTouchPoint(RefPtr<dom::Touch>& aTouch,
65 dom::Document* aLimitToDocument);
66 static void AppendToTouchList(WidgetTouchEvent::TouchArrayBase* aTouchList);
68 RefPtr<PresShell> mPresShell;
69 RefPtr<dom::Document> mDocument;
71 struct TouchInfo {
72 RefPtr<mozilla::dom::Touch> mTouch;
73 nsCOMPtr<nsIContent> mNonAnonymousTarget;
74 bool mConvertToPointer;
77 static StaticAutoPtr<nsTHashMap<nsUint32HashKey, TouchInfo>>
78 sCaptureTouchList;
79 static layers::LayersId sCaptureTouchLayersId;
82 } // namespace mozilla
84 #endif /* !defined(TouchManager_h_) */