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

Unified Diff: third_party/WebKit/Source/core/frame/RootFrameViewport.cpp

Issue 2650343008: Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Added SimTest. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/RootFrameViewport.cpp
diff --git a/third_party/WebKit/Source/core/frame/RootFrameViewport.cpp b/third_party/WebKit/Source/core/frame/RootFrameViewport.cpp
index 1f4632132bb43eaf0d7c679da4023ffbf3a4fed0..516383333a5c0ca6237df85b3a19bc0f42834766 100644
--- a/third_party/WebKit/Source/core/frame/RootFrameViewport.cpp
+++ b/third_party/WebKit/Source/core/frame/RootFrameViewport.cpp
@@ -209,7 +209,8 @@ ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const {
LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent,
const ScrollAlignment& alignX,
const ScrollAlignment& alignY,
- ScrollType scrollType) {
+ ScrollType scrollType,
+ bool isSmooth) {
// We want to move the rect into the viewport that excludes the scrollbars so
// we intersect the visual viewport with the scrollbar-excluded frameView
// content rect. However, we don't use visibleContentRect directly since it
@@ -229,8 +230,14 @@ LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent,
LayoutRect targetViewport = ScrollAlignment::getRectToExpose(
viewRectInContent, rectInContent, alignX, alignY);
if (targetViewport != viewRectInContent) {
- setScrollOffset(ScrollOffset(targetViewport.x(), targetViewport.y()),
- scrollType);
+ if (isSmooth) {
+ DCHECK(scrollType != UserScroll);
+ getProgrammaticScrollCoordinator()->queueAnimation(
+ this, ScrollOffset(targetViewport.x(), targetViewport.y()));
+ } else {
+ setScrollOffset(ScrollOffset(targetViewport.x(), targetViewport.y()),
+ scrollType);
+ }
}
// RootFrameViewport only changes the viewport relative to the document so we
@@ -430,6 +437,11 @@ HostWindow* RootFrameViewport::getHostWindow() const {
return layoutViewport().getHostWindow();
}
+ProgrammaticScrollCoordinator*
+RootFrameViewport::getProgrammaticScrollCoordinator() const {
+ return layoutViewport().getProgrammaticScrollCoordinator();
+}
+
void RootFrameViewport::serviceScrollAnimations(double monotonicTime) {
ScrollableArea::serviceScrollAnimations(monotonicTime);
layoutViewport().serviceScrollAnimations(monotonicTime);

Powered by Google App Engine
This is Rietveld 408576698