Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Unified Diff: components/arc/input/arc_input_bridge.h

Issue 1408263006: chromeos: Add ArcInputBridge to components/arc (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@arcxx
Patch Set: integration with ArcServiceManager and ExoSurfaces Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f61e7a8b6c8c6abf23e68c230b084bfd6af525e4
--- /dev/null
+++ b/components/arc/input/arc_input_bridge.h
@@ -0,0 +1,140 @@
+// 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_
reveman 2015/12/04 03:21:24 should be COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_
denniskempin 2015/12/04 22:35:30 Done.
+
+#include "base/macros.h"
+#include "components/arc/arc_bridge_service.h"
+#include "ui/aura/window_observer.h"
+#include "ui/aura/env.h"
+#include "ui/aura/env_observer.h"
+#include "ui/events/event.h"
+#include "ui/events/event_handler.h"
+
+namespace aura {
+
+class Window;
+
+} // namespace aura
reveman 2015/12/04 03:21:24 fyi, typically just namespace aura { class Window
denniskempin 2015/12/04 22:35:30 Done.
+
+namespace arc {
+
+class ArcBridgeService;
+
+// The ArcInputBridge is responsible for sending input events from ARC windows
+// to the ARC instance.
+// It hooks into aura::Env to watch for ExoSurface windows that are running ARC
+// applications. On those windows the input bridge will attach an EventPreTarget
+// to capture all input events.
+// To send those events to the ARC instance it will create bridge input devices
+// through the ArcBridgeService, which will provide a file descriptor to which
+// we can send linux input_event's.
+// ui::Events to the ARC windows are translated to linux input_event's, which
+// are then sent through the respective file descriptor.
+class ArcInputBridge : public ArcBridgeService::Observer,
+ public aura::EnvObserver,
+ public ui::EventHandler {
+ public:
+ // The constructor will register an Observer with aura::Env and the
+ // ArcBridgeService. From then on, no further interaction with this class
+ // is needed.
+ ArcInputBridge(
+ ArcBridgeService* arc_bridge_service,
+ const scoped_refptr<base::SingleThreadTaskRunner>& io_task_runner);
+ ~ArcInputBridge() override;
+
+ protected:
+ // 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 OnEvent(ui::Event* event) override;
reveman 2015/12/04 03:21:24 nit: I don't recommend inheriting a public functio
denniskempin 2015/12/04 22:35:30 Done.
+
+ // Attaches the input bridge to the window if it is marked as an ARC window.
+ void OnWindowInitialized(aura::Window* new_window) override;
reveman 2015/12/04 03:21:24 ditto
denniskempin 2015/12/04 22:35:30 Done.
+
+ private:
+ // Initialized the aura::EnvObserver on the ui message loop.
+ void InitializeAuraObserver();
+
+ void SendInputEventIO(scoped_ptr<ui::Event> event);
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+
+ // Specialized method to translate and send events to the right file
+ // descriptor
reveman 2015/12/04 03:21:24 nit: missing punctuation. also, does this comment
denniskempin 2015/12/04 22:35:30 close. 82. Added dot.
+ void SendKeyEventIO(ui::KeyEvent* event);
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+ void SendTouchEventIO(ui::TouchEvent* event);
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+ void SendMouseEventIO(ui::MouseEvent* event);
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+
+ // 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,
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+ 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);
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+
+ // Return existing or new slot for this event.
+ int AcquireTouchSlotIO(ui::TouchEvent* event);
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+
+ // Return touch slot for tracking id.
+ int FindTouchSlotIO(int tracking_id);
reveman 2015/12/04 03:21:24 nit: s/IO/OnIO/
denniskempin 2015/12/04 22:35:30 Done.
+
+ // ArcBridgeService::Observer:
+ void OnInstanceBootPhase(InstanceBootPhase phase) override;
reveman 2015/12/04 03:21:24 nit: avoid inheriting a public function as private
denniskempin 2015/12/04 22:35:30 Done.
+
+ // 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);
+
+ ArcBridgeService* arc_bridge_service_;
reveman 2015/12/04 03:21:24 it's not clear what members below are used on what
denniskempin 2015/12/04 22:35:30 Done.
+
+ // File descriptors for the different device types.
+ base::ScopedFD keyboard_fd_;
+ base::ScopedFD mouse_fd_;
+ base::ScopedFD touchscreen_fd_;
+
+ // Scroll accumlator.
+ float offset_x_acc;
jochen (gone - plz use gerrit) 2015/12/04 14:18:12 should end in _
denniskempin 2015/12/04 22:35:30 Done.
+ float offset_y_acc;
+
+ // 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_
reveman 2015/12/04 03:21:24 COMPONENTS_ARC_INPUT_ARC_INPUT_BRIDGE_H_
denniskempin 2015/12/04 22:35:30 Done.

Powered by Google App Engine
This is Rietveld 408576698