Index: Source/modules/screen_orientation/ScreenOrientation.cpp |
diff --git a/Source/modules/screen_orientation/ScreenOrientation.cpp b/Source/modules/screen_orientation/ScreenOrientation.cpp |
index d428f1a2fbc710cdc6589fc0ba4de4f36710c11b..bb0fb9d1b68f083f0398a671349a0b46c474e141 100644 |
--- a/Source/modules/screen_orientation/ScreenOrientation.cpp |
+++ b/Source/modules/screen_orientation/ScreenOrientation.cpp |
@@ -5,6 +5,7 @@ |
#include "config.h" |
#include "modules/screen_orientation/ScreenOrientation.h" |
+#include "core/dom/FullscreenElementStack.h" |
#include "core/frame/DOMWindow.h" |
#include "core/frame/LocalFrame.h" |
#include "core/frame/Screen.h" |
@@ -101,6 +102,39 @@ void ScreenOrientation::orientationLockTimerFired(Timer<ScreenOrientation>*) |
blink::Platform::current()->lockOrientation(m_prospectiveLock); |
} |
+void ScreenOrientation::startListeningForFullscreenExit() |
+{ |
+ Document* document = this->document(); |
+ ASSERT(document); |
+ FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExists(*document); |
+ ASSERT(fullscreen); |
+ fullscreen->addObserver(this); |
+} |
+ |
+void ScreenOrientation::stopListeningForFullscreenExit() |
+{ |
+ Document* document = this->document(); |
+ if (!document) |
+ return; |
+ FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExists(*document); |
+ if (!fullscreen) |
+ return; |
+ fullscreen->removeObserver(this); |
+} |
+ |
+// We need to set the screen orientation lock back to the default when |
+// the document fully exists fullscreen. |
+void ScreenOrientation::didFullyExitFullscreen() |
+{ |
+ stopListeningForFullscreenExit(); |
+ |
+ m_prospectiveLock = blink::WebScreenOrientationLockDefault; |
+ if (m_orientationLockTimer.isActive()) |
+ m_orientationLockTimer.stop(); |
+ |
+ blink::Platform::current()->unlockOrientation(); |
+} |
+ |
const char* ScreenOrientation::supplementName() |
{ |
return "ScreenOrientation"; |
@@ -126,6 +160,7 @@ ScreenOrientation& ScreenOrientation::from(Screen& screen) |
ScreenOrientation::~ScreenOrientation() |
{ |
+ stopListeningForFullscreenExit(); |
sof
2014/05/08 21:41:17
With Oilpan, this is a somewhat problematic cleanu
|
} |
const AtomicString& ScreenOrientation::orientation(Screen& screen) |
@@ -139,15 +174,31 @@ const AtomicString& ScreenOrientation::orientation(Screen& screen) |
return orientationTypeToString(controller.orientation()); |
} |
+bool ScreenOrientation::isOrientationLockingAllowed(Document& document) const |
+{ |
+ // We only allow locking the orientation while in fullscreen, for consistency with other browsers. |
+ return FullscreenElementStack::isFullScreen(document); |
+} |
+ |
bool ScreenOrientation::lockOrientation(Screen& screen, const AtomicString& lockString) |
{ |
- ScreenOrientation::from(screen).lockOrientationAsync(stringToOrientationLock(lockString)); |
+ ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
+ Document* document = screenOrientation.document(); |
+ if (!document) |
+ return false; |
+ if (!screenOrientation.isOrientationLockingAllowed(*document)) |
+ return false; |
+ |
+ screenOrientation.lockOrientationAsync(stringToOrientationLock(lockString)); |
+ screenOrientation.startListeningForFullscreenExit(); |
return true; |
} |
void ScreenOrientation::unlockOrientation(Screen& screen) |
{ |
- ScreenOrientation::from(screen).lockOrientationAsync(blink::WebScreenOrientationLockDefault); |
+ ScreenOrientation& screenOrientation = ScreenOrientation::from(screen); |
+ screenOrientation.stopListeningForFullscreenExit(); |
+ screenOrientation.lockOrientationAsync(blink::WebScreenOrientationLockDefault); |
} |
} // namespace WebCore |