Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / modules / gamepad / GamepadDispatcher.h
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
13 namespace blink {
14
15 class WebGamepads;
16
17 class GamepadDispatcher final : public GarbageCollectedFinalized<GamepadDispatcher>, public PlatformEventDispatcher, public WebGamepadListener {
18     USING_GARBAGE_COLLECTED_MIXIN(GamepadDispatcher);
19 public:
20     static GamepadDispatcher& instance();
21     virtual ~GamepadDispatcher();
22
23     void sampleGamepads(WebGamepads&);
24
25     struct ConnectionChange {
26         WebGamepad pad;
27         unsigned index;
28     };
29
30     const ConnectionChange& latestConnectionChange() const { return m_latestChange; }
31
32     virtual void trace(Visitor*) override;
33
34 private:
35     GamepadDispatcher();
36
37     // WebGamepadListener
38     virtual void didConnectGamepad(unsigned index, const WebGamepad&) override;
39     virtual void didDisconnectGamepad(unsigned index, const WebGamepad&) override;
40
41     // PlatformEventDispatcher
42     virtual void startListening() override;
43     virtual void stopListening() override;
44
45     void dispatchDidConnectOrDisconnectGamepad(unsigned index, const WebGamepad&, bool connected);
46
47     ConnectionChange m_latestChange;
48 };
49
50 } // namespace blink
51
52 #endif