2011-01-17 Yi Shen <yi.4.shen@nokia.com>
[WebKit-https.git] / Source / WebKit / qt / WebCoreSupport / FullScreenVideoQt.cpp
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 #include "HTMLNames.h"
26 #include "HTMLVideoElement.h"
27 #include "MediaPlayerPrivateQt.h"
28 #include "Node.h"
29 #include "qwebkitplatformplugin.h"
30
31 #include <QGraphicsVideoItem>
32
33 namespace WebCore {
34
35 FullScreenVideoQt::FullScreenVideoQt(ChromeClientQt* chromeClient)
36     : m_chromeClient(chromeClient)
37     , m_videoElement(0)
38 {
39     Q_ASSERT(m_chromeClient);
40     m_FullScreenVideoHandler = m_chromeClient->m_platformPlugin.createFullScreenVideoHandler();
41
42     if (m_FullScreenVideoHandler)
43         connect(m_FullScreenVideoHandler, SIGNAL(fullScreenClosed()), this, SLOT(aboutToClose()));
44 }
45
46 FullScreenVideoQt::~FullScreenVideoQt()
47 {
48     delete m_FullScreenVideoHandler;
49 }
50
51 void FullScreenVideoQt::enterFullScreenForNode(Node* node)
52 {
53     Q_ASSERT(node);
54     Q_ASSERT(m_FullScreenVideoHandler);
55
56     if (!m_FullScreenVideoHandler)
57         return;
58
59     MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayerForNode(node);
60     mediaPlayerQt->removeVideoItem();
61     m_FullScreenVideoHandler->enterFullScreen(mediaPlayerQt->mediaPlayer());
62 }
63
64 void FullScreenVideoQt::exitFullScreenForNode(Node* node)
65 {
66     Q_ASSERT(node);
67     Q_ASSERT(m_FullScreenVideoHandler);
68
69     if (!m_FullScreenVideoHandler)
70         return;
71
72     m_FullScreenVideoHandler->exitFullScreen();
73     MediaPlayerPrivateQt* mediaPlayerQt = mediaPlayerForNode(node);
74     mediaPlayerQt->restoreVideoItem();
75 }
76
77 void FullScreenVideoQt::aboutToClose()
78 {
79     Q_ASSERT(m_videoElement);
80     m_videoElement->exitFullscreen();
81 }
82
83 MediaPlayerPrivateQt* FullScreenVideoQt::mediaPlayer()
84 {
85     Q_ASSERT(m_videoElement);
86     PlatformMedia platformMedia = m_videoElement->platformMedia();
87     return static_cast<MediaPlayerPrivateQt*>(platformMedia.media.qtMediaPlayer);
88 }
89
90 MediaPlayerPrivateQt* FullScreenVideoQt::mediaPlayerForNode(Node* node)
91 {
92     Q_ASSERT(node);
93     if (node)
94         m_videoElement = static_cast<HTMLVideoElement*>(node);
95     return mediaPlayer();
96 }
97
98 bool FullScreenVideoQt::requiresFullScreenForVideoPlayback()
99 {
100     return m_FullScreenVideoHandler ? m_FullScreenVideoHandler->requiresFullScreenForVideoPlayback() : false;
101 }
102
103 }
104