Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #ifndef mozilla_layers_APZEventState_h
7 : #define mozilla_layers_APZEventState_h
8 :
9 : #include <stdint.h>
10 :
11 : #include "FrameMetrics.h" // for ScrollableLayerGuid
12 : #include "Units.h"
13 : #include "mozilla/EventForwards.h"
14 : #include "mozilla/layers/GeckoContentController.h" // for APZStateChange
15 : #include "mozilla/RefPtr.h"
16 : #include "nsCOMPtr.h"
17 : #include "nsISupportsImpl.h" // for NS_INLINE_DECL_REFCOUNTING
18 : #include "nsIWeakReferenceUtils.h" // for nsWeakPtr
19 :
20 : #include <functional>
21 :
22 : template <class> class nsCOMPtr;
23 : class nsIContent;
24 : class nsIDocument;
25 : class nsIPresShell;
26 : class nsIWidget;
27 :
28 : namespace mozilla {
29 : namespace layers {
30 :
31 : class ActiveElementManager;
32 :
33 : typedef std::function<void(const ScrollableLayerGuid&,
34 : uint64_t /* input block id */,
35 : bool /* prevent default */)>
36 : ContentReceivedInputBlockCallback;
37 :
38 : /**
39 : * A content-side component that keeps track of state for handling APZ
40 : * gestures and sending APZ notifications.
41 : */
42 : class APZEventState {
43 : typedef GeckoContentController::APZStateChange APZStateChange;
44 : typedef FrameMetrics::ViewID ViewID;
45 : public:
46 : APZEventState(nsIWidget* aWidget,
47 : ContentReceivedInputBlockCallback&& aCallback);
48 :
49 3 : NS_INLINE_DECL_REFCOUNTING(APZEventState);
50 :
51 : void ProcessSingleTap(const CSSPoint& aPoint,
52 : const CSSToLayoutDeviceScale& aScale,
53 : Modifiers aModifiers,
54 : const ScrollableLayerGuid& aGuid,
55 : int32_t aClickCount);
56 : void ProcessLongTap(const nsCOMPtr<nsIPresShell>& aUtils,
57 : const CSSPoint& aPoint,
58 : const CSSToLayoutDeviceScale& aScale,
59 : Modifiers aModifiers,
60 : const ScrollableLayerGuid& aGuid,
61 : uint64_t aInputBlockId);
62 : void ProcessLongTapUp(const nsCOMPtr<nsIPresShell>& aPresShell,
63 : const CSSPoint& aPoint,
64 : const CSSToLayoutDeviceScale& aScale,
65 : Modifiers aModifiers);
66 : void ProcessTouchEvent(const WidgetTouchEvent& aEvent,
67 : const ScrollableLayerGuid& aGuid,
68 : uint64_t aInputBlockId,
69 : nsEventStatus aApzResponse,
70 : nsEventStatus aContentResponse);
71 : void ProcessWheelEvent(const WidgetWheelEvent& aEvent,
72 : const ScrollableLayerGuid& aGuid,
73 : uint64_t aInputBlockId);
74 : void ProcessMouseEvent(const WidgetMouseEvent& aEvent,
75 : const ScrollableLayerGuid& aGuid,
76 : uint64_t aInputBlockId);
77 : void ProcessAPZStateChange(ViewID aViewId,
78 : APZStateChange aChange,
79 : int aArg);
80 : void ProcessClusterHit();
81 : private:
82 : ~APZEventState();
83 : bool SendPendingTouchPreventedResponse(bool aPreventDefault);
84 : bool FireContextmenuEvents(const nsCOMPtr<nsIPresShell>& aPresShell,
85 : const CSSPoint& aPoint,
86 : const CSSToLayoutDeviceScale& aScale,
87 : Modifiers aModifiers,
88 : const nsCOMPtr<nsIWidget>& aWidget);
89 : already_AddRefed<nsIWidget> GetWidget() const;
90 : already_AddRefed<nsIContent> GetTouchRollup() const;
91 : private:
92 : nsWeakPtr mWidget;
93 : RefPtr<ActiveElementManager> mActiveElementManager;
94 : ContentReceivedInputBlockCallback mContentReceivedInputBlockCallback;
95 : bool mPendingTouchPreventedResponse;
96 : ScrollableLayerGuid mPendingTouchPreventedGuid;
97 : uint64_t mPendingTouchPreventedBlockId;
98 : bool mEndTouchIsClick;
99 : bool mTouchEndCancelled;
100 : int32_t mLastTouchIdentifier;
101 :
102 : // Because touch-triggered mouse events (e.g. mouse events from a tap
103 : // gesture) happen asynchronously from the touch events themselves, we
104 : // need to stash and replicate some of the state from the touch events
105 : // to the mouse events. One piece of state is the rollup content, which
106 : // is the content for which a popup window was recently closed. If we
107 : // don't replicate this state properly during the mouse events, the
108 : // synthetic click might reopen a popup window that was just closed by
109 : // the touch event, which is undesirable. See also documentation in
110 : // nsAutoRollup.h
111 : // Note that in cases where we get multiple touch blocks interleaved with
112 : // their single-tap event notifications, mTouchRollup may hold an incorrect
113 : // value. This is kind of an edge case, and falls in the same category of
114 : // problems as bug 1227241. I intend that fixing that bug will also take
115 : // care of this potential problem.
116 : nsWeakPtr mTouchRollup;
117 : };
118 :
119 : } // namespace layers
120 : } // namespace mozilla
121 :
122 : #endif /* mozilla_layers_APZEventState_h */
|