

#ifndef PointerLockController_h
#define PointerLockController_h

#if ENABLE(POINTER_LOCK)

#include <wtf/RefPtr.h>
#include <wtf/text/AtomicString.h>

namespace WebCore {

class Element;
class Document;
class Page;
class PlatformMouseEvent;
class VoidCallback;

class PointerLockController {
    WTF_MAKE_NONCOPYABLE(PointerLockController);
    WTF_MAKE_FAST_ALLOCATED;
public:
    static PassOwnPtr<PointerLockController> create(Page*);

    void requestPointerLock(Element* target);
    void requestPointerUnlock();
    void elementRemoved(Element*);
    void documentDetached(Document*);
    bool lockPending() const;
    Element* element() const;

    void didAcquirePointerLock();
    void didNotAcquirePointerLock();
    void didLosePointerLock();
    void dispatchLockedMouseEvent(const PlatformMouseEvent&, const AtomicString& eventType);

private:
    explicit PointerLockController(Page*);
    void clearElement();
    void enqueueEvent(const AtomicString& type, Element*);
    void enqueueEvent(const AtomicString& type, Document*);
    Page* m_page;
    bool m_lockPending;
    RefPtr<Element> m_element;
    RefPtr<Document> m_documentOfRemovedElementWhileWaitingForUnlock;
};

} // namespace WebCore

#endif // ENABLE(POINTER_LOCK)

#endif // PointerLockController_h
