Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 | |
| 5 #ifndef BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_ | |
| 6 #define BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_ | |
| 7 | |
| 8 #include "base/macros.h" | |
| 9 #include "base/memory/scoped_ptr.h" | |
| 10 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/synchronization/waitable_event.h" | |
| 12 #include "third_party/WebKit/public/web/WebInputEvent.h" | |
| 13 #include "ui/events/blink/input_handler_proxy.h" | |
| 14 #include "ui/events/blink/input_handler_proxy_client.h" | |
| 15 #include "ui/events/gesture_detection/filtered_gesture_provider.h" | |
| 16 #include "ui/events/gesture_detection/motion_event.h" | |
| 17 | |
| 18 namespace blimp { | |
| 19 | |
| 20 class BlimpInputManagerClient { | |
| 21 public: | |
| 22 virtual void SendWebInputEvent( | |
| 23 const blink::WebInputEvent& input_event) = 0; | |
| 24 }; | |
| 25 | |
| 26 // The BlimpInputManager handles input events for a specific render widget. The | |
| 27 // class processes ui::events to generate web input events which are forwarded | |
| 28 // to the compositor to be handled on the compositor thread. If the event can | |
| 29 // not be handled locally by the compositor, it is given to the | |
| 30 // BlimpInputManagerClient to be sent to the engine. | |
| 31 // | |
| 32 // The BlimpInputManager is created and destroyed on the main thread but can be | |
| 33 // called from the main or compositor thread. It is safe for the | |
| 34 // BlimpInputManager to be called on the compositor thread because: | |
| 35 // 1) The only compositor threaded callers of the BlimpInputManager are the | |
| 36 // BlimpInputManager itself. | |
| 37 // 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.
| |
| 38 // teardown in its dtor, so there is no risk of any queued tasks calling it on | |
| 39 // the compositor thread after it has been deleted on the main thread. | |
| 40 class BlimpInputManager : public ui::InputHandlerProxyClient, | |
| 41 public ui::GestureProviderClient { | |
| 42 public: | |
| 43 static scoped_ptr<BlimpInputManager> Create( | |
| 44 BlimpInputManagerClient* client, | |
| 45 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 46 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | |
| 47 const base::WeakPtr<cc::InputHandler>& input_handler); | |
| 48 | |
| 49 ~BlimpInputManager(); | |
| 50 | |
| 51 // Called to process a ui::MotionEvent. Returns true if the event was | |
| 52 // successfully processed. | |
| 53 bool OnTouchEvent(const ui::MotionEvent& motion_event); | |
| 54 | |
| 55 private: | |
| 56 struct MainThreadOnly { | |
| 57 BlimpInputManagerClient* client; | |
| 58 ui::FilteredGestureProvider gesture_provider; | |
| 59 | |
| 60 base::WeakPtrFactory<BlimpInputManager> weak_factory; | |
| 61 | |
| 62 MainThreadOnly( | |
| 63 BlimpInputManagerClient* client, | |
| 64 BlimpInputManager* input_manager); | |
| 65 ~MainThreadOnly(); | |
| 66 }; | |
| 67 | |
| 68 struct CompositorThreadOnly { | |
| 69 scoped_ptr<ui::InputHandlerProxy> input_handler_proxy; | |
| 70 | |
| 71 // Used to queue calls to the BlimpInputManager to be run on the main | |
| 72 // thread. This ensures that any tasks queued are abandoned after the | |
| 73 // BlimpInputManager is destroyed. | |
| 74 base::WeakPtr<BlimpInputManager> input_manager_weak_ptr; | |
| 75 | |
| 76 CompositorThreadOnly(); | |
| 77 ~CompositorThreadOnly(); | |
| 78 }; | |
| 79 | |
| 80 BlimpInputManager( | |
| 81 BlimpInputManagerClient* client, | |
| 82 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
| 83 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | |
| 84 const base::WeakPtr<cc::InputHandler>& input_handler); | |
| 85 | |
| 86 | |
| 87 // InputHandlerProxyClient implementation. Called on the compositor thread. | |
| 88 void WillShutdown() override; | |
| 89 void TransferActiveWheelFlingAnimation( | |
| 90 const blink::WebActiveWheelFlingParameters& params) override; | |
| 91 blink::WebGestureCurve* CreateFlingAnimationCurve( | |
| 92 blink::WebGestureDevice device_source, | |
| 93 const blink::WebFloatPoint& velocity, | |
| 94 const blink::WebSize& cumulative_scroll) override; | |
| 95 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, | |
| 96 const gfx::Vector2dF& latest_overscroll_delta, | |
| 97 const gfx::Vector2dF& current_fling_velocity, | |
| 98 const gfx::PointF& causal_event_viewport_point) override; | |
| 99 void DidStopFlinging() override; | |
| 100 void DidAnimateForInput() override; | |
| 101 | |
| 102 // ui::GestureProviderClient implementation. Called on main thread. | |
| 103 void OnGestureEvent(const ui::GestureEventData& gesture) override; | |
| 104 | |
| 105 void CreateInputHandlerProxyOnCompositorThread( | |
| 106 base::WeakPtr<BlimpInputManager> input_manager_weak_ptr, | |
| 107 const base::WeakPtr<cc::InputHandler>& input_handler); | |
| 108 void HandleWebInputEventOnCompositorThread( | |
| 109 const blink::WebInputEvent& input_event); | |
| 110 void ShutdownOnCompositorThread(base::WaitableEvent* shutdown_event); | |
| 111 void SendWebInputEvent(const blink::WebInputEvent& input_event); | |
| 112 | |
| 113 bool IsMainThread() const; | |
| 114 bool IsCompositorThread() const; | |
| 115 | |
| 116 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
| 117 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner_; | |
| 118 | |
| 119 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
| |
| 120 | |
| 121 MainThreadOnly main_thread_vars_unsafe_; | |
| 122 MainThreadOnly& main(); | |
| 123 | |
| 124 CompositorThreadOnly compositor_thread_vars_unsafe_; | |
| 125 CompositorThreadOnly& compositor(); | |
| 126 | |
| 127 DISALLOW_COPY_AND_ASSIGN(BlimpInputManager); | |
| 128 }; | |
| 129 | |
| 130 } // namespace blimp | |
| 131 | |
| 132 #endif // BLIMP_CLIENT_INPUT_BLIMP_INPUT_MANAGER_H_ | |
| OLD | NEW |