1/****************************************************************************
2**
3** Copyright (C) 2015 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the QtWebView module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qwebview_p.h"
38#include "qwebviewplugin_p.h"
39#include "qwebviewloadrequest_p.h"
40#include "qwebviewfactory_p.h"
41
42
43QT_BEGIN_NAMESPACE
44
45QWebView::QWebView(QObject *p)
46 : QObject(p)
47 , d(QWebViewFactory::createWebView())
48 , m_progress(0)
49{
50 d->setParent(this);
51 qRegisterMetaType<QWebViewLoadRequestPrivate>();
52
53 connect(sender: d, signal: &QAbstractWebView::titleChanged, receiver: this, slot: &QWebView::onTitleChanged);
54 connect(sender: d, signal: &QAbstractWebView::urlChanged, receiver: this, slot: &QWebView::onUrlChanged);
55 connect(sender: d, signal: &QAbstractWebView::loadingChanged, receiver: this, slot: &QWebView::onLoadingChanged);
56 connect(sender: d, signal: &QAbstractWebView::loadProgressChanged, receiver: this, slot: &QWebView::onLoadProgressChanged);
57 connect(sender: d, signal: &QAbstractWebView::httpUserAgentChanged, receiver: this, slot: &QWebView::onHttpUserAgentChanged);
58 connect(sender: d, signal: &QAbstractWebView::requestFocus, receiver: this, slot: &QWebView::requestFocus);
59 connect(sender: d, signal: &QAbstractWebView::javaScriptResult,
60 receiver: this, slot: &QWebView::javaScriptResult);
61}
62
63QWebView::~QWebView()
64{
65}
66
67QString QWebView::httpUserAgent() const
68{
69 if (m_httpUserAgent.isEmpty()){
70 m_httpUserAgent = d->httpUserAgent();
71 }
72 return m_httpUserAgent;
73}
74
75void QWebView::setHttpUserAgent(const QString &userAgent)
76{
77 return d->setHttpUserAgent(userAgent);
78}
79
80QUrl QWebView::url() const
81{
82 return m_url;
83}
84
85void QWebView::setUrl(const QUrl &url)
86{
87 d->setUrl(url);
88}
89
90bool QWebView::canGoBack() const
91{
92 return d->canGoBack();
93}
94
95void QWebView::goBack()
96{
97 d->goBack();
98}
99
100bool QWebView::canGoForward() const
101{
102 return d->canGoForward();
103}
104
105void QWebView::goForward()
106{
107 d->goForward();
108}
109
110void QWebView::reload()
111{
112 d->reload();
113}
114
115void QWebView::stop()
116{
117 d->stop();
118}
119
120QString QWebView::title() const
121{
122 return m_title;
123}
124
125int QWebView::loadProgress() const
126{
127 return m_progress;
128}
129
130bool QWebView::isLoading() const
131{
132 return d->isLoading();
133}
134
135void QWebView::setParentView(QObject *view)
136{
137 d->setParentView(view);
138}
139
140QObject *QWebView::parentView() const
141{
142 return d->parentView();
143}
144
145void QWebView::setGeometry(const QRect &geometry)
146{
147 d->setGeometry(geometry);
148}
149
150void QWebView::setVisibility(QWindow::Visibility visibility)
151{
152 d->setVisibility(visibility);
153}
154
155void QWebView::setVisible(bool visible)
156{
157 d->setVisible(visible);
158}
159
160void QWebView::setFocus(bool focus)
161{
162 d->setFocus(focus);
163}
164
165void QWebView::loadHtml(const QString &html, const QUrl &baseUrl)
166{
167 d->loadHtml(html, baseUrl);
168}
169
170void QWebView::runJavaScriptPrivate(const QString &script,
171 int callbackId)
172{
173 d->runJavaScriptPrivate(script, callbackId);
174}
175
176void QWebView::onTitleChanged(const QString &title)
177{
178 if (m_title == title)
179 return;
180
181 m_title = title;
182 Q_EMIT titleChanged();
183}
184
185void QWebView::onUrlChanged(const QUrl &url)
186{
187 if (m_url == url)
188 return;
189
190 m_url = url;
191 Q_EMIT urlChanged();
192}
193
194void QWebView::onLoadProgressChanged(int progress)
195{
196 if (m_progress == progress)
197 return;
198
199 m_progress = progress;
200 Q_EMIT loadProgressChanged();
201}
202
203void QWebView::onLoadingChanged(const QWebViewLoadRequestPrivate &loadRequest)
204{
205 if (loadRequest.m_status == QWebView::LoadFailedStatus)
206 m_progress = 0;
207
208 onUrlChanged(url: loadRequest.m_url);
209 Q_EMIT loadingChanged(loadRequest);
210}
211
212void QWebView::onHttpUserAgentChanged(const QString &userAgent)
213{
214 if (m_httpUserAgent == userAgent)
215 return;
216 m_httpUserAgent = userAgent;
217 Q_EMIT httpUserAgentChanged();
218}
219
220void QWebView::init()
221{
222 d->init();
223}
224
225QT_END_NAMESPACE
226

source code of qtwebview/src/webview/qwebview.cpp