Commit 854a1b3c authored by abarth@webkit.org's avatar abarth@webkit.org

2009-10-03 Adam Barth <abarth@webkit.org>

        Reviewed by Sam Weinig.

        Factor back-forward list methods out of FrameLoader
        https://bugs.webkit.org/show_bug.cgi?id=30037

        This change moves these back-forward related methods from FrameLoader
        to Page.  It's possible we should move these methods into some kind of
        "page controller" object, but we can figure that out in a future patch.

        * loader/FrameLoader.cpp:
        * loader/FrameLoader.h:
        * loader/RedirectScheduler.cpp:
        (WebCore::RedirectScheduler::timerFired):
        * page/ContextMenuController.cpp:
        (WebCore::ContextMenuController::contextMenuItemSelected):
        * page/DOMWindow.cpp:
        (WebCore::DOMWindow::close):
        * page/History.cpp:
        (WebCore::History::length):
        * page/Page.cpp:
        (WebCore::Page::canGoBackOrForward):
        (WebCore::Page::goBackOrForward):
        (WebCore::Page::getHistoryLength):
        * page/Page.h:
        * platform/ContextMenu.cpp:
        (WebCore::ContextMenu::populate):
        (WebCore::ContextMenu::checkOrEnableIfNeeded):
2009-10-03  Adam Barth  <abarth@webkit.org>

        Reviewed by Sam Weinig.

        Factor PageController out of FrameLoader and Page
        https://bugs.webkit.org/show_bug.cgi?id=30037

        * webkit/webkitwebview.cpp:
        (webkit_web_view_can_go_back_or_forward):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@49067 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent cd3cf03e
