FullScreenVideoQt.cpp 5.9 KB

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