Permalink
Browse files

Implementing "goBack", "goForward" and "go".

  • Loading branch information...
1 parent 40a14b7 commit 9ba13ba989c5e910a6bc684dbe5460f7a4953bed @detro detro committed with Nov 18, 2012
Showing with 37 additions and 8 deletions.
  1. +22 −4 src/webpage.cpp
  2. +15 −4 src/webpage.h
View
@@ -45,6 +45,7 @@
#include <QPainter>
#include <QPrinter>
#include <QWebHistory>
+#include <QWebHistoryItem>
#include <QWebElement>
#include <QWebFrame>
#include <QWebPage>
@@ -425,10 +426,10 @@ bool WebPage::canGoBack()
return m_customWebPage->history()->canGoBack();
}
-bool WebPage::back()
+bool WebPage::goBack()
{
if (canGoBack()) {
- m_customWebPage->triggerAction(QWebPage::Back);
+ m_customWebPage->history()->back();
return true;
}
return false;
@@ -439,15 +440,32 @@ bool WebPage::canGoForward()
return m_customWebPage->history()->canGoForward();
}
-bool WebPage::forward()
+bool WebPage::goForward()
{
if (canGoForward()) {
- m_customWebPage->triggerAction(QWebPage::Forward);
+ m_customWebPage->history()->forward();
return true;
}
return false;
}
+bool WebPage::go(int historyItemRelativeIndex)
+{
+ // Convert the relative index to absolute
+ int historyItemIndex = m_customWebPage->history()->currentItemIndex() + historyItemRelativeIndex;
+
+ // Fetch the right item from the history
+ QWebHistoryItem historyItem = m_customWebPage->history()->itemAt(historyItemIndex);
+
+ // Go to the history item, if it's valid
+ if (historyItem.isValid()) {
+ m_customWebPage->history()->goToItem(historyItem);
+ return true;
+ }
+
+ return false;
+}
+
void WebPage::reload()
{
m_customWebPage->triggerAction(QWebPage::Reload);
View
@@ -412,10 +412,10 @@ public slots:
bool canGoBack();
/**
* Goes back in the Navigation History
- * @brief back
+ * @brief goBack
* @return "true" if it does go back in the Navigation History, "false" otherwise
*/
- bool back();
+ bool goBack();
/**
* Checks if this Page can go forward in the Navigation History (i.e. next URL)
* @brief canGoForward
@@ -424,10 +424,21 @@ public slots:
bool canGoForward();
/**
* Goes forward in the Navigation History
- * @brief forward
+ * @brief goForward
* @return "true" if it does go forward in the Navigation History, "false" otherwise
*/
- bool forward();
+ bool goForward();
+ /**
+ * Go to the page identified by its relative location to the current page.
+ * For example '-1' for the previous page or 1 for the next page.
+ *
+ * Modelled after JavaScript "window.go(num)" method:
+ * {@see https://developer.mozilla.org/en-US/docs/DOM/window.history#Syntax}.
+ * @brief go
+ * @param historyRelativeIndex
+ * @return "true" if it does go forward/backgward in the Navigation History, "false" otherwise
+ */
+ bool go(int historyRelativeIndex);
/**
* Reload current page
* @brief reload

0 comments on commit 9ba13ba

Please sign in to comment.