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