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
23 #include "HTMLVideoElement.h"
24 #include "PlatformVideoWindowPrivate.h"
25
26 #include <QApplication>
27 #include <QDesktopWidget>
28 #include <QKeyEvent>
29 #include <QPalette>
30 using namespace WebCore;
31
32 static const int gHideMouseCursorDelay = 3000;
33
FullScreenVideoWindow()34 FullScreenVideoWindow::FullScreenVideoWindow()
35 : QWidget(0, Qt::Window)
36 , m_mediaElement(0)
37 {
38 setAttribute(Qt::WA_NativeWindow);
39 setWindowModality(Qt::ApplicationModal);
40 setAttribute(Qt::WA_NoSystemBackground, true);
41 setAttribute(Qt::WA_PaintOnScreen, true);
42
43 m_cursorTimer.setSingleShot(true);
44 connect(&m_cursorTimer, SIGNAL(timeout()), this, SLOT(hideCursor()));
45 }
46
setVideoElement(HTMLVideoElement * element)47 void FullScreenVideoWindow::setVideoElement(HTMLVideoElement* element)
48 {
49 m_mediaElement = element;
50 }
51
closeEvent(QCloseEvent *)52 void FullScreenVideoWindow::closeEvent(QCloseEvent*)
53 {
54 m_cursorTimer.stop();
55 setMouseTracking(false);
56 releaseMouse();
57 QApplication::restoreOverrideCursor();
58 }
59
keyPressEvent(QKeyEvent * ev)60 void FullScreenVideoWindow::keyPressEvent(QKeyEvent* ev)
61 {
62 if (m_mediaElement && ev->key() == Qt::Key_Space) {
63 if (!m_mediaElement->paused())
64 m_mediaElement->pause(true);
65 else
66 m_mediaElement->play(true);
67 } else if (ev->key() == Qt::Key_Escape)
68 emit closed();
69 QWidget::keyPressEvent(ev);
70 }
71
event(QEvent * ev)72 bool FullScreenVideoWindow::event(QEvent* ev)
73 {
74 switch (ev->type()) {
75 case QEvent::MouseMove:
76 showCursor();
77 ev->accept();
78 return true;
79 case QEvent::MouseButtonDblClick:
80 emit closed();
81 ev->accept();
82 return true;
83 default:
84 return QWidget::event(ev);
85 }
86 }
87
showFullScreen()88 void FullScreenVideoWindow::showFullScreen()
89 {
90 QWidget::showFullScreen();
91 setMouseTracking(true);
92 raise();
93 setFocus();
94 hideCursor();
95 }
96
hideCursor()97 void FullScreenVideoWindow::hideCursor()
98 {
99 QApplication::setOverrideCursor(QCursor(Qt::BlankCursor));
100 }
101
showCursor()102 void FullScreenVideoWindow::showCursor()
103 {
104 QApplication::restoreOverrideCursor();
105 m_cursorTimer.start(gHideMouseCursorDelay);
106 }
107
108
PlatformVideoWindow()109 PlatformVideoWindow::PlatformVideoWindow()
110 {
111 m_window = new FullScreenVideoWindow();
112 m_window->setWindowFlags(m_window->windowFlags() | Qt::FramelessWindowHint);
113 QPalette p;
114 p.setColor(QPalette::Base, Qt::black);
115 p.setColor(QPalette::Window, Qt::black);
116 m_window->setPalette(p);
117 m_window->showFullScreen();
118 m_videoWindowId = m_window->winId();
119 }
120
~PlatformVideoWindow()121 PlatformVideoWindow::~PlatformVideoWindow()
122 {
123 delete m_window;
124 m_videoWindowId = 0;
125 }
126
prepareForOverlay(GstMessage *)127 void PlatformVideoWindow::prepareForOverlay(GstMessage*)
128 {
129 }
130