OLD | NEW |
| (Empty) |
1 // Copyright 2011 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_CORE_INPUT_BLIMP_INPUT_HANDLER_WRAPPER_H_ | |
6 #define BLIMP_CLIENT_CORE_INPUT_BLIMP_INPUT_HANDLER_WRAPPER_H_ | |
7 | |
8 #include "base/macros.h" | |
9 #include "base/memory/weak_ptr.h" | |
10 #include "base/single_thread_task_runner.h" | |
11 #include "base/threading/thread_checker.h" | |
12 #include "ui/events/blink/input_handler_proxy.h" | |
13 #include "ui/events/blink/input_handler_proxy_client.h" | |
14 | |
15 namespace cc { | |
16 class InputHandler; | |
17 } // namespace cc | |
18 | |
19 namespace blimp { | |
20 namespace client { | |
21 | |
22 class BlimpInputManager; | |
23 | |
24 // The BlimpInputHandlerWrapper isolates all input handling processing done on | |
25 // the compositor thread from the BlimpInputManager. It takes web gesture events | |
26 // from the BlimpInputManager and sends them to the ui::InputHandlerProxy. | |
27 // The class is created on the main thread, but becomes bound to the compositor | |
28 // thread when it binds to the ui::InputHandlerProxy, and should only be called | |
29 // on the compositor thread. | |
30 // The creater of this class ensures that the cc::InputHandler is destroyed | |
31 // before this class is destroyed. This is necessary to ensure that the | |
32 // compositor thread components of this class, i.e., the ui::InputHandlerProxy | |
33 // and any weak ptrs dispensed for posting tasks to the class on the compositor | |
34 // thread, are destroyed before the class is destroyed on the main thread. | |
35 class BlimpInputHandlerWrapper : public ui::InputHandlerProxyClient { | |
36 public: | |
37 BlimpInputHandlerWrapper( | |
38 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
39 base::SingleThreadTaskRunner* compositor_task_runner, | |
40 const base::WeakPtr<BlimpInputManager> input_manager_weak_ptr, | |
41 const base::WeakPtr<cc::InputHandler>& input_handler_weak_ptr); | |
42 | |
43 ~BlimpInputHandlerWrapper() override; | |
44 | |
45 // Called by the BlimpInputManager to process a web gesture event. This will | |
46 // call BlimpInputManager::HandleWebGestureEvent with the result on the main | |
47 // thread. | |
48 void HandleWebGestureEvent(const blink::WebGestureEvent& gesture_event); | |
49 | |
50 void InitOnCompositorThread(cc::InputHandler* input_handler); | |
51 | |
52 private: | |
53 // InputHandlerProxyClient implementation. | |
54 void WillShutdown() override; | |
55 void TransferActiveWheelFlingAnimation( | |
56 const blink::WebActiveWheelFlingParameters& params) override; | |
57 void DispatchNonBlockingEventToMainThread( | |
58 blink::WebScopedInputEvent event, | |
59 const ui::LatencyInfo& latency_info) override; | |
60 blink::WebGestureCurve* CreateFlingAnimationCurve( | |
61 blink::WebGestureDevice device_source, | |
62 const blink::WebFloatPoint& velocity, | |
63 const blink::WebSize& cumulative_scroll) override; | |
64 void DidOverscroll(const gfx::Vector2dF& accumulated_overscroll, | |
65 const gfx::Vector2dF& latest_overscroll_delta, | |
66 const gfx::Vector2dF& current_fling_velocity, | |
67 const gfx::PointF& causal_event_viewport_point) override; | |
68 void DidStopFlinging() override; | |
69 void DidAnimateForInput() override; | |
70 | |
71 base::ThreadChecker compositor_thread_checker_; | |
72 | |
73 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | |
74 | |
75 // Used to queue calls to the BlimpInputManager to be run on the main | |
76 // thread. This ensures that any tasks queued are abandoned after the | |
77 // BlimpInputManager is destroyed. | |
78 base::WeakPtr<BlimpInputManager> input_manager_weak_ptr_; | |
79 | |
80 std::unique_ptr<ui::InputHandlerProxy> input_handler_proxy_; | |
81 | |
82 // Used to dispense weak ptrs to post tasks to the wrapper on the compositor | |
83 // thread. The weak ptrs created using this factory will be invalidated in | |
84 // WillShutdown. This method is called on the compositor thread when the | |
85 // InputHandlerProxy is being terminated. The wrapper does not need to be used | |
86 // beyond this point. | |
87 base::WeakPtrFactory<BlimpInputHandlerWrapper> weak_factory_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(BlimpInputHandlerWrapper); | |
90 }; | |
91 | |
92 } // namespace client | |
93 } // namespace blimp | |
94 | |
95 #endif // BLIMP_CLIENT_CORE_INPUT_BLIMP_INPUT_HANDLER_WRAPPER_H_ | |
OLD | NEW |