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