Index: third_party/WebKit/Source/core/dom/Element.cpp |
diff --git a/third_party/WebKit/Source/core/dom/Element.cpp b/third_party/WebKit/Source/core/dom/Element.cpp |
index 36834df69780f4e1f97da8ac9f49a34cb58bb91e..48d8e5ba1844ce6f4698ec352609922556f2bb84 100644 |
--- a/third_party/WebKit/Source/core/dom/Element.cpp |
+++ b/third_party/WebKit/Source/core/dom/Element.cpp |
@@ -26,10 +26,12 @@ |
#include "core/dom/Element.h" |
+#include <memory> |
#include "bindings/core/v8/DOMDataStore.h" |
#include "bindings/core/v8/Dictionary.h" |
#include "bindings/core/v8/ExceptionMessages.h" |
#include "bindings/core/v8/ExceptionState.h" |
+#include "bindings/core/v8/ScrollIntoViewOptionsOrBoolean.h" |
#include "bindings/core/v8/V8DOMActivityLogger.h" |
#include "bindings/core/v8/V8DOMWrapper.h" |
#include "bindings/core/v8/V8PerContextData.h" |
@@ -97,6 +99,7 @@ |
#include "core/frame/HostsUsingFeatures.h" |
#include "core/frame/LocalDOMWindow.h" |
#include "core/frame/LocalFrame.h" |
+#include "core/frame/ScrollIntoViewOptions.h" |
#include "core/frame/ScrollToOptions.h" |
#include "core/frame/Settings.h" |
#include "core/frame/UseCounter.h" |
@@ -131,6 +134,7 @@ |
#include "core/page/scrolling/ScrollCustomizationCallbacks.h" |
#include "core/page/scrolling/ScrollState.h" |
#include "core/page/scrolling/ScrollStateCallback.h" |
+#include "core/page/scrolling/ScrollingCoordinator.h" |
#include "core/page/scrolling/TopDocumentRootScrollerController.h" |
#include "core/paint/PaintLayer.h" |
#include "core/svg/SVGAElement.h" |
@@ -140,13 +144,13 @@ |
#include "platform/RuntimeEnabledFeatures.h" |
#include "platform/graphics/CompositorMutableProperties.h" |
#include "platform/graphics/CompositorMutation.h" |
+#include "platform/scroll/ProgrammaticScrollCoordinator.h" |
#include "platform/scroll/ScrollableArea.h" |
#include "wtf/BitVector.h" |
#include "wtf/HashFunctions.h" |
#include "wtf/text/CString.h" |
#include "wtf/text/StringBuilder.h" |
#include "wtf/text/TextPosition.h" |
-#include <memory> |
namespace blink { |
@@ -428,7 +432,51 @@ bool Element::shouldIgnoreAttributeCase() const { |
return isHTMLElement() && document().isHTMLDocument(); |
} |
+void Element::scrollIntoView(ExceptionState& exception) { |
+ ScrollIntoViewOptions options; |
+ options.setBlock("start"); |
+ options.setInlinePosition("nearest"); |
+ scrollIntoViewWithOptions(options); |
+} |
+ |
+void Element::scrollIntoView(ScrollIntoViewOptionsOrBoolean arg, |
+ ExceptionState& exception) { |
+ ScrollIntoViewOptions options; |
+ if (arg.isBoolean()) { |
+ if (arg.getAsBoolean()) |
+ options.setBlock("start"); |
+ else |
+ options.setBlock("end"); |
+ options.setInlinePosition("nearest"); |
+ } else if (arg.isScrollIntoViewOptions()) { |
+ options = arg.getAsScrollIntoViewOptions(); |
+ if (!RuntimeEnabledFeatures::cssomSmoothScrollEnabled() && |
+ options.behavior() == "smooth") { |
+ exception.throwTypeError( |
+ "Smooth ScrollIntoView is an Experimental Web" |
bokan
2017/03/28 16:29:53
I don't think we usually throw for a feature being
sunyunjia
2017/04/07 13:53:20
Done.
|
+ " Platform Feature, go to chrome://flags to enable it."); |
+ return; |
+ } |
+ } else { |
+ exception.throwTypeError( |
+ "ScrollIntoView only supports bool or" |
+ " ScrollIntoViewOptions as argument."); |
+ return; |
+ } |
+ scrollIntoViewWithOptions(options); |
+} |
+ |
void Element::scrollIntoView(bool alignToTop) { |
+ ScrollIntoViewOptions options; |
+ if (alignToTop) |
+ options.setBlock("start"); |
+ else |
+ options.setBlock("end"); |
+ options.setInlinePosition("nearest"); |
+ scrollIntoViewWithOptions(options); |
+} |
+ |
+void Element::scrollIntoViewWithOptions(const ScrollIntoViewOptions& options) { |
document().updateStyleAndLayoutIgnorePendingStylesheetsForNode(this); |
if (!layoutObject()) |
@@ -437,18 +485,40 @@ void Element::scrollIntoView(bool alignToTop) { |
bool makeVisibleInVisualViewport = |
!document().page()->settings().getInertVisualViewport(); |
+ ScrollBehavior behavior = ScrollBehaviorAuto; |
+ if (options.behavior() == "smooth") { |
+ behavior = ScrollBehaviorSmooth; |
+ } |
+ // Block Alignment to the top / bottom and to the closest edge. |
+ ScrollAlignment blockAlignment = ScrollAlignment::alignTopAlways; |
+ if (options.block() == "center") |
+ blockAlignment = ScrollAlignment::alignCenterAlways; |
+ else if (options.block() == "end") |
+ blockAlignment = ScrollAlignment::alignBottomAlways; |
+ else if (options.block() == "nearest") |
+ blockAlignment = ScrollAlignment::alignToEdgeIfNeeded; |
+ |
+ // Inline Alignment to the top / bottom and to the closest edge. |
+ ScrollAlignment inlineAlignment = ScrollAlignment::alignToEdgeIfNeeded; |
+ if (options.inlinePosition() == "start") |
+ inlineAlignment = ScrollAlignment::alignLeftAlways; |
+ else if (options.inlinePosition() == "center") |
+ inlineAlignment = ScrollAlignment::alignCenterAlways; |
+ else if (options.inlinePosition() == "end") |
+ inlineAlignment = ScrollAlignment::alignRightAlways; |
+ |
LayoutRect bounds = boundingBox(); |
- // Align to the top / bottom and to the closest edge. |
- if (alignToTop) |
- layoutObject()->scrollRectToVisible( |
- bounds, ScrollAlignment::alignToEdgeIfNeeded, |
- ScrollAlignment::alignTopAlways, ProgrammaticScroll, |
- makeVisibleInVisualViewport); |
- else |
- layoutObject()->scrollRectToVisible( |
- bounds, ScrollAlignment::alignToEdgeIfNeeded, |
- ScrollAlignment::alignBottomAlways, ProgrammaticScroll, |
- makeVisibleInVisualViewport); |
+ layoutObject()->scrollRectToVisible(bounds, inlineAlignment, blockAlignment, |
+ ProgrammaticScroll, |
+ makeVisibleInVisualViewport, behavior); |
+ |
+ if (document().page()->scrollingCoordinator()) { |
+ document() |
+ .page() |
+ ->scrollingCoordinator() |
+ ->programmaticScrollCoordinator() |
+ ->runQueuedAnimations(); |
+ } |
document().setSequentialFocusNavigationStartingPoint(this); |
} |