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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutBox.cpp

Issue 2650343008: Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Revised according to the comments. We are still missing tests. 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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com)
6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. 6 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc.
7 * All rights reserved. 7 * All rights reserved.
8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. 8 * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved.
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
623 frameElementBase->scrollingMode() == ScrollbarAlwaysOff; 623 frameElementBase->scrollingMode() == ScrollbarAlwaysOff;
624 } 624 }
625 } 625 }
626 return false; 626 return false;
627 } 627 }
628 628
629 void LayoutBox::scrollRectToVisible(const LayoutRect& rect, 629 void LayoutBox::scrollRectToVisible(const LayoutRect& rect,
630 const ScrollAlignment& alignX, 630 const ScrollAlignment& alignX,
631 const ScrollAlignment& alignY, 631 const ScrollAlignment& alignY,
632 ScrollType scrollType, 632 ScrollType scrollType,
633 bool makeVisibleInVisualViewport) { 633 bool makeVisibleInVisualViewport,
634 ScrollBehavior scrollBehavior) {
634 ASSERT(scrollType == ProgrammaticScroll || scrollType == UserScroll); 635 ASSERT(scrollType == ProgrammaticScroll || scrollType == UserScroll);
635 // Presumably the same issue as in setScrollTop. See crbug.com/343132. 636 // Presumably the same issue as in setScrollTop. See crbug.com/343132.
636 DisableCompositingQueryAsserts disabler; 637 DisableCompositingQueryAsserts disabler;
637 638
638 LayoutRect rectToScroll = rect; 639 LayoutRect rectToScroll = rect;
639 if (rectToScroll.width() <= 0) 640 if (rectToScroll.width() <= 0)
640 rectToScroll.setWidth(LayoutUnit(1)); 641 rectToScroll.setWidth(LayoutUnit(1));
641 if (rectToScroll.height() <= 0) 642 if (rectToScroll.height() <= 0)
642 rectToScroll.setHeight(LayoutUnit(1)); 643 rectToScroll.setHeight(LayoutUnit(1));
643 644
644 LayoutBox* parentBox = nullptr; 645 LayoutBox* parentBox = nullptr;
645 LayoutRect newRect = rectToScroll; 646 LayoutRect newRect = rectToScroll;
646 647
647 bool restrictedByLineClamp = false; 648 bool restrictedByLineClamp = false;
648 if (containingBlock()) { 649 if (containingBlock()) {
649 parentBox = containingBlock(); 650 parentBox = containingBlock();
650 restrictedByLineClamp = !containingBlock()->style()->lineClamp().isNone(); 651 restrictedByLineClamp = !containingBlock()->style()->lineClamp().isNone();
651 } 652 }
652 653
654 ScrollBehavior behavior = ScrollBehaviorAuto;
bokan 2017/02/21 21:33:00 This should be ScrollBehaviorInstant so that we pa
sunyunjia 2017/02/24 19:11:48 Done.
655 if (scrollBehavior == ScrollBehaviorSmooth ||
656 (scrollBehavior == ScrollBehaviorAuto &&
657 style()->getScrollBehavior() == ScrollBehaviorSmooth)) {
658 behavior = ScrollBehaviorSmooth;
659 }
660
653 if (hasOverflowClip() && !restrictedByLineClamp) { 661 if (hasOverflowClip() && !restrictedByLineClamp) {
654 // Don't scroll to reveal an overflow layer that is restricted by the 662 // Don't scroll to reveal an overflow layer that is restricted by the
655 // -webkit-line-clamp property. This will prevent us from revealing text 663 // -webkit-line-clamp property. This will prevent us from revealing text
656 // hidden by the slider in Safari RSS. 664 // hidden by the slider in Safari RSS.
657 // TODO(eae): We probably don't need this any more as we don't share any 665 // TODO(eae): We probably don't need this any more as we don't share any
658 // code with the Safari RSS reeder. 666 // code with the Safari RSS reeder.
659 newRect = getScrollableArea()->scrollIntoView(rectToScroll, alignX, alignY, 667 newRect = getScrollableArea()->scrollIntoView(rectToScroll, alignX, alignY,
660 scrollType); 668 scrollType, behavior);
661 if (newRect.isEmpty()) 669 if (newRect.isEmpty())
662 return; 670 return;
663 } else if (!parentBox && canBeProgramaticallyScrolled()) { 671 } else if (!parentBox && canBeProgramaticallyScrolled()) {
664 if (FrameView* frameView = this->frameView()) { 672 if (FrameView* frameView = this->frameView()) {
665 HTMLFrameOwnerElement* ownerElement = document().localOwner(); 673 HTMLFrameOwnerElement* ownerElement = document().localOwner();
666 if (!isDisallowedAutoscroll(ownerElement, frameView)) { 674 if (!isDisallowedAutoscroll(ownerElement, frameView)) {
667 if (makeVisibleInVisualViewport) { 675 if (makeVisibleInVisualViewport) {
668 frameView->getScrollableArea()->scrollIntoView(rectToScroll, alignX, 676 frameView->getScrollableArea()->scrollIntoView(
669 alignY, scrollType); 677 rectToScroll, alignX, alignY, scrollType, behavior);
670 } else { 678 } else {
671 frameView->layoutViewportScrollableArea()->scrollIntoView( 679 frameView->layoutViewportScrollableArea()->scrollIntoView(
672 rectToScroll, alignX, alignY, scrollType); 680 rectToScroll, alignX, alignY, scrollType, behavior);
673 } 681 }
674 if (ownerElement && ownerElement->layoutObject()) { 682 if (ownerElement && ownerElement->layoutObject()) {
675 if (frameView->safeToPropagateScrollToParent()) { 683 if (frameView->safeToPropagateScrollToParent()) {
676 parentBox = ownerElement->layoutObject()->enclosingBox(); 684 parentBox = ownerElement->layoutObject()->enclosingBox();
677 LayoutView* parentView = ownerElement->layoutObject()->view(); 685 LayoutView* parentView = ownerElement->layoutObject()->view();
678 newRect = enclosingLayoutRect( 686 newRect = enclosingLayoutRect(
679 view() 687 view()
680 ->localToAncestorQuad( 688 ->localToAncestorQuad(
681 FloatRect(rectToScroll), parentView, 689 FloatRect(rectToScroll), parentView,
682 UseTransforms | TraverseDocumentBoundaries) 690 UseTransforms | TraverseDocumentBoundaries)
683 .boundingBox()); 691 .boundingBox());
684 } else { 692 } else {
685 parentBox = nullptr; 693 parentBox = nullptr;
686 } 694 }
687 } 695 }
688 } 696 }
689 } 697 }
690 } 698 }
691 699
692 // If we are fixed-position and stick to the viewport, it is useless to 700 // If we are fixed-position and stick to the viewport, it is useless to
693 // scroll the parent. 701 // scroll the parent.
694 if (style()->position() == FixedPosition && 702 if (style()->position() == FixedPosition &&
695 containerForFixedPosition() == view()) { 703 containerForFixedPosition() == view()) {
696 return; 704 return;
697 } 705 }
698 706
699 if (frame()->page()->autoscrollController().autoscrollInProgress()) 707 if (frame()->page()->autoscrollController().autoscrollInProgress())
700 parentBox = enclosingScrollableBox(); 708 parentBox = enclosingScrollableBox();
701 709
702 if (parentBox) 710 if (parentBox) {
703 parentBox->scrollRectToVisible(newRect, alignX, alignY, scrollType, 711 parentBox->scrollRectToVisible(newRect, alignX, alignY, scrollType,
704 makeVisibleInVisualViewport); 712 makeVisibleInVisualViewport, scrollBehavior);
713 }
705 } 714 }
706 715
707 void LayoutBox::absoluteRects(Vector<IntRect>& rects, 716 void LayoutBox::absoluteRects(Vector<IntRect>& rects,
708 const LayoutPoint& accumulatedOffset) const { 717 const LayoutPoint& accumulatedOffset) const {
709 rects.push_back(pixelSnappedIntRect(accumulatedOffset, size())); 718 rects.push_back(pixelSnappedIntRect(accumulatedOffset, size()));
710 } 719 }
711 720
712 void LayoutBox::absoluteQuads(Vector<FloatQuad>& quads, 721 void LayoutBox::absoluteQuads(Vector<FloatQuad>& quads,
713 MapCoordinatesFlags mode) const { 722 MapCoordinatesFlags mode) const {
714 if (LayoutFlowThread* flowThread = flowThreadContainingBlock()) { 723 if (LayoutFlowThread* flowThread = flowThreadContainingBlock()) {
(...skipping 4979 matching lines...) Expand 10 before | Expand all | Expand 10 after
5694 block->adjustChildDebugRect(rect); 5703 block->adjustChildDebugRect(rect);
5695 5704
5696 return rect; 5705 return rect;
5697 } 5706 }
5698 5707
5699 bool LayoutBox::shouldClipOverflow() const { 5708 bool LayoutBox::shouldClipOverflow() const {
5700 return hasOverflowClip() || styleRef().containsPaint() || hasControlClip(); 5709 return hasOverflowClip() || styleRef().containsPaint() || hasControlClip();
5701 } 5710 }
5702 5711
5703 } // namespace blink 5712 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698