OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ | 5 #ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ |
6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ | 6 #define CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
11 #include "content/public/renderer/renderer_gamepad_provider.h" | 11 #include "content/public/renderer/renderer_gamepad_provider.h" |
12 #include "third_party/WebKit/public/platform/WebGamepads.h" | 12 #include "third_party/WebKit/public/platform/WebGamepads.h" |
13 | 13 |
14 namespace blink { | 14 namespace blink { |
15 class WebFrame; | 15 class WebFrame; |
16 class WebGamepadListener; | 16 class WebGamepadListener; |
17 } | 17 } |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 class WebTestDelegate; | 21 class WebTestDelegate; |
22 | 22 |
23 class GamepadController | 23 class GamepadController |
24 : public base::SupportsWeakPtr<GamepadController>, | 24 : public base::SupportsWeakPtr<GamepadController>, |
25 public RendererGamepadProvider { | 25 public RendererGamepadProvider { |
26 public: | 26 public: |
27 GamepadController(); | 27 static base::WeakPtr<GamepadController> Create(WebTestDelegate* delegate); |
28 virtual ~GamepadController(); | 28 virtual ~GamepadController(); |
29 | 29 |
30 void Reset(); | 30 void Reset(); |
31 void Install(blink::WebFrame* frame); | 31 void Install(blink::WebFrame* frame); |
32 void SetDelegate(WebTestDelegate* delegate); | |
33 | 32 |
34 // RendererGamepadProvider implementation. | 33 // RendererGamepadProvider implementation. |
35 virtual void SampleGamepads( | 34 virtual void SampleGamepads( |
36 blink::WebGamepads& gamepads) OVERRIDE; | 35 blink::WebGamepads& gamepads) OVERRIDE; |
37 virtual void SetGamepadListener( | 36 virtual bool OnControlMessageReceived(const IPC::Message& msg) OVERRIDE; |
38 blink::WebGamepadListener* listener) OVERRIDE; | 37 virtual void SendStartMessage() OVERRIDE; |
| 38 virtual void SendStopMessage() OVERRIDE; |
39 | 39 |
40 private: | 40 private: |
41 friend class GamepadControllerBindings; | 41 friend class GamepadControllerBindings; |
| 42 GamepadController(); |
42 | 43 |
43 // TODO(b.kelemen): for historical reasons Connect just initializes the | 44 // TODO(b.kelemen): for historical reasons Connect just initializes the |
44 // object. The 'gamepadconnected' event will be dispatched via | 45 // object. The 'gamepadconnected' event will be dispatched via |
45 // DispatchConnected. Tests for connected events need to first connect(), | 46 // DispatchConnected. Tests for connected events need to first connect(), |
46 // then set the gamepad data and finally call dispatchConnected(). | 47 // then set the gamepad data and finally call dispatchConnected(). |
47 // We should consider renaming Connect to Init and DispatchConnected to | 48 // We should consider renaming Connect to Init and DispatchConnected to |
48 // Connect and at the same time updating all the gamepad tests. | 49 // Connect and at the same time updating all the gamepad tests. |
49 void Connect(int index); | 50 void Connect(int index); |
50 void DispatchConnected(int index); | 51 void DispatchConnected(int index); |
51 | 52 |
52 void Disconnect(int index); | 53 void Disconnect(int index); |
53 void SetId(int index, const std::string& src); | 54 void SetId(int index, const std::string& src); |
54 void SetButtonCount(int index, int buttons); | 55 void SetButtonCount(int index, int buttons); |
55 void SetButtonData(int index, int button, double data); | 56 void SetButtonData(int index, int button, double data); |
56 void SetAxisCount(int index, int axes); | 57 void SetAxisCount(int index, int axes); |
57 void SetAxisData(int index, int axis, double data); | 58 void SetAxisData(int index, int axis, double data); |
58 | 59 |
59 blink::WebGamepads gamepads_; | 60 blink::WebGamepads gamepads_; |
60 | 61 |
61 blink::WebGamepadListener* listener_; | |
62 | |
63 // Mapping from gamepad index to connection state. | 62 // Mapping from gamepad index to connection state. |
64 std::map<int, bool> pending_changes_; | 63 std::map<int, bool> pending_changes_; |
65 | 64 |
66 base::WeakPtrFactory<GamepadController> weak_factory_; | 65 base::WeakPtrFactory<GamepadController> weak_factory_; |
67 | 66 |
68 DISALLOW_COPY_AND_ASSIGN(GamepadController); | 67 DISALLOW_COPY_AND_ASSIGN(GamepadController); |
69 }; | 68 }; |
70 | 69 |
71 } // namespace content | 70 } // namespace content |
72 | 71 |
73 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ | 72 #endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ |
OLD | NEW |