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