Index: Source/bindings/v8/custom/V8WebKitNamedFlowCustom.cpp |
diff --git a/Source/bindings/v8/custom/V8WebKitNamedFlowCustom.cpp b/Source/bindings/v8/custom/V8WebKitNamedFlowCustom.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..37b0301447b95db6392e6418e65a23b6440752b5 |
--- /dev/null |
+++ b/Source/bindings/v8/custom/V8WebKitNamedFlowCustom.cpp |
@@ -0,0 +1,85 @@ |
+/* |
+ * Copyright (C) 2013 Adobe Systems Incorporated. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions |
+ * are met: |
+ * |
+ * 1. Redistributions of source code must retain the above |
+ * copyright notice, this list of conditions and the following |
+ * disclaimer. |
+ * 2. Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following |
+ * disclaimer in the documentation and/or other materials |
+ * provided with the distribution. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY |
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE |
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, |
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR |
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
+ * SUCH DAMAGE. |
+ */ |
+ |
+#include "config.h" |
+#include "V8WebKitNamedFlow.h" |
+ |
+#include "V8HTMLElement.h" |
+#include "V8PseudoElement.h" |
+ |
abarth-chromium
2013/11/14 07:55:15
no need for this blank line
|
+#include "bindings/v8/V8Binding.h" |
+#include "core/dom/NamedFlow.h" |
+#include "core/rendering/RenderRegion.h" |
+ |
abarth-chromium
2013/11/14 07:55:15
ditto
|
+#include "wtf/RefPtr.h" |
+#include "wtf/Vector.h" |
+ |
+namespace WebCore { |
+ |
+static v8::Handle<v8::Value> toV8Array(Vector<const RenderRegion*>& regionsList, v8::Handle<v8::Object> creationContext, v8::Isolate* isolate) |
abarth-chromium
2013/11/14 07:55:15
regionsList -> regions
|
+{ |
+ v8::Local<v8::Array> result = v8::Array::New(regionsList.size()); |
abarth-chromium
2013/11/14 07:55:15
If script has replaced the global Array constructo
abucur
2013/11/15 07:15:14
Good point, I agree it's a problem if this code ex
|
+ |
+ int index = 0; |
+ Vector<const RenderRegion*>::const_iterator end = regionsList.end(); |
+ for (Vector<const RenderRegion*>::const_iterator iter = regionsList.begin(); iter != end; ++iter) { |
+ const RenderRegion* region = *iter; |
+ Element* generator = region->element(); |
+ if (!generator) |
+ continue; |
abarth-chromium
2013/11/14 07:55:15
When can this happen?
abucur
2013/11/15 07:15:14
At this moment, never. It's better to make it an A
|
+ if (generator->isHTMLElement()) |
+ result->Set(v8::Integer::New(index++, isolate), toV8(toHTMLElement(generator), creationContext, isolate)); |
+ else if (generator->isPseudoElement()) |
+ result->Set(v8::Integer::New(index++, isolate), toV8(toPseudoElement(generator), creationContext, isolate)); |
+ else |
+ ASSERT_NOT_REACHED(); |
abarth-chromium
2013/11/14 07:55:15
Why can't it be a non-HTML element?
abucur
2013/11/15 07:15:14
At this moment only blocks can become regions (I s
|
+ } |
+ |
+ return result; |
+} |
+ |
+void V8WebKitNamedFlow::getRegionsMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) |
+{ |
+ NamedFlow* imp = V8WebKitNamedFlow::toNative(args.Holder()); |
+ Vector<const RenderRegion*> regionsList = imp->getRegions(); |
+ |
+ v8SetReturnValue(args, toV8Array(regionsList, args.Holder(), args.GetIsolate())); |
+} |
+ |
+void V8WebKitNamedFlow::getRegionsByContentMethodCustom(const v8::FunctionCallbackInfo<v8::Value>& args) |
+{ |
+ NamedFlow* imp = V8WebKitNamedFlow::toNative(args.Holder()); |
+ |
+ V8TRYCATCH_VOID(Node*, node, V8Node::HasInstance(args[1], args.GetIsolate(), worldType(args.GetIsolate())) ? V8Node::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0); |
abarth-chromium
2013/11/14 07:55:15
What about args[0]? What if there are zero or one
abucur
2013/11/15 07:15:14
Oh, I don't know why I had the feeling args[0] was
|
+ Vector<const RenderRegion*> regionsList = imp->getRegionsByContent(node); |
+ |
+ v8SetReturnValue(args, toV8Array(regionsList, args.Holder(), args.GetIsolate())); |
+} |
+ |
+} // namespace WebCore |