| 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" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 return promise; | 71 return promise; |
| 72 } | 72 } |
| 73 | 73 |
| 74 VRController* NavigatorVR::controller() { | 74 VRController* NavigatorVR::controller() { |
| 75 if (!supplementable()->frame()) | 75 if (!supplementable()->frame()) |
| 76 return 0; | 76 return 0; |
| 77 | 77 |
| 78 if (!m_controller) { | 78 if (!m_controller) { |
| 79 m_controller = new VRController(this); | 79 m_controller = new VRController(this); |
| 80 m_controller->setListeningForActivate(m_focused && m_listeningForActivate); |
| 81 m_controller->focusChanged(); |
| 80 } | 82 } |
| 81 | 83 |
| 82 return m_controller; | 84 return m_controller; |
| 83 } | 85 } |
| 84 | 86 |
| 85 Document* NavigatorVR::document() { | 87 Document* NavigatorVR::document() { |
| 86 return supplementable()->frame() ? supplementable()->frame()->document() | 88 return supplementable()->frame() ? supplementable()->frame()->document() |
| 87 : nullptr; | 89 : nullptr; |
| 88 } | 90 } |
| 89 | 91 |
| 90 DEFINE_TRACE(NavigatorVR) { | 92 DEFINE_TRACE(NavigatorVR) { |
| 91 visitor->trace(m_controller); | 93 visitor->trace(m_controller); |
| 92 Supplement<Navigator>::trace(visitor); | 94 Supplement<Navigator>::trace(visitor); |
| 93 PageVisibilityObserver::trace(visitor); | |
| 94 } | 95 } |
| 95 | 96 |
| 96 NavigatorVR::NavigatorVR(Navigator& navigator) | 97 NavigatorVR::NavigatorVR(Navigator& navigator) |
| 97 : Supplement<Navigator>(navigator), | 98 : Supplement<Navigator>(navigator), |
| 98 PageVisibilityObserver(navigator.frame()->page()) { | 99 FocusChangedObserver(navigator.frame()->page()) { |
| 99 navigator.frame()->domWindow()->registerEventListenerObserver(this); | 100 navigator.frame()->domWindow()->registerEventListenerObserver(this); |
| 101 focusedFrameChanged(); |
| 100 } | 102 } |
| 101 | 103 |
| 102 NavigatorVR::~NavigatorVR() {} | 104 NavigatorVR::~NavigatorVR() {} |
| 103 | 105 |
| 104 const char* NavigatorVR::supplementName() { | 106 const char* NavigatorVR::supplementName() { |
| 105 return "NavigatorVR"; | 107 return "NavigatorVR"; |
| 106 } | 108 } |
| 107 | 109 |
| 108 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { | 110 void NavigatorVR::enqueueVREvent(VRDisplayEvent* event) { |
| 109 if (supplementable()->frame()) { | 111 if (supplementable()->frame()) { |
| 110 supplementable()->frame()->domWindow()->enqueueWindowEvent(event); | 112 supplementable()->frame()->domWindow()->enqueueWindowEvent(event); |
| 111 } | 113 } |
| 112 } | 114 } |
| 113 | 115 |
| 114 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { | 116 void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { |
| 115 if (!(supplementable()->frame())) | 117 if (!(supplementable()->frame())) |
| 116 return; | 118 return; |
| 117 UserGestureIndicator gestureIndicator( | 119 UserGestureIndicator gestureIndicator( |
| 118 DocumentUserGestureToken::create(document())); | 120 DocumentUserGestureToken::create(document())); |
| 119 LocalDOMWindow* window = supplementable()->frame()->domWindow(); | 121 LocalDOMWindow* window = supplementable()->frame()->domWindow(); |
| 120 DCHECK(window); | 122 DCHECK(window); |
| 121 event->setTarget(window); | 123 event->setTarget(window); |
| 122 window->dispatchEvent(event); | 124 window->dispatchEvent(event); |
| 123 } | 125 } |
| 124 | 126 |
| 125 void NavigatorVR::pageVisibilityChanged() { | 127 void NavigatorVR::focusedFrameChanged() { |
| 126 if (!page()) | 128 bool focused = isFrameFocused(supplementable()->frame()); |
| 129 if (focused == m_focused) |
| 127 return; | 130 return; |
| 131 m_focused = focused; |
| 128 if (m_controller) { | 132 if (m_controller) { |
| 129 m_controller->setListeningForActivate(page()->isPageVisible() && | 133 m_controller->setListeningForActivate(m_listeningForActivate && focused); |
| 130 m_listeningForActivate); | 134 m_controller->focusChanged(); |
| 131 } | 135 } |
| 132 } | 136 } |
| 133 | 137 |
| 134 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, | 138 void NavigatorVR::didAddEventListener(LocalDOMWindow* window, |
| 135 const AtomicString& eventType) { | 139 const AtomicString& eventType) { |
| 136 // TODO(mthiesse): Remove fullscreen requirement for presentation. See | 140 // TODO(mthiesse): Remove fullscreen requirement for presentation. See |
| 137 // crbug.com/687369 | 141 // crbug.com/687369 |
| 138 if (eventType == EventTypeNames::vrdisplayactivate && | 142 if (eventType == EventTypeNames::vrdisplayactivate && |
| 139 supplementable()->frame() && supplementable()->frame()->document() && | 143 supplementable()->frame() && supplementable()->frame()->document() && |
| 140 Fullscreen::fullscreenEnabled(*supplementable()->frame()->document())) { | 144 Fullscreen::fullscreenEnabled(*supplementable()->frame()->document())) { |
| 141 controller()->setListeningForActivate(true); | |
| 142 m_listeningForActivate = true; | 145 m_listeningForActivate = true; |
| 146 controller()->setListeningForActivate(m_focused); |
| 143 } else if (eventType == EventTypeNames::vrdisplayconnect) { | 147 } else if (eventType == EventTypeNames::vrdisplayconnect) { |
| 144 // If the page is listening for connection events make sure we've created a | 148 // If the page is listening for connection events make sure we've created a |
| 145 // controller so that we'll be notified of new devices. | 149 // controller so that we'll be notified of new devices. |
| 146 controller(); | 150 controller(); |
| 147 } | 151 } |
| 148 } | 152 } |
| 149 | 153 |
| 150 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, | 154 void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, |
| 151 const AtomicString& eventType) { | 155 const AtomicString& eventType) { |
| 152 if (eventType == EventTypeNames::vrdisplayactivate && | 156 if (eventType == EventTypeNames::vrdisplayactivate && |
| 153 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { | 157 !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { |
| 158 m_listeningForActivate = false; |
| 154 controller()->setListeningForActivate(false); | 159 controller()->setListeningForActivate(false); |
| 155 m_listeningForActivate = false; | |
| 156 } | 160 } |
| 157 } | 161 } |
| 158 | 162 |
| 159 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { | 163 void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow* window) { |
| 160 if (m_controller) { | 164 if (m_controller) { |
| 161 m_controller->setListeningForActivate(false); | 165 m_controller->setListeningForActivate(false); |
| 162 m_listeningForActivate = false; | 166 m_listeningForActivate = false; |
| 163 } | 167 } |
| 164 } | 168 } |
| 165 | 169 |
| 166 } // namespace blink | 170 } // namespace blink |
| OLD | NEW |