1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/layers/apz/util/ActiveElementManager.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef mozilla_layers_ActiveElementManager_h 1.10 +#define mozilla_layers_ActiveElementManager_h 1.11 + 1.12 +#include "nsCOMPtr.h" 1.13 +#include "nsISupportsImpl.h" 1.14 + 1.15 +class inIDOMUtils; 1.16 +class nsIDOMEventTarget; 1.17 +class nsIDOMElement; 1.18 +class CancelableTask; 1.19 + 1.20 +namespace mozilla { 1.21 +namespace layers { 1.22 + 1.23 +/** 1.24 + * Manages setting and clearing the ':active' CSS pseudostate in the presence 1.25 + * of touch input. 1.26 + */ 1.27 +class ActiveElementManager { 1.28 +public: 1.29 + NS_INLINE_DECL_REFCOUNTING(ActiveElementManager) 1.30 + 1.31 + ActiveElementManager(); 1.32 + ~ActiveElementManager(); 1.33 + 1.34 + /** 1.35 + * Specify the target of a touch. Typically this should be called right 1.36 + * before HandleTouchStart(), but we give callers the flexibility to specify 1.37 + * the target later if they don't know it at the time they call 1.38 + * HandleTouchStart(). 1.39 + * |aTarget| may be nullptr. 1.40 + */ 1.41 + void SetTargetElement(nsIDOMEventTarget* aTarget); 1.42 + /** 1.43 + * Handle a touch-start event. 1.44 + * @param aCanBePan whether the touch can be a pan 1.45 + */ 1.46 + void HandleTouchStart(bool aCanBePan); 1.47 + /** 1.48 + * Handle the start of panning. 1.49 + */ 1.50 + void HandlePanStart(); 1.51 + /** 1.52 + * Handle a touch-end or touch-cancel event. 1.53 + * @param aWasClick whether the touch was a click 1.54 + */ 1.55 + void HandleTouchEnd(bool aWasClick); 1.56 +private: 1.57 + nsCOMPtr<inIDOMUtils> mDomUtils; 1.58 + /** 1.59 + * The target of the first touch point in the current touch block. 1.60 + */ 1.61 + nsCOMPtr<nsIDOMElement> mTarget; 1.62 + /** 1.63 + * Whether the current touch block can be a pan. Set in HandleTouchStart(). 1.64 + */ 1.65 + bool mCanBePan; 1.66 + /** 1.67 + * Whether mCanBePan has been set for the current touch block. 1.68 + * We need to keep track of this to allow HandleTouchStart() and 1.69 + * SetTargetElement() to be called in either order. 1.70 + */ 1.71 + bool mCanBePanSet; 1.72 + /** 1.73 + * A task for calling SetActive() after a timeout. 1.74 + */ 1.75 + CancelableTask* mSetActiveTask; 1.76 + 1.77 + // Helpers 1.78 + void TriggerElementActivation(); 1.79 + void SetActive(nsIDOMElement* aTarget); 1.80 + void ResetActive(); 1.81 + void SetActiveTask(nsIDOMElement* aTarget); 1.82 + void CancelTask(); 1.83 +}; 1.84 + 1.85 +} 1.86 +} 1.87 + 1.88 +#endif /* mozilla_layers_ActiveElementManager_h */