| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "blimp/client/feature/compositor/blimp_input_manager.h" | 5 #include "blimp/client/core/input/blimp_input_manager.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/location.h" | 9 #include "base/location.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/single_thread_task_runner.h" |
| 12 #include "base/synchronization/waitable_event.h" |
| 13 #include "blimp/client/core/input/blimp_input_handler_wrapper.h" |
| 14 #include "cc/input/input_handler.h" |
| 15 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 11 #include "ui/events/blink/blink_event_util.h" | 16 #include "ui/events/blink/blink_event_util.h" |
| 12 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 17 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
| 18 #include "ui/events/gesture_detection/motion_event.h" |
| 13 | 19 |
| 14 namespace blimp { | 20 namespace blimp { |
| 15 namespace client { | 21 namespace client { |
| 16 | 22 |
| 17 std::unique_ptr<BlimpInputManager> BlimpInputManager::Create( | 23 std::unique_ptr<BlimpInputManager> BlimpInputManager::Create( |
| 18 BlimpInputManagerClient* client, | 24 BlimpInputManagerClient* client, |
| 19 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 25 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | 26 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, |
| 21 const base::WeakPtr<cc::InputHandler>& input_handler) { | 27 const base::WeakPtr<cc::InputHandler>& input_handler) { |
| 22 return base::WrapUnique(new BlimpInputManager( | 28 return base::WrapUnique(new BlimpInputManager( |
| 23 client, main_task_runner, compositor_task_runner, input_handler)); | 29 client, main_task_runner, compositor_task_runner, input_handler)); |
| 24 } | 30 } |
| 25 | 31 |
| 26 BlimpInputManager::BlimpInputManager( | 32 BlimpInputManager::BlimpInputManager( |
| 27 BlimpInputManagerClient* client, | 33 BlimpInputManagerClient* client, |
| 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 34 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 29 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | 35 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, |
| 30 const base::WeakPtr<cc::InputHandler>& input_handler) | 36 const base::WeakPtr<cc::InputHandler>& input_handler) |
| 31 : client_(client), | 37 : client_(client), |
| 32 gesture_provider_(ui::GetGestureProviderConfig( | 38 gesture_provider_(ui::GetGestureProviderConfig( |
| 33 ui::GestureProviderConfigType::CURRENT_PLATFORM), this), | 39 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
| 40 this), |
| 34 main_task_runner_(main_task_runner), | 41 main_task_runner_(main_task_runner), |
| 35 compositor_task_runner_(compositor_task_runner), | 42 compositor_task_runner_(compositor_task_runner), |
| 36 main_thread_blocked_(false), | 43 main_thread_blocked_(false), |
| 37 weak_factory_(this) { | 44 weak_factory_(this) { |
| 38 DCHECK(IsMainThread()); | 45 DCHECK(IsMainThread()); |
| 39 compositor_task_runner_->PostTask( | 46 compositor_task_runner_->PostTask( |
| 40 FROM_HERE, | 47 FROM_HERE, |
| 41 base::Bind( | 48 base::Bind( |
| 42 &BlimpInputManager::CreateInputHandlerWrapperOnCompositorThread, | 49 &BlimpInputManager::CreateInputHandlerWrapperOnCompositorThread, |
| 43 base::Unretained(this), weak_factory_.GetWeakPtr(), | 50 base::Unretained(this), weak_factory_.GetWeakPtr(), input_handler)); |
| 44 input_handler)); | |
| 45 } | 51 } |
| 46 | 52 |
| 47 BlimpInputManager::~BlimpInputManager() { | 53 BlimpInputManager::~BlimpInputManager() { |
| 48 DCHECK(IsMainThread()); | 54 DCHECK(IsMainThread()); |
| 49 | 55 |
| 50 base::WaitableEvent shutdown_event( | 56 base::WaitableEvent shutdown_event( |
| 51 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 57 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 52 base::WaitableEvent::InitialState::NOT_SIGNALED); | 58 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 53 { | 59 { |
| 54 base::AutoReset<bool> auto_reset_main_thread_blocked( | 60 base::AutoReset<bool> auto_reset_main_thread_blocked(&main_thread_blocked_, |
| 55 &main_thread_blocked_, true); | 61 true); |
| 56 compositor_task_runner_->PostTask( | 62 compositor_task_runner_->PostTask( |
| 57 FROM_HERE, | 63 FROM_HERE, base::Bind(&BlimpInputManager::ShutdownOnCompositorThread, |
| 58 base::Bind( | 64 base::Unretained(this), &shutdown_event)); |
| 59 &BlimpInputManager::ShutdownOnCompositorThread, | |
| 60 base::Unretained(this), &shutdown_event)); | |
| 61 shutdown_event.Wait(); | 65 shutdown_event.Wait(); |
| 62 } | 66 } |
| 63 } | 67 } |
| 64 | 68 |
| 65 bool BlimpInputManager::OnTouchEvent(const ui::MotionEvent& motion_event) { | 69 bool BlimpInputManager::OnTouchEvent(const ui::MotionEvent& motion_event) { |
| 66 DCHECK(IsMainThread()); | 70 DCHECK(IsMainThread()); |
| 67 | 71 |
| 68 ui::FilteredGestureProvider::TouchHandlingResult result = | 72 ui::FilteredGestureProvider::TouchHandlingResult result = |
| 69 gesture_provider_.OnTouchEvent(motion_event); | 73 gesture_provider_.OnTouchEvent(motion_event); |
| 70 if (!result.succeeded) | 74 if (!result.succeeded) |
| 71 return false; | 75 return false; |
| 72 | 76 |
| 73 blink::WebTouchEvent touch = | 77 blink::WebTouchEvent touch = ui::CreateWebTouchEventFromMotionEvent( |
| 74 ui::CreateWebTouchEventFromMotionEvent(motion_event, | 78 motion_event, result.moved_beyond_slop_region); |
| 75 result.moved_beyond_slop_region); | |
| 76 | 79 |
| 77 // Touch events are queued in the Gesture Provider until acknowledged to | 80 // Touch events are queued in the Gesture Provider until acknowledged to |
| 78 // allow them to be consumed by the touch event handlers in blink which can | 81 // allow them to be consumed by the touch event handlers in blink which can |
| 79 // prevent-default on the event. Since we currently do not support touch | 82 // prevent-default on the event. Since we currently do not support touch |
| 80 // handlers the event is always acknowledged as not consumed. | 83 // handlers the event is always acknowledged as not consumed. |
| 81 gesture_provider_.OnTouchEventAck(touch.uniqueTouchEventId, false); | 84 gesture_provider_.OnTouchEventAck(touch.uniqueTouchEventId, false); |
| 82 | 85 |
| 83 return true; | 86 return true; |
| 84 } | 87 } |
| 85 | 88 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 bool BlimpInputManager::IsMainThread() const { | 149 bool BlimpInputManager::IsMainThread() const { |
| 147 return main_task_runner_->BelongsToCurrentThread(); | 150 return main_task_runner_->BelongsToCurrentThread(); |
| 148 } | 151 } |
| 149 | 152 |
| 150 bool BlimpInputManager::IsCompositorThread() const { | 153 bool BlimpInputManager::IsCompositorThread() const { |
| 151 return compositor_task_runner_->BelongsToCurrentThread(); | 154 return compositor_task_runner_->BelongsToCurrentThread(); |
| 152 } | 155 } |
| 153 | 156 |
| 154 } // namespace client | 157 } // namespace client |
| 155 } // namespace blimp | 158 } // namespace blimp |
| OLD | NEW |