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

Unified Diff: Source/core/dom/Element.cpp

Issue 1057603002: Expose scroll customization for touch to JS (behind REF). (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix case where documentElement was added to scroll chain twice. Created 5 years, 8 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: Source/core/dom/Element.cpp
diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
index 71191c2d41e13f567b68072831047999af2ca051..f9ac92895cf5069982d831c00d16cc7e4634ace0 100644
--- a/Source/core/dom/Element.cpp
+++ b/Source/core/dom/Element.cpp
@@ -30,6 +30,8 @@
#include "bindings/core/v8/Dictionary.h"
#include "bindings/core/v8/ExceptionMessages.h"
#include "bindings/core/v8/ExceptionState.h"
+#include "bindings/core/v8/ScriptFunctionCall.h"
+#include "bindings/core/v8/ToV8.h"
#include "bindings/core/v8/V8DOMWrapper.h"
#include "bindings/core/v8/V8PerContextData.h"
#include "core/CSSValueKeywords.h"
@@ -489,7 +491,38 @@ void Element::scrollIntoViewIfNeeded(bool centerIfNeeded)
layoutObject()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
}
-void Element::distributeScroll(ScrollState& scrollState)
+// Returns true iff a V8 method existed and was called.
+static bool callScrollCustomizationV8Method(Element* element,
+ ScrollState& scrollState, String methodName)
+{
+ ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
+
+ LocalFrame* frame = element->document().frame();
+ if (!frame)
+ return false;
+ ScriptState* scriptState = ScriptState::forMainWorld(frame);
+ ScriptState::Scope scope(scriptState);
+
+ v8::Handle<v8::Object> creationContext = scriptState->context()->Global();
+ ScriptValue thisWrapper = ScriptValue(scriptState, toV8(element, creationContext, scriptState->isolate()));
+ ScriptValue scrollStateWrapper = ScriptValue(scriptState, toV8(&scrollState, creationContext, scriptState->isolate()));
+
+ v8::Handle<v8::Object> thisObject = v8::Handle<v8::Object>::Cast(thisWrapper.v8Value());
+ v8::Local<v8::Value> functionValue = thisObject->Get(v8String(scriptState->isolate(), methodName));
+ ASSERT(functionValue->IsFunction());
+ v8::Local<v8::Function> function = v8::Local<v8::Function>::Cast(functionValue);
+
+ // Native methods should avoid the performance overhead of a v8 method call.
+ if (function->ScriptId() == v8::UnboundScript::kNoScriptId)
+ return false;
+
+ ScriptFunctionCall functionCall(thisWrapper, methodName);
+ functionCall.appendArgument(scrollStateWrapper);
+ functionCall.call();
+ return true;
+}
+
+void Element::distributeScrollNative(ScrollState& scrollState)
{
ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
if (scrollState.fullyConsumed())
@@ -509,13 +542,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 (!callScrollCustomizationV8Method(this, scrollState, "distributeScroll"))
+ distributeScrollNative(scrollState);
+};
+
+void Element::distributeScroll(ScrollState* scrollState)
+{
+ ASSERT(scrollState);
+ distributeScrollNative(*scrollState);
+}
+
+void Element::applyScrollNative(ScrollState& scrollState)
{
ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
if (scrollState.fullyConsumed())
@@ -561,6 +606,18 @@ void Element::applyScroll(ScrollState& scrollState)
document().frame()->view()->setWasScrolledByUser(true);
};
+void Element::callApplyScroll(ScrollState& scrollState)
+{
+ if (!callScrollCustomizationV8Method(this, scrollState, "applyScroll"))
+ applyScrollNative(scrollState);
+};
+
+void Element::applyScroll(ScrollState* scrollState)
+{
+ ASSERT(scrollState);
+ applyScrollNative(*scrollState);
+}
+
static float localZoomForRenderer(LayoutObject& renderer)
{
// FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each

Powered by Google App Engine
This is Rietveld 408576698