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

Completing work for [Issue #808](http://code.google.com/p/phantomjs/issues/detail?id=808).
1.8
Ivan De Marino 2012-11-18 00:08:54 +00:00 committed by Ariya Hidayat
parent 40a14b72b1
commit 9ba13ba989
2 changed files with 37 additions and 8 deletions

View File

@ -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 File

@ -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