Index: Source/core/dom/Element.cpp |
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp |
index c69348e34641b001dad546df2a175dd3c422cf6d..6a805ece91c01398d1d00de3a654aaa5f0a36807 100644 |
--- a/Source/core/dom/Element.cpp |
+++ b/Source/core/dom/Element.cpp |
@@ -30,6 +30,7 @@ |
#include "bindings/core/v8/Dictionary.h" |
#include "bindings/core/v8/ExceptionMessages.h" |
#include "bindings/core/v8/ExceptionState.h" |
+#include "bindings/core/v8/ToV8.h" |
#include "bindings/core/v8/V8DOMWrapper.h" |
#include "bindings/core/v8/V8PerContextData.h" |
#include "core/CSSValueKeywords.h" |
@@ -113,6 +114,7 @@ |
#include "core/page/PointerLockController.h" |
#include "core/page/SpatialNavigation.h" |
#include "core/page/scrolling/ScrollState.h" |
+#include "core/page/scrolling/ScrollStateCallback.h" |
#include "core/paint/DeprecatedPaintLayer.h" |
#include "core/svg/SVGDocumentExtensions.h" |
#include "core/svg/SVGElement.h" |
@@ -470,7 +472,59 @@ void Element::scrollIntoViewIfNeeded(bool centerIfNeeded) |
layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded); |
} |
-void Element::distributeScroll(ScrollState& scrollState) |
+namespace { |
+ |
+class DistributeScrollCallback : public ScrollStateCallback { |
haraken
2015/06/30 07:08:30
We should define this in ScrollStateCallback.h (or
|
+public: |
+ DistributeScrollCallback() { m_callbackType = CallbackType::DISTRIBUTE_SCROLL; } |
+ void handleEvent(ScrollState* scrollState) |
+ { |
+ ASSERT(m_targetElement); |
+ ASSERT(scrollState); |
+ m_targetElement->nativeDistributeScroll(*scrollState); |
+ } |
+}; |
+ |
+class ApplyScrollCallback : public ScrollStateCallback { |
haraken
2015/06/30 07:08:30
Ditto.
|
+public: |
+ ApplyScrollCallback() { m_callbackType = CallbackType::APPLY_SCROLL; } |
+ void handleEvent(ScrollState* scrollState) |
+ { |
+ ASSERT(m_targetElement); |
+ ASSERT(scrollState); |
+ m_targetElement->nativeApplyScroll(*scrollState); |
+ } |
+}; |
+ |
+} // namespace |
+ |
+void Element::setDistributeScroll(ScrollStateCallback* scrollStateCallback) |
+{ |
+ scrollStateCallback->setCallbackType(ScrollStateCallback::CallbackType::DISTRIBUTE_SCROLL); |
+ ensureElementRareData().setDistributeScroll(scrollStateCallback); |
+} |
+ |
+ScriptValue Element::distributeScroll(ScriptState* scriptState) |
+{ |
+ if (!hasRareData() || !elementRareData()->getDistributeScroll()) |
+ setDistributeScroll(new DistributeScrollCallback()); |
haraken
2015/06/30 07:08:30
In a case where we don't have a customized calback
|
+ return elementRareData()->getDistributeScroll()->toScriptValue(scriptState); |
+} |
+ |
+void Element::setApplyScroll(ScrollStateCallback* scrollStateCallback) |
+{ |
+ scrollStateCallback->setCallbackType(ScrollStateCallback::CallbackType::APPLY_SCROLL); |
+ ensureElementRareData().setApplyScroll(scrollStateCallback); |
+} |
+ |
+ScriptValue Element::applyScroll(ScriptState* scriptState) |
+{ |
+ if (!hasRareData() || !elementRareData()->getApplyScroll()) |
+ setApplyScroll(new ApplyScrollCallback()); |
haraken
2015/06/30 07:08:30
Ditto.
|
+ return elementRareData()->getApplyScroll()->toScriptValue(scriptState); |
+} |
+ |
+void Element::nativeDistributeScroll(ScrollState& scrollState) |
{ |
ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
if (scrollState.fullyConsumed()) |
@@ -490,15 +544,25 @@ void Element::distributeScroll(ScrollState& scrollState) |
const double deltaX = scrollState.deltaX(); |
const double deltaY = scrollState.deltaY(); |
- applyScroll(scrollState); |
+ callApplyScroll(scrollState); |
if (deltaX != scrollState.deltaX() || deltaY != scrollState.deltaY()) |
scrollState.setCurrentNativeScrollingElement(this); |
} |
-void Element::applyScroll(ScrollState& scrollState) |
+void Element::callDistributeScroll(ScrollState& scrollState) |
+{ |
+ if (!hasRareData() || !elementRareData()->getDistributeScroll()) |
+ nativeDistributeScroll(scrollState); |
+ else |
+ elementRareData()->getDistributeScroll()->handleEventForElement(*this, &scrollState); |
+}; |
+ |
+void Element::nativeApplyScroll(ScrollState& scrollState) |
{ |
ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled()); |
+ document().updateLayoutIgnorePendingStylesheets(); |
+ |
if (scrollState.fullyConsumed()) |
return; |
@@ -506,8 +570,8 @@ void Element::applyScroll(ScrollState& scrollState) |
const double deltaY = scrollState.deltaY(); |
bool scrolled = false; |
- // Handle the documentElement separately, as it scrolls the FrameView. |
- if (this == document().documentElement()) { |
+ // Handle the scrollingElement separately, as it scrolls the FrameView. |
+ if (this == document().scrollingElement()) { |
FloatSize delta(deltaX, deltaY); |
if (document().frame()->applyScrollDelta(delta, scrollState.isBeginning()).didScroll()) { |
scrolled = true; |
@@ -542,6 +606,14 @@ void Element::applyScroll(ScrollState& scrollState) |
document().frame()->view()->setWasScrolledByUser(true); |
}; |
+void Element::callApplyScroll(ScrollState& scrollState) |
+{ |
+ if (!hasRareData() || !elementRareData()->getApplyScroll()) |
+ nativeApplyScroll(scrollState); |
+ else |
+ elementRareData()->getApplyScroll()->handleEventForElement(*this, &scrollState); |
+}; |
+ |
static float localZoomForLayoutObject(LayoutObject& layoutObject) |
{ |
// FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each |