1/*
2 * Copyright (C) 2010 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
26#include "config.h"
27
28#if ENABLE(FULLSCREEN_API)
29
30#include "InjectedBundlePageFullScreenClient.h"
31
32#include "InjectedBundleNodeHandle.h"
33#include "WKAPICast.h"
34#include "WKBundleAPICast.h"
35#include "WKSharedAPICast.h"
36#include "WebCoreArgumentCoders.h"
37#include "WebFullScreenManagerProxyMessages.h"
38#include "WebPage.h"
39#include <WebCore/Element.h>
40
41using namespace WebCore;
42
43namespace WebKit {
44
45bool InjectedBundlePageFullScreenClient::supportsFullScreen(WebPage *page, bool withKeyboard)
46{
47    if (m_client.supportsFullScreen)
48        return m_client.supportsFullScreen(toAPI(page), withKeyboard);
49
50    bool supports = true;
51    page->sendSync(Messages::WebFullScreenManagerProxy::SupportsFullScreen(withKeyboard), supports);
52    return supports;
53}
54
55void InjectedBundlePageFullScreenClient::enterFullScreenForElement(WebPage *page, WebCore::Element *element)
56{
57    if (m_client.enterFullScreenForElement) {
58        RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(element);
59        m_client.enterFullScreenForElement(toAPI(page), toAPI(nodeHandle.get()));
60    } else
61        page->send(Messages::WebFullScreenManagerProxy::EnterFullScreen());
62}
63
64void InjectedBundlePageFullScreenClient::exitFullScreenForElement(WebPage *page, WebCore::Element *element)
65{
66    if (m_client.exitFullScreenForElement) {
67        RefPtr<InjectedBundleNodeHandle> nodeHandle = InjectedBundleNodeHandle::getOrCreate(element);
68        m_client.exitFullScreenForElement(toAPI(page), toAPI(nodeHandle.get()));
69    } else
70        page->send(Messages::WebFullScreenManagerProxy::ExitFullScreen());
71}
72
73
74void InjectedBundlePageFullScreenClient::beganEnterFullScreen(WebPage *page, IntRect& initialFrame, IntRect& finalFrame)
75{
76    if (m_client.beganEnterFullScreen)
77        m_client.beganEnterFullScreen(toAPI(page), toAPI(initialFrame), toAPI(finalFrame));
78    else
79        page->send(Messages::WebFullScreenManagerProxy::BeganEnterFullScreen(initialFrame, finalFrame));
80}
81
82
83void InjectedBundlePageFullScreenClient::beganExitFullScreen(WebPage *page, IntRect& initialFrame, IntRect& finalFrame)
84{
85    if (m_client.beganExitFullScreen)
86        m_client.beganExitFullScreen(toAPI(page), toAPI(initialFrame), toAPI(finalFrame));
87    else
88        page->send(Messages::WebFullScreenManagerProxy::BeganExitFullScreen(initialFrame, finalFrame));
89}
90
91void InjectedBundlePageFullScreenClient::closeFullScreen(WebPage *page)
92{
93    if (m_client.closeFullScreen)
94        m_client.closeFullScreen(toAPI(page));
95    else
96        page->send(Messages::WebFullScreenManagerProxy::Close());
97}
98
99} // namespace WebKit
100
101#endif // ENABLE(FULLSCREEN_API)
102