OLD | NEW |
| (Empty) |
1 // Copyright 2015 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 #include "blimp/client/core/input/blimp_input_manager.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/location.h" | |
9 #include "base/memory/ptr_util.h" | |
10 #include "blimp/client/core/input/blimp_input_handler_wrapper.h" | |
11 #include "ui/events/blink/blink_event_util.h" | |
12 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | |
13 | |
14 namespace blimp { | |
15 namespace client { | |
16 | |
17 std::unique_ptr<BlimpInputManager> BlimpInputManager::Create( | |
18 BlimpInputManagerClient* client, | |
19 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
20 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | |
21 const base::WeakPtr<cc::InputHandler>& input_handler) { | |
22 return base::WrapUnique(new BlimpInputManager( | |
23 client, main_task_runner, compositor_task_runner, input_handler)); | |
24 } | |
25 | |
26 BlimpInputManager::BlimpInputManager( | |
27 BlimpInputManagerClient* client, | |
28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | |
29 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | |
30 const base::WeakPtr<cc::InputHandler>& input_handler) | |
31 : client_(client), | |
32 gesture_provider_(ui::GetGestureProviderConfig( | |
33 ui::GestureProviderConfigType::CURRENT_PLATFORM), | |
34 this), | |
35 compositor_task_runner_(std::move(compositor_task_runner)), | |
36 weak_factory_(this) { | |
37 DCHECK(thread_checker_.CalledOnValidThread()); | |
38 input_handler_wrapper_ = base::MakeUnique<BlimpInputHandlerWrapper>( | |
39 main_task_runner, compositor_task_runner_.get(), | |
40 weak_factory_.GetWeakPtr(), input_handler); | |
41 } | |
42 | |
43 BlimpInputManager::~BlimpInputManager() { | |
44 DCHECK(thread_checker_.CalledOnValidThread()); | |
45 } | |
46 | |
47 bool BlimpInputManager::OnTouchEvent(const ui::MotionEvent& motion_event) { | |
48 DCHECK(thread_checker_.CalledOnValidThread()); | |
49 | |
50 ui::FilteredGestureProvider::TouchHandlingResult result = | |
51 gesture_provider_.OnTouchEvent(motion_event); | |
52 if (!result.succeeded) | |
53 return false; | |
54 | |
55 blink::WebTouchEvent touch = ui::CreateWebTouchEventFromMotionEvent( | |
56 motion_event, result.moved_beyond_slop_region); | |
57 | |
58 // Touch events are queued in the Gesture Provider until acknowledged to | |
59 // allow them to be consumed by the touch event handlers in blink which can | |
60 // prevent-default on the event. Since we currently do not support touch | |
61 // handlers the event is always acknowledged as not consumed. | |
62 gesture_provider_.OnTouchEventAck(touch.uniqueTouchEventId, false); | |
63 | |
64 return true; | |
65 } | |
66 | |
67 void BlimpInputManager::OnInputHandlerWrapperInitialized( | |
68 base::WeakPtr<BlimpInputHandlerWrapper> input_handler_wrapper_weak_ptr) { | |
69 DCHECK(thread_checker_.CalledOnValidThread()); | |
70 input_handler_wrapper_weak_ptr_ = input_handler_wrapper_weak_ptr; | |
71 } | |
72 | |
73 void BlimpInputManager::OnGestureEvent(const ui::GestureEventData& gesture) { | |
74 DCHECK(thread_checker_.CalledOnValidThread()); | |
75 | |
76 blink::WebGestureEvent web_gesture = | |
77 ui::CreateWebGestureEventFromGestureEventData(gesture); | |
78 // TODO(khushalsagar): Remove this workaround after Android fixes UiAutomator | |
79 // to stop providing shift meta values to synthetic MotionEvents. This | |
80 // prevents unintended shift+click interpretation of all accessibility clicks. | |
81 // See crbug.com/443247. | |
82 if (web_gesture.type == blink::WebInputEvent::GestureTap && | |
83 web_gesture.modifiers == blink::WebInputEvent::ShiftKey) { | |
84 web_gesture.setModifiers(blink::WebInputEvent::NoModifiers); | |
85 } | |
86 | |
87 compositor_task_runner_->PostTask( | |
88 FROM_HERE, base::Bind(&BlimpInputHandlerWrapper::HandleWebGestureEvent, | |
89 input_handler_wrapper_weak_ptr_, web_gesture)); | |
90 } | |
91 | |
92 void BlimpInputManager::DidHandleWebGestureEvent( | |
93 const blink::WebGestureEvent& gesture_event, | |
94 bool consumed) { | |
95 DCHECK(thread_checker_.CalledOnValidThread()); | |
96 | |
97 if (!consumed) | |
98 client_->SendWebGestureEvent(gesture_event); | |
99 } | |
100 | |
101 } // namespace client | |
102 } // namespace blimp | |
OLD | NEW |