From e817192df3db3b415bf277777625924e6d84d981 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Mon, 11 May 2015 16:44:01 +0800 Subject: [PATCH] Make history.go work --- atom/browser/api/atom_api_web_contents.cc | 6 ++++++ atom/browser/api/atom_api_web_contents.h | 2 +- atom/browser/api/lib/navigation-controller.coffee | 7 ++++++- atom/renderer/lib/override.coffee | 1 + 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index ddb05cfd..e228a064 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -454,6 +454,11 @@ void WebContents::GoForward() { web_contents()->GetController().GoForward(); } +void WebContents::GoToOffset(int offset) { + atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce(); + web_contents()->GetController().GoToOffset(offset); +} + int WebContents::GetRoutingID() const { return web_contents()->GetRoutingID(); } @@ -624,6 +629,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache) .SetMethod("_goBack", &WebContents::GoBack) .SetMethod("_goForward", &WebContents::GoForward) + .SetMethod("_goToOffset", &WebContents::GoToOffset) .SetMethod("getRoutingId", &WebContents::GetRoutingID) .SetMethod("getProcessId", &WebContents::GetProcessID) .SetMethod("isCrashed", &WebContents::IsCrashed) diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index aa0ee8d6..e75cfb02 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -55,7 +55,7 @@ class WebContents : public mate::EventEmitter, void ReloadIgnoringCache(); void GoBack(); void GoForward(); - void GoToIndex(); + void GoToOffset(int offset); int GetRoutingID() const; int GetProcessID() const; bool IsCrashed() const; diff --git a/atom/browser/api/lib/navigation-controller.coffee b/atom/browser/api/lib/navigation-controller.coffee index 82c4ab4d..f7945e07 100644 --- a/atom/browser/api/lib/navigation-controller.coffee +++ b/atom/browser/api/lib/navigation-controller.coffee @@ -94,7 +94,12 @@ class NavigationController goToOffset: (offset) -> return unless @canGoToOffset offset - @goToIndex @currentIndex + offset + pendingIndex = @currentIndex + offset + if @inPageIndex > -1 and pendingIndex >= @inPageIndex + @pendingIndex = pendingIndex + @webContents._goToOffset offset + else + @goToIndex pendingIndex getActiveIndex: -> if @pendingIndex is -1 then @currentIndex else @pendingIndex diff --git a/atom/renderer/lib/override.coffee b/atom/renderer/lib/override.coffee index 1bc1e612..1ca6e692 100644 --- a/atom/renderer/lib/override.coffee +++ b/atom/renderer/lib/override.coffee @@ -87,3 +87,4 @@ sendHistoryOperation = (args...) -> ipc.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args... window.history.back = -> sendHistoryOperation 'goBack' window.history.forward = -> sendHistoryOperation 'goForward' +window.history.go = (offset) -> sendHistoryOperation 'goToOffset', offset -- 2.43.0