[Qt] [WK2] Expose onNavigationRequested signal instead of expecting a slot be defined...
[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     void chooseFiles(WKOpenPanelResultListenerRef, const QStringList& selectedFileNames, QtWebPageUIClient::FileChooserType);
74     void runJavaScriptAlert(const QString&);
75     bool runJavaScriptConfirm(const QString&);
76     QString runJavaScriptPrompt(const QString&, const QString& defaultValue, bool& ok);
77
78     void setUseTraditionalDesktopBehaviour(bool enable);
79
80 private:
81     // This class is responsible for collecting and applying all properties
82     // on the viewport item, when transitioning from page A to page B is finished.
83     // See more at https://trac.webkit.org/wiki/QtWebKitLayoutInteraction
84     class PostTransitionState {
85     public:
86         PostTransitionState(QQuickWebViewPrivate* parent)
87             : p(parent)
88         { }
89
90         void apply()
91         {
92             p->interactionEngine->reset();
93             p->interactionEngine->applyConstraints(p->computeViewportConstraints());
94
95             if (contentsSize.isValid()) {
96                 p->pageView->setWidth(contentsSize.width());
97                 p->pageView->setHeight(contentsSize.height());
98             }
99
100             contentsSize = QSize();
101         }
102
103         QQuickWebViewPrivate* p;
104         QSize contentsSize;
105     };
106
107     bool isTransitioningToNewPage() const { return transitioningToNewPage; }
108
109     void setViewInAttachedProperties(QObject*);
110
111     QScopedPointer<QtWebPageLoadClient> pageLoadClient;
112     QScopedPointer<QtWebPagePolicyClient> pagePolicyClient;
113     QScopedPointer<QtWebPageUIClient> pageUIClient;
114
115     QScopedPointer<QQuickWebPage> pageView;
116     QScopedPointer<QtViewportInteractionEngine> interactionEngine;
117
118     QQuickWebView* q_ptr;
119     QScopedPointer<QtWebPageProxy> pageProxy;
120
121     QDeclarativeComponent* alertDialog;
122     QDeclarativeComponent* confirmDialog;
123     QDeclarativeComponent* promptDialog;
124
125     WebCore::ViewportArguments viewportArguments;
126     OwnPtr<PostTransitionState> postTransitionState;
127     bool transitioningToNewPage;
128
129     bool useTraditionalDesktopBehaviour;
130     QFileDialog* fileDialog;
131     WKOpenPanelResultListenerRef openPanelResultListener;
132 };
133
134 #endif // qquickwebview_p_p_h