Chromium Code Reviews| Index: blimp/client/input/blimp_input_manager.h |
| diff --git a/blimp/client/input/blimp_input_manager.h b/blimp/client/input/blimp_input_manager.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..db4202e8ec6a4aa4059b0281a537279273fe748b |
| --- /dev/null |
| +++ b/blimp/client/input/blimp_input_manager.h |
| @@ -0,0 +1,132 @@ |
| +// 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 BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_ |
| +#define BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_ |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/single_thread_task_runner.h" |
| +#include "base/synchronization/waitable_event.h" |
| +#include "third_party/WebKit/public/web/WebInputEvent.h" |
| +#include "ui/events/blink/input_handler_proxy.h" |
| +#include "ui/events/blink/input_handler_proxy_client.h" |
| +#include "ui/events/gesture_detection/filtered_gesture_provider.h" |
| +#include "ui/events/gesture_detection/motion_event.h" |
| + |
| +namespace blimp { |
| + |
| +class BlimpInputManagerClient { |
| + public: |
| + virtual void SendWebInputEvent( |
| + const blink::WebInputEvent& input_event) = 0; |
| +}; |
| + |
| +// The BlimpInputManager handles input events for a specific render widget. The |
| +// class processes ui::events to generate web input events which are forwarded |
| +// to the compositor to be handled on the compositor thread. If the event can |
| +// not be handled locally by the compositor, it is given to the |
| +// BlimpInputManagerClient to be sent to the engine. |
| +// |
| +// The BlimpInputManager is created and destroyed on the main thread but can be |
| +// called from the main or compositor thread. It is safe for the |
| +// BlimpInputManager to be called on the compositor thread because: |
| +// 1) The only compositor threaded callers of the BlimpInputManager are the |
| +// BlimpInputManager itself. |
| +// 2) BlimpInputManager blocks the main thread to ensure the compositor-thread |
|
David Trainor- moved to gerrit
2015/12/03 16:14:04
Can you be a little more explicit that this is blo
Khushal
2015/12/04 21:54:51
Done.
|
| +// teardown in its dtor, so there is no risk of any queued tasks calling it on |
| +// the compositor thread after it has been deleted on the main thread. |
| +class BlimpInputManager : public ui::InputHandlerProxyClient, |
| + public ui::GestureProviderClient { |
| + public: |
| + static scoped_ptr<BlimpInputManager> Create( |
| + BlimpInputManagerClient* client, |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, |
| + const base::WeakPtr<cc::InputHandler>& input_handler); |
| + |
| + ~BlimpInputManager(); |
| + |
| + // Called to process a ui::MotionEvent. Returns true if the event was |
| + // successfully processed. |
| + bool OnTouchEvent(const ui::MotionEvent& motion_event); |
| + |
| + private: |
| + struct MainThreadOnly { |
| + BlimpInputManagerClient* client; |
| + ui::FilteredGestureProvider gesture_provider; |
| + |
| + base::WeakPtrFactory<BlimpInputManager> weak_factory; |
| + |
| + MainThreadOnly( |
| + BlimpInputManagerClient* client, |
| + BlimpInputManager* input_manager); |
| + ~MainThreadOnly(); |
| + }; |
| + |
| + struct CompositorThreadOnly { |
| + scoped_ptr<ui::InputHandlerProxy> input_handler_proxy; |
| + |
| + // Used to queue calls to the BlimpInputManager to be run on the main |
| + // thread. This ensures that any tasks queued are abandoned after the |
| + // BlimpInputManager is destroyed. |
| + base::WeakPtr<BlimpInputManager> input_manager_weak_ptr; |
| + |
| + CompositorThreadOnly(); |
| + ~CompositorThreadOnly(); |
| + }; |
| + |
| + BlimpInputManager( |
| + BlimpInputManagerClient* client, |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| + scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, |
| + const base::WeakPtr<cc::InputHandler>& input_handler); |
| + |
| + |
| + // InputHandlerProxyClient implementation. Called on the compositor thread. |
| + void WillShutdown() override; |
| + void TransferActiveWheelFlingAnimation( |
| + const blink::WebActiveWheelFlingParameters& params) override; |
| + blink::WebGestureCurve* CreateFlingAnimationCurve( |
| + blink::WebGestureDevice device_source, |
| + const blink::WebFloatPoint& velocity, |
| + const blink::WebSize& cumulative_scroll) override; |
| + void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, |
| + const gfx::Vector2dF& latest_overscroll_delta, |
| + const gfx::Vector2dF& current_fling_velocity, |
| + const gfx::PointF& causal_event_viewport_point) override; |
| + void DidStopFlinging() override; |
| + void DidAnimateForInput() override; |
| + |
| + // ui::GestureProviderClient implementation. Called on main thread. |
| + void OnGestureEvent(const ui::GestureEventData& gesture) override; |
| + |
| + void CreateInputHandlerProxyOnCompositorThread( |
| + base::WeakPtr<BlimpInputManager> input_manager_weak_ptr, |
| + const base::WeakPtr<cc::InputHandler>& input_handler); |
| + void HandleWebInputEventOnCompositorThread( |
| + const blink::WebInputEvent& input_event); |
| + void ShutdownOnCompositorThread(base::WaitableEvent* shutdown_event); |
| + void SendWebInputEvent(const blink::WebInputEvent& input_event); |
| + |
| + bool IsMainThread() const; |
| + bool IsCompositorThread() const; |
| + |
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| + scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; |
| + |
| + bool main_thread_blocked_; |
|
David Trainor- moved to gerrit
2015/12/03 16:14:04
Can you put a comment on how/where this is expecte
Khushal
2015/12/04 21:54:51
Done. Though, I'm not sure if its necessary. We co
|
| + |
| + MainThreadOnly main_thread_vars_unsafe_; |
| + MainThreadOnly& main(); |
| + |
| + CompositorThreadOnly compositor_thread_vars_unsafe_; |
| + CompositorThreadOnly& compositor(); |
| + |
| + DISALLOW_COPY_AND_ASSIGN(BlimpInputManager); |
| +}; |
| + |
| +} // namespace blimp |
| + |
| +#endif // BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_ |