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

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: rebase 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 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 } 118 }
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 // FIXME: Make setSavedLayerScrollOffset take DoubleSize. crbug.com/4142 83.
128 if (node && node->isElementNode()) 129 if (node && node->isElementNode())
129 toElement(node)->setSavedLayerScrollOffset(m_scrollOffset); 130 toElement(node)->setSavedLayerScrollOffset(flooredIntSize(m_scrollOf fset));
130 } 131 }
131 132
132 if (LocalFrame* frame = box().frame()) { 133 if (LocalFrame* frame = box().frame()) {
133 if (FrameView* frameView = frame->view()) 134 if (FrameView* frameView = frame->view())
134 frameView->removeResizerArea(box()); 135 frameView->removeResizerArea(box());
135 } 136 }
136 137
137 destroyScrollbar(HorizontalScrollbar); 138 destroyScrollbar(HorizontalScrollbar);
138 destroyScrollbar(VerticalScrollbar); 139 destroyScrollbar(VerticalScrollbar);
139 140
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 } 338 }
338 339
339 int RenderLayerScrollableArea::scrollSize(ScrollbarOrientation orientation) cons t 340 int RenderLayerScrollableArea::scrollSize(ScrollbarOrientation orientation) cons t
340 { 341 {
341 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition() ; 342 IntSize scrollDimensions = maximumScrollPosition() - minimumScrollPosition() ;
342 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr ollDimensions.height(); 343 return (orientation == HorizontalScrollbar) ? scrollDimensions.width() : scr ollDimensions.height();
343 } 344 }
344 345
345 void RenderLayerScrollableArea::setScrollOffset(const IntPoint& newScrollOffset) 346 void RenderLayerScrollableArea::setScrollOffset(const IntPoint& newScrollOffset)
346 { 347 {
348 setScrollOffset(DoublePoint(newScrollOffset));
349 }
350
351 void RenderLayerScrollableArea::setScrollOffset(const DoublePoint& newScrollOffs et)
352 {
347 if (!box().isMarquee()) { 353 if (!box().isMarquee()) {
348 // Ensure that the dimensions will be computed if they need to be (for o verflow:hidden blocks). 354 // Ensure that the dimensions will be computed if they need to be (for o verflow:hidden blocks).
349 if (m_scrollDimensionsDirty) 355 if (m_scrollDimensionsDirty)
350 computeScrollDimensions(); 356 computeScrollDimensions();
351 } 357 }
352 358
353 if (scrollOffset() == toIntSize(newScrollOffset)) 359 if (scrollOffset() == toDoubleSize(newScrollOffset))
354 return; 360 return;
355 361
356 m_scrollOffset = toIntSize(newScrollOffset); 362 m_scrollOffset = toDoubleSize(newScrollOffset);
357 363
358 LocalFrame* frame = box().frame(); 364 LocalFrame* frame = box().frame();
359 ASSERT(frame); 365 ASSERT(frame);
360 366
361 RefPtr<FrameView> frameView = box().frameView(); 367 RefPtr<FrameView> frameView = box().frameView();
362 368
363 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("devtools.timeline"), "ScrollLayer", "data", InspectorScrollLayerEvent::data(&box())); 369 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. 370 // FIXME(361045): remove InspectorInstrumentation calls once DevTools Timeli ne migrates to tracing.
365 InspectorInstrumentation::willScrollLayer(&box()); 371 InspectorInstrumentation::willScrollLayer(&box());
366 372
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 box().node()->document().enqueueScrollEventForNode(box().node()); 416 box().node()->document().enqueueScrollEventForNode(box().node());
411 417
412 if (AXObjectCache* cache = box().document().existingAXObjectCache()) 418 if (AXObjectCache* cache = box().document().existingAXObjectCache())
413 cache->handleScrollPositionChanged(&box()); 419 cache->handleScrollPositionChanged(&box());
414 420
415 InspectorInstrumentation::didScrollLayer(&box()); 421 InspectorInstrumentation::didScrollLayer(&box());
416 } 422 }
417 423
418 IntPoint RenderLayerScrollableArea::scrollPosition() const 424 IntPoint RenderLayerScrollableArea::scrollPosition() const
419 { 425 {
420 return IntPoint(m_scrollOffset); 426 return IntPoint(flooredIntSize(m_scrollOffset));
427 }
428
429 DoublePoint RenderLayerScrollableArea::scrollPositionDouble() const
430 {
431 return DoublePoint(m_scrollOffset);
421 } 432 }
422 433
423 IntPoint RenderLayerScrollableArea::minimumScrollPosition() const 434 IntPoint RenderLayerScrollableArea::minimumScrollPosition() const
424 { 435 {
425 return -scrollOrigin(); 436 return -scrollOrigin();
426 } 437 }
427 438
428 IntPoint RenderLayerScrollableArea::maximumScrollPosition() const 439 IntPoint RenderLayerScrollableArea::maximumScrollPosition() const
429 { 440 {
430 if (!box().hasOverflowClip()) 441 if (!box().hasOverflowClip())
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 m_scrollDimensionsDirty = false; 566 m_scrollDimensionsDirty = false;
556 567
557 m_overflowRect = box().layoutOverflowRect(); 568 m_overflowRect = box().layoutOverflowRect();
558 box().flipForWritingMode(m_overflowRect); 569 box().flipForWritingMode(m_overflowRect);
559 570
560 int scrollableLeftOverflow = m_overflowRect.x() - box().borderLeft() - (box( ).style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? box().verticalScr ollbarWidth() : 0); 571 int scrollableLeftOverflow = m_overflowRect.x() - box().borderLeft() - (box( ).style()->shouldPlaceBlockDirectionScrollbarOnLogicalLeft() ? box().verticalScr ollbarWidth() : 0);
561 int scrollableTopOverflow = m_overflowRect.y() - box().borderTop(); 572 int scrollableTopOverflow = m_overflowRect.y() - box().borderTop();
562 setScrollOrigin(IntPoint(-scrollableLeftOverflow, -scrollableTopOverflow)); 573 setScrollOrigin(IntPoint(-scrollableLeftOverflow, -scrollableTopOverflow));
563 } 574 }
564 575
565 void RenderLayerScrollableArea::scrollToOffset(const IntSize& scrollOffset, Scro llOffsetClamping clamp) 576 void RenderLayerScrollableArea::scrollToOffset(const DoubleSize& scrollOffset, S crollOffsetClamping clamp)
566 { 577 {
567 IntSize newScrollOffset = clamp == ScrollOffsetClamped ? clampScrollOffset(s crollOffset) : scrollOffset; 578 DoubleSize newScrollOffset = clamp == ScrollOffsetClamped ? clampScrollOffse t(scrollOffset) : scrollOffset;
568 if (newScrollOffset != adjustedScrollOffset()) 579 if (newScrollOffset != adjustedScrollOffset()) {
569 scrollToOffsetWithoutAnimation(-scrollOrigin() + newScrollOffset); 580 DoublePoint origin(scrollOrigin());
581 // FIXME: Make scrollToOffsetWithoutAnimation take DoublePoint. crbug.co m/414283.
582 scrollToOffsetWithoutAnimation(toFloatPoint(-origin + newScrollOffset));
583 }
570 } 584 }
571 585
572 void RenderLayerScrollableArea::updateAfterLayout() 586 void RenderLayerScrollableArea::updateAfterLayout()
573 { 587 {
574 m_scrollDimensionsDirty = true; 588 m_scrollDimensionsDirty = true;
575 IntSize originalScrollOffset = adjustedScrollOffset(); 589 DoubleSize originalScrollOffset = adjustedScrollOffset();
576 590
577 computeScrollDimensions(); 591 computeScrollDimensions();
578 592
579 if (!box().isMarquee()) { 593 if (!box().isMarquee()) {
580 // Layout may cause us to be at an invalid scroll position. In this case we need 594 // 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). 595 // to pull our scroll offsets back to the max (or push them up to the mi n).
582 IntSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset()); 596 DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset( ));
583 if (clampedScrollOffset != adjustedScrollOffset()) 597 if (clampedScrollOffset != adjustedScrollOffset())
584 scrollToOffset(clampedScrollOffset); 598 scrollToOffset(clampedScrollOffset);
585 } 599 }
586 600
587 if (originalScrollOffset != adjustedScrollOffset()) 601 if (originalScrollOffset != adjustedScrollOffset()) {
588 scrollToOffsetWithoutAnimation(-scrollOrigin() + adjustedScrollOffset()) ; 602 DoublePoint origin(scrollOrigin());
603 scrollToOffsetWithoutAnimation(toFloatPoint(-origin + adjustedScrollOffs et()));
604 }
589 605
590 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 606 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
591 bool hasVerticalOverflow = this->hasVerticalOverflow(); 607 bool hasVerticalOverflow = this->hasVerticalOverflow();
592 608
593 { 609 {
594 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html. 610 // Hits in compositing/overflow/automatically-opt-into-composited-scroll ing-after-style-change.html.
595 DisableCompositingQueryAsserts disabler; 611 DisableCompositingQueryAsserts disabler;
596 612
597 // overflow:scroll should just enable/disable. 613 // overflow:scroll should just enable/disable.
598 if (box().style()->overflowX() == OSCROLL) 614 if (box().style()->overflowX() == OSCROLL)
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
773 } 789 }
774 790
775 bool hasHorizontalOverflow = this->hasHorizontalOverflow(); 791 bool hasHorizontalOverflow = this->hasHorizontalOverflow();
776 bool hasVerticalOverflow = this->hasVerticalOverflow(); 792 bool hasVerticalOverflow = this->hasVerticalOverflow();
777 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow); 793 bool autoHorizontalScrollBarChanged = box().hasAutoHorizontalScrollbar() && (hasHorizontalScrollbar() != hasHorizontalOverflow);
778 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow); 794 bool autoVerticalScrollBarChanged = box().hasAutoVerticalScrollbar() && (has VerticalScrollbar() != hasVerticalOverflow);
779 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged) 795 if (autoHorizontalScrollBarChanged || autoVerticalScrollBarChanged)
780 box().setNeedsLayoutAndFullPaintInvalidation(); 796 box().setNeedsLayoutAndFullPaintInvalidation();
781 } 797 }
782 798
783 IntSize RenderLayerScrollableArea::clampScrollOffset(const IntSize& scrollOffset ) const 799 DoubleSize RenderLayerScrollableArea::clampScrollOffset(const DoubleSize& scroll Offset) const
784 { 800 {
785 int maxX = scrollWidth() - box().pixelSnappedClientWidth(); 801 int maxX = scrollWidth() - box().pixelSnappedClientWidth();
786 int maxY = scrollHeight() - box().pixelSnappedClientHeight(); 802 int maxY = scrollHeight() - box().pixelSnappedClientHeight();
787 803
788 int x = std::max(std::min(scrollOffset.width(), maxX), 0); 804 double x = std::max(std::min(scrollOffset.width(), static_cast<double>(maxX) ), 0.0);
789 int y = std::max(std::min(scrollOffset.height(), maxY), 0); 805 double y = std::max(std::min(scrollOffset.height(), static_cast<double>(maxY )), 0.0);
790 return IntSize(x, y); 806 return DoubleSize(x, y);
791 } 807 }
792 808
793 IntRect RenderLayerScrollableArea::rectForHorizontalScrollbar(const IntRect& bor derBoxRect) const 809 IntRect RenderLayerScrollableArea::rectForHorizontalScrollbar(const IntRect& bor derBoxRect) const
794 { 810 {
795 if (!m_hBar) 811 if (!m_hBar)
796 return IntRect(); 812 return IntRect();
797 813
798 const IntRect& scrollCorner = scrollCornerRect(); 814 const IntRect& scrollCorner = scrollCornerRect();
799 815
800 return IntRect(horizontalScrollbarStart(borderBoxRect.x()), 816 return IntRect(horizontalScrollbarStart(borderBoxRect.x()),
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1383 1399
1384 // FIXME (Radar 4118564): We should also autoscroll the window as necessary to keep the point under the cursor in view. 1400 // FIXME (Radar 4118564): We should also autoscroll the window as necessary to keep the point under the cursor in view.
1385 } 1401 }
1386 1402
1387 LayoutRect RenderLayerScrollableArea::exposeRect(const LayoutRect& rect, const S crollAlignment& alignX, const ScrollAlignment& alignY) 1403 LayoutRect RenderLayerScrollableArea::exposeRect(const LayoutRect& rect, const S crollAlignment& alignX, const ScrollAlignment& alignY)
1388 { 1404 {
1389 LayoutRect localExposeRect(box().absoluteToLocalQuad(FloatQuad(FloatRect(rec t)), UseTransforms).boundingBox()); 1405 LayoutRect localExposeRect(box().absoluteToLocalQuad(FloatQuad(FloatRect(rec t)), UseTransforms).boundingBox());
1390 LayoutRect layerBounds(0, 0, box().clientWidth(), box().clientHeight()); 1406 LayoutRect layerBounds(0, 0, box().clientWidth(), box().clientHeight());
1391 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect , alignX, alignY); 1407 LayoutRect r = ScrollAlignment::getRectToExpose(layerBounds, localExposeRect , alignX, alignY);
1392 1408
1393 IntSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset() + toI ntSize(roundedIntRect(r).location())); 1409 DoubleSize clampedScrollOffset = clampScrollOffset(adjustedScrollOffset() + toIntSize(roundedIntRect(r).location()));
1394 if (clampedScrollOffset == adjustedScrollOffset()) 1410 if (clampedScrollOffset == adjustedScrollOffset())
1395 return rect; 1411 return rect;
1396 1412
1397 IntSize oldScrollOffset = adjustedScrollOffset(); 1413 DoubleSize oldScrollOffset = adjustedScrollOffset();
1398 scrollToOffset(clampedScrollOffset); 1414 scrollToOffset(clampedScrollOffset);
1399 IntSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset; 1415 DoubleSize scrollOffsetDifference = adjustedScrollOffset() - oldScrollOffset ;
1400 localExposeRect.move(-scrollOffsetDifference); 1416 localExposeRect.move(-LayoutSize(scrollOffsetDifference));
1401 return LayoutRect(box().localToAbsoluteQuad(FloatQuad(FloatRect(localExposeR ect)), UseTransforms).boundingBox()); 1417 return LayoutRect(box().localToAbsoluteQuad(FloatQuad(FloatRect(localExposeR ect)), UseTransforms).boundingBox());
1402 } 1418 }
1403 1419
1404 void RenderLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow) 1420 void RenderLayerScrollableArea::updateScrollableAreaSet(bool hasOverflow)
1405 { 1421 {
1406 LocalFrame* frame = box().frame(); 1422 LocalFrame* frame = box().frame();
1407 if (!frame) 1423 if (!frame)
1408 return; 1424 return;
1409 1425
1410 FrameView* frameView = frame->view(); 1426 FrameView* frameView = frame->view();
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1475 void RenderLayerScrollableArea::setTopmostScrollChild(RenderLayer* scrollChild) 1491 void RenderLayerScrollableArea::setTopmostScrollChild(RenderLayer* scrollChild)
1476 { 1492 {
1477 // We only want to track the topmost scroll child for scrollable areas with 1493 // We only want to track the topmost scroll child for scrollable areas with
1478 // overlay scrollbars. 1494 // overlay scrollbars.
1479 if (!hasOverlayScrollbars()) 1495 if (!hasOverlayScrollbars())
1480 return; 1496 return;
1481 m_nextTopmostScrollChild = scrollChild; 1497 m_nextTopmostScrollChild = scrollChild;
1482 } 1498 }
1483 1499
1484 } // namespace blink 1500 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderLayerScrollableArea.h ('k') | Source/core/rendering/compositing/CompositedLayerMapping.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698