d3e39a57992c7ba78c96b1dacf4e0582eaa26de4
[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 #if ENABLE(FULLSCREEN_API)
151
152 // WebFullScreenManagerProxyClient
153 bool WebViewEfl::isFullScreen()
154 {
155     return m_hasRequestedFullScreen;
156 }
157
158 void WebViewEfl::enterFullScreen()
159 {
160     if (!m_ewkView || m_hasRequestedFullScreen)
161         return;
162
163     m_hasRequestedFullScreen = true;
164
165     WebFullScreenManagerProxy* manager = m_page->fullScreenManager();
166     manager->willEnterFullScreen();
167     m_ewkView->enterFullScreen();
168     manager->didEnterFullScreen();
169 }
170
171 void WebViewEfl::exitFullScreen()
172 {
173     if (!m_ewkView || !m_hasRequestedFullScreen)
174         return;
175
176     m_hasRequestedFullScreen = false;
177
178     WebFullScreenManagerProxy* manager = m_page->fullScreenManager();
179     manager->willExitFullScreen();
180     m_ewkView->exitFullScreen();
181     manager->didExitFullScreen();
182 }
183 #endif // ENABLE(FULLSCREEN_API)
184
185 void WebViewEfl::didFinishLoadingDataForCustomContentProvider(const String&, const IPC::DataReference&)
186 {
187     notImplemented();
188 }
189
190 #if ENABLE(INPUT_TYPE_COLOR)
191 void WebViewEfl::initializeColorPickerClient(const WKColorPickerClientBase* client)
192 {
193     m_colorPickerClient.initialize(client);
194 }
195
196 PassRefPtr<WebColorPicker> WebViewEfl::createColorPicker(WebPageProxy* page, const WebCore::Color& color, const WebCore::IntRect&)
197 {
198     return WebColorPickerEfl::create(this, page, color);
199 }
200 #endif
201
202 } // namespace WebKit