1/*
2 * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3 *
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.
8 *
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.
13 *
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.
18 *
19 */
20
21#include "config.h"
22#include "FullScreenVideoQt.h"
23
24#include "ChromeClientQt.h"
25#if USE(QT_MULTIMEDIA)
26#include "MediaPlayerPrivateQt.h"
27#endif
28#include "HTMLNames.h"
29#include "HTMLVideoElement.h"
30#include "Node.h"
31
32#if USE(GSTREAMER)
33#include "GStreamerGWorld.h"
34#include "PlatformVideoWindowPrivate.h"
35#endif
36
37#if USE(QT_MULTIMEDIA)
38#include <QMediaPlayer>
39#endif
40
41namespace WebCore {
42
43#if USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)
44GStreamerFullScreenVideoHandler::GStreamerFullScreenVideoHandler()
45    : m_videoElement(0)
46    , m_fullScreenWidget(0)
47{
48}
49
50void GStreamerFullScreenVideoHandler::setVideoElement(HTMLVideoElement* element)
51{
52    m_videoElement = element;
53}
54
55void GStreamerFullScreenVideoHandler::enterFullScreen()
56{
57    if (m_videoElement->platformMedia().type != WebCore::PlatformMedia::GStreamerGWorldType)
58        return;
59
60    GStreamerGWorld* gstreamerGWorld = m_videoElement->platformMedia().media.gstreamerGWorld;
61
62    if (!gstreamerGWorld->enterFullscreen())
63        return;
64
65    m_fullScreenWidget = reinterpret_cast<FullScreenVideoWindow*>(gstreamerGWorld->platformVideoWindow()->window());
66    m_fullScreenWidget->setVideoElement(m_videoElement);
67    connect(m_fullScreenWidget, SIGNAL(closed()), this, SLOT(windowClosed()));
68    m_fullScreenWidget->showFullScreen();
69}
70
71void GStreamerFullScreenVideoHandler::windowClosed()
72{
73    m_videoElement->exitFullscreen();
74}
75
76void GStreamerFullScreenVideoHandler::exitFullScreen()
77{
78    if (m_videoElement->platformMedia().type == WebCore::PlatformMedia::GStreamerGWorldType)
79        m_videoElement->platformMedia().media.gstreamerGWorld->exitFullscreen();
80
81    m_fullScreenWidget->setVideoElement(0);
82    m_fullScreenWidget->close();
83}
84#endif
85
86FullScreenVideoQt::FullScreenVideoQt(ChromeClientQt* chromeClient)
87    : m_chromeClient(chromeClient)
88    , m_videoElement(0)
89{
90    Q_ASSERT(m_chromeClient);
91
92#if USE(QT_MULTIMEDIA)
93    m_FullScreenVideoHandler = m_chromeClient->createFullScreenVideoHandler();
94    if (m_FullScreenVideoHandler)
95        connect(m_FullScreenVideoHandler, SIGNAL(fullScreenClosed()), this, SLOT(aboutToClose()));
96#endif
97
98#if USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)
99    m_FullScreenVideoHandlerGStreamer = new GStreamerFullScreenVideoHandler;
100#endif
101}
102
103FullScreenVideoQt::~FullScreenVideoQt()
104{
105#if USE(QT_MULTIMEDIA)
106    delete m_FullScreenVideoHandler;
107#endif
108#if USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)
109    delete m_FullScreenVideoHandlerGStreamer;
110#endif
111}
112
113void FullScreenVideoQt::enterFullScreenForNode(Node* node)
114{
115    Q_ASSERT(node);
116    m_videoElement = static_cast<HTMLVideoElement*>(node);
117
118#if USE(QT_MULTIMEDIA)
119    Q_ASSERT(m_FullScreenVideoHandler);
120    HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(node);
121    PlatformMedia platformMedia = videoElement->platformMedia();
122
123    ASSERT(platformMedia.type == PlatformMedia::QtMediaPlayerType);
124    if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
125        return;
126
127    if (!m_FullScreenVideoHandler)
128        return;
129
130    MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayer();
131    mediaPlayerQt->removeVideoItem();
132    m_FullScreenVideoHandler->enterFullScreen(mediaPlayerQt->mediaPlayer());
133#endif
134
135#if USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)
136    m_FullScreenVideoHandlerGStreamer->setVideoElement(m_videoElement);
137    m_FullScreenVideoHandlerGStreamer->enterFullScreen();
138#endif
139}
140
141void FullScreenVideoQt::exitFullScreenForNode(Node* node)
142{
143    Q_ASSERT(node);
144
145#if USE(QT_MULTIMEDIA)
146    HTMLVideoElement* videoElement = static_cast<HTMLVideoElement*>(node);
147    PlatformMedia platformMedia = videoElement->platformMedia();
148
149    ASSERT(platformMedia.type == PlatformMedia::QtMediaPlayerType);
150    if (platformMedia.type != PlatformMedia::QtMediaPlayerType)
151        return;
152
153    Q_ASSERT(m_FullScreenVideoHandler);
154
155    if (!m_FullScreenVideoHandler)
156        return;
157
158    m_FullScreenVideoHandler->exitFullScreen();
159    MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayer();
160    mediaPlayerQt->restoreVideoItem();
161#endif
162#if USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)
163    m_FullScreenVideoHandlerGStreamer->exitFullScreen();
164#endif
165}
166
167void FullScreenVideoQt::aboutToClose()
168{
169    Q_ASSERT(m_videoElement);
170    m_videoElement->exitFullscreen();
171}
172
173#if USE(QT_MULTIMEDIA)
174MediaPlayerPrivateQt* FullScreenVideoQt::mediaPlayer()
175{
176    Q_ASSERT(m_videoElement);
177    PlatformMedia platformMedia = m_videoElement->platformMedia();
178    return static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
179}
180#endif
181
182bool FullScreenVideoQt::requiresFullScreenForVideoPlayback()
183{
184#if USE(QT_MULTIMEDIA)
185    return m_FullScreenVideoHandler ? m_FullScreenVideoHandler->requiresFullScreenForVideoPlayback() : false;
186#else
187    return false;
188#endif
189}
190
191bool FullScreenVideoQt::isValid() const
192{
193#if USE(QT_MULTIMEDIA)
194    return m_FullScreenVideoHandler;
195#endif
196#if USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO)
197    return m_FullScreenVideoHandlerGStreamer;
198#else
199    return 0;
200#endif
201}
202
203}
204
205