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
28#if ENABLE(FULLSCREEN_API)
29
30#include "Connection.h"
31#include "MessageID.h"
32#include "WebCoreArgumentCoders.h"
33#include "WebFullScreenManagerProxyMessages.h"
34#include "WebPage.h"
35#include "WebProcess.h"
36#include <WebCore/Color.h>
37#include <WebCore/Page.h>
38#include <WebCore/Settings.h>
39
40using namespace WebCore;
41
42namespace WebKit {
43
44WebFullScreenManager::WebFullScreenManager(WebPage* page)
45    : m_page(page)
46{
47}
48
49WebFullScreenManager::~WebFullScreenManager()
50{
51
52}
53
54WebCore::Element* WebFullScreenManager::element()
55{
56    return m_element.get();
57}
58
59void WebFullScreenManager::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
60{
61    didReceiveWebFullScreenManagerMessage(connection, messageID, arguments);
62}
63
64bool WebFullScreenManager::supportsFullScreen(bool withKeyboard)
65{
66    if (!m_page->corePage()->settings()->fullScreenEnabled())
67        return false;
68
69    return m_page->injectedBundleFullScreenClient().supportsFullScreen(m_page.get(), withKeyboard);
70
71}
72
73void WebFullScreenManager::enterFullScreenForElement(WebCore::Element* element)
74{
75    ASSERT(element);
76    m_element = element;
77    m_initialFrame = m_element->screenRect();
78    m_page->injectedBundleFullScreenClient().enterFullScreenForElement(m_page.get(), element);
79}
80
81void WebFullScreenManager::exitFullScreenForElement(WebCore::Element* element)
82{
83    ASSERT(element);
84    ASSERT(m_element == element);
85    m_page->injectedBundleFullScreenClient().exitFullScreenForElement(m_page.get(), element);
86}
87
88void WebFullScreenManager::beganEnterFullScreenAnimation()
89{
90    m_page->send(Messages::WebFullScreenManagerProxy::BeganEnterFullScreenAnimation());
91}
92
93void WebFullScreenManager::finishedEnterFullScreenAnimation(bool completed)
94{
95    m_page->send(Messages::WebFullScreenManagerProxy::FinishedEnterFullScreenAnimation(completed));
96}
97
98void WebFullScreenManager::beganExitFullScreenAnimation()
99{
100    m_page->send(Messages::WebFullScreenManagerProxy::BeganExitFullScreenAnimation());
101}
102
103void WebFullScreenManager::finishedExitFullScreenAnimation(bool completed)
104{
105    m_page->send(Messages::WebFullScreenManagerProxy::FinishedExitFullScreenAnimation(completed));
106}
107
108IntRect WebFullScreenManager::getFullScreenRect()
109{
110    IntRect rect;
111    m_page->sendSync(Messages::WebFullScreenManagerProxy::GetFullScreenRect(), Messages::WebFullScreenManagerProxy::GetFullScreenRect::Reply(rect));
112    return rect;
113}
114
115void WebFullScreenManager::willEnterFullScreen()
116{
117    ASSERT(m_element);
118    m_element->document()->webkitWillEnterFullScreenForElement(m_element.get());
119    m_element->document()->setFullScreenRendererBackgroundColor(Color::transparent);
120}
121
122void WebFullScreenManager::didEnterFullScreen()
123{
124    ASSERT(m_element);
125    m_element->document()->webkitDidEnterFullScreenForElement(m_element.get());
126    m_element->document()->setFullScreenRendererBackgroundColor(Color::black);
127}
128
129void WebFullScreenManager::willExitFullScreen()
130{
131    ASSERT(m_element);
132    m_element->document()->webkitWillExitFullScreenForElement(m_element.get());
133    m_element->document()->setFullScreenRendererBackgroundColor(Color::transparent);
134}
135
136void WebFullScreenManager::didExitFullScreen()
137{
138    ASSERT(m_element);
139    m_element->document()->webkitDidExitFullScreenForElement(m_element.get());
140    m_element->document()->setFullScreenRendererBackgroundColor(Color::black);
141}
142
143
144} // namespace WebKit
145
146#endif // ENABLE(FULLSCREEN_API)
147