1/* 2 Copyright (C) 2010 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#include "config.h" 21#include "PlatformVideoWindow.h" 22#if ENABLE(VIDEO) && USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO) 23 24#include "HTMLVideoElement.h" 25#include "PlatformVideoWindowPrivate.h" 26 27#include <QCursor> 28#include <QGuiApplication> 29#include <QKeyEvent> 30#include <QPalette> 31 32using namespace WebCore; 33 34#ifndef QT_NO_CURSOR 35static const int gHideMouseCursorDelay = 3000; 36#endif 37 38FullScreenVideoWindow::FullScreenVideoWindow() 39 : m_mediaElement(0) 40{ 41 setModality(Qt::ApplicationModal); 42 43#ifndef QT_NO_CURSOR 44 m_cursorTimer.setSingleShot(true); 45 connect(&m_cursorTimer, SIGNAL(timeout()), this, SLOT(hideCursor())); 46#endif 47} 48 49void FullScreenVideoWindow::setVideoElement(HTMLVideoElement* element) 50{ 51 m_mediaElement = element; 52} 53 54void FullScreenVideoWindow::keyPressEvent(QKeyEvent* ev) 55{ 56 if (m_mediaElement && ev->key() == Qt::Key_Space) { 57 if (!m_mediaElement->paused()) 58 m_mediaElement->pause(); 59 else 60 m_mediaElement->play(); 61 } else if (ev->key() == Qt::Key_Escape) 62 emit closed(); 63 QWindow::keyPressEvent(ev); 64} 65 66bool FullScreenVideoWindow::event(QEvent* ev) 67{ 68 switch (ev->type()) { 69 case QEvent::MouseMove: 70 showCursor(); 71 ev->accept(); 72 return true; 73 case QEvent::MouseButtonDblClick: 74 emit closed(); 75 ev->accept(); 76 return true; 77 case QEvent::Close: 78#ifndef QT_NO_CURSOR 79 m_cursorTimer.stop(); 80#endif 81#ifndef QT_NO_CURSOR 82 QGuiApplication::restoreOverrideCursor(); 83#endif 84 break; 85 default: 86 break; 87 } 88 return QWindow::event(ev); 89} 90 91void FullScreenVideoWindow::showFullScreen() 92{ 93 QWindow::showFullScreen(); 94 raise(); 95 hideCursor(); 96} 97 98void FullScreenVideoWindow::hideCursor() 99{ 100#ifndef QT_NO_CURSOR 101 QGuiApplication::setOverrideCursor(QCursor(Qt::BlankCursor)); 102#endif 103} 104 105void FullScreenVideoWindow::showCursor() 106{ 107#ifndef QT_NO_CURSOR 108 QGuiApplication::restoreOverrideCursor(); 109 m_cursorTimer.start(gHideMouseCursorDelay); 110#endif 111} 112 113 114PlatformVideoWindow::PlatformVideoWindow() 115{ 116 QWindow* win = new FullScreenVideoWindow(); 117 m_window = win; 118 win->setFlags(win->flags() | Qt::FramelessWindowHint); 119 // FIXME: Port to Qt 5. 120 win->showFullScreen(); 121 m_videoWindowId = win->winId(); 122} 123 124PlatformVideoWindow::~PlatformVideoWindow() 125{ 126 delete m_window; 127 m_videoWindowId = 0; 128} 129 130void PlatformVideoWindow::prepareForOverlay(GstMessage*) 131{ 132} 133#endif // ENABLE(VIDEO) && USE(GSTREAMER) && USE(NATIVE_FULLSCREEN_VIDEO) 134