1// Copyright 2014 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef GamepadDispatcher_h
6#define GamepadDispatcher_h
7
8#include "core/frame/PlatformEventDispatcher.h"
9#include "platform/heap/Handle.h"
10#include "public/platform/WebGamepad.h"
11#include "public/platform/WebGamepadListener.h"
12
13namespace blink {
14
15class NavigatorGamepad;
16class WebGamepads;
17
18class GamepadDispatcher : public PlatformEventDispatcher, public WebGamepadListener {
19public:
20    static GamepadDispatcher& instance();
21
22    void sampleGamepads(WebGamepads&);
23
24    struct ConnectionChange {
25        WebGamepad pad;
26        unsigned index;
27    };
28
29    const ConnectionChange& latestConnectionChange() const { return m_latestChange; }
30
31private:
32    GamepadDispatcher();
33    virtual ~GamepadDispatcher();
34
35    // WebGamepadListener
36    virtual void didConnectGamepad(unsigned index, const WebGamepad&) OVERRIDE;
37    virtual void didDisconnectGamepad(unsigned index, const WebGamepad&) OVERRIDE;
38
39    // PlatformEventDispatcher
40    virtual void startListening() OVERRIDE;
41    virtual void stopListening() OVERRIDE;
42
43    void dispatchDidConnectOrDisconnectGamepad(unsigned index, const WebGamepad&, bool connected);
44
45    ConnectionChange m_latestChange;
46};
47
48} // namespace blink
49
50#endif
51