| 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 "blimp/client/core/input/blimp_input_handler_wrapper.h" |
| 11 #include "ui/events/blink/blink_event_util.h" | 12 #include "ui/events/blink/blink_event_util.h" |
| 12 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" | 13 #include "ui/events/gesture_detection/gesture_provider_config_helper.h" |
| 13 | 14 |
| 14 namespace blimp { | 15 namespace blimp { |
| 15 namespace client { | 16 namespace client { |
| 16 | 17 |
| 17 std::unique_ptr<BlimpInputManager> BlimpInputManager::Create( | 18 std::unique_ptr<BlimpInputManager> BlimpInputManager::Create( |
| 18 BlimpInputManagerClient* client, | 19 BlimpInputManagerClient* client, |
| 19 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 20 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 20 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | 21 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, |
| 21 const base::WeakPtr<cc::InputHandler>& input_handler) { | 22 const base::WeakPtr<cc::InputHandler>& input_handler) { |
| 22 return base::WrapUnique(new BlimpInputManager( | 23 return base::WrapUnique(new BlimpInputManager( |
| 23 client, main_task_runner, compositor_task_runner, input_handler)); | 24 client, main_task_runner, compositor_task_runner, input_handler)); |
| 24 } | 25 } |
| 25 | 26 |
| 26 BlimpInputManager::BlimpInputManager( | 27 BlimpInputManager::BlimpInputManager( |
| 27 BlimpInputManagerClient* client, | 28 BlimpInputManagerClient* client, |
| 28 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, | 29 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner, |
| 29 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, | 30 scoped_refptr<base::SingleThreadTaskRunner> compositor_task_runner, |
| 30 const base::WeakPtr<cc::InputHandler>& input_handler) | 31 const base::WeakPtr<cc::InputHandler>& input_handler) |
| 31 : client_(client), | 32 : client_(client), |
| 32 gesture_provider_(ui::GetGestureProviderConfig( | 33 gesture_provider_(ui::GetGestureProviderConfig( |
| 33 ui::GestureProviderConfigType::CURRENT_PLATFORM), this), | 34 ui::GestureProviderConfigType::CURRENT_PLATFORM), |
| 35 this), |
| 34 main_task_runner_(main_task_runner), | 36 main_task_runner_(main_task_runner), |
| 35 compositor_task_runner_(compositor_task_runner), | 37 compositor_task_runner_(compositor_task_runner), |
| 36 main_thread_blocked_(false), | 38 main_thread_blocked_(false), |
| 37 weak_factory_(this) { | 39 weak_factory_(this) { |
| 38 DCHECK(IsMainThread()); | 40 DCHECK(IsMainThread()); |
| 39 compositor_task_runner_->PostTask( | 41 compositor_task_runner_->PostTask( |
| 40 FROM_HERE, | 42 FROM_HERE, |
| 41 base::Bind( | 43 base::Bind( |
| 42 &BlimpInputManager::CreateInputHandlerWrapperOnCompositorThread, | 44 &BlimpInputManager::CreateInputHandlerWrapperOnCompositorThread, |
| 43 base::Unretained(this), weak_factory_.GetWeakPtr(), | 45 base::Unretained(this), weak_factory_.GetWeakPtr(), input_handler)); |
| 44 input_handler)); | |
| 45 } | 46 } |
| 46 | 47 |
| 47 BlimpInputManager::~BlimpInputManager() { | 48 BlimpInputManager::~BlimpInputManager() { |
| 48 DCHECK(IsMainThread()); | 49 DCHECK(IsMainThread()); |
| 49 | 50 |
| 50 base::WaitableEvent shutdown_event( | 51 base::WaitableEvent shutdown_event( |
| 51 base::WaitableEvent::ResetPolicy::AUTOMATIC, | 52 base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 52 base::WaitableEvent::InitialState::NOT_SIGNALED); | 53 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 53 { | 54 { |
| 54 base::AutoReset<bool> auto_reset_main_thread_blocked( | 55 base::AutoReset<bool> auto_reset_main_thread_blocked(&main_thread_blocked_, |
| 55 &main_thread_blocked_, true); | 56 true); |
| 56 compositor_task_runner_->PostTask( | 57 compositor_task_runner_->PostTask( |
| 57 FROM_HERE, | 58 FROM_HERE, base::Bind(&BlimpInputManager::ShutdownOnCompositorThread, |
| 58 base::Bind( | 59 base::Unretained(this), &shutdown_event)); |
| 59 &BlimpInputManager::ShutdownOnCompositorThread, | |
| 60 base::Unretained(this), &shutdown_event)); | |
| 61 shutdown_event.Wait(); | 60 shutdown_event.Wait(); |
| 62 } | 61 } |
| 63 } | 62 } |
| 64 | 63 |
| 65 bool BlimpInputManager::OnTouchEvent(const ui::MotionEvent& motion_event) { | 64 bool BlimpInputManager::OnTouchEvent(const ui::MotionEvent& motion_event) { |
| 66 DCHECK(IsMainThread()); | 65 DCHECK(IsMainThread()); |
| 67 | 66 |
| 68 ui::FilteredGestureProvider::TouchHandlingResult result = | 67 ui::FilteredGestureProvider::TouchHandlingResult result = |
| 69 gesture_provider_.OnTouchEvent(motion_event); | 68 gesture_provider_.OnTouchEvent(motion_event); |
| 70 if (!result.succeeded) | 69 if (!result.succeeded) |
| 71 return false; | 70 return false; |
| 72 | 71 |
| 73 blink::WebTouchEvent touch = | 72 blink::WebTouchEvent touch = ui::CreateWebTouchEventFromMotionEvent( |
| 74 ui::CreateWebTouchEventFromMotionEvent(motion_event, | 73 motion_event, result.moved_beyond_slop_region); |
| 75 result.moved_beyond_slop_region); | |
| 76 | 74 |
| 77 // Touch events are queued in the Gesture Provider until acknowledged to | 75 // 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 | 76 // 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 | 77 // prevent-default on the event. Since we currently do not support touch |
| 80 // handlers the event is always acknowledged as not consumed. | 78 // handlers the event is always acknowledged as not consumed. |
| 81 gesture_provider_.OnTouchEventAck(touch.uniqueTouchEventId, false); | 79 gesture_provider_.OnTouchEventAck(touch.uniqueTouchEventId, false); |
| 82 | 80 |
| 83 return true; | 81 return true; |
| 84 } | 82 } |
| 85 | 83 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 bool BlimpInputManager::IsMainThread() const { | 144 bool BlimpInputManager::IsMainThread() const { |
| 147 return main_task_runner_->BelongsToCurrentThread(); | 145 return main_task_runner_->BelongsToCurrentThread(); |
| 148 } | 146 } |
| 149 | 147 |
| 150 bool BlimpInputManager::IsCompositorThread() const { | 148 bool BlimpInputManager::IsCompositorThread() const { |
| 151 return compositor_task_runner_->BelongsToCurrentThread(); | 149 return compositor_task_runner_->BelongsToCurrentThread(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 } // namespace client | 152 } // namespace client |
| 155 } // namespace blimp | 153 } // namespace blimp |
| OLD | NEW |