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

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: Rebase now that dependency patch has landed 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
Index: Source/modules/screen_orientation/ScreenOrientationController.cpp
diff --git a/Source/modules/screen_orientation/ScreenOrientationController.cpp b/Source/modules/screen_orientation/ScreenOrientationController.cpp
index e3d75596605f1c4ad16a60b6c633c0f784ba0b7f..a6e645583f9b74fa53c0bd6b5f7c4f58afcec32a 100644
--- a/Source/modules/screen_orientation/ScreenOrientationController.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp
@@ -11,6 +11,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"
@@ -31,7 +32,9 @@ ScreenOrientationController& ScreenOrientationController::from(Document& documen
}
ScreenOrientationController::ScreenOrientationController(Document& document)
- : m_document(document)
+ : PageLifecycleObserver(document.page())
mlamouri (slow - plz ping) 2014/05/28 14:05:33 Can a document get detached and attached again?
Inactive 2014/05/28 15:27:28 I do not think so.
+ , m_document(document)
+ , m_lastVisibleOrientation(blink::WebScreenOrientationUndefined)
{
}
@@ -67,8 +70,25 @@ blink::WebScreenOrientationType ScreenOrientationController::computeOrientation(
}
}
+void ScreenOrientationController::pageVisibilityChanged()
+{
+ if (page() && page()->visibilityState() == PageVisibilityStateVisible) {
+ m_lastVisibleOrientation = blink::WebScreenOrientationUndefined;
mlamouri (slow - plz ping) 2014/05/28 14:05:33 I think it would be appropriate to also fire an ev
Inactive 2014/05/28 15:27:28 Done.
+ } else if (m_lastVisibleOrientation == 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_lastVisibleOrientation = orientation();
+ }
+}
+
blink::WebScreenOrientationType ScreenOrientationController::orientation() const
{
+ if (m_lastVisibleOrientation != blink::WebScreenOrientationUndefined) {
mlamouri (slow - plz ping) 2014/05/28 14:05:33 I'm not a big fan of side effects like that (ie. m
Inactive 2014/05/28 15:27:28 I renamed the variable to m_overrideOrientation fo
+ // The page is not visible, keep returning the last known screen orientation.
+ return m_lastVisibleOrientation;
+ }
+
LocalFrame* mainFrame = m_document.frame();
if (!mainFrame)
return blink::WebScreenOrientationPortraitPrimary;

Powered by Google App Engine
This is Rietveld 408576698