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 ENABLE(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"
38 #if ENABLE(QT_MULTIMEDIA)
39 #include <QGraphicsVideoItem>
40 #include <QMediaPlayer>
47 GStreamerFullScreenVideoHandler::GStreamerFullScreenVideoHandler()
49 , m_fullScreenWidget(0)
53 void GStreamerFullScreenVideoHandler::setVideoElement(HTMLVideoElement* element)
55 m_videoElement = element;
58 void GStreamerFullScreenVideoHandler::enterFullScreen()
60 if (m_videoElement->platformMedia().type != WebCore::PlatformMedia::GStreamerGWorldType)
63 GStreamerGWorld* gstreamerGWorld = m_videoElement->platformMedia().media.gstreamerGWorld;
65 if (!gstreamerGWorld->enterFullscreen())
68 m_fullScreenWidget = reinterpret_cast<FullScreenVideoWindow*>(gstreamerGWorld->platformVideoWindow()->window());
69 m_fullScreenWidget->setVideoElement(m_videoElement);
70 connect(m_fullScreenWidget, SIGNAL(closed()), this, SLOT(windowClosed()));
71 m_fullScreenWidget->showFullScreen();
74 void GStreamerFullScreenVideoHandler::windowClosed()
76 m_videoElement->exitFullscreen();
79 void GStreamerFullScreenVideoHandler::exitFullScreen()
81 if (m_videoElement->platformMedia().type == WebCore::PlatformMedia::GStreamerGWorldType)
82 m_videoElement->platformMedia().media.gstreamerGWorld->exitFullscreen();
84 m_fullScreenWidget->setVideoElement(0);
85 m_fullScreenWidget->close();
89 #if ENABLE(QT_MULTIMEDIA)
90 bool DefaultFullScreenVideoHandler::s_shouldForceFullScreenVideoPlayback = false;
92 DefaultFullScreenVideoHandler::DefaultFullScreenVideoHandler()
93 : QWebFullScreenVideoHandler()
94 , m_fullScreenWidget(new FullScreenVideoWidget)
96 connect(m_fullScreenWidget, SIGNAL(didExitFullScreen()), this, SIGNAL(fullScreenClosed()));
97 m_fullScreenWidget->hide();
99 m_fullScreenWidget->close();
102 DefaultFullScreenVideoHandler::~DefaultFullScreenVideoHandler()
104 delete m_fullScreenWidget;
107 bool DefaultFullScreenVideoHandler::requiresFullScreenForVideoPlayback() const
109 static bool initialized = false;
111 QByteArray forceFullScreen = qgetenv("QT_WEBKIT_FORCE_FULLSCREEN_VIDEO");
112 if (!forceFullScreen.isEmpty())
113 s_shouldForceFullScreenVideoPlayback = true;
118 return s_shouldForceFullScreenVideoPlayback;
121 void DefaultFullScreenVideoHandler::enterFullScreen(QMediaPlayer* player)
123 m_fullScreenWidget->show(player);
126 void DefaultFullScreenVideoHandler::exitFullScreen()
128 m_fullScreenWidget->close();
132 FullScreenVideoQt::FullScreenVideoQt(ChromeClientQt* chromeClient)
133 : m_chromeClient(chromeClient)
136 Q_ASSERT(m_chromeClient);
138 #if ENABLE(QT_MULTIMEDIA)
139 m_FullScreenVideoHandler = m_chromeClient->m_platformPlugin.createFullScreenVideoHandler();
140 if (!m_FullScreenVideoHandler)
141 m_FullScreenVideoHandler = new DefaultFullScreenVideoHandler;
143 if (m_FullScreenVideoHandler)
144 connect(m_FullScreenVideoHandler, SIGNAL(fullScreenClosed()), this, SLOT(aboutToClose()));
148 m_FullScreenVideoHandlerGStreamer = new GStreamerFullScreenVideoHandler;
152 FullScreenVideoQt::~FullScreenVideoQt()
154 #if ENABLE(QT_MULTIMEDIA)
155 delete m_FullScreenVideoHandler;
158 delete m_FullScreenVideoHandlerGStreamer;
162 void FullScreenVideoQt::enterFullScreenForNode(Node* node)
165 Q_ASSERT(m_FullScreenVideoHandler);
167 m_videoElement = static_cast<HTMLVideoElement*>(node);
169 #if ENABLE(QT_MULTIMEDIA)
170 HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(node);
171 PlatformMedia platformMedia = videoElement->platformMedia();
173 ASSERT(platformMedia.type == PlatformMedia::QtMediaPlayerType);
174 if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
177 if (!m_FullScreenVideoHandler)
180 MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayer();
181 mediaPlayerQt->removeVideoItem();
182 m_FullScreenVideoHandler->enterFullScreen(mediaPlayerQt->mediaPlayer());
186 m_FullScreenVideoHandlerGStreamer->setVideoElement(m_videoElement);
187 m_FullScreenVideoHandlerGStreamer->enterFullScreen();
191 void FullScreenVideoQt::exitFullScreenForNode(Node* node)
195 #if ENABLE(QT_MULTIMEDIA)
196 HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(node);
197 PlatformMedia platformMedia = videoElement->platformMedia();
199 ASSERT(platformMedia.type == PlatformMedia::QtMediaPlayerType);
200 if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
203 Q_ASSERT(m_FullScreenVideoHandler);
205 if (!m_FullScreenVideoHandler)
208 m_FullScreenVideoHandler->exitFullScreen();
209 MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayer();
210 mediaPlayerQt->restoreVideoItem();
213 m_FullScreenVideoHandlerGStreamer->exitFullScreen();
217 void FullScreenVideoQt::aboutToClose()
219 Q_ASSERT(m_videoElement);
220 m_videoElement->exitFullscreen();
223 #if ENABLE(QT_MULTIMEDIA)
224 MediaPlayerPrivateQt* FullScreenVideoQt::mediaPlayer()
226 Q_ASSERT(m_videoElement);
227 PlatformMedia platformMedia = m_videoElement->platformMedia();
228 return static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
232 bool FullScreenVideoQt::requiresFullScreenForVideoPlayback()
234 #if ENABLE(QT_MULTIMEDIA)
235 return m_FullScreenVideoHandler ? m_FullScreenVideoHandler->requiresFullScreenForVideoPlayback() : false;
242 bool FullScreenVideoQt::isValid() const
244 #if ENABLE(QT_MULTIMEDIA)
245 return m_FullScreenVideoHandler;
248 return m_FullScreenVideoHandlerGStreamer;