Index: third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
diff --git a/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp b/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
index b3acb36935316dd79addae9993ee094dfba11e3a..76778d047a0f6c89364f251cdc1474829108a3e5 100644 |
--- a/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
+++ b/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
@@ -81,14 +81,56 @@ Document* NavigatorVR::document() |
DEFINE_TRACE(NavigatorVR) |
{ |
visitor->trace(m_controller); |
+ visitor->trace(m_pendingEvents); |
+ visitor->trace(m_dispatchOneEventRunner); |
Supplement<Navigator>::trace(visitor); |
DOMWindowProperty::trace(visitor); |
} |
+bool NavigatorVR::isVREvent(const AtomicString& eventType) |
+{ |
+ return eventType == EventTypeNames::vrdisplayconnect |
+ || eventType == EventTypeNames::vrdisplaydisconnect |
+ || eventType == EventTypeNames::vrdisplayactivate |
+ || eventType == EventTypeNames::vrdisplaydeactivate; |
+} |
+ |
+void NavigatorVR::didAddEventListener(LocalDOMWindow*, const AtomicString& eventType) |
+{ |
+ if (isVREvent(eventType)) { |
+ m_hasEventListener = true; |
+ } |
+} |
+ |
+void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, const AtomicString& eventType) |
+{ |
+ if (isVREvent(eventType) |
+ && !window->hasEventListeners(EventTypeNames::vrdisplayconnect) |
+ && !window->hasEventListeners(EventTypeNames::vrdisplaydisconnect)) { |
+ didRemoveVREventListeners(); |
+ } |
+} |
+ |
+void NavigatorVR::didRemoveAllEventListeners(LocalDOMWindow*) |
+{ |
+ didRemoveVREventListeners(); |
+} |
+ |
+void NavigatorVR::didRemoveVREventListeners() |
+{ |
+ m_hasEventListener = false; |
+ m_dispatchOneEventRunner->stop(); |
+ m_pendingEvents.clear(); |
+} |
+ |
NavigatorVR::NavigatorVR(LocalFrame* frame) |
: DOMWindowProperty(frame) |
+ , m_hasEventListener(false) |
+ , m_dispatchOneEventRunner(AsyncMethodRunner<NavigatorVR>::create(this, &NavigatorVR::dispatchOneEvent)) |
{ |
+ if (frame) |
+ frame->localDOMWindow()->registerEventListenerObserver(this); |
} |
NavigatorVR::~NavigatorVR() |
@@ -108,4 +150,23 @@ void NavigatorVR::fireVRDisplayPresentChange(VRDisplay* display) |
} |
} |
+void NavigatorVR::fireVREvent(VRDisplayEvent* event) |
bajones
2016/09/06 23:25:46
Lets have this function call m_frame->localDOMWind
|
+{ |
+ m_pendingEvents.append(event); |
+ m_dispatchOneEventRunner->runAsync(); |
+} |
+ |
+void NavigatorVR::dispatchOneEvent() |
+{ |
+ DCHECK(frame()); |
+ DCHECK(frame()->domWindow()); |
+ DCHECK(!m_pendingEvents.isEmpty()); |
+ |
+ if (m_frame) |
+ m_frame->domWindow()->dispatchEvent(m_pendingEvents.takeFirst()); |
+ |
+ if (!m_pendingEvents.isEmpty()) |
+ m_dispatchOneEventRunner->runAsync(); |
+} |
+ |
} // namespace blink |