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

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

Issue 2650343008: Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Fixed nits. Created 3 years, 6 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 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 frame_element_base->ScrollingMode() == kScrollbarAlwaysOff; 641 frame_element_base->ScrollingMode() == kScrollbarAlwaysOff;
642 } 642 }
643 } 643 }
644 return false; 644 return false;
645 } 645 }
646 646
647 void LayoutBox::ScrollRectToVisible(const LayoutRect& rect, 647 void LayoutBox::ScrollRectToVisible(const LayoutRect& rect,
648 const ScrollAlignment& align_x, 648 const ScrollAlignment& align_x,
649 const ScrollAlignment& align_y, 649 const ScrollAlignment& align_y,
650 ScrollType scroll_type, 650 ScrollType scroll_type,
651 bool make_visible_in_visual_viewport) { 651 bool make_visible_in_visual_viewport,
652 ScrollBehavior scroll_behavior) {
652 DCHECK(scroll_type == kProgrammaticScroll || scroll_type == kUserScroll); 653 DCHECK(scroll_type == kProgrammaticScroll || scroll_type == kUserScroll);
653 // Presumably the same issue as in setScrollTop. See crbug.com/343132. 654 // Presumably the same issue as in setScrollTop. See crbug.com/343132.
654 DisableCompositingQueryAsserts disabler; 655 DisableCompositingQueryAsserts disabler;
655 656
656 LayoutRect rect_to_scroll = rect; 657 LayoutRect rect_to_scroll = rect;
657 if (rect_to_scroll.Width() <= 0) 658 if (rect_to_scroll.Width() <= 0)
658 rect_to_scroll.SetWidth(LayoutUnit(1)); 659 rect_to_scroll.SetWidth(LayoutUnit(1));
659 if (rect_to_scroll.Height() <= 0) 660 if (rect_to_scroll.Height() <= 0)
660 rect_to_scroll.SetHeight(LayoutUnit(1)); 661 rect_to_scroll.SetHeight(LayoutUnit(1));
661 662
662 LayoutBox* parent_box = nullptr; 663 LayoutBox* parent_box = nullptr;
663 LayoutRect new_rect = rect_to_scroll; 664 LayoutRect new_rect = rect_to_scroll;
664 665
665 bool restricted_by_line_clamp = false; 666 bool restricted_by_line_clamp = false;
666 if (ContainingBlock()) { 667 if (ContainingBlock()) {
667 parent_box = ContainingBlock(); 668 parent_box = ContainingBlock();
668 restricted_by_line_clamp = 669 restricted_by_line_clamp =
669 !ContainingBlock()->Style()->LineClamp().IsNone(); 670 !ContainingBlock()->Style()->LineClamp().IsNone();
670 } 671 }
671 672
673 bool is_smooth = scroll_behavior == kScrollBehaviorSmooth ||
674 (scroll_behavior == kScrollBehaviorAuto &&
675 Style()->GetScrollBehavior() == kScrollBehaviorSmooth);
676
672 if (HasOverflowClip() && !restricted_by_line_clamp) { 677 if (HasOverflowClip() && !restricted_by_line_clamp) {
673 // Don't scroll to reveal an overflow layer that is restricted by the 678 // Don't scroll to reveal an overflow layer that is restricted by the
674 // -webkit-line-clamp property. This will prevent us from revealing text 679 // -webkit-line-clamp property. This will prevent us from revealing text
675 // hidden by the slider in Safari RSS. 680 // hidden by the slider in Safari RSS.
676 // TODO(eae): We probably don't need this any more as we don't share any 681 // TODO(eae): We probably don't need this any more as we don't share any
677 // code with the Safari RSS reeder. 682 // code with the Safari RSS reeder.
678 new_rect = GetScrollableArea()->ScrollIntoView(rect_to_scroll, align_x, 683 new_rect = GetScrollableArea()->ScrollIntoView(
679 align_y, scroll_type); 684 rect_to_scroll, align_x, align_y, is_smooth, scroll_type);
680 if (new_rect.IsEmpty()) 685 if (new_rect.IsEmpty())
681 return; 686 return;
682 } else if (!parent_box && CanBeProgramaticallyScrolled()) { 687 } else if (!parent_box && CanBeProgramaticallyScrolled()) {
683 if (LocalFrameView* frame_view = this->GetFrameView()) { 688 if (LocalFrameView* frame_view = this->GetFrameView()) {
684 HTMLFrameOwnerElement* owner_element = GetDocument().LocalOwner(); 689 HTMLFrameOwnerElement* owner_element = GetDocument().LocalOwner();
685 if (!IsDisallowedAutoscroll(owner_element, frame_view)) { 690 if (!IsDisallowedAutoscroll(owner_element, frame_view)) {
686 if (make_visible_in_visual_viewport) { 691 if (make_visible_in_visual_viewport) {
687 frame_view->GetScrollableArea()->ScrollIntoView( 692 frame_view->GetScrollableArea()->ScrollIntoView(
688 rect_to_scroll, align_x, align_y, scroll_type); 693 rect_to_scroll, align_x, align_y, is_smooth, scroll_type);
689 } else { 694 } else {
690 frame_view->LayoutViewportScrollableArea()->ScrollIntoView( 695 frame_view->LayoutViewportScrollableArea()->ScrollIntoView(
691 rect_to_scroll, align_x, align_y, scroll_type); 696 rect_to_scroll, align_x, align_y, is_smooth, scroll_type);
692 } 697 }
693 if (owner_element && owner_element->GetLayoutObject()) { 698 if (owner_element && owner_element->GetLayoutObject()) {
694 if (frame_view->SafeToPropagateScrollToParent()) { 699 if (frame_view->SafeToPropagateScrollToParent()) {
695 parent_box = owner_element->GetLayoutObject()->EnclosingBox(); 700 parent_box = owner_element->GetLayoutObject()->EnclosingBox();
696 LayoutView* parent_view = owner_element->GetLayoutObject()->View(); 701 LayoutView* parent_view = owner_element->GetLayoutObject()->View();
697 new_rect = EnclosingLayoutRect( 702 new_rect = EnclosingLayoutRect(
698 View() 703 View()
699 ->LocalToAncestorQuad( 704 ->LocalToAncestorQuad(
700 FloatRect(rect_to_scroll), parent_view, 705 FloatRect(rect_to_scroll), parent_view,
701 kUseTransforms | kTraverseDocumentBoundaries) 706 kUseTransforms | kTraverseDocumentBoundaries)
702 .BoundingBox()); 707 .BoundingBox());
703 } else { 708 } else {
704 parent_box = nullptr; 709 parent_box = nullptr;
705 } 710 }
706 } 711 }
707 } 712 }
708 } 713 }
709 } 714 }
710 715
711 // If we are fixed-position and stick to the viewport, it is useless to 716 // If we are fixed-position and stick to the viewport, it is useless to
712 // scroll the parent. 717 // scroll the parent.
713 if (Style()->GetPosition() == EPosition::kFixed && 718 if (Style()->GetPosition() == EPosition::kFixed &&
714 ContainerForFixedPosition() == View()) { 719 ContainerForFixedPosition() == View()) {
715 return; 720 return;
716 } 721 }
717 722
718 if (GetFrame()->GetPage()->GetAutoscrollController().AutoscrollInProgress()) 723 if (GetFrame()->GetPage()->GetAutoscrollController().AutoscrollInProgress())
719 parent_box = EnclosingScrollableBox(); 724 parent_box = EnclosingScrollableBox();
720 725
721 if (parent_box) 726 if (parent_box) {
722 parent_box->ScrollRectToVisible(new_rect, align_x, align_y, scroll_type, 727 parent_box->ScrollRectToVisible(new_rect, align_x, align_y, scroll_type,
723 make_visible_in_visual_viewport); 728 make_visible_in_visual_viewport,
729 scroll_behavior);
730 }
724 } 731 }
725 732
726 void LayoutBox::AbsoluteRects(Vector<IntRect>& rects, 733 void LayoutBox::AbsoluteRects(Vector<IntRect>& rects,
727 const LayoutPoint& accumulated_offset) const { 734 const LayoutPoint& accumulated_offset) const {
728 rects.push_back(PixelSnappedIntRect(accumulated_offset, Size())); 735 rects.push_back(PixelSnappedIntRect(accumulated_offset, Size()));
729 } 736 }
730 737
731 void LayoutBox::AbsoluteQuads(Vector<FloatQuad>& quads, 738 void LayoutBox::AbsoluteQuads(Vector<FloatQuad>& quads,
732 MapCoordinatesFlags mode) const { 739 MapCoordinatesFlags mode) const {
733 if (LayoutFlowThread* flow_thread = FlowThreadContainingBlock()) { 740 if (LayoutFlowThread* flow_thread = FlowThreadContainingBlock()) {
(...skipping 5157 matching lines...) Expand 10 before | Expand all | Expand 10 after
5891 void LayoutBox::MutableForPainting:: 5898 void LayoutBox::MutableForPainting::
5892 SavePreviousContentBoxSizeAndLayoutOverflowRect() { 5899 SavePreviousContentBoxSizeAndLayoutOverflowRect() {
5893 auto& rare_data = GetLayoutBox().EnsureRareData(); 5900 auto& rare_data = GetLayoutBox().EnsureRareData();
5894 rare_data.has_previous_content_box_size_and_layout_overflow_rect_ = true; 5901 rare_data.has_previous_content_box_size_and_layout_overflow_rect_ = true;
5895 rare_data.previous_content_box_size_ = GetLayoutBox().ContentBoxRect().Size(); 5902 rare_data.previous_content_box_size_ = GetLayoutBox().ContentBoxRect().Size();
5896 rare_data.previous_layout_overflow_rect_ = 5903 rare_data.previous_layout_overflow_rect_ =
5897 GetLayoutBox().LayoutOverflowRect(); 5904 GetLayoutBox().LayoutOverflowRect();
5898 } 5905 }
5899 5906
5900 } // namespace blink 5907 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698