|
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_ActiveElementManager_h |
|
7 #define mozilla_layers_ActiveElementManager_h |
|
8 |
|
9 #include "nsCOMPtr.h" |
|
10 #include "nsISupportsImpl.h" |
|
11 |
|
12 class inIDOMUtils; |
|
13 class nsIDOMEventTarget; |
|
14 class nsIDOMElement; |
|
15 class CancelableTask; |
|
16 |
|
17 namespace mozilla { |
|
18 namespace layers { |
|
19 |
|
20 /** |
|
21 * Manages setting and clearing the ':active' CSS pseudostate in the presence |
|
22 * of touch input. |
|
23 */ |
|
24 class ActiveElementManager { |
|
25 public: |
|
26 NS_INLINE_DECL_REFCOUNTING(ActiveElementManager) |
|
27 |
|
28 ActiveElementManager(); |
|
29 ~ActiveElementManager(); |
|
30 |
|
31 /** |
|
32 * Specify the target of a touch. Typically this should be called right |
|
33 * before HandleTouchStart(), but we give callers the flexibility to specify |
|
34 * the target later if they don't know it at the time they call |
|
35 * HandleTouchStart(). |
|
36 * |aTarget| may be nullptr. |
|
37 */ |
|
38 void SetTargetElement(nsIDOMEventTarget* aTarget); |
|
39 /** |
|
40 * Handle a touch-start event. |
|
41 * @param aCanBePan whether the touch can be a pan |
|
42 */ |
|
43 void HandleTouchStart(bool aCanBePan); |
|
44 /** |
|
45 * Handle the start of panning. |
|
46 */ |
|
47 void HandlePanStart(); |
|
48 /** |
|
49 * Handle a touch-end or touch-cancel event. |
|
50 * @param aWasClick whether the touch was a click |
|
51 */ |
|
52 void HandleTouchEnd(bool aWasClick); |
|
53 private: |
|
54 nsCOMPtr<inIDOMUtils> mDomUtils; |
|
55 /** |
|
56 * The target of the first touch point in the current touch block. |
|
57 */ |
|
58 nsCOMPtr<nsIDOMElement> mTarget; |
|
59 /** |
|
60 * Whether the current touch block can be a pan. Set in HandleTouchStart(). |
|
61 */ |
|
62 bool mCanBePan; |
|
63 /** |
|
64 * Whether mCanBePan has been set for the current touch block. |
|
65 * We need to keep track of this to allow HandleTouchStart() and |
|
66 * SetTargetElement() to be called in either order. |
|
67 */ |
|
68 bool mCanBePanSet; |
|
69 /** |
|
70 * A task for calling SetActive() after a timeout. |
|
71 */ |
|
72 CancelableTask* mSetActiveTask; |
|
73 |
|
74 // Helpers |
|
75 void TriggerElementActivation(); |
|
76 void SetActive(nsIDOMElement* aTarget); |
|
77 void ResetActive(); |
|
78 void SetActiveTask(nsIDOMElement* aTarget); |
|
79 void CancelTask(); |
|
80 }; |
|
81 |
|
82 } |
|
83 } |
|
84 |
|
85 #endif /* mozilla_layers_ActiveElementManager_h */ |