| Index: components/arc/input/arc_input_bridge.h
|
| diff --git a/components/arc/input/arc_input_bridge.h b/components/arc/input/arc_input_bridge.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..07a9aaf90e3061ed125f3a1e183bf92fe5f91818
|
| --- /dev/null
|
| +++ b/components/arc/input/arc_input_bridge.h
|
| @@ -0,0 +1,111 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_
|
| +#define COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_
|
| +
|
| +#include "base/macros.h"
|
| +#include "components/arc/arc_bridge_service.h"
|
| +#include "ui/events/event.h"
|
| +#include "ui/events/event_handler.h"
|
| +
|
| +namespace arc {
|
| +
|
| +class ArcBridgeService;
|
| +
|
| +// This class allows ui::Event's to be sent through the ArcBridgeService to be
|
| +// received by the ARC instance.
|
| +class ArcInputBridge : public ArcBridgeService::Observer {
|
| + public:
|
| + // Registers an observer with the ArcBridgeService.
|
| + explicit ArcInputBridge(
|
| + base::WeakPtr<ArcBridgeService> arc_bridge_service,
|
| + const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
|
| + ~ArcInputBridge() override;
|
| +
|
| + // Gets the global instance of the ARC Input Bridge.
|
| + static ArcInputBridge* Get();
|
| +
|
| + // Translates and sends a ui::Event to the appropriate bridge device of the
|
| + // ARC instance. If the devices have not yet been initialized, the event
|
| + // will be ignored.
|
| + void SendInputEvent(ui::Event* event);
|
| +
|
| + private:
|
| + void SendInputEventIO(scoped_ptr<ui::Event> event);
|
| +
|
| + // Specialized method to translate and send events to the right file
|
| + // descriptor
|
| + void SendKeyEventIO(ui::KeyEvent* event);
|
| + void SendTouchEventIO(ui::TouchEvent* event);
|
| + void SendMouseEventIO(ui::MouseEvent* event);
|
| +
|
| + // Helper method to send a struct input_event to the file descriptor. This
|
| + // method is to be called on the ui thread and will post a request to send
|
| + // the event to the io thread.
|
| + // The parameters map directly to the members of input_event as
|
| + // defined by the evdev protocol.
|
| + // |type| is the type of event to sent, such as EV_SYN, EV_KEY, EV_ABS.
|
| + // |code| is either interpreted as axis (ABS_X, ABS_Y, ...) or as key-code
|
| + // (KEY_A, KEY_B, ...).
|
| + // |value| is either the value of that axis or the boolean value of the key
|
| + // as in 0 (released), 1 (pressed) or 2 (repeated press).
|
| + void SendKernelEventIO(const base::ScopedFD& fd,
|
| + base::TimeDelta timestamp,
|
| + unsigned short type,
|
| + unsigned short code,
|
| + int value);
|
| +
|
| + // Shorthand for sending EV_SYN/SYN_REPORT
|
| + void SendSynReportIO(const base::ScopedFD& fd, base::TimeDelta timestamp);
|
| +
|
| + // Return existing or new slot for this event.
|
| + int AcquireTouchSlotIO(ui::TouchEvent* event);
|
| +
|
| + // Return touch slot for tracking id.
|
| + int FindTouchSlotIO(int tracking_id);
|
| +
|
| + // ArcBridgeService::Observer:
|
| + void OnInstanceBootPhase(InstanceBootPhase phase) override;
|
| +
|
| + // Setup bridge devices on the instance side. This needs to be called after
|
| + // the InstanceBootPhase::SYSTEM_SERVICES_READY has been reached.
|
| + void SetupBridgeDevices();
|
| +
|
| + // Creates and registers file descriptor pair with the ARC bridge service,
|
| + // the write end is returned while the read end is sent through the bridge
|
| + // to the ARC instance.
|
| + // TODO(denniskempin): Make this interface more typesafe.
|
| + // |name| should be the displayable name of the emulated device (e.g. "Chrome
|
| + // OS Keyboard"), |device_type| the name of the device type (e.g. "keyboard")
|
| + // and |fd| a file descriptor that emulates the kernel events of the device.
|
| + // This can only be called on the thread that this class was created on.
|
| + base::ScopedFD CreateBridgeInputDevice(const std::string& name,
|
| + const std::string& device_type);
|
| +
|
| + base::WeakPtr<ArcBridgeService> arc_bridge_service_;
|
| +
|
| + // File descriptors for the different device types.
|
| + base::ScopedFD keyboard_fd_;
|
| + base::ScopedFD mouse_fd_;
|
| + base::ScopedFD touchscreen_fd_;
|
| +
|
| + // Currently selected slot for multi-touch events
|
| + int current_slot_;
|
| +
|
| + // List of touch tracking id to slot assignments
|
| + std::vector<int> current_slot_tracking_ids_;
|
| +
|
| + scoped_refptr<base::SequencedTaskRunner> origin_task_runner_;
|
| + scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
|
| +
|
| + // WeakPtrFactory to use callbacks.
|
| + base::WeakPtrFactory<ArcInputBridge> weak_factory_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ArcInputBridge);
|
| +};
|
| +
|
| +} // namespace arc
|
| +
|
| +#endif // COMPONENTS_EXO_ARC_ARC_INPUT_BRIDGE_H_
|
|
|