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

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

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

Powered by Google App Engine
This is Rietveld 408576698