2011-01-17 Yi Shen <yi.4.shen@nokia.com>
[WebKit-https.git] / Source / WebKit / qt / examples / platformplugin / WebPlugin.cpp
index d029b73..320079f 100644 (file)
@@ -19,7 +19,9 @@
  */
 #include "WebPlugin.h"
 
+#include <QEvent>
 #include <QHBoxLayout>
+#include <QKeyEvent>
 #include <QListWidget>
 #include <QListWidgetItem>
 #include <QPainter>
@@ -208,6 +210,71 @@ MultipleSelectionPopup::MultipleSelectionPopup(const QWebSelectData& data)
     resize(size().width(), visibleItemCount * gMaemoListItemSize);
 }
 
+#if defined(ENABLE_QT_MULTIMEDIA) && ENABLE_QT_MULTIMEDIA
+FullScreenVideoWidget::FullScreenVideoWidget(QMediaPlayer* player)
+    : QVideoWidget()
+    , m_mediaPlayer(player)
+{
+    Q_ASSERT(m_mediaPlayer);
+
+    setFullScreen(true);
+    m_mediaPlayer->setVideoOutput(this);
+}
+
+bool FullScreenVideoWidget::event(QEvent* ev)
+{
+    if (ev->type() ==  QEvent::MouseButtonDblClick) {
+        emit fullScreenClosed();
+        ev->accept();
+        return true;
+    } 
+    return QWidget::event(ev);
+}
+
+void FullScreenVideoWidget::keyPressEvent(QKeyEvent* ev)
+{
+    if (ev->key() == Qt::Key_Space) {
+        if (m_mediaPlayer->state() == QMediaPlayer::PlayingState)
+            m_mediaPlayer->pause();
+        else
+            m_mediaPlayer->play();
+        ev->accept();
+        return;
+    }
+}
+
+FullScreenVideoHandler::FullScreenVideoHandler()
+    : m_mediaWidget(0)
+{
+}
+
+FullScreenVideoHandler::~FullScreenVideoHandler()
+{
+    delete m_mediaWidget;
+}
+
+bool FullScreenVideoHandler::requiresFullScreenForVideoPlayback() const
+{
+    return true;
+}
+
+void FullScreenVideoHandler::enterFullScreen(QMediaPlayer* player)
+{
+    Q_ASSERT(player);
+
+    m_mediaWidget = new FullScreenVideoWidget(player);
+    connect(m_mediaWidget, SIGNAL(fullScreenClosed()), this, SIGNAL(fullScreenClosed()));
+    m_mediaWidget->showFullScreen();
+}
+
+void FullScreenVideoHandler::exitFullScreen()
+{
+    m_mediaWidget->hide();
+    delete m_mediaWidget;
+    m_mediaWidget = 0;
+}
+#endif
+
 bool WebPlugin::supportsExtension(Extension extension) const
 {
     switch (extension) {
@@ -219,6 +286,10 @@ bool WebPlugin::supportsExtension(Extension extension) const
 #endif
     case TouchInteraction:
         return true;
+#if defined(ENABLE_QT_MULTIMEDIA) && ENABLE_QT_MULTIMEDIA
+    case FullScreenVideoPlayer:
+        return true;
+#endif
     default:
         return false;
     }
@@ -235,6 +306,10 @@ QObject* WebPlugin::createExtension(Extension extension) const
 #endif
     case TouchInteraction:
         return new TouchModifier();
+#if defined(ENABLE_QT_MULTIMEDIA) && ENABLE_QT_MULTIMEDIA
+    case FullScreenVideoPlayer:
+        return new FullScreenVideoHandler();
+#endif
     default:
         return 0;
     }