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