2009-10-03 Adam Barth <abarth@webkit.org>
Reviewed by Sam Weinig.
Factor back-forward list methods out of FrameLoader
https://bugs.webkit.org/show_bug.cgi?id=30037
This change moves these back-forward related methods from FrameLoader
to Page. It's possible we should move these methods into some kind of
"page controller" object, but we can figure that out in a future patch.
* loader/FrameLoader.cpp:
* loader/FrameLoader.h:
* loader/RedirectScheduler.cpp:
(WebCore::RedirectScheduler::timerFired):
* page/ContextMenuController.cpp:
(WebCore::ContextMenuController::contextMenuItemSelected):
* page/DOMWindow.cpp:
(WebCore::DOMWindow::close):
* page/History.cpp:
(WebCore::History::length):
* page/Page.cpp:
(WebCore::Page::canGoBackOrForward):
(WebCore::Page::goBackOrForward):
(WebCore::Page::getHistoryLength):
* page/Page.h:
* platform/ContextMenu.cpp:
(WebCore::ContextMenu::populate):
(WebCore::ContextMenu::checkOrEnableIfNeeded):
2009-10-02 Pavel Feldman <pfeldman@chromium.org>
Reviewed by Timothy Hatcher.
......@@ -1270,36 +1270,6 @@ KURL FrameLoader::completeURL(const String& url)
return m_frame->document()->completeURL(url);
}
void FrameLoader::goBackOrForward(int distance)
{
if (distance == 0)
return;
Page* page = m_frame->page();
if (!page)
return;
BackForwardList* list = page->backForwardList();
if (!list)
return;
HistoryItem* item = list->itemAtIndex(distance);
if (!item) {
if (distance > 0) {
int forwardListCount = list->forwardListCount();
if (forwardListCount > 0)
item = list->itemAtIndex(forwardListCount);
} else {
int backListCount = list->backListCount();
if (backListCount > 0)
item = list->itemAtIndex(-backListCount);
}
}
ASSERT(item); // we should not reach this line with an empty back/forward list
if (item)
page->goToItem(item, FrameLoadTypeIndexedBackForward);
}
void FrameLoader::loadURLIntoChildFrame(const KURL& url, const String& referer, Frame* childFrame)
{
ASSERT(childFrame);
......@@ -3957,26 +3927,6 @@ bool FrameLoader::shouldInterruptLoadForXFrameOptions(const String& content, con
return false;
}
bool FrameLoader::canGoBackOrForward(int distance) const
{
if (Page* page = m_frame->page()) {
if (distance == 0)
return true;
if (distance > 0 && distance <= page->backForwardList()->forwardListCount())
return true;
if (distance < 0 && -distance <= page->backForwardList()->backListCount())
return true;
}
return false;
}
int FrameLoader::getHistoryLength()
{
if (Page* page = m_frame->page())
return page->backForwardList()->backListCount() + 1;
return 0;
}
void FrameLoader::addHistoryItemForFragmentScroll()
{
addBackForwardItemClippedAtTarget(false);
......
......@@ -238,10 +238,6 @@ namespace WebCore {
KURL baseURL() const;
bool canGoBackOrForward(int distance) const;
void goBackOrForward(int distance);
int getHistoryLength();
void begin();
void begin(const KURL&, bool dispatchWindowObjectAvailable = true, SecurityOrigin* forcedSecurityOrigin = 0);
......
......@@ -282,8 +282,8 @@ void RedirectScheduler::timerFired(Timer<RedirectScheduler>*)
}
// go(i!=0) from a frame navigates into the history of the frame only,
// in both IE and NS (but not in Mozilla). We can't easily do that.
if (loader->canGoBackOrForward(redirection->historySteps))
loader->goBackOrForward(redirection->historySteps);
if (m_frame->page()->canGoBackOrForward(redirection->historySteps))
m_frame->page()->goBackOrForward(redirection->historySteps);
return;
case ScheduledRedirection::formSubmission:
// The submitForm function will find a target frame before using the redirection timer.
......
......@@ -166,10 +166,12 @@ void ContextMenuController::contextMenuItemSelected(ContextMenuItem* item)
frame->editor()->copy();
break;
case ContextMenuItemTagGoBack:
frame->loader()->goBackOrForward(-1);
if (Page* page = frame->page())
page->goBackOrForward(-1);
break;
case ContextMenuItemTagGoForward:
frame->loader()->goBackOrForward(1);
if (Page* page = frame->page())
page->goBackOrForward(1);
break;
case ContextMenuItemTagStop:
frame->loader()->stop();
......
......@@ -743,7 +743,7 @@ void DOMWindow::close()
settings && settings->allowScriptsToCloseWindows();
if (m_frame->loader()->openedByDOM()
|| m_frame->loader()->getHistoryLength() <= 1
|| page->getHistoryLength() <= 1
|| allowScriptsToCloseWindows)
m_frame->scheduleClose();
}
......
......@@ -50,7 +50,9 @@ unsigned History::length() const
{
if (!m_frame)
return 0;
return m_frame->loader()->getHistoryLength();
if (!m_frame->page())
return 0;
return m_frame->page()->getHistoryLength();
}
void History::back()
......
......@@ -228,6 +228,40 @@ bool Page::goForward()
return false;
}
bool Page::canGoBackOrForward(int distance) const
{
if (distance == 0)
return true;
if (distance > 0 && distance <= m_backForwardList->forwardListCount())
return true;
if (distance < 0 && -distance <= m_backForwardList->backListCount())
return true;
return false;
}
void Page::goBackOrForward(int distance)
{
if (distance == 0)
return;
HistoryItem* item = m_backForwardList->itemAtIndex(distance);
if (!item) {
if (distance > 0) {
int forwardListCount = m_backForwardList->forwardListCount();
if (forwardListCount > 0)
item = m_backForwardList->itemAtIndex(forwardListCount);
} else {
int backListCount = m_backForwardList->backListCount();
if (backListCount > 0)
item = m_backForwardList->itemAtIndex(-backListCount);
}
}
ASSERT(item); // we should not reach this line with an empty back/forward list
if (item)
goToItem(item, FrameLoadTypeIndexedBackForward);
}
void Page::goToItem(HistoryItem* item, FrameLoadType type)
{
// Abort any current load if we're going to a history item
......@@ -247,6 +281,11 @@ void Page::goToItem(HistoryItem* item, FrameLoadType type)
m_mainFrame->loader()->goToItem(item, type);
}
int Page::getHistoryLength()
{
return m_backForwardList->backListCount() + 1;
}
void Page::setGlobalHistoryItem(HistoryItem* item)
{
m_globalHistoryItem = item;
......
......@@ -111,7 +111,10 @@ namespace WebCore {
// makes more sense when that class exists.
bool goBack();
bool goForward();
bool canGoBackOrForward(int distance) const;
void goBackOrForward(int distance);
void goToItem(HistoryItem*, FrameLoadType);
int getHistoryLength();
HistoryItem* globalHistoryItem() const { return m_globalHistoryItem.get(); }
void setGlobalHistoryItem(HistoryItem*);
......
......@@ -361,10 +361,10 @@ void ContextMenu::populate()
appendItem(StopItem);
appendItem(ReloadItem);
#else
if (loader->canGoBackOrForward(-1))
if (frame->page() && frame->page()->canGoBackOrForward(-1))
appendItem(BackItem);
if (loader->canGoBackOrForward(1))
if (frame->page() && frame->page()->canGoBackOrForward(1))
appendItem(ForwardItem);
// use isLoadingInAPISense rather than isLoading because Stop/Reload are
......@@ -721,10 +721,10 @@ void ContextMenu::checkOrEnableIfNeeded(ContextMenuItem& item) const
#endif
#if PLATFORM(GTK)
case ContextMenuItemTagGoBack:
shouldEnable = frame->loader()->canGoBackOrForward(-1);
shouldEnable = frame->page() && frame->page()->canGoBackOrForward(-1);
break;
case ContextMenuItemTagGoForward:
shouldEnable = frame->loader()->canGoBackOrForward(1);
shouldEnable = frame->page() && frame->page()->canGoBackOrForward(1);
break;
case ContextMenuItemTagStop:
shouldEnable = frame->loader()->documentLoader()->isLoadingInAPISense();
......
2009-10-03 Adam Barth <abarth@webkit.org>
Reviewed by Sam Weinig.
Factor PageController out of FrameLoader and Page
https://bugs.webkit.org/show_bug.cgi?id=30037
* webkit/webkitwebview.cpp:
(webkit_web_view_can_go_back_or_forward):
2009-10-01 Xan Lopez <xlopez@igalia.com>
Reviewed by Gustavo Noronha.
......
......@@ -2879,8 +2879,7 @@ gboolean webkit_web_view_can_go_back_or_forward(WebKitWebView* webView, gint ste
{
g_return_val_if_fail(WEBKIT_IS_WEB_VIEW(webView), FALSE);
Frame* frame = core(webView)->mainFrame();
return frame->loader()->canGoBackOrForward(steps);
return core(webView)->goBackOrForward(steps);
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment