Bug 881487. Make anchor scrolls on wyciwyg documents work correctly. r=smaug
This commit is contained in:
@@ -9115,13 +9115,21 @@ nsDocShell::InternalLoad(nsIURI * aURI,
|
|||||||
aLoadType == LOAD_HISTORY ||
|
aLoadType == LOAD_HISTORY ||
|
||||||
aLoadType == LOAD_LINK) {
|
aLoadType == LOAD_LINK) {
|
||||||
|
|
||||||
// Split mCurrentURI and aURI on the '#' character. Make sure we read
|
nsCOMPtr<nsIURI> currentURI;
|
||||||
|
if (sURIFixup && mCurrentURI) {
|
||||||
|
rv = sURIFixup->CreateExposableURI(mCurrentURI,
|
||||||
|
getter_AddRefs(currentURI));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
} else {
|
||||||
|
currentURI = mCurrentURI;
|
||||||
|
}
|
||||||
|
// Split currentURI and aURI on the '#' character. Make sure we read
|
||||||
// the return values of SplitURIAtHash; if it fails, we don't want to
|
// the return values of SplitURIAtHash; if it fails, we don't want to
|
||||||
// allow a short-circuited navigation.
|
// allow a short-circuited navigation.
|
||||||
nsAutoCString curBeforeHash, curHash, newBeforeHash, newHash;
|
nsAutoCString curBeforeHash, curHash, newBeforeHash, newHash;
|
||||||
nsresult splitRv1, splitRv2;
|
nsresult splitRv1, splitRv2;
|
||||||
splitRv1 = mCurrentURI ?
|
splitRv1 = currentURI ?
|
||||||
nsContentUtils::SplitURIAtHash(mCurrentURI,
|
nsContentUtils::SplitURIAtHash(currentURI,
|
||||||
curBeforeHash, curHash) :
|
curBeforeHash, curHash) :
|
||||||
NS_ERROR_FAILURE;
|
NS_ERROR_FAILURE;
|
||||||
splitRv2 = nsContentUtils::SplitURIAtHash(aURI, newBeforeHash, newHash);
|
splitRv2 = nsContentUtils::SplitURIAtHash(aURI, newBeforeHash, newHash);
|
||||||
@@ -9179,9 +9187,6 @@ nsDocShell::InternalLoad(nsIURI * aURI,
|
|||||||
mDocumentRequest->Cancel(NS_BINDING_ABORTED);
|
mDocumentRequest->Cancel(NS_BINDING_ABORTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the current URI; we need it if we fire a hashchange later.
|
|
||||||
nsCOMPtr<nsIURI> oldURI = mCurrentURI;
|
|
||||||
|
|
||||||
// Save the position of the scrollers.
|
// Save the position of the scrollers.
|
||||||
nscoord cx = 0, cy = 0;
|
nscoord cx = 0, cy = 0;
|
||||||
GetCurScrollPos(ScrollOrientation_X, &cx);
|
GetCurScrollPos(ScrollOrientation_X, &cx);
|
||||||
@@ -9342,15 +9347,15 @@ nsDocShell::InternalLoad(nsIURI * aURI,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (doHashchange) {
|
if (doHashchange) {
|
||||||
// Make sure to use oldURI here, not mCurrentURI, because by
|
// Note that currentURI hasn't changed because it's on the
|
||||||
// now, mCurrentURI has changed!
|
// stack, so we can just use it directly as the old URI.
|
||||||
win->DispatchAsyncHashchange(oldURI, aURI);
|
win->DispatchAsyncHashchange(currentURI, aURI);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Inform the favicon service that the favicon for oldURI also
|
// Inform the favicon service that the favicon for oldURI also
|
||||||
// applies to aURI.
|
// applies to aURI.
|
||||||
CopyFavicon(oldURI, aURI, mInPrivateBrowsing);
|
CopyFavicon(currentURI, aURI, mInPrivateBrowsing);
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
15
docshell/test/file_anchor_scroll_after_document_open.html
Normal file
15
docshell/test/file_anchor_scroll_after_document_open.html
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<script>
|
||||||
|
if (location.hash == "#target") {
|
||||||
|
parent.postMessage("haveHash", "*");
|
||||||
|
} else {
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
document.open();
|
||||||
|
document.write("<!DOCTYPE html><html style='height: 100%'><body style='height: 100%'><div style='height: 200%'></div><div id='target'></div></body></html>");
|
||||||
|
document.close();
|
||||||
|
// Notify parent via postMessage, since otherwise exceptions will not get
|
||||||
|
// caught by its onerror handler.
|
||||||
|
parent.postMessage("doTest", "*");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
||||||
@@ -11,6 +11,7 @@ support-files =
|
|||||||
bug668513_redirect.html
|
bug668513_redirect.html
|
||||||
bug668513_redirect.html^headers^
|
bug668513_redirect.html^headers^
|
||||||
bug691547_frame.html
|
bug691547_frame.html
|
||||||
|
file_anchor_scroll_after_document_open.html
|
||||||
file_bug385434_1.html
|
file_bug385434_1.html
|
||||||
file_bug385434_2.html
|
file_bug385434_2.html
|
||||||
file_bug385434_3.html
|
file_bug385434_3.html
|
||||||
@@ -33,6 +34,7 @@ support-files =
|
|||||||
file_bug728939.html
|
file_bug728939.html
|
||||||
historyframes.html
|
historyframes.html
|
||||||
|
|
||||||
|
[test_anchor_scroll_after_document_open.html]
|
||||||
[test_bfcache_plus_hash.html]
|
[test_bfcache_plus_hash.html]
|
||||||
[test_bug123696.html]
|
[test_bug123696.html]
|
||||||
[test_bug369814.html]
|
[test_bug369814.html]
|
||||||
|
|||||||
55
docshell/test/test_anchor_scroll_after_document_open.html
Normal file
55
docshell/test/test_anchor_scroll_after_document_open.html
Normal file
@@ -0,0 +1,55 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
|
<html>
|
||||||
|
<!--
|
||||||
|
https://bugzilla.mozilla.org/show_bug.cgi?id=881487
|
||||||
|
-->
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Test for Bug 881487</title>
|
||||||
|
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||||
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||||
|
<script type="application/javascript">
|
||||||
|
|
||||||
|
/** Test for Bug 881487 **/
|
||||||
|
SimpleTest.waitForExplicitFinish();
|
||||||
|
// Child needs to invoke us, otherwise our onload will fire before the child
|
||||||
|
// has done the write/close bit.
|
||||||
|
var gotOnload = false;
|
||||||
|
addLoadEvent(function() {
|
||||||
|
gotOnload = true;
|
||||||
|
});
|
||||||
|
onmessage = function handleMessage(msg) {
|
||||||
|
if (msg.data == "doTest") {
|
||||||
|
if (!gotOnload) {
|
||||||
|
addLoadEvent(function() { handleMessage(msg); });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
frames[0].onscroll = function() {
|
||||||
|
ok(true, "Got a scroll event");
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
frames[0].location.hash = "#target";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (msg.data == "haveHash") {
|
||||||
|
ok(false, "Child got reloaded");
|
||||||
|
} else {
|
||||||
|
ok(false, "Unexpected message");
|
||||||
|
}
|
||||||
|
SimpleTest.finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=881487">Mozilla Bug 881487</a>
|
||||||
|
<p id="display">
|
||||||
|
<!-- iframe goes here so it can scroll -->
|
||||||
|
<iframe src="file_anchor_scroll_after_document_open.html"></iframe>
|
||||||
|
</p>
|
||||||
|
<div id="content" style="display: none">
|
||||||
|
</div>
|
||||||
|
<pre id="test">
|
||||||
|
</pre>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
Reference in New Issue
Block a user