Chromium Code Reviews| 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 076b64f97ce91586aaa57f9bb66de94042215eba..a565578456093a995812a743bfd56b5fdad8f68b 100644 |
| --- a/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
| +++ b/third_party/WebKit/Source/modules/vr/NavigatorVR.cpp |
| @@ -14,6 +14,7 @@ |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/Navigator.h" |
| #include "core/frame/UseCounter.h" |
| +#include "core/page/FocusController.h" |
| #include "core/page/Page.h" |
| #include "modules/vr/VRController.h" |
| #include "modules/vr/VRDisplay.h" |
| @@ -25,6 +26,18 @@ |
| namespace blink { |
| +namespace { |
| +bool isFrameFocused(LocalFrame* frame) { |
|
haraken
2017/02/03 18:46:18
I'd move this to FocusChangedObserver.
mthiesse
2017/02/03 20:47:29
Done.
|
| + if (!frame) |
| + return false; |
| + Page* page = frame->page(); |
| + if (!page) |
| + return false; |
| + const FocusController& controller = page->focusController(); |
| + return controller.isFocused() && (controller.focusedOrMainFrame() == frame); |
| +} |
| +} // namespace |
| + |
| NavigatorVR* NavigatorVR::from(Document& document) { |
| if (!document.frame() || !document.frame()->domWindow()) |
| return 0; |
| @@ -77,6 +90,8 @@ VRController* NavigatorVR::controller() { |
| if (!m_controller) { |
| m_controller = new VRController(this); |
| + m_controller->setListeningForActivate(m_focused && m_listeningForActivate); |
| + m_controller->focusChanged(m_focused); |
| } |
| return m_controller; |
| @@ -90,13 +105,14 @@ Document* NavigatorVR::document() { |
| DEFINE_TRACE(NavigatorVR) { |
| visitor->trace(m_controller); |
| Supplement<Navigator>::trace(visitor); |
| - PageVisibilityObserver::trace(visitor); |
| } |
| NavigatorVR::NavigatorVR(Navigator& navigator) |
| - : Supplement<Navigator>(navigator), |
| - PageVisibilityObserver(navigator.frame()->page()) { |
| + : Supplement<Navigator>(navigator) { |
| navigator.frame()->domWindow()->registerEventListenerObserver(this); |
| + navigator.frame()->page()->focusController().registerFocusChangedObserver( |
| + this); |
| + focusedFrameChanged(); |
| } |
| NavigatorVR::~NavigatorVR() {} |
| @@ -122,12 +138,14 @@ void NavigatorVR::dispatchVRGestureEvent(VRDisplayEvent* event) { |
| window->dispatchEvent(event); |
| } |
| -void NavigatorVR::pageVisibilityChanged() { |
| - if (!page()) |
| +void NavigatorVR::focusedFrameChanged() { |
| + bool focused = isFrameFocused(supplementable()->frame()); |
| + if (focused == m_focused) |
| return; |
| + m_focused = focused; |
| if (m_controller) { |
| - m_controller->setListeningForActivate(page()->isPageVisible() && |
| - m_listeningForActivate); |
| + m_controller->setListeningForActivate(m_listeningForActivate && focused); |
| + m_controller->focusChanged(focused); |
| } |
| } |
| @@ -138,8 +156,8 @@ void NavigatorVR::didAddEventListener(LocalDOMWindow* window, |
| if (eventType == EventTypeNames::vrdisplayactivate && |
| supplementable()->frame() && supplementable()->frame()->document() && |
| Fullscreen::fullscreenEnabled(*supplementable()->frame()->document())) { |
| - controller()->setListeningForActivate(true); |
| m_listeningForActivate = true; |
| + controller()->setListeningForActivate(m_focused); |
| } else if (eventType == EventTypeNames::vrdisplayconnect) { |
| // If the page is listening for connection events make sure we've created a |
| // controller so that we'll be notified of new devices. |
| @@ -151,8 +169,8 @@ void NavigatorVR::didRemoveEventListener(LocalDOMWindow* window, |
| const AtomicString& eventType) { |
| if (eventType == EventTypeNames::vrdisplayactivate && |
| !window->hasEventListeners(EventTypeNames::vrdisplayactivate)) { |
| - controller()->setListeningForActivate(false); |
| m_listeningForActivate = false; |
| + controller()->setListeningForActivate(false); |
| } |
| } |