diff options
-rw-r--r-- | examples/widgets/widgetwindow.cpp | 13 | ||||
-rw-r--r-- | examples/widgets/widgetwindow.h | 3 | ||||
-rw-r--r-- | lib/lib.pro | 1 | ||||
-rw-r--r-- | lib/qquickwebcontentsview.cpp | 2 | ||||
-rw-r--r-- | lib/qwebcontentsview.cpp | 25 | ||||
-rw-r--r-- | lib/qwebcontentsview.h | 3 | ||||
-rw-r--r-- | lib/qwebcontentsview_p.h | 83 | ||||
-rw-r--r-- | lib/web_contents_delegate_qt.cpp | 8 | ||||
-rw-r--r-- | lib/web_contents_delegate_qt.h | 5 |
9 files changed, 130 insertions, 13 deletions
diff --git a/examples/widgets/widgetwindow.cpp b/examples/widgets/widgetwindow.cpp index 2cf2cfddd..dad64cb7f 100644 --- a/examples/widgets/widgetwindow.cpp +++ b/examples/widgets/widgetwindow.cpp @@ -70,7 +70,7 @@ WidgetWindow::WidgetWindow() forwardButton->setIcon(QIcon::fromTheme("go-next")); addressBar->addWidget(forwardButton); - QToolButton* reloadButton = new QToolButton; + reloadButton = new QToolButton; reloadButton->setIcon(QIcon::fromTheme("view-refresh")); addressBar->addWidget(reloadButton); @@ -86,6 +86,8 @@ WidgetWindow::WidgetWindow() connect(backButton, SIGNAL(clicked()), m_webView.data(), SLOT(back())); connect(forwardButton, SIGNAL(clicked()), m_webView.data(), SLOT(forward())); connect(reloadButton, SIGNAL(clicked()), m_webView.data(), SLOT(reload())); + connect(m_webView.data(), SIGNAL(loadStarted()), SLOT(loadStarted())); + connect(m_webView.data(), SIGNAL(loadFinished(bool)), SLOT(loadFinished(bool))); connect(m_webView.data(), SIGNAL(titleChanged(const QString&)), SLOT(setWindowTitle(const QString&))); connect(m_webView.data(), SIGNAL(urlChanged(const QUrl&)), SLOT(setAddressBarUrl(const QUrl&))); @@ -106,3 +108,12 @@ void WidgetWindow::setAddressBarUrl(const QUrl& url) addressLineEdit->setText(url.toString()); } +void WidgetWindow::loadStarted() +{ + reloadButton->setIcon(QIcon::fromTheme("process-stop")); +} + +void WidgetWindow::loadFinished(bool success) +{ + reloadButton->setIcon(QIcon::fromTheme("view-refresh")); +} diff --git a/examples/widgets/widgetwindow.h b/examples/widgets/widgetwindow.h index 334f815ea..5273d4255 100644 --- a/examples/widgets/widgetwindow.h +++ b/examples/widgets/widgetwindow.h @@ -56,10 +56,13 @@ public: private Q_SLOTS: void loadAddressFromAddressBar(); void setAddressBarUrl(const QUrl& url); + void loadStarted(); + void loadFinished(bool); private: QScopedPointer<QWebContentsView> m_webView; QLineEdit* addressLineEdit; + QToolButton* reloadButton; }; #endif // WIDGETWINDOW_H diff --git a/lib/lib.pro b/lib/lib.pro index 92b5e61b6..54a35b226 100644 --- a/lib/lib.pro +++ b/lib/lib.pro @@ -33,6 +33,7 @@ HEADERS = \ content_browser_client_qt.h \ qquickwebcontentsview.h \ qwebcontentsview.h \ + qwebcontentsview_p.h \ resource_context_qt.h \ url_request_context_getter_qt.h \ web_contents_delegate_qt.h \ diff --git a/lib/qquickwebcontentsview.cpp b/lib/qquickwebcontentsview.cpp index 0b56aa543..0d82020fa 100644 --- a/lib/qquickwebcontentsview.cpp +++ b/lib/qquickwebcontentsview.cpp @@ -79,7 +79,7 @@ QQuickWebContentsView::QQuickWebContentsView() WebContentsDelegateQt* delegate = d->webContentsDelegate.get(); connect(delegate, SIGNAL(titleChanged(QString)), this, SIGNAL(titleChanged(QString))); - connect(delegate, SIGNAL(urlChanged()), this, SIGNAL(urlChanged())); + connect(delegate, SIGNAL(urlChanged(QUrl)), this, SIGNAL(urlChanged())); connect(delegate, SIGNAL(loadingStateChanged()), this, SIGNAL(loadingStateChanged())); WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(d->webContentsDelegate->web_contents()->GetView()); diff --git a/lib/qwebcontentsview.cpp b/lib/qwebcontentsview.cpp index 061d518cd..323bb3b60 100644 --- a/lib/qwebcontentsview.cpp +++ b/lib/qwebcontentsview.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qwebcontentsview.h" +#include "qwebcontentsview_p.h" // Needed to get access to content::GetContentClient() #define CONTENT_IMPLEMENTATION @@ -55,16 +56,10 @@ #include <QVBoxLayout> #include <QUrl> -class QWebContentsViewPrivate -{ -public: - scoped_refptr<WebEngineContext> context; - scoped_ptr<WebContentsDelegateQt> webContentsDelegate; -}; QWebContentsView::QWebContentsView() { - d.reset(new QWebContentsViewPrivate); + d.reset(new QWebContentsViewPrivate(this)); // This has to be the first thing we do. d->context = WebEngineContext::current(); @@ -74,6 +69,11 @@ QWebContentsView::QWebContentsView() layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); + WebContentsDelegateQt* delegate = d->webContentsDelegate.get(); + connect(delegate, SIGNAL(titleChanged(const QString&)), this, SIGNAL(titleChanged(const QString&))); + connect(delegate, SIGNAL(urlChanged(const QUrl&)), this, SIGNAL(urlChanged(const QUrl&))); + connect(delegate, SIGNAL(loadingStateChanged()), d.data(), SLOT(loadingStateChanged())); + WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(d->webContentsDelegate->web_contents()->GetView()); layout->addLayout(content_view->windowContainer()->widget()); } @@ -112,3 +112,14 @@ void QWebContentsView::reload() d->webContentsDelegate->web_contents()->GetController().Reload(false); d->webContentsDelegate->web_contents()->GetView()->Focus(); } + +void QWebContentsView::stop() +{ + content::NavigationController& controller = d->webContentsDelegate->web_contents()->GetController(); + + int index = controller.GetPendingEntryIndex(); + if (index != -1) + controller.RemoveEntryAtIndex(index); + + d->webContentsDelegate->web_contents()->GetView()->Focus(); +} diff --git a/lib/qwebcontentsview.h b/lib/qwebcontentsview.h index e5f082310..6eef056c7 100644 --- a/lib/qwebcontentsview.h +++ b/lib/qwebcontentsview.h @@ -59,8 +59,11 @@ public Q_SLOTS: void back(); void forward(); void reload(); + void stop(); Q_SIGNALS: + void loadFinished(bool ok); + void loadStarted(); void titleChanged(const QString& title); void urlChanged(const QUrl& url); diff --git a/lib/qwebcontentsview_p.h b/lib/qwebcontentsview_p.h new file mode 100644 index 000000000..8af2f1bce --- /dev/null +++ b/lib/qwebcontentsview_p.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBCONTESTSVIEWPRIVATE_H +#define QWEBCONTESTSVIEWPRIVATE_H + +#include "qwebcontentsview.h" +#include "web_contents_delegate_qt.h" +#include "web_contents_view_qt.h" +#include "web_engine_context.h" + + +#include <QScopedPointer> +#include <QObject> + +class QWebContentsViewPrivate : public QObject +{ + Q_OBJECT +public: + QWebContentsViewPrivate(QWebContentsView* webContentsView) + : q(webContentsView) + , m_isLoading(false) + { } + +public Q_SLOTS: + void loadingStateChanged() + { + bool isLoading = webContentsDelegate->web_contents()->IsLoading(); + if (m_isLoading != isLoading) { + m_isLoading = isLoading; + if (m_isLoading) + Q_EMIT q->loadStarted(); + else + Q_EMIT q->loadFinished(true); + } + } + +public: + bool m_isLoading; + QWebContentsView* q; + scoped_refptr<WebEngineContext> context; + scoped_ptr<WebContentsDelegateQt> webContentsDelegate; +}; + +#endif
\ No newline at end of file diff --git a/lib/web_contents_delegate_qt.cpp b/lib/web_contents_delegate_qt.cpp index d4aad13a0..cc0f53679 100644 --- a/lib/web_contents_delegate_qt.cpp +++ b/lib/web_contents_delegate_qt.cpp @@ -53,6 +53,7 @@ #include <QGuiApplication> #include <QStyleHints> +#include <QUrl> static const int kTestWindowWidth = 800; static const int kTestWindowHeight = 600; @@ -95,8 +96,11 @@ void WebContentsDelegateQt::Observe(int type, const content::NotificationSource& void WebContentsDelegateQt::NavigationStateChanged(const content::WebContents* source, unsigned changed_flags) { - if (changed_flags & content::INVALIDATE_TYPE_URL) - Q_EMIT urlChanged(); + if (changed_flags & content::INVALIDATE_TYPE_URL) { + GURL gurl = web_contents()->GetActiveURL(); + QUrl url(QString::fromStdString(gurl.spec())); + Q_EMIT urlChanged(url); + } } void WebContentsDelegateQt::LoadingStateChanged(content::WebContents* source) diff --git a/lib/web_contents_delegate_qt.h b/lib/web_contents_delegate_qt.h index 80776a2d4..349519c65 100644 --- a/lib/web_contents_delegate_qt.h +++ b/lib/web_contents_delegate_qt.h @@ -48,6 +48,7 @@ #include "content/public/browser/web_contents.h" #include <QObject> +#include <QUrl> namespace content { @@ -69,8 +70,8 @@ public: virtual void LoadingStateChanged(content::WebContents* source); Q_SIGNALS: - void titleChanged(QString title); - void urlChanged(); + void titleChanged(const QString& title); + void urlChanged(const QUrl& url); void loadingStateChanged(); private: |