| Index: blimp/client/input/blimp_input_manager.cc
|
| diff --git a/blimp/client/input/blimp_input_manager.cc b/blimp/client/input/blimp_input_manager.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..cec668f76318751ee4af2e01966ea85f189b4988
|
| --- /dev/null
|
| +++ b/blimp/client/input/blimp_input_manager.cc
|
| @@ -0,0 +1,230 @@
|
| +// Copyright 2015 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 "blimp/client/input/blimp_input_manager.h"
|
| +
|
| +#include "base/auto_reset.h"
|
| +#include "base/bind.h"
|
| +#include "base/location.h"
|
| +#include "ui/events/blink/blink_event_util.h"
|
| +#include "ui/events/gesture_detection/gesture_provider_config_helper.h"
|
| +#include "ui/events/gestures/blink/web_gesture_curve_impl.h"
|
| +
|
| +namespace blimp {
|
| +
|
| +BlimpInputManager::MainThreadOnly::MainThreadOnly(
|
| + BlimpInputManagerClient* client,
|
| + BlimpInputManager* input_manager)
|
| + : client(client),
|
| + gesture_provider(ui::GetGestureProviderConfig(
|
| + ui::GestureProviderConfigType::CURRENT_PLATFORM),
|
| + input_manager),
|
| + weak_factory(input_manager) {
|
| + DCHECK(client);
|
| +}
|
| +
|
| +BlimpInputManager::MainThreadOnly::~MainThreadOnly() {}
|
| +
|
| +BlimpInputManager::CompositorThreadOnly::CompositorThreadOnly() {}
|
| +
|
| +BlimpInputManager::CompositorThreadOnly::~CompositorThreadOnly() {}
|
| +
|
| +scoped_ptr<BlimpInputManager> BlimpInputManager::Create(
|
| + BlimpInputManagerClient* client,
|
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
|
| + const base::WeakPtr<cc::InputHandler>& input_handler) {
|
| + return make_scoped_ptr(new BlimpInputManager(client,
|
| + main_task_runner,
|
| + compositor_task_runner,
|
| + input_handler));
|
| +}
|
| +
|
| +BlimpInputManager::BlimpInputManager(
|
| + BlimpInputManagerClient* client,
|
| + scoped_refptr<base::SingleThreadTaskRunner> main_task_runner,
|
| + scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner,
|
| + const base::WeakPtr<cc::InputHandler>& input_handler)
|
| + : main_task_runner_(main_task_runner),
|
| + compositor_task_runner_(compositor_task_runner),
|
| + main_thread_blocked_(false),
|
| + main_thread_vars_unsafe_(client, this) {
|
| + DCHECK(IsMainThread());
|
| + compositor_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &BlimpInputManager::CreateInputHandlerProxyOnCompositorThread,
|
| + base::Unretained(this), main().weak_factory.GetWeakPtr(),
|
| + input_handler));
|
| +}
|
| +
|
| +BlimpInputManager::~BlimpInputManager() {
|
| + DCHECK(IsMainThread());
|
| +
|
| + base::WaitableEvent shutdown_event(false /* manual_reset */,
|
| + false /* initially_signaled */);
|
| + base::AutoReset<bool> auto_reset_main_thread_blocked(
|
| + &main_thread_blocked_, true);
|
| + compositor_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &BlimpInputManager::ShutdownOnCompositorThread,
|
| + base::Unretained(this), &shutdown_event));
|
| + shutdown_event.Wait();
|
| +}
|
| +
|
| +bool BlimpInputManager::OnTouchEvent(const ui::MotionEvent& motion_event) {
|
| + DCHECK(IsMainThread());
|
| +
|
| + ui::FilteredGestureProvider::TouchHandlingResult result =
|
| + main().gesture_provider.OnTouchEvent(motion_event);
|
| + if (!result.succeeded)
|
| + return false;
|
| +
|
| + blink::WebTouchEvent touch =
|
| + ui::CreateWebTouchEventFromMotionEvent(motion_event,
|
| + result.did_generate_scroll);
|
| +
|
| + // Touch events are queued in the Gesture Provider until acknowledged to
|
| + // allow them to be consumed by the touch event handlers in blink which can
|
| + // prevent-default on the event. Since we currently do not support touch
|
| + // handlers the event is always acknowledged as not consumed.
|
| + main().gesture_provider.OnTouchEventAck(touch.uniqueTouchEventId, false);
|
| +
|
| + return true;
|
| +}
|
| +
|
| +void BlimpInputManager::WillShutdown() {
|
| + DCHECK(IsCompositorThread());
|
| +
|
| + compositor().input_handler_proxy.reset();
|
| +}
|
| +
|
| +void BlimpInputManager::TransferActiveWheelFlingAnimation(
|
| + const blink::WebActiveWheelFlingParameters& params) {
|
| + DCHECK(IsCompositorThread());
|
| +
|
| + NOTIMPLEMENTED() <<
|
| + "Transferring Fling Animations to the engine is not supported";
|
| +}
|
| +
|
| +blink::WebGestureCurve* BlimpInputManager::CreateFlingAnimationCurve(
|
| + blink::WebGestureDevice device_source,
|
| + const blink::WebFloatPoint& velocity,
|
| + const blink::WebSize& cumulative_scroll) {
|
| + DCHECK(IsCompositorThread());
|
| +
|
| + return ui::WebGestureCurveImpl::CreateFromDefaultPlatformCurve(
|
| + gfx::Vector2dF(velocity.x, velocity.y),
|
| + gfx::Vector2dF(cumulative_scroll.width,
|
| + cumulative_scroll.height),
|
| + false /* on_main_thread */).release();
|
| +}
|
| +
|
| +void BlimpInputManager::DidOverscroll(
|
| + const gfx::Vector2dF& accumulated_overscroll,
|
| + const gfx::Vector2dF& latest_overscroll_delta,
|
| + const gfx::Vector2dF& current_fling_velocity,
|
| + const gfx::PointF& causal_event_viewport_point) {
|
| + DCHECK(IsCompositorThread());
|
| +}
|
| +
|
| +void BlimpInputManager::DidStopFlinging() {
|
| + DCHECK(IsCompositorThread());
|
| +}
|
| +
|
| +void BlimpInputManager::DidAnimateForInput() {
|
| + DCHECK(IsCompositorThread());
|
| +}
|
| +
|
| +void BlimpInputManager::OnGestureEvent(const ui::GestureEventData& gesture) {
|
| + DCHECK(IsMainThread());
|
| +
|
| + blink::WebGestureEvent web_gesture =
|
| + ui::CreateWebGestureEventFromGestureEventData(gesture);
|
| + // TODO(jdduke): Remove this workaround after Android fixes UiAutomator to
|
| + // stop providing shift meta values to synthetic MotionEvents. This prevents
|
| + // unintended shift+click interpretation of all accessibility clicks.
|
| + // See crbug.com/443247.
|
| + if (web_gesture.type == blink::WebInputEvent::GestureTap &&
|
| + web_gesture.modifiers == blink::WebInputEvent::ShiftKey) {
|
| + web_gesture.modifiers = 0;
|
| + }
|
| +
|
| + compositor_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(
|
| + &BlimpInputManager::HandleWebInputEventOnCompositorThread,
|
| + base::Unretained(this), web_gesture));
|
| +}
|
| +
|
| +void BlimpInputManager::CreateInputHandlerProxyOnCompositorThread(
|
| + base::WeakPtr<BlimpInputManager> input_manager_weak_ptr,
|
| + const base::WeakPtr<cc::InputHandler>& input_handler) {
|
| + DCHECK(IsCompositorThread());
|
| +
|
| + // The input_handler might have been destroyed at this point.
|
| + if (!input_handler)
|
| + return;
|
| +
|
| + DCHECK(!compositor().input_handler_proxy);
|
| + compositor().input_handler_proxy =
|
| + make_scoped_ptr(new ui::InputHandlerProxy(input_handler.get(), this));
|
| + compositor().input_manager_weak_ptr = input_manager_weak_ptr;
|
| +}
|
| +
|
| +void BlimpInputManager::HandleWebInputEventOnCompositorThread(
|
| + const blink::WebInputEvent& input_event) {
|
| + DCHECK(IsCompositorThread());
|
| +
|
| + // We might not have the input handler proxy anymore.
|
| + if (!compositor().input_handler_proxy)
|
| + return;
|
| +
|
| + ui::InputHandlerProxy::EventDisposition disposition =
|
| + compositor().input_handler_proxy->HandleInputEvent(input_event);
|
| +
|
| + if (disposition == ui::InputHandlerProxy::DID_NOT_HANDLE) {
|
| + main_task_runner_->PostTask(
|
| + FROM_HERE,
|
| + base::Bind(&BlimpInputManager::SendWebInputEvent,
|
| + compositor().input_manager_weak_ptr, input_event));
|
| + }
|
| +}
|
| +
|
| +void BlimpInputManager::ShutdownOnCompositorThread(
|
| + base::WaitableEvent* shutdown_event) {
|
| + DCHECK(IsCompositorThread());
|
| + DCHECK(main_thread_blocked_);
|
| +
|
| + DCHECK(!compositor().input_handler_proxy);
|
| + shutdown_event->Signal();
|
| +}
|
| +
|
| +void BlimpInputManager::SendWebInputEvent(
|
| + const blink::WebInputEvent& input_event) {
|
| + DCHECK(IsMainThread());
|
| +
|
| + main().client->SendWebInputEvent(input_event);
|
| +}
|
| +
|
| +bool BlimpInputManager::IsMainThread() const {
|
| + return main_task_runner_->BelongsToCurrentThread();
|
| +}
|
| +
|
| +bool BlimpInputManager::IsCompositorThread() const {
|
| + return compositor_task_runner_->BelongsToCurrentThread();
|
| +}
|
| +
|
| +BlimpInputManager::MainThreadOnly& BlimpInputManager::main() {
|
| + DCHECK(IsMainThread());
|
| + return main_thread_vars_unsafe_;
|
| +}
|
| +
|
| +BlimpInputManager::CompositorThreadOnly& BlimpInputManager::compositor() {
|
| + DCHECK(IsCompositorThread());
|
| + return compositor_thread_vars_unsafe_;
|
| +}
|
| +
|
| +} // namespace blimp
|
|
|