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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/frame/RootFrameViewport.h" 5 #include "core/frame/RootFrameViewport.h"
6 6
7 #include "core/frame/FrameView.h" 7 #include "core/frame/FrameView.h"
8 #include "core/layout/ScrollAlignment.h" 8 #include "core/layout/ScrollAlignment.h"
9 #include "core/layout/ScrollAnchor.h" 9 #include "core/layout/ScrollAnchor.h"
10 #include "platform/geometry/DoubleRect.h" 10 #include "platform/geometry/DoubleRect.h"
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 ScrollableArea::setScrollOffset(clampedOffset, scrollType, scrollBehavior); 202 ScrollableArea::setScrollOffset(clampedOffset, scrollType, scrollBehavior);
203 } 203 }
204 204
205 ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const { 205 ScrollBehavior RootFrameViewport::scrollBehaviorStyle() const {
206 return layoutViewport().scrollBehaviorStyle(); 206 return layoutViewport().scrollBehaviorStyle();
207 } 207 }
208 208
209 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent, 209 LayoutRect RootFrameViewport::scrollIntoView(const LayoutRect& rectInContent,
210 const ScrollAlignment& alignX, 210 const ScrollAlignment& alignX,
211 const ScrollAlignment& alignY, 211 const ScrollAlignment& alignY,
212 ScrollType scrollType) { 212 ScrollType scrollType,
213 bool isSmooth) {
213 // We want to move the rect into the viewport that excludes the scrollbars so 214 // We want to move the rect into the viewport that excludes the scrollbars so
214 // we intersect the visual viewport with the scrollbar-excluded frameView 215 // we intersect the visual viewport with the scrollbar-excluded frameView
215 // content rect. However, we don't use visibleContentRect directly since it 216 // content rect. However, we don't use visibleContentRect directly since it
216 // floors the scroll offset. Instead, we use ScrollAnimatorBase::currentOffset 217 // floors the scroll offset. Instead, we use ScrollAnimatorBase::currentOffset
217 // and construct a LayoutRect from that. 218 // and construct a LayoutRect from that.
218 LayoutRect frameRectInContent = 219 LayoutRect frameRectInContent =
219 LayoutRect(FloatPoint(layoutViewport().scrollAnimator().currentOffset()), 220 LayoutRect(FloatPoint(layoutViewport().scrollAnimator().currentOffset()),
220 FloatSize(layoutViewport().visibleContentRect().size())); 221 FloatSize(layoutViewport().visibleContentRect().size()));
221 LayoutRect visualRectInContent = 222 LayoutRect visualRectInContent =
222 LayoutRect(FloatPoint(scrollOffsetFromScrollAnimators()), 223 LayoutRect(FloatPoint(scrollOffsetFromScrollAnimators()),
223 FloatSize(visualViewport().visibleContentRect().size())); 224 FloatSize(visualViewport().visibleContentRect().size()));
224 225
225 // Intersect layout and visual rects to exclude the scrollbar from the view 226 // Intersect layout and visual rects to exclude the scrollbar from the view
226 // rect. 227 // rect.
227 LayoutRect viewRectInContent = 228 LayoutRect viewRectInContent =
228 intersection(visualRectInContent, frameRectInContent); 229 intersection(visualRectInContent, frameRectInContent);
229 LayoutRect targetViewport = ScrollAlignment::getRectToExpose( 230 LayoutRect targetViewport = ScrollAlignment::getRectToExpose(
230 viewRectInContent, rectInContent, alignX, alignY); 231 viewRectInContent, rectInContent, alignX, alignY);
231 if (targetViewport != viewRectInContent) { 232 if (targetViewport != viewRectInContent) {
232 setScrollOffset(ScrollOffset(targetViewport.x(), targetViewport.y()), 233 ScrollOffset targetOffset(targetViewport.x(), targetViewport.y());
233 scrollType); 234 if (isSmooth) {
235 DCHECK(scrollType != UserScroll);
236 getSmoothScrollSequencer()->queueAnimation(this, targetOffset);
237 } else {
238 setScrollOffset(targetOffset, scrollType);
239 }
234 } 240 }
235 241
236 // RootFrameViewport only changes the viewport relative to the document so we 242 // RootFrameViewport only changes the viewport relative to the document so we
237 // can't change the input rect's location relative to the document origin. 243 // can't change the input rect's location relative to the document origin.
238 return rectInContent; 244 return rectInContent;
239 } 245 }
240 246
241 void RootFrameViewport::updateScrollOffset(const ScrollOffset& offset, 247 void RootFrameViewport::updateScrollOffset(const ScrollOffset& offset,
242 ScrollType scrollType) { 248 ScrollType scrollType) {
243 distributeScrollBetweenViewports(offset, scrollType, ScrollBehaviorInstant, 249 distributeScrollBetweenViewports(offset, scrollType, ScrollBehaviorInstant,
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 } 429 }
424 430
425 bool RootFrameViewport::scrollAnimatorEnabled() const { 431 bool RootFrameViewport::scrollAnimatorEnabled() const {
426 return layoutViewport().scrollAnimatorEnabled(); 432 return layoutViewport().scrollAnimatorEnabled();
427 } 433 }
428 434
429 HostWindow* RootFrameViewport::getHostWindow() const { 435 HostWindow* RootFrameViewport::getHostWindow() const {
430 return layoutViewport().getHostWindow(); 436 return layoutViewport().getHostWindow();
431 } 437 }
432 438
439 SmoothScrollSequencer* RootFrameViewport::getSmoothScrollSequencer() const {
440 return layoutViewport().getSmoothScrollSequencer();
441 }
442
433 void RootFrameViewport::serviceScrollAnimations(double monotonicTime) { 443 void RootFrameViewport::serviceScrollAnimations(double monotonicTime) {
434 ScrollableArea::serviceScrollAnimations(monotonicTime); 444 ScrollableArea::serviceScrollAnimations(monotonicTime);
435 layoutViewport().serviceScrollAnimations(monotonicTime); 445 layoutViewport().serviceScrollAnimations(monotonicTime);
436 visualViewport().serviceScrollAnimations(monotonicTime); 446 visualViewport().serviceScrollAnimations(monotonicTime);
437 } 447 }
438 448
439 void RootFrameViewport::updateCompositorScrollAnimations() { 449 void RootFrameViewport::updateCompositorScrollAnimations() {
440 ScrollableArea::updateCompositorScrollAnimations(); 450 ScrollableArea::updateCompositorScrollAnimations();
441 layoutViewport().updateCompositorScrollAnimations(); 451 layoutViewport().updateCompositorScrollAnimations();
442 visualViewport().updateCompositorScrollAnimations(); 452 visualViewport().updateCompositorScrollAnimations();
(...skipping 15 matching lines...) Expand all
458 visualViewport().clearScrollableArea(); 468 visualViewport().clearScrollableArea();
459 } 469 }
460 470
461 DEFINE_TRACE(RootFrameViewport) { 471 DEFINE_TRACE(RootFrameViewport) {
462 visitor->trace(m_visualViewport); 472 visitor->trace(m_visualViewport);
463 visitor->trace(m_layoutViewport); 473 visitor->trace(m_layoutViewport);
464 ScrollableArea::trace(visitor); 474 ScrollableArea::trace(visitor);
465 } 475 }
466 476
467 } // namespace blink 477 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698