529e253f48ed9c716677752826c8cbcb4c4622cc
[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 "QtPolicyInterface.h"
25 #include "QtViewportInteractionEngine.h"
26 #include "QtWebPageProxy.h"
27 #include "QtWebPageUIClient.h"
28
29 #include "qquickwebview_p.h"
30 #include "qquickwebpage_p.h"
31
32 #include <QtCore/QObject>
33 #include <QtCore/QScopedPointer>
34 #include <wtf/OwnPtr.h>
35
36 class QtWebPageProxy;
37
38 QT_BEGIN_NAMESPACE
39 class QDeclarativeComponent;
40 class QFileDialog;
41 QT_END_NAMESPACE
42
43 class QQuickWebViewPrivate : public WebKit::QtPolicyInterface {
44
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     // QtPolicyInterface.
74     virtual QtPolicyInterface::PolicyAction navigationPolicyForURL(const QUrl&, Qt::MouseButton, Qt::KeyboardModifiers);
75
76     void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, QtWebPageUIClient::FileChooserType);
77     void runJavaScriptAlert(const QString&);
78     bool runJavaScriptConfirm(const QString&);
79     QString runJavaScriptPrompt(const QString&, const QString& defaultValue, bool& ok);
80
81     void setUseTraditionalDesktopBehaviour(bool enable);
82
83 private:
84     // This class is responsible for collecting and applying all properties
85     // on the viewport item, when transitioning from page A to page B is finished.
86     // See more at https://trac.webkit.org/wiki/QtWebKitLayoutInteraction
87     class PostTransitionState {
88     public:
89         PostTransitionState(QQuickWebViewPrivate* parent)
90             : p(parent)
91         { }
92
93         void apply()
94         {
95             p->interactionEngine->reset();
96             p->interactionEngine->applyConstraints(p->computeViewportConstraints());
97
98             if (contentsSize.isValid()) {
99                 p->pageView->setWidth(contentsSize.width());
100                 p->pageView->setHeight(contentsSize.height());
101             }
102
103             contentsSize = QSize();
104         }
105
106         QQuickWebViewPrivate* p;
107         QSize contentsSize;
108     };
109
110     bool isTransitioningToNewPage() const { return transitioningToNewPage; }
111
112     void setViewInAttachedProperties(QObject*);
113
114     QScopedPointer<QtWebPageUIClient> pageUIClient;
115
116     QScopedPointer<QQuickWebPage> pageView;
117     QScopedPointer<QtViewportInteractionEngine> interactionEngine;
118
119     QQuickWebView* q_ptr;
120     QScopedPointer<QtWebPageProxy> pageProxy;
121
122     QDeclarativeComponent* alertDialog;
123     QDeclarativeComponent* confirmDialog;
124     QDeclarativeComponent* promptDialog;
125
126     WebCore::ViewportArguments viewportArguments;
127     OwnPtr<PostTransitionState> postTransitionState;
128     bool transitioningToNewPage;
129
130     bool useTraditionalDesktopBehaviour;
131     QFileDialog* fileDialog;
132     WKOpenPanelResultListenerRef openPanelResultListener;
133 };
134
135 #endif // qquickwebview_p_p_h