This source file includes following definitions.
- create
- m_isCancelingFullScreen
- willEnterFullScreen
- didEnterFullScreen
- willExitFullScreen
- didExitFullScreen
- enterFullScreenForElement
- exitFullScreenForElement
#include "config.h"
#include "FullscreenController.h"
#include "RuntimeEnabledFeatures.h"
#include "WebFrame.h"
#include "WebViewClient.h"
#include "WebViewImpl.h"
#include "core/dom/Document.h"
#include "core/dom/FullscreenElementStack.h"
#include "core/frame/LocalFrame.h"
#include "core/html/HTMLMediaElement.h"
#include "platform/LayoutTestSupport.h"
using namespace WebCore;
namespace blink {
PassOwnPtr<FullscreenController> FullscreenController::create(WebViewImpl* webViewImpl)
{
return adoptPtr(new FullscreenController(webViewImpl));
}
FullscreenController::FullscreenController(WebViewImpl* webViewImpl)
: m_webViewImpl(webViewImpl)
, m_exitFullscreenPageScaleFactor(0)
, m_isCancelingFullScreen(false)
{
}
void FullscreenController::willEnterFullScreen()
{
if (!m_provisionalFullScreenElement)
return;
Document& doc = m_provisionalFullScreenElement->document();
if (doc.frame()) {
FullscreenElementStack::from(doc).webkitWillEnterFullScreenForElement(m_provisionalFullScreenElement.get());
m_fullScreenFrame = doc.frame();
}
m_provisionalFullScreenElement.clear();
}
void FullscreenController::didEnterFullScreen()
{
if (!m_fullScreenFrame)
return;
if (Document* doc = m_fullScreenFrame->document()) {
if (FullscreenElementStack::isFullScreen(*doc)) {
if (!m_exitFullscreenPageScaleFactor) {
m_exitFullscreenPageScaleFactor = m_webViewImpl->pageScaleFactor();
m_exitFullscreenScrollOffset = m_webViewImpl->mainFrame()->scrollOffset();
m_webViewImpl->setPageScaleFactorPreservingScrollOffset(1.0f);
}
FullscreenElementStack::from(*doc).webkitDidEnterFullScreenForElement(0);
if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled()) {
Element* element = FullscreenElementStack::currentFullScreenElementFrom(*doc);
ASSERT(element);
if (isHTMLMediaElement(*element) && m_webViewImpl->layerTreeView())
m_webViewImpl->layerTreeView()->setHasTransparentBackground(true);
}
}
}
}
void FullscreenController::willExitFullScreen()
{
if (!m_fullScreenFrame)
return;
if (Document* doc = m_fullScreenFrame->document()) {
FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExists(*doc);
if (!fullscreen)
return;
if (fullscreen->isFullScreen(*doc)) {
m_isCancelingFullScreen = true;
fullscreen->webkitCancelFullScreen();
m_isCancelingFullScreen = false;
fullscreen->webkitWillExitFullScreenForElement(0);
if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled() && m_webViewImpl->layerTreeView())
m_webViewImpl->layerTreeView()->setHasTransparentBackground(m_webViewImpl->isTransparent());
}
}
}
void FullscreenController::didExitFullScreen()
{
if (!m_fullScreenFrame)
return;
if (Document* doc = m_fullScreenFrame->document()) {
if (FullscreenElementStack* fullscreen = FullscreenElementStack::fromIfExists(*doc)) {
if (fullscreen->webkitIsFullScreen()) {
if (m_exitFullscreenPageScaleFactor) {
m_webViewImpl->setPageScaleFactor(m_exitFullscreenPageScaleFactor,
WebPoint(m_exitFullscreenScrollOffset.width(), m_exitFullscreenScrollOffset.height()));
m_exitFullscreenPageScaleFactor = 0;
m_exitFullscreenScrollOffset = IntSize();
}
fullscreen->webkitDidExitFullScreenForElement(0);
}
}
}
m_fullScreenFrame.clear();
}
void FullscreenController::enterFullScreenForElement(WebCore::Element* element)
{
if (m_provisionalFullScreenElement) {
m_provisionalFullScreenElement = element;
return;
}
if (m_fullScreenFrame) {
m_provisionalFullScreenElement = element;
willEnterFullScreen();
didEnterFullScreen();
return;
}
if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled()
&& isHTMLMediaElement(element)
&& !isRunningLayoutTest()) {
HTMLMediaElement* mediaElement = toHTMLMediaElement(element);
if (mediaElement->player() && mediaElement->player()->canShowFullscreenOverlay()) {
mediaElement->player()->showFullscreenOverlay();
m_provisionalFullScreenElement = element;
return;
}
}
if (WebViewClient* client = m_webViewImpl->client()) {
if (client->enterFullScreen())
m_provisionalFullScreenElement = element;
}
}
void FullscreenController::exitFullScreenForElement(WebCore::Element* element)
{
if (m_isCancelingFullScreen)
return;
if (RuntimeEnabledFeatures::overlayFullscreenVideoEnabled()
&& isHTMLMediaElement(element)
&& !isRunningLayoutTest()) {
HTMLMediaElement* mediaElement = toHTMLMediaElement(element);
if (mediaElement->player())
mediaElement->player()->hideFullscreenOverlay();
return;
}
if (WebViewClient* client = m_webViewImpl->client())
client->exitFullScreen();
}
}