diff --git a/examples/qtquick/quickwindow.qml b/examples/qtquick/quickwindow.qml index 7962be141eed3dedd06fe2194e05a18c39f926f2..afaff7c8d95a58cfaccc32adf00675891683676b 100644 --- a/examples/qtquick/quickwindow.qml +++ b/examples/qtquick/quickwindow.qml @@ -20,12 +20,14 @@ ApplicationWindow { iconName: "go-previous" iconSource: ":/icons/go-previous.png" onClicked: webContentsView.goBack() + enabled: webContentsView.canGoBack } ToolButton { id: forwardButton iconName: "go-next" iconSource: ":/icons/go-next.png" onClicked: webContentsView.goForward() + enabled: webContentsView.canGoForward } ToolButton { id: reloadButton diff --git a/examples/widgets/widgetwindow.cpp b/examples/widgets/widgetwindow.cpp index 589ef13c36c535c1f913672e42142b839444c32b..a28a6f130f4796f786bf5394d24d3d92ccc66b3b 100644 --- a/examples/widgets/widgetwindow.cpp +++ b/examples/widgets/widgetwindow.cpp @@ -63,11 +63,11 @@ WidgetWindow::WidgetWindow() QHBoxLayout* addressBar = new QHBoxLayout; addressBar->setSpacing(margin); // Bigger buttons, less space between them - QToolButton* backButton = new QToolButton; + backButton = new QToolButton; backButton->setIcon(QIcon::fromTheme("go-previous")); addressBar->addWidget(backButton); - QToolButton* forwardButton = new QToolButton; + forwardButton = new QToolButton; forwardButton->setIcon(QIcon::fromTheme("go-next")); addressBar->addWidget(forwardButton); @@ -117,5 +117,7 @@ void WidgetWindow::loadStarted() void WidgetWindow::loadFinished(bool success) { Q_UNUSED(success); + forwardButton->setEnabled(m_webView->canGoForward()); + backButton->setEnabled(m_webView->canGoBack()); reloadButton->setIcon(QIcon::fromTheme("view-refresh")); } diff --git a/examples/widgets/widgetwindow.h b/examples/widgets/widgetwindow.h index 5273d425582025cf4fb500ef31f13a5a7ffc0e47..863e8a73f8bce800163641554f0aa5959f97acd1 100644 --- a/examples/widgets/widgetwindow.h +++ b/examples/widgets/widgetwindow.h @@ -62,6 +62,8 @@ private Q_SLOTS: private: QScopedPointer<QWebContentsView> m_webView; QLineEdit* addressLineEdit; + QToolButton* forwardButton; + QToolButton* backButton; QToolButton* reloadButton; }; diff --git a/lib/qwebcontentsview.cpp b/lib/qwebcontentsview.cpp index 323bb3b603a4a0a1707bbed8556fac2e1de7f4d3..07aa034d58d28647f54286825a115ccf40191cb7 100644 --- a/lib/qwebcontentsview.cpp +++ b/lib/qwebcontentsview.cpp @@ -95,6 +95,16 @@ void QWebContentsView::load(const QUrl& url) d->webContentsDelegate->web_contents()->GetView()->Focus(); } +bool QWebContentsView::canGoBack() const +{ + return d->webContentsDelegate->web_contents()->GetController().CanGoBack(); +} + +bool QWebContentsView::canGoForward() const +{ + return d->webContentsDelegate->web_contents()->GetController().CanGoForward(); +} + void QWebContentsView::back() { d->webContentsDelegate->web_contents()->GetController().GoToOffset(-1); diff --git a/lib/qwebcontentsview.h b/lib/qwebcontentsview.h index 6eef056c7db7760c60186a3360126926179397cc..83eefd59e5e148863bea3d45bba2ce5ad1def529 100644 --- a/lib/qwebcontentsview.h +++ b/lib/qwebcontentsview.h @@ -54,6 +54,8 @@ public: ~QWebContentsView(); void load(const QUrl& url); + bool canGoBack() const; + bool canGoForward() const; public Q_SLOTS: void back();