initial import
[vuplus_webkit] / Source / WebKit2 / UIProcess / qt / qtouchwebpageproxy.cpp
1 /*
2  * Copyright (C) 2010, 2011 Nokia Corporation and/or its subsidiary(-ies)
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public License
15  * along with this program; see the file COPYING.LIB.  If not, write to
16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  *
19  */
20
21 #include "config.h"
22 #include "qtouchwebpageproxy.h"
23
24 #include <IntRect.h>
25 #include <NativeWebTouchEvent.h>
26 #include <WebEventFactoryQt.h>
27
28 using namespace WebCore;
29
30 QTouchWebPageProxy::QTouchWebPageProxy(TouchViewInterface* viewInterface, ViewportInteractionEngine* viewportInteractionEngine)
31     : QtWebPageProxy(viewInterface, 0)
32     , m_panGestureRecognizer(viewportInteractionEngine)
33     , m_pinchGestureRecognizer(viewportInteractionEngine)
34 {
35     init();
36 }
37
38 PassOwnPtr<DrawingAreaProxy> QTouchWebPageProxy::createDrawingAreaProxy()
39 {
40     return TiledDrawingAreaProxy::create(touchViewInterface(), m_webPageProxy.get());
41 }
42
43 void QTouchWebPageProxy::processDidCrash()
44 {
45     QtWebPageProxy::processDidCrash();
46     m_panGestureRecognizer.reset();
47     m_pinchGestureRecognizer.reset();
48 }
49
50 void QTouchWebPageProxy::paintContent(QPainter* painter, const QRect& area)
51 {
52     m_webPageProxy->drawingArea()->paint(IntRect(area), painter);
53 }
54
55 #if ENABLE(TOUCH_EVENTS)
56 void QTouchWebPageProxy::doneWithTouchEvent(const NativeWebTouchEvent& event, bool wasEventHandled)
57 {
58     if (wasEventHandled) {
59         m_panGestureRecognizer.reset();
60         m_pinchGestureRecognizer.reset();
61     } else {
62         m_panGestureRecognizer.recognize(event.nativeEvent());
63         m_pinchGestureRecognizer.recognize(event.nativeEvent());
64     }
65 }
66 #endif
67
68 bool QTouchWebPageProxy::handleEvent(QEvent* ev)
69 {
70     switch (ev->type()) {
71     case QEvent::TouchBegin:
72     case QEvent::TouchEnd:
73     case QEvent::TouchUpdate:
74         touchEvent(static_cast<QTouchEvent*>(ev));
75         return true;
76     }
77     return QtWebPageProxy::handleEvent(ev);
78 }
79
80 void QTouchWebPageProxy::setVisibleContentRectAndScale(const QRectF& visibleContentRect, float scale)
81 {
82     QRect alignedVisibleContentRect = visibleContentRect.toAlignedRect();
83     drawingArea()->setVisibleContentRectAndScale(alignedVisibleContentRect, scale);
84
85     // FIXME: Once we support suspend and resume, this should be delayed until the page is active if the page is suspended.
86     m_webPageProxy->setFixedVisibleContentRect(alignedVisibleContentRect);
87 }
88
89 void QTouchWebPageProxy::setVisibleContentRectTrajectoryVector(const QPointF& trajectoryVector)
90 {
91     drawingArea()->setVisibleContentRectTrajectoryVector(trajectoryVector);
92 }
93
94 void QTouchWebPageProxy::setResizesToContentsUsingLayoutSize(const QSize& targetLayoutSize)
95 {
96     m_webPageProxy->setResizesToContentsUsingLayoutSize(targetLayoutSize);
97 }
98
99 void QTouchWebPageProxy::touchEvent(QTouchEvent* event)
100 {
101 #if ENABLE(TOUCH_EVENTS)
102     m_webPageProxy->handleTouchEvent(NativeWebTouchEvent(event));
103     event->accept();
104 #else
105     ASSERT_NOT_REACHED();
106     ev->ignore();
107 #endif
108 }
109
110 void QTouchWebPageProxy::findZoomableAreaForPoint(const QPoint& point)
111 {
112     m_webPageProxy->findZoomableAreaForPoint(point);
113 }
114
115 void QTouchWebPageProxy::renderNextFrame()
116 {
117     drawingArea()->renderNextFrame();
118 }