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

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

Issue 2387883002: Use float for scroll offset. (Closed)
Patch Set: 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 reserv ed. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 4 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com>
6 * Copyright (C) Research In Motion Limited 2009. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2009. All rights reserved.
7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com> 7 * Copyright (C) 2011 Kris Jordan <krisjordan@gmail.com>
8 * Copyright (C) 2011 Google Inc. All rights reserved. 8 * Copyright (C) 2011 Google Inc. All rights reserved.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 if (!m_currentItem || !m_frame->view()) 265 if (!m_currentItem || !m_frame->view())
266 return; 266 return;
267 267
268 // Shouldn't clobber anything if we might still restore later. 268 // Shouldn't clobber anything if we might still restore later.
269 if (needsHistoryItemRestore(m_loadType) && m_documentLoader && 269 if (needsHistoryItemRestore(m_loadType) && m_documentLoader &&
270 !m_documentLoader->initialScrollState().wasScrolledByUser) 270 !m_documentLoader->initialScrollState().wasScrolledByUser)
271 return; 271 return;
272 272
273 if (ScrollableArea* layoutScrollableArea = 273 if (ScrollableArea* layoutScrollableArea =
274 m_frame->view()->layoutViewportScrollableArea()) 274 m_frame->view()->layoutViewportScrollableArea())
275 m_currentItem->setScrollPoint(layoutScrollableArea->scrollPosition()); 275 m_currentItem->setScrollOffset(layoutScrollableArea->scrollOffset());
276 m_currentItem->setVisualViewportScrollPoint( 276 m_currentItem->setVisualViewportScrollOffset(toScrollOffset(
277 m_frame->host()->visualViewport().visibleRect().location()); 277 m_frame->host()->visualViewport().visibleRect().location()));
278 278
279 if (m_frame->isMainFrame()) 279 if (m_frame->isMainFrame())
280 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor()); 280 m_currentItem->setPageScaleFactor(m_frame->page()->pageScaleFactor());
281 281
282 client()->didUpdateCurrentHistoryItem(); 282 client()->didUpdateCurrentHistoryItem();
283 } 283 }
284 284
285 void FrameLoader::dispatchUnloadEvent() { 285 void FrameLoader::dispatchUnloadEvent() {
286 NavigationDisablerForUnload navigationDisabler; 286 NavigationDisablerForUnload navigationDisabler;
287 287
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 if (!oldItem || isBackForwardLoadType(loadType)) 413 if (!oldItem || isBackForwardLoadType(loadType))
414 return; 414 return;
415 // Don't propagate state from the old item if this is a different-document nav igation, unless the before 415 // Don't propagate state from the old item if this is a different-document nav igation, unless the before
416 // and after pages are logically related. This means they have the same url (i gnoring fragment) and 416 // and after pages are logically related. This means they have the same url (i gnoring fragment) and
417 // the new item was loaded via reload or client redirect. 417 // the new item was loaded via reload or client redirect.
418 if (navigationType == HistoryNavigationType::DifferentDocument && 418 if (navigationType == HistoryNavigationType::DifferentDocument &&
419 (historyCommitType != HistoryInertCommit || 419 (historyCommitType != HistoryInertCommit ||
420 !equalIgnoringFragmentIdentifier(oldItem->url(), m_currentItem->url()))) 420 !equalIgnoringFragmentIdentifier(oldItem->url(), m_currentItem->url())))
421 return; 421 return;
422 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber()); 422 m_currentItem->setDocumentSequenceNumber(oldItem->documentSequenceNumber());
423 m_currentItem->setScrollPoint(oldItem->scrollPoint()); 423 m_currentItem->setScrollOffset(oldItem->scrollOffset());
424 m_currentItem->setVisualViewportScrollPoint( 424 m_currentItem->setVisualViewportScrollOffset(
425 oldItem->visualViewportScrollPoint()); 425 oldItem->visualViewportScrollOffset());
426 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor()); 426 m_currentItem->setPageScaleFactor(oldItem->pageScaleFactor());
427 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType()); 427 m_currentItem->setScrollRestorationType(oldItem->scrollRestorationType());
428 428
429 // The item sequence number determines whether items are "the same", such back /forward navigation 429 // The item sequence number determines whether items are "the same", such back /forward navigation
430 // between items with the same item sequence number is a no-op. Only treat thi s as identical if the 430 // between items with the same item sequence number is a no-op. Only treat thi s as identical if the
431 // navigation did not create a back/forward entry and the url is identical or it was loaded via 431 // navigation did not create a back/forward entry and the url is identical or it was loaded via
432 // history.replaceState(). 432 // history.replaceState().
433 if (historyCommitType == HistoryInertCommit && 433 if (historyCommitType == HistoryInertCommit &&
434 (navigationType == HistoryNavigationType::HistoryApi || 434 (navigationType == HistoryNavigationType::HistoryApi ||
435 oldItem->url() == m_currentItem->url())) { 435 oldItem->url() == m_currentItem->url())) {
(...skipping 880 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 1316
1317 // This tries to balance: 1317 // This tries to balance:
1318 // 1. restoring as soon as possible 1318 // 1. restoring as soon as possible
1319 // 2. not overriding user scroll (TODO(majidvp): also respect user scale) 1319 // 2. not overriding user scroll (TODO(majidvp): also respect user scale)
1320 // 3. detecting clamping to avoid repeatedly popping the scroll position 1320 // 3. detecting clamping to avoid repeatedly popping the scroll position
1321 // down as the page height increases 1321 // down as the page height increases
1322 // 4. ignore clamp detection if we are not restoring scroll or after load 1322 // 4. ignore clamp detection if we are not restoring scroll or after load
1323 // completes because that may be because the page will never reach its 1323 // completes because that may be because the page will never reach its
1324 // previous height 1324 // previous height
1325 bool canRestoreWithoutClamping = 1325 bool canRestoreWithoutClamping =
1326 view->layoutViewportScrollableArea()->clampScrollPosition( 1326 view->layoutViewportScrollableArea()->clampScrollOffset(
1327 m_currentItem->scrollPoint()) == m_currentItem->scrollPoint(); 1327 m_currentItem->scrollOffset()) == m_currentItem->scrollOffset();
1328 bool canRestoreWithoutAnnoyingUser = 1328 bool canRestoreWithoutAnnoyingUser =
1329 !documentLoader()->initialScrollState().wasScrolledByUser && 1329 !documentLoader()->initialScrollState().wasScrolledByUser &&
1330 (canRestoreWithoutClamping || !m_frame->isLoading() || 1330 (canRestoreWithoutClamping || !m_frame->isLoading() ||
1331 !shouldRestoreScroll); 1331 !shouldRestoreScroll);
1332 if (!canRestoreWithoutAnnoyingUser) 1332 if (!canRestoreWithoutAnnoyingUser)
1333 return; 1333 return;
1334 1334
1335 if (shouldRestoreScroll) 1335 if (shouldRestoreScroll) {
1336 view->layoutViewportScrollableArea()->setScrollPosition( 1336 view->layoutViewportScrollableArea()->setScrollOffset(
1337 m_currentItem->scrollPoint(), ProgrammaticScroll); 1337 m_currentItem->scrollOffset(), ProgrammaticScroll);
1338 }
1338 1339
1339 // For main frame restore scale and visual viewport position 1340 // For main frame restore scale and visual viewport position
1340 if (m_frame->isMainFrame()) { 1341 if (m_frame->isMainFrame()) {
1341 FloatPoint visualViewportOffset(m_currentItem->visualViewportScrollPoint()); 1342 ScrollOffset visualViewportOffset(
1343 m_currentItem->visualViewportScrollOffset());
1342 1344
1343 // If the visual viewport's offset is (-1, -1) it means the history item 1345 // If the visual viewport's offset is (-1, -1) it means the history item
1344 // is an old version of HistoryItem so distribute the scroll between 1346 // is an old version of HistoryItem so distribute the scroll between
1345 // the main frame and the visual viewport as best as we can. 1347 // the main frame and the visual viewport as best as we can.
1346 if (visualViewportOffset.x() == -1 && visualViewportOffset.y() == -1) 1348 if (visualViewportOffset.width() == -1 &&
1349 visualViewportOffset.height() == -1) {
1347 visualViewportOffset = 1350 visualViewportOffset =
1348 FloatPoint(m_currentItem->scrollPoint() - view->scrollPosition()); 1351 m_currentItem->scrollOffset() - view->scrollOffset();
1352 }
1349 1353
1350 VisualViewport& visualViewport = m_frame->host()->visualViewport(); 1354 VisualViewport& visualViewport = m_frame->host()->visualViewport();
1351 if (shouldRestoreScale && shouldRestoreScroll) 1355 if (shouldRestoreScale && shouldRestoreScroll) {
1352 visualViewport.setScaleAndLocation(m_currentItem->pageScaleFactor(), 1356 visualViewport.setScaleAndLocation(m_currentItem->pageScaleFactor(),
1353 visualViewportOffset); 1357 FloatPoint(visualViewportOffset));
1354 else if (shouldRestoreScale) 1358 } else if (shouldRestoreScale) {
1355 visualViewport.setScale(m_currentItem->pageScaleFactor()); 1359 visualViewport.setScale(m_currentItem->pageScaleFactor());
1356 else if (shouldRestoreScroll) 1360 } else if (shouldRestoreScroll) {
1357 visualViewport.setLocation(visualViewportOffset); 1361 visualViewport.setLocation(FloatPoint(visualViewportOffset));
1362 }
1358 1363
1359 if (ScrollingCoordinator* scrollingCoordinator = 1364 if (ScrollingCoordinator* scrollingCoordinator =
1360 m_frame->page()->scrollingCoordinator()) 1365 m_frame->page()->scrollingCoordinator())
1361 scrollingCoordinator->frameViewRootLayerDidChange(view); 1366 scrollingCoordinator->frameViewRootLayerDidChange(view);
1362 } 1367 }
1363 1368
1364 documentLoader()->initialScrollState().didRestoreFromHistory = true; 1369 documentLoader()->initialScrollState().didRestoreFromHistory = true;
1365 } 1370 }
1366 1371
1367 String FrameLoader::userAgent() const { 1372 String FrameLoader::userAgent() const {
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
1860 m_documentLoader ? m_documentLoader->url() : String()); 1865 m_documentLoader ? m_documentLoader->url() : String());
1861 return tracedValue; 1866 return tracedValue;
1862 } 1867 }
1863 1868
1864 inline void FrameLoader::takeObjectSnapshot() const { 1869 inline void FrameLoader::takeObjectSnapshot() const {
1865 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this, 1870 TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID("loading", "FrameLoader", this,
1866 toTracedValue()); 1871 toTracedValue());
1867 } 1872 }
1868 1873
1869 } // namespace blink 1874 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698