diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-06-19 11:37:01 +0200 |
---|---|---|
committer | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2013-06-19 11:41:22 +0200 |
commit | 0fafd21965f813635a6f4fa0c0b37ee375a233b6 (patch) | |
tree | c592dc2bd2c075c7e7c32689e2e485cd6ea75576 | |
parent | 7ce5fb981bc11d26c060d88ceb018e5adaf0e7be (diff) |
Hide the p-impl pointer the same way as QObject to be able to use Q_D and Q_Q.
-rw-r--r-- | lib/qquickwebcontentsview.cpp | 26 | ||||
-rw-r--r-- | lib/qquickwebcontentsview.h | 4 | ||||
-rw-r--r-- | lib/qwebcontentsview.cpp | 37 | ||||
-rw-r--r-- | lib/qwebcontentsview.h | 4 | ||||
-rw-r--r-- | lib/qwebcontentsview_p.h | 22 |
5 files changed, 66 insertions, 27 deletions
diff --git a/lib/qquickwebcontentsview.cpp b/lib/qquickwebcontentsview.cpp index e28525d23..900f83028 100644 --- a/lib/qquickwebcontentsview.cpp +++ b/lib/qquickwebcontentsview.cpp @@ -61,17 +61,20 @@ void QQuickWebContentsView::registerType() struct QQuickWebContentsViewPrivate { + QQuickWebContentsView *q_ptr; + Q_DECLARE_PUBLIC(QQuickWebContentsView) + QQuickWebContentsViewPrivate(); + scoped_refptr<WebEngineContext> context; scoped_ptr<WebContentsDelegateQt> webContentsDelegate; }; QQuickWebContentsView::QQuickWebContentsView() + : d_ptr(new QQuickWebContentsViewPrivate) { - d.reset(new QQuickWebContentsViewPrivate); - - // This has to be the first thing we do. - d->context = WebEngineContext::current(); + d_ptr->q_ptr = this; + Q_D(QQuickWebContentsView); content::BrowserContext* browser_context = static_cast<ContentBrowserClientQt*>(content::GetContentClient()->browser())->browser_context(); d->webContentsDelegate.reset(new WebContentsDelegateQt(this, browser_context, NULL, MSG_ROUTING_NONE, gfx::Size())); @@ -92,12 +95,14 @@ QQuickWebContentsView::~QQuickWebContentsView() QUrl QQuickWebContentsView::url() const { + Q_D(const QQuickWebContentsView); GURL gurl = d->webContentsDelegate->web_contents()->GetActiveURL(); return QUrl(QString::fromStdString(gurl.spec())); } void QQuickWebContentsView::setUrl(const QUrl& url) { + Q_D(QQuickWebContentsView); GURL gurl(url.toString().toStdString()); content::NavigationController::LoadURLParams params(gurl); @@ -108,24 +113,28 @@ void QQuickWebContentsView::setUrl(const QUrl& url) void QQuickWebContentsView::goBack() { + Q_D(QQuickWebContentsView); d->webContentsDelegate->web_contents()->GetController().GoToOffset(-1); d->webContentsDelegate->web_contents()->GetView()->Focus(); } void QQuickWebContentsView::goForward() { + Q_D(QQuickWebContentsView); d->webContentsDelegate->web_contents()->GetController().GoToOffset(1); d->webContentsDelegate->web_contents()->GetView()->Focus(); } void QQuickWebContentsView::reload() { + Q_D(QQuickWebContentsView); d->webContentsDelegate->web_contents()->GetController().Reload(false); d->webContentsDelegate->web_contents()->GetView()->Focus(); } void QQuickWebContentsView::stop() { + Q_D(QQuickWebContentsView); content::NavigationController& controller = d->webContentsDelegate->web_contents()->GetController(); int index = controller.GetPendingEntryIndex(); @@ -137,11 +146,13 @@ void QQuickWebContentsView::stop() bool QQuickWebContentsView::isLoading() const { + Q_D(const QQuickWebContentsView); return d->webContentsDelegate->web_contents()->IsLoading(); } QString QQuickWebContentsView::title() const { + Q_D(const QQuickWebContentsView); content::NavigationEntry* entry = d->webContentsDelegate->web_contents()->GetController().GetVisibleEntry(); if (!entry) return QString(); @@ -150,11 +161,18 @@ QString QQuickWebContentsView::title() const bool QQuickWebContentsView::canGoBack() const { + Q_D(const QQuickWebContentsView); return d->webContentsDelegate->web_contents()->GetController().CanGoBack(); } bool QQuickWebContentsView::canGoForward() const { + Q_D(const QQuickWebContentsView); return d->webContentsDelegate->web_contents()->GetController().CanGoForward(); } +QQuickWebContentsViewPrivate::QQuickWebContentsViewPrivate() + // This has to be the first thing we do. + : context(WebEngineContext::current()) +{ +} diff --git a/lib/qquickwebcontentsview.h b/lib/qquickwebcontentsview.h index c94d5e488..81459c490 100644 --- a/lib/qquickwebcontentsview.h +++ b/lib/qquickwebcontentsview.h @@ -80,7 +80,9 @@ Q_SIGNALS: void loadingStateChanged(); private: - QScopedPointer<QQuickWebContentsViewPrivate> d; + Q_DECLARE_PRIVATE(QQuickWebContentsView) + // Hides QObject::d_ptr allowing us to use the convenience macros. + QScopedPointer<QQuickWebContentsViewPrivate> d_ptr; }; QML_DECLARE_TYPE(QQuickWebContentsView) diff --git a/lib/qwebcontentsview.cpp b/lib/qwebcontentsview.cpp index cfbaccc4c..902f65fb6 100644 --- a/lib/qwebcontentsview.cpp +++ b/lib/qwebcontentsview.cpp @@ -55,13 +55,14 @@ QWebContentsView::QWebContentsView() + : d_ptr(new QWebContentsViewPrivate) { - d.reset(new QWebContentsViewPrivate(this)); - // This has to be the first thing we do. - d->context = WebEngineContext::current(); + d_ptr->q_ptr = this; + Q_D(QWebContentsView); content::BrowserContext* browser_context = static_cast<ContentBrowserClientQt*>(content::GetContentClient()->browser())->browser_context(); d->webContentsDelegate.reset(new WebContentsDelegateQt(this, browser_context, NULL, MSG_ROUTING_NONE, gfx::Size())); + QVBoxLayout *layout = new QVBoxLayout; layout->setContentsMargins(0, 0, 0, 0); setLayout(layout); @@ -69,7 +70,7 @@ QWebContentsView::QWebContentsView() 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())); + connect(delegate, SIGNAL(loadingStateChanged()), d, SLOT(loadingStateChanged())); WebContentsViewQt* content_view = static_cast<WebContentsViewQt*>(d->webContentsDelegate->web_contents()->GetView()); layout->addLayout(content_view->windowContainer()->widget()); @@ -81,6 +82,7 @@ QWebContentsView::~QWebContentsView() void QWebContentsView::load(const QUrl& url) { + Q_D(QWebContentsView); QString urlString = url.toString(); GURL gurl(urlString.toStdString()); if (!gurl.has_scheme()) @@ -94,34 +96,40 @@ void QWebContentsView::load(const QUrl& url) bool QWebContentsView::canGoBack() const { + Q_D(const QWebContentsView); return d->webContentsDelegate->web_contents()->GetController().CanGoBack(); } bool QWebContentsView::canGoForward() const { + Q_D(const QWebContentsView); return d->webContentsDelegate->web_contents()->GetController().CanGoForward(); } void QWebContentsView::back() { + Q_D(QWebContentsView); d->webContentsDelegate->web_contents()->GetController().GoToOffset(-1); d->webContentsDelegate->web_contents()->GetView()->Focus(); } void QWebContentsView::forward() { + Q_D(QWebContentsView); d->webContentsDelegate->web_contents()->GetController().GoToOffset(1); d->webContentsDelegate->web_contents()->GetView()->Focus(); } void QWebContentsView::reload() { + Q_D(QWebContentsView); d->webContentsDelegate->web_contents()->GetController().Reload(false); d->webContentsDelegate->web_contents()->GetView()->Focus(); } void QWebContentsView::stop() { + Q_D(QWebContentsView); content::NavigationController& controller = d->webContentsDelegate->web_contents()->GetController(); int index = controller.GetPendingEntryIndex(); @@ -129,4 +137,25 @@ void QWebContentsView::stop() controller.RemoveEntryAtIndex(index); d->webContentsDelegate->web_contents()->GetView()->Focus(); + +} + +QWebContentsViewPrivate::QWebContentsViewPrivate() + // This has to be the first thing we do. + : context(WebEngineContext::current()) + , m_isLoading(false) +{ +} + +void QWebContentsViewPrivate::loadingStateChanged() +{ + Q_Q(QWebContentsView); + 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); + } } diff --git a/lib/qwebcontentsview.h b/lib/qwebcontentsview.h index 83eefd59e..2bea89a14 100644 --- a/lib/qwebcontentsview.h +++ b/lib/qwebcontentsview.h @@ -70,7 +70,9 @@ Q_SIGNALS: void urlChanged(const QUrl& url); private: - QScopedPointer<QWebContentsViewPrivate> d; + Q_DECLARE_PRIVATE(QWebContentsView) + // Hides QObject::d_ptr allowing us to use the convenience macros. + QScopedPointer<QWebContentsViewPrivate> d_ptr; }; #endif // QWEBCONTESTSVIEW_H diff --git a/lib/qwebcontentsview_p.h b/lib/qwebcontentsview_p.h index 8af2f1bce..9d2190ee2 100644 --- a/lib/qwebcontentsview_p.h +++ b/lib/qwebcontentsview_p.h @@ -53,31 +53,19 @@ class QWebContentsViewPrivate : public QObject { + QWebContentsView *q_ptr; + Q_DECLARE_PUBLIC(QWebContentsView) Q_OBJECT public: - QWebContentsViewPrivate(QWebContentsView* webContentsView) - : q(webContentsView) - , m_isLoading(false) - { } + QWebContentsViewPrivate(); 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); - } - } + void loadingStateChanged(); public: - bool m_isLoading; - QWebContentsView* q; scoped_refptr<WebEngineContext> context; scoped_ptr<WebContentsDelegateQt> webContentsDelegate; + bool m_isLoading; }; #endif
\ No newline at end of file |