 Chromium Code Reviews
 Chromium Code Reviews Issue 2650343008:
  Implement Element.scrollIntoView for scroll-behavior: smooth.  (Closed)
    
  
    Issue 2650343008:
  Implement Element.scrollIntoView for scroll-behavior: smooth.  (Closed) 
  | Index: third_party/WebKit/Source/core/frame/FrameView.cpp | 
| diff --git a/third_party/WebKit/Source/core/frame/FrameView.cpp b/third_party/WebKit/Source/core/frame/FrameView.cpp | 
| index 29ddba69decec3a8f4fbbd0b60c08dd5bb9df356..1885bb75dde5cc950285721b189476f5f8331d4e 100644 | 
| --- a/third_party/WebKit/Source/core/frame/FrameView.cpp | 
| +++ b/third_party/WebKit/Source/core/frame/FrameView.cpp | 
| @@ -2060,6 +2060,14 @@ HostWindow* FrameView::getHostWindow() const { | 
| return &page->chromeClient(); | 
| } | 
| +ProgrammaticScrollCoordinator* FrameView::getProgrammaticScrollCoordinator() | 
| + const { | 
| + Page* page = frame().page(); | 
| + if (!page) | 
| + return nullptr; | 
| + return page->scrollingCoordinator()->programmaticScrollCoordinator(); | 
| +} | 
| + | 
| void FrameView::contentsResized() { | 
| if (m_frame->isMainFrame() && m_frame->document()) { | 
| if (TextAutosizer* textAutosizer = m_frame->document()->textAutosizer()) | 
| @@ -4457,16 +4465,23 @@ Widget* FrameView::getWidget() { | 
| LayoutRect FrameView::scrollIntoView(const LayoutRect& rectInContent, | 
| const ScrollAlignment& alignX, | 
| const ScrollAlignment& alignY, | 
| - ScrollType scrollType) { | 
| + ScrollType scrollType, | 
| + bool isSmooth) { | 
| LayoutRect viewRect(visibleContentRect()); | 
| LayoutRect exposeRect = | 
| ScrollAlignment::getRectToExpose(viewRect, rectInContent, alignX, alignY); | 
| if (exposeRect != viewRect) { | 
| - setScrollOffset( | 
| - ScrollOffset(exposeRect.x().toFloat(), exposeRect.y().toFloat()), | 
| - scrollType); | 
| + if (isSmooth) { | 
| + DCHECK(scrollType != UserScroll); | 
| + getProgrammaticScrollCoordinator()->queueAnimation( | 
| + this, | 
| + ScrollOffset(exposeRect.x().toFloat(), exposeRect.y().toFloat())); | 
| 
bokan
2017/03/28 16:29:53
Store the ScrollOffset in a variable above, outsid
 
sunyunjia
2017/04/07 13:53:20
Done.
 | 
| + } else { | 
| + setScrollOffset( | 
| + ScrollOffset(exposeRect.x().toFloat(), exposeRect.y().toFloat()), | 
| + scrollType); | 
| + } | 
| } | 
| - | 
| // Scrolling the FrameView cannot change the input rect's location relative to | 
| // the document. | 
| return rectInContent; |