Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(71)

Unified Diff: Source/modules/screen_orientation/ScreenOrientation.cpp

Issue 261983005: Stop firing orientationchange events at pages that are not visible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Simplify test case Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientation.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698