Chromium Code Reviews| 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 "modules/vr/NavigatorVR.h" | 5 #include "modules/vr/NavigatorVR.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptPromiseResolver.h" | 7 #include "bindings/core/v8/ScriptPromiseResolver.h" |
| 8 #include "core/dom/DOMException.h" | 8 #include "core/dom/DOMException.h" |
| 9 #include "core/dom/Document.h" | 9 #include "core/dom/Document.h" |
| 10 #include "core/dom/DocumentUserGestureToken.h" | 10 #include "core/dom/DocumentUserGestureToken.h" |
| 11 #include "core/dom/ExceptionCode.h" | 11 #include "core/dom/ExceptionCode.h" |
| 12 #include "core/frame/LocalDOMWindow.h" | 12 #include "core/frame/LocalDOMWindow.h" |
| 13 #include "core/frame/LocalFrame.h" | 13 #include "core/frame/LocalFrame.h" |
| 14 #include "core/frame/Navigator.h" | 14 #include "core/frame/Navigator.h" |
| 15 #include "core/frame/UseCounter.h" | 15 #include "core/frame/UseCounter.h" |
| 16 #include "core/page/FocusController.h" | |
| 16 #include "core/page/Page.h" | 17 #include "core/page/Page.h" |
| 17 #include "modules/vr/VRController.h" | 18 #include "modules/vr/VRController.h" |
| 18 #include "modules/vr/VRDisplay.h" | 19 #include "modules/vr/VRDisplay.h" |
| 19 #include "modules/vr/VRGetDevicesCallback.h" | 20 #include "modules/vr/VRGetDevicesCallback.h" |
| 20 #include "modules/vr/VRPose.h" | 21 #include "modules/vr/VRPose.h" |
| 21 #include "platform/UserGestureIndicator.h" | 22 #include "platform/UserGestureIndicator.h" |
| 22 #include "public/platform/Platform.h" | 23 #include "public/platform/Platform.h" |
| 23 #include "wtf/PtrUtil.h" | 24 #include "wtf/PtrUtil.h" |
| 24 | 25 |
| 25 namespace blink { | 26 namespace blink { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 69 | 70 |
| 70 return promise; | 71 return promise; |
| 71 } | 72 } |
| 72 | 73 |
| 73 VRController* NavigatorVR::controller() { | 74 VRController* NavigatorVR::controller() { |
| 74 if (!supplementable()->frame()) | 75 if (!supplementable()->frame()) |
| 75 return 0; | 76 return 0; |
| 76 | 77 |
| 77 if (!m_controller) { | 78 if (!m_controller) { |
| 78 m_controller = new VRController(this); | 79 m_controller = new VRController(this); |
| 80 m_controller->setListeningForActivate(m_listeningForActivate); | |
| 81 m_controller->focusChanged(m_focused); | |
| 79 } | 82 } |
| 80 | 83 |
| 81 return m_controller; | 84 return m_controller; |
| 82 } | 85 } |
| 83 | 86 |
| 84 Document* NavigatorVR::document() { | 87 Document* NavigatorVR::document() { |
| 85 return supplementable()->frame() ? supplementable()->frame()->document() | 88 return supplementable()->frame() ? supplementable()->frame()->document() |
| 86 : nullptr; | 89 : nullptr; |
| 87 } | 90 } |
| 88 | 91 |
| 89 DEFINE_TRACE(NavigatorVR) { | 92 DEFINE_TRACE(NavigatorVR) { |
| 90 visitor->trace(m_controller); | 93 visitor->trace(m_controller); |
| 91 Supplement<Navigator>::trace(visitor); | 94 Supplement<Navigator>::trace(visitor); |
| 92 PageVisibilityObserver::trace(visitor); | |
| 93 } | 95 } |
| 94 | 96 |
| 95 NavigatorVR::NavigatorVR(Navigator& navigator) | 97 NavigatorVR::NavigatorVR(Navigator& navigator) |
| 96 : Supplement<Navigator>(navigator), | 98 : Supplement<Navigator>(navigator) { |
| 97 PageVisibilityObserver(navigator.frame()->page()) { | |
| 98 navigator.frame()->domWindow()->registerEventListenerObserver(this); | 99 navigator.frame()->domWindow()->registerEventListenerObserver(this); |
| 100 navigator.frame()->page()->focusController().registerFocusChangedObserver( | |
| 101 this); | |
| 102 focusedFrameChanged(); | |
| 99 } | 103 } |
| 100 | 104 |
| 101 NavigatorVR::~NavigatorVR() {} | 105 NavigatorVR::~NavigatorVR() {} |
| 102 | 106 |
| 103 const char* NavigatorVR::supplementName() { | 107 const char* NavigatorVR::supplementName() { |
| 104 return "NavigatorVR"; | 108 return "NavigatorVR"; |
| 105 } | 109 } |
| 106 | 110 |
| 107 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { | 111 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { |
| 108 if (supplementable()->frame()) { | 112 if (supplementable()->frame()) { |
| 109 supplementable()->frame()->domWindow()->enqueueWindowEvent(event); | 113 supplementable()->frame()->domWindow()->enqueueWindowEvent(event); |
| 110 } | 114 } |
| 111 } | 115 } |
| 112 | 116 |
| 113 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { | 117 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { |
| 114 if (!(supplementable()->frame())) | 118 if (!(supplementable()->frame())) |
| 115 return; | 119 return; |
| 116 UserGestureIndicator gestureIndicator( | 120 UserGestureIndicator gestureIndicator( |
| 117 DocumentUserGestureToken::create(document())); | 121 DocumentUserGestureToken::create(document())); |
| 118 LocalDOMWindow* window = supplementable()->frame()->domWindow(); | 122 LocalDOMWindow* window = supplementable()->frame()->domWindow(); |
| 119 DCHECK(window); | 123 DCHECK(window); |
| 120 event->setTarget(window); | 124 event->setTarget(window); |
| 121 window->dispatchEvent(event); | 125 window->dispatchEvent(event); |
| 122 } | 126 } |
| 123 | 127 |
| 124 void NavigatorVR::pageVisibilityChanged() { | 128 void NavigatorVR::focusedFrameChanged() { |
|
jbroman
2017/02/02 16:07:20
nit: This condition might be clearer factored out
mthiesse
2017/02/02 17:52:18
Done.
| |
| 125 if (!page()) | 129 if (supplementable() && supplementable()->frame() && |
| 130 supplementable()->frame()->page() && | |
| 131 supplementable()->frame()->document() && | |
| 132 supplementable()->frame()->page()->focusController().isDocumentFocused( | |
|
jbroman
2017/02/02 16:07:20
Do you really want isDocumentFocused? This will re
mthiesse
2017/02/02 17:52:18
Hmm I think you're right, and isDocumentFocused wa
| |
| 133 *supplementable()->frame()->document())) { | |
| 134 if (!m_focused && m_controller) { | |
| 135 m_controller->setListeningForActivate(m_listeningForActivate); | |
| 136 m_controller->focusChanged(true); | |
| 137 } | |
| 138 m_focused = true; | |
| 126 return; | 139 return; |
| 127 if (m_controller) { | |
| 128 m_controller->setListeningForActivate(page()->isPageVisible() && | |
| 129 m_listeningForActivate); | |
| 130 } | 140 } |
| 141 if (m_focused && m_controller) { | |
| 142 m_controller->setListeningForActivate(false); | |
| 143 m_controller->focusChanged(false); | |
| 144 } | |
| 145 m_focused = false; | |
| 131 } | 146 } |
| 132 | 147 |
| 133 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, | 148 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, |
| 134 const AtomicString& eventType) { | 149 const AtomicString& eventType) { |
| 135 if (eventType == EventTypeNames::vrdisplayactivate) { | 150 if (eventType == EventTypeNames::vrdisplayactivate) { |
| 136 controller()->setListeningForActivate(true); | 151 controller()->setListeningForActivate(m_focused); |
| 137 m_listeningForActivate = true; | 152 m_listeningForActivate = true; |
| 138 } else if (eventType == EventTypeNames::vrdisplayconnect) { | 153 } else if (eventType == EventTypeNames::vrdisplayconnect) { |
| 139 // If the page is listening for connection events make sure we've created a | 154 // If the page is listening for connection events make sure we've created a |
| 140 // controller so that we'll be notified of new devices. | 155 // controller so that we'll be notified of new devices. |
| 141 controller(); | 156 controller(); |
| 142 } | 157 } |
| 143 } | 158 } |
| 144 | 159 |
| 145 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, | 160 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, |
| 146 const AtomicString& eventType) { | 161 const AtomicString& eventType) { |
| 147 if (eventType == EventTypeNames::vrdisplayactivate && | 162 if (eventType == EventTypeNames::vrdisplayactivate && |
| 148 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { | 163 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { |
| 149 controller()->setListeningForActivate(false); | 164 controller()->setListeningForActivate(false); |
| 150 m_listeningForActivate = false; | 165 m_listeningForActivate = false; |
| 151 } | 166 } |
| 152 } | 167 } |
| 153 | 168 |
| 154 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { | 169 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { |
| 155 if (m_controller) { | 170 if (m_controller) { |
| 156 m_controller->setListeningForActivate(false); | 171 m_controller->setListeningForActivate(false); |
| 157 m_listeningForActivate = false; | 172 m_listeningForActivate = false; |
| 158 } | 173 } |
| 159 } | 174 } |
| 160 | 175 |
| 161 } // namespace blink | 176 } // namespace blink |
| OLD | NEW |