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

Unified Diff: Source/core/html/HTMLBodyElement.cpp

Issue 782793002: Update Element API for CSSOM smooth scrolling to match the spec (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebased Created 6 years 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: Source/core/html/HTMLBodyElement.cpp
diff --git a/Source/core/html/HTMLBodyElement.cpp b/Source/core/html/HTMLBodyElement.cpp
index c855c82efd216db3f03ca1b4ffeb019dd2497f65..12da1cc61b113e9181561f8ca4acd93f7610f749 100644
--- a/Source/core/html/HTMLBodyElement.cpp
+++ b/Source/core/html/HTMLBodyElement.cpp
@@ -33,6 +33,7 @@
#include "core/dom/Attribute.h"
#include "core/frame/FrameView.h"
#include "core/frame/LocalFrame.h"
+#include "core/frame/ScrollToOptions.h"
#include "core/frame/UseCounter.h"
#include "core/html/HTMLFrameElementBase.h"
#include "core/html/parser/HTMLParserIdioms.h"
@@ -265,7 +266,7 @@ void HTMLBodyElement::setScrollLeft(double scrollLeft)
FrameView* view = frame->view();
if (!view)
return;
- view->setScrollPosition(DoublePoint(scrollLeft * frame->pageZoomFactor(), view->scrollY()));
+ view->setScrollPosition(DoublePoint(scrollLeft * frame->pageZoomFactor(), view->scrollY()), ScrollBehaviorAuto);
}
double HTMLBodyElement::scrollTop()
@@ -315,7 +316,7 @@ void HTMLBodyElement::setScrollTop(double scrollTop)
FrameView* view = frame->view();
if (!view)
return;
- view->setScrollPosition(DoublePoint(view->scrollX(), scrollTop * frame->pageZoomFactor()));
+ view->setScrollPosition(DoublePoint(view->scrollX(), scrollTop * frame->pageZoomFactor()), ScrollBehaviorAuto);
}
int HTMLBodyElement::scrollHeight()
@@ -336,4 +337,93 @@ int HTMLBodyElement::scrollWidth()
return view ? adjustForZoom(view->contentsWidth(), &document) : 0;
}
+void HTMLBodyElement::scrollBy(const ScrollToOptions& scrollToOptions)
Ian Vollick 2014/12/08 16:35:23 nit: The similarity of these methods and those in
ajuma 2014/12/08 18:34:13 Added helpers (scrollFrameBy, scrollFrameTo, scrol
+{
+ Document& document = this->document();
+ document.updateLayoutIgnorePendingStylesheets();
+
+ double left = scrollToOptions.hasLeft() ? scrollToOptions.left() : 0.0;
+ double top = scrollToOptions.hasTop() ? scrollToOptions.top() : 0.0;
+ if (std::isnan(left) || std::isnan(top))
+ return;
+
+ ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
+ ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollBehavior);
+
+ if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
+ RenderBox* render = renderBox();
+ if (!render)
+ return;
+ if (render->hasOverflowClip()) {
+ double currentScaledLeft = render->scrollLeft();
+ double currentScaledTop = render->scrollTop();
+ double newScaledLeft = left * render->style()->effectiveZoom() + currentScaledLeft;
+ double newScaledTop = top * render->style()->effectiveZoom() + currentScaledTop;
+ // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instantly.
+ render->scrollToOffset(DoubleSize(newScaledLeft, newScaledTop));
+ return;
+ }
+ if (!document.inQuirksMode())
+ return;
+ }
+
+ LocalFrame* frame = document.frame();
+ if (!frame)
+ return;
+ FrameView* view = frame->view();
+ if (!view)
+ return;
+
+ double newScaledLeft = left * frame->pageZoomFactor() + view->scrollX();
+ double newScaledTop = top * frame->pageZoomFactor() + view->scrollY();
+ view->setScrollPosition(DoublePoint(newScaledLeft, newScaledTop), scrollBehavior);
+}
+
+void HTMLBodyElement::scrollTo(const ScrollToOptions& scrollToOptions)
+{
+ Document& document = this->document();
+ document.updateLayoutIgnorePendingStylesheets();
+
+ if ((scrollToOptions.hasLeft() && std::isnan(scrollToOptions.left()))
+ || (scrollToOptions.hasTop() && std::isnan(scrollToOptions.top())))
+ return;
+
+ ScrollBehavior scrollBehavior = ScrollBehaviorAuto;
+ ScrollableArea::scrollBehaviorFromString(scrollToOptions.behavior(), scrollBehavior);
+
+ if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
+ RenderBox* render = renderBox();
+ if (!render)
+ return;
+ if (render->hasOverflowClip()) {
+ double scaledLeft = render->scrollLeft();
+ double scaledTop = render->scrollTop();
+ if (scrollToOptions.hasLeft())
+ scaledLeft = scrollToOptions.left() * render->style()->effectiveZoom();
+ if (scrollToOptions.hasTop())
+ scaledTop = scrollToOptions.top() * render->style()->effectiveZoom();
+ // FIXME: Use scrollBehavior to decide whether to scroll smoothly or instantly.
+ render->scrollToOffset(DoubleSize(scaledLeft, scaledTop));
+ return;
+ }
+ if (!document.inQuirksMode())
+ return;
+ }
+
+ LocalFrame* frame = document.frame();
+ if (!frame)
+ return;
+ FrameView* view = frame->view();
+ if (!view)
+ return;
+
+ double scaledLeft = view->scrollX();
+ double scaledTop = view->scrollY();
+ if (scrollToOptions.hasLeft())
+ scaledLeft = scrollToOptions.left() * frame->pageZoomFactor();
+ if (scrollToOptions.hasTop())
+ scaledTop = scrollToOptions.top() * frame->pageZoomFactor();
+ view->setScrollPosition(DoublePoint(scaledLeft, scaledTop), scrollBehavior);
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698