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

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

Issue 2650343008: Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Rebase Created 3 years, 8 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 c54b6e215a9009a14879f49fbd3513c22fa15a51..6010de568163bbd498daf484510148fdb1cf3f25 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,13 @@ LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent,
LayoutRect targetViewport = ScrollAlignment::getRectToExpose(
viewRectInContent, rectInContent, alignX, alignY);
if (targetViewport != viewRectInContent) {
- setScrollOffset(ScrollOffset(targetViewport.x(), targetViewport.y()),
- scrollType);
+ ScrollOffset targetOffset(targetViewport.x(), targetViewport.y());
+ if (isSmooth) {
+ DCHECK(scrollType != UserScroll);
+ getSmoothScrollSequencer()->queueAnimation(this, targetOffset);
+ } else {
+ setScrollOffset(targetOffset, scrollType);
+ }
}
// RootFrameViewport only changes the viewport relative to the document so we
@@ -430,6 +436,10 @@ HostWindow* RootFrameViewport::getHostWindow() const {
return layoutViewport().getHostWindow();
}
+SmoothScrollSequencer* RootFrameViewport::getSmoothScrollSequencer() const {
+ return layoutViewport().getSmoothScrollSequencer();
+}
+
void RootFrameViewport::serviceScrollAnimations(double monotonicTime) {
ScrollableArea::serviceScrollAnimations(monotonicTime);
layoutViewport().serviceScrollAnimations(monotonicTime);

Powered by Google App Engine
This is Rietveld 408576698