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

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

Issue 381753002: Revert of [screen-orientation] Update implementation to match recent spec changes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 5 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 8e1882d59117cf66d219d025dfcec93b491f0380..af35b986950871a69d10afc1166fb7977f197568 100644
--- a/Source/modules/screen_orientation/ScreenOrientationController.cpp
+++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp
@@ -5,11 +5,11 @@
#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/ScreenOrientation.h"
#include "platform/LayoutTestSupport.h"
#include "platform/PlatformScreen.h"
#include "public/platform/WebScreenOrientationClient.h"
@@ -32,13 +32,14 @@
WillBeHeapSupplement<LocalFrame>::provideTo(frame, supplementName(), adoptPtrWillBeNoop(controller));
}
-ScreenOrientationController* ScreenOrientationController::from(LocalFrame& frame)
+ScreenOrientationController& ScreenOrientationController::from(LocalFrame& frame)
{
- return static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalFrame>::from(frame, supplementName()));
+ return *static_cast<ScreenOrientationController*>(WillBeHeapSupplement<LocalFrame>::from(frame, supplementName()));
}
ScreenOrientationController::ScreenOrientationController(LocalFrame& frame, blink::WebScreenOrientationClient* client)
: PageLifecycleObserver(frame.page())
+ , m_overrideOrientation(blink::WebScreenOrientationUndefined)
, m_client(client)
, m_frame(frame)
{
@@ -76,9 +77,33 @@
}
}
-void ScreenOrientationController::updateOrientation()
+void ScreenOrientationController::pageVisibilityChanged()
{
- ASSERT(m_orientation);
+ 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
+{
+ 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) {
@@ -86,66 +111,10 @@
orientationType = computeOrientation(m_frame.view());
}
ASSERT(orientationType != blink::WebScreenOrientationUndefined);
-
- m_orientation->setType(orientationType);
- m_orientation->setAngle(screenOrientationAngle(m_frame.view()));
+ return orientationType;
}
-void ScreenOrientationController::pageVisibilityChanged()
-{
- if (!m_orientation || !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()
-{
- ASSERT(RuntimeEnabledFeatures::screenOrientationEnabled());
-
- if (!m_orientation || !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 change 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 orientation object.
- m_orientation->dispatchEvent(Event::create(EventTypeNames::change));
-
- // ... and child frames, if they have a ScreenOrientationController.
- for (size_t i = 0; i < childFrames.size(); ++i) {
- ScreenOrientationController* controller = ScreenOrientationController::from(*childFrames[i]);
- if (controller)
- controller->notifyOrientationChanged();
- }
-}
-
-void ScreenOrientationController::setOrientation(ScreenOrientation* orientation)
-{
- m_orientation = orientation;
- if (m_orientation)
- updateOrientation();
-}
-
-void ScreenOrientationController::lock(blink::WebScreenOrientationLockType orientation, blink::WebLockOrientationCallback* callback)
+void ScreenOrientationController::lockOrientation(blink::WebScreenOrientationLockType orientation, blink::WebLockOrientationCallback* callback)
{
if (!m_client) {
return;
@@ -154,7 +123,7 @@
m_client->lockOrientation(orientation, callback);
}
-void ScreenOrientationController::unlock()
+void ScreenOrientationController::unlockOrientation()
{
if (!m_client) {
return;
@@ -163,15 +132,4 @@
m_client->unlockOrientation();
}
-const LocalFrame& ScreenOrientationController::frame() const
-{
- return m_frame;
-}
-
-void ScreenOrientationController::trace(Visitor* visitor)
-{
- visitor->trace(m_orientation);
- WillBeHeapSupplement<LocalFrame>::trace(visitor);
-}
-
} // namespace WebCore

Powered by Google App Engine
This is Rietveld 408576698