WebKit Bugzilla
Attachment 346619 Details for
Bug 188300
: Make two-arguments versions of scrollBy/scrollTo depend on the one-argument versions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for landing
bug-188300-20180806111645.patch (text/plain), 9.01 KB, created by
Frédéric Wang (:fredw)
on 2018-08-06 02:16:47 PDT
(
hide
)
Description:
Patch for landing
Filename:
MIME Type:
Creator:
Frédéric Wang (:fredw)
Created:
2018-08-06 02:16:47 PDT
Size:
9.01 KB
patch
obsolete
>Subversion Revision: 234586 >diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog >index 35b4a0bee7cbfc70b72a03107b6fe4225ea06ee0..250895626905d7c4a7ce078dfc54c5f038cc5740 100644 >--- a/Source/WebCore/ChangeLog >+++ b/Source/WebCore/ChangeLog >@@ -1,3 +1,39 @@ >+2018-08-06 Frederic Wang <fwang@igalia.com> >+ >+ Make two-arguments versions of scrollBy/scrollTo depend on the one-argument versions >+ https://bugs.webkit.org/show_bug.cgi?id=188300 >+ >+ Reviewed by Darin Adler. >+ >+ This patch refactors a bit the scrollBy/scrollTo code, so that the two-arguments versions >+ share the same code path as the more generic one-argument versions. In particular, this >+ helps to implement the ScrollBehavior option (bug 188043) since the one-argument versions >+ will require to distinguish between smooth and instant scrolling. The logic to normalize >+ non finite left/right values or to use a fallback when they are absent is also factored out >+ into ScrollToOptions. >+ >+ References: >+ https://drafts.csswg.org/cssom-view/#dom-element-scroll >+ https://drafts.csswg.org/cssom-view/#dom-element-scrollby >+ https://drafts.csswg.org/cssom-view/#dom-window-scroll >+ https://drafts.csswg.org/cssom-view/#dom-window-scrollby >+ >+ No new tests, behavior is unchanged. >+ >+ * dom/Element.cpp: >+ (WebCore::Element::scrollBy): Make two-parameter version depends on one-parameter version >+ and rewrite the normalize / fallback logic. >+ (WebCore::Element::scrollTo): Rewrite the normalize / fallback logic. >+ (WebCore::normalizeNonFiniteValue): Deleted. The logic is moved to ScrollToOptions. >+ * page/DOMWindow.cpp: >+ (WebCore::DOMWindow::scrollBy const): Make two-parameter version depends on one-parameter >+ version and rewrite the normalize / fallback logic. >+ (WebCore::DOMWindow::scrollTo const): Make two-parameter version depends on one-parameter >+ version and rewrite the normalize / fallback logic. >+ * page/ScrollToOptions.h: Add <cmath> to use std::isfinite >+ (WebCore::ScrollToOptions::normalizeNonFiniteCoordinatesOrFallBackTo): New function to >+ normalize left/right values or fallback to the specified value if it is missing. >+ > 2018-08-05 Yusuke Suzuki <utatane.tea@gmail.com> > > Add support for microtasks in workers >diff --git a/Source/WebCore/dom/Element.cpp b/Source/WebCore/dom/Element.cpp >index 79cecb585374b0c4f2cd46301bb73370eb2fdd65..8870d2dffd129b766e1a4a1c78d629f4c69a278c 100644 >--- a/Source/WebCore/dom/Element.cpp >+++ b/Source/WebCore/dom/Element.cpp >@@ -692,17 +692,15 @@ void Element::scrollIntoViewIfNotVisible(bool centerIfNotVisible) > > void Element::scrollBy(const ScrollToOptions& options) > { >- return scrollBy(options.left.value_or(0), options.top.value_or(0)); >-} >- >-static inline double normalizeNonFiniteValue(double f) >-{ >- return std::isfinite(f) ? f : 0; >+ ScrollToOptions scrollToOptions = normalizeNonFiniteCoordinatesOrFallBackTo(options, 0, 0); >+ scrollToOptions.left.value() += scrollLeft(); >+ scrollToOptions.top.value() += scrollTop(); >+ scrollTo(scrollToOptions); > } > > void Element::scrollBy(double x, double y) > { >- scrollTo(scrollLeft() + normalizeNonFiniteValue(x), scrollTop() + normalizeNonFiniteValue(y)); >+ scrollBy({ x, y }); > } > > void Element::scrollTo(const ScrollToOptions& options, ScrollClamping clamping) >@@ -720,12 +718,12 @@ void Element::scrollTo(const ScrollToOptions& options, ScrollClamping clamping) > if (!renderer || !renderer->hasOverflowClip()) > return; > >- // Normalize non-finite values for left and top dictionary members of options, if present. >- double x = options.left ? normalizeNonFiniteValue(options.left.value()) : adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer); >- double y = options.top ? normalizeNonFiniteValue(options.top.value()) : adjustForAbsoluteZoom(renderer->scrollTop(), *renderer); >- >- renderer->setScrollLeft(clampToInteger(x * renderer->style().effectiveZoom()), clamping); >- renderer->setScrollTop(clampToInteger(y * renderer->style().effectiveZoom()), clamping); >+ ScrollToOptions scrollToOptions = normalizeNonFiniteCoordinatesOrFallBackTo(options, >+ adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer), >+ adjustForAbsoluteZoom(renderer->scrollTop(), *renderer) >+ ); >+ renderer->setScrollLeft(clampToInteger(scrollToOptions.left.value() * renderer->style().effectiveZoom()), clamping); >+ renderer->setScrollTop(clampToInteger(scrollToOptions.top.value() * renderer->style().effectiveZoom()), clamping); > } > > void Element::scrollTo(double x, double y) >diff --git a/Source/WebCore/page/DOMWindow.cpp b/Source/WebCore/page/DOMWindow.cpp >index ff371715c0835dfbbeaaf5cf27eca8b459dda5c8..73073263639f02cf9128bd44586012a481deaa7f 100644 >--- a/Source/WebCore/page/DOMWindow.cpp >+++ b/Source/WebCore/page/DOMWindow.cpp >@@ -1574,12 +1574,12 @@ double DOMWindow::devicePixelRatio() const > return page->deviceScaleFactor(); > } > >-void DOMWindow::scrollBy(const ScrollToOptions& options) const >+void DOMWindow::scrollBy(double x, double y) const > { >- return scrollBy(options.left.value_or(0), options.top.value_or(0)); >+ scrollBy({ x, y }); > } > >-void DOMWindow::scrollBy(double x, double y) const >+void DOMWindow::scrollBy(const ScrollToOptions& options) const > { > if (!isCurrentlyDisplayedInFrame()) > return; >@@ -1590,29 +1590,17 @@ void DOMWindow::scrollBy(double x, double y) const > if (!view) > return; > >- // Normalize non-finite values (https://drafts.csswg.org/cssom-view/#normalize-non-finite-values). >- x = std::isfinite(x) ? x : 0; >- y = std::isfinite(y) ? y : 0; >- >- IntSize scaledOffset(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y)); >+ ScrollToOptions scrollToOptions = normalizeNonFiniteCoordinatesOrFallBackTo(options, 0, 0); >+ IntSize scaledOffset(view->mapFromCSSToLayoutUnits(scrollToOptions.left.value()), view->mapFromCSSToLayoutUnits(scrollToOptions.top.value())); > view->setContentsScrollPosition(view->contentsScrollPosition() + scaledOffset); > } > >-void DOMWindow::scrollTo(const ScrollToOptions& options, ScrollClamping clamping) const >+void DOMWindow::scrollTo(double x, double y, ScrollClamping clamping) const > { >- if (!isCurrentlyDisplayedInFrame()) >- return; >- >- RefPtr<FrameView> view = m_frame->view(); >- if (!view) >- return; >- >- double x = options.left ? options.left.value() : view->contentsScrollPosition().x(); >- double y = options.top ? options.top.value() : view->contentsScrollPosition().y(); >- return scrollTo(x, y, clamping); >+ scrollTo({ x, y }, clamping); > } > >-void DOMWindow::scrollTo(double x, double y, ScrollClamping) const >+void DOMWindow::scrollTo(const ScrollToOptions& options, ScrollClamping) const > { > if (!isCurrentlyDisplayedInFrame()) > return; >@@ -1621,16 +1609,16 @@ void DOMWindow::scrollTo(double x, double y, ScrollClamping) const > if (!view) > return; > >- // Normalize non-finite values (https://drafts.csswg.org/cssom-view/#normalize-non-finite-values). >- x = std::isfinite(x) ? x : 0; >- y = std::isfinite(y) ? y : 0; >+ ScrollToOptions scrollToOptions = normalizeNonFiniteCoordinatesOrFallBackTo(options, >+ view->contentsScrollPosition().x(), view->contentsScrollPosition().y() >+ ); > >- if (!x && !y && view->contentsScrollPosition() == IntPoint(0, 0)) >+ if (!scrollToOptions.left.value() && !scrollToOptions.top.value() && view->contentsScrollPosition() == IntPoint(0, 0)) > return; > > document()->updateLayoutIgnorePendingStylesheets(); > >- IntPoint layoutPos(view->mapFromCSSToLayoutUnits(x), view->mapFromCSSToLayoutUnits(y)); >+ IntPoint layoutPos(view->mapFromCSSToLayoutUnits(scrollToOptions.left.value()), view->mapFromCSSToLayoutUnits(scrollToOptions.top.value())); > view->setContentsScrollPosition(layoutPos); > } > >diff --git a/Source/WebCore/page/ScrollToOptions.h b/Source/WebCore/page/ScrollToOptions.h >index 84a9d9ddb2805d7f2b3943764a3190a9ccf5d0ff..87eeaa9cca9527681f383fc2b4d449f0d480e24f 100644 >--- a/Source/WebCore/page/ScrollToOptions.h >+++ b/Source/WebCore/page/ScrollToOptions.h >@@ -28,6 +28,7 @@ > > #pragma once > >+#include <cmath> > #include <wtf/Optional.h> > > namespace WebCore { >@@ -37,4 +38,19 @@ struct ScrollToOptions { > std::optional<double> top; > }; > >+inline double normalizeNonFiniteValueOrFallBackTo(std::optional<double> value, double fallbackValue) >+{ >+ // Normalize non-finite values (https://drafts.csswg.org/cssom-view/#normalize-non-finite-values). >+ return value ? (std::isfinite(*value) ? *value : 0) : fallbackValue; >+} >+ >+// FIXME(https://webkit.org/b/88339): Consider using FloatPoint or DoublePoint for fallback and return values. >+inline ScrollToOptions normalizeNonFiniteCoordinatesOrFallBackTo(const ScrollToOptions& value, double x, double y) >+{ >+ ScrollToOptions options; >+ options.left = normalizeNonFiniteValueOrFallBackTo(value.left, x); >+ options.top = normalizeNonFiniteValueOrFallBackTo(value.top, y); >+ return options; >+} >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Formatted Diff
|
Diff
Attachments on
bug 188300
:
346469
|
346512
|
346583
|
346616
| 346619