Make history.go work

This commit is contained in:
Cheng Zhao 2015-05-11 16:44:01 +08:00
parent 2bb7497312
commit e817192df3
4 changed files with 14 additions and 2 deletions

View file

@ -454,6 +454,11 @@ void WebContents::GoForward() {
web_contents()->GetController().GoForward(); web_contents()->GetController().GoForward();
} }
void WebContents::GoToOffset(int offset) {
atom::AtomBrowserClient::SuppressRendererProcessRestartForOnce();
web_contents()->GetController().GoToOffset(offset);
}
int WebContents::GetRoutingID() const { int WebContents::GetRoutingID() const {
return web_contents()->GetRoutingID(); return web_contents()->GetRoutingID();
} }
@ -624,6 +629,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache) .SetMethod("_reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
.SetMethod("_goBack", &WebContents::GoBack) .SetMethod("_goBack", &WebContents::GoBack)
.SetMethod("_goForward", &WebContents::GoForward) .SetMethod("_goForward", &WebContents::GoForward)
.SetMethod("_goToOffset", &WebContents::GoToOffset)
.SetMethod("getRoutingId", &WebContents::GetRoutingID) .SetMethod("getRoutingId", &WebContents::GetRoutingID)
.SetMethod("getProcessId", &WebContents::GetProcessID) .SetMethod("getProcessId", &WebContents::GetProcessID)
.SetMethod("isCrashed", &WebContents::IsCrashed) .SetMethod("isCrashed", &WebContents::IsCrashed)

View file

@ -55,7 +55,7 @@ class WebContents : public mate::EventEmitter,
void ReloadIgnoringCache(); void ReloadIgnoringCache();
void GoBack(); void GoBack();
void GoForward(); void GoForward();
void GoToIndex(); void GoToOffset(int offset);
int GetRoutingID() const; int GetRoutingID() const;
int GetProcessID() const; int GetProcessID() const;
bool IsCrashed() const; bool IsCrashed() const;

View file

@ -94,7 +94,12 @@ class NavigationController
goToOffset: (offset) -> goToOffset: (offset) ->
return unless @canGoToOffset 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: -> getActiveIndex: ->
if @pendingIndex is -1 then @currentIndex else @pendingIndex if @pendingIndex is -1 then @currentIndex else @pendingIndex

View file

@ -87,3 +87,4 @@ sendHistoryOperation = (args...) ->
ipc.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args... ipc.send 'ATOM_SHELL_NAVIGATION_CONTROLLER', args...
window.history.back = -> sendHistoryOperation 'goBack' window.history.back = -> sendHistoryOperation 'goBack'
window.history.forward = -> sendHistoryOperation 'goForward' window.history.forward = -> sendHistoryOperation 'goForward'
window.history.go = (offset) -> sendHistoryOperation 'goToOffset', offset