| Index: Source/core/dom/Element.cpp
|
| diff --git a/Source/core/dom/Element.cpp b/Source/core/dom/Element.cpp
|
| index c14c52345eacf4a9e133f109554e4dc7c945bd2c..262a7488de06d16765c10fbf376c03b777181d00 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"
|
| @@ -113,6 +115,7 @@
|
| #include "core/page/Page.h"
|
| #include "core/page/PointerLockController.h"
|
| #include "core/page/SpatialNavigation.h"
|
| +#include "core/page/scrolling/ScrollState.h"
|
| #include "core/svg/SVGDocumentExtensions.h"
|
| #include "core/svg/SVGElement.h"
|
| #include "platform/EventDispatchForbiddenScope.h"
|
| @@ -481,6 +484,121 @@ void Element::scrollIntoViewIfNeeded(bool centerIfNeeded)
|
| renderer()->scrollRectToVisible(bounds, ScrollAlignment::alignToEdgeIfNeeded, ScrollAlignment::alignToEdgeIfNeeded);
|
| }
|
|
|
| +// 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::callDistributeScroll(ScrollState* scrollState)
|
| +{
|
| + if (!callScrollCustomizationV8Method(this, scrollState, "distributeScroll"))
|
| + distributeScroll(scrollState);
|
| +};
|
| +
|
| +void Element::distributeScroll(ScrollState* scrollState)
|
| +{
|
| + ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
|
| + if (!scrollState) {
|
| + // FIXME: Ideally we'd throw an exception here...
|
| + fprintf(stderr, "WE SHOULD HANDLE THIS CASE BETTER\n");
|
| + return;
|
| + }
|
| +
|
| + if (scrollState->fullyConsumed())
|
| + return;
|
| +
|
| + scrollState->distributeToScrollChainDescendant();
|
| +
|
| + if (!scrollState->shouldPropagate() && scrollState->scrollLockedToElement() && scrollState->currentNativeScrollingElement() != this)
|
| + return;
|
| +
|
| + const double deltaX = scrollState->deltaX();
|
| + const double deltaY = scrollState->deltaY();
|
| +
|
| + callApplyScroll(scrollState);
|
| +
|
| + bool scrolled = deltaX != scrollState->deltaX() || deltaY != scrollState->deltaY();
|
| + if (scrolled)
|
| + scrollState->setCurrentNativeScrollingElement(this);
|
| +}
|
| +
|
| +void Element::callApplyScroll(ScrollState* scrollState)
|
| +{
|
| + if (!callScrollCustomizationV8Method(this, scrollState, "applyScroll"))
|
| + applyScroll(scrollState);
|
| +}
|
| +
|
| +void Element::applyScroll(ScrollState* scrollState)
|
| +{
|
| + ASSERT(RuntimeEnabledFeatures::scrollCustomizationEnabled());
|
| +
|
| + if (!scrollState) {
|
| + // FIXME: Ideally we'd throw an exception here...
|
| + fprintf(stderr, "WE SHOULD HANDLE THIS CASE BETTER\n");
|
| + return;
|
| + }
|
| +
|
| + const double deltaX = scrollState->deltaX();
|
| + const double deltaY = scrollState->deltaY();
|
| + bool scrolled = false;
|
| +
|
| + if (scrollState->fullyConsumed())
|
| + return;
|
| +
|
| + // Handle the documentElement separately, as it scrolls the FrameView.
|
| + if (this == document().documentElement()) {
|
| + FloatSize delta(deltaX, deltaY);
|
| + if (!document().frame()->scrollByDelta(delta))
|
| + return;
|
| + scrolled = true;
|
| + } else {
|
| + LayoutBox* curBox = renderer()->enclosingBox();
|
| + if (deltaX && curBox->scroll(ScrollLeft, ScrollByPrecisePixel, deltaX))
|
| + scrolled = true;
|
| +
|
| + if (deltaY && curBox->scroll(ScrollUp, ScrollByPrecisePixel, deltaY))
|
| + scrolled = true;
|
| + }
|
| +
|
| + if (scrolled) {
|
| + scrollState->consumeDeltaNative(scrollState->deltaX(), scrollState->deltaY());
|
| +
|
| + // We need to setCurrentNativeScrollingElement in both the
|
| + // distributeScroll and applyScroll default implementations so
|
| + // that if the user overrides one of these methods, but not the
|
| + // other, this bookkeeping remains accurate.
|
| + scrollState->setCurrentNativeScrollingElement(this);
|
| +
|
| + if (scrollState->fromUserInput())
|
| + document().frame()->view()->setWasScrolledByUser(true);
|
| + }
|
| +};
|
| +
|
| static float localZoomForRenderer(LayoutObject& renderer)
|
| {
|
| // FIXME: This does the wrong thing if two opposing zooms are in effect and canceled each
|
|
|