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

Side by Side Diff: third_party/WebKit/Source/core/page/scrolling/snap/SnapManagerBridge.cpp

Issue 1333323003: SnapManager implementation using V8 Extras - {WIP} Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Update with latest master Created 4 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/page/scrolling/snap/SnapManagerBridge.h"
6
7 #include "bindings/core/v8/V8ObjectConstructor.h"
8 #include "core/dom/Document.h"
9 #include "core/dom/Element.h"
10 #include "core/frame/DOMWindow.h"
11 #include "core/frame/LocalDOMWindow.h"
12 #include "core/layout/LayoutBox.h"
13 #include "wtf/Vector.h"
14
15 #include <v8.h>
16
17 namespace blink {
18
19 SnapManagerBridge::SnapManagerBridge(const Document* document)
20 : m_document(document)
21 {
22 }
23
24 void SnapManagerBridge::maybeCreateSnapManagerInstance()
25 {
26 if (!m_instance.isEmpty())
27 return;
28
29 m_scriptState = ScriptState::forMainWorld(m_document->frame());
30 ScriptState::Scope scope(m_scriptState.get());
31
32 // Pass in window
33 v8::Local<v8::Value> args[] = {toV8(m_document->domWindow(), m_scriptState-> context()->Global(), m_scriptState->isolate())};
34 v8::MaybeLocal<v8::Value> result = V8ScriptRunner::callExtra(m_scriptState.g et(), "CreateSnapManager", args);
35
36 v8::Local<v8::Value> managerInstance;
37 if (result.ToLocal(&managerInstance)) {
38 m_instance = ScriptValue(m_scriptState.get(), managerInstance.As<v8::Obj ect>());
39 } else {
40 NOTREACHED() << "Couldn't instantiate SnapManager";
41 }
42 }
43
44 void SnapManagerBridge::didUpdateSnapOffsets(const LayoutBox& box, SnapOffsets o ffsets)
45 {
46 maybeCreateSnapManagerInstance();
47 Node* container = box.node();
48
49 ScriptState::Scope scope(m_scriptState.get());
50 v8::Local<v8::Value> containerWrapper = toV8(container, m_scriptState->conte xt()->Global(), m_scriptState->isolate());
51 v8::Local<v8::Value> horizontalOffsetsWrapper = toV8(offsets.horizontal, m_s criptState->context()->Global(), m_scriptState->isolate());
52 v8::Local<v8::Value> verticalOffsetsWrapper = toV8(offsets.vertical, m_scrip tState->context()->Global(), m_scriptState->isolate());
53
54 v8::Local<v8::Value> args[] = { m_instance.v8Value(), containerWrapper, hori zontalOffsetsWrapper, verticalOffsetsWrapper};
55
56 V8ScriptRunner::callExtra(m_scriptState.get(), "UpdateSnapContainer", args);
57 }
58
59 } // namespace blink
60
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698