Bug 86975, synchronise ScrollToRef() code between HTML and XML content sinks. r=harishd, sr=jst.
git-svn-id: svn://10.0.0.236/trunk@100126 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
3c51d19ca8
commit
dc699b5159
@ -3921,7 +3921,7 @@ HTMLContentSink::StartLayout()
|
||||
}
|
||||
|
||||
// Convert the ref from document charset to unicode.
|
||||
static nsresult CharsetConvRef(const nsString& aDocCharset, const nsCString& aRefInDocCharset, nsString& aRefInUnicode)
|
||||
nsresult CharsetConvRef(const nsString& aDocCharset, const nsCString& aRefInDocCharset, nsString& aRefInUnicode)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
@ -3962,6 +3962,8 @@ static nsresult CharsetConvRef(const nsString& aDocCharset, const nsCString& aRe
|
||||
void
|
||||
HTMLContentSink::ScrollToRef()
|
||||
{
|
||||
// XXX Duplicate code in nsXMLContentSink.
|
||||
// XXX Be sure to change both places if you make changes here.
|
||||
if (!mRef.IsEmpty()) {
|
||||
char* tmpstr = mRef.ToNewCString();
|
||||
if(! tmpstr)
|
||||
|
||||
@ -79,6 +79,9 @@
|
||||
#include "nsIWebNavigation.h"
|
||||
#include "nsIScriptElement.h"
|
||||
#include "nsStyleLinkElement.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsICharsetConverterManager2.h"
|
||||
|
||||
// XXX misnamed header file, but oh well
|
||||
#include "nsHTMLTokens.h"
|
||||
@ -246,19 +249,56 @@ nsXMLContentSink::WillBuildModel(void)
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// This function's implementation is in nsHTMLContentSink.cpp
|
||||
nsresult CharsetConvRef(const nsString& aDocCharset, const nsCString& aRefInDocCharset, nsString& aRefInUnicode);
|
||||
|
||||
void
|
||||
nsXMLContentSink::ScrollToRef()
|
||||
{
|
||||
if (mRef.Length() > 0)
|
||||
{
|
||||
// XXX Duplicate code in nsHTMLContentSink.
|
||||
// XXX Be sure to change both places if you make changes here.
|
||||
if (!mRef.IsEmpty()) {
|
||||
char* tmpstr = mRef.ToNewCString();
|
||||
if(! tmpstr)
|
||||
return;
|
||||
nsUnescape(tmpstr);
|
||||
nsCAutoString unescapedRef;
|
||||
unescapedRef.Assign(tmpstr);
|
||||
nsMemory::Free(tmpstr);
|
||||
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
// We assume that the bytes are in UTF-8, as it says in the spec:
|
||||
// http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.1
|
||||
nsAutoString ref = NS_ConvertUTF8toUCS2(unescapedRef);
|
||||
|
||||
PRInt32 i, ns = mDocument->GetNumberOfShells();
|
||||
for (i = 0; i < ns; i++) {
|
||||
nsCOMPtr<nsIPresShell> shell;
|
||||
mDocument->GetShellAt(i, getter_AddRefs(shell));
|
||||
if (shell) {
|
||||
shell->FlushPendingNotifications();
|
||||
// Scroll to the anchor
|
||||
shell->GoToAnchor(mRef);
|
||||
shell->FlushPendingNotifications();
|
||||
|
||||
// Check an empty string which might be caused by the UTF-8 conversion
|
||||
if (!ref.IsEmpty())
|
||||
rv = shell->GoToAnchor(ref);
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
// If UTF-8 URL failed then try to assume the string as a
|
||||
// document's charset.
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
nsAutoString docCharset;
|
||||
rv = mDocument->GetDocumentCharacterSet(docCharset);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = CharsetConvRef(docCharset, unescapedRef, ref);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && !ref.IsEmpty())
|
||||
rv = shell->GoToAnchor(ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user