| 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..c8df9c7c25cf1f06c11210238cc314185e5f8087 100644
|
| --- a/Source/modules/screen_orientation/ScreenOrientationController.cpp
|
| +++ b/Source/modules/screen_orientation/ScreenOrientationController.cpp
|
| @@ -5,15 +5,18 @@
|
| #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"
|
|
|
| +
|
| namespace WebCore {
|
|
|
| ScreenOrientationController::~ScreenOrientationController()
|
| @@ -39,7 +42,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 +80,68 @@ blink::WebScreenOrientationType ScreenOrientationController::computeOrientation(
|
| }
|
| }
|
|
|
| -void ScreenOrientationController::pageVisibilityChanged()
|
| +void ScreenOrientationController::updateOrientation()
|
| {
|
| - 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) {
|
| // 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;
|
| +
|
| + OrientationInformation previousOrientation = *m_orientation;
|
| + updateOrientation();
|
| +
|
| + // 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() && previousOrientation != *m_orientation)
|
| + ScreenOrientationController::from(m_frame).notifyOrientationChanged();
|
| +}
|
| +
|
| +void ScreenOrientationController::notifyOrientationChanged()
|
| +{
|
| + if (!RuntimeEnabledFeatures::orientationEventEnabled() && !RuntimeEnabledFeatures::screenOrientationEnabled())
|
| + return;
|
| +
|
| + if (!page() || page()->visibilityState() != PageVisibilityStateVisible)
|
| + return;
|
| +
|
| + updateOrientation();
|
| +
|
| + LocalDOMWindow* window = m_frame.domWindow();
|
| + if (!window)
|
| + return;
|
| + window->dispatchEvent(Event::create(EventTypeNames::orientationchange));
|
| +
|
| + // Notify subframes.
|
| + Vector<RefPtr<LocalFrame> > childFrames;
|
| + for (Frame* child = m_frame.tree().firstChild(); child; child = child->tree().nextSibling()) {
|
| + if (child->isLocalFrame())
|
| + childFrames.append(toLocalFrame(child));
|
| + }
|
| +
|
| + 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 +162,10 @@ void ScreenOrientationController::unlockOrientation()
|
| m_client->unlockOrientation();
|
| }
|
|
|
| +void ScreenOrientationController::trace(Visitor* visitor)
|
| +{
|
| + WillBeHeapSupplement<LocalFrame>::trace(visitor);
|
| + visitor->trace(m_orientation);
|
| +}
|
| +
|
| } // namespace WebCore
|
|
|