Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 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 "base/logging.h" | |
| 6 #include "chrome/browser/android/vr_shell/vr_controller_manager.h" | |
| 7 #include "content/public/browser/browser_thread.h" | |
| 8 | |
| 9 namespace vr_shell { | |
| 10 | |
| 11 VrControllerManager::VrControllerManager() {} | |
| 12 | |
| 13 VrControllerManager::~VrControllerManager() {} | |
| 14 | |
| 15 void VrControllerManager::OnResume() { | |
| 16 if (vr_controller_) | |
| 17 vr_controller_->OnResume(); | |
| 18 } | |
| 19 | |
| 20 void VrControllerManager::SetContentViewCore( | |
| 21 content::ContentViewCore* content_cvc_ptr, | |
| 22 content::ContentViewCore* ui_cvc_ptr) { | |
| 23 vr_content_ptr = | |
| 24 content::VrInputManager::FromContentViewCore(content_cvc_ptr); | |
| 25 vr_ui_ptr = content::VrInputManager::FromContentViewCore(ui_cvc_ptr); | |
| 26 } | |
| 27 | |
| 28 void VrControllerManager::OnPause() { | |
| 29 if (vr_controller_) | |
| 30 vr_controller_->OnPause(); | |
| 31 } | |
| 32 | |
| 33 void VrControllerManager::Initialize(gvr_context_* gvr_context) { | |
|
mthiesse
2016/09/22 16:20:11
gvr_context*
asimjour
2016/09/22 22:55:16
Done.
| |
| 34 vr_controller_.reset(new VrController(gvr_context)); | |
| 35 vr_controller_->Initialize(gvr_context); | |
| 36 } | |
| 37 | |
| 38 VrGesture VrControllerManager::Update() { | |
| 39 if (!vr_controller_) | |
| 40 return VrGesture(); | |
| 41 vr_controller_->UpdateState(); | |
| 42 VrGesture gesture = vr_controller_->DetectGesture(); | |
| 43 return gesture; | |
| 44 } | |
| 45 | |
| 46 void VrControllerManager::ProcessUpdatedGesture(VrGesture gesture) { | |
| 47 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) | |
| 48 content::BrowserThread::PostTask( | |
| 49 content::BrowserThread::UI, FROM_HERE, | |
| 50 base::Bind(&VrControllerManager::SendGesture, this, gesture, | |
| 51 vr_content_ptr)); | |
| 52 else | |
| 53 SendGesture(gesture, vr_content_ptr); | |
| 54 } | |
| 55 | |
| 56 void VrControllerManager::ProcessUpdatedUIGesture(VrGesture gesture) { | |
| 57 if (!content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)) | |
| 58 content::BrowserThread::PostTask( | |
| 59 content::BrowserThread::UI, FROM_HERE, | |
| 60 base::Bind(&VrControllerManager::SendGesture, this, gesture, | |
| 61 vr_ui_ptr)); | |
| 62 else | |
| 63 SendGesture(gesture, vr_ui_ptr); | |
| 64 } | |
| 65 | |
| 66 void VrControllerManager::SendGesture(VrGesture gesture, | |
| 67 content::VrInputManager* vr_cvc_ptr) { | |
| 68 int64_t event_time = gesture.start_time; | |
| 69 long event_time_milliseconds = (long)(event_time / 1000000); | |
| 70 | |
| 71 if (gesture.type == kGestureTypeScroll) { | |
| 72 vr_cvc_ptr->SendScrollEvent( | |
| 73 event_time_milliseconds, 0.0f, 0.0f, gesture.details.scroll.dx, | |
| 74 gesture.details.scroll.dy, gesture.details.scroll.state); | |
| 75 } else if (gesture.type == kGestureTypeButtonsChange) { | |
| 76 vr_cvc_ptr->SendClickEvent(event_time_milliseconds, | |
| 77 gesture.details.buttons.x, | |
| 78 gesture.details.buttons.y); | |
| 79 } else if (gesture.type == kGestureTypeAngularMove) { | |
| 80 vr_cvc_ptr->SendMouseMoveEvent( | |
| 81 event_time_milliseconds, gesture.details.move.x, gesture.details.move.y, | |
| 82 gesture.details.move.type); | |
| 83 } | |
| 84 return; | |
| 85 } | |
| 86 | |
| 87 bool VrControllerManager::IsTouching() { | |
| 88 return vr_controller_->IsTouching(); | |
| 89 } | |
| 90 | |
| 91 float VrControllerManager::TouchPosX() { | |
| 92 return vr_controller_->TouchPosX(); | |
| 93 } | |
| 94 | |
| 95 float VrControllerManager::TouchPosY() { | |
| 96 return vr_controller_->TouchPosY(); | |
| 97 } | |
| 98 | |
| 99 const gvr::Quatf VrControllerManager::Orientation() { | |
| 100 return vr_controller_->Orientation(); | |
| 101 } | |
| 102 | |
| 103 bool VrControllerManager::IsTouchDown() { | |
| 104 return vr_controller_->IsTouchDown(); | |
| 105 } | |
| 106 | |
| 107 bool VrControllerManager::IsTouchUp() { | |
| 108 return vr_controller_->IsTouchUp(); | |
| 109 } | |
| 110 | |
| 111 bool VrControllerManager::ButtonDown(const int32_t button) { | |
| 112 return vr_controller_->ButtonDown(button); | |
| 113 } | |
| 114 | |
| 115 bool VrControllerManager::ButtonUp(const int32_t button) { | |
| 116 return vr_controller_->ButtonUp(button); | |
| 117 } | |
| 118 | |
| 119 bool VrControllerManager::IsConnected() { | |
| 120 return vr_controller_->IsConnected(); | |
| 121 } | |
| 122 | |
| 123 } // namespace vr_shell | |
| OLD | NEW |