| Index: content/browser/android/in_process/synchronous_input_event_filter.cc
|
| diff --git a/content/browser/android/in_process/synchronous_input_event_filter.cc b/content/browser/android/in_process/synchronous_input_event_filter.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..ea5e6f162a6f22109b4a8fb1c7c38bf4e1a32efb
|
| --- /dev/null
|
| +++ b/content/browser/android/in_process/synchronous_input_event_filter.cc
|
| @@ -0,0 +1,67 @@
|
| +// Copyright (c) 2012 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.
|
| +
|
| +#include "content/browser/android/in_process/synchronous_input_event_filter.h"
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/logging.h"
|
| +#include "content/public/browser/browser_thread.h"
|
| +
|
| +using WebKit::WebInputEvent;
|
| +
|
| +namespace content {
|
| +
|
| +SynchronousInputEventFilter::SynchronousInputEventFilter()
|
| + : handle_input_event_result_(NULL) {
|
| +}
|
| +
|
| +SynchronousInputEventFilter::~SynchronousInputEventFilter() {
|
| +}
|
| +
|
| +InputEventAckState SynchronousInputEventFilter::HandleInputEvent(
|
| + int routing_id,
|
| + const WebKit::WebInputEvent* input_event) {
|
| + // The handler will be empty both before renderer initialization and after
|
| + // renderer destruction. It's possible that this will be reached in such a
|
| + // state. While not good, it should also not be fatal.
|
| + if (handler_.is_null())
|
| + return INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
|
| +
|
| + InputEventAckState result = INPUT_EVENT_ACK_STATE_UNKNOWN;
|
| + handle_input_event_result_ = &result;
|
| +
|
| + // It is expected that handler_ initiates a synchronous callback to
|
| + // Did/DidNotHandleInputEvent.
|
| + handler_.Run(routing_id, input_event);
|
| + DCHECK(result != INPUT_EVENT_ACK_STATE_UNKNOWN);
|
| +
|
| + handle_input_event_result_ = NULL;
|
| + return result;
|
| +}
|
| +
|
| +void SynchronousInputEventFilter::SetHandler(const Handler& handler) {
|
| + BrowserThread::GetMessageLoopProxyForThread(BrowserThread::UI)->
|
| + PostTask(FROM_HERE,
|
| + base::Bind(&SynchronousInputEventFilter::SetHandlerOnUIThread,
|
| + base::Unretained(this),
|
| + handler));
|
| +}
|
| +
|
| +void SynchronousInputEventFilter::DidHandleInputEvent() {
|
| + DCHECK(handle_input_event_result_);
|
| + *handle_input_event_result_ = INPUT_EVENT_ACK_STATE_CONSUMED;
|
| +}
|
| +
|
| +void SynchronousInputEventFilter::DidNotHandleInputEvent(bool send_to_widget) {
|
| + DCHECK(handle_input_event_result_);
|
| + *handle_input_event_result_ =
|
| + send_to_widget ? INPUT_EVENT_ACK_STATE_NOT_CONSUMED
|
| + : INPUT_EVENT_ACK_STATE_NO_CONSUMER_EXISTS;
|
| +}
|
| +
|
| +void SynchronousInputEventFilter::SetHandlerOnUIThread(const Handler& handler) {
|
| + handler_ = handler;
|
| +}
|
| +
|
| +} // namespace content
|
|
|