michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_layers_ActiveElementManager_h michael@0: #define mozilla_layers_ActiveElementManager_h michael@0: michael@0: #include "nsCOMPtr.h" michael@0: #include "nsISupportsImpl.h" michael@0: michael@0: class inIDOMUtils; michael@0: class nsIDOMEventTarget; michael@0: class nsIDOMElement; michael@0: class CancelableTask; michael@0: michael@0: namespace mozilla { michael@0: namespace layers { michael@0: michael@0: /** michael@0: * Manages setting and clearing the ':active' CSS pseudostate in the presence michael@0: * of touch input. michael@0: */ michael@0: class ActiveElementManager { michael@0: public: michael@0: NS_INLINE_DECL_REFCOUNTING(ActiveElementManager) michael@0: michael@0: ActiveElementManager(); michael@0: ~ActiveElementManager(); michael@0: michael@0: /** michael@0: * Specify the target of a touch. Typically this should be called right michael@0: * before HandleTouchStart(), but we give callers the flexibility to specify michael@0: * the target later if they don't know it at the time they call michael@0: * HandleTouchStart(). michael@0: * |aTarget| may be nullptr. michael@0: */ michael@0: void SetTargetElement(nsIDOMEventTarget* aTarget); michael@0: /** michael@0: * Handle a touch-start event. michael@0: * @param aCanBePan whether the touch can be a pan michael@0: */ michael@0: void HandleTouchStart(bool aCanBePan); michael@0: /** michael@0: * Handle the start of panning. michael@0: */ michael@0: void HandlePanStart(); michael@0: /** michael@0: * Handle a touch-end or touch-cancel event. michael@0: * @param aWasClick whether the touch was a click michael@0: */ michael@0: void HandleTouchEnd(bool aWasClick); michael@0: private: michael@0: nsCOMPtr mDomUtils; michael@0: /** michael@0: * The target of the first touch point in the current touch block. michael@0: */ michael@0: nsCOMPtr mTarget; michael@0: /** michael@0: * Whether the current touch block can be a pan. Set in HandleTouchStart(). michael@0: */ michael@0: bool mCanBePan; michael@0: /** michael@0: * Whether mCanBePan has been set for the current touch block. michael@0: * We need to keep track of this to allow HandleTouchStart() and michael@0: * SetTargetElement() to be called in either order. michael@0: */ michael@0: bool mCanBePanSet; michael@0: /** michael@0: * A task for calling SetActive() after a timeout. michael@0: */ michael@0: CancelableTask* mSetActiveTask; michael@0: michael@0: // Helpers michael@0: void TriggerElementActivation(); michael@0: void SetActive(nsIDOMElement* aTarget); michael@0: void ResetActive(); michael@0: void SetActiveTask(nsIDOMElement* aTarget); michael@0: void CancelTask(); michael@0: }; michael@0: michael@0: } michael@0: } michael@0: michael@0: #endif /* mozilla_layers_ActiveElementManager_h */