2 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
22 #include "FullScreenVideoQt.h"
24 #include "ChromeClientQt.h"
25 #if USE(QT_MULTIMEDIA)
26 #include "FullScreenVideoWidget.h"
27 #include "MediaPlayerPrivateQt.h"
29 #include "HTMLNames.h"
30 #include "HTMLVideoElement.h"
34 #include "GStreamerGWorld.h"
35 #include "PlatformVideoWindowPrivate.h"
39 #include "QTKitFullScreenVideoHandler.h"
42 #if USE(QT_MULTIMEDIA)
43 #include <QGraphicsVideoItem>
44 #include <QMediaPlayer>
51 GStreamerFullScreenVideoHandler::GStreamerFullScreenVideoHandler()
53 , m_fullScreenWidget(0)
57 void GStreamerFullScreenVideoHandler::setVideoElement(HTMLVideoElement* element)
59 m_videoElement = element;
62 void GStreamerFullScreenVideoHandler::enterFullScreen()
64 if (m_videoElement->platformMedia().type != WebCore::PlatformMedia::GStreamerGWorldType)
67 GStreamerGWorld* gstreamerGWorld = m_videoElement->platformMedia().media.gstreamerGWorld;
69 if (!gstreamerGWorld->enterFullscreen())
72 m_fullScreenWidget = reinterpret_cast<FullScreenVideoWindow*>(gstreamerGWorld->platformVideoWindow()->window());
73 m_fullScreenWidget->setVideoElement(m_videoElement);
74 connect(m_fullScreenWidget, SIGNAL(closed()), this, SLOT(windowClosed()));
75 m_fullScreenWidget->showFullScreen();
78 void GStreamerFullScreenVideoHandler::windowClosed()
80 m_videoElement->exitFullscreen();
83 void GStreamerFullScreenVideoHandler::exitFullScreen()
85 if (m_videoElement->platformMedia().type == WebCore::PlatformMedia::GStreamerGWorldType)
86 m_videoElement->platformMedia().media.gstreamerGWorld->exitFullscreen();
88 m_fullScreenWidget->setVideoElement(0);
89 m_fullScreenWidget->close();
93 #if USE(QT_MULTIMEDIA)
94 bool DefaultFullScreenVideoHandler::s_shouldForceFullScreenVideoPlayback = false;
96 DefaultFullScreenVideoHandler::DefaultFullScreenVideoHandler()
97 : QWebFullScreenVideoHandler()
98 , m_fullScreenWidget(new FullScreenVideoWidget)
100 connect(m_fullScreenWidget, SIGNAL(didExitFullScreen()), this, SIGNAL(fullScreenClosed()));
101 m_fullScreenWidget->hide();
103 m_fullScreenWidget->close();
106 DefaultFullScreenVideoHandler::~DefaultFullScreenVideoHandler()
108 delete m_fullScreenWidget;
111 bool DefaultFullScreenVideoHandler::requiresFullScreenForVideoPlayback() const
113 static bool initialized = false;
115 QByteArray forceFullScreen = qgetenv("QT_WEBKIT_FORCE_FULLSCREEN_VIDEO");
116 if (!forceFullScreen.isEmpty())
117 s_shouldForceFullScreenVideoPlayback = true;
122 return s_shouldForceFullScreenVideoPlayback;
125 void DefaultFullScreenVideoHandler::enterFullScreen(QMediaPlayer* player)
127 m_fullScreenWidget->show(player);
130 void DefaultFullScreenVideoHandler::exitFullScreen()
132 m_fullScreenWidget->close();
136 FullScreenVideoQt::FullScreenVideoQt(ChromeClientQt* chromeClient)
137 : m_chromeClient(chromeClient)
140 Q_ASSERT(m_chromeClient);
142 #if USE(QT_MULTIMEDIA)
143 m_FullScreenVideoHandler = m_chromeClient->m_platformPlugin.createFullScreenVideoHandler().leakPtr();
144 if (!m_FullScreenVideoHandler)
145 m_FullScreenVideoHandler = new DefaultFullScreenVideoHandler;
147 if (m_FullScreenVideoHandler)
148 connect(m_FullScreenVideoHandler, SIGNAL(fullScreenClosed()), this, SLOT(aboutToClose()));
152 m_FullScreenVideoHandlerGStreamer = new GStreamerFullScreenVideoHandler;
156 m_FullScreenVideoHandlerQTKit = new QTKitFullScreenVideoHandler;
160 FullScreenVideoQt::~FullScreenVideoQt()
162 #if USE(QT_MULTIMEDIA)
163 delete m_FullScreenVideoHandler;
166 delete m_FullScreenVideoHandlerGStreamer;
169 delete m_FullScreenVideoHandlerQTKit;
173 void FullScreenVideoQt::enterFullScreenForNode(Node* node)
176 m_videoElement = static_cast<HTMLVideoElement*>(node);
178 #if USE(QT_MULTIMEDIA)
179 Q_ASSERT(m_FullScreenVideoHandler);
180 HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(node);
181 PlatformMedia platformMedia = videoElement->platformMedia();
183 ASSERT(platformMedia.type == PlatformMedia::QtMediaPlayerType);
184 if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
187 if (!m_FullScreenVideoHandler)
190 MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayer();
191 mediaPlayerQt->removeVideoItem();
192 m_FullScreenVideoHandler->enterFullScreen(mediaPlayerQt->mediaPlayer());
196 m_FullScreenVideoHandlerGStreamer->setVideoElement(m_videoElement);
197 m_FullScreenVideoHandlerGStreamer->enterFullScreen();
201 m_FullScreenVideoHandlerQTKit->enterFullScreen(m_videoElement);
205 void FullScreenVideoQt::exitFullScreenForNode(Node* node)
209 #if USE(QT_MULTIMEDIA)
210 HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(node);
211 PlatformMedia platformMedia = videoElement->platformMedia();
213 ASSERT(platformMedia.type == PlatformMedia::QtMediaPlayerType);
214 if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
217 Q_ASSERT(m_FullScreenVideoHandler);
219 if (!m_FullScreenVideoHandler)
222 m_FullScreenVideoHandler->exitFullScreen();
223 MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayer();
224 mediaPlayerQt->restoreVideoItem();
227 m_FullScreenVideoHandlerGStreamer->exitFullScreen();
231 m_FullScreenVideoHandlerQTKit->exitFullScreen();
236 void FullScreenVideoQt::aboutToClose()
238 Q_ASSERT(m_videoElement);
239 m_videoElement->exitFullscreen();
242 #if USE(QT_MULTIMEDIA)
243 MediaPlayerPrivateQt* FullScreenVideoQt::mediaPlayer()
245 Q_ASSERT(m_videoElement);
246 PlatformMedia platformMedia = m_videoElement->platformMedia();
247 return static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
251 bool FullScreenVideoQt::requiresFullScreenForVideoPlayback()
253 #if USE(QT_MULTIMEDIA)
254 return m_FullScreenVideoHandler ? m_FullScreenVideoHandler->requiresFullScreenForVideoPlayback() : false;
260 bool FullScreenVideoQt::isValid() const
262 #if USE(QT_MULTIMEDIA)
263 return m_FullScreenVideoHandler;
266 return m_FullScreenVideoHandlerGStreamer;
268 return m_FullScreenVideoHandlerQTKit;