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 #include "content/browser/android/in_process/synchronous_input_event_filter.h"
7 #include "base/callback.h"
8 #include "cc/input/input_handler.h"
9 #include "content/browser/android/in_process/synchronous_compositor_impl.h"
10 #include "content/public/browser/browser_thread.h"
11 #include "ui/events/latency_info.h"
13 using blink::WebInputEvent;
17 SynchronousInputEventFilter::SynchronousInputEventFilter() {
20 SynchronousInputEventFilter::~SynchronousInputEventFilter() {
23 InputEventAckState SynchronousInputEventFilter::HandleInputEvent(
25 const blink::WebInputEvent& input_event) {
26 // The handler will be empty both before renderer initialization and after
27 // renderer destruction. It's possible that this will be reached in such a
28 // state. While not good, it should also not be fatal.
29 if (handler_.is_null())
30 return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
31 ui::LatencyInfo latency;
32 return handler_.Run(routing_id, &input_event, &latency);
35 void SynchronousInputEventFilter::SetBoundHandler(const Handler& handler) {
36 BrowserThread::PostTask(
37 BrowserThread::UI, FROM_HERE,
38 base::Bind(&SynchronousInputEventFilter::SetBoundHandlerOnUIThread,
39 base::Unretained(this), handler));
42 void SynchronousInputEventFilter::SetBoundHandlerOnUIThread(
43 const Handler& handler) {
44 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
48 void SynchronousInputEventFilter::DidAddInputHandler(
50 cc::InputHandler* input_handler) {
51 // The SynchronusCompositorImpl can be NULL if the WebContents that it's
52 // bound to has already been deleted.
53 SynchronousCompositorImpl* compositor =
54 SynchronousCompositorImpl::FromRoutingID(routing_id);
56 compositor->SetInputHandler(input_handler);
59 void SynchronousInputEventFilter::DidRemoveInputHandler(int routing_id) {
60 // The SynchronusCompositorImpl can be NULL if the WebContents that it's
61 // bound to has already been deleted.
62 SynchronousCompositorImpl* compositor =
63 SynchronousCompositorImpl::FromRoutingID(routing_id);
65 compositor->SetInputHandler(NULL);
68 void SynchronousInputEventFilter::DidOverscroll(
70 const DidOverscrollParams& params) {
71 // The SynchronusCompositorImpl can be NULL if the WebContents that it's
72 // bound to has already been deleted.
73 SynchronousCompositorImpl* compositor =
74 SynchronousCompositorImpl::FromRoutingID(routing_id);
76 compositor->DidOverscroll(params);
79 void SynchronousInputEventFilter::DidStopFlinging(int routing_id) {
80 // The SynchronusCompositorImpl can be NULL if the WebContents that it's
81 // bound to has already been deleted.
82 SynchronousCompositorImpl* compositor =
83 SynchronousCompositorImpl::FromRoutingID(routing_id);
85 compositor->DidStopFlinging();
88 } // namespace content