Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: third_party/WebKit/Source/core/loader/FrameLoader.cpp

Issue 2628683003: Add DidSaveScrollOrScaleState flag to prevent restoreScrollPositionAndViewState restore from default (Closed)
Patch Set: add test Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 4 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. 5 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
6 * (http://www.torchmobile.com/) 6 * (http://www.torchmobile.com/)
7 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 7 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
8 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 8 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 9 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
10 * Copyright (C) 2011 Google Inc. All rights reserved. 10 * Copyright (C) 2011 Google Inc. All rights reserved.
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 277
278 if (ScrollableArea* layoutScrollableArea = 278 if (ScrollableArea* layoutScrollableArea =
279 m_frame->view()->layoutViewportScrollableArea()) 279 m_frame->view()->layoutViewportScrollableArea())
280 m_currentItem->setScrollOffset(layoutScrollableArea->getScrollOffset()); 280 m_currentItem->setScrollOffset(layoutScrollableArea->getScrollOffset());
281 m_currentItem->setVisualViewportScrollOffset(toScrollOffset( 281 m_currentItem->setVisualViewportScrollOffset(toScrollOffset(
282 m_frame->host()->visualViewport().visibleRect().location())); 282 m_frame->host()->visualViewport().visibleRect().location()));
283 283
284 if (m_frame->isMainFrame()) 284 if (m_frame->isMainFrame())
285 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); 285 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor());
286 286
287 m_currentItem->setDidSaveScrollState(true);
majidvp 2017/02/14 20:42:17 should we set this flag inside HistoryItem::setScr
287 client()->didUpdateCurrentHistoryItem(); 288 client()->didUpdateCurrentHistoryItem();
288 } 289 }
289 290
290 void FrameLoader::dispatchUnloadEvent() { 291 void FrameLoader::dispatchUnloadEvent() {
291 FrameNavigationDisabler navigationDisabler(*m_frame); 292 FrameNavigationDisabler navigationDisabler(*m_frame);
292 293
293 // If the frame is unloading, the provisional loader should no longer be 294 // If the frame is unloading, the provisional loader should no longer be
294 // protected. It will be detached soon. 295 // protected. It will be detached soon.
295 m_protectProvisionalLoader = false; 296 m_protectProvisionalLoader = false;
296 saveScrollState(); 297 saveScrollState();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 // Don't propagate state from the old item if this is a different-document 415 // Don't propagate state from the old item if this is a different-document
415 // navigation, unless the before and after pages are logically related. This 416 // navigation, unless the before and after pages are logically related. This
416 // means they have the same url (ignoring fragment) and the new item was 417 // means they have the same url (ignoring fragment) and the new item was
417 // loaded via reload or client redirect. 418 // loaded via reload or client redirect.
418 if (navigationType == HistoryNavigationType::DifferentDocument && 419 if (navigationType == HistoryNavigationType::DifferentDocument &&
419 (historyCommitType != HistoryInertCommit || 420 (historyCommitType != HistoryInertCommit ||
420 !equalIgnoringFragmentIdentifier(oldItem->url(), m_currentItem->url()))) 421 !equalIgnoringFragmentIdentifier(oldItem->url(), m_currentItem->url())))
421 return; 422 return;
422 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber()); 423 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber());
423 m_currentItem->setScrollOffset(oldItem->getScrollOffset()); 424 m_currentItem->setScrollOffset(oldItem->getScrollOffset());
425 m_currentItem->setDidSaveScrollState(oldItem->didSaveScrollState());
majidvp 2017/02/14 20:42:17 Perhaps copy over the scroll state only if the did
424 m_currentItem->setVisualViewportScrollOffset( 426 m_currentItem->setVisualViewportScrollOffset(
425 oldItem->visualViewportScrollOffset()); 427 oldItem->visualViewportScrollOffset());
426 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor()); 428 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor());
427 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType()); 429 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType());
428 430
429 // The item sequence number determines whether items are "the same", such 431 // The item sequence number determines whether items are "the same", such
430 // back/forward navigation between items with the same item sequence number is 432 // back/forward navigation between items with the same item sequence number is
431 // a no-op. Only treat this as identical if the navigation did not create a 433 // a no-op. Only treat this as identical if the navigation did not create a
432 // back/forward entry and the url is identical or it was loaded via 434 // back/forward entry and the url is identical or it was loaded via
433 // history.replaceState(). 435 // history.replaceState().
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 1409
1408 void FrameLoader::restoreScrollPositionAndViewStateForLoadType( 1410 void FrameLoader::restoreScrollPositionAndViewStateForLoadType(
1409 FrameLoadType loadType) { 1411 FrameLoadType loadType) {
1410 FrameView* view = m_frame->view(); 1412 FrameView* view = m_frame->view();
1411 if (!view || !view->layoutViewportScrollableArea() || !m_currentItem || 1413 if (!view || !view->layoutViewportScrollableArea() || !m_currentItem ||
1412 !m_stateMachine.committedFirstRealDocumentLoad()) { 1414 !m_stateMachine.committedFirstRealDocumentLoad()) {
1413 return; 1415 return;
1414 } 1416 }
1415 if (!needsHistoryItemRestore(loadType)) 1417 if (!needsHistoryItemRestore(loadType))
1416 return; 1418 return;
1419 if (!m_currentItem->didSaveScrollState())
1420 return;
1417 1421
1418 bool shouldRestoreScroll = 1422 bool shouldRestoreScroll =
1419 m_currentItem->scrollRestorationType() != ScrollRestorationManual; 1423 m_currentItem->scrollRestorationType() != ScrollRestorationManual;
1420 bool shouldRestoreScale = m_currentItem->pageScaleFactor(); 1424 bool shouldRestoreScale = m_currentItem->pageScaleFactor();
1421 1425
1422 // This tries to balance: 1426 // This tries to balance:
1423 // 1. restoring as soon as possible 1427 // 1. restoring as soon as possible
1424 // 2. not overriding user scroll (TODO(majidvp): also respect user scale) 1428 // 2. not overriding user scroll (TODO(majidvp): also respect user scale)
1425 // 3. detecting clamping to avoid repeatedly popping the scroll position down 1429 // 3. detecting clamping to avoid repeatedly popping the scroll position down
1426 // as the page height increases 1430 // as the page height increases
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
2010 frameLoadRequest.clientRedirect()); 2014 frameLoadRequest.clientRedirect());
2011 2015
2012 loader->setLoadType(loadType); 2016 loader->setLoadType(loadType);
2013 loader->setNavigationType(navigationType); 2017 loader->setNavigationType(navigationType);
2014 loader->setReplacesCurrentHistoryItem(loadType == 2018 loader->setReplacesCurrentHistoryItem(loadType ==
2015 FrameLoadTypeReplaceCurrentItem); 2019 FrameLoadTypeReplaceCurrentItem);
2016 return loader; 2020 return loader;
2017 } 2021 }
2018 2022
2019 } // namespace blink 2023 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698