UserGestureIndicator.h [plain text]
#pragma once
#include <wtf/Function.h>
#include <wtf/Noncopyable.h>
#include <wtf/Optional.h>
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/Vector.h>
namespace WebCore {
class Document;
enum ProcessingUserGestureState {
ProcessingUserGesture,
ProcessingPotentialUserGesture,
NotProcessingUserGesture
};
enum class UserGestureType { EscapeKey, Other };
class UserGestureToken : public RefCounted<UserGestureToken> {
public:
static RefPtr<UserGestureToken> create(ProcessingUserGestureState state, UserGestureType gestureType)
{
return adoptRef(new UserGestureToken(state, gestureType));
}
WEBCORE_EXPORT ~UserGestureToken();
ProcessingUserGestureState state() const { return m_state; }
bool processingUserGesture() const { return m_state == ProcessingUserGesture; }
bool processingUserGestureForMedia() const { return m_state == ProcessingUserGesture || m_state == ProcessingPotentialUserGesture; }
UserGestureType gestureType() const { return m_gestureType; }
void addDestructionObserver(WTF::Function<void (UserGestureToken&)>&& observer)
{
m_destructionObservers.append(WTFMove(observer));
}
private:
UserGestureToken(ProcessingUserGestureState state, UserGestureType gestureType)
: m_state(state)
, m_gestureType(gestureType)
{
}
ProcessingUserGestureState m_state = NotProcessingUserGesture;
Vector<WTF::Function<void (UserGestureToken&)>> m_destructionObservers;
UserGestureType m_gestureType;
};
class UserGestureIndicator {
WTF_MAKE_NONCOPYABLE(UserGestureIndicator);
public:
WEBCORE_EXPORT static RefPtr<UserGestureToken> currentUserGesture();
WEBCORE_EXPORT static bool processingUserGesture();
WEBCORE_EXPORT static bool processingUserGestureForMedia();
WEBCORE_EXPORT explicit UserGestureIndicator(std::optional<ProcessingUserGestureState>, Document* = nullptr, UserGestureType = UserGestureType::Other);
WEBCORE_EXPORT explicit UserGestureIndicator(RefPtr<UserGestureToken>);
WEBCORE_EXPORT ~UserGestureIndicator();
private:
RefPtr<UserGestureToken> m_previousToken;
};
}