Changed LoadURL() to look at the destination anchor and see if it's an element

within the current document. If so, it calls the pres shell's GoToAnchor()
function


git-svn-id: svn://10.0.0.236/trunk@20532 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
troy%netscape.com
1999-02-12 05:43:46 +00:00
parent 946499d8d7
commit ec6abf170e
2 changed files with 72 additions and 0 deletions

View File

@@ -53,6 +53,8 @@
#include "nsIBrowserWindow.h"
#include "nsIContent.h"
#include "prlog.h"
#include "nsCOMPtr.h"
#include "nsIPresShell.h"
#ifdef XP_PC
#include <windows.h>
@@ -1324,6 +1326,40 @@ nsWebShell::LoadURL(const PRUnichar *aURLSpec,
}
ShowHistory();
// If it's a normal reload that uses the cache, look at the destination anchor
// and see if it's an element within the current document
if ((aType == nsURLReload) && (nsnull != mContentViewer)) {
nsCOMPtr<nsIDocumentViewer> docViewer;
if (NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID,
getter_AddRefs(docViewer)))) {
// Get the document object
nsCOMPtr<nsIDocument> doc;
docViewer->GetDocument(*getter_AddRefs(doc));
// Get the URL for the document
nsCOMPtr<nsIURL> docURL = nsDontAddRef<nsIURL>(doc->GetDocumentURL());
// See if they're the same
nsCOMPtr<nsIURL> url;
NS_NewURL(getter_AddRefs(url), urlSpec);
if ((PRBool)docURL->Equals(url)) {
// See if there's a destination anchor
const char* ref;
url->GetRef(&ref);
if (nsnull != ref) {
// Get the pres shell object
nsCOMPtr<nsIPresShell> presShell;
docViewer->GetPresShell(*getter_AddRefs(presShell));
presShell->GoToAnchor(nsAutoString(ref));
return NS_OK;
}
}
}
}
// Stop loading the current document (if any...). This call may result in
// firing an EndLoadURL notification for the old document...
Stop();