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

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

Issue 280283002: Stop firing orientationchange events at pages that are not visible (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Take feedback into consideration 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/ScreenOrientationController.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/ScreenOrientationController.cpp
diff --git a/Source/modules/screen_orientation/ScreenOrientationController.cpp b/Source/modules/screen_orientation/ScreenOrientationController.cpp
index 5e612192a3a0876b241fa5d1a94156070a376042..ab8288facb71132635a6b365185d186fd23338ae 100644
--- a/Source/modules/screen_orientation/ScreenOrientationController.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp
@@ -10,6 +10,7 @@
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Screen.h"
+#include "core/page/Page.h"
#include "platform/LayoutTestSupport.h"
#include "platform/PlatformScreen.h"
@@ -28,7 +29,9 @@ ScreenOrientationController& ScreenOrientationController::from(Document& documen
}
ScreenOrientationController::ScreenOrientationController(Document& document)
- : m_document(document)
+ : PageLifecycleObserver(document.page())
+ , m_document(document)
+ , m_overrideOrientation(blink::WebScreenOrientationUndefined)
{
}
@@ -64,8 +67,30 @@ blink::WebScreenOrientationType ScreenOrientationController::computeOrientation(
}
}
+void ScreenOrientationController::pageVisibilityChanged()
+{
+ if (page() && page()->visibilityState() == PageVisibilityStateVisible) {
+ blink::WebScreenOrientationType oldOrientation = m_overrideOrientation;
+ m_overrideOrientation = blink::WebScreenOrientationUndefined;
+ LocalFrame* mainFrame = m_document.frame();
+ if (mainFrame && oldOrientation != orientation())
+ mainFrame->sendOrientationChangeEvent();
+ } else if (m_overrideOrientation == blink::WebScreenOrientationUndefined) {
+ // The page is no longer visible, store the last know screen orientation
+ // so that we keep returning this orientation until the page becomes
+ // visible again.
+ m_overrideOrientation = orientation();
+ }
+}
+
blink::WebScreenOrientationType ScreenOrientationController::orientation() const
{
+ if (m_overrideOrientation != blink::WebScreenOrientationUndefined) {
+ // The page is not visible, keep returning the last known screen orientation.
+ ASSERT(!page() || page()->visibilityState() != PageVisibilityStateVisible);
+ return m_overrideOrientation;
+ }
+
LocalFrame* mainFrame = m_document.frame();
if (!mainFrame)
return blink::WebScreenOrientationPortraitPrimary;
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientationController.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698