Bug 1717887 Part 2: Make RenderThread backed by nsIThread, with a hang monitor. r...
[gecko.git] / layout / base / TouchManager.h
blob9fbb8551eb10cc12b0dc87a13513fa1357bb21c2
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/TouchEvents.h"
18 #include "nsRefPtrHashtable.h"
20 namespace mozilla {
21 class PresShell;
23 class TouchManager {
24 public:
25 // Initialize and release static variables
26 static void InitializeStatics();
27 static void ReleaseStatics();
29 void Init(PresShell* aPresShell, dom::Document* aDocument);
30 void Destroy();
32 // Perform hit test and setup the event targets for touchstart. Other touch
33 // events are dispatched to the same target as touchstart.
34 static nsIFrame* SetupTarget(WidgetTouchEvent* aEvent, nsIFrame* aFrame);
36 /**
37 * This function checks whether all touch points hit elements in the same
38 * document. If not, we try to find its cross document parent which is in the
39 * same document of the existing target as the event target. We mark the
40 * touch point as suppressed if can't find it. The suppressed touch points are
41 * removed in TouchManager::PreHandleEvent so that we don't dispatch them to
42 * content.
44 * @param aEvent A touch event to be checked.
46 * @return The targeted frame of aEvent.
48 static nsIFrame* SuppressInvalidPointsAndGetTargetedFrame(
49 WidgetTouchEvent* aEvent);
51 bool PreHandleEvent(mozilla::WidgetEvent* aEvent, nsEventStatus* aStatus,
52 bool& aTouchIsNew,
53 nsCOMPtr<nsIContent>& aCurrentEventContent);
55 static already_AddRefed<nsIContent> GetAnyCapturedTouchTarget();
56 static bool HasCapturedTouch(int32_t aId);
57 static already_AddRefed<dom::Touch> GetCapturedTouch(int32_t aId);
58 static bool ShouldConvertTouchToPointer(const dom::Touch* aTouch,
59 const WidgetTouchEvent* aEvent);
61 private:
62 void EvictTouches(dom::Document* aLimitToDocument = nullptr);
63 static void EvictTouchPoint(RefPtr<dom::Touch>& aTouch,
64 dom::Document* aLimitToDocument);
65 static void AppendToTouchList(WidgetTouchEvent::TouchArrayBase* aTouchList);
67 RefPtr<PresShell> mPresShell;
68 RefPtr<dom::Document> mDocument;
70 struct TouchInfo {
71 RefPtr<mozilla::dom::Touch> mTouch;
72 nsCOMPtr<nsIContent> mNonAnonymousTarget;
73 bool mConvertToPointer;
76 static nsTHashMap<nsUint32HashKey, TouchInfo>* sCaptureTouchList;
77 static layers::LayersId sCaptureTouchLayersId;
80 } // namespace mozilla
82 #endif /* !defined(TouchManager_h_) */