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

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

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: Fix README.md Created 4 years, 2 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 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (!m_currentItem || !m_frame->view()) 268 if (!m_currentItem || !m_frame->view())
269 return; 269 return;
270 270
271 // Shouldn't clobber anything if we might still restore later. 271 // Shouldn't clobber anything if we might still restore later.
272 if (needsHistoryItemRestore(m_loadType) && m_documentLoader && 272 if (needsHistoryItemRestore(m_loadType) && m_documentLoader &&
273 !m_documentLoader->initialScrollState().wasScrolledByUser) 273 !m_documentLoader->initialScrollState().wasScrolledByUser)
274 return; 274 return;
275 275
276 if (ScrollableArea* layoutScrollableArea = 276 if (ScrollableArea* layoutScrollableArea =
277 m_frame->view()->layoutViewportScrollableArea()) 277 m_frame->view()->layoutViewportScrollableArea())
278 m_currentItem->setScrollPoint(layoutScrollableArea->scrollPosition()); 278 m_currentItem->setScrollOffset(layoutScrollableArea->scrollOffset());
279 m_currentItem->setVisualViewportScrollPoint( 279 m_currentItem->setVisualViewportScrollOffset(toScrollOffset(
280 m_frame->host()->visualViewport().visibleRect().location()); 280 m_frame->host()->visualViewport().visibleRect().location()));
281 281
282 if (m_frame->isMainFrame()) 282 if (m_frame->isMainFrame())
283 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); 283 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor());
284 284
285 client()->didUpdateCurrentHistoryItem(); 285 client()->didUpdateCurrentHistoryItem();
286 } 286 }
287 287
288 void FrameLoader::dispatchUnloadEvent() { 288 void FrameLoader::dispatchUnloadEvent() {
289 NavigationDisablerForUnload navigationDisabler; 289 NavigationDisablerForUnload navigationDisabler;
290 290
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 return; 418 return;
419 // Don't propagate state from the old item if this is a different-document 419 // Don't propagate state from the old item if this is a different-document
420 // navigation, unless the before and after pages are logically related. This 420 // navigation, unless the before and after pages are logically related. This
421 // means they have the same url (ignoring fragment) and the new item was 421 // means they have the same url (ignoring fragment) and the new item was
422 // loaded via reload or client redirect. 422 // loaded via reload or client redirect.
423 if (navigationType == HistoryNavigationType::DifferentDocument && 423 if (navigationType == HistoryNavigationType::DifferentDocument &&
424 (historyCommitType != HistoryInertCommit || 424 (historyCommitType != HistoryInertCommit ||
425 !equalIgnoringFragmentIdentifier(oldItem->url(), m_currentItem->url()))) 425 !equalIgnoringFragmentIdentifier(oldItem->url(), m_currentItem->url())))
426 return; 426 return;
427 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber()); 427 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber());
428 m_currentItem->setScrollPoint(oldItem->scrollPoint()); 428 m_currentItem->setScrollOffset(oldItem->scrollOffset());
429 m_currentItem->setVisualViewportScrollPoint( 429 m_currentItem->setVisualViewportScrollOffset(
430 oldItem->visualViewportScrollPoint()); 430 oldItem->visualViewportScrollOffset());
431 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor()); 431 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor());
432 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType()); 432 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType());
433 433
434 // The item sequence number determines whether items are "the same", such 434 // The item sequence number determines whether items are "the same", such
435 // back/forward navigation between items with the same item sequence number is 435 // back/forward navigation between items with the same item sequence number is
436 // a no-op. Only treat this as identical if the navigation did not create a 436 // a no-op. Only treat this as identical if the navigation did not create a
437 // back/forward entry and the url is identical or it was loaded via 437 // back/forward entry and the url is identical or it was loaded via
438 // history.replaceState(). 438 // history.replaceState().
439 if (historyCommitType == HistoryInertCommit && 439 if (historyCommitType == HistoryInertCommit &&
440 (navigationType == HistoryNavigationType::HistoryApi || 440 (navigationType == HistoryNavigationType::HistoryApi ||
(...skipping 891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1332 1332
1333 // This tries to balance: 1333 // This tries to balance:
1334 // 1. restoring as soon as possible 1334 // 1. restoring as soon as possible
1335 // 2. not overriding user scroll (TODO(majidvp): also respect user scale) 1335 // 2. not overriding user scroll (TODO(majidvp): also respect user scale)
1336 // 3. detecting clamping to avoid repeatedly popping the scroll position down 1336 // 3. detecting clamping to avoid repeatedly popping the scroll position down
1337 // as the page height increases 1337 // as the page height increases
1338 // 4. ignore clamp detection if we are not restoring scroll or after load 1338 // 4. ignore clamp detection if we are not restoring scroll or after load
1339 // completes because that may be because the page will never reach its 1339 // completes because that may be because the page will never reach its
1340 // previous height 1340 // previous height
1341 bool canRestoreWithoutClamping = 1341 bool canRestoreWithoutClamping =
1342 view->layoutViewportScrollableArea()->clampScrollPosition( 1342 view->layoutViewportScrollableArea()->clampScrollOffset(
1343 m_currentItem->scrollPoint()) == m_currentItem->scrollPoint(); 1343 m_currentItem->scrollOffset()) == m_currentItem->scrollOffset();
1344 bool canRestoreWithoutAnnoyingUser = 1344 bool canRestoreWithoutAnnoyingUser =
1345 !documentLoader()->initialScrollState().wasScrolledByUser && 1345 !documentLoader()->initialScrollState().wasScrolledByUser &&
1346 (canRestoreWithoutClamping || !m_frame->isLoading() || 1346 (canRestoreWithoutClamping || !m_frame->isLoading() ||
1347 !shouldRestoreScroll); 1347 !shouldRestoreScroll);
1348 if (!canRestoreWithoutAnnoyingUser) 1348 if (!canRestoreWithoutAnnoyingUser)
1349 return; 1349 return;
1350 1350
1351 if (shouldRestoreScroll) 1351 if (shouldRestoreScroll) {
1352 view->layoutViewportScrollableArea()->setScrollPosition( 1352 view->layoutViewportScrollableArea()->setScrollOffset(
1353 m_currentItem->scrollPoint(), ProgrammaticScroll); 1353 m_currentItem->scrollOffset(), ProgrammaticScroll);
1354 }
1354 1355
1355 // For main frame restore scale and visual viewport position 1356 // For main frame restore scale and visual viewport position
1356 if (m_frame->isMainFrame()) { 1357 if (m_frame->isMainFrame()) {
1357 FloatPoint visualViewportOffset(m_currentItem->visualViewportScrollPoint()); 1358 ScrollOffset visualViewportOffset(
1359 m_currentItem->visualViewportScrollOffset());
1358 1360
1359 // If the visual viewport's offset is (-1, -1) it means the history item is 1361 // If the visual viewport's offset is (-1, -1) it means the history item
1360 // an old version of HistoryItem so distribute the scroll between the main 1362 // is an old version of HistoryItem so distribute the scroll between
1361 // frame and the visual viewport as best as we can. 1363 // the main frame and the visual viewport as best as we can.
1362 if (visualViewportOffset.x() == -1 && visualViewportOffset.y() == -1) 1364 if (visualViewportOffset.width() == -1 &&
1365 visualViewportOffset.height() == -1) {
1363 visualViewportOffset = 1366 visualViewportOffset =
1364 FloatPoint(m_currentItem->scrollPoint() - view->scrollPosition()); 1367 m_currentItem->scrollOffset() - view->scrollOffset();
1368 }
1365 1369
1366 VisualViewport& visualViewport = m_frame->host()->visualViewport(); 1370 VisualViewport& visualViewport = m_frame->host()->visualViewport();
1367 if (shouldRestoreScale && shouldRestoreScroll) 1371 if (shouldRestoreScale && shouldRestoreScroll) {
1368 visualViewport.setScaleAndLocation(m_currentItem->pageScaleFactor(), 1372 visualViewport.setScaleAndLocation(m_currentItem->pageScaleFactor(),
1369 visualViewportOffset); 1373 FloatPoint(visualViewportOffset));
1370 else if (shouldRestoreScale) 1374 } else if (shouldRestoreScale) {
1371 visualViewport.setScale(m_currentItem->pageScaleFactor()); 1375 visualViewport.setScale(m_currentItem->pageScaleFactor());
1372 else if (shouldRestoreScroll) 1376 } else if (shouldRestoreScroll) {
1373 visualViewport.setLocation(visualViewportOffset); 1377 visualViewport.setLocation(FloatPoint(visualViewportOffset));
1378 }
1374 1379
1375 if (ScrollingCoordinator* scrollingCoordinator = 1380 if (ScrollingCoordinator* scrollingCoordinator =
1376 m_frame->page()->scrollingCoordinator()) 1381 m_frame->page()->scrollingCoordinator())
1377 scrollingCoordinator->frameViewRootLayerDidChange(view); 1382 scrollingCoordinator->frameViewRootLayerDidChange(view);
1378 } 1383 }
1379 1384
1380 documentLoader()->initialScrollState().didRestoreFromHistory = true; 1385 documentLoader()->initialScrollState().didRestoreFromHistory = true;
1381 } 1386 }
1382 1387
1383 String FrameLoader::userAgent() const { 1388 String FrameLoader::userAgent() const {
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
1883 m_documentLoader ? m_documentLoader->url() : String()); 1888 m_documentLoader ? m_documentLoader->url() : String());
1884 return tracedValue; 1889 return tracedValue;
1885 } 1890 }
1886 1891
1887 inline void FrameLoader::takeObjectSnapshot() const { 1892 inline void FrameLoader::takeObjectSnapshot() const {
1888 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this, 1893 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this,
1889 toTracedValue()); 1894 toTracedValue());
1890 } 1895 }
1891 1896
1892 } // namespace blink 1897 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/doc/rtl-tb-scroll.png ('k') | third_party/WebKit/Source/core/loader/HistoryItem.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698