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

Side by Side Diff: Source/core/rendering/RenderLayerScrollableArea.cpp

Issue 610423004: Preserve fractional scroll offset for JS scrolling API (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 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, 2012 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 Apple Inc. All rights reserved.
3 * 3 *
4 * Portions are Copyright (C) 1998 Netscape Communications Corporation. 4 * Portions are Copyright (C) 1998 Netscape Communications Corporation.
5 * 5 *
6 * Other contributors: 6 * Other contributors:
7 * Robert O'Callahan <roc+@cs.cmu.edu> 7 * Robert O'Callahan <roc+@cs.cmu.edu>
8 * David Baron <dbaron@fas.harvard.edu> 8 * David Baron <dbaron@fas.harvard.edu>
9 * Christian Biesinger <cbiesinger@web.de> 9 * Christian Biesinger <cbiesinger@web.de>
10 * Randall Jesup <rjesup@wgate.com> 10 * Randall Jesup <rjesup@wgate.com>
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 119 }
120 120
121 if (box().frame() && box().frame()->page()) { 121 if (box().frame() && box().frame()->page()) {
122 if (ScrollingCoordinator* scrollingCoordinator = box().frame()->page()-> scrollingCoordinator()) 122 if (ScrollingCoordinator* scrollingCoordinator = box().frame()->page()-> scrollingCoordinator())
123 scrollingCoordinator->willDestroyScrollableArea(this); 123 scrollingCoordinator->willDestroyScrollableArea(this);
124 } 124 }
125 125
126 if (!box().documentBeingDestroyed()) { 126 if (!box().documentBeingDestroyed()) {
127 Node* node = box().node(); 127 Node* node = box().node();
128 if (node && node->isElementNode()) 128 if (node && node->isElementNode())
129 toElement(node)->setSavedLayerScrollOffset(m_scrollOffset); 129 toElement(node)->setSavedLayerScrollOffset(flooredIntSize(m_scrollOf fset));
Rick Byers 2014/10/02 21:44:06 What's the implication of flooring here? Do we ne
Yufeng Shen (Slow to review) 2014/10/02 23:34:34 No documentation about what this scrolloffet save/
130 } 130 }
131 131
132 if (LocalFrame* frame = box().frame()) { 132 if (LocalFrame* frame = box().frame()) {
133 if (FrameView* frameView = frame->view()) 133 if (FrameView* frameView = frame->view())
134 frameView->removeResizerArea(box()); 134 frameView->removeResizerArea(box());
135 } 135 }
136 136
137 destroyScrollbar(HorizontalScrollbar); 137 destroyScrollbar(HorizontalScrollbar);
138 destroyScrollbar(VerticalScrollbar); 138 destroyScrollbar(VerticalScrollbar);
139 139
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 337 }
338 338
339 int RenderLayerScrollableArea::scrollSize(ScrollbarOrientation orientation) cons t 339 int RenderLayerScrollableArea::scrollSize(ScrollbarOrientation orientation) cons t
340 { 340 {
341 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition() ; 341 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition() ;
342 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr ollDimensions.height(); 342 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr ollDimensions.height();
343 } 343 }
344 344
345 void RenderLayerScrollableArea::setScrollOffset(const IntPoint& newScrollOffset) 345 void RenderLayerScrollableArea::setScrollOffset(const IntPoint& newScrollOffset)
346 { 346 {
347 setScrollOffset(DoublePoint(newScrollOffset));
348 }
349
350 void RenderLayerScrollableArea::setScrollOffset(const DoublePoint& newScrollOffs et)
Rick Byers 2014/10/02 21:44:06 Didn't you guys agree that you'd drive to move tow
Yufeng Shen (Slow to review) 2014/10/02 23:34:34 Ideally yes. Just that ScrollableArea::setScrollOf
Rick Byers 2014/10/03 16:42:46 Sounds good, thanks.
351 {
347 if (!box().isMarquee()) { 352 if (!box().isMarquee()) {
348 // Ensure that the dimensions will be computed if they need to be (for o verflow:hidden blocks). 353 // Ensure that the dimensions will be computed if they need to be (for o verflow:hidden blocks).
349 if (m_scrollDimensionsDirty) 354 if (m_scrollDimensionsDirty)
350 computeScrollDimensions(); 355 computeScrollDimensions();
351 } 356 }
352 357
353 if (scrollOffset() == toIntSize(newScrollOffset)) 358 if (scrollOffset() == toDoubleSize(newScrollOffset))
354 return; 359 return;
355 360
356 m_scrollOffset = toIntSize(newScrollOffset); 361 m_scrollOffset = toDoubleSize(newScrollOffset);
357 362
358 LocalFrame* frame = box().frame(); 363 LocalFrame* frame = box().frame();
359 ASSERT(frame); 364 ASSERT(frame);
360 365
361 RefPtr<FrameView> frameView = box().frameView(); 366 RefPtr<FrameView> frameView = box().frameView();
362 367
363 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ScrollLayer", "data", InspectorScrollLayerEvent::data(&box())); 368 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ScrollLayer", "data", InspectorScrollLayerEvent::data(&box()));
364 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing. 369 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing.
365 InspectorInstrumentation::willScrollLayer(&box()); 370 InspectorInstrumentation::willScrollLayer(&box());
366 371
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 box().node()->document().enqueueScrollEventForNode(box().node()); 415 box().node()->document().enqueueScrollEventForNode(box().node());
411 416
412 if (AXObjectCache* cache = box().document().existingAXObjectCache()) 417 if (AXObjectCache* cache = box().document().existingAXObjectCache())
413 cache->handleScrollPositionChanged(&box()); 418 cache->handleScrollPositionChanged(&box());
414 419
415 InspectorInstrumentation::didScrollLayer(&box()); 420 InspectorInstrumentation::didScrollLayer(&box());
416 } 421 }
417 422
418 IntPoint RenderLayerScrollableArea::scrollPosition() const 423 IntPoint RenderLayerScrollableArea::scrollPosition() const
419 { 424 {
420 return IntPoint(m_scrollOffset); 425 return IntPoint(flooredIntSize(m_scrollOffset));
426 }
427
428 DoublePoint RenderLayerScrollableArea::scrollPositionDouble() const
429 {
430 return DoublePoint(m_scrollOffset);
421 } 431 }
422 432
423 IntPoint RenderLayerScrollableArea::minimumScrollPosition() const 433 IntPoint RenderLayerScrollableArea::minimumScrollPosition() const
424 { 434 {
425 return -scrollOrigin(); 435 return -scrollOrigin();
426 } 436 }
427 437
428 IntPoint RenderLayerScrollableArea::maximumScrollPosition() const 438 IntPoint RenderLayerScrollableArea::maximumScrollPosition() const
429 { 439 {
430 if (!box().hasOverflowClip()) 440 if (!box().hasOverflowClip())
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 m_scrollDimensionsDirty = false; 565 m_scrollDimensionsDirty = false;
556 566
557 m_overflowRect = box().layoutOverflowRect(); 567 m_overflowRect = box().layoutOverflowRect();
558 box().flipForWritingMode(m_overflowRect); 568 box().flipForWritingMode(m_overflowRect);
559 569
560 int scrollableLeftOverflow = m_overflowRect.x() - box().borderLeft() - (box( ).style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? box().verticalScr ollbarWidth() : 0); 570 int scrollableLeftOverflow = m_overflowRect.x() - box().borderLeft() - (box( ).style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? box().verticalScr ollbarWidth() : 0);
561 int scrollableTopOverflow = m_overflowRect.y() - box().borderTop(); 571 int scrollableTopOverflow = m_overflowRect.y() - box().borderTop();
562 setScrollOrigin(IntPoint(-scrollableLeftOverflow, -scrollableTopOverflow)); 572 setScrollOrigin(IntPoint(-scrollableLeftOverflow, -scrollableTopOverflow));
563 } 573 }
564 574
565 void RenderLayerScrollableArea::scrollToOffset(const IntSize& scrollOffset, Scro llOffsetClamping clamp) 575 void RenderLayerScrollableArea::scrollToOffset(const DoubleSize& scrollOffset, S crollOffsetClamping clamp)
566 { 576 {
567 IntSize newScrollOffset = clamp == ScrollOffsetClamped ? clampScrollOffset(s crollOffset) : scrollOffset; 577 DoubleSize newScrollOffset = clamp == ScrollOffsetClamped ? clampScrollOffse t(scrollOffset) : scrollOffset;
568 if (newScrollOffset != adjustedScrollOffset()) 578 if (newScrollOffset != adjustedScrollOffset()) {
569 scrollToOffsetWithoutAnimation(-scrollOrigin() + newScrollOffset); 579 DoublePoint origin(scrollOrigin());
580 scrollToOffsetWithoutAnimation(toFloatPoint(-origin + newScrollOffset));
Rick Byers 2014/10/02 21:44:06 scrollToOffsetWithoutAnimation should be updated (
Yufeng Shen (Slow to review) 2014/10/02 23:34:34 FIXME added.
581 }
570 } 582 }
571 583
572 void RenderLayerScrollableArea::updateAfterLayout() 584 void RenderLayerScrollableArea::updateAfterLayout()
573 { 585 {
574 m_scrollDimensionsDirty = true; 586 m_scrollDimensionsDirty = true;
575 IntSize originalScrollOffset = adjustedScrollOffset(); 587 DoubleSize originalScrollOffset = adjustedScrollOffset();
576 588
577 computeScrollDimensions(); 589 computeScrollDimensions();
578 590
579 if (!box().isMarquee()) { 591 if (!box().isMarquee()) {
580 // Layout may cause us to be at an invalid scroll position. In this case we need 592 // Layout may cause us to be at an invalid scroll position. In this case we need
581 // to pull our scroll offsets back to the max (or push them up to the mi n). 593 // to pull our scroll offsets back to the max (or push them up to the mi n).
582 IntSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset()); 594 DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset( ));
583 if (clampedScrollOffset != adjustedScrollOffset()) 595 if (clampedScrollOffset != adjustedScrollOffset())
584 scrollToOffset(clampedScrollOffset); 596 scrollToOffset(clampedScrollOffset);
585 } 597 }
586 598
587 if (originalScrollOffset != adjustedScrollOffset()) 599 if (originalScrollOffset != adjustedScrollOffset()) {
588 scrollToOffsetWithoutAnimation(-scrollOrigin() + adjustedScrollOffset()) ; 600 DoublePoint origin(scrollOrigin());
601 scrollToOffsetWithoutAnimation(toFloatPoint(-origin + adjustedScrollOffs et()));
602 }
589 603
590 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 604 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
591 bool hasVerticalOverflow = this->hasVerticalOverflow(); 605 bool hasVerticalOverflow = this->hasVerticalOverflow();
592 606
593 { 607 {
594 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html. 608 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html.
595 DisableCompositingQueryAsserts disabler; 609 DisableCompositingQueryAsserts disabler;
596 610
597 // overflow:scroll should just enable/disable. 611 // overflow:scroll should just enable/disable.
598 if (box().style()->overflowX() == OSCROLL) 612 if (box().style()->overflowX() == OSCROLL)
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 } 782 }
769 783
770 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 784 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
771 bool hasVerticalOverflow = this->hasVerticalOverflow(); 785 bool hasVerticalOverflow = this->hasVerticalOverflow();
772 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow); 786 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
773 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow); 787 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow);
774 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged) 788 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged)
775 box().setNeedsLayoutAndFullPaintInvalidation(); 789 box().setNeedsLayoutAndFullPaintInvalidation();
776 } 790 }
777 791
778 IntSize RenderLayerScrollableArea::clampScrollOffset(const IntSize& scrollOffset ) const 792 DoubleSize RenderLayerScrollableArea::clampScrollOffset(const DoubleSize& scroll Offset) const
779 { 793 {
780 int maxX = scrollWidth() - box().pixelSnappedClientWidth(); 794 int maxX = scrollWidth() - box().pixelSnappedClientWidth();
781 int maxY = scrollHeight() - box().pixelSnappedClientHeight(); 795 int maxY = scrollHeight() - box().pixelSnappedClientHeight();
782 796
783 int x = std::max(std::min(scrollOffset.width(), maxX), 0); 797 double x = std::max(std::min(scrollOffset.width(), static_cast<double>(maxX) ), 0.0);
784 int y = std::max(std::min(scrollOffset.height(), maxY), 0); 798 double y = std::max(std::min(scrollOffset.height(), static_cast<double>(maxY )), 0.0);
785 return IntSize(x, y); 799 return DoubleSize(x, y);
786 } 800 }
787 801
788 IntRect RenderLayerScrollableArea::rectForHorizontalScrollbar(const IntRect& bor derBoxRect) const 802 IntRect RenderLayerScrollableArea::rectForHorizontalScrollbar(const IntRect& bor derBoxRect) const
789 { 803 {
790 if (!m_hBar) 804 if (!m_hBar)
791 return IntRect(); 805 return IntRect();
792 806
793 const IntRect& scrollCorner = scrollCornerRect(); 807 const IntRect& scrollCorner = scrollCornerRect();
794 808
795 return IntRect(horizontalScrollbarStart(borderBoxRect.x()), 809 return IntRect(horizontalScrollbarStart(borderBoxRect.x()),
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1378 1392
1379 // FIXME (Radar 4118564): We should also autoscroll the window as necessary to keep the point under the cursor in view. 1393 // FIXME (Radar 4118564): We should also autoscroll the window as necessary to keep the point under the cursor in view.
1380 } 1394 }
1381 1395
1382 LayoutRect RenderLayerScrollableArea::exposeRect(const LayoutRect& rect, const S crollAlignment& alignX, const ScrollAlignment& alignY) 1396 LayoutRect RenderLayerScrollableArea::exposeRect(const LayoutRect& rect, const S crollAlignment& alignX, const ScrollAlignment& alignY)
1383 { 1397 {
1384 LayoutRect localExposeRect(box().absoluteToLocalQuad(FloatQuad(FloatRect(rec t)), UseTransforms).boundingBox()); 1398 LayoutRect localExposeRect(box().absoluteToLocalQuad(FloatQuad(FloatRect(rec t)), UseTransforms).boundingBox());
1385 LayoutRect layerBounds(0, 0, box().clientWidth(), box().clientHeight()); 1399 LayoutRect layerBounds(0, 0, box().clientWidth(), box().clientHeight());
1386 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect , alignX, alignY); 1400 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect , alignX, alignY);
1387 1401
1388 IntSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset() + toI ntSize(roundedIntRect(r).location())); 1402 DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset() + toIntSize(roundedIntRect(r).location()));
1389 if (clampedScrollOffset == adjustedScrollOffset()) 1403 if (clampedScrollOffset == adjustedScrollOffset())
1390 return rect; 1404 return rect;
1391 1405
1392 IntSize oldScrollOffset = adjustedScrollOffset(); 1406 DoubleSize oldScrollOffset = adjustedScrollOffset();
1393 scrollToOffset(clampedScrollOffset); 1407 scrollToOffset(clampedScrollOffset);
1394 IntSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset; 1408 DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset ;
1395 localExposeRect.move(-scrollOffsetDifference); 1409 localExposeRect.move(-LayoutSize(scrollOffsetDifference));
1396 return LayoutRect(box().localToAbsoluteQuad(FloatQuad(FloatRect(localExposeR ect)), UseTransforms).boundingBox()); 1410 return LayoutRect(box().localToAbsoluteQuad(FloatQuad(FloatRect(localExposeR ect)), UseTransforms).boundingBox());
1397 } 1411 }
1398 1412
1399 void RenderLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow) 1413 void RenderLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow)
1400 { 1414 {
1401 LocalFrame* frame = box().frame(); 1415 LocalFrame* frame = box().frame();
1402 if (!frame) 1416 if (!frame)
1403 return; 1417 return;
1404 1418
1405 FrameView* frameView = frame->view(); 1419 FrameView* frameView = frame->view();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 void RenderLayerScrollableArea::setTopmostScrollChild(RenderLayer* scrollChild) 1484 void RenderLayerScrollableArea::setTopmostScrollChild(RenderLayer* scrollChild)
1471 { 1485 {
1472 // We only want to track the topmost scroll child for scrollable areas with 1486 // We only want to track the topmost scroll child for scrollable areas with
1473 // overlay scrollbars. 1487 // overlay scrollbars.
1474 if (!hasOverlayScrollbars()) 1488 if (!hasOverlayScrollbars())
1475 return; 1489 return;
1476 m_nextTopmostScrollChild = scrollChild; 1490 m_nextTopmostScrollChild = scrollChild;
1477 } 1491 }
1478 1492
1479 } // namespace blink 1493 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698