| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 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 | |
| jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 5 | #ifndef COMPONENTS_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ |
| 6 | #define COMPONENTS_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 7 | |
| b.kelemen@samsung.com | 078780b | 2014-06-20 16:57:06 | [diff] [blame] | 8 | #include <map> |
| 9 | |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 10 | #include "base/memory/weak_ptr.h" |
| jochen | 746754c5 | 2015-06-05 16:40:41 | [diff] [blame] | 11 | #include "components/test_runner/test_runner_export.h" |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 12 | #include "third_party/WebKit/public/platform/WebGamepads.h" |
| 13 | |
| 14 | namespace blink { |
| 15 | class WebFrame; |
| b.kelemen@samsung.com | 078780b | 2014-06-20 16:57:06 | [diff] [blame] | 16 | class WebGamepadListener; |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 17 | } |
| 18 | |
| jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 19 | namespace test_runner { |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 20 | |
| tfarina@chromium.org | 79ecada | 2014-05-04 05:16:16 | [diff] [blame] | 21 | class WebTestDelegate; |
| 22 | |
| jochen | 746754c5 | 2015-06-05 16:40:41 | [diff] [blame] | 23 | class TEST_RUNNER_EXPORT GamepadController |
| 24 | : public base::SupportsWeakPtr<GamepadController> { |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 25 | public: |
| mlamouri@chromium.org | 9c41b46 | 2014-08-19 15:51:34 | [diff] [blame] | 26 | static base::WeakPtr<GamepadController> Create(WebTestDelegate* delegate); |
| jochen | c833781 | 2015-05-14 01:11:58 | [diff] [blame] | 27 | ~GamepadController(); |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 28 | |
| 29 | void Reset(); |
| 30 | void Install(blink::WebFrame* frame); |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 31 | |
| jochen | c833781 | 2015-05-14 01:11:58 | [diff] [blame] | 32 | void SampleGamepads(blink::WebGamepads& gamepads); |
| 33 | void SetListener(blink::WebGamepadListener* listener); |
| b.kelemen@samsung.com | 078780b | 2014-06-20 16:57:06 | [diff] [blame] | 34 | |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 35 | private: |
| 36 | friend class GamepadControllerBindings; |
| mlamouri@chromium.org | 9c41b46 | 2014-08-19 15:51:34 | [diff] [blame] | 37 | GamepadController(); |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 38 | |
| b.kelemen@samsung.com | 85603cbb | 2014-03-25 02:20:01 | [diff] [blame] | 39 | // TODO(b.kelemen): for historical reasons Connect just initializes the |
| 40 | // object. The 'gamepadconnected' event will be dispatched via |
| 41 | // DispatchConnected. Tests for connected events need to first connect(), |
| 42 | // then set the gamepad data and finally call dispatchConnected(). |
| 43 | // We should consider renaming Connect to Init and DispatchConnected to |
| 44 | // Connect and at the same time updating all the gamepad tests. |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 45 | void Connect(int index); |
| b.kelemen@samsung.com | 85603cbb | 2014-03-25 02:20:01 | [diff] [blame] | 46 | void DispatchConnected(int index); |
| 47 | |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 48 | void Disconnect(int index); |
| 49 | void SetId(int index, const std::string& src); |
| 50 | void SetButtonCount(int index, int buttons); |
| 51 | void SetButtonData(int index, int button, double data); |
| 52 | void SetAxisCount(int index, int axes); |
| 53 | void SetAxisData(int index, int axis, double data); |
| 54 | |
| jochen | c833781 | 2015-05-14 01:11:58 | [diff] [blame] | 55 | blink::WebGamepadListener* listener_; |
| 56 | |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 57 | blink::WebGamepads gamepads_; |
| 58 | |
| b.kelemen@samsung.com | 078780b | 2014-06-20 16:57:06 | [diff] [blame] | 59 | // Mapping from gamepad index to connection state. |
| 60 | std::map<int, bool> pending_changes_; |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 61 | |
| 62 | base::WeakPtrFactory<GamepadController> weak_factory_; |
| 63 | |
| 64 | DISALLOW_COPY_AND_ASSIGN(GamepadController); |
| 65 | }; |
| 66 | |
| jochen | f5f3175 | 2015-06-03 12:06:34 | [diff] [blame] | 67 | } // namespace test_runner |
| jochen@chromium.org | cf78600 | 2014-02-11 02:05:54 | [diff] [blame] | 68 | |
| jochen | 73e711c | 2015-06-03 10:01:46 | [diff] [blame] | 69 | #endif // COMPONENTS_TEST_RUNNER_GAMEPAD_CONTROLLER_H_ |