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

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

Issue 2650343008: Implement Element.scrollIntoView for scroll-behavior: smooth. (Closed)
Patch Set: Add a short comment. 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
diff --git a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
index 1e6b1b694ac7b88a8a454348bce30302a726f0e7..3bd31655f9be5933d4e1b77f11d22baf6969634a 100644
--- a/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
+++ b/third_party/WebKit/Source/core/frame/LocalDOMWindow.cpp
@@ -1210,6 +1210,21 @@ double LocalDOMWindow::devicePixelRatio() const {
return GetFrame()->DevicePixelRatio();
}
+void LocalDOMWindow::scrollViewportTo(ScrollableArea* viewport,
+ const ScrollOffset& offset,
+ ScrollBehavior scroll_behavior) const {
+ if (SmoothScrollSequencer* sequencer =
+ GetFrame()->GetPage()->GetSmoothScrollSequencer()) {
+ sequencer->AbortAnimations();
+ if (scroll_behavior == kScrollBehaviorSmooth) {
+ sequencer->QueueAnimation(viewport, offset);
+ sequencer->RunQueuedAnimations();
+ } else {
+ viewport->SetScrollOffset(offset, kProgrammaticScroll, scroll_behavior);
+ }
+ }
+}
+
void LocalDOMWindow::scrollBy(double x,
double y,
ScrollBehavior scroll_behavior) const {
@@ -1237,8 +1252,7 @@ void LocalDOMWindow::scrollBy(double x,
ScrollOffset scaled_delta(x * GetFrame()->PageZoomFactor(),
y * GetFrame()->PageZoomFactor());
- viewport->SetScrollOffset(current_offset + scaled_delta, kProgrammaticScroll,
- scroll_behavior);
+ scrollViewportTo(viewport, current_offset + scaled_delta, scroll_behavior);
}
void LocalDOMWindow::scrollBy(const ScrollToOptions& scroll_to_options) const {
@@ -1279,8 +1293,7 @@ void LocalDOMWindow::scrollTo(double x, double y) const {
ScrollableArea* viewport = page->GetSettings().GetInertVisualViewport()
? view->LayoutViewportScrollableArea()
: view->GetScrollableArea();
- viewport->SetScrollOffset(layout_offset, kProgrammaticScroll,
- kScrollBehaviorAuto);
+ scrollViewportTo(viewport, layout_offset, kScrollBehaviorAuto);
}
void LocalDOMWindow::scrollTo(const ScrollToOptions& scroll_to_options) const {
@@ -1327,8 +1340,7 @@ void LocalDOMWindow::scrollTo(const ScrollToOptions& scroll_to_options) const {
ScrollableArea::ScrollBehaviorFromString(scroll_to_options.behavior(),
scroll_behavior);
- viewport->SetScrollOffset(ScrollOffset(scaled_x, scaled_y),
- kProgrammaticScroll, scroll_behavior);
+ scrollViewportTo(viewport, ScrollOffset(scaled_x, scaled_y), scroll_behavior);
}
void LocalDOMWindow::moveBy(int x, int y) const {
« no previous file with comments | « third_party/WebKit/Source/core/frame/LocalDOMWindow.h ('k') | third_party/WebKit/Source/core/frame/RootFrameViewport.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698