[CoordinatedGraphics][EFL] Remove view_source functions.
[WebKit-https.git] / Source / WebKit2 / UIProcess / CoordinatedGraphics / WebView.cpp
1 /*
2  * Copyright (C) 2013 Intel Corporation. All rights reserved.
3  * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
15  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
18  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include "config.h"
28 #if USE(COORDINATED_GRAPHICS)
29
30 #include "WebView.h"
31
32 #include "CoordinatedDrawingAreaProxy.h"
33 #include "CoordinatedLayerTreeHostProxy.h"
34 #include "NotImplemented.h"
35 #include "ViewState.h"
36 #include "WebContextMenuProxy.h"
37 #include "WebPageProxy.h"
38 #include <WebCore/CoordinatedGraphicsScene.h>
39
40 #if ENABLE(FULLSCREEN_API)
41 #include "WebFullScreenManagerProxy.h"
42 #endif
43
44 using namespace WebCore;
45
46 namespace WebKit {
47
48 WebView::WebView(WebContext* context, WebPageGroup* pageGroup)
49     : m_focused(false)
50     , m_visible(false)
51     , m_opacity(1.0)
52 {
53     WebPageConfiguration webPageConfiguration;
54     webPageConfiguration.pageGroup = pageGroup;
55
56     // Need to call createWebPage after other data members, specifically m_visible, are initialized.
57     m_page = context->createWebPage(*this, std::move(webPageConfiguration));
58
59     m_page->pageGroup().preferences().setAcceleratedCompositingEnabled(true);
60     m_page->pageGroup().preferences().setForceCompositingMode(true);
61
62     char* debugVisualsEnvironment = getenv("WEBKIT_SHOW_COMPOSITING_DEBUG_VISUALS");
63     bool showDebugVisuals = debugVisualsEnvironment && !strcmp(debugVisualsEnvironment, "1");
64     m_page->pageGroup().preferences().setCompositingBordersVisible(showDebugVisuals);
65     m_page->pageGroup().preferences().setCompositingRepaintCountersVisible(showDebugVisuals);
66 }
67
68 WebView::~WebView()
69 {
70     if (m_page->isClosed())
71         return;
72
73     m_page->close();
74 }
75
76 void WebView::initialize()
77 {
78     m_page->initializeWebPage();
79     setActive(true);
80 }
81
82 void WebView::setContentScaleFactor(float scaleFactor)
83 {
84     m_page->scalePage(scaleFactor, roundedIntPoint(contentPosition()));
85     updateViewportSize();
86 }
87
88 void WebView::setActive(bool active)
89 {
90     CoordinatedGraphicsScene* scene = coordinatedGraphicsScene();
91     if (!scene || scene->isActive() == active)
92         return;
93
94     scene->setActive(active);
95     m_page->viewStateDidChange(ViewState::WindowIsActive);
96 }
97
98 void WebView::setSize(const WebCore::IntSize& size)
99 {
100     if (m_size == size)
101         return;
102
103     m_size = size;
104
105     updateViewportSize();
106 }
107
108 void WebView::setFocused(bool focused)
109 {
110     if (m_focused == focused)
111         return;
112
113     m_focused = focused;
114     m_page->viewStateDidChange(ViewState::IsFocused | ViewState::WindowIsActive);
115 }
116
117 void WebView::setVisible(bool visible)
118 {
119     if (m_visible == visible)
120         return;
121
122     m_visible = visible;
123     m_page->viewStateDidChange(ViewState::IsVisible);
124
125     if (CoordinatedDrawingAreaProxy* drawingArea = static_cast<CoordinatedDrawingAreaProxy*>(page()->drawingArea()))
126         drawingArea->visibilityDidChange();
127 }
128
129 void WebView::setUserViewportTranslation(double tx, double ty)
130 {
131     m_userViewportTransform = TransformationMatrix().translate(tx, ty);
132 }
133
134 IntPoint WebView::userViewportToContents(const IntPoint& point) const
135 {
136     return transformFromScene().mapPoint(point);
137 }
138
139 IntPoint WebView::userViewportToScene(const WebCore::IntPoint& point) const
140 {
141     return m_userViewportTransform.mapPoint(point);
142 }
143
144 IntPoint WebView::contentsToUserViewport(const IntPoint& point) const
145 {
146     return transformToScene().mapPoint(point);
147 }
148
149 void WebView::paintToCurrentGLContext()
150 {
151     CoordinatedGraphicsScene* scene = coordinatedGraphicsScene();
152     if (!scene)
153         return;
154
155     // FIXME: We need to clean up this code as it is split over CoordGfx and Page.
156     scene->setDrawsBackground(m_page->drawsBackground());
157     const FloatRect& viewport = m_userViewportTransform.mapRect(IntRect(IntPoint(), m_size));
158
159     scene->paintToCurrentGLContext(transformToScene().toTransformationMatrix(), m_opacity, viewport);
160 }
161
162 void WebView::setDrawsBackground(bool drawsBackground)
163 {
164     m_page->setDrawsBackground(drawsBackground);
165 }
166
167 bool WebView::drawsBackground() const
168 {
169     return m_page->drawsBackground();
170 }
171
172 void WebView::setDrawsTransparentBackground(bool transparentBackground)
173 {
174     m_page->setDrawsTransparentBackground(transparentBackground);
175 }
176
177 bool WebView::drawsTransparentBackground() const
178 {
179     return m_page->drawsTransparentBackground();
180 }
181
182 void WebView::suspendActiveDOMObjectsAndAnimations()
183 {
184     m_page->suspendActiveDOMObjectsAndAnimations();
185 }
186
187 void WebView::resumeActiveDOMObjectsAndAnimations()
188 {
189     m_page->resumeActiveDOMObjectsAndAnimations();
190 }
191
192 #if ENABLE(FULLSCREEN_API)
193 WebFullScreenManagerProxyClient& WebView::fullScreenManagerProxyClient()
194 {
195     return *this;
196 }
197
198 bool WebView::requestExitFullScreen()
199 {
200     if (!isFullScreen())
201         return false;
202
203     m_page->fullScreenManager()->requestExitFullScreen();
204     return true;
205 }
206 #endif
207
208 void WebView::initializeClient(const WKViewClientBase* client)
209 {
210     m_client.initialize(client);
211 }
212
213 void WebView::didChangeContentSize(const WebCore::IntSize& size)
214 {
215     if (m_contentsSize == size)
216         return;
217
218     m_contentsSize = size;
219     m_client.didChangeContentsSize(this, size);
220
221     updateViewportSize();
222 }
223
224 void WebView::didFindZoomableArea(const WebCore::IntPoint& target, const WebCore::IntRect& area)
225 {
226     m_client.didFindZoomableArea(this, target, area);
227 }
228
229 AffineTransform WebView::transformFromScene() const
230 {
231     return transformToScene().inverse();
232 }
233
234 AffineTransform WebView::transformToScene() const
235 {
236     FloatPoint position = -m_contentPosition;
237     float effectiveScale = contentScaleFactor() * m_page->deviceScaleFactor();
238     position.scale(effectiveScale, effectiveScale);
239
240     TransformationMatrix transform = m_userViewportTransform;
241     transform.translate(position.x(), position.y());
242     transform.scale(effectiveScale);
243
244     return transform.toAffineTransform();
245 }
246
247 CoordinatedGraphicsScene* WebView::coordinatedGraphicsScene()
248 {
249     if (CoordinatedDrawingAreaProxy* drawingArea = static_cast<CoordinatedDrawingAreaProxy*>(page()->drawingArea()))
250         return drawingArea->coordinatedLayerTreeHostProxy().coordinatedGraphicsScene();
251
252     return nullptr;
253 }
254
255 void WebView::updateViewportSize()
256 {
257     if (CoordinatedDrawingAreaProxy* drawingArea = static_cast<CoordinatedDrawingAreaProxy*>(page()->drawingArea())) {
258         // Web Process expects sizes in UI units, and not raw device units.
259         drawingArea->setSize(roundedIntSize(dipSize()), IntSize(), IntSize());
260         FloatRect visibleContentsRect(contentPosition(), visibleContentsSize());
261         visibleContentsRect.intersect(FloatRect(FloatPoint(), contentsSize()));
262         drawingArea->setVisibleContentsRect(visibleContentsRect, FloatPoint());
263     }
264 }
265
266 inline WebCore::FloatSize WebView::dipSize() const
267 {
268     FloatSize dipSize(size());
269     dipSize.scale(1 / m_page->deviceScaleFactor());
270
271     return dipSize;
272 }
273
274 WebCore::FloatSize WebView::visibleContentsSize() const
275 {
276     FloatSize visibleContentsSize(dipSize());
277     visibleContentsSize.scale(1 / contentScaleFactor());
278
279     return visibleContentsSize;
280 }
281
282 // Page Client
283
284 std::unique_ptr<DrawingAreaProxy> WebView::createDrawingAreaProxy()
285 {
286     return std::make_unique<CoordinatedDrawingAreaProxy>(page());
287 }
288
289 void WebView::setViewNeedsDisplay(const WebCore::IntRect& area)
290 {
291     m_client.viewNeedsDisplay(this, area);
292 }
293
294 void WebView::displayView()
295 {
296     notImplemented();
297 }
298
299 void WebView::scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize&)
300 {
301     setViewNeedsDisplay(scrollRect);
302 }
303
304 WebCore::IntSize WebView::viewSize()
305 {
306     return roundedIntSize(dipSize());
307 }
308
309 bool WebView::isActive() const
310 {
311     const CoordinatedGraphicsScene* scene = const_cast<WebView*>(this)->coordinatedGraphicsScene();
312     if (!scene)
313         return false;
314
315     return scene->isActive();
316 }
317
318 bool WebView::isViewWindowActive()
319 {
320     notImplemented();
321     return true;
322 }
323
324 bool WebView::isViewFocused()
325 {
326     return isFocused();
327 }
328
329 bool WebView::isViewVisible()
330 {
331     return isVisible();
332 }
333
334 bool WebView::isViewInWindow()
335 {
336     notImplemented();
337     return true;
338 }
339
340 void WebView::processDidExit()
341 {
342     m_client.webProcessCrashed(this, m_page->urlAtProcessExit());
343 }
344
345 void WebView::didRelaunchProcess()
346 {
347     m_client.webProcessDidRelaunch(this);
348 }
349
350 void WebView::pageClosed()
351 {
352     notImplemented();
353 }
354
355 void WebView::preferencesDidChange()
356 {
357     notImplemented();
358 }
359
360 void WebView::toolTipChanged(const String&, const String& newToolTip)
361 {
362     m_client.didChangeTooltip(this, newToolTip);
363 }
364
365 void WebView::didCommitLoadForMainFrame()
366 {
367     m_contentsSize = IntSize();
368 }
369
370 void WebView::setCursor(const WebCore::Cursor&)
371 {
372     notImplemented();
373 }
374
375 void WebView::setCursorHiddenUntilMouseMoves(bool)
376 {
377     notImplemented();
378 }
379
380 void WebView::registerEditCommand(PassRefPtr<WebEditCommandProxy> command, WebPageProxy::UndoOrRedo undoOrRedo)
381 {
382     m_undoController.registerEditCommand(command, undoOrRedo);
383 }
384
385 void WebView::clearAllEditCommands()
386 {
387     m_undoController.clearAllEditCommands();
388 }
389
390 bool WebView::canUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
391 {
392     return m_undoController.canUndoRedo(undoOrRedo);
393 }
394
395 void WebView::executeUndoRedo(WebPageProxy::UndoOrRedo undoOrRedo)
396 {
397     m_undoController.executeUndoRedo(undoOrRedo);
398 }
399
400 IntPoint WebView::screenToRootView(const IntPoint& point)
401 {
402     notImplemented();
403     return point;
404 }
405
406 IntRect WebView::rootViewToScreen(const IntRect&)
407 {
408     notImplemented();
409     return IntRect();
410 }
411
412 void WebView::doneWithKeyEvent(const NativeWebKeyboardEvent&, bool)
413 {
414     notImplemented();
415 }
416
417 #if ENABLE(TOUCH_EVENTS)
418 void WebView::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
419 {
420     m_client.doneWithTouchEvent(this, event, wasEventHandled);
421 }
422 #endif
423
424 PassRefPtr<WebPopupMenuProxy> WebView::createPopupMenuProxy(WebPageProxy*)
425 {
426     notImplemented();
427     return 0;
428 }
429
430 PassRefPtr<WebContextMenuProxy> WebView::createContextMenuProxy(WebPageProxy*)
431 {
432     notImplemented();
433     return 0;
434 }
435
436 #if ENABLE(INPUT_TYPE_COLOR)
437 PassRefPtr<WebColorPicker> WebView::createColorPicker(WebPageProxy*, const WebCore::Color&, const WebCore::IntRect&)
438 {
439     notImplemented();
440     return 0;
441 }
442 #endif
443
444 void WebView::setFindIndicator(PassRefPtr<FindIndicator>, bool, bool)
445 {
446     notImplemented();
447 }
448
449 void WebView::enterAcceleratedCompositingMode(const LayerTreeContext&)
450 {
451     setActive(true);
452 }
453
454 void WebView::exitAcceleratedCompositingMode()
455 {
456     setActive(false);
457 }
458
459 void WebView::updateAcceleratedCompositingMode(const LayerTreeContext&)
460 {
461     notImplemented();
462 }
463
464 void WebView::updateTextInputState()
465 {
466     notImplemented();
467 }
468
469 void WebView::handleDownloadRequest(DownloadProxy*)
470 {
471     notImplemented();
472 }
473
474 FloatRect WebView::convertToDeviceSpace(const FloatRect& userRect)
475 {
476     if (m_page->useFixedLayout()) {
477         FloatRect result = userRect;
478         result.scale(m_page->deviceScaleFactor());
479         return result;
480     }
481     // Legacy mode.
482     notImplemented();
483     return userRect;
484 }
485
486 FloatRect WebView::convertToUserSpace(const FloatRect& deviceRect)
487 {
488     if (m_page->useFixedLayout()) {
489         FloatRect result = deviceRect;
490         result.scale(1 / m_page->deviceScaleFactor());
491         return result;
492     }
493     // Legacy mode.
494     notImplemented();
495     return deviceRect;
496 }
497
498 void WebView::didChangeViewportProperties(const WebCore::ViewportAttributes& attr)
499 {
500     m_client.didChangeViewportAttributes(this, attr);
501 }
502
503 void WebView::pageDidRequestScroll(const IntPoint& position)
504 {
505     FloatPoint uiPosition(position);
506     setContentPosition(uiPosition);
507
508     m_client.didChangeContentsPosition(this, position);
509 }
510
511 void WebView::didRenderFrame(const WebCore::IntSize& contentsSize, const WebCore::IntRect& coveredRect)
512 {
513     m_client.didRenderFrame(this, contentsSize, coveredRect);
514 }
515
516 void WebView::pageTransitionViewportReady()
517 {
518     m_client.didCompletePageTransition(this);
519 }
520
521 void WebView::findZoomableAreaForPoint(const IntPoint& point, const IntSize& size)
522 {
523     m_page->findZoomableAreaForPoint(transformFromScene().mapPoint(point), transformFromScene().mapSize(size));
524 }
525
526 } // namespace WebKit
527
528 #endif // USE(COORDINATED_GRAPHICS)
529