Bug 1155730, implement History.scrollRestoration r=jst
This commit is contained in:
@@ -10043,9 +10043,11 @@ nsDocShell::InternalLoad(nsIURI* aURI,
|
||||
nsCOMPtr<nsIInputStream> postData;
|
||||
nsCOMPtr<nsISupports> cacheKey;
|
||||
|
||||
bool scrollRestorationIsManual = false;
|
||||
if (mOSHE) {
|
||||
/* save current position of scroller(s) (bug 59774) */
|
||||
mOSHE->SetScrollPosition(cx, cy);
|
||||
mOSHE->GetScrollRestorationIsManual(&scrollRestorationIsManual);
|
||||
// Get the postdata and page ident from the current page, if
|
||||
// the new load is being done via normal means. Note that
|
||||
// "normal means" can be checked for just by checking for
|
||||
@@ -10060,6 +10062,11 @@ nsDocShell::InternalLoad(nsIURI* aURI,
|
||||
// cache data, since the two SHEntries correspond to the
|
||||
// same document.
|
||||
if (mLSHE) {
|
||||
if (!aSHEntry) {
|
||||
// If we're not doing a history load, scroll restoration
|
||||
// should be inherited from the previous session history entry.
|
||||
mLSHE->SetScrollRestorationIsManual(scrollRestorationIsManual);
|
||||
}
|
||||
mLSHE->AdoptBFCacheEntry(mOSHE);
|
||||
}
|
||||
}
|
||||
@@ -10132,10 +10139,12 @@ nsDocShell::InternalLoad(nsIURI* aURI,
|
||||
/* restore previous position of scroller(s), if we're moving
|
||||
* back in history (bug 59774)
|
||||
*/
|
||||
nscoord bx, by;
|
||||
nscoord bx = 0;
|
||||
nscoord by = 0;
|
||||
bool needsScrollPosUpdate = false;
|
||||
if (mOSHE && (aLoadType == LOAD_HISTORY ||
|
||||
aLoadType == LOAD_RELOAD_NORMAL)) {
|
||||
aLoadType == LOAD_RELOAD_NORMAL) &&
|
||||
!scrollRestorationIsManual) {
|
||||
needsScrollPosUpdate = true;
|
||||
mOSHE->GetScrollPosition(&bx, &by);
|
||||
}
|
||||
@@ -11624,6 +11633,9 @@ nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
|
||||
GetCurScrollPos(ScrollOrientation_Y, &cy);
|
||||
mOSHE->SetScrollPosition(cx, cy);
|
||||
|
||||
bool scrollRestorationIsManual = false;
|
||||
mOSHE->GetScrollRestorationIsManual(&scrollRestorationIsManual);
|
||||
|
||||
// Since we're not changing which page we have loaded, pass
|
||||
// true for aCloneChildren.
|
||||
rv = AddToSessionHistory(newURI, nullptr, nullptr, true,
|
||||
@@ -11632,6 +11644,10 @@ nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
|
||||
|
||||
NS_ENSURE_TRUE(newSHEntry, NS_ERROR_FAILURE);
|
||||
|
||||
// Session history entries created by pushState inherit scroll restoration
|
||||
// mode from the current entry.
|
||||
newSHEntry->SetScrollRestorationIsManual(scrollRestorationIsManual);
|
||||
|
||||
// Link the new SHEntry to the old SHEntry's BFCache entry, since the
|
||||
// two entries correspond to the same document.
|
||||
NS_ENSURE_SUCCESS(newSHEntry->AdoptBFCacheEntry(oldOSHE), NS_ERROR_FAILURE);
|
||||
@@ -11740,6 +11756,27 @@ nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::GetCurrentScrollRestorationIsManual(bool* aIsManual)
|
||||
{
|
||||
*aIsManual = false;
|
||||
if (mOSHE) {
|
||||
mOSHE->GetScrollRestorationIsManual(aIsManual);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDocShell::SetCurrentScrollRestorationIsManual(bool aIsManual)
|
||||
{
|
||||
if (mOSHE) {
|
||||
mOSHE->SetScrollRestorationIsManual(aIsManual);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
bool
|
||||
nsDocShell::ShouldAddToSessionHistory(nsIURI* aURI)
|
||||
{
|
||||
@@ -12140,10 +12177,21 @@ nsDocShell::PersistLayoutHistoryState()
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (mOSHE) {
|
||||
bool scrollRestorationIsManual = false;
|
||||
mOSHE->GetScrollRestorationIsManual(&scrollRestorationIsManual);
|
||||
|
||||
nsCOMPtr<nsIPresShell> shell = GetPresShell();
|
||||
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
||||
if (shell) {
|
||||
nsCOMPtr<nsILayoutHistoryState> layoutState;
|
||||
rv = shell->CaptureHistoryState(getter_AddRefs(layoutState));
|
||||
} else if (scrollRestorationIsManual) {
|
||||
// Even if we don't have layout anymore, we may want to reset the current
|
||||
// scroll state in layout history.
|
||||
GetLayoutHistoryState(getter_AddRefs(layoutState));
|
||||
}
|
||||
|
||||
if (scrollRestorationIsManual && layoutState) {
|
||||
layoutState->ResetScrollState();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user