[EFL][WK2] Extract the control of page background out of color_set
[WebKit-https.git] / Source / WebKit2 / UIProcess / efl / WebViewEfl.cpp
1 /*
2  * Copyright (C) 2013 Intel Corporation. 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 #include "WebViewEfl.h"
28
29 #include "DownloadManagerEfl.h"
30 #include "EwkView.h"
31 #include "InputMethodContextEfl.h"
32 #include "NativeWebMouseEvent.h"
33 #include "NotImplemented.h"
34 #include "WebContextMenuProxyEfl.h"
35 #include "WebPopupMenuListenerEfl.h"
36 #include "ewk_context_private.h"
37 #include <WebCore/CoordinatedGraphicsScene.h>
38 #include <WebCore/PlatformContextCairo.h>
39
40 #if ENABLE(FULLSCREEN_API)
41 #include "WebFullScreenManagerProxy.h"
42 #endif
43
44 #if ENABLE(TOUCH_EVENTS)
45 #include "EwkTouchEvent.h"
46 #endif
47
48 #if ENABLE(INPUT_TYPE_COLOR)
49 #include "WebColorPickerEfl.h"
50 #endif
51
52 using namespace EwkViewCallbacks;
53 using namespace WebCore;
54
55 namespace WebKit {
56
57 PassRefPtr<WebView> WebView::create(WebContext* context, WebPageGroup* pageGroup)
58 {
59     return adoptRef(new WebViewEfl(context, pageGroup));
60 }
61
62 WebViewEfl::WebViewEfl(WebContext* context, WebPageGroup* pageGroup)
63     : WebView(context, pageGroup)
64     , m_ewkView(0)
65     , m_hasRequestedFullScreen(false)
66 {
67 }
68
69 void WebViewEfl::setEwkView(EwkView* ewkView)
70 {
71     m_ewkView = ewkView;
72 }
73
74 void WebViewEfl::paintToCairoSurface(cairo_surface_t* surface)
75 {
76     CoordinatedGraphicsScene* scene = coordinatedGraphicsScene();
77     if (!scene)
78         return;
79
80     PlatformContextCairo context(cairo_create(surface));
81
82     const FloatPoint& position = contentPosition();
83     double effectiveScale = m_page->deviceScaleFactor() * contentScaleFactor();
84
85     cairo_matrix_t transform = { effectiveScale, 0, 0, effectiveScale, - position.x() * m_page->deviceScaleFactor(), - position.y() * m_page->deviceScaleFactor() };
86     cairo_set_matrix(context.cr(), &transform);
87     scene->paintToGraphicsContext(&context);
88 }
89
90 PassRefPtr<WebPopupMenuProxy> WebViewEfl::createPopupMenuProxy(WebPageProxy* page)
91 {
92     return WebPopupMenuListenerEfl::create(page);
93 }
94
95 #if ENABLE(CONTEXT_MENUS)
96 PassRefPtr<WebContextMenuProxy> WebViewEfl::createContextMenuProxy(WebPageProxy* page)
97 {
98     return WebContextMenuProxyEfl::create(m_ewkView, page);
99 }
100 #endif
101
102 void WebViewEfl::setCursor(const Cursor& cursor)
103 {
104     m_ewkView->setCursor(cursor);
105 }
106
107 void WebViewEfl::updateTextInputState()
108 {
109     if (InputMethodContextEfl* inputMethodContext = m_ewkView->inputMethodContext())
110         inputMethodContext->updateTextInputState();
111 }
112
113 void WebViewEfl::handleDownloadRequest(DownloadProxy* download)
114 {
115     EwkContext* context = m_ewkView->ewkContext();
116     context->downloadManager()->registerDownloadJob(toAPI(download), m_ewkView);
117 }
118
119 void WebViewEfl::setThemePath(const String& theme)
120 {
121     m_page->setThemePath(theme);
122 }
123
124 #if ENABLE(TOUCH_EVENTS)
125 void WebViewEfl::sendTouchEvent(EwkTouchEvent* touchEvent)
126 {
127     ASSERT(touchEvent);
128     m_page->handleTouchEvent(NativeWebTouchEvent(touchEvent, transformFromScene()));
129 }
130 #endif
131
132 void WebViewEfl::sendMouseEvent(const Evas_Event_Mouse_Down* event)
133 {
134     ASSERT(event);
135     m_page->handleMouseEvent(NativeWebMouseEvent(event, transformFromScene(), m_userViewportTransform.toAffineTransform()));
136 }
137
138 void WebViewEfl::sendMouseEvent(const Evas_Event_Mouse_Up* event)
139 {
140     ASSERT(event);
141     m_page->handleMouseEvent(NativeWebMouseEvent(event, transformFromScene(), m_userViewportTransform.toAffineTransform()));
142 }
143
144 void WebViewEfl::sendMouseEvent(const Evas_Event_Mouse_Move* event)
145 {
146     ASSERT(event);
147     m_page->handleMouseEvent(NativeWebMouseEvent(event, transformFromScene(), m_userViewportTransform.toAffineTransform()));
148 }
149
150 void WebViewEfl::setViewBackgroundColor(const WebCore::Color& color)
151 {
152     CoordinatedGraphicsScene* scene = coordinatedGraphicsScene();
153     if (!scene)
154         return;
155
156     scene->setViewBackgroundColor(color);
157 }
158
159 WebCore::Color WebViewEfl::viewBackgroundColor()
160 {
161     CoordinatedGraphicsScene* scene = coordinatedGraphicsScene();
162     if (!scene)
163         return Color();
164
165     return scene->viewBackgroundColor();
166 }
167
168 #if ENABLE(FULLSCREEN_API)
169
170 // WebFullScreenManagerProxyClient
171 bool WebViewEfl::isFullScreen()
172 {
173     return m_hasRequestedFullScreen;
174 }
175
176 void WebViewEfl::enterFullScreen()
177 {
178     if (!m_ewkView || m_hasRequestedFullScreen)
179         return;
180
181     m_hasRequestedFullScreen = true;
182
183     WebFullScreenManagerProxy* manager = m_page->fullScreenManager();
184     manager->willEnterFullScreen();
185     m_ewkView->enterFullScreen();
186     manager->didEnterFullScreen();
187 }
188
189 void WebViewEfl::exitFullScreen()
190 {
191     if (!m_ewkView || !m_hasRequestedFullScreen)
192         return;
193
194     m_hasRequestedFullScreen = false;
195
196     WebFullScreenManagerProxy* manager = m_page->fullScreenManager();
197     manager->willExitFullScreen();
198     m_ewkView->exitFullScreen();
199     manager->didExitFullScreen();
200 }
201 #endif // ENABLE(FULLSCREEN_API)
202
203 void WebViewEfl::didFinishLoadingDataForCustomContentProvider(const String&, const IPC::DataReference&)
204 {
205     notImplemented();
206 }
207
208 #if ENABLE(INPUT_TYPE_COLOR)
209 void WebViewEfl::initializeColorPickerClient(const WKColorPickerClientBase* client)
210 {
211     m_colorPickerClient.initialize(client);
212 }
213
214 PassRefPtr<WebColorPicker> WebViewEfl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect&)
215 {
216     return WebColorPickerEfl::create(this, page, color);
217 }
218 #endif
219
220 } // namespace WebKit