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

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

Issue 366853008: [screen-orientation] Expose orientation info in OrientationInformation interface. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: update ctor listing Created 6 years, 6 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') | Source/web/WebLocalFrameImpl.cpp » ('j') | 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 af35b986950871a69d10afc1166fb7977f197568..bf8ae5ee3d889eca1c339b6417a99d05e30d2cfb 100644
--- a/Source/modules/screen_orientation/ScreenOrientationController.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp
@@ -5,11 +5,13 @@
#include "config.h"
#include "modules/screen_orientation/ScreenOrientationController.h"
+#include "core/events/Event.h"
#include "core/frame/LocalDOMWindow.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/Screen.h"
#include "core/page/Page.h"
+#include "modules/screen_orientation/OrientationInformation.h"
#include "platform/LayoutTestSupport.h"
#include "platform/PlatformScreen.h"
#include "public/platform/WebScreenOrientationClient.h"
@@ -39,7 +41,7 @@ ScreenOrientationController& ScreenOrientationController::from(LocalFrame& frame
ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blink::WebScreenOrientationClient* client)
: PageLifecycleObserver(frame.page())
- , m_overrideOrientation(blink::WebScreenOrientationUndefined)
+ , m_orientation(new OrientationInformation)
, m_client(client)
, m_frame(frame)
{
@@ -77,41 +79,72 @@ blink::WebScreenOrientationType ScreenOrientationController::computeOrientation(
}
}
-void ScreenOrientationController::pageVisibilityChanged()
-{
- if (page() && page()->visibilityState() == PageVisibilityStateVisible) {
- blink::WebScreenOrientationType oldOrientation = m_overrideOrientation;
- m_overrideOrientation = blink::WebScreenOrientationUndefined;
- // FIXME: sendOrientationChangeEvent() currently send an event all the
- // children of the frame, so it should only be called on the frame on
- // top of the tree. We would need the embedder to call
- // sendOrientationChangeEvent on every WebFrame part of a WebView to be
- // able to remove this.
- if (m_frame == m_frame.localFrameRoot() && oldOrientation != orientation())
- m_frame.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
+void ScreenOrientationController::updateOrientation()
{
- 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;
- }
-
blink::WebScreenOrientationType orientationType = screenOrientationType(m_frame.view());
if (orientationType == blink::WebScreenOrientationUndefined) {
// The embedder could not provide us with an orientation, deduce it ourselves.
orientationType = computeOrientation(m_frame.view());
}
ASSERT(orientationType != blink::WebScreenOrientationUndefined);
- return orientationType;
+
+ m_orientation->setType(orientationType);
+ m_orientation->setAngle(screenOrientationAngle(m_frame.view()));
+}
+
+void ScreenOrientationController::pageVisibilityChanged()
+{
+ if (!page() || page()->visibilityState() != PageVisibilityStateVisible)
+ return;
+
+ // The orientation type and angle are tied in a way that if the angle has
+ // changed, the type must have changed.
+ unsigned short currentAngle = screenOrientationAngle(m_frame.view());
+
+ // FIXME: sendOrientationChangeEvent() currently send an event all the
+ // children of the frame, so it should only be called on the frame on
+ // top of the tree. We would need the embedder to call
+ // sendOrientationChangeEvent on every WebFrame part of a WebView to be
+ // able to remove this.
+ if (m_frame == m_frame.localFrameRoot() && m_orientation->angle() != currentAngle)
+ notifyOrientationChanged();
+}
+
+void ScreenOrientationController::notifyOrientationChanged()
+{
+ if (!RuntimeEnabledFeatures::orientationEventEnabled() && !RuntimeEnabledFeatures::screenOrientationEnabled())
+ return;
+
+ if (!page() || page()->visibilityState() != PageVisibilityStateVisible)
+ return;
+
+ updateOrientation();
+
+ // Keep track of the frames that need to be notified before notifying the
+ // current frame as it will prevent side effects from the orientationchange
+ // event handlers.
+ Vector<RefPtr<LocalFrame> > childFrames;
+ for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree().nextSibling()) {
+ if (child->isLocalFrame())
+ childFrames.append(toLocalFrame(child));
+ }
+
+ // Notify current frame.
+ LocalDOMWindow* window = m_frame.domWindow();
+ if (window)
+ window->dispatchEvent(Event::create(EventTypeNames::orientationchange));
+
+ // Notify subframes.
+ for (size_t i = 0; i < childFrames.size(); ++i)
+ ScreenOrientationController::from(*childFrames[i]).notifyOrientationChanged();
+}
+
+OrientationInformation* ScreenOrientationController::orientation()
+{
+ if (!m_orientation->initialized())
+ updateOrientation();
+
+ return m_orientation.get();
}
void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLockType orientation, blink::WebLockOrientationCallback* callback)
@@ -132,4 +165,10 @@ void ScreenOrientationController::unlockOrientation()
m_client->unlockOrientation();
}
+void ScreenOrientationController::trace(Visitor* visitor)
+{
+ WillBeHeapSupplement<LocalFrame>::trace(visitor);
+ visitor->trace(m_orientation);
+}
+
} // namespace WebCore
« no previous file with comments | « Source/modules/screen_orientation/ScreenOrientationController.h ('k') | Source/web/WebLocalFrameImpl.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698