From 90f219c74e6f063285211f6fcfeb5604978d2c10 Mon Sep 17 00:00:00 2001 From: "vidur%netscape.com" Date: Thu, 13 Aug 1998 04:36:42 +0000 Subject: [PATCH] Added modifyHistory option to LoadURL. --- docshell/base/nsWebShell.cpp | 47 ++++++++++++++++++++++++----------- webshell/public/nsIWebShell.h | 4 ++- webshell/src/nsWebShell.cpp | 47 ++++++++++++++++++++++++----------- 3 files changed, 69 insertions(+), 29 deletions(-) diff --git a/docshell/base/nsWebShell.cpp b/docshell/base/nsWebShell.cpp index 864425c70fee..45b6e3e34888 100644 --- a/docshell/base/nsWebShell.cpp +++ b/docshell/base/nsWebShell.cpp @@ -143,8 +143,10 @@ public: nsIWebShell*& aResult); NS_IMETHOD Back(void); NS_IMETHOD Forward(void); + NS_IMETHOD Reload(); NS_IMETHOD LoadURL(const nsString& aURLSpec, - nsIPostData* aPostData=nsnull); + nsIPostData* aPostData=nsnull, + PRBool aModifyHistory=PR_TRUE); NS_IMETHOD GoTo(PRInt32 aHistoryIndex); NS_IMETHOD GetHistoryIndex(PRInt32& aResult); NS_IMETHOD GetURL(PRInt32 aHistoryIndex, nsString& aURLResult); @@ -867,7 +869,8 @@ nsWebShell::Forward(void) NS_IMETHODIMP nsWebShell::LoadURL(const nsString& aURLSpec, - nsIPostData* aPostData) + nsIPostData* aPostData, + PRBool aModifyHistory) { nsresult rv; PRInt32 colon, fSlash; @@ -894,19 +897,29 @@ nsWebShell::LoadURL(const nsString& aURLSpec, } } - // Discard part of history that is no longer reachable - PRInt32 i, n = mHistory.Count(); - i = mHistoryIndex + 1; - while (--n >= i) { - nsString* u = (nsString*) mHistory.ElementAt(n); - delete u; - mHistory.RemoveElementAt(n); - } - - // Tack on new url nsString* url = new nsString(urlSpec); - mHistory.AppendElement(url); - mHistoryIndex++; + if (aModifyHistory) { + // Discard part of history that is no longer reachable + PRInt32 i, n = mHistory.Count(); + i = mHistoryIndex + 1; + while (--n >= i) { + nsString* u = (nsString*) mHistory.ElementAt(n); + delete u; + mHistory.RemoveElementAt(n); + } + + // Tack on new url + mHistory.AppendElement(url); + mHistoryIndex++; + } + else { + // Replace the current history index with this URL + nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex); + if (nsnull != u) { + delete u; + } + mHistory.ReplaceElementAt(url, mHistoryIndex); + } ShowHistory(); // Tell web-shell-container we are loading a new url @@ -929,6 +942,12 @@ nsWebShell::LoadURL(const nsString& aURLSpec, return rv; } +NS_IMETHODIMP +nsWebShell::Reload() +{ + return NS_OK; +} + NS_IMETHODIMP nsWebShell::GoTo(PRInt32 aHistoryIndex) { diff --git a/webshell/public/nsIWebShell.h b/webshell/public/nsIWebShell.h index 8ad6f3c0d4ff..a3769e7a1651 100644 --- a/webshell/public/nsIWebShell.h +++ b/webshell/public/nsIWebShell.h @@ -134,8 +134,10 @@ public: // History api's NS_IMETHOD Back() = 0; NS_IMETHOD Forward() = 0; + NS_IMETHOD Reload() = 0; NS_IMETHOD LoadURL(const nsString& aURLSpec, - nsIPostData* aPostData=nsnull) = 0; + nsIPostData* aPostData=nsnull, + PRBool aModifyHistory=PR_TRUE) = 0; NS_IMETHOD GoTo(PRInt32 aHistoryIndex) = 0; NS_IMETHOD GetHistoryIndex(PRInt32& aResult) = 0; NS_IMETHOD GetURL(PRInt32 aHistoryIndex, nsString& aURLResult) = 0; diff --git a/webshell/src/nsWebShell.cpp b/webshell/src/nsWebShell.cpp index 864425c70fee..45b6e3e34888 100644 --- a/webshell/src/nsWebShell.cpp +++ b/webshell/src/nsWebShell.cpp @@ -143,8 +143,10 @@ public: nsIWebShell*& aResult); NS_IMETHOD Back(void); NS_IMETHOD Forward(void); + NS_IMETHOD Reload(); NS_IMETHOD LoadURL(const nsString& aURLSpec, - nsIPostData* aPostData=nsnull); + nsIPostData* aPostData=nsnull, + PRBool aModifyHistory=PR_TRUE); NS_IMETHOD GoTo(PRInt32 aHistoryIndex); NS_IMETHOD GetHistoryIndex(PRInt32& aResult); NS_IMETHOD GetURL(PRInt32 aHistoryIndex, nsString& aURLResult); @@ -867,7 +869,8 @@ nsWebShell::Forward(void) NS_IMETHODIMP nsWebShell::LoadURL(const nsString& aURLSpec, - nsIPostData* aPostData) + nsIPostData* aPostData, + PRBool aModifyHistory) { nsresult rv; PRInt32 colon, fSlash; @@ -894,19 +897,29 @@ nsWebShell::LoadURL(const nsString& aURLSpec, } } - // Discard part of history that is no longer reachable - PRInt32 i, n = mHistory.Count(); - i = mHistoryIndex + 1; - while (--n >= i) { - nsString* u = (nsString*) mHistory.ElementAt(n); - delete u; - mHistory.RemoveElementAt(n); - } - - // Tack on new url nsString* url = new nsString(urlSpec); - mHistory.AppendElement(url); - mHistoryIndex++; + if (aModifyHistory) { + // Discard part of history that is no longer reachable + PRInt32 i, n = mHistory.Count(); + i = mHistoryIndex + 1; + while (--n >= i) { + nsString* u = (nsString*) mHistory.ElementAt(n); + delete u; + mHistory.RemoveElementAt(n); + } + + // Tack on new url + mHistory.AppendElement(url); + mHistoryIndex++; + } + else { + // Replace the current history index with this URL + nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex); + if (nsnull != u) { + delete u; + } + mHistory.ReplaceElementAt(url, mHistoryIndex); + } ShowHistory(); // Tell web-shell-container we are loading a new url @@ -929,6 +942,12 @@ nsWebShell::LoadURL(const nsString& aURLSpec, return rv; } +NS_IMETHODIMP +nsWebShell::Reload() +{ + return NS_OK; +} + NS_IMETHODIMP nsWebShell::GoTo(PRInt32 aHistoryIndex) {