WebFullScreenManager.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*
  2. * Copyright (C) 2011 Apple Inc. All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
  14. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
  17. * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  18. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  19. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  20. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  21. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  23. * THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "config.h"
  26. #include "WebFullScreenManager.h"
  27. #if ENABLE(FULLSCREEN_API)
  28. #include "Connection.h"
  29. #include "WebCoreArgumentCoders.h"
  30. #include "WebFrame.h"
  31. #include "WebFullScreenManagerProxyMessages.h"
  32. #include "WebPage.h"
  33. #include <WebCore/Color.h>
  34. #include <WebCore/Element.h>
  35. #include <WebCore/Frame.h>
  36. #include <WebCore/FrameView.h>
  37. #include <WebCore/Page.h>
  38. #include <WebCore/RenderLayer.h>
  39. #include <WebCore/RenderLayerBacking.h>
  40. #include <WebCore/RenderObject.h>
  41. #include <WebCore/RenderView.h>
  42. #include <WebCore/Settings.h>
  43. using namespace WebCore;
  44. namespace WebKit {
  45. static IntRect screenRectOfContents(Element* element)
  46. {
  47. ASSERT(element);
  48. #if USE(ACCELERATED_COMPOSITING)
  49. if (element->renderer() && element->renderer()->hasLayer() && element->renderer()->enclosingLayer()->isComposited()) {
  50. FloatQuad contentsBox = static_cast<FloatRect>(element->renderer()->enclosingLayer()->backing()->contentsBox());
  51. contentsBox = element->renderer()->localToAbsoluteQuad(contentsBox);
  52. return element->renderer()->view()->frameView()->contentsToScreen(contentsBox.enclosingBoundingBox());
  53. }
  54. #endif
  55. return element->screenRect();
  56. }
  57. PassRefPtr<WebFullScreenManager> WebFullScreenManager::create(WebPage* page)
  58. {
  59. return adoptRef(new WebFullScreenManager(page));
  60. }
  61. WebFullScreenManager::WebFullScreenManager(WebPage* page)
  62. : m_page(page)
  63. {
  64. }
  65. WebFullScreenManager::~WebFullScreenManager()
  66. {
  67. }
  68. WebCore::Element* WebFullScreenManager::element()
  69. {
  70. return m_element.get();
  71. }
  72. void WebFullScreenManager::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageDecoder& decoder)
  73. {
  74. didReceiveWebFullScreenManagerMessage(connection, decoder);
  75. }
  76. bool WebFullScreenManager::supportsFullScreen(bool withKeyboard)
  77. {
  78. if (!m_page->corePage()->settings()->fullScreenEnabled())
  79. return false;
  80. return m_page->injectedBundleFullScreenClient().supportsFullScreen(m_page.get(), withKeyboard);
  81. }
  82. void WebFullScreenManager::enterFullScreenForElement(WebCore::Element* element)
  83. {
  84. ASSERT(element);
  85. m_element = element;
  86. m_initialFrame = screenRectOfContents(m_element.get());
  87. m_page->injectedBundleFullScreenClient().enterFullScreenForElement(m_page.get(), element);
  88. }
  89. void WebFullScreenManager::exitFullScreenForElement(WebCore::Element* element)
  90. {
  91. m_page->injectedBundleFullScreenClient().exitFullScreenForElement(m_page.get(), element);
  92. }
  93. void WebFullScreenManager::willEnterFullScreen()
  94. {
  95. ASSERT(m_element);
  96. m_element->document()->webkitWillEnterFullScreenForElement(m_element.get());
  97. m_page->hidePageBanners();
  98. m_element->document()->updateLayout();
  99. m_page->forceRepaintWithoutCallback();
  100. m_finalFrame = screenRectOfContents(m_element.get());
  101. m_page->injectedBundleFullScreenClient().beganEnterFullScreen(m_page.get(), m_initialFrame, m_finalFrame);
  102. }
  103. void WebFullScreenManager::didEnterFullScreen()
  104. {
  105. ASSERT(m_element);
  106. m_element->document()->webkitDidEnterFullScreenForElement(m_element.get());
  107. }
  108. void WebFullScreenManager::willExitFullScreen()
  109. {
  110. ASSERT(m_element);
  111. m_finalFrame = screenRectOfContents(m_element.get());
  112. m_element->document()->webkitWillExitFullScreenForElement(m_element.get());
  113. m_page->showPageBanners();
  114. m_page->injectedBundleFullScreenClient().beganExitFullScreen(m_page.get(), m_finalFrame, m_initialFrame);
  115. }
  116. void WebFullScreenManager::didExitFullScreen()
  117. {
  118. ASSERT(m_element);
  119. m_element->document()->webkitDidExitFullScreenForElement(m_element.get());
  120. }
  121. void WebFullScreenManager::setAnimatingFullScreen(bool animating)
  122. {
  123. ASSERT(m_element);
  124. m_element->document()->setAnimatingFullScreen(animating);
  125. }
  126. void WebFullScreenManager::requestExitFullScreen()
  127. {
  128. ASSERT(m_element);
  129. m_element->document()->webkitCancelFullScreen();
  130. }
  131. void WebFullScreenManager::close()
  132. {
  133. m_page->injectedBundleFullScreenClient().closeFullScreen(m_page.get());
  134. }
  135. void WebFullScreenManager::saveScrollPosition()
  136. {
  137. m_scrollPosition = m_page->corePage()->mainFrame()->view()->scrollPosition();
  138. }
  139. void WebFullScreenManager::restoreScrollPosition()
  140. {
  141. m_page->corePage()->mainFrame()->view()->setScrollPosition(m_scrollPosition);
  142. }
  143. } // namespace WebKit
  144. #endif // ENABLE(FULLSCREEN_API)