25546355d8b952c53d9b9db5122caec11d662126
[WebKit.git] / Source / WebKit2 / UIProcess / API / qt / qquickwebview_p_p.h
1 /*
2  * Copyright (C) 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 #ifndef qquickwebview_p_p_h
22 #define qquickwebview_p_p_h
23
24 #include "QtWebPageEventHandler.h"
25 #include "QtViewportInteractionEngine.h"
26 #include "QtWebPageLoadClient.h"
27 #include "QtWebPagePolicyClient.h"
28 #include "QtWebPageProxy.h"
29 #include "QtWebPageUIClient.h"
30
31 #include "qquickwebview_p.h"
32 #include "qquickwebpage_p.h"
33
34 #include <QtCore/QObject>
35 #include <QtCore/QScopedPointer>
36 #include <wtf/OwnPtr.h>
37
38 class QtWebPageProxy;
39
40 QT_BEGIN_NAMESPACE
41 class QDeclarativeComponent;
42 class QFileDialog;
43 QT_END_NAMESPACE
44
45 class QQuickWebViewPrivate {
46     Q_DECLARE_PUBLIC(QQuickWebView)
47     friend class QQuickWebViewExperimental;
48
49 public:
50     QQuickWebViewPrivate(QQuickWebView* viewport, WKContextRef contextRef = 0, WKPageGroupRef pageGroupRef = 0);
51     virtual ~QQuickWebViewPrivate() { }
52     void setPageProxy(QtWebPageProxy*);
53     void initializeTouch(QQuickWebView* viewport);
54     void initializeDesktop(QQuickWebView* viewport);
55     void enableMouseEvents();
56     void disableMouseEvents();
57
58     void loadDidCommit();
59
60     void didFinishFirstNonEmptyLayout();
61     void didChangeContentsSize(const QSize& newSize);
62     void didChangeViewportProperties(const WebCore::ViewportArguments& args);
63
64     void scrollPositionRequested(const QPoint& pos);
65     void updateViewportSize();
66     QtViewportInteractionEngine::Constraints computeViewportConstraints();
67
68     void updateVisibleContentRect();
69
70     void _q_suspend();
71     void _q_resume();
72     void _q_viewportTrajectoryVectorChanged(const QPointF&);
73     void _q_onOpenPanelFilesSelected();
74     void _q_onOpenPanelFinished(int result);
75     void _q_onVisibleChanged();
76
77     void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, QtWebPageUIClient::FileChooserType);
78     void runJavaScriptAlert(const QString&);
79     bool runJavaScriptConfirm(const QString&);
80     QString runJavaScriptPrompt(const QString&, const QString& defaultValue, bool& ok);
81
82     void setUseTraditionalDesktopBehaviour(bool enable);
83
84 private:
85     // This class is responsible for collecting and applying all properties
86     // on the viewport item, when transitioning from page A to page B is finished.
87     // See more at https://trac.webkit.org/wiki/QtWebKitLayoutInteraction
88     class PostTransitionState {
89     public:
90         PostTransitionState(QQuickWebViewPrivate* parent)
91             : p(parent)
92         { }
93
94         void apply()
95         {
96             p->interactionEngine->reset();
97             p->interactionEngine->applyConstraints(p->computeViewportConstraints());
98
99             if (contentsSize.isValid()) {
100                 p->pageView->setWidth(contentsSize.width());
101                 p->pageView->setHeight(contentsSize.height());
102             }
103
104             contentsSize = QSize();
105         }
106
107         QQuickWebViewPrivate* p;
108         QSize contentsSize;
109     };
110
111     void setViewInAttachedProperties(QObject*);
112
113     QScopedPointer<QtWebPageEventHandler> eventHandler;
114
115     QScopedPointer<QtWebPageLoadClient> pageLoadClient;
116     QScopedPointer<QtWebPagePolicyClient> pagePolicyClient;
117     QScopedPointer<QtWebPageUIClient> pageUIClient;
118
119     QScopedPointer<QQuickWebPage> pageView;
120     QScopedPointer<QtViewportInteractionEngine> interactionEngine;
121
122     QQuickWebView* q_ptr;
123     QScopedPointer<QtWebPageProxy> pageProxy;
124
125     QDeclarativeComponent* alertDialog;
126     QDeclarativeComponent* confirmDialog;
127     QDeclarativeComponent* promptDialog;
128
129     WebCore::ViewportArguments viewportArguments;
130     OwnPtr<PostTransitionState> postTransitionState;
131     bool isTransitioningToNewPage;
132     bool pageIsSuspended;
133
134     bool useTraditionalDesktopBehaviour;
135     QFileDialog* fileDialog;
136     WKOpenPanelResultListenerRef openPanelResultListener;
137 };
138
139 #endif // qquickwebview_p_p_h