| Index: third_party/WebKit/Source/core/page/scrolling/snap/SnapManagerBridge.cpp
|
| diff --git a/third_party/WebKit/Source/core/page/scrolling/snap/SnapManagerBridge.cpp b/third_party/WebKit/Source/core/page/scrolling/snap/SnapManagerBridge.cpp
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..f83ea8b3602ec272a2eb6ee76dc2ec1141da1bcb
|
| --- /dev/null
|
| +++ b/third_party/WebKit/Source/core/page/scrolling/snap/SnapManagerBridge.cpp
|
| @@ -0,0 +1,60 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "core/page/scrolling/snap/SnapManagerBridge.h"
|
| +
|
| +#include "bindings/core/v8/V8ObjectConstructor.h"
|
| +#include "core/dom/Document.h"
|
| +#include "core/dom/Element.h"
|
| +#include "core/frame/DOMWindow.h"
|
| +#include "core/frame/LocalDOMWindow.h"
|
| +#include "core/layout/LayoutBox.h"
|
| +#include "wtf/Vector.h"
|
| +
|
| +#include <v8.h>
|
| +
|
| +namespace blink {
|
| +
|
| +SnapManagerBridge::SnapManagerBridge(const Document* document)
|
| + : m_document(document)
|
| +{
|
| +}
|
| +
|
| +void SnapManagerBridge::maybeCreateSnapManagerInstance()
|
| +{
|
| + if (!m_instance.isEmpty())
|
| + return;
|
| +
|
| + m_scriptState = ScriptState::forMainWorld(m_document->frame());
|
| + ScriptState::Scope scope(m_scriptState.get());
|
| +
|
| + // Pass in window
|
| + v8::Local<v8::Value> args[] = {toV8(m_document->domWindow(), m_scriptState->context()->Global(), m_scriptState->isolate())};
|
| + v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(m_scriptState.get(), "CreateSnapManager", args);
|
| +
|
| + v8::Local<v8::Value> managerInstance;
|
| + if (result.ToLocal(&managerInstance)) {
|
| + m_instance = ScriptValue(m_scriptState.get(), managerInstance.As<v8::Object>());
|
| + } else {
|
| + NOTREACHED() << "Couldn't instantiate SnapManager";
|
| + }
|
| +}
|
| +
|
| +void SnapManagerBridge::didUpdateSnapOffsets(const LayoutBox& box, SnapOffsets offsets)
|
| +{
|
| + maybeCreateSnapManagerInstance();
|
| + Node* container = box.node();
|
| +
|
| + ScriptState::Scope scope(m_scriptState.get());
|
| + v8::Local<v8::Value> containerWrapper = toV8(container, m_scriptState->context()->Global(), m_scriptState->isolate());
|
| + v8::Local<v8::Value> horizontalOffsetsWrapper = toV8(offsets.horizontal, m_scriptState->context()->Global(), m_scriptState->isolate());
|
| + v8::Local<v8::Value> verticalOffsetsWrapper = toV8(offsets.vertical, m_scriptState->context()->Global(), m_scriptState->isolate());
|
| +
|
| + v8::Local<v8::Value> args[] = { m_instance.v8Value(), containerWrapper, horizontalOffsetsWrapper, verticalOffsetsWrapper};
|
| +
|
| + V8ScriptRunner::callExtra(m_scriptState.get(), "UpdateSnapContainer", args);
|
| +}
|
| +
|
| +} // namespace blink
|
| +
|
|
|