diff options
Diffstat (limited to 'content/browser/web_contents/navigation_controller_impl.cc')
-rw-r--r-- | content/browser/web_contents/navigation_controller_impl.cc | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/content/browser/web_contents/navigation_controller_impl.cc b/content/browser/web_contents/navigation_controller_impl.cc index 5dad661..d985605 100644 --- a/content/browser/web_contents/navigation_controller_impl.cc +++ b/content/browser/web_contents/navigation_controller_impl.cc @@ -428,15 +428,19 @@ NavigationEntry* NavigationControllerImpl::GetEntryAtIndex( NavigationEntry* NavigationControllerImpl::GetEntryAtOffset( int offset) const { - int index = (transient_entry_index_ != -1) ? - transient_entry_index_ + offset : - last_committed_entry_index_ + offset; + int index = GetIndexForOffset(offset); if (index < 0 || index >= GetEntryCount()) return NULL; return entries_[index].get(); } +int NavigationControllerImpl::GetIndexForOffset(int offset) const { + return (transient_entry_index_ != -1) ? + transient_entry_index_ + offset : + last_committed_entry_index_ + offset; +} + bool NavigationControllerImpl::CanGoBack() const { return entries_.size() > 1 && GetCurrentEntryIndex() > 0; } @@ -446,6 +450,11 @@ bool NavigationControllerImpl::CanGoForward() const { return index >= 0 && index < (static_cast<int>(entries_.size()) - 1); } +bool NavigationControllerImpl::CanGoToOffset(int offset) const { + int index = GetIndexForOffset(offset); + return index >= 0 && index < GetEntryCount(); +} + void NavigationControllerImpl::GoBack() { if (!CanGoBack()) { NOTREACHED(); @@ -519,13 +528,10 @@ void NavigationControllerImpl::GoToIndex(int index) { } void NavigationControllerImpl::GoToOffset(int offset) { - int index = (transient_entry_index_ != -1) ? - transient_entry_index_ + offset : - last_committed_entry_index_ + offset; - if (index < 0 || index >= GetEntryCount()) + if (!CanGoToOffset(offset)) return; - GoToIndex(index); + GoToIndex(GetIndexForOffset(offset)); } void NavigationControllerImpl::RemoveEntryAtIndex(int index) { |