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

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

Issue 1738243002: Removed main-thread one dimensional scrolling paths. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@removeStepFromUserScroll
Patch Set: Rebase Created 4 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 2446d420779e8101175f849d7ddfe8f001489690..62882cb05bfecd44506e8b4381109f1f3ee9f3c2 100644
--- a/third_party/WebKit/Source/core/frame/RootFrameViewport.cpp
+++ b/third_party/WebKit/Source/core/frame/RootFrameViewport.cpp
@@ -232,50 +232,76 @@ GraphicsLayer* RootFrameViewport::layerForVerticalScrollbar() const
return layoutViewport().layerForVerticalScrollbar();
}
-ScrollResultOneDimensional RootFrameViewport::userScroll(ScrollDirectionPhysical direction, ScrollGranularity granularity, float delta)
+ScrollResult RootFrameViewport::userScroll(ScrollGranularity granularity, const FloatSize& delta)
{
- updateScrollAnimator();
-
- ScrollbarOrientation orientation = scrollbarOrientationFromDirection(direction);
-
- if (layoutViewport().userInputScrollable(orientation) && visualViewport().userInputScrollable(orientation)) {
- // Distribute the scroll between the visual and layout viewport.
- float step = scrollStep(granularity, orientation);
-
- if (direction == ScrollUp || direction == ScrollLeft)
- delta = -delta;
+ // TODO(bokan/ymalik): Once smooth scrolling is permanently enabled we
+ // should be able to remove this method override and use the base class
+ // version: ScrollableArea::userScroll.
- // This is the total amount we need to scroll. Instead of passing step
- // to the scroll animator and letting it compute the total delta, we
- // give it the delta it should scroll. This way we can apply the
- // unused delta from the visual viewport to the layout viewport.
- delta *= step;
-
- cancelProgrammaticScrollAnimation();
+ updateScrollAnimator();
- float visualUsedDelta = visualViewport().scrollAnimator().computeDeltaToConsume(orientation, delta);
- ScrollResultOneDimensional visualResult = visualViewport().scrollAnimator().userScroll(
- orientation, granularity, visualUsedDelta);
+ // Distribute the scroll between the visual and layout viewport.
+
+ float stepX = scrollStep(granularity, HorizontalScrollbar);
+ float stepY = scrollStep(granularity, VerticalScrollbar);
+
+ FloatSize pixelDelta(delta);
+ pixelDelta.scale(stepX, stepY);
+
+ // Precompute the amount of possible scrolling since, when animated,
+ // ScrollAnimator::userScroll will report having consumed the total given
+ // scroll delta, regardless of how much will actually scroll, but we need to
+ // know how much to leave for the layout viewport.
+ FloatSize visualConsumedDelta =
+ visualViewport().scrollAnimator().computeDeltaToConsume(pixelDelta);
+
+ // Split the remaining delta between scrollable and unscrollable axes of the
+ // layout viewport. We only pass a delta to the scrollable axes and remember
+ // how much was held back so we can add it to the unused delta in the
+ // result.
+ FloatSize layoutDelta = pixelDelta - visualConsumedDelta;
+ FloatSize scrollableAxisDelta(
+ layoutViewport().userInputScrollable(HorizontalScrollbar)
+ ? layoutDelta.width()
+ : 0,
+ layoutViewport().userInputScrollable(VerticalScrollbar)
+ ? layoutDelta.height()
+ : 0);
+
+ // If there won't be any scrolling, bail early so we don't produce any side
+ // effects like cancelling existing animations.
+ if (visualConsumedDelta.isZero() && scrollableAxisDelta.isZero()) {
+ return ScrollResult(
+ false,
+ false,
+ pixelDelta.width(),
+ pixelDelta.height());
+ }
- // Scroll the layout viewport if all of the scroll was not applied to the
- // visual viewport.
- if (visualUsedDelta == delta)
- return visualResult;
+ cancelProgrammaticScrollAnimation();
- ScrollResultOneDimensional layoutResult = layoutViewport().scrollAnimator().userScroll(
- orientation, granularity, delta - visualUsedDelta);
+ // TODO(bokan): Why do we call userScroll on the animators directly and
+ // not through the ScrollableAreas?
+ ScrollResult visualResult = visualViewport().scrollAnimator().userScroll(
+ granularity,
+ visualConsumedDelta);
- return ScrollResultOneDimensional(visualResult.didScroll || layoutResult.didScroll,
- layoutResult.unusedScrollDelta);
- }
+ if (visualConsumedDelta == pixelDelta)
+ return visualResult;
- if (visualViewport().userInputScrollable(orientation))
- return visualViewport().userScroll(direction, granularity, delta);
+ ScrollResult layoutResult = layoutViewport().scrollAnimator().userScroll(
+ granularity,
+ scrollableAxisDelta);
- if (layoutViewport().userInputScrollable(orientation))
- return layoutViewport().userScroll(direction, granularity, delta);
+ // Remember to add any delta not used because of !userInputScrollable to the
+ // unusedScrollDelta in the result.
+ FloatSize unscrollableAxisDelta = layoutDelta - scrollableAxisDelta;
- return ScrollResultOneDimensional(false, delta);
+ return ScrollResult(
+ visualResult.didScrollX || layoutResult.didScrollX,
+ visualResult.didScrollY || layoutResult.didScrollY,
+ layoutResult.unusedScrollDeltaX + unscrollableAxisDelta.width(),
+ layoutResult.unusedScrollDeltaY + unscrollableAxisDelta.height());
}
bool RootFrameViewport::scrollAnimatorEnabled() const

Powered by Google App Engine
This is Rietveld 408576698