Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / renderer / input / input_handler_manager.h
blob130fc97e702cd2501558712bcce4cbb86e4912c0
1 // Copyright 2013 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.
5 #ifndef CONTENT_RENDERER_INPUT_INPUT_HANDLER_MANAGER_H_
6 #define CONTENT_RENDERER_INPUT_INPUT_HANDLER_MANAGER_H_
8 #include "base/containers/scoped_ptr_hash_map.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/weak_ptr.h"
11 #include "content/common/input/input_event_ack_state.h"
12 #include "content/renderer/render_view_impl.h"
14 namespace base {
15 class MessageLoopProxy;
18 namespace cc {
19 class InputHandler;
20 struct InputHandlerScrollResult;
23 namespace blink {
24 class WebInputEvent;
25 class WebMouseWheelEvent;
28 namespace content {
30 class InputHandlerWrapper;
31 class InputHandlerManagerClient;
32 struct DidOverscrollParams;
33 class RendererScheduler;
35 // InputHandlerManager class manages InputHandlerProxy instances for
36 // the WebViews in this renderer.
37 class InputHandlerManager {
38 public:
39 // |message_loop_proxy| is the MessageLoopProxy of the compositor thread. The
40 // underlying MessageLoop and supplied |client| and the |renderer_scheduler|
41 // must outlive this object. The RendererScheduler needs to know when input
42 // events and fling animations occur, which is why it's passed in here.
43 InputHandlerManager(
44 const scoped_refptr<base::MessageLoopProxy>& message_loop_proxy,
45 InputHandlerManagerClient* client,
46 RendererScheduler* renderer_scheduler);
47 ~InputHandlerManager();
49 // Callable from the main thread only.
50 void AddInputHandler(
51 int routing_id,
52 const base::WeakPtr<cc::InputHandler>& input_handler,
53 const base::WeakPtr<RenderViewImpl>& render_view_impl);
55 void ObserveWheelEventAndResultOnMainThread(
56 int routing_id,
57 const blink::WebMouseWheelEvent& wheel_event,
58 const cc::InputHandlerScrollResult& scroll_result);
60 // Callback only from the compositor's thread.
61 void RemoveInputHandler(int routing_id);
63 // Called from the compositor's thread.
64 InputEventAckState HandleInputEvent(int routing_id,
65 const blink::WebInputEvent* input_event,
66 ui::LatencyInfo* latency_info);
68 // Called from the compositor's thread.
69 void DidOverscroll(int routing_id, const DidOverscrollParams& params);
71 // Called from the compositor's thread.
72 void DidStopFlinging(int routing_id);
74 // Called from the compositor's thread.
75 void DidReceiveInputEvent(const blink::WebInputEvent& web_input_event);
77 // Called from the compositor's thread.
78 void DidAnimateForInput();
80 private:
81 // Called from the compositor's thread.
82 void AddInputHandlerOnCompositorThread(
83 int routing_id,
84 const scoped_refptr<base::MessageLoopProxy>& main_loop,
85 const base::WeakPtr<cc::InputHandler>& input_handler,
86 const base::WeakPtr<RenderViewImpl>& render_view_impl);
88 void ObserveWheelEventAndResultOnCompositorThread(
89 int routing_id,
90 const blink::WebMouseWheelEvent& wheel_event,
91 const cc::InputHandlerScrollResult& scroll_result);
93 typedef base::ScopedPtrHashMap<int, // routing_id
94 InputHandlerWrapper> InputHandlerMap;
95 InputHandlerMap input_handlers_;
97 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
98 InputHandlerManagerClient* client_;
99 RendererScheduler* renderer_scheduler_; // Not owned.
102 } // namespace content
104 #endif // CONTENT_RENDERER_INPUT_INPUT_HANDLER_MANAGER_H_