summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/bindings')
-rw-r--r--WebCore/bindings/js/GCController.cpp93
-rw-r--r--WebCore/bindings/js/GCController.h55
-rw-r--r--WebCore/bindings/js/JSAttrCustom.cpp60
-rw-r--r--WebCore/bindings/js/JSAudioConstructor.cpp71
-rw-r--r--WebCore/bindings/js/JSAudioConstructor.h48
-rw-r--r--WebCore/bindings/js/JSCSSRuleCustom.cpp84
-rw-r--r--WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp172
-rw-r--r--WebCore/bindings/js/JSCSSValueCustom.cpp72
-rw-r--r--WebCore/bindings/js/JSCanvasPixelArrayCustom.cpp74
-rw-r--r--WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp356
-rw-r--r--WebCore/bindings/js/JSCustomSQLStatementCallback.cpp106
-rw-r--r--WebCore/bindings/js/JSCustomSQLStatementCallback.h59
-rw-r--r--WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp112
-rw-r--r--WebCore/bindings/js/JSCustomSQLStatementErrorCallback.h60
-rw-r--r--WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp157
-rw-r--r--WebCore/bindings/js/JSCustomSQLTransactionCallback.h58
-rw-r--r--WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp104
-rw-r--r--WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h59
-rw-r--r--WebCore/bindings/js/JSCustomVoidCallback.cpp118
-rw-r--r--WebCore/bindings/js/JSCustomVoidCallback.h60
-rw-r--r--WebCore/bindings/js/JSCustomXPathNSResolver.cpp135
-rw-r--r--WebCore/bindings/js/JSCustomXPathNSResolver.h64
-rw-r--r--WebCore/bindings/js/JSDOMWindowCustom.cpp161
-rw-r--r--WebCore/bindings/js/JSDatabaseCustom.cpp130
-rw-r--r--WebCore/bindings/js/JSDocumentCustom.cpp111
-rw-r--r--WebCore/bindings/js/JSElementCustom.cpp123
-rw-r--r--WebCore/bindings/js/JSEventCustom.cpp114
-rw-r--r--WebCore/bindings/js/JSEventTargetBase.cpp244
-rw-r--r--WebCore/bindings/js/JSEventTargetBase.h155
-rw-r--r--WebCore/bindings/js/JSEventTargetNode.cpp88
-rw-r--r--WebCore/bindings/js/JSEventTargetNode.h72
-rw-r--r--WebCore/bindings/js/JSHTMLAllCollection.h48
-rw-r--r--WebCore/bindings/js/JSHTMLAppletElementCustom.cpp67
-rw-r--r--WebCore/bindings/js/JSHTMLCollectionCustom.cpp151
-rw-r--r--WebCore/bindings/js/JSHTMLDocumentCustom.cpp145
-rw-r--r--WebCore/bindings/js/JSHTMLElementCustom.cpp52
-rw-r--r--WebCore/bindings/js/JSHTMLElementWrapperFactory.cpp273
-rw-r--r--WebCore/bindings/js/JSHTMLElementWrapperFactory.h37
-rw-r--r--WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp67
-rw-r--r--WebCore/bindings/js/JSHTMLFormElementCustom.cpp59
-rw-r--r--WebCore/bindings/js/JSHTMLFrameElementCustom.cpp72
-rw-r--r--WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp61
-rw-r--r--WebCore/bindings/js/JSHTMLIFrameElementCustom.cpp53
-rw-r--r--WebCore/bindings/js/JSHTMLInputElementBase.cpp113
-rw-r--r--WebCore/bindings/js/JSHTMLInputElementBase.h52
-rw-r--r--WebCore/bindings/js/JSHTMLObjectElementCustom.cpp67
-rw-r--r--WebCore/bindings/js/JSHTMLOptionElementConstructor.cpp70
-rw-r--r--WebCore/bindings/js/JSHTMLOptionElementConstructor.h39
-rw-r--r--WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp98
-rw-r--r--WebCore/bindings/js/JSHTMLSelectElementCustom.cpp70
-rw-r--r--WebCore/bindings/js/JSHTMLSelectElementCustom.h40
-rw-r--r--WebCore/bindings/js/JSHistoryCustom.cpp99
-rw-r--r--WebCore/bindings/js/JSLocation.cpp313
-rw-r--r--WebCore/bindings/js/JSLocation.h71
-rw-r--r--WebCore/bindings/js/JSNamedNodeMapCustom.cpp48
-rw-r--r--WebCore/bindings/js/JSNamedNodesCollection.cpp90
-rw-r--r--WebCore/bindings/js/JSNamedNodesCollection.h56
-rw-r--r--WebCore/bindings/js/JSNodeCustom.cpp222
-rw-r--r--WebCore/bindings/js/JSNodeFilterCondition.cpp84
-rw-r--r--WebCore/bindings/js/JSNodeFilterCondition.h45
-rw-r--r--WebCore/bindings/js/JSNodeFilterCustom.cpp68
-rw-r--r--WebCore/bindings/js/JSNodeIteratorCustom.cpp72
-rw-r--r--WebCore/bindings/js/JSNodeListCustom.cpp65
-rw-r--r--WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp81
-rw-r--r--WebCore/bindings/js/JSSQLTransactionCustom.cpp114
-rw-r--r--WebCore/bindings/js/JSSVGElementWrapperFactory.cpp316
-rw-r--r--WebCore/bindings/js/JSSVGElementWrapperFactory.h41
-rw-r--r--WebCore/bindings/js/JSSVGLazyEventListener.cpp46
-rw-r--r--WebCore/bindings/js/JSSVGLazyEventListener.h42
-rw-r--r--WebCore/bindings/js/JSSVGMatrixCustom.cpp135
-rw-r--r--WebCore/bindings/js/JSSVGPODTypeWrapper.h286
-rw-r--r--WebCore/bindings/js/JSSVGPathSegCustom.cpp116
-rw-r--r--WebCore/bindings/js/JSSVGPathSegListCustom.cpp166
-rw-r--r--WebCore/bindings/js/JSSVGPointListCustom.cpp190
-rw-r--r--WebCore/bindings/js/JSSVGTransformListCustom.cpp190
-rw-r--r--WebCore/bindings/js/JSStyleSheetCustom.cpp55
-rw-r--r--WebCore/bindings/js/JSStyleSheetListCustom.cpp50
-rw-r--r--WebCore/bindings/js/JSTreeWalkerCustom.cpp117
-rw-r--r--WebCore/bindings/js/JSXMLHttpRequest.cpp400
-rw-r--r--WebCore/bindings/js/JSXMLHttpRequest.h78
-rw-r--r--WebCore/bindings/js/JSXSLTProcessor.cpp208
-rw-r--r--WebCore/bindings/js/JSXSLTProcessor.h76
-rw-r--r--WebCore/bindings/js/PausedTimeouts.cpp41
-rw-r--r--WebCore/bindings/js/PausedTimeouts.h57
-rw-r--r--WebCore/bindings/js/ScheduledAction.cpp102
-rw-r--r--WebCore/bindings/js/ScheduledAction.h58
-rw-r--r--WebCore/bindings/js/kjs_binding.cpp378
-rw-r--r--WebCore/bindings/js/kjs_binding.h152
-rw-r--r--WebCore/bindings/js/kjs_css.cpp85
-rw-r--r--WebCore/bindings/js/kjs_css.h55
-rw-r--r--WebCore/bindings/js/kjs_dom.cpp108
-rw-r--r--WebCore/bindings/js/kjs_dom.h41
-rw-r--r--WebCore/bindings/js/kjs_events.cpp518
-rw-r--r--WebCore/bindings/js/kjs_events.h132
-rw-r--r--WebCore/bindings/js/kjs_html.cpp142
-rw-r--r--WebCore/bindings/js/kjs_html.h57
-rw-r--r--WebCore/bindings/js/kjs_navigator.cpp620
-rw-r--r--WebCore/bindings/js/kjs_navigator.h51
-rw-r--r--WebCore/bindings/js/kjs_proxy.cpp196
-rw-r--r--WebCore/bindings/js/kjs_proxy.h89
-rw-r--r--WebCore/bindings/js/kjs_window.cpp1503
-rw-r--r--WebCore/bindings/js/kjs_window.h191
-rw-r--r--WebCore/bindings/objc/DOM.h36
-rw-r--r--WebCore/bindings/objc/DOM.mm815
-rw-r--r--WebCore/bindings/objc/DOMCSS.h296
-rw-r--r--WebCore/bindings/objc/DOMCSS.mm1443
-rw-r--r--WebCore/bindings/objc/DOMCore.h45
-rw-r--r--WebCore/bindings/objc/DOMCustomXPathNSResolver.h56
-rw-r--r--WebCore/bindings/objc/DOMCustomXPathNSResolver.mm58
-rw-r--r--WebCore/bindings/objc/DOMEventException.h33
-rw-r--r--WebCore/bindings/objc/DOMEvents.h44
-rw-r--r--WebCore/bindings/objc/DOMEvents.mm115
-rw-r--r--WebCore/bindings/objc/DOMException.h48
-rw-r--r--WebCore/bindings/objc/DOMExtensions.h62
-rw-r--r--WebCore/bindings/objc/DOMHTML.h86
-rw-r--r--WebCore/bindings/objc/DOMHTML.mm187
-rw-r--r--WebCore/bindings/objc/DOMImplementationFront.cpp82
-rw-r--r--WebCore/bindings/objc/DOMImplementationFront.h61
-rw-r--r--WebCore/bindings/objc/DOMInternal.h356
-rw-r--r--WebCore/bindings/objc/DOMInternal.mm126
-rw-r--r--WebCore/bindings/objc/DOMObject.h48
-rw-r--r--WebCore/bindings/objc/DOMObject.mm100
-rw-r--r--WebCore/bindings/objc/DOMPrivate.h130
-rw-r--r--WebCore/bindings/objc/DOMRGBColor.mm162
-rw-r--r--WebCore/bindings/objc/DOMRangeException.h34
-rw-r--r--WebCore/bindings/objc/DOMRanges.h28
-rw-r--r--WebCore/bindings/objc/DOMSVG.h169
-rw-r--r--WebCore/bindings/objc/DOMSVGException.h35
-rw-r--r--WebCore/bindings/objc/DOMSVGPathSegInternal.mm154
-rw-r--r--WebCore/bindings/objc/DOMStylesheets.h33
-rw-r--r--WebCore/bindings/objc/DOMTraversal.h48
-rw-r--r--WebCore/bindings/objc/DOMUtility.mm126
-rw-r--r--WebCore/bindings/objc/DOMViews.h31
-rw-r--r--WebCore/bindings/objc/DOMXPath.h34
-rw-r--r--WebCore/bindings/objc/DOMXPath.mm94
-rw-r--r--WebCore/bindings/objc/DOMXPathException.h34
-rw-r--r--WebCore/bindings/objc/ExceptionHandlers.h58
-rw-r--r--WebCore/bindings/objc/ExceptionHandlers.mm74
-rw-r--r--WebCore/bindings/objc/PublicDOMInterfaces.h1092
-rw-r--r--WebCore/bindings/objc/WebScriptObject.h313
-rw-r--r--WebCore/bindings/objc/WebScriptObject.mm655
-rw-r--r--WebCore/bindings/objc/WebScriptObjectPrivate.h68
-rw-r--r--WebCore/bindings/scripts/CodeGenerator.pm382
-rw-r--r--WebCore/bindings/scripts/CodeGeneratorCOM.pm1313
-rw-r--r--WebCore/bindings/scripts/CodeGeneratorJS.pm1864
-rw-r--r--WebCore/bindings/scripts/CodeGeneratorObjC.pm1626
-rw-r--r--WebCore/bindings/scripts/IDLParser.pm416
-rw-r--r--WebCore/bindings/scripts/IDLStructure.pm107
-rwxr-xr-xWebCore/bindings/scripts/generate-bindings.pl69
149 files changed, 26771 insertions, 0 deletions
diff --git a/WebCore/bindings/js/GCController.cpp b/WebCore/bindings/js/GCController.cpp
new file mode 100644
index 0000000..94c48a1
--- /dev/null
+++ b/WebCore/bindings/js/GCController.cpp
@@ -0,0 +1,93 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "GCController.h"
+
+#include <kjs/JSLock.h>
+#include <kjs/collector.h>
+
+#if USE(PTHREADS)
+#include <pthread.h>
+#endif
+
+using namespace KJS;
+
+namespace WebCore {
+
+#if USE(PTHREADS)
+
+static void* collect(void*)
+{
+ JSLock lock;
+ Collector::collect();
+ return 0;
+}
+
+#endif
+
+GCController& gcController()
+{
+ static GCController staticGCController;
+ return staticGCController;
+}
+
+GCController::GCController()
+ : m_GCTimer(this, &GCController::gcTimerFired)
+{
+}
+
+void GCController::garbageCollectSoon()
+{
+ if (!m_GCTimer.isActive())
+ m_GCTimer.startOneShot(0);
+}
+
+void GCController::gcTimerFired(Timer<GCController>*)
+{
+ JSLock lock;
+ Collector::collect();
+}
+
+void GCController::garbageCollectNow()
+{
+ JSLock lock;
+ Collector::collect();
+}
+
+void GCController::garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone)
+{
+#if USE(PTHREADS)
+ pthread_t thread;
+ pthread_create(&thread, NULL, collect, NULL);
+
+ if (waitUntilDone) {
+ JSLock::DropAllLocks dropLocks; // Otherwise our lock would deadlock the collect thread we're joining
+ pthread_join(thread, NULL);
+ }
+#endif
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/GCController.h b/WebCore/bindings/js/GCController.h
new file mode 100644
index 0000000..452019a
--- /dev/null
+++ b/WebCore/bindings/js/GCController.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef GCController_h
+#define GCController_h
+
+#include <wtf/Noncopyable.h>
+#include "Timer.h"
+
+namespace WebCore {
+
+ class GCController : Noncopyable {
+ friend GCController& gcController();
+
+ public:
+ void garbageCollectSoon();
+ void garbageCollectNow(); // It's better to call garbageCollectSoon, unless you have a specific reason not to.
+
+ void garbageCollectOnAlternateThreadForDebugging(bool waitUntilDone); // Used for stress testing.
+
+ private:
+ GCController(); // Use gcController() instead
+ void gcTimerFired(Timer<GCController>*);
+
+ Timer<GCController> m_GCTimer;
+ };
+
+ // Function to obtain the global GC controller.
+ GCController& gcController();
+
+} // namespace WebCore
+
+#endif // GCController_h
diff --git a/WebCore/bindings/js/JSAttrCustom.cpp b/WebCore/bindings/js/JSAttrCustom.cpp
new file mode 100644
index 0000000..c7d3848
--- /dev/null
+++ b/WebCore/bindings/js/JSAttrCustom.cpp
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSAttr.h"
+
+#include "CSSHelper.h"
+#include "HTMLFrameElementBase.h"
+#include "HTMLNames.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+void JSAttr::setValue(ExecState* exec, JSValue* value)
+{
+ Attr* imp = static_cast<Attr*>(impl());
+ String attrValue = valueToStringWithNullCheck(exec, value);
+
+ Element* ownerElement = imp->ownerElement();
+ if (ownerElement && (ownerElement->hasTagName(iframeTag) || ownerElement->hasTagName(frameTag))) {
+ if (equalIgnoringCase(imp->name(), "src") && protocolIs(parseURL(attrValue), "javascript")) {
+ if (!checkNodeSecurity(exec, static_cast<HTMLFrameElementBase*>(ownerElement)->contentDocument()))
+ return;
+ }
+ }
+
+ ExceptionCode ec = 0;
+ imp->setValue(attrValue, ec);
+ setDOMException(exec, ec);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSAudioConstructor.cpp b/WebCore/bindings/js/JSAudioConstructor.cpp
new file mode 100644
index 0000000..1efb0d8
--- /dev/null
+++ b/WebCore/bindings/js/JSAudioConstructor.cpp
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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"
+
+#if ENABLE(VIDEO)
+#include "JSAudioConstructor.h"
+
+#include "Document.h"
+#include "HTMLAudioElement.h"
+#include "JSHTMLAudioElement.h"
+#include "Text.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSAudioConstructor::JSAudioConstructor(ExecState* exec, Document* d)
+ : DOMObject(exec->lexicalGlobalObject()->objectPrototype())
+ , m_doc(d)
+{
+ putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
+}
+
+bool JSAudioConstructor::implementsConstruct() const
+{
+ return true;
+}
+
+JSObject* JSAudioConstructor::construct(ExecState* exec, const List& args)
+{
+ int exception = 0;
+ RefPtr<Element> el(m_doc->createElement("audio", exception));
+ HTMLAudioElement* audio = 0;
+ if (el && !exception) {
+ audio = static_cast<HTMLAudioElement*>(el.get());
+ int sz = args.size();
+ if (sz > 0) {
+ audio->setSrc(args[0]->toString(exec));
+ audio->scheduleLoad();
+ }
+ }
+
+ setDOMException(exec, exception);
+ return static_cast<JSObject*>(toJS(exec, audio));
+}
+
+}
+#endif
diff --git a/WebCore/bindings/js/JSAudioConstructor.h b/WebCore/bindings/js/JSAudioConstructor.h
new file mode 100644
index 0000000..3bfd857
--- /dev/null
+++ b/WebCore/bindings/js/JSAudioConstructor.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSAudioConstructor_h
+#define JSAudioConstructor_h
+
+#if ENABLE(VIDEO)
+
+#include "kjs_binding.h"
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+ class JSAudioConstructor : public DOMObject {
+ public:
+ JSAudioConstructor(KJS::ExecState*, Document*);
+ virtual bool implementsConstruct() const;
+ virtual KJS::JSObject *construct(KJS::ExecState*, const KJS::List& args);
+ private:
+ RefPtr<Document> m_doc;
+ };
+
+}
+
+#endif
+#endif
diff --git a/WebCore/bindings/js/JSCSSRuleCustom.cpp b/WebCore/bindings/js/JSCSSRuleCustom.cpp
new file mode 100644
index 0000000..44a52a6
--- /dev/null
+++ b/WebCore/bindings/js/JSCSSRuleCustom.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSCSSRule.h"
+
+#include "CSSCharsetRule.h"
+#include "CSSFontFaceRule.h"
+#include "CSSImportRule.h"
+#include "CSSMediaRule.h"
+#include "CSSPageRule.h"
+#include "CSSStyleRule.h"
+#include "JSCSSCharsetRule.h"
+#include "JSCSSFontFaceRule.h"
+#include "JSCSSImportRule.h"
+#include "JSCSSMediaRule.h"
+#include "JSCSSPageRule.h"
+#include "JSCSSStyleRule.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* toJS(ExecState* exec, CSSRule* rule)
+{
+ if (!rule)
+ return jsNull();
+
+ DOMObject* ret = ScriptInterpreter::getDOMObject(rule);
+
+ if (ret)
+ return ret;
+
+ switch (rule->type()) {
+ case CSSRule::STYLE_RULE:
+ ret = new JSCSSStyleRule(JSCSSRulePrototype::self(exec), static_cast<CSSStyleRule*>(rule));
+ break;
+ case CSSRule::MEDIA_RULE:
+ ret = new JSCSSMediaRule(JSCSSMediaRulePrototype::self(exec), static_cast<CSSMediaRule*>(rule));
+ break;
+ case CSSRule::FONT_FACE_RULE:
+ ret = new JSCSSFontFaceRule(JSCSSFontFaceRulePrototype::self(exec), static_cast<CSSFontFaceRule*>(rule));
+ break;
+ case CSSRule::PAGE_RULE:
+ ret = new JSCSSPageRule(JSCSSPageRulePrototype::self(exec), static_cast<CSSPageRule*>(rule));
+ break;
+ case CSSRule::IMPORT_RULE:
+ ret = new JSCSSImportRule(JSCSSImportRulePrototype::self(exec), static_cast<CSSImportRule*>(rule));
+ break;
+ case CSSRule::CHARSET_RULE:
+ ret = new JSCSSCharsetRule(JSCSSCharsetRulePrototype::self(exec), static_cast<CSSCharsetRule*>(rule));
+ break;
+ default:
+ ret = new JSCSSRule(JSCSSRulePrototype::self(exec), rule);
+ break;
+ }
+
+ ScriptInterpreter::putDOMObject(rule, ret);
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp b/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
new file mode 100644
index 0000000..0723410
--- /dev/null
+++ b/WebCore/bindings/js/JSCSSStyleDeclarationCustom.cpp
@@ -0,0 +1,172 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSCSSStyleDeclaration.h"
+
+#include "AtomicString.h"
+#include "CSSPrimitiveValue.h"
+#include "CSSStyleDeclaration.h"
+#include "CSSValue.h"
+#include "PlatformString.h"
+#include <kjs/string_object.h>
+#include <wtf/ASCIICType.h>
+
+using namespace KJS;
+using namespace WTF;
+
+namespace WebCore {
+
+// Check for a CSS prefix.
+// Passed prefix is all lowercase.
+// First characters of property name may be upper or lowercase.
+// Other characters in the prefix within the property name must be lowercase.
+// The prefix within the property name must be followed by a capital letter.
+static bool hasCSSPropertyNamePrefix(const Identifier& propertyName, const char* prefix)
+{
+#ifndef NDEBUG
+ ASSERT(*prefix);
+ for (const char* p = prefix; *p; ++p)
+ ASSERT(isASCIILower(*p));
+#endif
+
+ unsigned length = propertyName.size();
+ ASSERT(length);
+
+ if (toASCIILower(propertyName.data()[0].unicode()) != prefix[0])
+ return false;
+
+ for (unsigned i = 1; i < length; ++i) {
+ if (!prefix[i])
+ return isASCIIUpper(propertyName.data()[i].unicode());
+ if (propertyName.data()[0].unicode() != prefix[0])
+ return false;
+ }
+ return false;
+}
+
+static String cssPropertyName(const Identifier& propertyName, bool* hadPixelOrPosPrefix = 0)
+{
+ if (hadPixelOrPosPrefix)
+ *hadPixelOrPosPrefix = false;
+
+ unsigned length = propertyName.size();
+ if (!length)
+ return String();
+
+ Vector< ::UChar> name;
+ name.reserveCapacity(length);
+
+ unsigned i = 0;
+
+ if (hasCSSPropertyNamePrefix(propertyName, "css"))
+ i += 3;
+ else if (hasCSSPropertyNamePrefix(propertyName, "pixel")) {
+ i += 5;
+ if (hadPixelOrPosPrefix)
+ *hadPixelOrPosPrefix = true;
+ } else if (hasCSSPropertyNamePrefix(propertyName, "pos")) {
+ i += 3;
+ if (hadPixelOrPosPrefix)
+ *hadPixelOrPosPrefix = true;
+ } else if (hasCSSPropertyNamePrefix(propertyName, "webkit")
+ || hasCSSPropertyNamePrefix(propertyName, "khtml")
+ || hasCSSPropertyNamePrefix(propertyName, "apple"))
+ name.append('-');
+
+ name.append(toASCIILower(propertyName.data()[i++].unicode()));
+
+ for (; i < length; ++i) {
+ ::UChar c = propertyName.data()[i].unicode();
+ if (!isASCIIUpper(c))
+ name.append(c);
+ else {
+ name.append('-');
+ name.append(toASCIILower(c));
+ }
+ }
+
+ return String::adopt(name);
+}
+
+static bool isCSSPropertyName(const Identifier& propertyName)
+{
+ return CSSStyleDeclaration::isPropertyName(cssPropertyName(propertyName));
+}
+
+bool JSCSSStyleDeclaration::canGetItemsForName(ExecState*, CSSStyleDeclaration*, const Identifier& propertyName)
+{
+ return isCSSPropertyName(propertyName);
+}
+
+// FIXME: You can get these properties, and set them (see customPut below),
+// but you should also be able to enumerate them.
+JSValue* JSCSSStyleDeclaration::nameGetter(ExecState* exec, JSObject* originalObject,
+ const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSCSSStyleDeclaration* thisObj = static_cast<JSCSSStyleDeclaration*>(slot.slotBase());
+
+ // Set up pixelOrPos boolean to handle the fact that
+ // pixelTop returns "CSS Top" as number value in unit pixels
+ // posTop returns "CSS top" as number value in unit pixels _if_ its a
+ // positioned element. if it is not a positioned element, return 0
+ // from MSIE documentation FIXME: IMPLEMENT THAT (Dirk)
+ bool pixelOrPos;
+ String prop = cssPropertyName(propertyName, &pixelOrPos);
+ RefPtr<CSSValue> v = thisObj->impl()->getPropertyCSSValue(prop);
+ if (v) {
+ if (pixelOrPos && v->cssValueType() == CSSValue::CSS_PRIMITIVE_VALUE)
+ return jsNumber(static_pointer_cast<CSSPrimitiveValue>(v)->getFloatValue(CSSPrimitiveValue::CSS_PX));
+ return jsStringOrNull(v->cssText());
+ }
+
+ // If the property is a shorthand property (such as "padding"),
+ // it can only be accessed using getPropertyValue.
+
+ // Make the SVG 'filter' attribute undetectable, to avoid confusion with the IE 'filter' attribute.
+ if (propertyName == "filter")
+ return new StringInstanceThatMasqueradesAsUndefined(exec->lexicalGlobalObject()->stringPrototype(),
+ thisObj->impl()->getPropertyValue(prop));
+
+ return jsString(thisObj->impl()->getPropertyValue(prop));
+}
+
+
+bool JSCSSStyleDeclaration::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ if (!isCSSPropertyName(propertyName))
+ return false;
+
+ DOMExceptionTranslator exception(exec);
+ bool pixelOrPos;
+ String prop = cssPropertyName(propertyName, &pixelOrPos);
+ String propValue = valueToStringWithNullCheck(exec, value);
+ if (pixelOrPos)
+ propValue += "px";
+ impl()->setProperty(prop, propValue, exception);
+ return true;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSCSSValueCustom.cpp b/WebCore/bindings/js/JSCSSValueCustom.cpp
new file mode 100644
index 0000000..88147d7
--- /dev/null
+++ b/WebCore/bindings/js/JSCSSValueCustom.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSCSSValue.h"
+
+#include "CSSPrimitiveValue.h"
+#include "CSSValueList.h"
+#include "JSCSSPrimitiveValue.h"
+#include "JSCSSValueList.h"
+
+#if ENABLE(SVG)
+#include "JSSVGColor.h"
+#include "JSSVGPaint.h"
+#include "SVGColor.h"
+#include "SVGPaint.h"
+#endif
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* toJS(ExecState* exec, CSSValue* value)
+{
+ if (!value)
+ return jsNull();
+
+ DOMObject* ret = ScriptInterpreter::getDOMObject(value);
+
+ if (ret)
+ return ret;
+
+ if (value->isValueList())
+ ret = new JSCSSValueList(JSCSSValueListPrototype::self(exec), static_cast<CSSValueList*>(value));
+#if ENABLE(SVG)
+ else if (value->isSVGPaint())
+ ret = new JSSVGPaint(JSSVGPaintPrototype::self(exec), static_cast<SVGPaint*>(value));
+ else if (value->isSVGColor())
+ ret = new JSSVGColor(JSSVGColorPrototype::self(exec), static_cast<SVGColor*>(value));
+#endif
+ else if (value->isPrimitiveValue())
+ ret = new JSCSSPrimitiveValue(JSCSSPrimitiveValuePrototype::self(exec), static_cast<CSSPrimitiveValue*>(value));
+ else
+ ret = new JSCSSValue(JSCSSValuePrototype::self(exec), value);
+
+ ScriptInterpreter::putDOMObject(value, ret);
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSCanvasPixelArrayCustom.cpp b/WebCore/bindings/js/JSCanvasPixelArrayCustom.cpp
new file mode 100644
index 0000000..23e6afd
--- /dev/null
+++ b/WebCore/bindings/js/JSCanvasPixelArrayCustom.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSCanvasPixelArray.h"
+
+#include "CanvasPixelArray.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSCanvasPixelArray::indexGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
+{
+ CanvasPixelArray* array = static_cast<JSCanvasPixelArray*>(slot.slotBase())->impl();
+ unsigned index = slot.index();
+ unsigned char result;
+ if (!array->get(index, result))
+ return jsUndefined();
+ return jsNumber(result);
+}
+
+void JSCanvasPixelArray::indexSetter(ExecState* exec, unsigned index, JSValue* value)
+{
+ double pixelValue = value->toNumber(exec);
+ if (exec->hadException())
+ return;
+ m_impl->set(index, pixelValue);
+}
+
+JSValue* toJS(ExecState* exec, CanvasPixelArray* pixels)
+{
+ if (!pixels)
+ return jsNull();
+
+ DOMObject* ret = ScriptInterpreter::getDOMObject(pixels);
+ if (ret)
+ return ret;
+
+ ret = new JSCanvasPixelArray(JSCanvasPixelArrayPrototype::self(exec), pixels);
+
+ Collector::reportExtraMemoryCost(pixels->length());
+
+ ScriptInterpreter::putDOMObject(pixels, ret);
+
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp b/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp
new file mode 100644
index 0000000..c5256d9
--- /dev/null
+++ b/WebCore/bindings/js/JSCanvasRenderingContext2DCustom.cpp
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSCanvasRenderingContext2D.h"
+
+#include "CanvasGradient.h"
+#include "CanvasPattern.h"
+#include "CanvasRenderingContext2D.h"
+#include "CanvasStyle.h"
+#include "ExceptionCode.h"
+#include "FloatRect.h"
+#include "HTMLCanvasElement.h"
+#include "HTMLImageElement.h"
+#include "ImageData.h"
+#include "JSCanvasGradient.h"
+#include "JSCanvasPattern.h"
+#include "JSHTMLCanvasElement.h"
+#include "JSHTMLImageElement.h"
+#include "JSImageData.h"
+#include "kjs_html.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+static JSValue* toJS(ExecState* exec, CanvasStyle* style)
+{
+ if (style->gradient())
+ return toJS(exec, style->gradient());
+ if (style->pattern())
+ return toJS(exec, style->pattern());
+ return jsString(style->color());
+}
+
+static PassRefPtr<CanvasStyle> toHTMLCanvasStyle(ExecState* exec, JSValue* value)
+{
+ if (value->isString())
+ return new CanvasStyle(value->toString(exec));
+ if (!value->isObject())
+ return 0;
+ JSObject* object = static_cast<JSObject*>(value);
+ if (object->inherits(&JSCanvasGradient::info))
+ return new CanvasStyle(static_cast<JSCanvasGradient*>(object)->impl());
+ if (object->inherits(&JSCanvasPattern::info))
+ return new CanvasStyle(static_cast<JSCanvasPattern*>(object)->impl());
+ return 0;
+}
+
+JSValue* JSCanvasRenderingContext2D::strokeStyle(ExecState* exec) const
+{
+ return toJS(exec, impl()->strokeStyle());
+}
+
+void JSCanvasRenderingContext2D::setStrokeStyle(ExecState* exec, JSValue* value)
+{
+ impl()->setStrokeStyle(toHTMLCanvasStyle(exec, value));
+}
+
+JSValue* JSCanvasRenderingContext2D::fillStyle(ExecState* exec) const
+{
+ return toJS(exec, impl()->fillStyle());
+}
+
+void JSCanvasRenderingContext2D::setFillStyle(ExecState* exec, JSValue* value)
+{
+ impl()->setFillStyle(toHTMLCanvasStyle(exec, value));
+}
+
+JSValue* JSCanvasRenderingContext2D::setFillColor(ExecState* exec, const List& args)
+{
+ CanvasRenderingContext2D* context = impl();
+
+ // string arg = named color
+ // number arg = gray color
+ // string arg, number arg = named color, alpha
+ // number arg, number arg = gray color, alpha
+ // 4 args = r, g, b, a
+ // 5 args = c, m, y, k, a
+ switch (args.size()) {
+ case 1:
+ if (args[0]->isString())
+ context->setFillColor(args[0]->toString(exec));
+ else
+ context->setFillColor(args[0]->toFloat(exec));
+ break;
+ case 2:
+ if (args[0]->isString())
+ context->setFillColor(args[0]->toString(exec), args[1]->toFloat(exec));
+ else
+ context->setFillColor(args[0]->toFloat(exec), args[1]->toFloat(exec));
+ break;
+ case 4:
+ context->setFillColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec));
+ break;
+ case 5:
+ context->setFillColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec), args[4]->toFloat(exec));
+ break;
+ default:
+ return throwError(exec, SyntaxError);
+ }
+ return jsUndefined();
+}
+
+JSValue* JSCanvasRenderingContext2D::setStrokeColor(ExecState* exec, const List& args)
+{
+ CanvasRenderingContext2D* context = impl();
+
+ // string arg = named color
+ // number arg = gray color
+ // string arg, number arg = named color, alpha
+ // number arg, number arg = gray color, alpha
+ // 4 args = r, g, b, a
+ // 5 args = c, m, y, k, a
+ switch (args.size()) {
+ case 1:
+ if (args[0]->isString())
+ context->setStrokeColor(args[0]->toString(exec));
+ else
+ context->setStrokeColor(args[0]->toFloat(exec));
+ break;
+ case 2:
+ if (args[0]->isString())
+ context->setStrokeColor(args[0]->toString(exec), args[1]->toFloat(exec));
+ else
+ context->setStrokeColor(args[0]->toFloat(exec), args[1]->toFloat(exec));
+ break;
+ case 4:
+ context->setStrokeColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec));
+ break;
+ case 5:
+ context->setStrokeColor(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec), args[4]->toFloat(exec));
+ break;
+ default:
+ return throwError(exec, SyntaxError);
+ }
+
+ return jsUndefined();
+}
+
+JSValue* JSCanvasRenderingContext2D::strokeRect(ExecState* exec, const List& args)
+{
+ CanvasRenderingContext2D* context = impl();
+ ExceptionCode ec;
+
+ if (args.size() <= 4)
+ context->strokeRect(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec), ec);
+ else
+ context->strokeRect(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec), args[4]->toFloat(exec), ec);
+ setDOMException(exec, ec);
+
+ return jsUndefined();
+}
+
+JSValue* JSCanvasRenderingContext2D::drawImage(ExecState* exec, const List& args)
+{
+ CanvasRenderingContext2D* context = impl();
+
+ // DrawImage has three variants:
+ // drawImage(img, dx, dy)
+ // drawImage(img, dx, dy, dw, dh)
+ // drawImage(img, sx, sy, sw, sh, dx, dy, dw, dh)
+ // Composite operation is specified with globalCompositeOperation.
+ // The img parameter can be a <img> or <canvas> element.
+ JSValue* value = args[0];
+ if (!value->isObject())
+ return throwError(exec, TypeError);
+ JSObject* o = static_cast<JSObject*>(value);
+
+ ExceptionCode ec = 0;
+ if (o->inherits(&JSHTMLImageElement::info)) {
+ HTMLImageElement* imgElt = static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
+ switch (args.size()) {
+ case 3:
+ context->drawImage(imgElt, args[1]->toFloat(exec), args[2]->toFloat(exec));
+ break;
+ case 5:
+ context->drawImage(imgElt, args[1]->toFloat(exec), args[2]->toFloat(exec),
+ args[3]->toFloat(exec), args[4]->toFloat(exec), ec);
+ setDOMException(exec, ec);
+ break;
+ case 9:
+ context->drawImage(imgElt, FloatRect(args[1]->toFloat(exec), args[2]->toFloat(exec),
+ args[3]->toFloat(exec), args[4]->toFloat(exec)),
+ FloatRect(args[5]->toFloat(exec), args[6]->toFloat(exec),
+ args[7]->toFloat(exec), args[8]->toFloat(exec)), ec);
+ setDOMException(exec, ec);
+ break;
+ default:
+ return throwError(exec, SyntaxError);
+ }
+ } else if (o->inherits(&JSHTMLCanvasElement::info)) {
+ HTMLCanvasElement* canvas = static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(args[0])->impl());
+ switch (args.size()) {
+ case 3:
+ context->drawImage(canvas, args[1]->toFloat(exec), args[2]->toFloat(exec));
+ break;
+ case 5:
+ context->drawImage(canvas, args[1]->toFloat(exec), args[2]->toFloat(exec),
+ args[3]->toFloat(exec), args[4]->toFloat(exec), ec);
+ setDOMException(exec, ec);
+ break;
+ case 9:
+ context->drawImage(canvas, FloatRect(args[1]->toFloat(exec), args[2]->toFloat(exec),
+ args[3]->toFloat(exec), args[4]->toFloat(exec)),
+ FloatRect(args[5]->toFloat(exec), args[6]->toFloat(exec),
+ args[7]->toFloat(exec), args[8]->toFloat(exec)), ec);
+ setDOMException(exec, ec);
+ break;
+ default:
+ return throwError(exec, SyntaxError);
+ }
+ } else {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return 0;
+ }
+
+ return jsUndefined();
+}
+
+JSValue* JSCanvasRenderingContext2D::drawImageFromRect(ExecState* exec, const List& args)
+{
+ CanvasRenderingContext2D* context = impl();
+
+ JSValue* value = args[0];
+ if (!value->isObject())
+ return throwError(exec, TypeError);
+ JSObject* o = static_cast<JSObject*>(value);
+
+ if (!o->inherits(&JSHTMLImageElement::info))
+ return throwError(exec, TypeError);
+ context->drawImageFromRect(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl()),
+ args[1]->toFloat(exec), args[2]->toFloat(exec),
+ args[3]->toFloat(exec), args[4]->toFloat(exec),
+ args[5]->toFloat(exec), args[6]->toFloat(exec),
+ args[7]->toFloat(exec), args[8]->toFloat(exec),
+ args[9]->toString(exec));
+ return jsUndefined();
+}
+
+JSValue* JSCanvasRenderingContext2D::setShadow(ExecState* exec, const List& args)
+{
+ CanvasRenderingContext2D* context = impl();
+
+ switch (args.size()) {
+ case 3:
+ context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec));
+ break;
+ case 4:
+ if (args[3]->isString())
+ context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toString(exec));
+ else
+ context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec));
+ break;
+ case 5:
+ if (args[3]->isString())
+ context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toString(exec),
+ args[4]->toFloat(exec));
+ else
+ context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec),
+ args[4]->toFloat(exec));
+ break;
+ case 7:
+ context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec),
+ args[4]->toFloat(exec), args[5]->toFloat(exec),
+ args[6]->toFloat(exec));
+ break;
+ case 8:
+ context->setShadow(args[0]->toFloat(exec), args[1]->toFloat(exec),
+ args[2]->toFloat(exec), args[3]->toFloat(exec),
+ args[4]->toFloat(exec), args[5]->toFloat(exec),
+ args[6]->toFloat(exec), args[7]->toFloat(exec));
+ break;
+ default:
+ return throwError(exec, SyntaxError);
+ }
+
+ return jsUndefined();
+}
+
+JSValue* JSCanvasRenderingContext2D::createPattern(ExecState* exec, const List& args)
+{
+ CanvasRenderingContext2D* context = impl();
+
+ JSValue* value = args[0];
+ if (!value->isObject())
+ return throwError(exec, TypeError);
+ JSObject* o = static_cast<JSObject*>(value);
+
+ if (o->inherits(&JSHTMLImageElement::info)) {
+ ExceptionCode ec;
+ JSValue* pattern = toJS(exec,
+ context->createPattern(static_cast<HTMLImageElement*>(static_cast<JSHTMLElement*>(args[0])->impl()),
+ args[1]->toString(exec), ec).get());
+ setDOMException(exec, ec);
+ return pattern;
+ }
+ if (o->inherits(&JSHTMLCanvasElement::info)) {
+ ExceptionCode ec;
+ JSValue* pattern = toJS(exec,
+ context->createPattern(static_cast<HTMLCanvasElement*>(static_cast<JSHTMLElement*>(args[0])->impl()),
+ args[1]->toString(exec), ec).get());
+ setDOMException(exec, ec);
+ return pattern;
+ }
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return 0;
+}
+
+JSValue* JSCanvasRenderingContext2D::putImageData(ExecState* exec, const List& args)
+{
+ // putImageData has two variants
+ // putImageData(ImageData, x, y)
+ // putImageData(ImageData, x, y, dirtyX, dirtyY, dirtyWidth, dirtyHeight)
+ CanvasRenderingContext2D* context = impl();
+
+ ExceptionCode ec = 0;
+ if (args.size() >= 7)
+ context->putImageData(toImageData(args[0]), args[1]->toFloat(exec), args[2]->toFloat(exec),
+ args[3]->toFloat(exec), args[4]->toFloat(exec), args[5]->toFloat(exec), args[6]->toFloat(exec), ec);
+ else
+ context->putImageData(toImageData(args[0]), args[1]->toFloat(exec), args[2]->toFloat(exec), ec);
+
+ setDOMException(exec, ec);
+ return jsUndefined();
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp b/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp
new file mode 100644
index 0000000..7adab5f
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLStatementCallback.cpp
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSCustomSQLStatementCallback.h"
+
+#include "CString.h"
+#include "Frame.h"
+#include "kjs_proxy.h"
+#include "JSSQLResultSet.h"
+#include "JSSQLTransaction.h"
+#include "Page.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+JSCustomSQLStatementCallback::JSCustomSQLStatementCallback(JSObject* callback, Frame* frame)
+ : m_callback(callback)
+ , m_frame(frame)
+{
+}
+
+void JSCustomSQLStatementCallback::handleEvent(SQLTransaction* transaction, SQLResultSet* resultSet, bool& raisedException)
+{
+ ASSERT(m_callback);
+ ASSERT(m_frame);
+
+ if (!m_frame->scriptProxy()->isEnabled())
+ return;
+
+ JSGlobalObject* globalObject = m_frame->scriptProxy()->globalObject();
+ ExecState* exec = globalObject->globalExec();
+
+ KJS::JSLock lock;
+
+ JSValue* handleEventFuncValue = m_callback->get(exec, "handleEvent");
+ JSObject* handleEventFunc = 0;
+ if (handleEventFuncValue->isObject()) {
+ handleEventFunc = static_cast<JSObject*>(handleEventFuncValue);
+ if (!handleEventFunc->implementsCall())
+ handleEventFunc = 0;
+ }
+
+ if (!handleEventFunc && !m_callback->implementsCall()) {
+ // FIXME: Should an exception be thrown here?
+ return;
+ }
+
+ RefPtr<JSCustomSQLStatementCallback> protect(this);
+
+ List args;
+ args.append(toJS(exec, transaction));
+ args.append(toJS(exec, resultSet));
+
+ globalObject->startTimeoutCheck();
+ if (handleEventFunc)
+ handleEventFunc->call(exec, m_callback, args);
+ else
+ m_callback->call(exec, m_callback, args);
+ globalObject->stopTimeoutCheck();
+
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("SQLStatementCallback: %s\n", message.utf8().data());
+ if (Page* page = m_frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+
+ raisedException = true;
+
+ exec->clearException();
+ }
+
+ Document::updateDocumentsRendering();
+}
+
+}
diff --git a/WebCore/bindings/js/JSCustomSQLStatementCallback.h b/WebCore/bindings/js/JSCustomSQLStatementCallback.h
new file mode 100644
index 0000000..27bca7b
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLStatementCallback.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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.
+ */
+
+#ifndef JSCustomSQLStatementCallback_h
+#define JSCustomSQLStatementCallback_h
+
+#include "SQLStatementCallback.h"
+
+#include <kjs/object.h>
+#include <kjs/protect.h>
+#include <wtf/Forward.h>
+
+namespace KJS {
+ class JSObject;
+}
+
+namespace WebCore {
+
+class Frame;
+class SQLResultSet;
+
+class JSCustomSQLStatementCallback : public SQLStatementCallback {
+public:
+ JSCustomSQLStatementCallback(KJS::JSObject* callback, Frame*);
+
+ virtual void handleEvent(SQLTransaction*, SQLResultSet*, bool& raisedException);
+private:
+ KJS::ProtectedPtr<KJS::JSObject> m_callback;
+ RefPtr<Frame> m_frame;
+};
+
+}
+
+#endif // JSCustomSQLStatementCallback_h
diff --git a/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp b/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp
new file mode 100644
index 0000000..615082d
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.cpp
@@ -0,0 +1,112 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSCustomSQLStatementErrorCallback.h"
+
+#include "CString.h"
+#include "Frame.h"
+#include "kjs_proxy.h"
+#include "JSSQLError.h"
+#include "JSSQLTransaction.h"
+#include "Page.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+JSCustomSQLStatementErrorCallback::JSCustomSQLStatementErrorCallback(JSObject* callback, Frame* frame)
+ : m_callback(callback)
+ , m_frame(frame)
+{
+}
+
+bool JSCustomSQLStatementErrorCallback::handleEvent(SQLTransaction* transaction, SQLError* error)
+{
+ ASSERT(m_callback);
+ ASSERT(m_frame);
+
+ if (!m_frame->scriptProxy()->isEnabled())
+ return true;
+
+ JSGlobalObject* globalObject = m_frame->scriptProxy()->globalObject();
+ ExecState* exec = globalObject->globalExec();
+
+ KJS::JSLock lock;
+
+ JSValue* handleEventFuncValue = m_callback->get(exec, "handleEvent");
+ JSObject* handleEventFunc = 0;
+ if (handleEventFuncValue->isObject()) {
+ handleEventFunc = static_cast<JSObject*>(handleEventFuncValue);
+ if (!handleEventFunc->implementsCall())
+ handleEventFunc = 0;
+ }
+
+ if (!handleEventFunc && !m_callback->implementsCall()) {
+ // FIXME: Should an exception be thrown here?
+ return true;
+ }
+
+ RefPtr<JSCustomSQLStatementErrorCallback> protect(this);
+
+ List args;
+ args.append(toJS(exec, transaction));
+ args.append(toJS(exec, error));
+
+ JSValue *result;
+ globalObject->startTimeoutCheck();
+ if (handleEventFunc)
+ result = handleEventFunc->call(exec, m_callback, args);
+ else
+ result = m_callback->call(exec, m_callback, args);
+ globalObject->stopTimeoutCheck();
+
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("SQLStatementErrorCallback: %s\n", message.utf8().data());
+ if (Page* page = m_frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+ exec->clearException();
+
+ // The spec says:
+ // "If the error callback returns false, then move on to the next statement..."
+ // "Otherwise, the error callback did not return false, or there was no error callback"
+ // Therefore an exception and returning true are the same thing - so, return true on an exception
+ return true;
+ }
+
+ Document::updateDocumentsRendering();
+
+ return result->toBoolean(exec);
+}
+
+}
diff --git a/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.h b/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.h
new file mode 100644
index 0000000..7bc40c6
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLStatementErrorCallback.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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.
+ */
+
+#ifndef JSCustomSQLStatementErrorCallback_h
+#define JSCustomSQLStatementErrorCallback_h
+
+#include "SQLStatementErrorCallback.h"
+
+#include <kjs/object.h>
+#include <kjs/protect.h>
+#include <wtf/Forward.h>
+
+namespace KJS {
+ class JSObject;
+}
+
+namespace WebCore {
+
+class Frame;
+class SQLError;
+
+class JSCustomSQLStatementErrorCallback : public SQLStatementErrorCallback {
+public:
+ JSCustomSQLStatementErrorCallback(KJS::JSObject* callback, Frame*);
+
+ virtual bool handleEvent(SQLTransaction*, SQLError*);
+private:
+ KJS::ProtectedPtr<KJS::JSObject> m_callback;
+ RefPtr<Frame> m_frame;
+};
+
+}
+
+#endif // JSCustomSQLStatementErrorCallback_h
+
diff --git a/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp b/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp
new file mode 100644
index 0000000..cd50ebd
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLTransactionCallback.cpp
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSCustomSQLTransactionCallback.h"
+
+#include "CString.h"
+#include "Frame.h"
+#include "Logging.h"
+#include "MainThread.h"
+#include "kjs_proxy.h"
+#include "JSSQLTransaction.h"
+#include "Page.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+#ifndef NDEBUG
+
+WTFLogChannel LogWebCoreSQLLeaks = { 0x00000000, "", WTFLogChannelOn };
+
+struct JSCustomSQLTransactionCallbackCounter {
+ static int count;
+ ~JSCustomSQLTransactionCallbackCounter()
+ {
+ if (count)
+ LOG(WebCoreSQLLeaks, "LEAK: %d JSCustomSQLTransactionCallback\n", count);
+ }
+};
+
+int JSCustomSQLTransactionCallbackCounter::count = 0;
+static JSCustomSQLTransactionCallbackCounter counter;
+
+#endif
+
+// We have to clean up the data on the main thread for two reasons:
+//
+// 1) Can't deref a Frame on a non-main thread.
+// 2) Unprotecting the JSObject on a non-main thread would register that thread
+// for JavaScript garbage collection, which could unnecessarily slow things down.
+
+class JSCustomSQLTransactionCallback::Data {
+public:
+ Data(JSObject* callback, Frame* frame) : m_callback(callback), m_frame(frame) { }
+ JSObject* callback() { return m_callback; }
+ Frame* frame() { return m_frame.get(); }
+
+private:
+ ProtectedPtr<JSObject> m_callback;
+ RefPtr<Frame> m_frame;
+};
+
+JSCustomSQLTransactionCallback::JSCustomSQLTransactionCallback(JSObject* callback, Frame* frame)
+ : m_data(new Data(callback, frame))
+{
+#ifndef NDEBUG
+ ++JSCustomSQLTransactionCallbackCounter::count;
+#endif
+}
+
+void JSCustomSQLTransactionCallback::deleteData(void* context)
+{
+ delete static_cast<Data*>(context);
+}
+
+JSCustomSQLTransactionCallback::~JSCustomSQLTransactionCallback()
+{
+ callOnMainThread(deleteData, m_data);
+#ifndef NDEBUG
+ m_data = 0;
+ --JSCustomSQLTransactionCallbackCounter::count;
+#endif
+}
+
+void JSCustomSQLTransactionCallback::handleEvent(SQLTransaction* transaction, bool& raisedException)
+{
+ ASSERT(m_data);
+ ASSERT(m_data->callback());
+ ASSERT(m_data->frame());
+
+ if (!m_data->frame()->scriptProxy()->isEnabled())
+ return;
+
+ JSGlobalObject* globalObject = m_data->frame()->scriptProxy()->globalObject();
+ ExecState* exec = globalObject->globalExec();
+
+ KJS::JSLock lock;
+
+ JSValue* handleEventFuncValue = m_data->callback()->get(exec, "handleEvent");
+ JSObject* handleEventFunc = 0;
+ if (handleEventFuncValue->isObject()) {
+ handleEventFunc = static_cast<JSObject*>(handleEventFuncValue);
+ if (!handleEventFunc->implementsCall())
+ handleEventFunc = 0;
+ }
+
+ if (!handleEventFunc && !m_data->callback()->implementsCall()) {
+ // FIXME: Should an exception be thrown here?
+ return;
+ }
+
+ RefPtr<JSCustomSQLTransactionCallback> protect(this);
+
+ List args;
+ args.append(toJS(exec, transaction));
+
+ globalObject->startTimeoutCheck();
+ if (handleEventFunc)
+ handleEventFunc->call(exec, m_data->callback(), args);
+ else
+ m_data->callback()->call(exec, m_data->callback(), args);
+ globalObject->stopTimeoutCheck();
+
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("SQLTransactionCallback: %s\n", message.utf8().data());
+ if (Page* page = m_data->frame()->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+ exec->clearException();
+
+ raisedException = true;
+ }
+
+ Document::updateDocumentsRendering();
+}
+
+}
diff --git a/WebCore/bindings/js/JSCustomSQLTransactionCallback.h b/WebCore/bindings/js/JSCustomSQLTransactionCallback.h
new file mode 100644
index 0000000..aa31d50
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLTransactionCallback.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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.
+ */
+
+#ifndef JSCustomSQLTransactionCallback_h
+#define JSCustomSQLTransactionCallback_h
+
+#include "SQLTransactionCallback.h"
+
+namespace KJS {
+ class JSObject;
+}
+
+namespace WebCore {
+
+class Frame;
+
+class JSCustomSQLTransactionCallback : public SQLTransactionCallback {
+public:
+ JSCustomSQLTransactionCallback(KJS::JSObject* callback, Frame*);
+ virtual ~JSCustomSQLTransactionCallback();
+
+ virtual void handleEvent(SQLTransaction*, bool& raisedException);
+
+private:
+ static void deleteData(void*);
+
+ class Data;
+ Data* m_data;
+};
+
+}
+
+#endif // JSCustomSQLTransactionCallback_h
diff --git a/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp b/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp
new file mode 100644
index 0000000..ff4d1c1
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.cpp
@@ -0,0 +1,104 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSCustomSQLTransactionErrorCallback.h"
+
+#include "CString.h"
+#include "Frame.h"
+#include "kjs_proxy.h"
+#include "JSSQLError.h"
+#include "Page.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+JSCustomSQLTransactionErrorCallback::JSCustomSQLTransactionErrorCallback(JSObject* callback, Frame* frame)
+ : m_callback(callback)
+ , m_frame(frame)
+{
+}
+
+bool JSCustomSQLTransactionErrorCallback::handleEvent(SQLError* error)
+{
+ ASSERT(m_callback);
+ ASSERT(m_frame);
+
+ if (!m_frame->scriptProxy()->isEnabled())
+ return true;
+
+ JSGlobalObject* globalObject = m_frame->scriptProxy()->globalObject();
+ ExecState* exec = globalObject->globalExec();
+
+ KJS::JSLock lock;
+
+ JSValue* handleEventFuncValue = m_callback->get(exec, "handleEvent");
+ JSObject* handleEventFunc = 0;
+ if (handleEventFuncValue->isObject()) {
+ handleEventFunc = static_cast<JSObject*>(handleEventFuncValue);
+ if (!handleEventFunc->implementsCall())
+ handleEventFunc = 0;
+ }
+
+ if (!handleEventFunc && !m_callback->implementsCall()) {
+ // FIXME: Should an exception be thrown here?
+ return true;
+ }
+
+ RefPtr<JSCustomSQLTransactionErrorCallback> protect(this);
+
+ List args;
+ args.append(toJS(exec, error));
+
+ JSValue *result;
+ globalObject->startTimeoutCheck();
+ if (handleEventFunc)
+ result = handleEventFunc->call(exec, m_callback, args);
+ else
+ result = m_callback->call(exec, m_callback, args);
+ globalObject->stopTimeoutCheck();
+
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("SQLTransactionErrorCallback: %s\n", message.utf8().data());
+ if (Page* page = m_frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+ exec->clearException();
+ }
+
+ Document::updateDocumentsRendering();
+
+ return result->toBoolean(exec);
+}
+
+}
diff --git a/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h b/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h
new file mode 100644
index 0000000..6b079c4
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomSQLTransactionErrorCallback.h
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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.
+ */
+
+#ifndef JSCustomSQLTransactionErrorCallback_h
+#define JSCustomSQLTransactionErrorCallback_h
+
+#include "SQLTransactionErrorCallback.h"
+
+#include <kjs/object.h>
+#include <kjs/protect.h>
+#include <wtf/Forward.h>
+
+namespace KJS {
+ class JSObject;
+}
+
+namespace WebCore {
+
+class Frame;
+class SQLError;
+
+class JSCustomSQLTransactionErrorCallback : public SQLTransactionErrorCallback {
+public:
+ JSCustomSQLTransactionErrorCallback(KJS::JSObject* callback, Frame*);
+
+ virtual bool handleEvent(SQLError*);
+private:
+ KJS::ProtectedPtr<KJS::JSObject> m_callback;
+ RefPtr<Frame> m_frame;
+};
+
+}
+
+#endif // JSCustomSQLTransactionErrorCallback_h
diff --git a/WebCore/bindings/js/JSCustomVoidCallback.cpp b/WebCore/bindings/js/JSCustomVoidCallback.cpp
new file mode 100644
index 0000000..7964e59
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomVoidCallback.cpp
@@ -0,0 +1,118 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSCustomVoidCallback.h"
+
+#include "CString.h"
+#include "DOMWindow.h"
+#include "Frame.h"
+#include "kjs_binding.h"
+#include "kjs_proxy.h"
+#include "kjs_window.h"
+#include "Page.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+JSCustomVoidCallback::JSCustomVoidCallback(JSObject* callback, Frame* frame)
+ : m_callback(callback)
+ , m_frame(frame)
+{
+}
+
+void JSCustomVoidCallback::handleEvent()
+{
+ ASSERT(m_callback);
+ ASSERT(m_frame);
+
+ if (!m_frame->scriptProxy()->isEnabled())
+ return;
+
+ JSGlobalObject* globalObject = m_frame->scriptProxy()->globalObject();
+ ExecState* exec = globalObject->globalExec();
+
+ KJS::JSLock lock;
+
+ JSValue* handleEventFuncValue = m_callback->get(exec, "handleEvent");
+ JSObject* handleEventFunc = 0;
+ if (handleEventFuncValue->isObject()) {
+ handleEventFunc = static_cast<JSObject*>(handleEventFuncValue);
+ if (!handleEventFunc->implementsCall())
+ handleEventFunc = 0;
+ }
+
+ if (!handleEventFunc && !m_callback->implementsCall()) {
+ // FIXME: Should an exception be thrown here?
+ return;
+ }
+
+ RefPtr<JSCustomVoidCallback> protect(this);
+
+ List args;
+
+ globalObject->startTimeoutCheck();
+ if (handleEventFunc)
+ handleEventFunc->call(exec, m_callback, args);
+ else
+ m_callback->call(exec, m_callback, args);
+ globalObject->stopTimeoutCheck();
+
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("VoidCallback: %s\n", message.utf8().data());
+ if (Page* page = m_frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+ exec->clearException();
+ }
+
+ Document::updateDocumentsRendering();
+}
+
+VoidCallback* toVoidCallback(ExecState* exec, JSValue* value, bool& ok)
+{
+ ok = false;
+
+ JSObject* object = value->getObject();
+ if (!object)
+ return 0;
+
+ Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+ if (!frame)
+ return 0;
+
+ ok = true;
+ return new JSCustomVoidCallback(object, frame);
+}
+
+}
diff --git a/WebCore/bindings/js/JSCustomVoidCallback.h b/WebCore/bindings/js/JSCustomVoidCallback.h
new file mode 100644
index 0000000..1f97f39
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomVoidCallback.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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.
+ */
+
+#ifndef JSCustomVoidCallback_h
+#define JSCustomVoidCallback_h
+
+#include "VoidCallback.h"
+
+#include <kjs/object.h>
+#include <kjs/protect.h>
+#include <wtf/Forward.h>
+
+namespace KJS {
+ class JSObject;
+}
+
+namespace WebCore {
+
+ class Frame;
+ class SQLError;
+
+ class JSCustomVoidCallback : public VoidCallback {
+ public:
+ JSCustomVoidCallback(KJS::JSObject* callback, Frame*);
+
+ virtual void handleEvent();
+ private:
+ KJS::ProtectedPtr<KJS::JSObject> m_callback;
+ RefPtr<Frame> m_frame;
+ };
+
+ VoidCallback* toVoidCallback(KJS::ExecState*, KJS::JSValue*, bool& ok);
+}
+
+#endif // JSCustomVoidCallback_h
diff --git a/WebCore/bindings/js/JSCustomXPathNSResolver.cpp b/WebCore/bindings/js/JSCustomXPathNSResolver.cpp
new file mode 100644
index 0000000..a8c4788
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomXPathNSResolver.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSCustomXPathNSResolver.h"
+
+#if ENABLE(XPATH)
+
+#include "CString.h"
+#include "DOMWindow.h"
+#include "Document.h"
+#include "ExceptionCode.h"
+#include "Frame.h"
+#include "Page.h"
+
+#include "kjs_binding.h"
+#include "kjs_proxy.h"
+#include "kjs_window.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+PassRefPtr<JSCustomXPathNSResolver> JSCustomXPathNSResolver::create(KJS::ExecState* exec, KJS::JSValue* value)
+{
+ if (value->isUndefinedOrNull())
+ return 0;
+
+ JSObject* resolverObject = value->getObject();
+ if (!resolverObject) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return 0;
+ }
+
+ return new JSCustomXPathNSResolver(resolverObject, KJS::Window::retrieveActive(exec)->impl()->frame());
+}
+
+JSCustomXPathNSResolver::JSCustomXPathNSResolver(JSObject* customResolver, Frame* frame)
+ : m_customResolver(customResolver)
+ , m_frame(frame)
+{
+}
+
+JSCustomXPathNSResolver::~JSCustomXPathNSResolver()
+{
+}
+
+String JSCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
+{
+ ASSERT(m_customResolver);
+
+ if (!m_frame)
+ return String();
+ if (!m_frame->scriptProxy()->isEnabled())
+ return String();
+
+ JSLock lock;
+
+ JSGlobalObject* globalObject = m_frame->scriptProxy()->globalObject();
+ ExecState* exec = globalObject->globalExec();
+
+ JSValue* lookupNamespaceURIFuncValue = m_customResolver->get(exec, "lookupNamespaceURI");
+ JSObject* lookupNamespaceURIFunc = 0;
+ if (lookupNamespaceURIFuncValue->isObject()) {
+ lookupNamespaceURIFunc = static_cast<JSObject*>(lookupNamespaceURIFuncValue);
+ if (!lookupNamespaceURIFunc->implementsCall())
+ lookupNamespaceURIFunc = 0;
+ }
+
+ if (!lookupNamespaceURIFunc && !m_customResolver->implementsCall()) {
+ // FIXME: pass actual line number and source URL.
+ if (Page* page = m_frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "XPathNSResolver does not have a lookupNamespaceURI method.", 0, String());
+ return String();
+ }
+
+ RefPtr<JSCustomXPathNSResolver> selfProtector(this);
+
+ List args;
+ args.append(jsString(prefix));
+
+ String result;
+ JSValue* retval;
+ globalObject->startTimeoutCheck();
+ if (lookupNamespaceURIFunc)
+ retval = lookupNamespaceURIFunc->call(exec, m_customResolver, args);
+ else
+ retval = m_customResolver->call(exec, m_customResolver, args);
+ globalObject->stopTimeoutCheck();
+
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("XPathNSResolver: %s\n", message.utf8().data());
+ if (Page* page = m_frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+ exec->clearException();
+ } else {
+ if (!retval->isUndefinedOrNull())
+ result = retval->toString(exec);
+ }
+
+ Document::updateDocumentsRendering();
+
+ return result;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(XPATH)
diff --git a/WebCore/bindings/js/JSCustomXPathNSResolver.h b/WebCore/bindings/js/JSCustomXPathNSResolver.h
new file mode 100644
index 0000000..ddd407a
--- /dev/null
+++ b/WebCore/bindings/js/JSCustomXPathNSResolver.h
@@ -0,0 +1,64 @@
+/*
+ * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSCustomXPathNSResolver_h
+#define JSCustomXPathNSResolver_h
+
+#if ENABLE(XPATH)
+
+#include "XPathNSResolver.h"
+#include <wtf/Forward.h>
+#include <wtf/RefPtr.h>
+
+namespace KJS {
+ class ExecState;
+ class JSObject;
+ class JSValue;
+}
+
+namespace WebCore {
+
+ class Frame;
+
+ class JSCustomXPathNSResolver : public XPathNSResolver {
+ public:
+ static PassRefPtr<JSCustomXPathNSResolver> create(KJS::ExecState*, KJS::JSValue*);
+
+ virtual ~JSCustomXPathNSResolver();
+
+ virtual String lookupNamespaceURI(const String& prefix);
+
+ private:
+ JSCustomXPathNSResolver(KJS::JSObject*, Frame*);
+
+ KJS::JSObject* m_customResolver; // JSCustomXPathNSResolvers are always temporary, thus no need to GC protect the object.
+ RefPtr<Frame> m_frame;
+ };
+
+} // namespace WebCore
+
+#endif // ENABLE(XPATH)
+
+#endif // JSCustomXPathNSResolver_h
diff --git a/WebCore/bindings/js/JSDOMWindowCustom.cpp b/WebCore/bindings/js/JSDOMWindowCustom.cpp
new file mode 100644
index 0000000..af2353c
--- /dev/null
+++ b/WebCore/bindings/js/JSDOMWindowCustom.cpp
@@ -0,0 +1,161 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSDOMWindow.h"
+
+#include "AtomicString.h"
+#include "DOMWindow.h"
+#include "Document.h"
+#include "ExceptionCode.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "FrameTree.h"
+#include "kjs_window.h"
+#include <kjs/object.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+bool JSDOMWindow::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ // When accessing a Window cross-domain, functions are always the native built-in ones, and they
+ // are not affected by properties changed on the Window or anything in its prototype chain.
+ // This is consistent with the behavior of Firefox.
+
+ const HashEntry* entry;
+
+ // We don't want any properties other than "close" and "closed" on a closed window.
+ if (!impl()->frame()) {
+ // The following code is safe for cross-domain and same domain use.
+ // It ignores any custom properties that might be set on the DOMWindow (including a custom prototype).
+ entry = Lookup::findEntry(info.propHashTable, propertyName);
+ if (entry && !(entry->attr & Function) && entry->value.intValue == ClosedAttrNum) {
+ slot.setStaticEntry(this, entry, staticValueGetter<JSDOMWindow>);
+ return true;
+ }
+ entry = Lookup::findEntry(JSDOMWindowPrototype::info.propHashTable, propertyName);
+ if (entry && (entry->attr & Function) && entry->value.functionValue == jsDOMWindowPrototypeFunctionClose) {
+ slot.setStaticEntry(this, entry, nonCachingStaticFunctionGetter);
+ return true;
+ }
+
+ // FIXME: We should have a message here that explains why the property access/function call was
+ // not allowed.
+ slot.setUndefined(this);
+ return true;
+ }
+
+ // We need to check for cross-domain access here without printing the generic warning message
+ // because we always allow access to some function, just different ones depending whether access
+ // is allowed.
+ bool allowsAccess = allowsAccessFromNoErrorMessage(exec);
+
+ // Look for overrides before looking at any of our own properties.
+ if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) {
+ // But ignore overrides completely if this is cross-domain access.
+ if (allowsAccess)
+ return true;
+ }
+
+ // We need this code here because otherwise KJS::Window will stop the search before we even get to the
+ // prototype due to the blanket same origin (allowsAccessFrom) check at the end of getOwnPropertySlot.
+ // Also, it's important to get the implementation straight out of the DOMWindow prototype regardless of
+ // what prototype is actually set on this object.
+ entry = Lookup::findEntry(JSDOMWindowPrototype::info.propHashTable, propertyName);
+ if (entry) {
+ if ((entry->attr & Function)
+ && (entry->value.functionValue == jsDOMWindowPrototypeFunctionBlur
+ || entry->value.functionValue == jsDOMWindowPrototypeFunctionClose
+ || entry->value.functionValue == jsDOMWindowPrototypeFunctionFocus
+#if ENABLE(CROSS_DOCUMENT_MESSAGING)
+ || entry->value.functionValue == jsDOMWindowPrototypeFunctionPostMessage
+#endif
+ )) {
+ if (!allowsAccess) {
+ slot.setStaticEntry(this, entry, nonCachingStaticFunctionGetter);
+ return true;
+ }
+ }
+ } else {
+ // Allow access to toString() cross-domain, but always Object.prototype.toString.
+ if (propertyName == exec->propertyNames().toString) {
+ if (!allowsAccess) {
+ slot.setCustom(this, objectToStringFunctionGetter);
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+bool JSDOMWindow::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ if (!impl()->frame())
+ return true;
+
+ // We have a local override (e.g. "var location"), save time and jump directly to JSGlobalObject.
+ PropertySlot slot;
+ if (JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot)) {
+ if (allowsAccessFrom(exec))
+ JSGlobalObject::put(exec, propertyName, value);
+ return true;
+ }
+
+ return false;
+}
+
+bool JSDOMWindow::deleteProperty(ExecState* exec, const Identifier& propertyName)
+{
+ // Only allow deleting properties by frames in the same origin.
+ if (!allowsAccessFrom(exec))
+ return false;
+ return Base::deleteProperty(exec, propertyName);
+}
+
+bool JSDOMWindow::customGetPropertyNames(ExecState* exec, PropertyNameArray&)
+{
+ // Only allow the window to enumerated by frames in the same origin.
+ if (!allowsAccessFrom(exec))
+ return true;
+ return false;
+}
+
+#if ENABLE(CROSS_DOCUMENT_MESSAGING)
+JSValue* JSDOMWindow::postMessage(ExecState* exec, const List& args)
+{
+ DOMWindow* window = impl();
+
+ DOMWindow* source = static_cast<JSDOMWindow*>(exec->dynamicGlobalObject())->impl();
+ String domain = source->frame()->loader()->url().host();
+ String uri = source->frame()->loader()->url().string();
+ String message = args[0]->toString(exec);
+
+ if (exec->hadException())
+ return jsUndefined();
+
+ window->postMessage(message, domain, uri, source);
+
+ return jsUndefined();
+}
+#endif
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSDatabaseCustom.cpp b/WebCore/bindings/js/JSDatabaseCustom.cpp
new file mode 100644
index 0000000..c4e9265
--- /dev/null
+++ b/WebCore/bindings/js/JSDatabaseCustom.cpp
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSDatabase.h"
+
+#include "Database.h"
+#include "Document.h"
+#include "DOMWindow.h"
+#include "ExceptionCode.h"
+#include "kjs_window.h"
+#include "JSCustomSQLTransactionCallback.h"
+#include "JSCustomSQLTransactionErrorCallback.h"
+#include "JSCustomVoidCallback.h"
+#include "PlatformString.h"
+#include "SQLValue.h"
+#include <kjs/array_instance.h>
+
+namespace WebCore {
+
+using namespace KJS;
+
+JSValue* JSDatabase::changeVersion(ExecState* exec, const List& args)
+{
+ String oldVersion = args[0]->toString(exec);
+ String newVersion = args[1]->toString(exec);
+
+ Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+ if (!frame)
+ return jsUndefined();
+
+ JSObject *object;
+ if (!(object = args[2]->getObject())) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ RefPtr<SQLTransactionCallback> callback(new JSCustomSQLTransactionCallback(object, frame));
+
+ RefPtr<SQLTransactionErrorCallback> errorCallback;
+ if (!args[3]->isNull()) {
+ if (!(object = args[3]->getObject())) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ errorCallback = new JSCustomSQLTransactionErrorCallback(object, frame);
+ }
+
+ RefPtr<VoidCallback> successCallback;
+ if (!args[4]->isNull()) {
+ bool ok;
+ successCallback = toVoidCallback(exec, args[4], ok);
+ if (!ok) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+ }
+
+ m_impl->changeVersion(oldVersion, newVersion, callback.release(), errorCallback.release(), successCallback.release());
+
+ return jsUndefined();
+}
+
+JSValue* JSDatabase::transaction(ExecState* exec, const List& args)
+{
+ JSObject* object;
+
+ if (!(object = args[0]->getObject())) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+ if (!frame)
+ return jsUndefined();
+
+ RefPtr<SQLTransactionCallback> callback(new JSCustomSQLTransactionCallback(object, frame));
+ RefPtr<SQLTransactionErrorCallback> errorCallback;
+
+ if (args.size() > 1 && !args[1]->isNull()) {
+ if (!(object = args[1]->getObject())) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ errorCallback = new JSCustomSQLTransactionErrorCallback(object, frame);
+ }
+
+ RefPtr<VoidCallback> successCallback;
+ if (args.size() > 2 && !args[2]->isNull()) {
+ bool ok;
+ successCallback = toVoidCallback(exec, args[2], ok);
+ if (!ok) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+ }
+
+ m_impl->transaction(callback.release(), errorCallback.release(), successCallback.release());
+
+ return jsUndefined();
+}
+
+}
diff --git a/WebCore/bindings/js/JSDocumentCustom.cpp b/WebCore/bindings/js/JSDocumentCustom.cpp
new file mode 100644
index 0000000..a957405
--- /dev/null
+++ b/WebCore/bindings/js/JSDocumentCustom.cpp
@@ -0,0 +1,111 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSDocument.h"
+
+#include "DOMWindow.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "HTMLDocument.h"
+#include "JSDOMWindow.h"
+#include "JSHTMLDocument.h"
+#include "JSLocation.h"
+#include "kjs_proxy.h"
+
+#if ENABLE(SVG)
+#include "JSSVGDocument.h"
+#include "SVGDocument.h"
+#endif
+
+using namespace KJS;
+
+namespace WebCore {
+
+void JSDocument::mark()
+{
+ JSEventTargetNode::mark();
+ ScriptInterpreter::markDOMNodesForDocument(static_cast<Document*>(impl()));
+}
+
+JSValue* JSDocument::location(ExecState* exec) const
+{
+ Frame* frame = static_cast<Document*>(impl())->frame();
+ if (!frame)
+ return jsNull();
+
+ Window* win = Window::retrieveWindow(frame);
+ ASSERT(win);
+ return win->location();
+}
+
+void JSDocument::setLocation(ExecState* exec, JSValue* value)
+{
+ Frame* frame = static_cast<Document*>(impl())->frame();
+ if (!frame)
+ return;
+
+ String str = value->toString(exec);
+
+ // IE and Mozilla both resolve the URL relative to the source frame,
+ // not the target frame.
+ Frame* activeFrame = static_cast<JSDOMWindow*>(exec->dynamicGlobalObject())->impl()->frame();
+ if (activeFrame)
+ str = activeFrame->document()->completeURL(str).string();
+
+ bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
+ frame->loader()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), false, userGesture);
+}
+
+JSValue* toJS(ExecState* exec, Document* doc)
+{
+ if (!doc)
+ return jsNull();
+
+ JSDocument* ret = static_cast<JSDocument*>(ScriptInterpreter::getDOMObject(doc));
+ if (ret)
+ return ret;
+
+ if (doc->isHTMLDocument())
+ ret = new JSHTMLDocument(JSHTMLDocumentPrototype::self(exec), static_cast<HTMLDocument*>(doc));
+#if ENABLE(SVG)
+ else if (doc->isSVGDocument())
+ ret = new JSSVGDocument(JSSVGDocumentPrototype::self(exec), static_cast<SVGDocument*>(doc));
+#endif
+ else
+ ret = new JSDocument(JSDocumentPrototype::self(exec), doc);
+
+ // Make sure the document is kept around by the window object, and works right with the
+ // back/forward cache.
+ if (doc->frame())
+ Window::retrieveWindow(doc->frame())->putDirect("document", ret, DontDelete|ReadOnly);
+ else {
+ size_t nodeCount = 0;
+ for (Node* n = doc; n; n = n->traverseNextNode())
+ nodeCount++;
+
+ Collector::reportExtraMemoryCost(nodeCount * sizeof(Node));
+ }
+
+ ScriptInterpreter::putDOMObject(doc, ret);
+
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSElementCustom.cpp b/WebCore/bindings/js/JSElementCustom.cpp
new file mode 100644
index 0000000..814ef06
--- /dev/null
+++ b/WebCore/bindings/js/JSElementCustom.cpp
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSElement.h"
+
+#include "CSSHelper.h"
+#include "ExceptionCode.h"
+#include "HTMLFrameElementBase.h"
+#include "HTMLNames.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+static inline bool allowSettingSrcToJavascriptURL(ExecState* exec, Element* element, const String& name, const String& value)
+{
+ if ((element->hasTagName(iframeTag) || element->hasTagName(frameTag)) && equalIgnoringCase(name, "src") && protocolIs(parseURL(value), "javascript")) {
+ HTMLFrameElementBase* frame = static_cast<HTMLFrameElementBase*>(element);
+ if (!checkNodeSecurity(exec, frame->contentDocument()))
+ return false;
+ }
+ return true;
+}
+
+JSValue* JSElement::setAttribute(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ String name = args[0]->toString(exec);
+ String value = args[1]->toString(exec);
+
+ Element* imp = impl();
+ if (!allowSettingSrcToJavascriptURL(exec, imp, name, value))
+ return jsUndefined();
+
+ imp->setAttribute(name, value, ec);
+ setDOMException(exec, ec);
+ return jsUndefined();
+}
+
+JSValue* JSElement::setAttributeNode(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ bool newAttrOk;
+ Attr* newAttr = toAttr(args[0], newAttrOk);
+ if (!newAttrOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ Element* imp = impl();
+ if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value()))
+ return jsUndefined();
+
+ JSValue* result = toJS(exec, WTF::getPtr(imp->setAttributeNode(newAttr, ec)));
+ setDOMException(exec, ec);
+ return result;
+}
+
+JSValue* JSElement::setAttributeNS(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ String namespaceURI = valueToStringWithNullCheck(exec, args[0]);
+ String qualifiedName = args[1]->toString(exec);
+ String value = args[2]->toString(exec);
+
+ Element* imp = impl();
+ if (!allowSettingSrcToJavascriptURL(exec, imp, qualifiedName, value))
+ return jsUndefined();
+
+ imp->setAttributeNS(namespaceURI, qualifiedName, value, ec);
+ setDOMException(exec, ec);
+ return jsUndefined();
+}
+
+JSValue* JSElement::setAttributeNodeNS(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ bool newAttrOk;
+ Attr* newAttr = toAttr(args[0], newAttrOk);
+ if (!newAttrOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ Element* imp = impl();
+ if (!allowSettingSrcToJavascriptURL(exec, imp, newAttr->name(), newAttr->value()))
+ return jsUndefined();
+
+ JSValue* result = toJS(exec, WTF::getPtr(imp->setAttributeNodeNS(newAttr, ec)));
+ setDOMException(exec, ec);
+ return result;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSEventCustom.cpp b/WebCore/bindings/js/JSEventCustom.cpp
new file mode 100644
index 0000000..e1e044c
--- /dev/null
+++ b/WebCore/bindings/js/JSEventCustom.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSEvent.h"
+
+#include "Clipboard.h"
+#include "Event.h"
+#include "JSKeyboardEvent.h"
+#include "JSMouseEvent.h"
+#include "JSMutationEvent.h"
+#include "JSOverflowEvent.h"
+#include "JSProgressEvent.h"
+#include "JSTextEvent.h"
+#include "JSUIEvent.h"
+#include "JSWheelEvent.h"
+#include "KeyboardEvent.h"
+#include "MouseEvent.h"
+#include "MutationEvent.h"
+#include "OverflowEvent.h"
+#include "ProgressEvent.h"
+#include "TextEvent.h"
+#include "UIEvent.h"
+#include "WheelEvent.h"
+#include "kjs_events.h"
+
+#if ENABLE(CROSS_DOCUMENT_MESSAGING)
+#include "JSMessageEvent.h"
+#include "MessageEvent.h"
+#endif
+
+#if ENABLE(SVG)
+#include "JSSVGZoomEvent.h"
+#include "SVGZoomEvent.h"
+#endif
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSEvent::clipboardData(ExecState* exec) const
+{
+ return impl()->isClipboardEvent() ? toJS(exec, impl()->clipboardData()) : jsUndefined();
+}
+
+JSValue* toJS(ExecState* exec, Event* event)
+{
+ JSLock lock;
+
+ if (!event)
+ return jsNull();
+
+ DOMObject* ret = ScriptInterpreter::getDOMObject(event);
+ if (ret)
+ return ret;
+
+ if (event->isUIEvent()) {
+ if (event->isKeyboardEvent())
+ ret = new JSKeyboardEvent(JSKeyboardEventPrototype::self(exec), static_cast<KeyboardEvent*>(event));
+ else if (event->isTextEvent())
+ ret = new JSTextEvent(JSTextEventPrototype::self(exec), static_cast<TextEvent*>(event));
+ else if (event->isMouseEvent())
+ ret = new JSMouseEvent(JSMouseEventPrototype::self(exec), static_cast<MouseEvent*>(event));
+ else if (event->isWheelEvent())
+ ret = new JSWheelEvent(JSWheelEventPrototype::self(exec), static_cast<WheelEvent*>(event));
+#if ENABLE(SVG)
+ else if (event->isSVGZoomEvent())
+ ret = new JSSVGZoomEvent(JSSVGZoomEventPrototype::self(exec), static_cast<SVGZoomEvent*>(event), 0);
+#endif
+ else
+ ret = new JSUIEvent(JSUIEventPrototype::self(exec), static_cast<UIEvent*>(event));
+ } else if (event->isMutationEvent())
+ ret = new JSMutationEvent(JSMutationEventPrototype::self(exec), static_cast<MutationEvent*>(event));
+ else if (event->isOverflowEvent())
+ ret = new JSOverflowEvent(JSOverflowEventPrototype::self(exec), static_cast<OverflowEvent*>(event));
+#if ENABLE(CROSS_DOCUMENT_MESSAGING)
+ else if (event->isMessageEvent())
+ ret = new JSMessageEvent(JSMessageEventPrototype::self(exec), static_cast<MessageEvent*>(event));
+#endif
+ else if (event->isProgressEvent())
+ ret = new JSProgressEvent(JSProgressEventPrototype::self(exec), static_cast<ProgressEvent*>(event));
+ else
+ ret = new JSEvent(JSEventPrototype::self(exec), event);
+
+ ScriptInterpreter::putDOMObject(event, ret);
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSEventTargetBase.cpp b/WebCore/bindings/js/JSEventTargetBase.cpp
new file mode 100644
index 0000000..d15171c
--- /dev/null
+++ b/WebCore/bindings/js/JSEventTargetBase.cpp
@@ -0,0 +1,244 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSEventTargetBase.h"
+
+#include "JSEventTargetNode.h"
+
+#include "JSEventTargetBase.lut.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+/* Source for JSEventTargetPropertiesTable
+@begin JSEventTargetPropertiesTable 50
+onabort WebCore::JSEventTargetProperties::OnAbort DontDelete
+onblur WebCore::JSEventTargetProperties::OnBlur DontDelete
+onchange WebCore::JSEventTargetProperties::OnChange DontDelete
+onclick WebCore::JSEventTargetProperties::OnClick DontDelete
+oncontextmenu WebCore::JSEventTargetProperties::OnContextMenu DontDelete
+ondblclick WebCore::JSEventTargetProperties::OnDblClick DontDelete
+onbeforecut WebCore::JSEventTargetProperties::OnBeforeCut DontDelete
+oncut WebCore::JSEventTargetProperties::OnCut DontDelete
+onbeforecopy WebCore::JSEventTargetProperties::OnBeforeCopy DontDelete
+oncopy WebCore::JSEventTargetProperties::OnCopy DontDelete
+onbeforepaste WebCore::JSEventTargetProperties::OnBeforePaste DontDelete
+onpaste WebCore::JSEventTargetProperties::OnPaste DontDelete
+ondrag WebCore::JSEventTargetProperties::OnDrag DontDelete
+ondragend WebCore::JSEventTargetProperties::OnDragEnd DontDelete
+ondragenter WebCore::JSEventTargetProperties::OnDragEnter DontDelete
+ondragleave WebCore::JSEventTargetProperties::OnDragLeave DontDelete
+ondragover WebCore::JSEventTargetProperties::OnDragOver DontDelete
+ondragstart WebCore::JSEventTargetProperties::OnDragStart DontDelete
+ondrop WebCore::JSEventTargetProperties::OnDrop DontDelete
+onerror WebCore::JSEventTargetProperties::OnError DontDelete
+onfocus WebCore::JSEventTargetProperties::OnFocus DontDelete
+oninput WebCore::JSEventTargetProperties::OnInput DontDelete
+onkeydown WebCore::JSEventTargetProperties::OnKeyDown DontDelete
+onkeypress WebCore::JSEventTargetProperties::OnKeyPress DontDelete
+onkeyup WebCore::JSEventTargetProperties::OnKeyUp DontDelete
+onload WebCore::JSEventTargetProperties::OnLoad DontDelete
+onmousedown WebCore::JSEventTargetProperties::OnMouseDown DontDelete
+onmousemove WebCore::JSEventTargetProperties::OnMouseMove DontDelete
+onmouseout WebCore::JSEventTargetProperties::OnMouseOut DontDelete
+onmouseover WebCore::JSEventTargetProperties::OnMouseOver DontDelete
+onmouseup WebCore::JSEventTargetProperties::OnMouseUp DontDelete
+onmousewheel WebCore::JSEventTargetProperties::OnMouseWheel DontDelete
+onreset WebCore::JSEventTargetProperties::OnReset DontDelete
+onresize WebCore::JSEventTargetProperties::OnResize DontDelete
+onscroll WebCore::JSEventTargetProperties::OnScroll DontDelete
+onsearch WebCore::JSEventTargetProperties::OnSearch DontDelete
+onselect WebCore::JSEventTargetProperties::OnSelect DontDelete
+onselectstart WebCore::JSEventTargetProperties::OnSelectStart DontDelete
+onsubmit WebCore::JSEventTargetProperties::OnSubmit DontDelete
+onunload WebCore::JSEventTargetProperties::OnUnload DontDelete
+@end
+*/
+
+/*
+@begin JSEventTargetPrototypeTable 5
+addEventListener WebCore::jsEventTargetAddEventListener DontDelete|Function 3
+removeEventListener WebCore::jsEventTargetRemoveEventListener DontDelete|Function 3
+dispatchEvent WebCore::jsEventTargetDispatchEvent DontDelete|Function 1
+@end
+*/
+
+JSValue* jsEventTargetAddEventListener(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ DOMExceptionTranslator exception(exec);
+
+ Node* eventNode = 0;
+ EventTarget* eventTarget = 0;
+ if (!retrieveEventTargetAndCorrespondingNode(exec, thisObj, eventNode, eventTarget))
+ return throwError(exec, TypeError);
+
+ Frame* frame = eventNode->document()->frame();
+ if (!frame)
+ return jsUndefined();
+
+ if (JSEventListener* listener = Window::retrieveWindow(frame)->findOrCreateJSEventListener(args[1]))
+ eventTarget->addEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec));
+
+ return jsUndefined();
+}
+
+JSValue* jsEventTargetRemoveEventListener(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ DOMExceptionTranslator exception(exec);
+
+ Node* eventNode = 0;
+ EventTarget* eventTarget = 0;
+ if (!retrieveEventTargetAndCorrespondingNode(exec, thisObj, eventNode, eventTarget))
+ return throwError(exec, TypeError);
+
+ Frame* frame = eventNode->document()->frame();
+ if (!frame)
+ return jsUndefined();
+
+ if (JSEventListener* listener = Window::retrieveWindow(frame)->findJSEventListener(args[1]))
+ eventTarget->removeEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec));
+
+ return jsUndefined();
+}
+
+JSValue* jsEventTargetDispatchEvent(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ Node* eventNode = 0;
+ EventTarget* eventTarget = 0;
+ if (!retrieveEventTargetAndCorrespondingNode(exec, thisObj, eventNode, eventTarget))
+ return throwError(exec, TypeError);
+
+ DOMExceptionTranslator exception(exec);
+ return jsBoolean(eventTarget->dispatchEvent(toEvent(args[0]), exception));
+}
+
+bool retrieveEventTargetAndCorrespondingNode(KJS::ExecState*, KJS::JSObject* thisObj, Node*& eventNode, EventTarget*& eventTarget)
+{
+ if (!thisObj->inherits(&JSNode::info))
+ return false;
+
+ JSEventTargetNode* jsNode = static_cast<JSEventTargetNode*>(thisObj);
+ ASSERT(jsNode);
+
+ EventTargetNode* node = static_cast<EventTargetNode*>(jsNode->impl());
+ ASSERT(node);
+
+ eventNode = node;
+ eventTarget = node;
+ return true;
+}
+
+AtomicString eventNameForPropertyToken(int token)
+{
+ switch (token) {
+ case JSEventTargetProperties::OnAbort:
+ return abortEvent;
+ case JSEventTargetProperties::OnBlur:
+ return blurEvent;
+ case JSEventTargetProperties::OnChange:
+ return changeEvent;
+ case JSEventTargetProperties::OnClick:
+ return clickEvent;
+ case JSEventTargetProperties::OnContextMenu:
+ return contextmenuEvent;
+ case JSEventTargetProperties::OnDblClick:
+ return dblclickEvent;
+ case JSEventTargetProperties::OnError:
+ return errorEvent;
+ case JSEventTargetProperties::OnFocus:
+ return focusEvent;
+ case JSEventTargetProperties::OnInput:
+ return inputEvent;
+ case JSEventTargetProperties::OnKeyDown:
+ return keydownEvent;
+ case JSEventTargetProperties::OnKeyPress:
+ return keypressEvent;
+ case JSEventTargetProperties::OnKeyUp:
+ return keyupEvent;
+ case JSEventTargetProperties::OnLoad:
+ return loadEvent;
+ case JSEventTargetProperties::OnMouseDown:
+ return mousedownEvent;
+ case JSEventTargetProperties::OnMouseMove:
+ return mousemoveEvent;
+ case JSEventTargetProperties::OnMouseOut:
+ return mouseoutEvent;
+ case JSEventTargetProperties::OnMouseOver:
+ return mouseoverEvent;
+ case JSEventTargetProperties::OnMouseUp:
+ return mouseupEvent;
+ case JSEventTargetProperties::OnMouseWheel:
+ return mousewheelEvent;
+ case JSEventTargetProperties::OnBeforeCut:
+ return beforecutEvent;
+ case JSEventTargetProperties::OnCut:
+ return cutEvent;
+ case JSEventTargetProperties::OnBeforeCopy:
+ return beforecopyEvent;
+ case JSEventTargetProperties::OnCopy:
+ return copyEvent;
+ case JSEventTargetProperties::OnBeforePaste:
+ return beforepasteEvent;
+ case JSEventTargetProperties::OnPaste:
+ return pasteEvent;
+ case JSEventTargetProperties::OnDragEnter:
+ return dragenterEvent;
+ case JSEventTargetProperties::OnDragOver:
+ return dragoverEvent;
+ case JSEventTargetProperties::OnDragLeave:
+ return dragleaveEvent;
+ case JSEventTargetProperties::OnDrop:
+ return dropEvent;
+ case JSEventTargetProperties::OnDragStart:
+ return dragstartEvent;
+ case JSEventTargetProperties::OnDrag:
+ return dragEvent;
+ case JSEventTargetProperties::OnDragEnd:
+ return dragendEvent;
+ case JSEventTargetProperties::OnReset:
+ return resetEvent;
+ case JSEventTargetProperties::OnResize:
+ return resizeEvent;
+ case JSEventTargetProperties::OnScroll:
+ return scrollEvent;
+ case JSEventTargetProperties::OnSearch:
+ return searchEvent;
+ case JSEventTargetProperties::OnSelect:
+ return selectEvent;
+ case JSEventTargetProperties::OnSelectStart:
+ return selectstartEvent;
+ case JSEventTargetProperties::OnSubmit:
+ return submitEvent;
+ case JSEventTargetProperties::OnUnload:
+ return unloadEvent;
+ }
+
+ return AtomicString();
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSEventTargetBase.h b/WebCore/bindings/js/JSEventTargetBase.h
new file mode 100644
index 0000000..218ad18
--- /dev/null
+++ b/WebCore/bindings/js/JSEventTargetBase.h
@@ -0,0 +1,155 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSEventTargetBase_h
+#define JSEventTargetBase_h
+
+#include "Document.h"
+#include "Event.h"
+#include "EventNames.h"
+#include "JSEvent.h"
+#include "kjs_events.h"
+#include "kjs_window.h"
+
+namespace KJS {
+
+ extern const struct HashTable JSEventTargetPropertiesTable;
+ extern const struct HashTable JSEventTargetPrototypeTable;
+
+}
+
+namespace WebCore {
+
+ using namespace EventNames;
+
+ class AtomicString;
+ class EventTarget;
+
+ // Event target properties (shared across all JSEventTarget* classes)
+ struct JSEventTargetProperties {
+ enum {
+ AddEventListener, RemoveEventListener, DispatchEvent,
+ OnAbort, OnBlur, OnChange, OnClick, OnContextMenu, OnDblClick, OnError,
+ OnDragEnter, OnDragOver, OnDragLeave, OnDrop, OnDragStart, OnDrag, OnDragEnd,
+ OnBeforeCut, OnCut, OnBeforeCopy, OnCopy, OnBeforePaste, OnPaste, OnSelectStart,
+ OnFocus, OnInput, OnKeyDown, OnKeyPress, OnKeyUp, OnLoad, OnMouseDown,
+ OnMouseMove, OnMouseOut, OnMouseOver, OnMouseUp, OnMouseWheel, OnReset,
+ OnResize, OnScroll, OnSearch, OnSelect, OnSubmit, OnUnload
+ };
+ };
+
+ // Helper function for the partial specializated template functions below
+ bool retrieveEventTargetAndCorrespondingNode(KJS::ExecState*, KJS::JSObject* thisObj, Node*&, EventTarget*&);
+
+ // Functions
+ KJS::JSValue* jsEventTargetAddEventListener(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsEventTargetRemoveEventListener(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsEventTargetDispatchEvent(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
+ // Helper function for getValueProperty/putValueProperty
+ AtomicString eventNameForPropertyToken(int token);
+
+ template<class JSEventTarget>
+ class JSEventTargetBase {
+ public:
+ JSEventTargetBase() { }
+
+ KJS::JSValue* getValueProperty(const JSEventTarget* owner, KJS::ExecState* exec, int token) const
+ {
+ AtomicString eventName = eventNameForPropertyToken(token);
+ if (!eventName.isEmpty())
+ return owner->getListener(eventName);
+
+ return KJS::jsUndefined();
+ }
+
+ void putValueProperty(const JSEventTarget* owner, KJS::ExecState* exec, int token, KJS::JSValue* value)
+ {
+ AtomicString eventName = eventNameForPropertyToken(token);
+ if (!eventName.isEmpty())
+ owner->setListener(exec, eventName, value);
+ }
+
+ private:
+ friend class JSEventTargetNode;
+ friend class JSEventTargetSVGElementInstance;
+
+ template<class JSParent>
+ bool getOwnPropertySlot(JSEventTarget* owner, KJS::ExecState* exec, const KJS::Identifier& propertyName, KJS::PropertySlot& slot)
+ {
+ return KJS::getStaticValueSlot<JSEventTarget, JSParent>(exec, &KJS::JSEventTargetPropertiesTable, owner, propertyName, slot);
+ }
+
+ template<class JSParent>
+ void put(JSEventTarget* owner, KJS::ExecState* exec, const KJS::Identifier& propertyName, KJS::JSValue* value)
+ {
+ KJS::lookupPut<JSEventTarget, JSParent>(exec, propertyName, value, &KJS::JSEventTargetPropertiesTable, owner);
+ }
+ };
+
+ // This class is a modified version of the code the KJS_DEFINE_PROTOTYPE_WITH_PROTOTYPE
+ // and KJS_IMPLEMENT_PROTOTYPE macros produce - the idea is that classes like JSEventTargetNode
+ // and JSEventTargetSVGElementInstance can share a single prototype just differing in the
+ // naming "EventTargetNodePrototype" vs "EventTargetSVGElementInstancePrototype". Above mentioned
+ // macros force the existance of several prototype tables for each of the classes - avoid that.
+ template<class JSEventTargetPrototypeParent, class JSEventTargetPrototypeInformation>
+ class JSEventTargetPrototype : public KJS::JSObject {
+ public:
+ JSEventTargetPrototype(KJS::ExecState* exec)
+ : KJS::JSObject(JSEventTargetPrototypeParent::self(exec))
+ {
+ }
+
+ static KJS::JSObject* self(KJS::ExecState* exec)
+ {
+ static KJS::Identifier* prototypeName = new KJS::Identifier(JSEventTargetPrototypeInformation::prototypeClassName());
+
+ KJS::JSGlobalObject* globalObject = exec->lexicalGlobalObject();
+ if (KJS::JSValue* objectValue = globalObject->getDirect(*prototypeName)) {
+ ASSERT(objectValue->isObject());
+ return static_cast<KJS::JSObject*>(objectValue);
+ }
+
+ KJS::JSObject* newObject = new JSEventTargetPrototype<JSEventTargetPrototypeParent, JSEventTargetPrototypeInformation>(exec);
+ globalObject->putDirect(*prototypeName, newObject, KJS::DontEnum);
+ return newObject;
+ }
+
+ bool getOwnPropertySlot(KJS::ExecState* exec, const KJS::Identifier& propertyName, KJS::PropertySlot& slot)
+ {
+ return KJS::getStaticFunctionSlot<KJS::JSObject>(exec, &KJS::JSEventTargetPrototypeTable, this, propertyName, slot);
+ }
+
+ virtual const KJS::ClassInfo* classInfo() const
+ {
+ static const KJS::ClassInfo s_classInfo = { JSEventTargetPrototypeInformation::prototypeClassName(), 0, &KJS::JSEventTargetPrototypeTable };
+ return &s_classInfo;
+ }
+ };
+
+} // namespace WebCore
+
+#endif // JSEventTargetBase_h
diff --git a/WebCore/bindings/js/JSEventTargetNode.cpp b/WebCore/bindings/js/JSEventTargetNode.cpp
new file mode 100644
index 0000000..92c0048
--- /dev/null
+++ b/WebCore/bindings/js/JSEventTargetNode.cpp
@@ -0,0 +1,88 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSEventTargetNode.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+JSEventTargetNode::JSEventTargetNode(JSObject* prototype, Node* node)
+ : JSNode(prototype, node)
+{
+}
+
+bool JSEventTargetNode::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return m_base.getOwnPropertySlot<JSNode>(this, exec, propertyName, slot);
+}
+
+JSValue* JSEventTargetNode::getValueProperty(ExecState* exec, int token) const
+{
+ return m_base.getValueProperty(this, exec, token);
+}
+
+void JSEventTargetNode::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ m_base.put<JSNode>(this, exec, propertyName, value);
+}
+
+void JSEventTargetNode::putValueProperty(ExecState* exec, int token, JSValue* value)
+{
+ m_base.putValueProperty(this, exec, token, value);
+}
+
+void JSEventTargetNode::setListener(ExecState* exec, const AtomicString& eventType, JSValue* func) const
+{
+ Frame* frame = impl()->document()->frame();
+ if (frame)
+ EventTargetNodeCast(impl())->setHTMLEventListener(eventType, KJS::Window::retrieveWindow(frame)->findOrCreateJSEventListener(func, true));
+}
+
+JSValue* JSEventTargetNode::getListener(const AtomicString& eventType) const
+{
+ EventListener* listener = EventTargetNodeCast(impl())->getHTMLEventListener(eventType);
+ JSEventListener* jsListener = static_cast<JSEventListener*>(listener);
+ if (jsListener && jsListener->listenerObj())
+ return jsListener->listenerObj();
+
+ return jsNull();
+}
+
+void JSEventTargetNode::pushEventHandlerScope(ExecState*, ScopeChain&) const
+{
+}
+
+EventTargetNode* toEventTargetNode(JSValue* val)
+{
+ if (!val || !val->isObject(&JSEventTargetNode::info))
+ return 0;
+
+ return static_cast<EventTargetNode*>(static_cast<JSEventTargetNode*>(val)->impl());
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSEventTargetNode.h b/WebCore/bindings/js/JSEventTargetNode.h
new file mode 100644
index 0000000..f83490a
--- /dev/null
+++ b/WebCore/bindings/js/JSEventTargetNode.h
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSEventTargetNode_h
+#define JSEventTargetNode_h
+
+#include "JSNode.h"
+#include "JSEventTargetBase.h"
+
+namespace WebCore {
+
+ class EventTargetNode;
+ class Node;
+
+ class JSEventTargetNode : public JSNode {
+ public:
+ JSEventTargetNode(KJS::JSObject* prototype, Node*);
+
+ void setListener(KJS::ExecState*, const AtomicString& eventType, KJS::JSValue* func) const;
+ KJS::JSValue* getListener(const AtomicString& eventType) const;
+ virtual void pushEventHandlerScope(KJS::ExecState*, KJS::ScopeChain&) const;
+
+ bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+ KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
+ virtual void put(KJS::ExecState*, const KJS::Identifier&, KJS::JSValue*);
+ void putValueProperty(KJS::ExecState*, int token, KJS::JSValue*);
+
+ private:
+ JSEventTargetBase<JSEventTargetNode> m_base;
+ };
+
+ struct JSEventTargetPrototypeInformation {
+ static const char* prototypeClassName()
+ {
+ return "EventTargetNodePrototype";
+ }
+
+ static const char* prototypeIdentifier()
+ {
+ return "[[EventTargetNode.prototype]]";
+ }
+ };
+
+ typedef JSEventTargetPrototype<JSNodePrototype, JSEventTargetPrototypeInformation> JSEventTargetNodePrototype;
+ EventTargetNode* toEventTargetNode(KJS::JSValue*);
+
+} // namespace WebCore
+
+#endif // JSEventTargetNode_h
diff --git a/WebCore/bindings/js/JSHTMLAllCollection.h b/WebCore/bindings/js/JSHTMLAllCollection.h
new file mode 100644
index 0000000..4661e12
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLAllCollection.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSHTMLAllCollection_h
+#define JSHTMLAllCollection_h
+
+#include "JSHTMLCollection.h"
+
+namespace WebCore {
+
+ class HTMLCollection;
+
+ class JSHTMLAllCollection : public JSHTMLCollection {
+ public:
+ JSHTMLAllCollection(KJS::JSObject* prototype, HTMLCollection* collection)
+ : JSHTMLCollection(prototype, collection)
+ {
+ }
+
+ virtual bool toBoolean(KJS::ExecState*) const { return false; }
+ virtual bool masqueradeAsUndefined() const { return true; }
+ };
+
+} // namespace WebCore
+
+#endif // JSHTMLAllCollection_h
diff --git a/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp b/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp
new file mode 100644
index 0000000..d34b8b5
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLAppletElementCustom.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSHTMLAppletElement.h"
+
+#include "HTMLAppletElement.h"
+#include "kjs_dom.h"
+#include "kjs_html.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+bool JSHTMLAppletElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLAppletElement::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ return runtimeObjectCustomPut(exec, propertyName, value, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLAppletElement::implementsCall() const
+{
+ return runtimeObjectImplementsCall(static_cast<HTMLElement*>(impl()));
+}
+
+JSValue* JSHTMLAppletElement::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ return runtimeObjectCallAsFunction(exec, thisObj, args, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLAppletElement::canGetItemsForName(ExecState*, HTMLAppletElement*, const Identifier& propertyName)
+{
+ return propertyName == "__apple_runtime_object";
+}
+
+JSValue* JSHTMLAppletElement::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ return runtimeObjectGetter(exec, originalObject, propertyName, slot);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLCollectionCustom.cpp b/WebCore/bindings/js/JSHTMLCollectionCustom.cpp
new file mode 100644
index 0000000..2c44ab0
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLCollectionCustom.cpp
@@ -0,0 +1,151 @@
+/*
+ * Copyright (C) 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSHTMLCollection.h"
+
+#include "AtomicString.h"
+#include "HTMLCollection.h"
+#include "HTMLOptionsCollection.h"
+#include "JSHTMLAllCollection.h"
+#include "JSHTMLOptionsCollection.h"
+#include "JSNamedNodesCollection.h"
+#include "JSNode.h"
+#include "Node.h"
+#include "kjs_binding.h"
+#include "kjs_html.h"
+#include <wtf/Vector.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+static JSValue* getNamedItems(ExecState* exec, HTMLCollection* impl, const Identifier& propertyName)
+{
+ Vector<RefPtr<Node> > namedItems;
+ impl->namedItems(propertyName, namedItems);
+
+ if (namedItems.isEmpty())
+ return jsUndefined();
+
+ if (namedItems.size() == 1)
+ return toJS(exec, namedItems[0].get());
+
+ return new JSNamedNodesCollection(exec->lexicalGlobalObject()->objectPrototype(), namedItems);
+}
+
+// HTMLCollections are strange objects, they support both get and call,
+// so that document.forms.item(0) and document.forms(0) both work.
+JSValue* JSHTMLCollection::callAsFunction(ExecState* exec, JSObject*, const List& args)
+{
+ if (args.size() < 1)
+ return jsUndefined();
+
+ // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case.
+ HTMLCollection* collection = impl();
+
+ // Also, do we need the TypeError test here ?
+
+ if (args.size() == 1) {
+ // Support for document.all(<index>) etc.
+ bool ok;
+ UString string = args[0]->toString(exec);
+ unsigned index = string.toUInt32(&ok, false);
+ if (ok)
+ return toJS(exec, collection->item(index));
+
+ // Support for document.images('<name>') etc.
+ return getNamedItems(exec, collection, Identifier(string));
+ }
+
+ // The second arg, if set, is the index of the item we want
+ bool ok;
+ UString string = args[0]->toString(exec);
+ unsigned index = args[1]->toString(exec).toUInt32(&ok, false);
+ if (ok) {
+ String pstr = string;
+ Node* node = collection->namedItem(pstr);
+ while (node) {
+ if (!index)
+ return toJS(exec, node);
+ node = collection->nextNamedItem(pstr);
+ --index;
+ }
+ }
+
+ return jsUndefined();
+}
+
+bool JSHTMLCollection::implementsCall() const
+{
+ return true;
+}
+
+bool JSHTMLCollection::canGetItemsForName(ExecState* exec, HTMLCollection* thisObj, const Identifier& propertyName)
+{
+ return !getNamedItems(exec, thisObj, propertyName)->isUndefined();
+}
+
+JSValue* JSHTMLCollection::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSHTMLCollection* thisObj = static_cast<JSHTMLCollection*>(slot.slotBase());
+ return getNamedItems(exec, thisObj->impl(), propertyName);
+}
+
+JSValue* JSHTMLCollection::item(ExecState* exec, const List& args)
+{
+ bool ok;
+ uint32_t index = args[0]->toString(exec).toUInt32(&ok, false);
+ if (ok)
+ return toJS(exec, impl()->item(index));
+ return getNamedItems(exec, impl(), Identifier(args[0]->toString(exec)));
+}
+
+JSValue* JSHTMLCollection::namedItem(ExecState* exec, const List& args)
+{
+ return getNamedItems(exec, impl(), Identifier(args[0]->toString(exec)));
+}
+
+JSValue* toJS(ExecState* exec, HTMLCollection* collection)
+{
+ if (!collection)
+ return jsNull();
+
+ DOMObject* ret = ScriptInterpreter::getDOMObject(collection);
+
+ if (ret)
+ return ret;
+
+ switch (collection->type()) {
+ case HTMLCollection::SelectOptions:
+ ret = new JSHTMLOptionsCollection(JSHTMLOptionsCollectionPrototype::self(exec), static_cast<HTMLOptionsCollection*>(collection));
+ break;
+ case HTMLCollection::DocAll:
+ ret = new JSHTMLAllCollection(JSHTMLCollectionPrototype::self(exec), static_cast<HTMLCollection*>(collection));
+ break;
+ default:
+ ret = new JSHTMLCollection(JSHTMLCollectionPrototype::self(exec), static_cast<HTMLCollection*>(collection));
+ break;
+ }
+
+ ScriptInterpreter::putDOMObject(collection, ret);
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLDocumentCustom.cpp b/WebCore/bindings/js/JSHTMLDocumentCustom.cpp
new file mode 100644
index 0000000..5455617
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLDocumentCustom.cpp
@@ -0,0 +1,145 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSHTMLDocument.h"
+
+#include "Frame.h"
+#include "HTMLBodyElement.h"
+#include "HTMLCollection.h"
+#include "HTMLDocument.h"
+#include "HTMLElement.h"
+#include "HTMLIFrameElement.h"
+#include "HTMLNames.h"
+#include "JSHTMLCollection.h"
+#include "kjs_html.h"
+#include "kjs_window.h"
+
+namespace WebCore {
+
+using namespace KJS;
+using namespace HTMLNames;
+
+bool JSHTMLDocument::canGetItemsForName(ExecState*, HTMLDocument* doc, const Identifier& propertyName)
+{
+ return doc->hasNamedItem(propertyName) || doc->hasDocExtraNamedItem(propertyName);
+}
+
+JSValue* JSHTMLDocument::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSHTMLDocument* thisObj = static_cast<JSHTMLDocument*>(slot.slotBase());
+ HTMLDocument* doc = static_cast<HTMLDocument*>(thisObj->impl());
+
+ String name = propertyName;
+ RefPtr<HTMLCollection> collection = doc->documentNamedItems(name);
+
+ unsigned length = collection->length();
+ if (!length)
+ return jsUndefined();
+
+ if (length == 1) {
+ Node* node = collection->firstItem();
+
+ Frame* frame;
+ if (node->hasTagName(iframeTag) && (frame = static_cast<HTMLIFrameElement*>(node)->contentFrame()))
+ return KJS::Window::retrieve(frame);
+
+ return toJS(exec, node);
+ }
+
+ return toJS(exec, collection.get());
+}
+
+// Custom attributes
+
+JSValue* JSHTMLDocument::all(ExecState* exec) const
+{
+ // If "all" has been overwritten, return the overwritten value
+ if (JSValue* v = getDirect("all"))
+ return v;
+
+ return toJS(exec, static_cast<HTMLDocument*>(impl())->all().get());
+}
+
+void JSHTMLDocument::setAll(ExecState*, JSValue* value)
+{
+ // Add "all" to the property map.
+ putDirect("all", value);
+}
+
+// Custom functions
+
+JSValue* JSHTMLDocument::open(ExecState* exec, const List& args)
+{
+ // For compatibility with other browsers, pass open calls with more than 2 parameters to the window.
+ if (args.size() > 2) {
+ Frame* frame = static_cast<HTMLDocument*>(impl())->frame();
+ if (frame) {
+ KJS::Window* window = KJS::Window::retrieveWindow(frame);
+ if (window) {
+ JSObject* functionObject = window->get(exec, "open")->getObject();
+ if (!functionObject || !functionObject->implementsCall())
+ return throwError(exec, TypeError);
+ return functionObject->call(exec, window, args);
+ }
+ }
+ return jsUndefined();
+ }
+
+ // In the case of two parameters or fewer, do a normal document open.
+ static_cast<HTMLDocument*>(impl())->open();
+ return jsUndefined();
+}
+
+static String writeHelper(ExecState* exec, const List& args)
+{
+ // DOM only specifies single string argument, but NS & IE allow multiple
+ // or no arguments.
+ String str = "";
+ for (unsigned int i = 0; i < args.size(); ++i)
+ str += args[i]->toString(exec);
+ return str;
+}
+
+JSValue* JSHTMLDocument::write(ExecState* exec, const List& args)
+{
+ static_cast<HTMLDocument*>(impl())->write(writeHelper(exec, args));
+ return jsUndefined();
+}
+
+JSValue* JSHTMLDocument::writeln(ExecState* exec, const List& args)
+{
+ static_cast<HTMLDocument*>(impl())->write(writeHelper(exec, args) + "\n");
+ return jsUndefined();
+}
+
+JSValue* JSHTMLDocument::clear(ExecState*, const List&)
+{
+ // even IE doesn't support this one...
+ // static_cast<HTMLDocument*>(impl())->clear();
+ return jsUndefined();
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLElementCustom.cpp b/WebCore/bindings/js/JSHTMLElementCustom.cpp
new file mode 100644
index 0000000..755277a
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLElementCustom.cpp
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSHTMLElement.h"
+
+#include "Document.h"
+#include "HTMLFormElement.h"
+#include "kjs_dom.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+void JSHTMLElement::pushEventHandlerScope(ExecState* exec, ScopeChain& scope) const
+{
+ HTMLElement* element = impl();
+
+ // The document is put on first, fall back to searching it only after the element and form.
+ scope.push(static_cast<JSObject*>(toJS(exec, element->ownerDocument())));
+
+ // The form is next, searched before the document, but after the element itself.
+ if (HTMLFormElement* form = element->form())
+ scope.push(static_cast<JSObject*>(toJS(exec, form)));
+
+ // The element is on top, searched first.
+ scope.push(static_cast<JSObject*>(toJS(exec, element)));
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLElementWrapperFactory.cpp b/WebCore/bindings/js/JSHTMLElementWrapperFactory.cpp
new file mode 100644
index 0000000..1202e6c
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLElementWrapperFactory.cpp
@@ -0,0 +1,273 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "JSHTMLElementWrapperFactory.h"
+
+#include "HTMLAnchorElement.h"
+#include "HTMLAppletElement.h"
+#include "HTMLAreaElement.h"
+#include "HTMLAudioElement.h"
+#include "HTMLBRElement.h"
+#include "HTMLBaseElement.h"
+#include "HTMLBaseFontElement.h"
+#include "HTMLBlockquoteElement.h"
+#include "HTMLBodyElement.h"
+#include "HTMLButtonElement.h"
+#include "HTMLCanvasElement.h"
+#include "HTMLDListElement.h"
+#include "HTMLDirectoryElement.h"
+#include "HTMLDivElement.h"
+#include "HTMLEmbedElement.h"
+#include "HTMLFieldSetElement.h"
+#include "HTMLFontElement.h"
+#include "HTMLFormElement.h"
+#include "HTMLFrameElement.h"
+#include "HTMLFrameSetElement.h"
+#include "HTMLHRElement.h"
+#include "HTMLHeadElement.h"
+#include "HTMLHeadingElement.h"
+#include "HTMLHtmlElement.h"
+#include "HTMLIFrameElement.h"
+#include "HTMLImageElement.h"
+#include "HTMLInputElement.h"
+#include "HTMLIsIndexElement.h"
+#include "HTMLLIElement.h"
+#include "HTMLLabelElement.h"
+#include "HTMLLegendElement.h"
+#include "HTMLLinkElement.h"
+#include "HTMLMapElement.h"
+#include "HTMLMarqueeElement.h"
+#include "HTMLMenuElement.h"
+#include "HTMLMetaElement.h"
+#include "HTMLModElement.h"
+#include "HTMLOListElement.h"
+#include "HTMLObjectElement.h"
+#include "HTMLOptGroupElement.h"
+#include "HTMLOptionElement.h"
+#include "HTMLParagraphElement.h"
+#include "HTMLParamElement.h"
+#include "HTMLPreElement.h"
+#include "HTMLQuoteElement.h"
+#include "HTMLScriptElement.h"
+#include "HTMLSelectElement.h"
+#include "HTMLSourceElement.h"
+#include "HTMLStyleElement.h"
+#include "HTMLTableCaptionElement.h"
+#include "HTMLTableCellElement.h"
+#include "HTMLTableColElement.h"
+#include "HTMLTableElement.h"
+#include "HTMLTableRowElement.h"
+#include "HTMLTableSectionElement.h"
+#include "HTMLTextAreaElement.h"
+#include "HTMLTitleElement.h"
+#include "HTMLUListElement.h"
+#include "HTMLVideoElement.h"
+
+#include "HTMLNames.h"
+
+#include "JSHTMLAnchorElement.h"
+#include "JSHTMLAppletElement.h"
+#include "JSHTMLAreaElement.h"
+#include "JSHTMLBRElement.h"
+#include "JSHTMLBaseElement.h"
+#include "JSHTMLBaseFontElement.h"
+#include "JSHTMLBlockquoteElement.h"
+#include "JSHTMLBodyElement.h"
+#include "JSHTMLButtonElement.h"
+#include "JSHTMLCanvasElement.h"
+#include "JSHTMLDListElement.h"
+#include "JSHTMLDirectoryElement.h"
+#include "JSHTMLDivElement.h"
+#include "JSHTMLEmbedElement.h"
+#include "JSHTMLFieldSetElement.h"
+#include "JSHTMLFontElement.h"
+#include "JSHTMLFormElement.h"
+#include "JSHTMLFrameElement.h"
+#include "JSHTMLFrameSetElement.h"
+#include "JSHTMLHRElement.h"
+#include "JSHTMLHeadElement.h"
+#include "JSHTMLHeadingElement.h"
+#include "JSHTMLHtmlElement.h"
+#include "JSHTMLIFrameElement.h"
+#include "JSHTMLImageElement.h"
+#include "JSHTMLInputElement.h"
+#include "JSHTMLIsIndexElement.h"
+#include "JSHTMLLIElement.h"
+#include "JSHTMLLabelElement.h"
+#include "JSHTMLLegendElement.h"
+#include "JSHTMLLinkElement.h"
+#include "JSHTMLMapElement.h"
+#include "JSHTMLMarqueeElement.h"
+#include "JSHTMLMenuElement.h"
+#include "JSHTMLMetaElement.h"
+#include "JSHTMLModElement.h"
+#include "JSHTMLOListElement.h"
+#include "JSHTMLObjectElement.h"
+#include "JSHTMLOptGroupElement.h"
+#include "JSHTMLOptionElement.h"
+#include "JSHTMLParagraphElement.h"
+#include "JSHTMLParamElement.h"
+#include "JSHTMLPreElement.h"
+#include "JSHTMLQuoteElement.h"
+#include "JSHTMLScriptElement.h"
+#include "JSHTMLSelectElement.h"
+#include "JSHTMLStyleElement.h"
+#include "JSHTMLTableCaptionElement.h"
+#include "JSHTMLTableCellElement.h"
+#include "JSHTMLTableColElement.h"
+#include "JSHTMLTableElement.h"
+#include "JSHTMLTableRowElement.h"
+#include "JSHTMLTableSectionElement.h"
+#include "JSHTMLTextAreaElement.h"
+#include "JSHTMLTitleElement.h"
+#include "JSHTMLUListElement.h"
+
+#if ENABLE(VIDEO)
+#include "JSHTMLAudioElement.h"
+#include "JSHTMLSourceElement.h"
+#include "JSHTMLVideoElement.h"
+#endif
+
+#include "kjs_html.h"
+
+using namespace KJS;
+
+// FIXME: Eventually this file should be autogenerated, just like HTMLNames, HTMLElementFactory, etc.
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+typedef JSNode* (*CreateHTMLElementWrapperFunction)(ExecState*, PassRefPtr<HTMLElement>);
+
+#define FOR_EACH_TAG(macro) \
+ macro(a, Anchor) \
+ macro(applet, Applet) \
+ macro(area, Area) \
+ macro(base, Base) \
+ macro(basefont, BaseFont) \
+ macro(blockquote, Blockquote) \
+ macro(body, Body) \
+ macro(br, BR) \
+ macro(button, Button) \
+ macro(canvas, Canvas) \
+ macro(caption, TableCaption) \
+ macro(col, TableCol) \
+ macro(del, Mod) \
+ macro(dir, Directory) \
+ macro(div, Div) \
+ macro(dl, DList) \
+ macro(embed, Embed) \
+ macro(fieldset, FieldSet) \
+ macro(font, Font) \
+ macro(form, Form) \
+ macro(frame, Frame) \
+ macro(frameset, FrameSet) \
+ macro(h1, Heading) \
+ macro(head, Head) \
+ macro(hr, HR) \
+ macro(html, Html) \
+ macro(iframe, IFrame) \
+ macro(img, Image) \
+ macro(input, Input) \
+ macro(isindex, IsIndex) \
+ macro(label, Label) \
+ macro(legend, Legend) \
+ macro(li, LI) \
+ macro(link, Link) \
+ macro(map, Map) \
+ macro(marquee, Marquee) \
+ macro(menu, Menu) \
+ macro(meta, Meta) \
+ macro(object, Object) \
+ macro(ol, OList) \
+ macro(optgroup, OptGroup) \
+ macro(option, Option) \
+ macro(p, Paragraph) \
+ macro(param, Param) \
+ macro(pre, Pre) \
+ macro(q, Quote) \
+ macro(script, Script) \
+ macro(select, Select) \
+ macro(style, Style) \
+ macro(table, Table) \
+ macro(tbody, TableSection) \
+ macro(td, TableCell) \
+ macro(textarea, TextArea) \
+ macro(tr, TableRow) \
+ macro(title, Title) \
+ macro(ul, UList) \
+ // end of macro
+
+#define FOR_EACH_MEDIA_TAG(macro) \
+ macro(audio, Audio) \
+ macro(source, Source) \
+ macro(video, Video) \
+ // end of macro
+
+#define CREATE_WRAPPER_FUNCTION(tag, name) \
+static JSNode* create##name##Wrapper(ExecState* exec, PassRefPtr<HTMLElement> element) \
+{ \
+ return new JSHTML##name##Element(JSHTML##name##ElementPrototype::self(exec), static_cast<HTML##name##Element*>(element.get())); \
+}
+#define CREATE_MEDIA_WRAPPER_FUNCTION(tag, name) \
+static JSNode* create##name##Wrapper(ExecState* exec, PassRefPtr<HTMLElement> element) \
+{ \
+ if (!MediaPlayer::isAvailable()) \
+ return new JSHTMLElement(JSHTMLElementPrototype::self(exec), element.get()); \
+ return new JSHTML##name##Element(JSHTML##name##ElementPrototype::self(exec), static_cast<HTML##name##Element*>(element.get())); \
+}
+FOR_EACH_TAG(CREATE_WRAPPER_FUNCTION)
+#if ENABLE(VIDEO)
+ FOR_EACH_MEDIA_TAG(CREATE_MEDIA_WRAPPER_FUNCTION)
+#endif
+#undef CREATE_WRAPPER_FUNCTION
+
+JSNode* createJSHTMLWrapper(ExecState* exec, PassRefPtr<HTMLElement> element)
+{
+ static HashMap<AtomicStringImpl*, CreateHTMLElementWrapperFunction> map;
+ if (map.isEmpty()) {
+#define ADD_TO_HASH_MAP(tag, name) map.set(tag##Tag.localName().impl(), create##name##Wrapper);
+FOR_EACH_TAG(ADD_TO_HASH_MAP)
+#if ENABLE(VIDEO)
+FOR_EACH_MEDIA_TAG(ADD_TO_HASH_MAP)
+#endif
+#undef ADD_TO_HASH_MAP
+ map.set(colgroupTag.localName().impl(), createTableColWrapper);
+ map.set(h2Tag.localName().impl(), createHeadingWrapper);
+ map.set(h3Tag.localName().impl(), createHeadingWrapper);
+ map.set(h4Tag.localName().impl(), createHeadingWrapper);
+ map.set(h5Tag.localName().impl(), createHeadingWrapper);
+ map.set(h6Tag.localName().impl(), createHeadingWrapper);
+ map.set(imageTag.localName().impl(), createImageWrapper);
+ map.set(insTag.localName().impl(), createModWrapper);
+ map.set(keygenTag.localName().impl(), createSelectWrapper);
+ map.set(listingTag.localName().impl(), createPreWrapper);
+ map.set(tfootTag.localName().impl(), createTableSectionWrapper);
+ map.set(thTag.localName().impl(), createTableCellWrapper);
+ map.set(theadTag.localName().impl(), createTableSectionWrapper);
+ map.set(xmpTag.localName().impl(), createPreWrapper);
+ }
+ CreateHTMLElementWrapperFunction createWrapperFunction = map.get(element->localName().impl());
+ if (createWrapperFunction)
+ return createWrapperFunction(exec, element);
+ return new JSHTMLElement(JSHTMLElementPrototype::self(exec), element.get());
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLElementWrapperFactory.h b/WebCore/bindings/js/JSHTMLElementWrapperFactory.h
new file mode 100644
index 0000000..8e8bffa
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLElementWrapperFactory.h
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All ri
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef JSHTMLElementWrapperFactory_h
+#define JSHTMLElementWrapperFactory_h
+
+#include <wtf/Forward.h>
+
+namespace KJS {
+ class ExecState;
+}
+
+namespace WebCore {
+
+ class JSNode;
+ class HTMLElement;
+
+ JSNode* createJSHTMLWrapper(KJS::ExecState*, PassRefPtr<HTMLElement>);
+
+}
+
+#endif
diff --git a/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp b/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp
new file mode 100644
index 0000000..1224f2c
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLEmbedElementCustom.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSHTMLEmbedElement.h"
+
+#include "HTMLEmbedElement.h"
+#include "kjs_dom.h"
+#include "kjs_html.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+bool JSHTMLEmbedElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLEmbedElement::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ return runtimeObjectCustomPut(exec, propertyName, value, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLEmbedElement::implementsCall() const
+{
+ return runtimeObjectImplementsCall(static_cast<HTMLElement*>(impl()));
+}
+
+JSValue* JSHTMLEmbedElement::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ return runtimeObjectCallAsFunction(exec, thisObj, args, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLEmbedElement::canGetItemsForName(ExecState*, HTMLEmbedElement*, const Identifier& propertyName)
+{
+ return propertyName == "__apple_runtime_object";
+}
+
+JSValue* JSHTMLEmbedElement::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ return runtimeObjectGetter(exec, originalObject, propertyName, slot);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLFormElementCustom.cpp b/WebCore/bindings/js/JSHTMLFormElementCustom.cpp
new file mode 100644
index 0000000..8e24618
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLFormElementCustom.cpp
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSHTMLFormElement.h"
+
+#include "HTMLCollection.h"
+#include "HTMLFormElement.h"
+#include "JSNamedNodesCollection.h"
+#include "kjs_dom.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+bool JSHTMLFormElement::canGetItemsForName(ExecState* exec, HTMLFormElement* form, const Identifier& propertyName)
+{
+ Vector<RefPtr<Node> > namedItems;
+ form->getNamedElements(propertyName, namedItems);
+ return namedItems.size();
+}
+
+JSValue* JSHTMLFormElement::nameGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
+{
+ HTMLFormElement* form = static_cast<HTMLFormElement*>(static_cast<JSHTMLElement*>(slot.slotBase())->impl());
+
+ Vector<RefPtr<Node> > namedItems;
+ form->getNamedElements(propertyName, namedItems);
+
+ if (namedItems.size() == 1)
+ return toJS(exec, namedItems[0].get());
+ if (namedItems.size() > 1)
+ return new JSNamedNodesCollection(exec->lexicalGlobalObject()->objectPrototype(), namedItems);
+ return jsUndefined();
+}
+
+}
diff --git a/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp b/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp
new file mode 100644
index 0000000..b5b6370
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLFrameElementCustom.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSHTMLFrameElement.h"
+
+#include "CSSHelper.h"
+#include "HTMLFrameElement.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+static inline bool allowSettingJavascriptURL(ExecState* exec, HTMLFrameElement* imp, const String& value)
+{
+ if (protocolIs(parseURL(value), "javascript")) {
+ if (!checkNodeSecurity(exec, imp->contentDocument()))
+ return false;
+ }
+ return true;
+}
+
+void JSHTMLFrameElement::setSrc(ExecState* exec, JSValue* value)
+{
+ HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl());
+ String srcValue = valueToStringWithNullCheck(exec, value);
+
+ if (!allowSettingJavascriptURL(exec, imp, srcValue))
+ return;
+
+ imp->setSrc(srcValue);
+ return;
+}
+
+void JSHTMLFrameElement::setLocation(ExecState* exec, JSValue* value)
+{
+ HTMLFrameElement* imp = static_cast<HTMLFrameElement*>(impl());
+ String locationValue = valueToStringWithNullCheck(exec, value);
+
+ if (!allowSettingJavascriptURL(exec, imp, locationValue))
+ return;
+
+ imp->setLocation(locationValue);
+ return;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp b/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp
new file mode 100644
index 0000000..1e10dc2
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLFrameSetElementCustom.cpp
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSHTMLFrameSetElement.h"
+
+#include "Document.h"
+#include "HTMLFrameElement.h"
+#include "HTMLFrameSetElement.h"
+#include "HTMLNames.h"
+#include "kjs_binding.h"
+#include "kjs_window.h"
+
+namespace WebCore {
+
+using namespace KJS;
+using namespace HTMLNames;
+
+bool JSHTMLFrameSetElement::canGetItemsForName(ExecState*, HTMLFrameSetElement* frameSet, const Identifier& propertyName)
+{
+ Node* frame = frameSet->children()->namedItem(propertyName);
+ return frame && frame->hasTagName(frameTag);
+}
+
+JSValue* JSHTMLFrameSetElement::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(slot.slotBase());
+ HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl());
+
+ Node* frame = element->children()->namedItem(propertyName);
+ if (Document* doc = static_cast<HTMLFrameElement*>(frame)->contentDocument()) {
+ if (KJS::Window* window = KJS::Window::retrieveWindow(doc->frame()))
+ return window;
+ }
+
+ return jsUndefined();
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLIFrameElementCustom.cpp b/WebCore/bindings/js/JSHTMLIFrameElementCustom.cpp
new file mode 100644
index 0000000..309c932
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLIFrameElementCustom.cpp
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSHTMLIFrameElement.h"
+
+#include "CSSHelper.h"
+#include "HTMLIFrameElement.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+void JSHTMLIFrameElement::setSrc(ExecState* exec, JSValue* value)
+{
+ HTMLIFrameElement* imp = static_cast<HTMLIFrameElement*>(impl());
+
+ String srcValue = valueToStringWithNullCheck(exec, value);
+
+ if (protocolIs(parseURL(srcValue), "javascript")) {
+ if (!checkNodeSecurity(exec, imp->contentDocument()))
+ return;
+ }
+
+ imp->setSrc(srcValue);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLInputElementBase.cpp b/WebCore/bindings/js/JSHTMLInputElementBase.cpp
new file mode 100644
index 0000000..f4b54b3
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLInputElementBase.cpp
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSHTMLInputElementBase.h"
+
+#include "HTMLInputElement.h"
+
+#include "JSHTMLInputElementBaseTable.cpp"
+
+using namespace KJS;
+
+namespace WebCore {
+
+/*
+@begin JSHTMLInputElementBaseTable 3
+ selectionStart WebCore::JSHTMLInputElementBase::SelectionStart DontDelete
+ selectionEnd WebCore::JSHTMLInputElementBase::SelectionEnd DontDelete
+@end
+@begin JSHTMLInputElementBasePrototypeTable 0
+@end
+@begin JSHTMLInputElementBaseFunctionTable 1
+ setSelectionRange WebCore::jsHTMLInputElementBaseFunctionSetSelectionRange DontDelete|Function 2
+@end
+*/
+
+KJS_IMPLEMENT_PROTOTYPE("JSHTMLInputElementBase", JSHTMLInputElementBasePrototype)
+
+JSValue* jsHTMLInputElementBaseFunctionSetSelectionRange(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ HTMLInputElement& input = *static_cast<HTMLInputElement*>(static_cast<JSHTMLInputElementBase*>(thisObj)->impl());
+ input.setSelectionRange(args[0]->toInt32(exec), args[1]->toInt32(exec));
+ return jsUndefined();
+}
+
+const ClassInfo JSHTMLInputElementBase::info = { "JSHTMLInputElementBase", &JSHTMLElement::info, &JSHTMLInputElementBaseTable };
+
+JSHTMLInputElementBase::JSHTMLInputElementBase(KJS::JSObject* prototype, PassRefPtr<HTMLInputElement> e)
+ : JSHTMLElement(prototype, e.get())
+{
+}
+
+bool JSHTMLInputElementBase::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ HTMLInputElement& input = *static_cast<HTMLInputElement*>(impl());
+
+ // if this element doesn't support selection, we have nothing to do, try our parent
+ if (!input.canHaveSelection())
+ return JSHTMLElement::getOwnPropertySlot(exec, propertyName, slot);
+
+ // otherwise, do our own function lookup on our function table
+ const HashEntry* entry = Lookup::findEntry(&JSHTMLInputElementBaseFunctionTable, propertyName);
+ if (entry && (entry->attr & KJS::Function) && entry->value.functionValue == jsHTMLInputElementBaseFunctionSetSelectionRange) {
+ slot.setStaticEntry(this, entry, staticFunctionGetter);
+ return true;
+ }
+ ASSERT(!entry);
+
+ // finally try value lookup or walk the parent chain
+ return getStaticValueSlot<JSHTMLInputElementBase, JSHTMLElement>(exec, &JSHTMLInputElementBaseTable, this, propertyName, slot);
+}
+
+JSValue* JSHTMLInputElementBase::getValueProperty(ExecState* exec, int token) const
+{
+ HTMLInputElement& input = *static_cast<HTMLInputElement*>(impl());
+ ASSERT(input.canHaveSelection());
+ switch (token) {
+ case SelectionStart:
+ return jsNumber(input.selectionStart());
+ case SelectionEnd:
+ return jsNumber(input.selectionEnd());
+ }
+ ASSERT_NOT_REACHED();
+ return jsUndefined();
+}
+
+void JSHTMLInputElementBase::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ lookupPut<JSHTMLInputElementBase, JSHTMLElement>(exec, propertyName, value, &JSHTMLInputElementBaseTable, this);
+}
+
+void JSHTMLInputElementBase::putValueProperty(ExecState* exec, int token, JSValue* value)
+{
+ HTMLInputElement& input = *static_cast<HTMLInputElement*>(impl());
+ ASSERT(input.canHaveSelection());
+ switch (token) {
+ case SelectionStart:
+ input.setSelectionStart(value->toInt32(exec));
+ return;
+ case SelectionEnd:
+ input.setSelectionEnd(value->toInt32(exec));
+ return;
+ }
+ ASSERT_NOT_REACHED();
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLInputElementBase.h b/WebCore/bindings/js/JSHTMLInputElementBase.h
new file mode 100644
index 0000000..cb90e07
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLInputElementBase.h
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef JSHTMLInputElementBase_h
+#define JSHTMLInputElementBase_h
+
+#include "JSHTMLElement.h"
+#include "kjs_binding.h"
+#include "kjs_html.h"
+
+namespace WebCore {
+
+ class HTMLInputElement;
+
+ KJS_DEFINE_PROTOTYPE_WITH_PROTOTYPE(JSHTMLInputElementBasePrototype, JSHTMLElementPrototype)
+
+ class JSHTMLInputElementBase : public JSHTMLElement {
+ public:
+ JSHTMLInputElementBase(KJS::JSObject* prototype, PassRefPtr<HTMLInputElement>);
+
+ virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+ KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
+ virtual void put(KJS::ExecState*, const KJS::Identifier& propertyName, JSValue*);
+ void putValueProperty(KJS::ExecState*, int token, KJS::JSValue*);
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+ enum { SelectionStart, SelectionEnd };
+ };
+
+ // SetSelectionRange is implemented on the class instead of on the prototype
+ // to make it easier to enable/disable lookup of the function based on input type.
+ KJS::JSValue* jsHTMLInputElementBaseFunctionSetSelectionRange(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
+} // namespace WebCore
+
+#endif // JSHTMLInputElementBase_h
diff --git a/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp b/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp
new file mode 100644
index 0000000..83e9b0d
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLObjectElementCustom.cpp
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSHTMLObjectElement.h"
+
+#include "HTMLObjectElement.h"
+#include "kjs_dom.h"
+#include "kjs_html.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+bool JSHTMLObjectElement::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return runtimeObjectCustomGetOwnPropertySlot(exec, propertyName, slot, this, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLObjectElement::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ return runtimeObjectCustomPut(exec, propertyName, value, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLObjectElement::implementsCall() const
+{
+ return runtimeObjectImplementsCall(static_cast<HTMLElement*>(impl()));
+}
+
+JSValue* JSHTMLObjectElement::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ return runtimeObjectCallAsFunction(exec, thisObj, args, static_cast<HTMLElement*>(impl()));
+}
+
+bool JSHTMLObjectElement::canGetItemsForName(ExecState*, HTMLObjectElement*, const Identifier& propertyName)
+{
+ return propertyName == "__apple_runtime_object";
+}
+
+JSValue* JSHTMLObjectElement::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ return runtimeObjectGetter(exec, originalObject, propertyName, slot);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLOptionElementConstructor.cpp b/WebCore/bindings/js/JSHTMLOptionElementConstructor.cpp
new file mode 100644
index 0000000..551854a
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLOptionElementConstructor.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSHTMLOptionElementConstructor.h"
+
+#include "Document.h"
+#include "HTMLOptionElement.h"
+#include "JSHTMLOptionElement.h"
+#include "Text.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSHTMLOptionElementConstructor::JSHTMLOptionElementConstructor(ExecState* exec, Document* document)
+ : DOMObject(exec->lexicalGlobalObject()->objectPrototype())
+ , m_document(document)
+{
+ putDirect(exec->propertyNames().length, jsNumber(4), ReadOnly|DontDelete|DontEnum);
+}
+
+bool JSHTMLOptionElementConstructor::implementsConstruct() const
+{
+ return true;
+}
+
+JSObject* JSHTMLOptionElementConstructor::construct(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ RefPtr<HTMLOptionElement> element = static_pointer_cast<HTMLOptionElement>(m_document->createElement("option", ec));
+ if (element) {
+ RefPtr<Text> text = m_document->createTextNode("");
+ if (!args[0]->isUndefined())
+ text->setData(args[0]->toString(exec), ec);
+ if (ec == 0)
+ element->appendChild(text.release(), ec);
+ if (ec == 0 && !args[1]->isUndefined())
+ element->setValue(args[1]->toString(exec));
+ if (ec == 0)
+ element->setDefaultSelected(args[2]->toBoolean(exec));
+ if (ec == 0)
+ element->setSelected(args[3]->toBoolean(exec));
+ }
+
+ setDOMException(exec, ec);
+ if (ec || !element)
+ return 0;
+
+ return static_cast<JSObject*>(toJS(exec, element.release()));
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSHTMLOptionElementConstructor.h b/WebCore/bindings/js/JSHTMLOptionElementConstructor.h
new file mode 100644
index 0000000..47a95c7
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLOptionElementConstructor.h
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef JSHTMLOptionElementConstructor_h
+#define JSHTMLOptionElementConstructor_h
+
+#include "kjs_binding.h"
+#include <wtf/RefPtr.h>
+
+namespace WebCore {
+
+ class JSHTMLOptionElementConstructor : public DOMObject {
+ public:
+ JSHTMLOptionElementConstructor(KJS::ExecState*, Document*);
+ virtual bool implementsConstruct() const;
+ virtual KJS::JSObject* construct(KJS::ExecState*, const KJS::List& args);
+ private:
+ RefPtr<Document> m_document;
+ };
+
+}
+
+#endif
diff --git a/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp b/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp
new file mode 100644
index 0000000..c0daf19
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp
@@ -0,0 +1,98 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSHTMLOptionsCollection.h"
+
+#include "ExceptionCode.h"
+#include "HTMLNames.h"
+#include "HTMLOptionElement.h"
+#include "HTMLOptionsCollection.h"
+#include "HTMLSelectElement.h"
+#include "JSHTMLOptionElement.h"
+#include "JSHTMLSelectElement.h"
+#include "JSHTMLSelectElementCustom.h"
+
+#include <wtf/MathExtras.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSHTMLOptionsCollection::length(ExecState* exec) const
+{
+ HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
+ return jsNumber(imp->length());
+}
+
+void JSHTMLOptionsCollection::setLength(ExecState* exec, JSValue* value)
+{
+ HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
+ ExceptionCode ec = 0;
+ unsigned newLength = 0;
+ double lengthValue = value->toNumber(exec);
+ if (!isnan(lengthValue) && !isinf(lengthValue)) {
+ if (lengthValue < 0.0)
+ ec = INDEX_SIZE_ERR;
+ else if (lengthValue > static_cast<double>(UINT_MAX))
+ newLength = UINT_MAX;
+ else
+ newLength = static_cast<unsigned>(lengthValue);
+ }
+ if (!ec)
+ imp->setLength(newLength, ec);
+ setDOMException(exec, ec);
+}
+
+void JSHTMLOptionsCollection::indexSetter(ExecState* exec, unsigned index, JSValue* value)
+{
+ HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
+ HTMLSelectElement* base = static_cast<HTMLSelectElement*>(imp->base());
+ selectIndexSetter(base, exec, index, value);
+}
+
+JSValue* JSHTMLOptionsCollection::add(ExecState* exec, const List& args)
+{
+ HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
+ HTMLOptionElement* option = toHTMLOptionElement(args[0]);
+ ExceptionCode ec = 0;
+ if (args.size() < 2)
+ imp->add(option, ec);
+ else {
+ bool ok;
+ int index = args[1]->toInt32(exec, ok);
+ if (exec->hadException())
+ return jsUndefined();
+ if (!ok)
+ ec = TYPE_MISMATCH_ERR;
+ else
+ imp->add(option, index, ec);
+ }
+ setDOMException(exec, ec);
+ return jsUndefined();
+}
+
+JSValue* JSHTMLOptionsCollection::remove(ExecState* exec, const List& args)
+{
+ HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
+ JSHTMLSelectElement* base = static_cast<JSHTMLSelectElement*>(toJS(exec, imp->base()));
+ return base->remove(exec, args);
+}
+
+}
diff --git a/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp b/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp
new file mode 100644
index 0000000..9688cfe
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2007 Apple, Inc.
+ * Copyright (C) 2007 Alexey Proskuryakov (ap@webkit.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSHTMLSelectElementCustom.h"
+
+#include "ExceptionCode.h"
+#include "HTMLNames.h"
+#include "HTMLOptionElement.h"
+#include "HTMLSelectElement.h"
+#include "JSHTMLOptionElement.h"
+#include "kjs_html.h"
+
+namespace WebCore {
+
+using namespace KJS;
+using namespace HTMLNames;
+
+JSValue* JSHTMLSelectElement::remove(ExecState* exec, const List& args)
+{
+ HTMLSelectElement& select = *static_cast<HTMLSelectElement*>(impl());
+
+ // we support both options index and options objects
+ HTMLElement* element = toHTMLElement(args[0]);
+ if (element && element->hasTagName(optionTag))
+ select.remove(static_cast<HTMLOptionElement*>(element)->index());
+ else
+ select.remove(args[0]->toInt32(exec));
+
+ return jsUndefined();
+}
+
+void selectIndexSetter(HTMLSelectElement* select, KJS::ExecState* exec, unsigned index, KJS::JSValue* value)
+{
+ if (value->isUndefinedOrNull())
+ select->remove(index);
+ else {
+ ExceptionCode ec = 0;
+ HTMLOptionElement* option = toHTMLOptionElement(value);
+ if (!option)
+ ec = TYPE_MISMATCH_ERR;
+ else
+ select->setOption(index, option, ec);
+ setDOMException(exec, ec);
+ }
+}
+
+void JSHTMLSelectElement::indexSetter(KJS::ExecState* exec, unsigned index, KJS::JSValue* value)
+{
+ selectIndexSetter(static_cast<HTMLSelectElement*>(impl()), exec, index, value);
+}
+
+}
diff --git a/WebCore/bindings/js/JSHTMLSelectElementCustom.h b/WebCore/bindings/js/JSHTMLSelectElementCustom.h
new file mode 100644
index 0000000..b6f08c7
--- /dev/null
+++ b/WebCore/bindings/js/JSHTMLSelectElementCustom.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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.
+ */
+
+#ifndef JSHTMLSelectElementCustom_h
+#define JSHTMLSelectElementCustom_h
+
+#include "JSHTMLSelectElement.h"
+
+namespace WebCore {
+
+void selectIndexSetter(HTMLSelectElement*, KJS::ExecState*, unsigned index, KJS::JSValue*);
+
+}
+
+#endif
diff --git a/WebCore/bindings/js/JSHistoryCustom.cpp b/WebCore/bindings/js/JSHistoryCustom.cpp
new file mode 100644
index 0000000..0e5d0d0
--- /dev/null
+++ b/WebCore/bindings/js/JSHistoryCustom.cpp
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2008 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSHistory.h"
+
+#include "Frame.h"
+#include "History.h"
+#include "kjs_window.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+bool JSHistory::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ // When accessing History cross-domain, functions are always the native built-in ones.
+ // See JSDOMWindow::customGetOwnPropertySlot for additional details.
+
+ // Our custom code is only needed to implement the Window cross-domain scheme, so if access is
+ // allowed, return false so the normal lookup will take place.
+ String message;
+ if (allowsAccessFromFrame(exec, impl()->frame(), message))
+ return false;
+
+ // Check for the few functions that we allow, even when called cross-domain.
+ const HashEntry* entry = Lookup::findEntry(JSHistoryPrototype::info.propHashTable, propertyName);
+ if (entry) {
+ // Allow access to back(), forward() and go() from any frame.
+ if ((entry->attr & Function)
+ && (entry->value.functionValue == jsHistoryPrototypeFunctionBack
+ || entry->value.functionValue == jsHistoryPrototypeFunctionForward
+ || entry->value.functionValue == jsHistoryPrototypeFunctionGo)) {
+ slot.setStaticEntry(this, entry, nonCachingStaticFunctionGetter);
+ return true;
+ }
+ } else {
+ // Allow access to toString() cross-domain, but always Object.toString.
+ if (propertyName == exec->propertyNames().toString) {
+ slot.setCustom(this, objectToStringFunctionGetter);
+ return true;
+ }
+ }
+
+ printErrorMessageForFrame(impl()->frame(), message);
+ slot.setUndefined(this);
+ return true;
+}
+
+bool JSHistory::customPut(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ // Only allow putting by frames in the same origin.
+ if (!allowsAccessFromFrame(exec, impl()->frame()))
+ return true;
+ return false;
+}
+
+bool JSHistory::deleteProperty(ExecState* exec, const Identifier& propertyName)
+{
+ // Only allow deleting by frames in the same origin.
+ if (!allowsAccessFromFrame(exec, impl()->frame()))
+ return false;
+ return Base::deleteProperty(exec, propertyName);
+}
+
+bool JSHistory::customGetPropertyNames(ExecState* exec, PropertyNameArray&)
+{
+ // Only allow the history object to enumerated by frames in the same origin.
+ if (!allowsAccessFromFrame(exec, impl()->frame()))
+ return true;
+ return false;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSLocation.cpp b/WebCore/bindings/js/JSLocation.cpp
new file mode 100644
index 0000000..2fc1a34
--- /dev/null
+++ b/WebCore/bindings/js/JSLocation.cpp
@@ -0,0 +1,313 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include "config.h"
+#include "JSLocation.h"
+
+#include "DOMWindow.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "kjs_proxy.h"
+#include "kjs_window.h"
+
+#include "JSLocation.lut.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+const ClassInfo JSLocation::info = { "Location", 0, &JSLocationTable };
+
+/*
+@begin JSLocationTable 12
+ assign WebCore::jsLocationProtoFuncAssign DontDelete|Function 1
+ hash WebCore::JSLocation::Hash DontDelete
+ host WebCore::JSLocation::Host DontDelete
+ hostname WebCore::JSLocation::Hostname DontDelete
+ href WebCore::JSLocation::Href DontDelete
+ pathname WebCore::JSLocation::Pathname DontDelete
+ port WebCore::JSLocation::Port DontDelete
+ protocol WebCore::JSLocation::Protocol DontDelete
+ search WebCore::JSLocation::Search DontDelete
+ toString WebCore::jsLocationProtoFuncToString DontEnum|DontDelete|Function 0
+ replace WebCore::jsLocationProtoFuncReplace DontDelete|Function 1
+ reload WebCore::jsLocationProtoFuncReload DontDelete|Function 0
+@end
+*/
+
+JSLocation::JSLocation(JSObject* /*prototype*/, Frame* frame)
+ : DOMObject(jsNull()) // FIXME: this needs to take a real prototype
+ , m_frame(frame)
+{
+}
+
+JSValue* JSLocation::getValueProperty(ExecState* exec, int token) const
+{
+ const KURL& url = m_frame->loader()->url();
+ switch (token) {
+ case Hash:
+ return jsString(url.ref().isNull() ? "" : "#" + url.ref());
+ case Host: {
+ // Note: this is the IE spec. The NS spec swaps the two, it says
+ // "The hostname property is the concatenation of the host and port properties, separated by a colon."
+ // Bleh.
+ UString str = url.host();
+ if (url.port())
+ str += ":" + String::number((int)url.port());
+ return jsString(str);
+ }
+ case Hostname:
+ return jsString(url.host());
+ case Href:
+ if (!url.hasPath())
+ return jsString(url.prettyURL() + "/");
+ return jsString(url.prettyURL());
+ case Pathname:
+ return jsString(url.path().isEmpty() ? "/" : url.path());
+ case Port:
+ return jsString(url.port() ? String::number((int)url.port()) : "");
+ case Protocol:
+ return jsString(url.protocol() + ":");
+ case Search:
+ return jsString(url.query());
+ default:
+ ASSERT_NOT_REACHED();
+ return jsUndefined();
+ }
+}
+
+bool JSLocation::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ if (customGetOwnPropertySlot(exec, propertyName, slot))
+ return true;
+ return getStaticPropertySlot<JSLocation, JSObject>(exec, &JSLocationTable, this, propertyName, slot);
+}
+
+bool JSLocation::customGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ // When accessing Location cross-domain, functions are always the native built-in ones.
+ // See JSDOMWindow::customGetOwnPropertySlot for additional details.
+
+ // Our custom code is only needed to implement the Window cross-domain scheme, so if access is
+ // allowed, return false so the normal lookup will take place.
+ String message;
+ if (allowsAccessFromFrame(exec, m_frame, message))
+ return false;
+
+ // Check for the few functions that we allow, even when called cross-domain.
+ const HashEntry* entry = Lookup::findEntry(&JSLocationTable, propertyName);
+ if (entry && (entry->attr & Function)
+ && (entry->value.functionValue == jsLocationProtoFuncReplace
+ || entry->value.functionValue == jsLocationProtoFuncReload
+ || entry->value.functionValue == jsLocationProtoFuncAssign)) {
+ slot.setStaticEntry(this, entry, nonCachingStaticFunctionGetter);
+ return true;
+ }
+ // FIXME: Other implementers of the Window cross-domain scheme (Window, History) allow toString,
+ // but for now we have decided not to, partly because it seems silly to return "[Object Location]" in
+ // such cases when normally the string form of Location would be the URL.
+
+ printErrorMessageForFrame(m_frame, message);
+ slot.setUndefined(this);
+ return true;
+}
+
+void JSLocation::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ if (!m_frame)
+ return;
+
+ String str = value->toString(exec);
+ KURL url = m_frame->loader()->url();
+ bool sameDomainAccess = allowsAccessFromFrame(exec, m_frame);
+
+ const HashEntry* entry = Lookup::findEntry(&JSLocationTable, propertyName);
+
+ if (entry) {
+ // cross-domain access to the location is allowed when assigning the whole location,
+ // but not when assigning the individual pieces, since that might inadvertently
+ // disclose other parts of the original location.
+ if (entry->value.intValue != Href && !sameDomainAccess)
+ return;
+
+ switch (entry->value.intValue) {
+ case Href: {
+ // FIXME: Why isn't this security check needed for the other properties, like Host, below?
+ Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+ if (!frame)
+ return;
+ if (!frame->loader()->shouldAllowNavigation(m_frame))
+ return;
+ url = frame->loader()->completeURL(str);
+ break;
+ }
+ case Hash:
+ if (str.startsWith("#"))
+ str = str.substring(1);
+ if (url.ref() == str)
+ return;
+ url.setRef(str);
+ break;
+ case Host:
+ url.setHostAndPort(str);
+ break;
+ case Hostname:
+ url.setHost(str);
+ break;
+ case Pathname:
+ url.setPath(str);
+ break;
+ case Port: {
+ // FIXME: Could make this a little less ugly if String provided a toUnsignedShort function.
+ int port = str.toInt();
+ if (port < 0 || port > 0xFFFF)
+ port = 0;
+ url.setPort(port);
+ break;
+ }
+ case Protocol:
+ url.setProtocol(str);
+ break;
+ case Search:
+ url.setQuery(str);
+ break;
+ default:
+ // Disallow changing other properties in JSLocationTable. e.g., "window.location.toString = ...".
+ // <http://bugs.webkit.org/show_bug.cgi?id=12720>
+ return;
+ }
+ } else {
+ if (sameDomainAccess)
+ JSObject::put(exec, propertyName, value);
+ return;
+ }
+
+ Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
+ if (!url.protocolIs("javascript") || sameDomainAccess) {
+ bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
+ m_frame->loader()->scheduleLocationChange(url.string(), activeFrame->loader()->outgoingReferrer(), false, userGesture);
+ }
+}
+
+bool JSLocation::deleteProperty(ExecState* exec, const Identifier& propertyName)
+{
+ // Only allow deleting by frames in the same origin.
+ if (!allowsAccessFromFrame(exec, m_frame))
+ return false;
+ return Base::deleteProperty(exec, propertyName);
+}
+
+void JSLocation::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
+{
+ // Only allow the location object to enumerated by frames in the same origin.
+ if (!allowsAccessFromFrame(exec, m_frame))
+ return;
+ Base::getPropertyNames(exec, propertyNames);
+}
+
+JSValue* jsLocationProtoFuncReplace(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSLocation::info))
+ return throwError(exec, TypeError);
+ JSLocation* location = static_cast<JSLocation*>(thisObj);
+ Frame* frame = location->frame();
+ if (!frame)
+ return jsUndefined();
+
+ Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
+ if (activeFrame) {
+ if (!activeFrame->loader()->shouldAllowNavigation(frame))
+ return jsUndefined();
+ String str = args[0]->toString(exec);
+ const Window* window = Window::retrieveWindow(frame);
+ if (!protocolIs(str, "javascript") || (window && window->allowsAccessFrom(exec))) {
+ bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
+ frame->loader()->scheduleLocationChange(activeFrame->loader()->completeURL(str).string(), activeFrame->loader()->outgoingReferrer(), true, userGesture);
+ }
+ }
+
+ return jsUndefined();
+}
+
+JSValue* jsLocationProtoFuncReload(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSLocation::info))
+ return throwError(exec, TypeError);
+ JSLocation* location = static_cast<JSLocation*>(thisObj);
+ Frame* frame = location->frame();
+ if (!frame)
+ return jsUndefined();
+
+ Window* window = Window::retrieveWindow(frame);
+ if (!window->allowsAccessFrom(exec))
+ return jsUndefined();
+
+ if (!frame->loader()->url().protocolIs("javascript") || (window && window->allowsAccessFrom(exec))) {
+ bool userGesture = Window::retrieveActive(exec)->impl()->frame()->scriptProxy()->processingUserGesture();
+ frame->loader()->scheduleRefresh(userGesture);
+ }
+ return jsUndefined();
+}
+
+JSValue* jsLocationProtoFuncAssign(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSLocation::info))
+ return throwError(exec, TypeError);
+ JSLocation* location = static_cast<JSLocation*>(thisObj);
+ Frame* frame = location->frame();
+ if (!frame)
+ return jsUndefined();
+
+ Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
+ if (activeFrame) {
+ if (!activeFrame->loader()->shouldAllowNavigation(frame))
+ return jsUndefined();
+ const Window* window = Window::retrieveWindow(frame);
+ String dstUrl = activeFrame->loader()->completeURL(args[0]->toString(exec)).string();
+ if (!protocolIs(dstUrl, "javascript") || (window && window->allowsAccessFrom(exec))) {
+ bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
+ // We want a new history item if this JS was called via a user gesture
+ frame->loader()->scheduleLocationChange(dstUrl, activeFrame->loader()->outgoingReferrer(), false, userGesture);
+ }
+ }
+
+ return jsUndefined();
+}
+
+JSValue* jsLocationProtoFuncToString(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSLocation::info))
+ return throwError(exec, TypeError);
+ JSLocation* location = static_cast<JSLocation*>(thisObj);
+ Frame* frame = location->frame();
+ if (!frame)
+ return jsUndefined();
+ if (!allowsAccessFromFrame(exec, frame))
+ return jsUndefined();
+
+ const KURL& url = frame->loader()->url();
+ if (!url.hasPath())
+ return jsString(url.prettyURL() + "/");
+ return jsString(url.prettyURL());
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSLocation.h b/WebCore/bindings/js/JSLocation.h
new file mode 100644
index 0000000..152c8a3
--- /dev/null
+++ b/WebCore/bindings/js/JSLocation.h
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef JSLocation_h
+#define JSLocation_h
+
+#include "kjs_binding.h"
+
+namespace KJS {
+ class Window;
+}
+
+namespace WebCore {
+
+ class Frame;
+
+ class JSLocation : public DOMObject {
+ typedef DOMObject Base;
+
+ friend class KJS::Window;
+ public:
+ JSLocation(KJS::JSObject* protoype, Frame*);
+
+ virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+ KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
+ virtual void put(KJS::ExecState*, const KJS::Identifier&, KJS::JSValue*);
+ virtual bool deleteProperty(KJS::ExecState*, const KJS::Identifier&);
+ virtual void getPropertyNames(KJS::ExecState*, KJS::PropertyNameArray&);
+
+ enum {
+ Hash, Href, Hostname, Host,
+ Pathname, Port, Protocol, Search,
+ Replace, Reload, ToString, Assign
+ };
+
+ Frame* frame() const { return m_frame; }
+
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+
+ private:
+ bool customGetOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+
+ Frame* m_frame;
+ };
+
+ // Functions
+ KJS::JSValue* jsLocationProtoFuncAssign(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsLocationProtoFuncToString(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsLocationProtoFuncReplace(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsLocationProtoFuncReload(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
+} // namespace WebCore
+
+#endif // JSLocation_h
diff --git a/WebCore/bindings/js/JSNamedNodeMapCustom.cpp b/WebCore/bindings/js/JSNamedNodeMapCustom.cpp
new file mode 100644
index 0000000..7cb60bf
--- /dev/null
+++ b/WebCore/bindings/js/JSNamedNodeMapCustom.cpp
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSNamedNodeMap.h"
+
+#include "NamedNodeMap.h"
+#include "kjs_binding.h"
+#include "kjs_dom.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+bool JSNamedNodeMap::canGetItemsForName(ExecState*, NamedNodeMap* impl, const Identifier& propertyName)
+{
+ return impl->getNamedItem(propertyName);
+}
+
+JSValue* JSNamedNodeMap::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSNamedNodeMap* thisObj = static_cast<JSNamedNodeMap*>(slot.slotBase());
+ return toJS(exec, thisObj->impl()->getNamedItem(propertyName));
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSNamedNodesCollection.cpp b/WebCore/bindings/js/JSNamedNodesCollection.cpp
new file mode 100644
index 0000000..1fc008f
--- /dev/null
+++ b/WebCore/bindings/js/JSNamedNodesCollection.cpp
@@ -0,0 +1,90 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSNamedNodesCollection.h"
+
+#include "AtomicString.h"
+#include "NamedAttrMap.h"
+#include "Node.h"
+#include "kjs_dom.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+const ClassInfo JSNamedNodesCollection::info = { "Collection", 0, 0 };
+
+// Such a collection is usually very short-lived, it only exists
+// for constructs like document.forms.<name>[1],
+// so it shouldn't be a problem that it's storing all the nodes (with the same name). (David)
+JSNamedNodesCollection::JSNamedNodesCollection(KJS::JSObject* prototype, const Vector<RefPtr<Node> >& nodes)
+ : DOMObject(prototype)
+ , m_nodes(nodes)
+{
+}
+
+JSValue* JSNamedNodesCollection::lengthGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSNamedNodesCollection* thisObj = static_cast<JSNamedNodesCollection*>(slot.slotBase());
+ return jsNumber(thisObj->m_nodes.size());
+}
+
+JSValue* JSNamedNodesCollection::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSNamedNodesCollection *thisObj = static_cast<JSNamedNodesCollection*>(slot.slotBase());
+ return toJS(exec, thisObj->m_nodes[slot.index()].get());
+}
+
+bool JSNamedNodesCollection::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ if (propertyName == exec->propertyNames().length) {
+ slot.setCustom(this, lengthGetter);
+ return true;
+ }
+
+ bool ok;
+ unsigned index = propertyName.toUInt32(&ok);
+ if (ok && index < m_nodes.size()) {
+ slot.setCustomIndex(this, index, indexGetter);
+ return true;
+ }
+
+ // For IE compatibility, we need to be able to look up elements in a
+ // document.formName.name result by id as well as be index.
+
+ AtomicString atomicPropertyName = propertyName;
+ for (unsigned i = 0; i < m_nodes.size(); i++) {
+ Node* node = m_nodes[i].get();
+ if (node->hasAttributes() && node->attributes()->id() == atomicPropertyName) {
+ slot.setCustomIndex(this, i, indexGetter);
+ return true;
+ }
+ }
+
+ return DOMObject::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSNamedNodesCollection.h b/WebCore/bindings/js/JSNamedNodesCollection.h
new file mode 100644
index 0000000..4b89c80
--- /dev/null
+++ b/WebCore/bindings/js/JSNamedNodesCollection.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSNamedNodesCollection_h
+#define JSNamedNodesCollection_h
+
+#include "kjs_binding.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+ class Node;
+
+ // Internal class, used for the collection return by e.g. document.forms.myinput
+ // when multiple nodes have the same name.
+ class JSNamedNodesCollection : public DOMObject {
+ public:
+ JSNamedNodesCollection(KJS::JSObject* prototype, const Vector<RefPtr<Node> >&);
+
+ virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+
+ private:
+ static KJS::JSValue* lengthGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
+ static KJS::JSValue* indexGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
+
+ Vector<RefPtr<Node> > m_nodes;
+ };
+
+} // namespace WebCore
+
+#endif // JSNamedNodesCollection_h
diff --git a/WebCore/bindings/js/JSNodeCustom.cpp b/WebCore/bindings/js/JSNodeCustom.cpp
new file mode 100644
index 0000000..20fdad2
--- /dev/null
+++ b/WebCore/bindings/js/JSNodeCustom.cpp
@@ -0,0 +1,222 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSNode.h"
+
+#include "Attr.h"
+#include "CDATASection.h"
+#include "Comment.h"
+#include "Document.h"
+#include "DocumentFragment.h"
+#include "DocumentType.h"
+#include "Entity.h"
+#include "EntityReference.h"
+#include "HTMLElement.h"
+#include "JSAttr.h"
+#include "JSCDATASection.h"
+#include "JSComment.h"
+#include "JSDocument.h"
+#include "JSDocumentFragment.h"
+#include "JSDocumentType.h"
+#include "JSEntity.h"
+#include "JSEntityReference.h"
+#include "JSHTMLElement.h"
+#include "JSHTMLElementWrapperFactory.h"
+#include "JSNotation.h"
+#include "JSProcessingInstruction.h"
+#include "JSText.h"
+#include "Node.h"
+#include "Notation.h"
+#include "ProcessingInstruction.h"
+#include "Text.h"
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefPtr.h>
+
+#if ENABLE(SVG)
+#include "JSSVGElementWrapperFactory.h"
+#include "SVGElement.h"
+#endif
+
+using namespace KJS;
+
+namespace WebCore {
+
+typedef int ExpectionCode;
+
+JSValue* JSNode::insertBefore(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ bool ok = impl()->insertBefore(toNode(args[0]), toNode(args[1]), ec);
+ setDOMException(exec, ec);
+ if (ok)
+ return args[0];
+ return jsNull();
+}
+
+JSValue* JSNode::replaceChild(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ bool ok = impl()->replaceChild(toNode(args[0]), toNode(args[1]), ec);
+ setDOMException(exec, ec);
+ if (ok)
+ return args[1];
+ return jsNull();
+}
+
+JSValue* JSNode::removeChild(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ bool ok = impl()->removeChild(toNode(args[0]), ec);
+ setDOMException(exec, ec);
+ if (ok)
+ return args[0];
+ return jsNull();
+}
+
+JSValue* JSNode::appendChild(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ bool ok = impl()->appendChild(toNode(args[0]), ec);
+ setDOMException(exec, ec);
+ if (ok)
+ return args[0];
+ return jsNull();
+}
+
+void JSNode::mark()
+{
+ ASSERT(!marked());
+
+ Node* node = m_impl.get();
+
+ // Nodes in the document are kept alive by ScriptInterpreter::mark,
+ // so we have no special responsibilities and can just call the base class here.
+ if (node->inDocument()) {
+ DOMObject::mark();
+ return;
+ }
+
+ // This is a node outside the document, so find the root of the tree it is in,
+ // and start marking from there.
+ Node* root = node;
+ for (Node* current = m_impl.get(); current; current = current->parentNode())
+ root = current;
+
+ // If we're already marking this tree, then we can simply mark this wrapper
+ // by calling the base class; our caller is iterating the tree.
+ if (root->m_inSubtreeMark) {
+ DOMObject::mark();
+ return;
+ }
+
+ // Mark the whole tree; use the global set of roots to avoid reentering.
+ root->m_inSubtreeMark = true;
+ for (Node* nodeToMark = root; nodeToMark; nodeToMark = nodeToMark->traverseNextNode()) {
+ JSNode* wrapper = ScriptInterpreter::getDOMNodeForDocument(m_impl->document(), nodeToMark);
+ if (wrapper) {
+ if (!wrapper->marked())
+ wrapper->mark();
+ } else if (nodeToMark == node) {
+ // This is the case where the map from the document to wrappers has
+ // been cleared out, but a wrapper is being marked. For now, we'll
+ // let the rest of the tree of wrappers get collected, because we have
+ // no good way of finding them. Later we should test behavior of other
+ // browsers and see if we need to preserve other wrappers in this case.
+ if (!marked())
+ mark();
+ }
+ }
+ root->m_inSubtreeMark = false;
+
+ // Double check that we actually ended up marked. This assert caught problems in the past.
+ ASSERT(marked());
+}
+
+JSValue* toJS(ExecState* exec, PassRefPtr<Node> n)
+{
+ Node* node = n.get();
+ if (!node)
+ return jsNull();
+
+ Document* doc = node->document();
+ JSNode* ret = ScriptInterpreter::getDOMNodeForDocument(doc, node);
+ if (ret)
+ return ret;
+
+ switch (node->nodeType()) {
+ case Node::ELEMENT_NODE:
+ if (node->isHTMLElement())
+ ret = createJSHTMLWrapper(exec, static_pointer_cast<HTMLElement>(n));
+#if ENABLE(SVG)
+ else if (node->isSVGElement())
+ ret = createJSSVGWrapper(exec, static_pointer_cast<SVGElement>(n));
+#endif
+ else
+ ret = new JSElement(JSElementPrototype::self(exec), static_cast<Element*>(node));
+ break;
+ case Node::ATTRIBUTE_NODE:
+ ret = new JSAttr(JSAttrPrototype::self(exec), static_cast<Attr*>(node));
+ break;
+ case Node::TEXT_NODE:
+ ret = new JSText(JSTextPrototype::self(exec), static_cast<Text*>(node));
+ break;
+ case Node::CDATA_SECTION_NODE:
+ ret = new JSCDATASection(JSCDATASectionPrototype::self(exec), static_cast<CDATASection*>(node));
+ break;
+ case Node::ENTITY_NODE:
+ ret = new JSEntity(JSEntityPrototype::self(exec), static_cast<Entity*>(node));
+ break;
+ case Node::PROCESSING_INSTRUCTION_NODE:
+ ret = new JSProcessingInstruction(JSProcessingInstructionPrototype::self(exec), static_cast<ProcessingInstruction*>(node));
+ break;
+ case Node::COMMENT_NODE:
+ ret = new JSComment(JSCommentPrototype::self(exec), static_cast<Comment*>(node));
+ break;
+ case Node::DOCUMENT_NODE:
+ // we don't want to cache the document itself in the per-document dictionary
+ return toJS(exec, static_cast<Document*>(node));
+ case Node::DOCUMENT_TYPE_NODE:
+ ret = new JSDocumentType(JSDocumentTypePrototype::self(exec), static_cast<DocumentType*>(node));
+ break;
+ case Node::NOTATION_NODE:
+ ret = new JSNotation(JSNotationPrototype::self(exec), static_cast<Notation*>(node));
+ break;
+ case Node::DOCUMENT_FRAGMENT_NODE:
+ ret = new JSDocumentFragment(JSDocumentFragmentPrototype::self(exec), static_cast<DocumentFragment*>(node));
+ break;
+ case Node::ENTITY_REFERENCE_NODE:
+ ret = new JSEntityReference(JSEntityReferencePrototype::self(exec), static_cast<EntityReference*>(node));
+ break;
+ default:
+ ret = new JSNode(JSNodePrototype::self(exec), node);
+ }
+
+ ScriptInterpreter::putDOMNodeForDocument(doc, node, ret);
+
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSNodeFilterCondition.cpp b/WebCore/bindings/js/JSNodeFilterCondition.cpp
new file mode 100644
index 0000000..17884f9
--- /dev/null
+++ b/WebCore/bindings/js/JSNodeFilterCondition.cpp
@@ -0,0 +1,84 @@
+/*
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "JSNodeFilterCondition.h"
+
+#include "Document.h"
+#include "Frame.h"
+#include "JSNode.h"
+#include "JSNodeFilter.h"
+#include "NodeFilter.h"
+#include "kjs_proxy.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+// FIXME: Add takeException as a member of ExecState?
+static JSValue* takeException(ExecState* exec)
+{
+ JSValue* exception = exec->exception();
+ exec->clearException();
+ return exception;
+}
+
+JSNodeFilterCondition::JSNodeFilterCondition(JSObject* filter)
+ : m_filter(filter)
+{
+}
+
+void JSNodeFilterCondition::mark()
+{
+ m_filter->mark();
+}
+
+short JSNodeFilterCondition::acceptNode(Node* filterNode, JSValue*& exception) const
+{
+ // FIXME: It makes no sense for this to depend on the document being in a frame!
+ Frame* frame = filterNode->document()->frame();
+ if (!frame)
+ return NodeFilter::FILTER_REJECT;
+
+ JSLock lock;
+
+ if (!m_filter->implementsCall())
+ return NodeFilter::FILTER_REJECT;
+
+ ExecState* exec = frame->scriptProxy()->globalObject()->globalExec();
+ List args;
+ args.append(toJS(exec, filterNode));
+ if (exec->hadException()) {
+ exception = takeException(exec);
+ return NodeFilter::FILTER_REJECT;
+ }
+ JSValue* result = m_filter->call(exec, m_filter, args);
+ if (exec->hadException()) {
+ exception = takeException(exec);
+ return NodeFilter::FILTER_REJECT;
+ }
+ int intResult = result->toInt32(exec);
+ if (exec->hadException()) {
+ exception = takeException(exec);
+ return NodeFilter::FILTER_REJECT;
+ }
+ return intResult;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSNodeFilterCondition.h b/WebCore/bindings/js/JSNodeFilterCondition.h
new file mode 100644
index 0000000..65519e9
--- /dev/null
+++ b/WebCore/bindings/js/JSNodeFilterCondition.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef JSNodeFilterCondition_h
+#define JSNodeFilterCondition_h
+
+#include "NodeFilterCondition.h"
+
+namespace KJS {
+ class JSObject;
+}
+
+namespace WebCore {
+
+ class Node;
+
+ class JSNodeFilterCondition : public NodeFilterCondition {
+ public:
+ JSNodeFilterCondition(KJS::JSObject* filter);
+ virtual short acceptNode(Node*, KJS::JSValue*& exception) const;
+ virtual void mark();
+
+ protected:
+ KJS::JSObject* m_filter;
+ };
+
+} // namespace WebCore
+
+#endif // JSNodeFilterCondition_h
diff --git a/WebCore/bindings/js/JSNodeFilterCustom.cpp b/WebCore/bindings/js/JSNodeFilterCustom.cpp
new file mode 100644
index 0000000..413abf9
--- /dev/null
+++ b/WebCore/bindings/js/JSNodeFilterCustom.cpp
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2007, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSNodeFilter.h"
+
+#include "JSNodeFilterCondition.h"
+#include "NodeFilter.h"
+#include "kjs_binding.h"
+#include "kjs_dom.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+void JSNodeFilter::mark()
+{
+ impl()->mark();
+ DOMObject::mark();
+}
+
+JSValue* JSNodeFilter::acceptNode(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ short result = impl()->acceptNode(toNode(args[0]), exception);
+ if (exception)
+ exec->setException(exception);
+ return jsNumber(result);
+}
+
+NodeFilter* toNodeFilter(KJS::JSValue* val)
+{
+ if (!val || !val->isObject())
+ return 0;
+
+ if (val->isObject(&JSNodeFilter::info))
+ return static_cast<JSNodeFilter*>(val)->impl();
+
+ KJS::JSObject* o = static_cast<KJS::JSObject*>(val);
+ if (o->implementsCall())
+ return new NodeFilter(new JSNodeFilterCondition(o));
+
+ return 0;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSNodeIteratorCustom.cpp b/WebCore/bindings/js/JSNodeIteratorCustom.cpp
new file mode 100644
index 0000000..937efa0
--- /dev/null
+++ b/WebCore/bindings/js/JSNodeIteratorCustom.cpp
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSNodeIterator.h"
+
+#include "JSNode.h"
+#include "Node.h"
+#include "NodeFilter.h"
+#include "NodeIterator.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+void JSNodeIterator::mark()
+{
+ if (NodeFilter* filter = m_impl->filter())
+ filter->mark();
+
+ DOMObject::mark();
+}
+
+JSValue* JSNodeIterator::nextNode(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ JSValue* exception = 0;
+ Node* node = impl()->nextNode(ec, exception);
+ if (ec) {
+ setDOMException(exec, ec);
+ return jsUndefined();
+ }
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+JSValue* JSNodeIterator::previousNode(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ JSValue* exception = 0;
+ Node* node = impl()->previousNode(ec, exception);
+ if (ec) {
+ setDOMException(exec, ec);
+ return jsUndefined();
+ }
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+}
diff --git a/WebCore/bindings/js/JSNodeListCustom.cpp b/WebCore/bindings/js/JSNodeListCustom.cpp
new file mode 100644
index 0000000..e484cb4
--- /dev/null
+++ b/WebCore/bindings/js/JSNodeListCustom.cpp
@@ -0,0 +1,65 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSNodeList.h"
+
+#include "AtomicString.h"
+#include "JSNode.h"
+#include "Node.h"
+#include "NodeList.h"
+
+namespace WebCore {
+
+// Need to support both get and call, so that list[0] and list(0) work.
+KJS::JSValue* JSNodeList::callAsFunction(KJS::ExecState* exec, KJS::JSObject* thisObj, const KJS::List& args)
+{
+ // Do not use thisObj here. See JSHTMLCollection.
+ KJS::UString s = args[0]->toString(exec);
+ bool ok;
+ unsigned u = s.toUInt32(&ok);
+ if (ok)
+ return toJS(exec, impl()->item(u));
+
+ return KJS::jsUndefined();
+}
+
+bool JSNodeList::implementsCall() const
+{
+ return true;
+}
+
+bool JSNodeList::canGetItemsForName(KJS::ExecState*, NodeList* impl, const KJS::Identifier& propertyName)
+{
+ return impl->itemWithName(propertyName);
+}
+
+KJS::JSValue* JSNodeList::nameGetter(KJS::ExecState* exec, KJS::JSObject* originalObject, const KJS::Identifier& propertyName, const KJS::PropertySlot& slot)
+{
+ JSNodeList* thisObj = static_cast<JSNodeList*>(slot.slotBase());
+ return toJS(exec, thisObj->impl()->itemWithName(propertyName));
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp b/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp
new file mode 100644
index 0000000..62dcd5d
--- /dev/null
+++ b/WebCore/bindings/js/JSSQLResultSetRowListCustom.cpp
@@ -0,0 +1,81 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSSQLResultSetRowList.h"
+
+#include "ExceptionCode.h"
+#include "SQLValue.h"
+#include "SQLResultSetRowList.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSSQLResultSetRowList::item(ExecState* exec, const List& args)
+{
+ bool indexOk;
+ int index = args[0]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+ if (index < 0 || (unsigned)index >= m_impl->length()) {
+ setDOMException(exec, INDEX_SIZE_ERR);
+ return jsUndefined();
+ }
+
+ JSObject* object = new JSObject(exec->lexicalGlobalObject()->objectPrototype());
+
+ unsigned numColumns = m_impl->columnNames().size();
+ unsigned valuesIndex = index * numColumns;
+ for (unsigned i = 0; i < numColumns; i++) {
+ const SQLValue& value = m_impl->values()[valuesIndex + i];
+ JSValue* jsValue = 0;
+
+ switch (value.type()) {
+ case SQLValue::StringValue:
+ jsValue = jsString(value.string());
+ break;
+ case SQLValue::NullValue:
+ jsValue = jsNull();
+ break;
+ case SQLValue::NumberValue:
+ jsValue = jsNumber(value.number());
+ break;
+ default:
+ ASSERT_NOT_REACHED();
+ }
+
+ object->putDirect(m_impl->columnNames()[i], jsValue, DontDelete | ReadOnly);
+ }
+
+ return object;
+}
+
+}
diff --git a/WebCore/bindings/js/JSSQLTransactionCustom.cpp b/WebCore/bindings/js/JSSQLTransactionCustom.cpp
new file mode 100644
index 0000000..1dca46d
--- /dev/null
+++ b/WebCore/bindings/js/JSSQLTransactionCustom.cpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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 "JSSQLTransaction.h"
+
+#include "DOMWindow.h"
+#include "ExceptionCode.h"
+#include "JSCustomSQLStatementCallback.h"
+#include "JSCustomSQLStatementErrorCallback.h"
+#include "SQLTransaction.h"
+#include "kjs_window.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSSQLTransaction::executeSql(ExecState* exec, const List& args)
+{
+ String sqlStatement = args[0]->toString(exec);
+ if (exec->hadException())
+ return jsUndefined();
+
+ // Now assemble the list of SQL arguments
+ Vector<SQLValue> sqlValues;
+ if (!args[1]->isUndefinedOrNull()) {
+ JSObject* object = args[1]->getObject();
+ if (!object) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ JSValue* lengthValue = object->get(exec, exec->propertyNames().length);
+ if (exec->hadException())
+ return jsUndefined();
+ unsigned length = lengthValue->toUInt32(exec);
+ if (exec->hadException())
+ return jsUndefined();
+
+ for (unsigned i = 0 ; i < length; ++i) {
+ JSValue* value = object->get(exec, i);
+ if (exec->hadException())
+ return jsUndefined();
+
+ if (value->isNull())
+ sqlValues.append(SQLValue());
+ else if (value->isNumber())
+ sqlValues.append(value->getNumber());
+ else {
+ // Convert the argument to a string and append it
+ sqlValues.append(value->toString(exec));
+ if (exec->hadException())
+ return jsUndefined();
+ }
+ }
+ }
+
+ RefPtr<SQLStatementCallback> callback;
+ if (!args[2]->isUndefinedOrNull()) {
+ JSObject* object = args[2]->getObject();
+ if (!object) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ if (Frame* frame = Window::retrieveActive(exec)->impl()->frame())
+ callback = new JSCustomSQLStatementCallback(object, frame);
+ }
+
+ RefPtr<SQLStatementErrorCallback> errorCallback;
+ if (!args[3]->isUndefinedOrNull()) {
+ JSObject* object = args[3]->getObject();
+ if (!object) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ if (Frame* frame = Window::retrieveActive(exec)->impl()->frame())
+ errorCallback = new JSCustomSQLStatementErrorCallback(object, frame);
+ }
+
+ ExceptionCode ec = 0;
+ m_impl->executeSQL(sqlStatement, sqlValues, callback.release(), errorCallback.release(), ec);
+ setDOMException(exec, ec);
+
+ return jsUndefined();
+}
+
+}
diff --git a/WebCore/bindings/js/JSSVGElementWrapperFactory.cpp b/WebCore/bindings/js/JSSVGElementWrapperFactory.cpp
new file mode 100644
index 0000000..29ead3d
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGElementWrapperFactory.cpp
@@ -0,0 +1,316 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+
+#include "JSSVGElementWrapperFactory.h"
+
+#include "JSSVGAElement.h"
+#include "JSSVGAnimateColorElement.h"
+#include "JSSVGAnimateElement.h"
+#include "JSSVGAnimateTransformElement.h"
+#include "JSSVGCircleElement.h"
+#include "JSSVGClipPathElement.h"
+#include "JSSVGCursorElement.h"
+#include "JSSVGDefsElement.h"
+#include "JSSVGDefinitionSrcElement.h"
+#include "JSSVGDescElement.h"
+#include "JSSVGEllipseElement.h"
+#include "JSSVGFEBlendElement.h"
+#include "JSSVGFEColorMatrixElement.h"
+#include "JSSVGFEComponentTransferElement.h"
+#include "JSSVGFECompositeElement.h"
+#include "JSSVGFEDiffuseLightingElement.h"
+#include "JSSVGFEDisplacementMapElement.h"
+#include "JSSVGFEDistantLightElement.h"
+#include "JSSVGFEFloodElement.h"
+#include "JSSVGFEFuncAElement.h"
+#include "JSSVGFEFuncBElement.h"
+#include "JSSVGFEFuncGElement.h"
+#include "JSSVGFEFuncRElement.h"
+#include "JSSVGFEGaussianBlurElement.h"
+#include "JSSVGFEImageElement.h"
+#include "JSSVGFEMergeElement.h"
+#include "JSSVGFEMergeNodeElement.h"
+#include "JSSVGFEOffsetElement.h"
+#include "JSSVGFEPointLightElement.h"
+#include "JSSVGFESpecularLightingElement.h"
+#include "JSSVGFESpotLightElement.h"
+#include "JSSVGFETileElement.h"
+#include "JSSVGFETurbulenceElement.h"
+#include "JSSVGFilterElement.h"
+#include "JSSVGForeignObjectElement.h"
+#include "JSSVGFontElement.h"
+#include "JSSVGFontFaceElement.h"
+#include "JSSVGFontFaceFormatElement.h"
+#include "JSSVGFontFaceNameElement.h"
+#include "JSSVGFontFaceSrcElement.h"
+#include "JSSVGFontFaceUriElement.h"
+#include "JSSVGGElement.h"
+#include "JSSVGGlyphElement.h"
+#include "JSSVGImageElement.h"
+#include "JSSVGLinearGradientElement.h"
+#include "JSSVGLineElement.h"
+#include "JSSVGMarkerElement.h"
+#include "JSSVGMaskElement.h"
+#include "JSSVGMetadataElement.h"
+#include "JSSVGMissingGlyphElement.h"
+#include "JSSVGPathElement.h"
+#include "JSSVGPatternElement.h"
+#include "JSSVGPolygonElement.h"
+#include "JSSVGPolylineElement.h"
+#include "JSSVGRadialGradientElement.h"
+#include "JSSVGRectElement.h"
+#include "JSSVGScriptElement.h"
+#include "JSSVGSetElement.h"
+#include "JSSVGStopElement.h"
+#include "JSSVGStyleElement.h"
+#include "JSSVGSVGElement.h"
+#include "JSSVGSwitchElement.h"
+#include "JSSVGSymbolElement.h"
+#include "JSSVGTextElement.h"
+#include "JSSVGTextPathElement.h"
+#include "JSSVGTitleElement.h"
+#include "JSSVGTRefElement.h"
+#include "JSSVGTSpanElement.h"
+#include "JSSVGUseElement.h"
+#include "JSSVGViewElement.h"
+
+#include "SVGNames.h"
+
+#include "SVGAElement.h"
+#include "SVGAnimateColorElement.h"
+#include "SVGAnimateElement.h"
+#include "SVGAnimateTransformElement.h"
+#include "SVGCircleElement.h"
+#include "SVGClipPathElement.h"
+#include "SVGCursorElement.h"
+#include "SVGDefsElement.h"
+#include "SVGDefinitionSrcElement.h"
+#include "SVGDescElement.h"
+#include "SVGEllipseElement.h"
+#include "SVGFEBlendElement.h"
+#include "SVGFEColorMatrixElement.h"
+#include "SVGFEComponentTransferElement.h"
+#include "SVGFECompositeElement.h"
+#include "SVGFEDiffuseLightingElement.h"
+#include "SVGFEDisplacementMapElement.h"
+#include "SVGFEDistantLightElement.h"
+#include "SVGFEFloodElement.h"
+#include "SVGFEFuncAElement.h"
+#include "SVGFEFuncBElement.h"
+#include "SVGFEFuncGElement.h"
+#include "SVGFEFuncRElement.h"
+#include "SVGFEGaussianBlurElement.h"
+#include "SVGFEImageElement.h"
+#include "SVGFEMergeElement.h"
+#include "SVGFEMergeNodeElement.h"
+#include "SVGFEOffsetElement.h"
+#include "SVGFEPointLightElement.h"
+#include "SVGFESpecularLightingElement.h"
+#include "SVGFESpotLightElement.h"
+#include "SVGFETileElement.h"
+#include "SVGFETurbulenceElement.h"
+#include "SVGFilterElement.h"
+#include "SVGForeignObjectElement.h"
+#include "SVGFontElement.h"
+#include "SVGFontFaceElement.h"
+#include "SVGFontFaceFormatElement.h"
+#include "SVGFontFaceNameElement.h"
+#include "SVGFontFaceSrcElement.h"
+#include "SVGFontFaceUriElement.h"
+#include "SVGGElement.h"
+#include "SVGGlyphElement.h"
+#include "SVGImageElement.h"
+#include "SVGLinearGradientElement.h"
+#include "SVGLineElement.h"
+#include "SVGMarkerElement.h"
+#include "SVGMaskElement.h"
+#include "SVGMetadataElement.h"
+#include "SVGMissingGlyphElement.h"
+#include "SVGPathElement.h"
+#include "SVGPatternElement.h"
+#include "SVGPolygonElement.h"
+#include "SVGPolylineElement.h"
+#include "SVGRadialGradientElement.h"
+#include "SVGRectElement.h"
+#include "SVGScriptElement.h"
+#include "SVGSetElement.h"
+#include "SVGStopElement.h"
+#include "SVGStyleElement.h"
+#include "SVGSVGElement.h"
+#include "SVGSwitchElement.h"
+#include "SVGSymbolElement.h"
+#include "SVGTextElement.h"
+#include "SVGTextPathElement.h"
+#include "SVGTitleElement.h"
+#include "SVGTRefElement.h"
+#include "SVGTSpanElement.h"
+#include "SVGUseElement.h"
+#include "SVGViewElement.h"
+
+using namespace KJS;
+
+// FIXME: Eventually this file should be autogenerated, just like SVGNames, SVGElementFactory, etc.
+
+namespace WebCore {
+
+using namespace SVGNames;
+
+typedef JSNode* (*CreateSVGElementWrapperFunction)(ExecState*, PassRefPtr<SVGElement>);
+
+#if ENABLE(SVG_ANIMATION)
+#define FOR_EACH_ANIMATION_TAG(macro) \
+ macro(animateColor, AnimateColor) \
+ macro(animate, Animate) \
+ macro(animateTransform, AnimateTransform) \
+ // end of macro
+
+#else
+#define FOR_EACH_ANIMATION_TAG(macro)
+#endif
+
+
+#if ENABLE(SVG_FONTS)
+#define FOR_EACH_FONT_TAG(macro) \
+ macro(definition_src, DefinitionSrc) \
+ macro(font, Font) \
+ macro(font_face, FontFace) \
+ macro(font_face_format, FontFaceFormat) \
+ macro(font_face_name, FontFaceName) \
+ macro(font_face_src, FontFaceSrc) \
+ macro(font_face_uri, FontFaceUri) \
+ macro(glyph, Glyph) \
+ macro(missing_glyph, MissingGlyph)
+ // end of macro
+
+#else
+#define FOR_EACH_FONT_TAG(macro)
+#endif
+
+#if ENABLE(SVG_FILTERS)
+#define FOR_EACH_FILTER_TAG(macro) \
+ macro(feBlend, FEBlend) \
+ macro(feColorMatrix, FEColorMatrix) \
+ macro(feComponentTransfer, FEComponentTransfer) \
+ macro(feComposite, FEComposite) \
+ macro(feDiffuseLighting, FEDiffuseLighting) \
+ macro(feDisplacementMap, FEDisplacementMap) \
+ macro(feDistantLight, FEDistantLight) \
+ macro(feFlood, FEFlood) \
+ macro(feFuncA, FEFuncA) \
+ macro(feFuncB, FEFuncB) \
+ macro(feFuncG, FEFuncG) \
+ macro(feFuncR, FEFuncR) \
+ macro(feGaussianBlur, FEGaussianBlur) \
+ macro(feImage, FEImage) \
+ macro(feMerge, FEMerge) \
+ macro(feMergeNode, FEMergeNode) \
+ macro(feOffset, FEOffset) \
+ macro(fePointLight, FEPointLight) \
+ macro(feSpecularLighting, FESpecularLighting) \
+ macro(feSpotLight, FESpotLight) \
+ macro(feTile, FETile) \
+ macro(feTurbulence, FETurbulence) \
+ macro(filter, Filter) \
+ // end of macro
+#else
+#define FOR_EACH_FILTER_TAG(macro)
+#endif
+
+#if ENABLE(SVG_FOREIGN_OBJECT)
+#define FOR_EACH_FOREIGN_OBJECT_TAG(macro) \
+ macro(foreignObject, ForeignObject) \
+ // end of macro
+#else
+#define FOR_EACH_FOREIGN_OBJECT_TAG(macro)
+#endif
+
+#define FOR_EACH_TAG(macro) \
+ macro(a, A) \
+ macro(circle, Circle) \
+ macro(clipPath, ClipPath) \
+ macro(cursor, Cursor) \
+ macro(defs, Defs) \
+ macro(desc, Desc) \
+ macro(ellipse, Ellipse) \
+ macro(g, G) \
+ macro(image, Image) \
+ macro(linearGradient, LinearGradient) \
+ macro(line, Line) \
+ macro(marker, Marker) \
+ macro(mask, Mask) \
+ macro(metadata, Metadata) \
+ macro(path, Path) \
+ macro(pattern, Pattern) \
+ macro(polyline, Polyline) \
+ macro(polygon, Polygon) \
+ macro(radialGradient, RadialGradient) \
+ macro(rect, Rect) \
+ macro(script, Script) \
+ macro(set, Set) \
+ macro(stop, Stop) \
+ macro(style, Style) \
+ macro(svg, SVG) \
+ macro(switch, Switch) \
+ macro(symbol, Symbol) \
+ macro(text, Text) \
+ macro(textPath, TextPath) \
+ macro(title, Title) \
+ macro(tref, TRef) \
+ macro(tspan, TSpan) \
+ macro(use, Use) \
+ macro(view, View) \
+ // end of macro
+
+#define CREATE_WRAPPER_FUNCTION(tag, name) \
+static JSNode* create##name##Wrapper(ExecState* exec, PassRefPtr<SVGElement> element) \
+{ \
+ return new JSSVG##name##Element(JSSVG##name##ElementPrototype::self(exec), static_cast<SVG##name##Element*>(element.get())); \
+}
+FOR_EACH_TAG(CREATE_WRAPPER_FUNCTION)
+FOR_EACH_ANIMATION_TAG(CREATE_WRAPPER_FUNCTION)
+FOR_EACH_FONT_TAG(CREATE_WRAPPER_FUNCTION)
+FOR_EACH_FILTER_TAG(CREATE_WRAPPER_FUNCTION)
+FOR_EACH_FOREIGN_OBJECT_TAG(CREATE_WRAPPER_FUNCTION)
+
+#undef CREATE_WRAPPER_FUNCTION
+
+JSNode* createJSSVGWrapper(ExecState* exec, PassRefPtr<SVGElement> element)
+{
+ static HashMap<WebCore::AtomicStringImpl*, CreateSVGElementWrapperFunction> map;
+ if (map.isEmpty()) {
+#define ADD_TO_HASH_MAP(tag, name) map.set(tag##Tag.localName().impl(), create##name##Wrapper);
+FOR_EACH_TAG(ADD_TO_HASH_MAP)
+FOR_EACH_ANIMATION_TAG(ADD_TO_HASH_MAP)
+FOR_EACH_FONT_TAG(ADD_TO_HASH_MAP)
+FOR_EACH_FILTER_TAG(ADD_TO_HASH_MAP)
+FOR_EACH_FOREIGN_OBJECT_TAG(ADD_TO_HASH_MAP)
+#undef ADD_TO_HASH_MAP
+ }
+ CreateSVGElementWrapperFunction createWrapperFunction = map.get(element->localName().impl());
+ if (createWrapperFunction)
+ return createWrapperFunction(exec, element);
+ return new JSSVGElement(JSSVGElementPrototype::self(exec), element.get());
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/bindings/js/JSSVGElementWrapperFactory.h b/WebCore/bindings/js/JSSVGElementWrapperFactory.h
new file mode 100644
index 0000000..3083fec
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGElementWrapperFactory.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef JSSVGElementWrapperFactory_h
+#define JSSVGElementWrapperFactory_h
+
+#if ENABLE(SVG)
+
+#include <wtf/Forward.h>
+
+namespace KJS {
+ class ExecState;
+}
+
+namespace WebCore {
+
+ class JSNode;
+ class SVGElement;
+
+ JSNode* createJSSVGWrapper(KJS::ExecState*, PassRefPtr<SVGElement>);
+
+}
+
+#endif // ENABLE(SVG)
+
+#endif // JSSVGElementWrapperFactory_h
diff --git a/WebCore/bindings/js/JSSVGLazyEventListener.cpp b/WebCore/bindings/js/JSSVGLazyEventListener.cpp
new file mode 100644
index 0000000..87d0cc6
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGLazyEventListener.cpp
@@ -0,0 +1,46 @@
+/*
+ Copyright (C) 2006 Apple Computer, Inc.
+
+ This file is part of the WebKit project
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#include "config.h"
+#if ENABLE(SVG)
+
+#include "JSSVGLazyEventListener.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSSVGLazyEventListener::JSSVGLazyEventListener(const String& functionName, const String& code, KJS::Window* win, Node* node, int lineno)
+ : JSLazyEventListener(functionName, code, win, node, lineno)
+{
+}
+
+JSValue *JSSVGLazyEventListener::eventParameterName() const
+{
+ static ProtectedPtr<JSValue> eventString = jsString("evt");
+ return eventString.get();
+}
+
+}
+
+#endif // ENABLE(SVG)
+
+// vim:ts=4:noet
diff --git a/WebCore/bindings/js/JSSVGLazyEventListener.h b/WebCore/bindings/js/JSSVGLazyEventListener.h
new file mode 100644
index 0000000..8247bdb
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGLazyEventListener.h
@@ -0,0 +1,42 @@
+/*
+ Copyright (C) 2006 Apple Computer, Inc.
+
+ This file is part of the WebKit project
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+
+#ifndef JSSVGLazyEventListener_h
+#define JSSVGLazyEventListener_h
+#if ENABLE(SVG)
+
+#include "kjs_events.h"
+
+namespace WebCore {
+
+ class JSSVGLazyEventListener : public JSLazyEventListener {
+ public:
+ JSSVGLazyEventListener(const String& functionName, const String& code, KJS::Window*, Node*, int lineno = 0);
+ private:
+ virtual KJS::JSValue* eventParameterName() const;
+ };
+
+}
+
+#endif // ENABLE(SVG)
+#endif
+
+// vim:ts=4:noet
diff --git a/WebCore/bindings/js/JSSVGMatrixCustom.cpp b/WebCore/bindings/js/JSSVGMatrixCustom.cpp
new file mode 100644
index 0000000..99da930
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGMatrixCustom.cpp
@@ -0,0 +1,135 @@
+/*
+ * Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+
+#include "JSSVGMatrix.h"
+
+#include "AffineTransform.h"
+#include "SVGException.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSSVGMatrix::multiply(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ AffineTransform secondMatrix = toSVGMatrix(args[0]);
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.multiply(secondMatrix)), m_context.get());
+}
+
+JSValue* JSSVGMatrix::inverse(ExecState* exec, const List&)
+{
+ AffineTransform imp(*impl());
+ KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.inverse()), m_context.get());
+
+ if (!imp.isInvertible())
+ setDOMException(exec, SVGException::SVG_MATRIX_NOT_INVERTABLE);
+
+ return result;
+}
+
+JSValue* JSSVGMatrix::translate(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ float x = args[0]->toFloat(exec);
+ float y = args[1]->toFloat(exec);
+
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.translate(x, y)), m_context.get());
+}
+
+JSValue* JSSVGMatrix::scale(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ float scaleFactor = args[0]->toFloat(exec);
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scale(scaleFactor)), m_context.get());
+}
+
+JSValue* JSSVGMatrix::scaleNonUniform(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ float scaleFactorX = args[0]->toFloat(exec);
+ float scaleFactorY = args[1]->toFloat(exec);
+
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.scaleNonUniform(scaleFactorX, scaleFactorY)), m_context.get());
+}
+
+JSValue* JSSVGMatrix::rotate(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ float angle = args[0]->toFloat(exec);
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotate(angle)), m_context.get());
+}
+
+JSValue* JSSVGMatrix::rotateFromVector(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ float x = args[0]->toFloat(exec);
+ float y = args[1]->toFloat(exec);
+
+ KJS::JSValue* result = toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.rotateFromVector(x, y)), m_context.get());
+
+ if (x == 0.0 || y == 0.0)
+ setDOMException(exec, SVGException::SVG_INVALID_VALUE_ERR);
+
+ return result;
+}
+
+JSValue* JSSVGMatrix::flipX(ExecState* exec, const List&)
+{
+ AffineTransform imp(*impl());
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipX()), m_context.get());
+}
+
+JSValue* JSSVGMatrix::flipY(ExecState* exec, const List&)
+{
+ AffineTransform imp(*impl());
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.flipY()), m_context.get());
+}
+
+JSValue* JSSVGMatrix::skewX(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ float angle = args[0]->toFloat(exec);
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewX(angle)), m_context.get());
+}
+
+JSValue* JSSVGMatrix::skewY(ExecState* exec, const List& args)
+{
+ AffineTransform imp(*impl());
+
+ float angle = args[0]->toFloat(exec);
+ return toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<AffineTransform>(imp.skewY(angle)), m_context.get());
+}
+
+}
+
+#endif // ENABLE(SVG)
+
+// vim:ts=4:noet
diff --git a/WebCore/bindings/js/JSSVGPODTypeWrapper.h b/WebCore/bindings/js/JSSVGPODTypeWrapper.h
new file mode 100644
index 0000000..1275950
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGPODTypeWrapper.h
@@ -0,0 +1,286 @@
+/*
+ * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSSVGPODTypeWrapper_h
+#define JSSVGPODTypeWrapper_h
+
+#if ENABLE(SVG)
+
+#include "Frame.h"
+#include <wtf/RefCounted.h>
+#include "SVGElement.h"
+
+#include <wtf/Assertions.h>
+#include <wtf/HashMap.h>
+
+namespace WebCore {
+
+template<typename PODType>
+class JSSVGPODTypeWrapper : public RefCounted<JSSVGPODTypeWrapper<PODType> > {
+public:
+ JSSVGPODTypeWrapper() : RefCounted<JSSVGPODTypeWrapper<PODType> >(0) { }
+ virtual ~JSSVGPODTypeWrapper() { }
+
+ // Getter wrapper
+ virtual operator PODType() = 0;
+
+ // Setter wrapper
+ virtual void commitChange(PODType, SVGElement*) = 0;
+};
+
+template<typename PODType, typename PODTypeCreator>
+class JSSVGPODTypeWrapperCreatorReadWrite : public JSSVGPODTypeWrapper<PODType>
+{
+public:
+ typedef PODType (PODTypeCreator::*GetterMethod)() const;
+ typedef void (PODTypeCreator::*SetterMethod)(PODType);
+
+ JSSVGPODTypeWrapperCreatorReadWrite(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter)
+ : m_creator(creator)
+ , m_getter(getter)
+ , m_setter(setter)
+ {
+ ASSERT(creator);
+ ASSERT(getter);
+ ASSERT(setter);
+ }
+
+ virtual ~JSSVGPODTypeWrapperCreatorReadWrite() { }
+
+ // Getter wrapper
+ virtual operator PODType() { return (m_creator.get()->*m_getter)(); }
+
+ // Setter wrapper
+ virtual void commitChange(PODType type, SVGElement* context)
+ {
+ if (!m_setter)
+ return;
+
+ (m_creator.get()->*m_setter)(type);
+
+ if (context)
+ context->svgAttributeChanged(m_creator->associatedAttributeName());
+ }
+
+private:
+ // Update callbacks
+ RefPtr<PODTypeCreator> m_creator;
+ GetterMethod m_getter;
+ SetterMethod m_setter;
+};
+
+template<typename PODType>
+class JSSVGPODTypeWrapperCreatorReadOnly : public JSSVGPODTypeWrapper<PODType>
+{
+public:
+ JSSVGPODTypeWrapperCreatorReadOnly(PODType type)
+ : m_podType(type)
+ { }
+
+ virtual ~JSSVGPODTypeWrapperCreatorReadOnly() { }
+
+ // Getter wrapper
+ virtual operator PODType() { return m_podType; }
+
+ // Setter wrapper
+ virtual void commitChange(PODType type, SVGElement*)
+ {
+ m_podType = type;
+ }
+
+private:
+ PODType m_podType;
+};
+
+template<typename PODType>
+class SVGPODListItem;
+
+template<typename PODType>
+class JSSVGPODTypeWrapperCreatorForList : public JSSVGPODTypeWrapper<PODType>
+{
+public:
+ typedef PODType (SVGPODListItem<PODType>::*GetterMethod)() const;
+ typedef void (SVGPODListItem<PODType>::*SetterMethod)(PODType);
+
+ JSSVGPODTypeWrapperCreatorForList(SVGPODListItem<PODType>* creator, const QualifiedName& attributeName)
+ : m_creator(creator)
+ , m_getter(&SVGPODListItem<PODType>::value)
+ , m_setter(&SVGPODListItem<PODType>::setValue)
+ , m_associatedAttributeName(attributeName)
+ {
+ ASSERT(m_creator);
+ ASSERT(m_getter);
+ ASSERT(m_setter);
+ }
+
+ virtual ~JSSVGPODTypeWrapperCreatorForList() { }
+
+ // Getter wrapper
+ virtual operator PODType() { return (m_creator.get()->*m_getter)(); }
+
+ // Setter wrapper
+ virtual void commitChange(PODType type, SVGElement* context)
+ {
+ if (!m_setter)
+ return;
+
+ (m_creator.get()->*m_setter)(type);
+
+ if (context)
+ context->svgAttributeChanged(m_associatedAttributeName);
+ }
+
+private:
+ // Update callbacks
+ RefPtr<SVGPODListItem<PODType> > m_creator;
+ GetterMethod m_getter;
+ SetterMethod m_setter;
+ const QualifiedName& m_associatedAttributeName;
+};
+
+// Caching facilities
+template<typename PODType, typename PODTypeCreator>
+struct PODTypeReadWriteHashInfo {
+ typedef PODType (PODTypeCreator::*GetterMethod)() const;
+ typedef void (PODTypeCreator::*SetterMethod)(PODType);
+
+ // Empty value
+ PODTypeReadWriteHashInfo()
+ : creator(0)
+ , getter(0)
+ , setter(0)
+ { }
+
+ // Deleted value
+ explicit PODTypeReadWriteHashInfo(bool)
+ : creator(reinterpret_cast<PODTypeCreator*>(-1))
+ , getter(0)
+ , setter(0)
+ { }
+
+ PODTypeReadWriteHashInfo(PODTypeCreator* _creator, GetterMethod _getter, SetterMethod _setter)
+ : creator(_creator)
+ , getter(_getter)
+ , setter(_setter)
+ {
+ ASSERT(creator);
+ ASSERT(getter);
+ }
+
+ bool operator==(const PODTypeReadWriteHashInfo& other) const
+ {
+ return creator == other.creator && getter == other.getter && setter == other.setter;
+ }
+
+ PODTypeCreator* creator;
+ GetterMethod getter;
+ SetterMethod setter;
+};
+
+template<typename PODType, typename PODTypeCreator>
+struct PODTypeReadWriteHashInfoHash {
+ static unsigned hash(const PODTypeReadWriteHashInfo<PODType, PODTypeCreator>& info)
+ {
+ return StringImpl::computeHash((::UChar*) &info, sizeof(PODTypeReadWriteHashInfo<PODType, PODTypeCreator>) / sizeof(::UChar));
+ }
+
+ static bool equal(const PODTypeReadWriteHashInfo<PODType, PODTypeCreator>& a, const PODTypeReadWriteHashInfo<PODType, PODTypeCreator>& b)
+ {
+ return a == b;
+ }
+
+ static const bool safeToCompareToEmptyOrDeleted = true;
+};
+
+template<typename PODType, typename PODTypeCreator>
+struct PODTypeReadWriteHashInfoTraits : WTF::GenericHashTraits<PODTypeReadWriteHashInfo<PODType, PODTypeCreator> > {
+ static const bool emptyValueIsZero = true;
+ static const bool needsDestruction = false;
+
+ static const PODTypeReadWriteHashInfo<PODType, PODTypeCreator>& deletedValue()
+ {
+ static PODTypeReadWriteHashInfo<PODType, PODTypeCreator> key(true);
+ return key;
+ }
+
+ static const PODTypeReadWriteHashInfo<PODType, PODTypeCreator>& emptyValue()
+ {
+ static PODTypeReadWriteHashInfo<PODType, PODTypeCreator> key;
+ return key;
+ }
+};
+
+template<typename PODType, typename PODTypeCreator>
+class JSSVGPODTypeWrapperCache
+{
+public:
+ typedef PODType (PODTypeCreator::*GetterMethod)() const;
+ typedef void (PODTypeCreator::*SetterMethod)(PODType);
+
+ typedef HashMap<PODTypeReadWriteHashInfo<PODType, PODTypeCreator>, JSSVGPODTypeWrapperCreatorReadWrite<PODType, PODTypeCreator>*, PODTypeReadWriteHashInfoHash<PODType, PODTypeCreator>, PODTypeReadWriteHashInfoTraits<PODType, PODTypeCreator> > ReadWriteHashMap;
+ typedef typename ReadWriteHashMap::const_iterator ReadWriteHashMapIterator;
+
+ static ReadWriteHashMap& readWriteHashMap()
+ {
+ static ReadWriteHashMap _readWriteHashMap;
+ return _readWriteHashMap;
+ }
+
+ // Used for readwrite attributes only
+ static JSSVGPODTypeWrapper<PODType>* lookupOrCreateWrapper(PODTypeCreator* creator, GetterMethod getter, SetterMethod setter)
+ {
+ ReadWriteHashMap& map(readWriteHashMap());
+ PODTypeReadWriteHashInfo<PODType, PODTypeCreator> info(creator, getter, setter);
+
+ if (map.contains(info))
+ return map.get(info);
+
+ JSSVGPODTypeWrapperCreatorReadWrite<PODType, PODTypeCreator>* wrapper = new JSSVGPODTypeWrapperCreatorReadWrite<PODType, PODTypeCreator>(creator, getter, setter);
+ map.set(info, wrapper);
+ return wrapper;
+ }
+
+ static void forgetWrapper(JSSVGPODTypeWrapper<PODType>* wrapper)
+ {
+ ReadWriteHashMap& map(readWriteHashMap());
+
+ ReadWriteHashMapIterator it = map.begin();
+ ReadWriteHashMapIterator end = map.end();
+
+ for (; it != end; ++it) {
+ if (it->second != wrapper)
+ continue;
+
+ // It's guaruanteed that there's just one object we need to take care of.
+ map.remove(it->first);
+ break;
+ }
+ }
+};
+
+};
+
+#endif // ENABLE(SVG)
+#endif // JSSVGPODTypeWrapper_h
diff --git a/WebCore/bindings/js/JSSVGPathSegCustom.cpp b/WebCore/bindings/js/JSSVGPathSegCustom.cpp
new file mode 100644
index 0000000..55db3a1
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGPathSegCustom.cpp
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "JSSVGPathSeg.h"
+#include "JSSVGPathSegArcAbs.h"
+#include "JSSVGPathSegArcRel.h"
+#include "JSSVGPathSegClosePath.h"
+#include "JSSVGPathSegCurvetoCubicAbs.h"
+#include "JSSVGPathSegCurvetoCubicRel.h"
+#include "JSSVGPathSegCurvetoCubicSmoothAbs.h"
+#include "JSSVGPathSegCurvetoCubicSmoothRel.h"
+#include "JSSVGPathSegCurvetoQuadraticAbs.h"
+#include "JSSVGPathSegCurvetoQuadraticRel.h"
+#include "JSSVGPathSegCurvetoQuadraticSmoothAbs.h"
+#include "JSSVGPathSegCurvetoQuadraticSmoothRel.h"
+#include "JSSVGPathSegLinetoAbs.h"
+#include "JSSVGPathSegLinetoRel.h"
+#include "JSSVGPathSegLinetoHorizontalAbs.h"
+#include "JSSVGPathSegLinetoHorizontalRel.h"
+#include "JSSVGPathSegLinetoVerticalAbs.h"
+#include "JSSVGPathSegLinetoVerticalRel.h"
+#include "JSSVGPathSegMovetoAbs.h"
+#include "JSSVGPathSegMovetoRel.h"
+
+#include "kjs_binding.h"
+
+#include "SVGPathSeg.h"
+#include "SVGPathSegArc.h"
+#include "SVGPathSegClosePath.h"
+#include "SVGPathSegCurvetoCubic.h"
+#include "SVGPathSegCurvetoCubicSmooth.h"
+#include "SVGPathSegCurvetoQuadratic.h"
+#include "SVGPathSegCurvetoQuadraticSmooth.h"
+#include "SVGPathSegLineto.h"
+#include "SVGPathSegLinetoHorizontal.h"
+#include "SVGPathSegLinetoVertical.h"
+#include "SVGPathSegMoveto.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* toJS(ExecState* exec, SVGPathSeg* obj, SVGElement* context)
+{
+ if (!obj)
+ return jsNull();
+
+ switch (obj->pathSegType()) {
+ case SVGPathSeg::PATHSEG_CLOSEPATH:
+ return cacheSVGDOMObject<SVGPathSegClosePath, JSSVGPathSegClosePath, JSSVGPathSegClosePathPrototype>(exec, static_cast<SVGPathSegClosePath*>(obj), context);
+ case SVGPathSeg::PATHSEG_MOVETO_ABS:
+ return cacheSVGDOMObject<SVGPathSegMovetoAbs, JSSVGPathSegMovetoAbs, JSSVGPathSegMovetoAbsPrototype>(exec, static_cast<SVGPathSegMovetoAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_MOVETO_REL:
+ return cacheSVGDOMObject<SVGPathSegMovetoRel, JSSVGPathSegMovetoRel, JSSVGPathSegMovetoRelPrototype>(exec, static_cast<SVGPathSegMovetoRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_LINETO_ABS:
+ return cacheSVGDOMObject<SVGPathSegLinetoAbs, JSSVGPathSegLinetoAbs, JSSVGPathSegLinetoAbsPrototype>(exec, static_cast<SVGPathSegLinetoAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_LINETO_REL:
+ return cacheSVGDOMObject<SVGPathSegLinetoRel, JSSVGPathSegLinetoRel, JSSVGPathSegLinetoRelPrototype>(exec, static_cast<SVGPathSegLinetoRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
+ return cacheSVGDOMObject<SVGPathSegCurvetoCubicAbs, JSSVGPathSegCurvetoCubicAbs, JSSVGPathSegCurvetoCubicAbsPrototype>(exec, static_cast<SVGPathSegCurvetoCubicAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_CUBIC_REL:
+ return cacheSVGDOMObject<SVGPathSegCurvetoCubicRel, JSSVGPathSegCurvetoCubicRel, JSSVGPathSegCurvetoCubicRelPrototype>(exec, static_cast<SVGPathSegCurvetoCubicRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS:
+ return cacheSVGDOMObject<SVGPathSegCurvetoQuadraticAbs, JSSVGPathSegCurvetoQuadraticAbs, JSSVGPathSegCurvetoQuadraticAbsPrototype>(exec, static_cast<SVGPathSegCurvetoQuadraticAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL:
+ return cacheSVGDOMObject<SVGPathSegCurvetoQuadraticRel, JSSVGPathSegCurvetoQuadraticRel, JSSVGPathSegCurvetoQuadraticRelPrototype>(exec, static_cast<SVGPathSegCurvetoQuadraticRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_ARC_ABS:
+ return cacheSVGDOMObject<SVGPathSegArcAbs, JSSVGPathSegArcAbs, JSSVGPathSegArcAbsPrototype>(exec, static_cast<SVGPathSegArcAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_ARC_REL:
+ return cacheSVGDOMObject<SVGPathSegArcRel, JSSVGPathSegArcRel, JSSVGPathSegArcRelPrototype>(exec, static_cast<SVGPathSegArcRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS:
+ return cacheSVGDOMObject<SVGPathSegLinetoHorizontalAbs, JSSVGPathSegLinetoHorizontalAbs, JSSVGPathSegLinetoHorizontalAbsPrototype>(exec, static_cast<SVGPathSegLinetoHorizontalAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL:
+ return cacheSVGDOMObject<SVGPathSegLinetoHorizontalRel, JSSVGPathSegLinetoHorizontalRel, JSSVGPathSegLinetoHorizontalRelPrototype>(exec, static_cast<SVGPathSegLinetoHorizontalRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS:
+ return cacheSVGDOMObject<SVGPathSegLinetoVerticalAbs, JSSVGPathSegLinetoVerticalAbs, JSSVGPathSegLinetoVerticalAbsPrototype>(exec, static_cast<SVGPathSegLinetoVerticalAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_LINETO_VERTICAL_REL:
+ return cacheSVGDOMObject<SVGPathSegLinetoVerticalRel, JSSVGPathSegLinetoVerticalRel, JSSVGPathSegLinetoVerticalRelPrototype>(exec, static_cast<SVGPathSegLinetoVerticalRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
+ return cacheSVGDOMObject<SVGPathSegCurvetoCubicSmoothAbs, JSSVGPathSegCurvetoCubicSmoothAbs, JSSVGPathSegCurvetoCubicSmoothAbsPrototype>(exec, static_cast<SVGPathSegCurvetoCubicSmoothAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
+ return cacheSVGDOMObject<SVGPathSegCurvetoCubicSmoothRel, JSSVGPathSegCurvetoCubicSmoothRel, JSSVGPathSegCurvetoCubicSmoothRelPrototype>(exec, static_cast<SVGPathSegCurvetoCubicSmoothRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
+ return cacheSVGDOMObject<SVGPathSegCurvetoQuadraticSmoothAbs, JSSVGPathSegCurvetoQuadraticSmoothAbs, JSSVGPathSegCurvetoQuadraticSmoothAbsPrototype>(exec, static_cast<SVGPathSegCurvetoQuadraticSmoothAbs*>(obj), context);
+ case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
+ return cacheSVGDOMObject<SVGPathSegCurvetoQuadraticSmoothRel, JSSVGPathSegCurvetoQuadraticSmoothRel, JSSVGPathSegCurvetoQuadraticSmoothRelPrototype>(exec, static_cast<SVGPathSegCurvetoQuadraticSmoothRel*>(obj), context);
+ case SVGPathSeg::PATHSEG_UNKNOWN:
+ default:
+ return cacheSVGDOMObject<SVGPathSeg, JSSVGPathSeg, JSSVGPathSegPrototype>(exec, obj, context);
+ }
+}
+
+}
+
+#endif // ENABLE(SVG)
+
+// vim:ts=4:noet
diff --git a/WebCore/bindings/js/JSSVGPathSegListCustom.cpp b/WebCore/bindings/js/JSSVGPathSegListCustom.cpp
new file mode 100644
index 0000000..19972a2
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGPathSegListCustom.cpp
@@ -0,0 +1,166 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "JSSVGPathSegList.h"
+
+#include "Document.h"
+#include "Frame.h"
+#include "JSSVGPathSeg.h"
+#include "SVGDocumentExtensions.h"
+#include "SVGElement.h"
+#include "SVGPathSegList.h"
+
+#include <wtf/Assertions.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSSVGPathSegList::clear(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
+ imp->clear(ec);
+
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+ return jsUndefined();
+}
+
+JSValue* JSSVGPathSegList::initialize(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGPathSeg* newItem = toSVGPathSeg(args[0]);
+
+ SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
+
+ SVGPathSeg* obj = WTF::getPtr(imp->initialize(newItem, ec));
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+ return result;
+}
+
+JSValue* JSSVGPathSegList::getItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ bool indexOk;
+ unsigned index = args[0]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
+ SVGPathSeg* obj = WTF::getPtr(imp->getItem(index, ec));
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+ return result;
+}
+
+JSValue* JSSVGPathSegList::insertItemBefore(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGPathSeg* newItem = toSVGPathSeg(args[0]);
+
+ bool indexOk;
+ unsigned index = args[1]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
+
+ KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->insertItemBefore(newItem, index, ec)), m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+ return result;
+}
+
+JSValue* JSSVGPathSegList::replaceItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGPathSeg* newItem = toSVGPathSeg(args[0]);
+
+ bool indexOk;
+ unsigned index = args[1]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
+
+ KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->replaceItem(newItem, index, ec)), m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+ return result;
+}
+
+JSValue* JSSVGPathSegList::removeItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ bool indexOk;
+ unsigned index = args[0]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
+
+ RefPtr<SVGPathSeg> obj(imp->removeItem(index, ec));
+
+ KJS::JSValue* result = toJS(exec, obj.get(), m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+ return result;
+}
+
+JSValue* JSSVGPathSegList::appendItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGPathSeg* newItem = toSVGPathSeg(args[0]);
+
+ SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
+
+ KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->appendItem(newItem, ec)), m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+ return result;
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/bindings/js/JSSVGPointListCustom.cpp b/WebCore/bindings/js/JSSVGPointListCustom.cpp
new file mode 100644
index 0000000..af4fc91
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGPointListCustom.cpp
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "JSSVGPointList.h"
+
+#include "Document.h"
+#include "Frame.h"
+#include "JSSVGPoint.h"
+#include "SVGDocumentExtensions.h"
+#include "SVGPointList.h"
+#include "SVGStyledElement.h"
+
+#include <wtf/Assertions.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSSVGPointList::clear(ExecState* exec, const List&)
+{
+ ExceptionCode ec = 0;
+
+ SVGPointList* imp = static_cast<SVGPointList*>(impl());
+ imp->clear(ec);
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return jsUndefined();
+}
+
+JSValue* JSSVGPointList::initialize(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ FloatPoint newItem = toSVGPoint(args[0]);
+
+ SVGPointList* imp = static_cast<SVGPointList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<FloatPoint> > >* listImp = imp;
+
+ SVGPODListItem<FloatPoint>* listItem = listImp->initialize(SVGPODListItem<FloatPoint>::copy(newItem), ec).get();
+ JSSVGPODTypeWrapperCreatorForList<FloatPoint>* obj = new JSSVGPODTypeWrapperCreatorForList<FloatPoint>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGPointList::getItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ bool indexOk;
+ unsigned index = args[0]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPointList* imp = static_cast<SVGPointList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<FloatPoint> > >* listImp = imp;
+
+ SVGPODListItem<FloatPoint>* listItem = listImp->getItem(index, ec).get();
+ JSSVGPODTypeWrapperCreatorForList<FloatPoint>* obj = new JSSVGPODTypeWrapperCreatorForList<FloatPoint>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+ return result;
+}
+
+JSValue* JSSVGPointList::insertItemBefore(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ FloatPoint newItem = toSVGPoint(args[0]);
+
+ bool indexOk;
+ unsigned index = args[1]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPointList* imp = static_cast<SVGPointList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<FloatPoint> > >* listImp = imp;
+
+ SVGPODListItem<FloatPoint>* listItem = listImp->insertItemBefore(SVGPODListItem<FloatPoint>::copy(newItem), index, ec).get();
+ JSSVGPODTypeWrapperCreatorForList<FloatPoint>* obj = new JSSVGPODTypeWrapperCreatorForList<FloatPoint>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGPointList::replaceItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ FloatPoint newItem = toSVGPoint(args[0]);
+
+ bool indexOk;
+ unsigned index = args[1]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPointList* imp = static_cast<SVGPointList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<FloatPoint> > >* listImp = imp;
+
+ SVGPODListItem<FloatPoint>* listItem = listImp->replaceItem(SVGPODListItem<FloatPoint>::copy(newItem), index, ec).get();
+ JSSVGPODTypeWrapperCreatorForList<FloatPoint>* obj = new JSSVGPODTypeWrapperCreatorForList<FloatPoint>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGPointList::removeItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ bool indexOk;
+ unsigned index = args[0]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGPointList* imp = static_cast<SVGPointList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<FloatPoint> > >* listImp = imp;
+
+ RefPtr<SVGPODListItem<FloatPoint> > listItem(listImp->removeItem(index, ec));
+ JSSVGPODTypeWrapper<FloatPoint>* obj = new JSSVGPODTypeWrapperCreatorReadOnly<FloatPoint>(*listItem.get());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGPointList::appendItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ FloatPoint newItem = toSVGPoint(args[0]);
+
+ SVGPointList* imp = static_cast<SVGPointList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<FloatPoint> > >* listImp = imp;
+
+ SVGPODListItem<FloatPoint>* listItem = listImp->appendItem(SVGPODListItem<FloatPoint>::copy(newItem), ec).get();
+ JSSVGPODTypeWrapperCreatorForList<FloatPoint>* obj = new JSSVGPODTypeWrapperCreatorForList<FloatPoint>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/bindings/js/JSSVGTransformListCustom.cpp b/WebCore/bindings/js/JSSVGTransformListCustom.cpp
new file mode 100644
index 0000000..d3d8d25
--- /dev/null
+++ b/WebCore/bindings/js/JSSVGTransformListCustom.cpp
@@ -0,0 +1,190 @@
+/*
+ * Copyright (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+
+#if ENABLE(SVG)
+#include "JSSVGTransformList.h"
+
+#include "Document.h"
+#include "Frame.h"
+#include "JSSVGTransform.h"
+#include "SVGDocumentExtensions.h"
+#include "SVGTransformList.h"
+#include "SVGStyledElement.h"
+
+#include <wtf/Assertions.h>
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* JSSVGTransformList::clear(ExecState* exec, const List&)
+{
+ ExceptionCode ec = 0;
+
+ SVGTransformList* imp = static_cast<SVGTransformList*>(impl());
+ imp->clear(ec);
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return jsUndefined();
+}
+
+JSValue* JSSVGTransformList::initialize(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGTransform newItem = toSVGTransform(args[0]);
+
+ SVGTransformList* imp = static_cast<SVGTransformList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<SVGTransform> > >* listImp = imp;
+
+ SVGPODListItem<SVGTransform>* listItem = listImp->initialize(SVGPODListItem<SVGTransform>::copy(newItem), ec).get();
+ JSSVGPODTypeWrapperCreatorForList<SVGTransform>* obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGTransformList::getItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ bool indexOk;
+ unsigned index = args[0]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGTransformList* imp = static_cast<SVGTransformList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<SVGTransform> > >* listImp = imp;
+
+ SVGPODListItem<SVGTransform>* listItem = listImp->getItem(index, ec).get();
+ JSSVGPODTypeWrapperCreatorForList<SVGTransform>* obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+ return result;
+}
+
+JSValue* JSSVGTransformList::insertItemBefore(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGTransform newItem = toSVGTransform(args[0]);
+
+ bool indexOk;
+ unsigned index = args[1]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGTransformList* imp = static_cast<SVGTransformList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<SVGTransform> > >* listImp = imp;
+
+ SVGPODListItem<SVGTransform>* listItem = listImp->insertItemBefore(SVGPODListItem<SVGTransform>::copy(newItem), index, ec).get();
+ JSSVGPODTypeWrapperCreatorForList<SVGTransform>* obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGTransformList::replaceItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGTransform newItem = toSVGTransform(args[0]);
+
+ bool indexOk;
+ unsigned index = args[1]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGTransformList* imp = static_cast<SVGTransformList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<SVGTransform> > >* listImp = imp;
+
+ SVGPODListItem<SVGTransform>* listItem = listImp->replaceItem(SVGPODListItem<SVGTransform>::copy(newItem), index, ec).get();
+ JSSVGPODTypeWrapperCreatorForList<SVGTransform>* obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGTransformList::removeItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+
+ bool indexOk;
+ unsigned index = args[0]->toInt32(exec, indexOk);
+ if (!indexOk) {
+ setDOMException(exec, TYPE_MISMATCH_ERR);
+ return jsUndefined();
+ }
+
+ SVGTransformList* imp = static_cast<SVGTransformList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<SVGTransform> > >* listImp = imp;
+
+ RefPtr<SVGPODListItem<SVGTransform> > listItem(listImp->removeItem(index, ec));
+ JSSVGPODTypeWrapper<SVGTransform>* obj = new JSSVGPODTypeWrapperCreatorReadOnly<SVGTransform>(*listItem.get());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+JSValue* JSSVGTransformList::appendItem(ExecState* exec, const List& args)
+{
+ ExceptionCode ec = 0;
+ SVGTransform newItem = toSVGTransform(args[0]);
+
+ SVGTransformList* imp = static_cast<SVGTransformList*>(impl());
+ SVGList<RefPtr<SVGPODListItem<SVGTransform> > >* listImp = imp;
+
+ SVGPODListItem<SVGTransform>* listItem = listImp->appendItem(SVGPODListItem<SVGTransform>::copy(newItem), ec).get();
+ JSSVGPODTypeWrapperCreatorForList<SVGTransform>* obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
+
+ KJS::JSValue* result = toJS(exec, obj, m_context.get());
+ setDOMException(exec, ec);
+
+ m_context->svgAttributeChanged(imp->associatedAttributeName());
+
+ return result;
+}
+
+}
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/bindings/js/JSStyleSheetCustom.cpp b/WebCore/bindings/js/JSStyleSheetCustom.cpp
new file mode 100644
index 0000000..4122831
--- /dev/null
+++ b/WebCore/bindings/js/JSStyleSheetCustom.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSStyleSheet.h"
+
+#include "CSSStyleSheet.h"
+#include "JSCSSStyleSheet.h"
+#include "StyleSheet.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* toJS(ExecState* exec, StyleSheet* styleSheet)
+{
+ if (!styleSheet)
+ return jsNull();
+
+ DOMObject* ret = ScriptInterpreter::getDOMObject(styleSheet);
+ if (ret)
+ return ret;
+
+ if (styleSheet->isCSSStyleSheet())
+ ret = new JSCSSStyleSheet(JSCSSStyleSheetPrototype::self(exec), static_cast<CSSStyleSheet*>(styleSheet));
+ else
+ ret = new JSStyleSheet(JSStyleSheetPrototype::self(exec), styleSheet);
+
+ ScriptInterpreter::putDOMObject(styleSheet, ret);
+ return ret;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSStyleSheetListCustom.cpp b/WebCore/bindings/js/JSStyleSheetListCustom.cpp
new file mode 100644
index 0000000..aa4014f
--- /dev/null
+++ b/WebCore/bindings/js/JSStyleSheetListCustom.cpp
@@ -0,0 +1,50 @@
+
+/*
+ * Copyright (C) 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "JSStyleSheetList.h"
+
+#include "HTMLStyleElement.h"
+#include "JSStyleSheet.h"
+#include "StyleSheet.h"
+#include "StyleSheetList.h"
+
+namespace WebCore {
+
+bool JSStyleSheetList::canGetItemsForName(KJS::ExecState*, StyleSheetList* styleSheetList, const KJS::Identifier& propertyName)
+{
+ return styleSheetList->getNamedItem(propertyName);
+}
+
+KJS::JSValue* JSStyleSheetList::nameGetter(KJS::ExecState* exec, KJS::JSObject*, const KJS::Identifier& propertyName, const KJS::PropertySlot& slot)
+{
+ JSStyleSheetList* thisObj = static_cast<JSStyleSheetList*>(slot.slotBase());
+ HTMLStyleElement* element = thisObj->impl()->getNamedItem(propertyName);
+ ASSERT(element);
+ return toJS(exec, element->sheet());
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/JSTreeWalkerCustom.cpp b/WebCore/bindings/js/JSTreeWalkerCustom.cpp
new file mode 100644
index 0000000..c9dbcd9
--- /dev/null
+++ b/WebCore/bindings/js/JSTreeWalkerCustom.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2006, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "config.h"
+#include "JSTreeWalker.h"
+
+#include "JSNode.h"
+#include "Node.h"
+#include "NodeFilter.h"
+#include "TreeWalker.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+void JSTreeWalker::mark()
+{
+ if (NodeFilter* filter = m_impl->filter())
+ filter->mark();
+
+ DOMObject::mark();
+}
+
+JSValue* JSTreeWalker::parentNode(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ Node* node = impl()->parentNode(exception);
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+JSValue* JSTreeWalker::firstChild(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ Node* node = impl()->firstChild(exception);
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+JSValue* JSTreeWalker::lastChild(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ Node* node = impl()->lastChild(exception);
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+JSValue* JSTreeWalker::nextSibling(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ Node* node = impl()->nextSibling(exception);
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+JSValue* JSTreeWalker::previousSibling(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ Node* node = impl()->previousSibling(exception);
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+JSValue* JSTreeWalker::previousNode(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ Node* node = impl()->previousNode(exception);
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+JSValue* JSTreeWalker::nextNode(ExecState* exec, const List& args)
+{
+ JSValue* exception = 0;
+ Node* node = impl()->nextNode(exception);
+ if (exception) {
+ exec->setException(exception);
+ return jsUndefined();
+ }
+ return toJS(exec, node);
+}
+
+}
diff --git a/WebCore/bindings/js/JSXMLHttpRequest.cpp b/WebCore/bindings/js/JSXMLHttpRequest.cpp
new file mode 100644
index 0000000..99d89f5
--- /dev/null
+++ b/WebCore/bindings/js/JSXMLHttpRequest.cpp
@@ -0,0 +1,400 @@
+/*
+ * Copyright (C) 2004, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "JSXMLHttpRequest.h"
+
+#include "DOMWindow.h"
+#include "Event.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "HTMLDocument.h"
+#include "JSDocument.h"
+#include "JSEvent.h"
+#include "XMLHttpRequest.h"
+#include "kjs_events.h"
+#include "kjs_window.h"
+
+using namespace KJS;
+using namespace WebCore;
+
+#include "JSXMLHttpRequest.lut.h"
+
+namespace WebCore {
+
+/* Source for JSXMLHttpRequestPrototypeTable.
+@begin JSXMLHttpRequestPrototypeTable 7
+ abort jsXMLHttpRequestPrototypeFunctionAbort DontDelete|Function 0
+ getAllResponseHeaders jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders DontDelete|Function 0
+ getResponseHeader jsXMLHttpRequestPrototypeFunctionGetResponseHeader DontDelete|Function 1
+ open jsXMLHttpRequestPrototypeFunctionOpen DontDelete|Function 5
+ overrideMimeType jsXMLHttpRequestPrototypeFunctionOverrideMIMEType DontDelete|Function 1
+ send jsXMLHttpRequestPrototypeFunctionSend DontDelete|Function 1
+ setRequestHeader jsXMLHttpRequestPrototypeFunctionSetRequestHeader DontDelete|Function 2
+# from the EventTarget interface
+# FIXME: add DOM3 EventTarget methods (addEventListenerNS, removeEventListenerNS).
+ addEventListener jsXMLHttpRequestPrototypeFunctionAddEventListener DontDelete|Function 3
+ removeEventListener jsXMLHttpRequestPrototypeFunctionRemoveEventListener DontDelete|Function 3
+ dispatchEvent jsXMLHttpRequestPrototypeFunctionDispatchEvent DontDelete|Function 1
+@end
+*/
+KJS_DEFINE_PROTOTYPE(JSXMLHttpRequestPrototype)
+KJS_IMPLEMENT_PROTOTYPE("JSXMLHttpRequest", JSXMLHttpRequestPrototype)
+
+JSXMLHttpRequestConstructorImp::JSXMLHttpRequestConstructorImp(ExecState* exec, Document* d)
+ : DOMObject(exec->lexicalGlobalObject()->objectPrototype())
+ , doc(d)
+{
+ putDirect(exec->propertyNames().prototype, JSXMLHttpRequestPrototype::self(exec), None);
+}
+
+bool JSXMLHttpRequestConstructorImp::implementsConstruct() const
+{
+ return true;
+}
+
+JSObject* JSXMLHttpRequestConstructorImp::construct(ExecState* exec, const List&)
+{
+ return new JSXMLHttpRequest(JSXMLHttpRequestPrototype::self(exec), doc.get());
+}
+
+const ClassInfo JSXMLHttpRequest::info = { "JSXMLHttpRequest", 0, &JSXMLHttpRequestTable };
+
+/* Source for JSXMLHttpRequestTable.
+@begin JSXMLHttpRequestTable 7
+ readyState JSXMLHttpRequest::ReadyState DontDelete|ReadOnly
+ responseText JSXMLHttpRequest::ResponseText DontDelete|ReadOnly
+ responseXML JSXMLHttpRequest::ResponseXML DontDelete|ReadOnly
+ status JSXMLHttpRequest::Status DontDelete|ReadOnly
+ statusText JSXMLHttpRequest::StatusText DontDelete|ReadOnly
+ onreadystatechange JSXMLHttpRequest::Onreadystatechange DontDelete
+ onload JSXMLHttpRequest::Onload DontDelete
+@end
+*/
+
+bool JSXMLHttpRequest::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return getStaticValueSlot<JSXMLHttpRequest, DOMObject>(exec, &JSXMLHttpRequestTable, this, propertyName, slot);
+}
+
+JSValue* JSXMLHttpRequest::getValueProperty(ExecState* exec, int token) const
+{
+ ExceptionCode ec = 0;
+
+ switch (token) {
+ case ReadyState:
+ return jsNumber(m_impl->getReadyState());
+ case ResponseText: {
+ JSValue* result = jsOwnedStringOrNull(m_impl->getResponseText(ec));
+ setDOMException(exec, ec);
+ return result;
+ }
+ case ResponseXML: {
+ Document* responseXML = m_impl->getResponseXML(ec);
+ setDOMException(exec, ec);
+ if (responseXML)
+ return toJS(exec, responseXML);
+
+ return jsNull();
+ }
+ case Status: {
+ JSValue* result = jsNumber(m_impl->getStatus(ec));
+ setDOMException(exec, ec);
+ return result;
+ }
+ case StatusText: {
+ JSValue* result = jsString(m_impl->getStatusText(ec));
+ setDOMException(exec, ec);
+ return result;
+ }
+ case Onreadystatechange:
+ if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onReadyStateChangeListener()))
+ if (JSObject* listenerObj = listener->listenerObj())
+ return listenerObj;
+ return jsNull();
+ case Onload:
+ if (JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(m_impl->onLoadListener()))
+ if (JSObject* listenerObj = listener->listenerObj())
+ return listenerObj;
+ return jsNull();
+ default:
+ return 0;
+ }
+}
+
+void JSXMLHttpRequest::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ lookupPut<JSXMLHttpRequest, DOMObject>(exec, propertyName, value, &JSXMLHttpRequestTable, this);
+}
+
+void JSXMLHttpRequest::putValueProperty(ExecState* exec, int token, JSValue* value)
+{
+ switch (token) {
+ case Onreadystatechange: {
+ Document* doc = m_impl->document();
+ if (!doc)
+ return;
+ Frame* frame = doc->frame();
+ if (!frame)
+ return;
+ m_impl->setOnReadyStateChangeListener(KJS::Window::retrieveWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+ break;
+ }
+ case Onload: {
+ Document* doc = m_impl->document();
+ if (!doc)
+ return;
+ Frame* frame = doc->frame();
+ if (!frame)
+ return;
+ m_impl->setOnLoadListener(KJS::Window::retrieveWindow(frame)->findOrCreateJSUnprotectedEventListener(value, true));
+ break;
+ }
+ }
+}
+
+void JSXMLHttpRequest::mark()
+{
+ DOMObject::mark();
+
+ JSUnprotectedEventListener* onReadyStateChangeListener = static_cast<JSUnprotectedEventListener*>(m_impl->onReadyStateChangeListener());
+ JSUnprotectedEventListener* onLoadListener = static_cast<JSUnprotectedEventListener*>(m_impl->onLoadListener());
+
+ if (onReadyStateChangeListener)
+ onReadyStateChangeListener->mark();
+
+ if (onLoadListener)
+ onLoadListener->mark();
+
+ typedef XMLHttpRequest::EventListenersMap EventListenersMap;
+ typedef XMLHttpRequest::ListenerVector ListenerVector;
+ EventListenersMap& eventListeners = m_impl->eventListeners();
+ for (EventListenersMap::iterator mapIter = eventListeners.begin(); mapIter != eventListeners.end(); ++mapIter) {
+ for (ListenerVector::iterator vecIter = mapIter->second.begin(); vecIter != mapIter->second.end(); ++vecIter) {
+ JSUnprotectedEventListener* listener = static_cast<JSUnprotectedEventListener*>(vecIter->get());
+ listener->mark();
+ }
+ }
+}
+
+
+JSXMLHttpRequest::JSXMLHttpRequest(JSObject* prototype, Document* d)
+ : DOMObject(prototype)
+ , m_impl(XMLHttpRequest::create(d))
+{
+ ScriptInterpreter::putDOMObject(m_impl.get(), this);
+}
+
+JSXMLHttpRequest::~JSXMLHttpRequest()
+{
+ m_impl->setOnReadyStateChangeListener(0);
+ m_impl->setOnLoadListener(0);
+ m_impl->eventListeners().clear();
+ ScriptInterpreter::forgetDOMObject(m_impl.get());
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionAbort(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+
+ request->impl()->abort();
+ return jsUndefined();
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+ ExceptionCode ec = 0;
+
+ JSValue* headers = jsStringOrUndefined(request->impl()->getAllResponseHeaders(ec));
+ setDOMException(exec, ec);
+ return headers;
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionGetResponseHeader(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+ ExceptionCode ec = 0;
+
+ if (args.size() < 1)
+ return throwError(exec, SyntaxError, "Not enough arguments");
+
+ JSValue* header = jsStringOrNull(request->impl()->getResponseHeader(args[0]->toString(exec), ec));
+ setDOMException(exec, ec);
+ return header;
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionOpen(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+ ExceptionCode ec = 0;
+
+ if (args.size() < 2)
+ return throwError(exec, SyntaxError, "Not enough arguments");
+
+ String method = args[0]->toString(exec);
+ Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+ if (!frame)
+ return jsUndefined();
+ KURL url = frame->loader()->completeURL(args[1]->toString(exec));
+
+ bool async = true;
+ if (args.size() >= 3)
+ async = args[2]->toBoolean(exec);
+
+ if (args.size() >= 4 && !args[3]->isUndefined()) {
+ String user = valueToStringWithNullCheck(exec, args[3]);
+
+ if (args.size() >= 5 && !args[4]->isUndefined()) {
+ String password = valueToStringWithNullCheck(exec, args[4]);
+ request->impl()->open(method, url, async, user, password, ec);
+ } else
+ request->impl()->open(method, url, async, user, ec);
+ } else
+ request->impl()->open(method, url, async, ec);
+
+ setDOMException(exec, ec);
+ return jsUndefined();
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionSend(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+ ExceptionCode ec = 0;
+
+ String body;
+
+ if (args.size() >= 1) {
+ if (args[0]->toObject(exec)->inherits(&JSDocument::info))
+ body = static_cast<Document*>(static_cast<JSDocument*>(args[0]->toObject(exec))->impl())->toString();
+ else {
+ // converting certain values (like null) to object can set an exception
+ if (exec->hadException())
+ exec->clearException();
+ else
+ body = args[0]->toString(exec);
+ }
+ }
+
+ request->impl()->send(body, ec);
+ setDOMException(exec, ec);
+
+ return jsUndefined();
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionSetRequestHeader(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+ ExceptionCode ec = 0;
+
+ if (args.size() < 2)
+ return throwError(exec, SyntaxError, "Not enough arguments");
+
+ request->impl()->setRequestHeader(args[0]->toString(exec), args[1]->toString(exec), ec);
+ setDOMException(exec, ec);
+ return jsUndefined();
+
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionOverrideMIMEType(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+
+ if (args.size() < 1)
+ return throwError(exec, SyntaxError, "Not enough arguments");
+
+ request->impl()->overrideMIMEType(args[0]->toString(exec));
+ return jsUndefined();
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionAddEventListener(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+
+ Document* doc = request->impl()->document();
+ if (!doc)
+ return jsUndefined();
+ Frame* frame = doc->frame();
+ if (!frame)
+ return jsUndefined();
+ JSUnprotectedEventListener* listener = KJS::Window::retrieveWindow(frame)->findOrCreateJSUnprotectedEventListener(args[1], true);
+ if (!listener)
+ return jsUndefined();
+ request->impl()->addEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec));
+ return jsUndefined();
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionRemoveEventListener(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+
+ Document* doc = request->impl()->document();
+ if (!doc)
+ return jsUndefined();
+ Frame* frame = doc->frame();
+ if (!frame)
+ return jsUndefined();
+ JSUnprotectedEventListener* listener = KJS::Window::retrieveWindow(frame)->findOrCreateJSUnprotectedEventListener(args[1], true);
+ if (!listener)
+ return jsUndefined();
+ request->impl()->removeEventListener(args[0]->toString(exec), listener, args[2]->toBoolean(exec));
+ return jsUndefined();
+}
+
+JSValue* jsXMLHttpRequestPrototypeFunctionDispatchEvent(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXMLHttpRequest::info))
+ return throwError(exec, TypeError);
+
+ JSXMLHttpRequest* request = static_cast<JSXMLHttpRequest*>(thisObj);
+ ExceptionCode ec = 0;
+
+ bool result = request->impl()->dispatchEvent(toEvent(args[0]), ec);
+ setDOMException(exec, ec);
+ return jsBoolean(result);
+}
+
+} // end namespace
diff --git a/WebCore/bindings/js/JSXMLHttpRequest.h b/WebCore/bindings/js/JSXMLHttpRequest.h
new file mode 100644
index 0000000..6567a6b
--- /dev/null
+++ b/WebCore/bindings/js/JSXMLHttpRequest.h
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2003, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2005, 2006 Alexey Proskuryakov <ap@nypop.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef JSXMLHttpRequest_h
+#define JSXMLHttpRequest_h
+
+#include "kjs_binding.h"
+
+namespace WebCore {
+
+class XMLHttpRequest;
+class Document;
+
+class JSXMLHttpRequestConstructorImp : public DOMObject {
+public:
+ JSXMLHttpRequestConstructorImp(KJS::ExecState*, Document*);
+
+ virtual bool implementsConstruct() const;
+ virtual KJS::JSObject* construct(KJS::ExecState*, const KJS::List&);
+
+private:
+ RefPtr<Document> doc;
+};
+
+class JSXMLHttpRequest : public DOMObject {
+public:
+ JSXMLHttpRequest(KJS::JSObject* prototype, Document*);
+ ~JSXMLHttpRequest();
+
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+ enum { Onload, Onreadystatechange, ReadyState, ResponseText, ResponseXML, Status,
+ StatusText, Abort, GetAllResponseHeaders, GetResponseHeader, Open, Send, SetRequestHeader, OverrideMIMEType,
+ AddEventListener, RemoveEventListener, DispatchEvent };
+
+ virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+ KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
+ virtual void put(KJS::ExecState*, const KJS::Identifier& propertyName, KJS::JSValue*);
+ void putValueProperty(KJS::ExecState*, int token, KJS::JSValue*);
+ virtual bool toBoolean(KJS::ExecState*) const { return true; }
+ virtual void mark();
+
+ XMLHttpRequest* impl() const { return m_impl.get(); }
+
+private:
+ RefPtr<XMLHttpRequest> m_impl;
+};
+
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionAbort(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionGetAllResponseHeaders(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionGetResponseHeader(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionOpen(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionSend(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionSetRequestHeader(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionOverrideMIMEType(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionAddEventListener(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionRemoveEventListener(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXMLHttpRequestPrototypeFunctionDispatchEvent(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
+} // namespace WebCore
+
+#endif // JSXMLHttpRequest_h
diff --git a/WebCore/bindings/js/JSXSLTProcessor.cpp b/WebCore/bindings/js/JSXSLTProcessor.cpp
new file mode 100644
index 0000000..7902f61
--- /dev/null
+++ b/WebCore/bindings/js/JSXSLTProcessor.cpp
@@ -0,0 +1,208 @@
+/*
+ * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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"
+
+#if ENABLE(XSLT)
+
+#include "JSXSLTProcessor.h"
+
+#include "XSLTProcessor.h"
+#include "kjs_dom.h"
+#include "JSDocument.h"
+#include "Document.h"
+#include "DocumentFragment.h"
+
+using namespace KJS;
+using namespace WebCore;
+
+#include "JSXSLTProcessor.lut.h"
+
+namespace WebCore {
+
+const ClassInfo JSXSLTProcessor::info = { "XSLTProcessor", 0, 0 };
+
+/*
+@begin XSLTProcessorPrototypeTable 7
+ importStylesheet jsXSLTProcessorPrototypeFunctionImportStylesheet DontDelete|Function 1
+ transformToFragment jsXSLTProcessorPrototypeFunctionTransformToFragment DontDelete|Function 2
+ transformToDocument jsXSLTProcessorPrototypeFunctionTransformToDocument DontDelete|Function 2
+ setParameter jsXSLTProcessorPrototypeFunctionSetParameter DontDelete|Function 3
+ getParameter jsXSLTProcessorPrototypeFunctionGetParameter DontDelete|Function 2
+ removeParameter jsXSLTProcessorPrototypeFunctionRemoveParameter DontDelete|Function 2
+ clearParameters jsXSLTProcessorPrototypeFunctionClearParameters DontDelete|Function 0
+ reset jsXSLTProcessorPrototypeFunctionReset DontDelete|Function 0
+@end
+*/
+
+KJS_DEFINE_PROTOTYPE(XSLTProcessorPrototype)
+KJS_IMPLEMENT_PROTOTYPE("XSLTProcessor", XSLTProcessorPrototype)
+
+JSXSLTProcessor::JSXSLTProcessor(JSObject* prototype)
+ : DOMObject(prototype)
+ , m_impl(XSLTProcessor::create())
+{
+}
+
+JSXSLTProcessor::~JSXSLTProcessor()
+{
+ ScriptInterpreter::forgetDOMObject(m_impl.get());
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionImportStylesheet(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ JSValue *nodeVal = args[0];
+ if (nodeVal->isObject(&JSNode::info)) {
+ JSNode* node = static_cast<JSNode*>(nodeVal);
+ processor.importStylesheet(node->impl());
+ return jsUndefined();
+ }
+ // Throw exception?
+ return jsUndefined();
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionTransformToFragment(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ JSValue *nodeVal = args[0];
+ JSValue *docVal = args[1];
+ if (nodeVal->isObject(&JSNode::info) && docVal->isObject(&JSDocument::info)) {
+ WebCore::Node* node = static_cast<JSNode*>(nodeVal)->impl();
+ Document* doc = static_cast<Document*>(static_cast<JSDocument *>(docVal)->impl());
+ return toJS(exec, processor.transformToFragment(node, doc).get());
+ }
+ // Throw exception?
+ return jsUndefined();
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionTransformToDocument(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ JSValue *nodeVal = args[0];
+ if (nodeVal->isObject(&JSNode::info)) {
+ JSNode* node = static_cast<JSNode*>(nodeVal);
+ RefPtr<Document> resultDocument = processor.transformToDocument(node->impl());
+ if (resultDocument)
+ return toJS(exec, resultDocument.get());
+ return jsUndefined();
+ }
+ // Throw exception?
+ return jsUndefined();
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionSetParameter(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ if (args[1]->isUndefinedOrNull() || args[2]->isUndefinedOrNull())
+ return jsUndefined(); // Throw exception?
+ String namespaceURI = args[0]->toString(exec);
+ String localName = args[1]->toString(exec);
+ String value = args[2]->toString(exec);
+ processor.setParameter(namespaceURI, localName, value);
+ return jsUndefined();
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionGetParameter(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ if (args[1]->isUndefinedOrNull())
+ return jsUndefined();
+ String namespaceURI = args[0]->toString(exec);
+ String localName = args[1]->toString(exec);
+ String value = processor.getParameter(namespaceURI, localName);
+ if (!value.isNull())
+ return jsString(value);
+ return jsUndefined();
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionRemoveParameter(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ if (args[1]->isUndefinedOrNull())
+ return jsUndefined();
+ String namespaceURI = args[0]->toString(exec);
+ String localName = args[1]->toString(exec);
+ processor.removeParameter(namespaceURI, localName);
+ return jsUndefined();
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionClearParameters(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ processor.clearParameters();
+ return jsUndefined();
+}
+
+JSValue* jsXSLTProcessorPrototypeFunctionReset(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSXSLTProcessor::info))
+ return throwError(exec, TypeError);
+ XSLTProcessor& processor = *static_cast<JSXSLTProcessor*>(thisObj)->impl();
+
+ processor.reset();
+ return jsUndefined();
+}
+
+XSLTProcessorConstructorImp::XSLTProcessorConstructorImp(ExecState* exec)
+ : DOMObject(exec->lexicalGlobalObject()->objectPrototype())
+{
+ putDirect(exec->propertyNames().prototype, XSLTProcessorPrototype::self(exec), None);
+}
+
+bool XSLTProcessorConstructorImp::implementsConstruct() const
+{
+ return true;
+}
+
+JSObject* XSLTProcessorConstructorImp::construct(ExecState* exec, const List& args)
+{
+ return new JSXSLTProcessor(XSLTProcessorPrototype::self(exec));
+}
+
+} // namespace KJS
+
+#endif // ENABLE(XSLT)
diff --git a/WebCore/bindings/js/JSXSLTProcessor.h b/WebCore/bindings/js/JSXSLTProcessor.h
new file mode 100644
index 0000000..26ba6b3
--- /dev/null
+++ b/WebCore/bindings/js/JSXSLTProcessor.h
@@ -0,0 +1,76 @@
+/*
+ * Copyright (C) 2005, 2008 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef JSXSLTProcessor_h
+#define JSXSLTProcessor_h
+
+#if ENABLE(XSLT)
+
+#include "kjs_binding.h"
+
+namespace WebCore {
+
+class XSLTProcessor;
+
+// Eventually we should implement XSLTException:
+// http://lxr.mozilla.org/seamonkey/source/content/xsl/public/nsIXSLTException.idl
+// http://bugs.webkit.org/show_bug.cgi?id=5446
+
+class JSXSLTProcessor : public DOMObject {
+public:
+ JSXSLTProcessor(KJS::JSObject* prototype);
+ ~JSXSLTProcessor();
+
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+
+ XSLTProcessor* impl() const { return m_impl.get(); }
+
+private:
+ RefPtr<XSLTProcessor> m_impl;
+};
+
+class XSLTProcessorConstructorImp : public DOMObject {
+public:
+ XSLTProcessorConstructorImp(KJS::ExecState*);
+
+ virtual bool implementsConstruct() const;
+ virtual KJS::JSObject* construct(KJS::ExecState*, const KJS::List&);
+};
+
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionImportStylesheet(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionTransformToFragment(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionTransformToDocument(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionSetParameter(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionGetParameter(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionRemoveParameter(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionClearParameters(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+KJS::JSValue* jsXSLTProcessorPrototypeFunctionReset(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
+} // namespace WebCore
+
+#endif // ENABLE(XSLT)
+
+#endif // JSXSLTProcessor_h
diff --git a/WebCore/bindings/js/PausedTimeouts.cpp b/WebCore/bindings/js/PausedTimeouts.cpp
new file mode 100644
index 0000000..c8a59d8
--- /dev/null
+++ b/WebCore/bindings/js/PausedTimeouts.cpp
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reseved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include "config.h"
+#include "PausedTimeouts.h"
+
+#include "ScheduledAction.h"
+
+namespace WebCore {
+
+PausedTimeouts::~PausedTimeouts()
+{
+ PausedTimeout* array = m_array;
+ if (!array)
+ return;
+ size_t count = m_length;
+ for (size_t i = 0; i != count; ++i)
+ delete array[i].action;
+ delete [] array;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/PausedTimeouts.h b/WebCore/bindings/js/PausedTimeouts.h
new file mode 100644
index 0000000..3839eae
--- /dev/null
+++ b/WebCore/bindings/js/PausedTimeouts.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reseved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef PausedTimeouts_h
+#define PausedTimeouts_h
+
+#include <wtf/Noncopyable.h>
+
+namespace WebCore {
+
+ class ScheduledAction;
+
+ struct PausedTimeout {
+ int timeoutId;
+ int nestingLevel;
+ double nextFireInterval;
+ double repeatInterval;
+ ScheduledAction* action;
+ };
+
+ class PausedTimeouts : Noncopyable {
+ public:
+ PausedTimeouts(PausedTimeout* array, size_t length)
+ : m_array(array)
+ , m_length(length)
+ {
+ }
+
+ ~PausedTimeouts();
+
+ size_t numTimeouts() const { return m_length; }
+ PausedTimeout* takeTimeouts() { PausedTimeout* a = m_array; m_array = 0; return a; }
+
+ private:
+ PausedTimeout* m_array;
+ size_t m_length;
+ };
+
+} // namespace WebCore
+
+#endif // PausedTimeouts_h
diff --git a/WebCore/bindings/js/ScheduledAction.cpp b/WebCore/bindings/js/ScheduledAction.cpp
new file mode 100644
index 0000000..a26923d
--- /dev/null
+++ b/WebCore/bindings/js/ScheduledAction.cpp
@@ -0,0 +1,102 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reseved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include "config.h"
+#include "ScheduledAction.h"
+
+#include "CString.h"
+#include "Chrome.h"
+#include "DOMWindow.h"
+#include "Document.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "Page.h"
+#include "kjs_proxy.h"
+#include "kjs_window.h"
+
+using namespace KJS;
+
+namespace WebCore {
+
+ScheduledAction::ScheduledAction(JSValue* func, const List& args)
+ : m_func(func)
+{
+ List::const_iterator end = args.end();
+ for (List::const_iterator it = args.begin(); it != end; ++it)
+ m_args.append(*it);
+}
+
+
+void ScheduledAction::execute(Window* window)
+{
+ RefPtr<Frame> frame = window->impl()->frame();
+ if (!frame)
+ return;
+
+ if (!frame->scriptProxy()->isEnabled())
+ return;
+
+ KJSProxy* scriptProxy = frame->scriptProxy();
+ Window* globalObject = scriptProxy->globalObject();
+
+ scriptProxy->setProcessingTimerCallback(true);
+
+ if (JSValue* func = m_func.get()) {
+ JSLock lock;
+ if (func->isObject() && static_cast<JSObject*>(func)->implementsCall()) {
+ ExecState* exec = window->globalExec();
+ ASSERT(window == globalObject);
+
+ List args;
+ size_t size = m_args.size();
+ for (size_t i = 0; i < size; ++i)
+ args.append(m_args[i]);
+
+ globalObject->startTimeoutCheck();
+ static_cast<JSObject*>(func)->call(exec, window, args);
+ globalObject->stopTimeoutCheck();
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ exec->clearException();
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("(timer):%s\n", message.utf8().data());
+ if (Page* page = frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, String());
+ }
+ }
+ } else
+ frame->loader()->executeScript(m_code);
+
+ // Update our document's rendering following the execution of the timeout callback.
+ // FIXME: Why not use updateDocumentsRendering to update rendering of all documents?
+ // FIXME: Is this really the right point to do the update? We need a place that works
+ // for all possible entry points that might possibly execute script, but this seems
+ // to be a bit too low-level.
+ if (Document* doc = frame->document())
+ doc->updateRendering();
+
+ scriptProxy->setProcessingTimerCallback(false);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/ScheduledAction.h b/WebCore/bindings/js/ScheduledAction.h
new file mode 100644
index 0000000..a3b1858
--- /dev/null
+++ b/WebCore/bindings/js/ScheduledAction.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reseved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef ScheduledAction_h
+#define ScheduledAction_h
+
+#include "PlatformString.h"
+#include <kjs/protect.h>
+#include <wtf/Vector.h>
+
+namespace KJS {
+ class Window;
+ class JSValue;
+ class List;
+}
+
+namespace WebCore {
+
+ /**
+ * An action (either function or string) to be executed after a specified
+ * time interval, either once or repeatedly. Used for window.setTimeout()
+ * and window.setInterval()
+ */
+ class ScheduledAction {
+ public:
+ ScheduledAction(KJS::JSValue* func, const KJS::List& args);
+ ScheduledAction(const String& code)
+ : m_code(code)
+ {
+ }
+
+ void execute(KJS::Window*);
+
+ private:
+ KJS::ProtectedPtr<KJS::JSValue> m_func;
+ Vector<KJS::ProtectedPtr<KJS::JSValue> > m_args;
+ String m_code;
+ };
+
+} // namespace WebCore
+
+#endif // ScheduledAction_h
diff --git a/WebCore/bindings/js/kjs_binding.cpp b/WebCore/bindings/js/kjs_binding.cpp
new file mode 100644
index 0000000..5855ca0
--- /dev/null
+++ b/WebCore/bindings/js/kjs_binding.cpp
@@ -0,0 +1,378 @@
+/*
+ * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+// gcc 3.x can't handle including the HashMap pointer specialization in this file
+#if defined __GNUC__ && !defined __GLIBCXX__ // less than gcc 3.4
+#define HASH_MAP_PTR_SPEC_WORKAROUND 1
+#endif
+
+#include "config.h"
+#include "kjs_binding.h"
+
+#include "DOMCoreException.h"
+#include "EventException.h"
+#include "ExceptionCode.h"
+#include "HTMLImageElement.h"
+#include "HTMLNames.h"
+#include "JSDOMCoreException.h"
+#include "JSEventException.h"
+#include "JSNode.h"
+#include "JSRangeException.h"
+#include "JSXMLHttpRequestException.h"
+#include "KURL.h"
+#include "RangeException.h"
+#include "XMLHttpRequestException.h"
+#include "kjs_window.h"
+
+#if ENABLE(SVG)
+#include "JSSVGException.h"
+#include "SVGException.h"
+#endif
+
+#if ENABLE(XPATH)
+#include "JSXPathException.h"
+#include "XPathException.h"
+#endif
+
+using namespace KJS;
+
+namespace WebCore {
+
+using namespace HTMLNames;
+
+typedef HashMap<void*, DOMObject*> DOMObjectMap;
+typedef HashMap<WebCore::Node*, JSNode*> NodeMap;
+typedef HashMap<Document*, NodeMap*> NodePerDocMap;
+
+// For debugging, keep a set of wrappers currently registered, and check that
+// all are unregistered before they are destroyed. This has helped us fix at
+// least one bug.
+
+static void addWrapper(DOMObject* wrapper);
+static void removeWrapper(DOMObject* wrapper);
+static void removeWrappers(const NodeMap& wrappers);
+
+#ifdef NDEBUG
+
+static inline void addWrapper(DOMObject*)
+{
+}
+
+static inline void removeWrapper(DOMObject*)
+{
+}
+
+static inline void removeWrappers(const NodeMap&)
+{
+}
+
+#else
+
+static HashSet<DOMObject*>& wrapperSet()
+{
+ static HashSet<DOMObject*> staticWrapperSet;
+ return staticWrapperSet;
+}
+
+static void addWrapper(DOMObject* wrapper)
+{
+ ASSERT(!wrapperSet().contains(wrapper));
+ wrapperSet().add(wrapper);
+}
+
+static void removeWrapper(DOMObject* wrapper)
+{
+ if (!wrapper)
+ return;
+ ASSERT(wrapperSet().contains(wrapper));
+ wrapperSet().remove(wrapper);
+}
+
+static void removeWrappers(const NodeMap& wrappers)
+{
+ for (NodeMap::const_iterator it = wrappers.begin(); it != wrappers.end(); ++it)
+ removeWrapper(it->second);
+}
+
+DOMObject::~DOMObject()
+{
+ ASSERT(!wrapperSet().contains(this));
+}
+
+#endif
+
+static DOMObjectMap& domObjects()
+{
+ // Don't use malloc here. Calling malloc from a mark function can deadlock.
+ static DOMObjectMap staticDOMObjects;
+ return staticDOMObjects;
+}
+
+static NodePerDocMap& domNodesPerDocument()
+{
+ // domNodesPerDocument() callers must synchronize using the JSLock because
+ // domNodesPerDocument() is called from a mark function, which can run
+ // on a secondary thread.
+ ASSERT(JSLock::lockCount());
+
+ // Don't use malloc here. Calling malloc from a mark function can deadlock.
+ static NodePerDocMap staticDOMNodesPerDocument;
+ return staticDOMNodesPerDocument;
+}
+
+DOMObject* ScriptInterpreter::getDOMObject(void* objectHandle)
+{
+ return domObjects().get(objectHandle);
+}
+
+void ScriptInterpreter::putDOMObject(void* objectHandle, DOMObject* wrapper)
+{
+ addWrapper(wrapper);
+ domObjects().set(objectHandle, wrapper);
+}
+
+void ScriptInterpreter::forgetDOMObject(void* objectHandle)
+{
+ removeWrapper(domObjects().take(objectHandle));
+}
+
+JSNode* ScriptInterpreter::getDOMNodeForDocument(Document* document, WebCore::Node* node)
+{
+ if (!document)
+ return static_cast<JSNode*>(domObjects().get(node));
+ NodeMap* documentDict = domNodesPerDocument().get(document);
+ if (documentDict)
+ return documentDict->get(node);
+ return NULL;
+}
+
+void ScriptInterpreter::forgetDOMNodeForDocument(Document* document, WebCore::Node* node)
+{
+ if (!document) {
+ removeWrapper(domObjects().take(node));
+ return;
+ }
+ NodeMap* documentDict = domNodesPerDocument().get(document);
+ if (documentDict)
+ removeWrapper(documentDict->take(node));
+}
+
+void ScriptInterpreter::putDOMNodeForDocument(Document* document, WebCore::Node* node, JSNode* wrapper)
+{
+ addWrapper(wrapper);
+ if (!document) {
+ domObjects().set(node, wrapper);
+ return;
+ }
+ NodeMap* documentDict = domNodesPerDocument().get(document);
+ if (!documentDict) {
+ documentDict = new NodeMap;
+ domNodesPerDocument().set(document, documentDict);
+ }
+ documentDict->set(node, wrapper);
+}
+
+void ScriptInterpreter::forgetAllDOMNodesForDocument(Document* document)
+{
+ ASSERT(document);
+ NodeMap* map = domNodesPerDocument().take(document);
+ if (!map)
+ return;
+ removeWrappers(*map);
+ delete map;
+}
+
+void ScriptInterpreter::markDOMNodesForDocument(Document* doc)
+{
+ NodePerDocMap::iterator dictIt = domNodesPerDocument().find(doc);
+ if (dictIt != domNodesPerDocument().end()) {
+ NodeMap* nodeDict = dictIt->second;
+ NodeMap::iterator nodeEnd = nodeDict->end();
+ for (NodeMap::iterator nodeIt = nodeDict->begin(); nodeIt != nodeEnd; ++nodeIt) {
+ JSNode* jsNode = nodeIt->second;
+ WebCore::Node* node = jsNode->impl();
+
+ // don't mark wrappers for nodes that are no longer in the
+ // document - they should not be saved if the node is not
+ // otherwise reachable from JS.
+ // However, image elements that aren't in the document are also
+ // marked, if they are not done loading yet.
+ if (!jsNode->marked() && (node->inDocument() || (node->hasTagName(imgTag) &&
+ !static_cast<HTMLImageElement*>(node)->haveFiredLoadEvent())))
+ jsNode->mark();
+ }
+ }
+}
+
+void ScriptInterpreter::updateDOMNodeDocument(WebCore::Node* node, Document* oldDoc, Document* newDoc)
+{
+ ASSERT(oldDoc != newDoc);
+ JSNode* wrapper = getDOMNodeForDocument(oldDoc, node);
+ if (wrapper) {
+ removeWrapper(wrapper);
+ putDOMNodeForDocument(newDoc, node, wrapper);
+ forgetDOMNodeForDocument(oldDoc, node);
+ addWrapper(wrapper);
+ }
+}
+
+JSValue* jsStringOrNull(const String& s)
+{
+ if (s.isNull())
+ return jsNull();
+ return jsString(s);
+}
+
+JSValue* jsOwnedStringOrNull(const KJS::UString& s)
+{
+ if (s.isNull())
+ return jsNull();
+ return jsOwnedString(s);
+}
+
+JSValue* jsStringOrUndefined(const String& s)
+{
+ if (s.isNull())
+ return jsUndefined();
+ return jsString(s);
+}
+
+JSValue* jsStringOrFalse(const String& s)
+{
+ if (s.isNull())
+ return jsBoolean(false);
+ return jsString(s);
+}
+
+JSValue* jsStringOrNull(const KURL& url)
+{
+ if (url.isNull())
+ return jsNull();
+ return jsString(url.string());
+}
+
+JSValue* jsStringOrUndefined(const KURL& url)
+{
+ if (url.isNull())
+ return jsUndefined();
+ return jsString(url.string());
+}
+
+JSValue* jsStringOrFalse(const KURL& url)
+{
+ if (url.isNull())
+ return jsBoolean(false);
+ return jsString(url.string());
+}
+
+String valueToStringWithNullCheck(ExecState* exec, JSValue* val)
+{
+ if (val->isNull())
+ return String();
+ return val->toString(exec);
+}
+
+String valueToStringWithUndefinedOrNullCheck(ExecState* exec, JSValue* val)
+{
+ if (val->isUndefinedOrNull())
+ return String();
+ return val->toString(exec);
+}
+
+void setDOMException(ExecState* exec, ExceptionCode ec)
+{
+ if (!ec || exec->hadException())
+ return;
+
+ // To be removed: See XMLHttpRequest.h.
+ if (ec == XMLHttpRequestException::PERMISSION_DENIED) {
+ throwError(exec, GeneralError, "Permission denied");
+ return;
+ }
+
+ ExceptionCodeDescription description;
+ getExceptionCodeDescription(ec, description);
+
+ JSValue* errorObject = 0;
+ switch (description.type) {
+ case DOMExceptionType:
+ errorObject = toJS(exec, new DOMCoreException(description));
+ break;
+ case RangeExceptionType:
+ errorObject = toJS(exec, new RangeException(description));
+ break;
+ case EventExceptionType:
+ errorObject = toJS(exec, new EventException(description));
+ break;
+ case XMLHttpRequestExceptionType:
+ errorObject = toJS(exec, new XMLHttpRequestException(description));
+ break;
+#if ENABLE(SVG)
+ case SVGExceptionType:
+ errorObject = toJS(exec, new SVGException(description), 0);
+ break;
+#endif
+#if ENABLE(XPATH)
+ case XPathExceptionType:
+ errorObject = toJS(exec, new XPathException(description));
+ break;
+#endif
+ }
+
+ ASSERT(errorObject);
+ exec->setException(errorObject);
+}
+
+bool allowsAccessFromFrame(ExecState* exec, Frame* frame)
+{
+ if (!frame)
+ return false;
+ Window* window = Window::retrieveWindow(frame);
+ return window && window->allowsAccessFrom(exec);
+}
+
+bool allowsAccessFromFrame(ExecState* exec, Frame* frame, String& message)
+{
+ if (!frame)
+ return false;
+ Window* window = Window::retrieveWindow(frame);
+ return window && window->allowsAccessFrom(exec, message);
+}
+
+void printErrorMessageForFrame(Frame* frame, const String& message)
+{
+ if (!frame)
+ return;
+ if (Window* window = Window::retrieveWindow(frame))
+ window->printErrorMessage(message);
+}
+
+JSValue* nonCachingStaticFunctionGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
+{
+ const HashEntry* entry = slot.staticEntry();
+ return new PrototypeFunction(exec, entry->params, propertyName, entry->value.functionValue);
+}
+
+JSValue* objectToStringFunctionGetter(ExecState* exec, JSObject*, const Identifier& propertyName, const PropertySlot&)
+{
+ return new PrototypeFunction(exec, 0, propertyName, objectProtoFuncToString);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/kjs_binding.h b/WebCore/bindings/js/kjs_binding.h
new file mode 100644
index 0000000..fb95652
--- /dev/null
+++ b/WebCore/bindings/js/kjs_binding.h
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_binding_h
+#define kjs_binding_h
+
+#include <kjs/function.h>
+#include <kjs/interpreter.h>
+#include <kjs/lookup.h>
+#include <wtf/Noncopyable.h>
+
+#if PLATFORM(MAC)
+#include <JavaScriptCore/runtime.h>
+#endif
+
+namespace WebCore {
+
+ class AtomicString;
+ class Document;
+ class Event;
+ class Frame;
+ class KURL;
+ class Node;
+ class String;
+ class JSNode;
+
+ typedef int ExceptionCode;
+
+#if ENABLE(SVG)
+ class SVGElement;
+#endif
+
+ // Base class for all objects in this binding except Window.
+ class DOMObject : public KJS::JSObject {
+ protected:
+ explicit DOMObject(KJS::JSValue* prototype) // FIXME: this should take a JSObject once JSLocation has a real prototype
+ : JSObject(prototype)
+ {
+ // DOMObject destruction is not thread-safe because DOMObjects wrap
+ // unsafe WebCore DOM data structures.
+ KJS::Collector::collectOnMainThreadOnly(this);
+ }
+
+#ifndef NDEBUG
+ virtual ~DOMObject();
+#endif
+
+ private:
+ DOMObject();
+ };
+
+ class ScriptInterpreter : public KJS::Interpreter {
+ public:
+ static DOMObject* getDOMObject(void* objectHandle);
+ static void putDOMObject(void* objectHandle, DOMObject*);
+ static void forgetDOMObject(void* objectHandle);
+
+ static JSNode* getDOMNodeForDocument(Document*, Node*);
+ static void putDOMNodeForDocument(Document*, Node*, JSNode* nodeWrapper);
+ static void forgetDOMNodeForDocument(Document*, Node*);
+ static void forgetAllDOMNodesForDocument(Document*);
+ static void updateDOMNodeDocument(Node*, Document* oldDoc, Document* newDoc);
+ static void markDOMNodesForDocument(Document*);
+ };
+
+ // Retrieve from cache, or create, a JS wrapper for a DOM object.
+ template<class DOMObj, class JSDOMObj, class JSDOMObjPrototype> inline KJS::JSValue* cacheDOMObject(KJS::ExecState* exec, DOMObj* domObj)
+ {
+ if (!domObj)
+ return KJS::jsNull();
+ if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
+ return ret;
+ DOMObject* ret = new JSDOMObj(JSDOMObjPrototype::self(exec), domObj);
+ ScriptInterpreter::putDOMObject(domObj, ret);
+ return ret;
+ }
+
+#if ENABLE(SVG)
+ // Retrieve from cache, or create, a JS wrapper for an SVG DOM object.
+ template<class DOMObj, class JSDOMObj, class JSDOMObjPrototype> inline KJS::JSValue* cacheSVGDOMObject(KJS::ExecState* exec, DOMObj* domObj, SVGElement* context)
+ {
+ if (!domObj)
+ return KJS::jsNull();
+ if (DOMObject* ret = ScriptInterpreter::getDOMObject(domObj))
+ return ret;
+ DOMObject* ret = new JSDOMObj(JSDOMObjPrototype::self(exec), domObj, context);
+ ScriptInterpreter::putDOMObject(domObj, ret);
+ return ret;
+ }
+#endif
+
+ // Convert a DOM implementation exception code into a JavaScript exception in the execution state.
+ void setDOMException(KJS::ExecState*, ExceptionCode);
+
+ // Helper class to call setDOMException on exit without adding lots of separate calls to that function.
+ class DOMExceptionTranslator : Noncopyable {
+ public:
+ explicit DOMExceptionTranslator(KJS::ExecState* exec) : m_exec(exec), m_code(0) { }
+ ~DOMExceptionTranslator() { setDOMException(m_exec, m_code); }
+ operator ExceptionCode&() { return m_code; }
+ private:
+ KJS::ExecState* m_exec;
+ ExceptionCode m_code;
+ };
+
+ KJS::JSValue* jsStringOrNull(const String&); // null if the string is null
+ KJS::JSValue* jsStringOrNull(const KURL&); // null if the URL is null
+
+ KJS::JSValue* jsStringOrUndefined(const String&); // undefined if the string is null
+ KJS::JSValue* jsStringOrUndefined(const KURL&); // undefined if the URL is null
+
+ KJS::JSValue* jsStringOrFalse(const String&); // boolean false if the string is null
+ KJS::JSValue* jsStringOrFalse(const KURL&); // boolean false if the URL is null
+
+ // See JavaScriptCore for explanation: Should be used for any UString that is already owned by another
+ // object, to let the engine know that collecting the JSString wrapper is unlikely to save memory.
+ KJS::JSValue* jsOwnedStringOrNull(const KJS::UString&);
+
+ String valueToStringWithNullCheck(KJS::ExecState*, KJS::JSValue*); // null String if the value is null
+ String valueToStringWithUndefinedOrNullCheck(KJS::ExecState*, KJS::JSValue*); // null String if the value is null or undefined
+
+ template <typename T> inline KJS::JSValue* toJS(KJS::ExecState* exec, PassRefPtr<T> ptr) { return toJS(exec, ptr.get()); }
+
+ // Helpers for Window, History, and Location classes to implement cross-domain policy.
+ // Besides the cross-domain check, they need non-caching versions of staticFunctionGetter for
+ // because we do not want current property values involved at all.
+ bool allowsAccessFromFrame(KJS::ExecState*, Frame*);
+ bool allowsAccessFromFrame(KJS::ExecState*, Frame*, String& message);
+ void printErrorMessageForFrame(Frame*, const String& message);
+ KJS::JSValue* nonCachingStaticFunctionGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier& propertyName, const KJS::PropertySlot&);
+ KJS::JSValue* objectToStringFunctionGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier& propertyName, const KJS::PropertySlot&);
+
+} // namespace WebCore
+
+#endif // kjs_binding_h
diff --git a/WebCore/bindings/js/kjs_css.cpp b/WebCore/bindings/js/kjs_css.cpp
new file mode 100644
index 0000000..e2ab70d
--- /dev/null
+++ b/WebCore/bindings/js/kjs_css.cpp
@@ -0,0 +1,85 @@
+// -*- c-basic-offset: 2 -*-
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 James G. Speth (speth@end.com)
+ * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "kjs_css.h"
+
+#include "CSSPrimitiveValue.h"
+#include "JSCSSPrimitiveValue.h"
+#include "kjs_dom.h"
+
+#include "kjs_css.lut.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+const ClassInfo JSRGBColor::info = { "RGBColor", 0, &JSRGBColorTable };
+
+/*
+@begin JSRGBColorTable 3
+ red WebCore::JSRGBColor::Red DontDelete|ReadOnly
+ green WebCore::JSRGBColor::Green DontDelete|ReadOnly
+ blue WebCore::JSRGBColor::Blue DontDelete|ReadOnly
+@end
+*/
+
+JSRGBColor::JSRGBColor(JSObject* prototype, unsigned color)
+ : DOMObject(prototype)
+ , m_color(color)
+{
+}
+
+JSRGBColor::~JSRGBColor()
+{
+}
+
+bool JSRGBColor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return getStaticValueSlot<JSRGBColor, DOMObject>(exec, &JSRGBColorTable, this, propertyName, slot);
+}
+
+JSValue* JSRGBColor::getValueProperty(ExecState* exec, int token) const
+{
+ int color = m_color;
+ switch (token) {
+ case Red:
+ color >>= 8;
+ // fall through
+ case Green:
+ color >>= 8;
+ // fall through
+ case Blue:
+ return toJS(exec, new CSSPrimitiveValue(color & 0xFF, CSSPrimitiveValue::CSS_NUMBER));
+ default:
+ return 0;
+ }
+}
+
+JSValue* getJSRGBColor(ExecState* exec, unsigned color)
+{
+ // FIXME: implement equals for RGBColor since they're not refcounted objects
+ return new JSRGBColor(exec->lexicalGlobalObject()->objectPrototype(), color);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/kjs_css.h b/WebCore/bindings/js/kjs_css.h
new file mode 100644
index 0000000..5a42e0c
--- /dev/null
+++ b/WebCore/bindings/js/kjs_css.h
@@ -0,0 +1,55 @@
+ // -*- c-basic-offset: 2 -*-
+/*
+ * This file is part of the KDE libraries
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_css_h
+#define kjs_css_h
+
+#include "Color.h"
+#include "kjs_binding.h"
+
+namespace WebCore {
+
+ class JSRGBColor : public DOMObject {
+ public:
+ JSRGBColor(KJS::JSObject* prototype, unsigned color);
+ ~JSRGBColor();
+
+ virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+ KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
+ // no put - all read-only
+
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+
+ enum { Red, Green, Blue };
+
+ unsigned impl() const { return m_color; }
+
+ private:
+ unsigned m_color;
+ };
+
+ KJS::JSValue* getJSRGBColor(KJS::ExecState*, unsigned color);
+
+} // namespace WebCore
+
+#endif // kjs_css_h
diff --git a/WebCore/bindings/js/kjs_dom.cpp b/WebCore/bindings/js/kjs_dom.cpp
new file mode 100644
index 0000000..e718d41
--- /dev/null
+++ b/WebCore/bindings/js/kjs_dom.cpp
@@ -0,0 +1,108 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "kjs_dom.h"
+
+#include "Document.h"
+#include "EventTarget.h"
+#include "Frame.h"
+#include "HTMLNames.h"
+#include "HTMLPlugInElement.h"
+#include "JSAttr.h"
+#include "JSNode.h"
+#include "XMLHttpRequest.h"
+#include "kjs_events.h"
+#include "kjs_window.h"
+
+#if ENABLE(SVG)
+#include "JSSVGElementInstance.h"
+#endif
+
+#if USE(JAVASCRIPTCORE_BINDINGS)
+#include <bindings/runtime_object.h>
+#endif
+
+namespace WebCore {
+
+using namespace KJS;
+using namespace HTMLNames;
+
+Attr* toAttr(JSValue* val, bool& ok)
+{
+ if (!val || !val->isObject(&JSAttr::info)) {
+ ok = false;
+ return 0;
+ }
+
+ ok = true;
+ return static_cast<Attr*>(static_cast<JSNode*>(val)->impl());
+}
+
+bool checkNodeSecurity(ExecState* exec, Node* node)
+{
+ return node && allowsAccessFromFrame(exec, node->document()->frame());
+}
+
+JSValue* toJS(ExecState* exec, EventTarget* target)
+{
+ if (!target)
+ return jsNull();
+
+#if ENABLE(SVG)
+ // SVGElementInstance supports both toSVGElementInstance and toNode since so much mouse handling code depends on toNode returning a valid node.
+ SVGElementInstance* instance = target->toSVGElementInstance();
+ if (instance)
+ return toJS(exec, instance);
+#endif
+
+ Node* node = target->toNode();
+ if (node)
+ return toJS(exec, node);
+
+ if (XMLHttpRequest* xhr = target->toXMLHttpRequest())
+ // XMLHttpRequest is always created via JS, so we don't need to use cacheDOMObject() here.
+ return ScriptInterpreter::getDOMObject(xhr);
+
+ // There are two kinds of EventTargets: EventTargetNode and XMLHttpRequest.
+ // If SVG support is enabled, there is also SVGElementInstance.
+ ASSERT(0);
+ return jsNull();
+}
+
+JSObject* getRuntimeObject(ExecState* exec, Node* n)
+{
+ if (!n)
+ return 0;
+
+#if USE(JAVASCRIPTCORE_BINDINGS)
+ if (n->hasTagName(objectTag) || n->hasTagName(embedTag) || n->hasTagName(appletTag)) {
+ HTMLPlugInElement* plugInElement = static_cast<HTMLPlugInElement*>(n);
+ if (plugInElement->getInstance() && plugInElement->getInstance()->rootObject())
+ // The instance is owned by the PlugIn element.
+ return KJS::Bindings::Instance::createRuntimeObject(plugInElement->getInstance());
+ }
+#endif
+
+ // If we don't have a runtime object return 0.
+ return 0;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/kjs_dom.h b/WebCore/bindings/js/kjs_dom.h
new file mode 100644
index 0000000..6e0f136
--- /dev/null
+++ b/WebCore/bindings/js/kjs_dom.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_dom_h
+#define kjs_dom_h
+
+#include "JSNode.h"
+#include "Node.h"
+#include "kjs_binding.h"
+
+namespace WebCore {
+
+ class Attr;
+ class EventTarget;
+
+ Attr* toAttr(KJS::JSValue*, bool& ok);
+
+ bool checkNodeSecurity(KJS::ExecState*, Node*);
+ KJS::JSObject* getRuntimeObject(KJS::ExecState*, Node*);
+ KJS::JSValue* toJS(KJS::ExecState*, EventTarget*);
+ KJS::JSObject* getNodeConstructor(KJS::ExecState*);
+
+} // namespace WebCore
+
+#endif // kjs_dom_h
diff --git a/WebCore/bindings/js/kjs_events.cpp b/WebCore/bindings/js/kjs_events.cpp
new file mode 100644
index 0000000..f289209
--- /dev/null
+++ b/WebCore/bindings/js/kjs_events.cpp
@@ -0,0 +1,518 @@
+/*
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007 Apple Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "kjs_events.h"
+
+#include "CString.h"
+#include "Chrome.h"
+#include "Clipboard.h"
+#include "ClipboardEvent.h"
+#include "DOMWindow.h"
+#include "Document.h"
+#include "Event.h"
+#include "EventNames.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "HTMLImageElement.h"
+#include "HTMLNames.h"
+#include "JSEvent.h"
+#include "JSEventTargetNode.h"
+#include "Page.h"
+#include "kjs_proxy.h"
+#include "kjs_window.h"
+#include <kjs/array_object.h>
+#include <kjs/function_object.h>
+
+#include "kjs_events.lut.h"
+
+namespace WebCore {
+
+using namespace KJS;
+using namespace EventNames;
+using namespace HTMLNames;
+
+JSAbstractEventListener::JSAbstractEventListener(bool html)
+ : m_html(html)
+{
+}
+
+void JSAbstractEventListener::handleEvent(Event* ele, bool isWindowEvent)
+{
+#ifdef KJS_DEBUGGER
+ if (KJSDebugWin::instance() && KJSDebugWin::instance()->inSession())
+ return;
+#endif
+
+ Event* event = ele;
+
+ JSObject* listener = listenerObj();
+ if (!listener)
+ return;
+
+ KJS::Window* window = windowObj();
+ // Null check as clearWindowObj() can clear this and we still get called back by
+ // xmlhttprequest objects. See http://bugs.webkit.org/show_bug.cgi?id=13275
+ if (!window)
+ return;
+ Frame *frame = window->impl()->frame();
+ if (!frame)
+ return;
+ if (!frame->scriptProxy()->isEnabled())
+ return;
+
+ JSLock lock;
+
+ JSGlobalObject* globalObject = frame->scriptProxy()->globalObject();
+ ExecState* exec = globalObject->globalExec();
+
+ JSValue* handleEventFuncValue = listener->get(exec, "handleEvent");
+ JSObject* handleEventFunc = 0;
+ if (handleEventFuncValue->isObject()) {
+ handleEventFunc = static_cast<JSObject*>(handleEventFuncValue);
+ if (!handleEventFunc->implementsCall())
+ handleEventFunc = 0;
+ }
+
+ if (handleEventFunc || listener->implementsCall()) {
+ ref();
+
+ List args;
+ args.append(toJS(exec, event));
+
+ window->setCurrentEvent(event);
+
+ JSValue* retval;
+ if (handleEventFunc) {
+ globalObject->startTimeoutCheck();
+ retval = handleEventFunc->call(exec, listener, args);
+ } else {
+ JSObject* thisObj;
+ if (isWindowEvent)
+ thisObj = window;
+ else
+ thisObj = static_cast<JSObject*>(toJS(exec, event->currentTarget()));
+ globalObject->startTimeoutCheck();
+ retval = listener->call(exec, thisObj, args);
+ }
+ globalObject->stopTimeoutCheck();
+
+ window->setCurrentEvent(0);
+
+ if (exec->hadException()) {
+ JSObject* exception = exec->exception()->toObject(exec);
+ String message = exception->get(exec, exec->propertyNames().message)->toString(exec);
+ int lineNumber = exception->get(exec, "line")->toInt32(exec);
+ String sourceURL = exception->get(exec, "sourceURL")->toString(exec);
+ if (Interpreter::shouldPrintExceptions())
+ printf("(event handler):%s\n", message.utf8().data());
+ if (Page* page = frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, lineNumber, sourceURL);
+ exec->clearException();
+ } else {
+ if (!retval->isUndefinedOrNull() && event->storesResultAsString())
+ event->storeResult(retval->toString(exec));
+ if (m_html) {
+ bool retvalbool;
+ if (retval->getBoolean(retvalbool) && !retvalbool)
+ event->preventDefault();
+ }
+ }
+
+ Document::updateDocumentsRendering();
+ deref();
+ }
+}
+
+bool JSAbstractEventListener::isHTMLEventListener() const
+{
+ return m_html;
+}
+
+// -------------------------------------------------------------------------
+
+JSUnprotectedEventListener::JSUnprotectedEventListener(JSObject* listener, KJS::Window* win, bool html)
+ : JSAbstractEventListener(html)
+ , m_listener(listener)
+ , m_win(win)
+{
+ if (m_listener) {
+ KJS::Window::UnprotectedListenersMap& listeners = html
+ ? m_win->jsUnprotectedHTMLEventListeners() : m_win->jsUnprotectedEventListeners();
+ listeners.set(m_listener, this);
+ }
+}
+
+JSUnprotectedEventListener::~JSUnprotectedEventListener()
+{
+ if (m_listener && m_win) {
+ KJS::Window::UnprotectedListenersMap& listeners = isHTMLEventListener()
+ ? m_win->jsUnprotectedHTMLEventListeners() : m_win->jsUnprotectedEventListeners();
+ listeners.remove(m_listener);
+ }
+}
+
+JSObject* JSUnprotectedEventListener::listenerObj() const
+{
+ return m_listener;
+}
+
+KJS::Window* JSUnprotectedEventListener::windowObj() const
+{
+ return m_win;
+}
+
+void JSUnprotectedEventListener::clearWindowObj()
+{
+ m_win = 0;
+}
+
+void JSUnprotectedEventListener::mark()
+{
+ if (m_listener && !m_listener->marked())
+ m_listener->mark();
+}
+
+#ifndef NDEBUG
+#ifndef LOG_CHANNEL_PREFIX
+#define LOG_CHANNEL_PREFIX Log
+#endif
+WTFLogChannel LogWebCoreEventListenerLeaks = { 0x00000000, "", WTFLogChannelOn };
+
+struct EventListenerCounter {
+ static unsigned count;
+ ~EventListenerCounter()
+ {
+ if (count)
+ LOG(WebCoreEventListenerLeaks, "LEAK: %u EventListeners\n", count);
+ }
+};
+unsigned EventListenerCounter::count = 0;
+static EventListenerCounter eventListenerCounter;
+#endif
+
+// -------------------------------------------------------------------------
+
+JSEventListener::JSEventListener(JSObject* listener, KJS::Window* win, bool html)
+ : JSAbstractEventListener(html)
+ , m_listener(listener)
+ , m_win(win)
+{
+ if (m_listener) {
+ KJS::Window::ListenersMap& listeners = html
+ ? m_win->jsHTMLEventListeners() : m_win->jsEventListeners();
+ listeners.set(m_listener, this);
+ }
+#ifndef NDEBUG
+ ++eventListenerCounter.count;
+#endif
+}
+
+JSEventListener::~JSEventListener()
+{
+ if (m_listener && m_win) {
+ KJS::Window::ListenersMap& listeners = isHTMLEventListener()
+ ? m_win->jsHTMLEventListeners() : m_win->jsEventListeners();
+ listeners.remove(m_listener);
+ }
+#ifndef NDEBUG
+ --eventListenerCounter.count;
+#endif
+}
+
+JSObject* JSEventListener::listenerObj() const
+{
+ return m_listener;
+}
+
+KJS::Window* JSEventListener::windowObj() const
+{
+ return m_win;
+}
+
+void JSEventListener::clearWindowObj()
+{
+ m_win = 0;
+}
+
+// -------------------------------------------------------------------------
+
+JSLazyEventListener::JSLazyEventListener(const String& functionName, const String& code, KJS::Window* win, Node* node, int lineNumber)
+ : JSEventListener(0, win, true)
+ , m_functionName(functionName)
+ , m_code(code)
+ , m_parsed(false)
+ , m_lineNumber(lineNumber)
+ , m_originalNode(node)
+{
+ // We don't retain the original node because we assume it
+ // will stay alive as long as this handler object is around
+ // and we need to avoid a reference cycle. If JS transfers
+ // this handler to another node, parseCode will be called and
+ // then originalNode is no longer needed.
+}
+
+JSObject* JSLazyEventListener::listenerObj() const
+{
+ parseCode();
+ return m_listener;
+}
+
+JSValue* JSLazyEventListener::eventParameterName() const
+{
+ static ProtectedPtr<JSValue> eventString = jsString("event");
+ return eventString.get();
+}
+
+void JSLazyEventListener::parseCode() const
+{
+ if (m_parsed)
+ return;
+ m_parsed = true;
+
+ Frame* frame = windowObj()->impl()->frame();
+ if (frame && frame->scriptProxy()->isEnabled()) {
+ ExecState* exec = frame->scriptProxy()->globalObject()->globalExec();
+
+ JSLock lock;
+ JSObject* constr = frame->scriptProxy()->globalObject()->functionConstructor();
+ List args;
+
+ UString sourceURL(frame->loader()->url().string());
+ args.append(eventParameterName());
+ args.append(jsString(m_code));
+ m_listener = constr->construct(exec, args, m_functionName, sourceURL, m_lineNumber); // FIXME: is globalExec ok ?
+
+ FunctionImp* listenerAsFunction = static_cast<FunctionImp*>(m_listener.get());
+
+ if (exec->hadException()) {
+ exec->clearException();
+
+ // failed to parse, so let's just make this listener a no-op
+ m_listener = 0;
+ } else if (m_originalNode) {
+ // Add the event's home element to the scope
+ // (and the document, and the form - see JSHTMLElement::eventHandlerScope)
+ ScopeChain scope = listenerAsFunction->scope();
+
+ JSValue* thisObj = toJS(exec, m_originalNode);
+ if (thisObj->isObject()) {
+ static_cast<JSEventTargetNode*>(thisObj)->pushEventHandlerScope(exec, scope);
+ listenerAsFunction->setScope(scope);
+ }
+ }
+ }
+
+ // no more need to keep the unparsed code around
+ m_functionName = String();
+ m_code = String();
+
+ if (m_listener) {
+ KJS::Window::ListenersMap& listeners = isHTMLEventListener()
+ ? windowObj()->jsHTMLEventListeners() : windowObj()->jsEventListeners();
+ listeners.set(m_listener, const_cast<JSLazyEventListener*>(this));
+ }
+}
+
+JSValue* getNodeEventListener(EventTargetNode* n, const AtomicString& eventType)
+{
+ if (JSAbstractEventListener* listener = static_cast<JSAbstractEventListener*>(n->getHTMLEventListener(eventType))) {
+ if (JSValue* obj = listener->listenerObj())
+ return obj;
+ }
+ return jsNull();
+}
+
+// -------------------------------------------------------------------------
+
+const ClassInfo JSClipboard::info = { "Clipboard", 0, &JSClipboardTable };
+
+/* Source for JSClipboardTable. Use "make hashtables" to regenerate.
+@begin JSClipboardTable 3
+ dropEffect WebCore::JSClipboard::DropEffect DontDelete
+ effectAllowed WebCore::JSClipboard::EffectAllowed DontDelete
+ types WebCore::JSClipboard::Types DontDelete|ReadOnly
+@end
+@begin JSClipboardPrototypeTable 4
+ clearData WebCore::jsClipboardPrototypeFunctionClearData DontDelete|Function 0
+ getData WebCore::jsClipboardPrototypeFunctionGetData DontDelete|Function 1
+ setData WebCore::jsClipboardPrototypeFunctionSetData DontDelete|Function 2
+ setDragImage WebCore::jsClipboardPrototypeFunctionSetDragImage DontDelete|Function 3
+@end
+*/
+
+KJS_DEFINE_PROTOTYPE(JSClipboardPrototype)
+KJS_IMPLEMENT_PROTOTYPE("Clipboard", JSClipboardPrototype)
+
+JSClipboard::JSClipboard(JSObject* prototype, Clipboard* clipboard)
+ : DOMObject(prototype)
+ , m_impl(clipboard)
+{
+}
+
+JSClipboard::~JSClipboard()
+{
+ ScriptInterpreter::forgetDOMObject(m_impl.get());
+}
+
+bool JSClipboard::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return getStaticValueSlot<JSClipboard, DOMObject>(exec, &JSClipboardTable, this, propertyName, slot);
+}
+
+JSValue* JSClipboard::getValueProperty(ExecState* exec, int token) const
+{
+ Clipboard* clipboard = impl();
+ switch (token) {
+ case DropEffect:
+ ASSERT(clipboard->isForDragging() || clipboard->dropEffect().isNull());
+ return jsStringOrUndefined(clipboard->dropEffect());
+ case EffectAllowed:
+ ASSERT(clipboard->isForDragging() || clipboard->effectAllowed().isNull());
+ return jsStringOrUndefined(clipboard->effectAllowed());
+ case Types:
+ {
+ HashSet<String> types = clipboard->types();
+ if (types.isEmpty())
+ return jsNull();
+ else {
+ List list;
+ HashSet<String>::const_iterator end = types.end();
+ for (HashSet<String>::const_iterator it = types.begin(); it != end; ++it)
+ list.append(jsString(UString(*it)));
+ return exec->lexicalGlobalObject()->arrayConstructor()->construct(exec, list);
+ }
+ }
+ default:
+ return 0;
+ }
+}
+
+void JSClipboard::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ lookupPut<JSClipboard, DOMObject>(exec, propertyName, value, &JSClipboardTable, this);
+}
+
+void JSClipboard::putValueProperty(ExecState* exec, int token, JSValue* value)
+{
+ Clipboard* clipboard = impl();
+ switch (token) {
+ case DropEffect:
+ // can never set this when not for dragging, thus getting always returns NULL string
+ if (clipboard->isForDragging())
+ clipboard->setDropEffect(value->toString(exec));
+ break;
+ case EffectAllowed:
+ // can never set this when not for dragging, thus getting always returns NULL string
+ if (clipboard->isForDragging())
+ clipboard->setEffectAllowed(value->toString(exec));
+ break;
+ }
+}
+
+JSValue* jsClipboardPrototypeFunctionClearData(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSClipboard::info))
+ return throwError(exec, TypeError);
+
+ Clipboard* clipboard = static_cast<JSClipboard*>(thisObj)->impl();
+
+ if (args.size() == 0) {
+ clipboard->clearAllData();
+ return jsUndefined();
+ } else if (args.size() == 1) {
+ clipboard->clearData(args[0]->toString(exec));
+ return jsUndefined();
+ } else
+ return throwError(exec, SyntaxError, "clearData: Invalid number of arguments");
+}
+
+JSValue* jsClipboardPrototypeFunctionGetData(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSClipboard::info))
+ return throwError(exec, TypeError);
+
+ Clipboard* clipboard = static_cast<JSClipboard*>(thisObj)->impl();
+
+ if (args.size() == 1) {
+ bool success;
+ String result = clipboard->getData(args[0]->toString(exec), success);
+ if (success)
+ return jsString(result);
+ return jsUndefined();
+ } else
+ return throwError(exec, SyntaxError, "getData: Invalid number of arguments");
+}
+
+JSValue* jsClipboardPrototypeFunctionSetData(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSClipboard::info))
+ return throwError(exec, TypeError);
+
+ Clipboard* clipboard = static_cast<JSClipboard*>(thisObj)->impl();
+
+ if (args.size() == 2)
+ return jsBoolean(clipboard->setData(args[0]->toString(exec), args[1]->toString(exec)));
+ return throwError(exec, SyntaxError, "setData: Invalid number of arguments");
+}
+
+JSValue* jsClipboardPrototypeFunctionSetDragImage(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&JSClipboard::info))
+ return throwError(exec, TypeError);
+
+ Clipboard* clipboard = static_cast<JSClipboard*>(thisObj)->impl();
+
+ if (!clipboard->isForDragging())
+ return jsUndefined();
+
+ if (args.size() != 3)
+ return throwError(exec, SyntaxError, "setDragImage: Invalid number of arguments");
+
+ int x = args[1]->toInt32(exec);
+ int y = args[2]->toInt32(exec);
+
+ // See if they passed us a node
+ Node* node = toNode(args[0]);
+ if (!node)
+ return throwError(exec, TypeError);
+
+ if (!node->isElementNode())
+ return throwError(exec, SyntaxError, "setDragImageFromElement: Invalid first argument");
+
+ if (static_cast<Element*>(node)->hasLocalName(imgTag) &&
+ !node->inDocument())
+ clipboard->setDragImage(static_cast<HTMLImageElement*>(node)->cachedImage(), IntPoint(x, y));
+ else
+ clipboard->setDragImageElement(node, IntPoint(x, y));
+
+ return jsUndefined();
+}
+
+JSValue* toJS(ExecState* exec, Clipboard* obj)
+{
+ return cacheDOMObject<Clipboard, JSClipboard, JSClipboardPrototype>(exec, obj);
+}
+
+Clipboard* toClipboard(JSValue* val)
+{
+ return val->isObject(&JSClipboard::info) ? static_cast<JSClipboard*>(val)->impl() : 0;
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/kjs_events.h b/WebCore/bindings/js/kjs_events.h
new file mode 100644
index 0000000..b488cc4
--- /dev/null
+++ b/WebCore/bindings/js/kjs_events.h
@@ -0,0 +1,132 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2003 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_events_h
+#define kjs_events_h
+
+#include "EventListener.h"
+#include "PlatformString.h"
+#include "kjs_dom.h"
+#include "kjs_html.h"
+#include <kjs/protect.h>
+
+namespace KJS {
+ class Window;
+}
+
+namespace WebCore {
+
+ class Clipboard;
+ class Event;
+
+ class JSAbstractEventListener : public EventListener {
+ public:
+ JSAbstractEventListener(bool html = false);
+
+ virtual void handleEvent(Event*, bool isWindowEvent);
+ virtual bool isHTMLEventListener() const;
+ virtual KJS::JSObject* listenerObj() const = 0;
+ virtual KJS::Window* windowObj() const = 0;
+
+ private:
+ bool m_html;
+ };
+
+ class JSUnprotectedEventListener : public JSAbstractEventListener {
+ public:
+ JSUnprotectedEventListener(KJS::JSObject* listener, KJS::Window*, bool html = false);
+ virtual ~JSUnprotectedEventListener();
+
+ virtual KJS::JSObject* listenerObj() const;
+ virtual KJS::Window* windowObj() const;
+ void clearWindowObj();
+ void mark();
+ private:
+ KJS::JSObject* m_listener;
+ KJS::Window* m_win;
+ };
+
+ class JSEventListener : public JSAbstractEventListener {
+ public:
+ JSEventListener(KJS::JSObject* listener, KJS::Window*, bool html = false);
+ virtual ~JSEventListener();
+
+ virtual KJS::JSObject* listenerObj() const;
+ virtual KJS::Window* windowObj() const;
+ void clearWindowObj();
+
+ protected:
+ mutable KJS::ProtectedPtr<KJS::JSObject> m_listener;
+
+ private:
+ KJS::ProtectedPtr<KJS::Window> m_win;
+ };
+
+ class JSLazyEventListener : public JSEventListener {
+ public:
+ JSLazyEventListener(const String& functionName, const String& code, KJS::Window*, Node*, int lineNumber = 0);
+ virtual KJS::JSObject* listenerObj() const;
+
+ private:
+ virtual KJS::JSValue* eventParameterName() const;
+ void parseCode() const;
+
+ mutable String m_functionName;
+ mutable String m_code;
+ mutable bool m_parsed;
+ int m_lineNumber;
+ Node* m_originalNode;
+ };
+
+ KJS::JSValue* getNodeEventListener(Node*, const AtomicString& eventType);
+
+ class JSClipboard : public DOMObject {
+ public:
+ JSClipboard(KJS::JSObject* prototype, Clipboard*);
+ virtual ~JSClipboard();
+
+ virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+ KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
+ virtual void put(KJS::ExecState*, const KJS::Identifier&, KJS::JSValue*);
+ void putValueProperty(KJS::ExecState*, int token, KJS::JSValue*);
+
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+
+ enum { ClearData, GetData, SetData, Types, SetDragImage, DropEffect, EffectAllowed };
+
+ Clipboard* impl() const { return m_impl.get(); }
+
+ private:
+ RefPtr<Clipboard> m_impl;
+ };
+
+ KJS::JSValue* toJS(KJS::ExecState*, Clipboard*);
+ Clipboard* toClipboard(KJS::JSValue*);
+
+ // Functions
+ KJS::JSValue* jsClipboardPrototypeFunctionClearData(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsClipboardPrototypeFunctionGetData(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsClipboardPrototypeFunctionSetData(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+ KJS::JSValue* jsClipboardPrototypeFunctionSetDragImage(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
+} // namespace WebCore
+
+#endif // kjs_events_h
diff --git a/WebCore/bindings/js/kjs_html.cpp b/WebCore/bindings/js/kjs_html.cpp
new file mode 100644
index 0000000..8f2c7c4
--- /dev/null
+++ b/WebCore/bindings/js/kjs_html.cpp
@@ -0,0 +1,142 @@
+// -*- c-basic-offset: 4 -*-
+/*
+ * This file is part of the KDE libraries
+ * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "kjs_html.h"
+
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "JSHTMLElement.h"
+#include "HTMLDocument.h"
+#include "HTMLImageElement.h"
+#include "kjs_proxy.h"
+
+namespace WebCore {
+
+using namespace KJS;
+
+ImageConstructorImp::ImageConstructorImp(ExecState* exec, Document* doc)
+ : DOMObject(exec->lexicalGlobalObject()->objectPrototype())
+ , m_doc(doc)
+{
+}
+
+JSObject* ImageConstructorImp::construct(ExecState* exec, const List& list)
+{
+ bool widthSet = false;
+ bool heightSet = false;
+ int width = 0;
+ int height = 0;
+
+ if (list.size() > 0) {
+ widthSet = true;
+ JSValue* w = list.at(0);
+ width = w->toInt32(exec);
+ }
+
+ if (list.size() > 1) {
+ heightSet = true;
+ JSValue* h = list.at(1);
+ height = h->toInt32(exec);
+ }
+
+ // Calling toJS on the document causes the JS document wrapper to be
+ // added to the window object. This is done to ensure that JSDocument::mark
+ // will be called (which will cause the image element to be marked if necessary).
+ // This is only a problem for elements created using the Image constructor since all
+ // other elements are created through the document, using document.createElement for example.
+ toJS(exec, m_doc.get());
+
+ HTMLImageElement* image = new HTMLImageElement(m_doc.get());
+ JSObject* result = static_cast<JSObject*>(toJS(exec, image));
+
+ if (widthSet)
+ image->setWidth(width);
+ if (heightSet)
+ image->setHeight(height);
+
+ return result;
+}
+
+// -------------------------------------------------------------------------
+
+// Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement.
+
+JSValue* runtimeObjectGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(slot.slotBase());
+ HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl());
+ return getRuntimeObject(exec, element);
+}
+
+JSValue* runtimeObjectPropertyGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ JSHTMLElement* thisObj = static_cast<JSHTMLElement*>(slot.slotBase());
+ HTMLElement* element = static_cast<HTMLElement*>(thisObj->impl());
+ JSObject* runtimeObject = getRuntimeObject(exec, element);
+ if (!runtimeObject)
+ return jsUndefined();
+ return runtimeObject->get(exec, propertyName);
+}
+
+bool runtimeObjectCustomGetOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot, JSHTMLElement* originalObj, HTMLElement* thisImp)
+{
+ JSObject* runtimeObject = getRuntimeObject(exec, thisImp);
+ if (!runtimeObject)
+ return false;
+ if (!runtimeObject->hasProperty(exec, propertyName))
+ return false;
+ slot.setCustom(originalObj, runtimeObjectPropertyGetter);
+ return true;
+}
+
+bool runtimeObjectCustomPut(ExecState* exec, const Identifier& propertyName, JSValue* value, HTMLElement* thisImp)
+{
+ JSObject* runtimeObject = getRuntimeObject(exec, thisImp);
+ if (!runtimeObject)
+ return 0;
+ if (!runtimeObject->hasProperty(exec, propertyName))
+ return false;
+ runtimeObject->put(exec, propertyName, value);
+ return true;
+}
+
+bool runtimeObjectImplementsCall(HTMLElement* thisImp)
+{
+ Frame* frame = thisImp->document()->frame();
+ if (!frame)
+ return false;
+ ExecState* exec = frame->scriptProxy()->globalObject()->globalExec();
+ JSObject* runtimeObject = getRuntimeObject(exec, thisImp);
+ if (!runtimeObject)
+ return false;
+ return runtimeObject->implementsCall();
+}
+
+JSValue* runtimeObjectCallAsFunction(ExecState* exec, JSObject* thisObj, const List& args, HTMLElement* thisImp)
+{
+ JSObject* runtimeObject = getRuntimeObject(exec, thisImp);
+ if (!runtimeObject)
+ return jsUndefined();
+ return runtimeObject->call(exec, thisObj, args);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/kjs_html.h b/WebCore/bindings/js/kjs_html.h
new file mode 100644
index 0000000..4b519d2
--- /dev/null
+++ b/WebCore/bindings/js/kjs_html.h
@@ -0,0 +1,57 @@
+// -*- c-basic-offset: 2 -*-
+/*
+ * Copyright (C) 1999 Harri Porten (porten@kde.org)
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_html_h
+#define kjs_html_h
+
+#include "kjs_dom.h"
+
+namespace WebCore {
+
+ class Document;
+ class HTMLCollection;
+ class HTMLElement;
+ class JSHTMLElement;
+
+ class ImageConstructorImp : public DOMObject {
+ public:
+ ImageConstructorImp(KJS::ExecState*, Document*);
+
+ virtual bool implementsConstruct() const { return true; }
+ virtual KJS::JSObject* construct(KJS::ExecState*, const KJS::List&);
+
+ private:
+ RefPtr<Document> m_doc;
+ };
+
+
+ // Runtime object support code for JSHTMLAppletElement, JSHTMLEmbedElement and JSHTMLObjectElement.
+ // FIXME: Move these to a more appropriate place.
+
+ KJS::JSValue* runtimeObjectGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
+ KJS::JSValue* runtimeObjectPropertyGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);
+ bool runtimeObjectCustomGetOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&, JSHTMLElement*, HTMLElement*);
+ bool runtimeObjectCustomPut(KJS::ExecState*, const KJS::Identifier&, KJS::JSValue*, HTMLElement*);
+ bool runtimeObjectImplementsCall(HTMLElement*);
+ KJS::JSValue* runtimeObjectCallAsFunction(KJS::ExecState*, KJS::JSObject*, const KJS::List&, HTMLElement*);
+
+} // namespace WebCore
+
+#endif // kjs_html_h
diff --git a/WebCore/bindings/js/kjs_navigator.cpp b/WebCore/bindings/js/kjs_navigator.cpp
new file mode 100644
index 0000000..6e9fbbd
--- /dev/null
+++ b/WebCore/bindings/js/kjs_navigator.cpp
@@ -0,0 +1,620 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (c) 2000 Daniel Molkentin (molkentin@kde.org)
+ * Copyright (c) 2000 Stefan Schimanski (schimmi@kde.org)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All Rights Reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "kjs_navigator.h"
+
+#include "AtomicString.h"
+#include "CookieJar.h"
+#include "DOMWindow.h"
+#include "Document.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "Language.h"
+#include "Page.h"
+#include "PluginInfoStore.h"
+#include "Settings.h"
+#include "kjs_window.h"
+#include <kjs/object_object.h>
+
+#ifndef WEBCORE_NAVIGATOR_PLATFORM
+#if PLATFORM(MAC) && PLATFORM(PPC)
+#define WEBCORE_NAVIGATOR_PLATFORM "MacPPC"
+#elif PLATFORM(MAC) && PLATFORM(X86)
+#define WEBCORE_NAVIGATOR_PLATFORM "MacIntel"
+#elif PLATFORM(WIN_OS)
+#define WEBCORE_NAVIGATOR_PLATFORM "Win32"
+#else
+#define WEBCORE_NAVIGATOR_PLATFORM ""
+#endif
+#endif // ifndef WEBCORE_NAVIGATOR_PLATFORM
+
+#ifndef WEBCORE_NAVIGATOR_PRODUCT
+#define WEBCORE_NAVIGATOR_PRODUCT "Gecko"
+#endif // ifndef WEBCORE_NAVIGATOR_PRODUCT
+
+#ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
+#define WEBCORE_NAVIGATOR_PRODUCT_SUB "20030107"
+#endif // ifndef WEBCORE_NAVIGATOR_PRODUCT_SUB
+
+#ifndef WEBCORE_NAVIGATOR_VENDOR
+#define WEBCORE_NAVIGATOR_VENDOR "Apple Computer, Inc."
+#endif // ifndef WEBCORE_NAVIGATOR_VENDOR
+
+#ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
+#define WEBCORE_NAVIGATOR_VENDOR_SUB ""
+#endif // ifndef WEBCORE_NAVIGATOR_VENDOR_SUB
+
+using namespace KJS;
+using namespace WebCore;
+
+namespace WebCore {
+
+ class PluginBase : public DOMObject {
+ public:
+ PluginBase(ExecState*);
+ virtual ~PluginBase();
+
+ static void refresh(bool reload);
+
+ protected:
+ static void cachePluginDataIfNecessary();
+ static Vector<PluginInfo*>* plugins;
+ static Vector<MimeClassInfo*>* mimes;
+
+ private:
+ static int m_plugInCacheRefCount;
+ };
+
+
+ class Plugins : public PluginBase {
+ public:
+ Plugins(ExecState* exec) : PluginBase(exec) { }
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ JSValue* getValueProperty(ExecState*, int token) const;
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+ enum { Length };
+ private:
+ static JSValue* indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+ static JSValue* nameGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+ };
+
+ JSValue* pluginsFunctionRefresh(ExecState*, JSObject*, const List&);
+
+ class MimeTypes : public PluginBase {
+ public:
+ MimeTypes(ExecState* exec) : PluginBase(exec) { };
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ JSValue* getValueProperty(ExecState*, int token) const;
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+ enum { Length };
+ private:
+ static JSValue* indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+ static JSValue* nameGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+ };
+
+ class Plugin : public PluginBase {
+ public:
+ Plugin(ExecState* exec, PluginInfo* info) : PluginBase(exec), m_info(info) { }
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ JSValue* getValueProperty(ExecState*, int token) const;
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+ enum { Name, Filename, Description, Length };
+ private:
+ static JSValue* indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+ static JSValue* nameGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+
+ PluginInfo* m_info;
+ };
+
+ class MimeType : public PluginBase {
+ public:
+ MimeType(ExecState* exec, MimeClassInfo* info) : PluginBase(exec), m_info(info) { }
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ JSValue* getValueProperty(ExecState*, int token) const;
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+ enum { Type, Suffixes, Description, EnabledPlugin };
+ private:
+ MimeClassInfo* m_info;
+ };
+
+}
+
+#include "kjs_navigator.lut.h"
+
+namespace WebCore {
+
+const ClassInfo Plugins::info = { "PluginArray", 0, &PluginsTable };
+const ClassInfo MimeTypes::info = { "MimeTypeArray", 0, &MimeTypesTable };
+const ClassInfo Plugin::info = { "Plugin", 0, &PluginTable };
+const ClassInfo MimeType::info = { "MimeType", 0, &MimeTypeTable };
+
+Vector<PluginInfo*>* PluginBase::plugins = 0;
+Vector<MimeClassInfo*>* PluginBase::mimes = 0;
+int PluginBase::m_plugInCacheRefCount = 0;
+
+const ClassInfo Navigator::info = { "Navigator", 0, &NavigatorTable };
+/*
+@begin NavigatorTable 13
+ appCodeName Navigator::AppCodeName DontDelete|ReadOnly
+ appName Navigator::AppName DontDelete|ReadOnly
+ appVersion Navigator::AppVersion DontDelete|ReadOnly
+ language Navigator::Language DontDelete|ReadOnly
+ userAgent Navigator::UserAgent DontDelete|ReadOnly
+ platform Navigator::Platform DontDelete|ReadOnly
+ plugins Navigator::_Plugins DontDelete|ReadOnly
+ mimeTypes Navigator::_MimeTypes DontDelete|ReadOnly
+ product Navigator::Product DontDelete|ReadOnly
+ productSub Navigator::ProductSub DontDelete|ReadOnly
+ vendor Navigator::Vendor DontDelete|ReadOnly
+ vendorSub Navigator::VendorSub DontDelete|ReadOnly
+ cookieEnabled Navigator::CookieEnabled DontDelete|ReadOnly
+ javaEnabled navigatorProtoFuncJavaEnabled DontDelete|Function 0
+@end
+*/
+
+Navigator::Navigator(JSObject* prototype, Frame* frame)
+ : DOMObject(prototype)
+ , m_frame(frame)
+{
+}
+
+bool Navigator::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return getStaticPropertySlot<Navigator, JSObject>(exec, &NavigatorTable, this, propertyName, slot);
+}
+
+static bool needsYouTubeQuirk(ExecState*, Frame*);
+
+#if !PLATFORM(WIN)
+
+static inline bool needsYouTubeQuirk(ExecState*, Frame*)
+{
+ return false;
+}
+
+#else
+
+static bool needsYouTubeQuirk(ExecState* exec, Frame* frame)
+{
+ // This quirk works around a mistaken check in an ad at youtube.com.
+ // There's a function called isSafari that returns false if the function
+ // called isWindows returns true; thus the site malfunctions with Windows Safari.
+
+ // Do the quirk only if the function's name is "isWindows".
+ FunctionImp* function = exec->function();
+ if (!function)
+ return false;
+ static const Identifier& isWindowsFunctionName = *new Identifier("isWindows");
+ if (function->functionName() != isWindowsFunctionName)
+ return false;
+
+ // Do the quirk only if the function is called by an "isSafari" function.
+ // However, that function is not itself named -- it is stored in the isSafari
+ // property, though, so that's how we recognize it.
+ ExecState* callingExec = exec->callingExecState();
+ if (!callingExec)
+ return false;
+ FunctionImp* callingFunction = callingExec->function();
+ if (!callingFunction)
+ return false;
+ JSObject* thisObject = callingExec->thisValue();
+ if (!thisObject)
+ return false;
+ static const Identifier& isSafariFunctionName = *new Identifier("isSafari");
+ JSValue* isSafariFunction = thisObject->getDirect(isSafariFunctionName);
+ if (isSafariFunction != callingFunction)
+ return false;
+
+ Document* document = frame->document();
+ // FIXME: The document is never null, so we should remove this check along with the
+ // other similar ones in this file when we are absolutely sure it's safe.
+ if (!document)
+ return false;
+
+ // Do the quirk only on the front page of the global version of YouTube.
+ const KURL& url = document->url();
+ if (url.host() != "youtube.com" && url.host() != "www.youtube.com")
+ return false;
+ if (url.path() != "/")
+ return false;
+
+ // As with other site-specific quirks, allow website developers to turn this off.
+ // In theory, this allows website developers to check if their fixes are effective.
+ Settings* settings = frame->settings();
+ if (!settings)
+ return false;
+ if (!settings->needsSiteSpecificQuirks())
+ return false;
+
+ return true;
+}
+
+#endif
+
+JSValue* Navigator::getValueProperty(ExecState* exec, int token) const
+{
+ switch (token) {
+ case AppCodeName:
+ return jsString("Mozilla");
+ case AppName:
+ return jsString("Netscape");
+ case AppVersion: {
+ if (needsYouTubeQuirk(exec, m_frame))
+ return jsString("");
+ // Version is everything in the user agent string past the "Mozilla/" prefix.
+ const String userAgent = m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->url() : KURL());
+ return jsString(userAgent.substring(userAgent.find('/') + 1));
+ }
+ case Product:
+ return jsString(WEBCORE_NAVIGATOR_PRODUCT);
+ case ProductSub:
+ return jsString(WEBCORE_NAVIGATOR_PRODUCT_SUB);
+ case Vendor:
+ return jsString(WEBCORE_NAVIGATOR_VENDOR);
+ case VendorSub:
+ return jsString(WEBCORE_NAVIGATOR_VENDOR_SUB);
+ case Language:
+ return jsString(defaultLanguage());
+ case UserAgent:
+ return jsString(m_frame->loader()->userAgent(m_frame->document() ? m_frame->document()->url() : KURL()));
+ case Platform:
+ return jsString(WEBCORE_NAVIGATOR_PLATFORM);
+ case _Plugins:
+ return new Plugins(exec);
+ case _MimeTypes:
+ return new MimeTypes(exec);
+ case CookieEnabled:
+ return jsBoolean(cookiesEnabled(m_frame->document()));
+ }
+ return 0;
+}
+
+/*******************************************************************/
+
+void PluginBase::cachePluginDataIfNecessary()
+{
+ if (!plugins) {
+ plugins = new Vector<PluginInfo*>;
+ mimes = new Vector<MimeClassInfo*>;
+
+ // read configuration
+ PluginInfoStore c;
+ unsigned pluginCount = c.pluginCount();
+ for (unsigned n = 0; n < pluginCount; n++) {
+ PluginInfo* plugin = c.createPluginInfoForPluginAtIndex(n);
+ if (!plugin)
+ continue;
+
+ plugins->append(plugin);
+ if (plugin->mimes.isEmpty())
+ continue;
+
+ Vector<MimeClassInfo*>::iterator end = plugin->mimes.end();
+ for (Vector<MimeClassInfo*>::iterator itr = plugin->mimes.begin(); itr != end; itr++)
+ mimes->append(*itr);
+ }
+ }
+}
+
+PluginBase::PluginBase(ExecState* exec)
+ : DOMObject(exec->lexicalGlobalObject()->objectPrototype())
+{
+ cachePluginDataIfNecessary();
+ m_plugInCacheRefCount++;
+}
+
+PluginBase::~PluginBase()
+{
+ m_plugInCacheRefCount--;
+ if (!m_plugInCacheRefCount) {
+ if (plugins) {
+ deleteAllValues(*plugins);
+ delete plugins;
+ plugins = 0;
+ }
+ if (mimes) {
+ deleteAllValues(*mimes);
+ delete mimes;
+ mimes = 0;
+ }
+ }
+}
+
+void PluginBase::refresh(bool reload)
+{
+ if (plugins) {
+ deleteAllValues(*plugins);
+ delete plugins;
+ plugins = 0;
+ }
+ if (mimes) {
+ deleteAllValues(*mimes);
+ delete mimes;
+ mimes = 0;
+ }
+
+ refreshPlugins(reload);
+ cachePluginDataIfNecessary();
+}
+
+
+/*******************************************************************/
+
+/*
+@begin PluginsTable 2
+ length Plugins::Length DontDelete|ReadOnly
+ refresh pluginsFunctionRefresh DontDelete|Function 0
+@end
+*/
+
+JSValue* Plugins::getValueProperty(ExecState* exec, int token) const
+{
+ ASSERT(token == Length);
+ return jsNumber(plugins->size());
+}
+
+JSValue* Plugins::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ return new Plugin(exec, plugins->at(slot.index()));
+}
+
+JSValue* Plugins::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ AtomicString atomicPropertyName = propertyName;
+ Vector<PluginInfo*>::iterator end = plugins->end();
+ for (Vector<PluginInfo*>::iterator itr = plugins->begin(); itr != end; itr++) {
+ PluginInfo* pl = *itr;
+ if (pl->name == atomicPropertyName)
+ return new Plugin(exec, pl);
+ }
+ return jsUndefined();
+}
+
+bool Plugins::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ const HashEntry* entry = Lookup::findEntry(&PluginsTable, propertyName);
+ if (entry) {
+ if (entry->attr & Function)
+ slot.setStaticEntry(this, entry, staticFunctionGetter);
+ else
+ slot.setStaticEntry(this, entry, staticValueGetter<Plugins>);
+ return true;
+ } else {
+ // plugins[#]
+ bool ok;
+ unsigned int i = propertyName.toUInt32(&ok);
+ if (ok && i < plugins->size()) {
+ slot.setCustomIndex(this, i, indexGetter);
+ return true;
+ }
+
+ // plugin[name]
+ AtomicString atomicPropertyName = propertyName;
+ Vector<PluginInfo*>::iterator end = plugins->end();
+ for (Vector<PluginInfo*>::iterator itr = plugins->begin(); itr != end; itr++) {
+ if ((*itr)->name == atomicPropertyName) {
+ slot.setCustom(this, nameGetter);
+ return true;
+ }
+ }
+ }
+
+ return PluginBase::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+/*******************************************************************/
+
+/*
+@begin MimeTypesTable 1
+ length MimeTypes::Length DontDelete|ReadOnly
+@end
+*/
+
+JSValue* MimeTypes::getValueProperty(ExecState* exec, int token) const
+{
+ ASSERT(token == Length);
+ return jsNumber(mimes->size());
+}
+
+JSValue* MimeTypes::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ return new MimeType(exec, mimes->at(slot.index()));
+}
+
+JSValue* MimeTypes::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ AtomicString atomicPropertyName = propertyName;
+ Vector<MimeClassInfo*>::iterator end = mimes->end();
+ for (Vector<MimeClassInfo*>::iterator itr = mimes->begin(); itr != end; itr++) {
+ MimeClassInfo* m = (*itr);
+ if (m->type == atomicPropertyName)
+ return new MimeType(exec, m);
+ }
+ return jsUndefined();
+}
+
+bool MimeTypes::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ const HashEntry* entry = Lookup::findEntry(&MimeTypesTable, propertyName);
+ if (entry) {
+ slot.setStaticEntry(this, entry, staticValueGetter<MimeTypes>);
+ return true;
+ } else {
+ // mimeTypes[#]
+ bool ok;
+ unsigned int i = propertyName.toUInt32(&ok);
+ if (ok && i < mimes->size()) {
+ slot.setCustomIndex(this, i, indexGetter);
+ return true;
+ }
+
+ // mimeTypes[name]
+ AtomicString atomicPropertyName = propertyName;
+ Vector<MimeClassInfo*>::iterator end = mimes->end();
+ for (Vector<MimeClassInfo*>::iterator itr = mimes->begin(); itr != end; itr++) {
+ if ((*itr)->type == atomicPropertyName) {
+ slot.setCustom(this, nameGetter);
+ return true;
+ }
+ }
+ }
+
+ return PluginBase::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+
+/************************************************************************/
+
+/*
+@begin PluginTable 4
+ name Plugin::Name DontDelete|ReadOnly
+ filename Plugin::Filename DontDelete|ReadOnly
+ description Plugin::Description DontDelete|ReadOnly
+ length Plugin::Length DontDelete|ReadOnly
+@end
+*/
+
+JSValue* Plugin::getValueProperty(ExecState* exec, int token) const
+{
+ switch (token) {
+ case Name:
+ return jsString(m_info->name);
+ case Filename:
+ return jsString(m_info->file);
+ case Description:
+ return jsString(m_info->desc);
+ case Length:
+ return jsNumber(m_info->mimes.size());
+ default:
+ ASSERT(0);
+ return jsUndefined();
+ }
+}
+
+JSValue* Plugin::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ Plugin* thisObj = static_cast<Plugin*>(slot.slotBase());
+ return new MimeType(exec, thisObj->m_info->mimes.at(slot.index()));
+}
+
+JSValue* Plugin::nameGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ Plugin* thisObj = static_cast<Plugin*>(slot.slotBase());
+ AtomicString atomicPropertyName = propertyName;
+ Vector<MimeClassInfo*>::iterator end = thisObj->m_info->mimes.end();
+ for (Vector<MimeClassInfo*>::iterator itr = thisObj->m_info->mimes.begin(); itr != end; itr++) {
+ MimeClassInfo* m = (*itr);
+ if (m->type == atomicPropertyName)
+ return new MimeType(exec, m);
+ }
+ return jsUndefined();
+}
+
+
+bool Plugin::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ const HashEntry* entry = Lookup::findEntry(&PluginTable, propertyName);
+ if (entry) {
+ slot.setStaticEntry(this, entry, staticValueGetter<Plugin>);
+ return true;
+ } else {
+ // plugin[#]
+ bool ok;
+ unsigned int i = propertyName.toUInt32(&ok);
+ if (ok && i < m_info->mimes.size()) {
+ slot.setCustomIndex(this, i, indexGetter);
+ return true;
+ }
+
+ // plugin["name"]
+ AtomicString atomicPropertyName = propertyName;
+ Vector<MimeClassInfo*>::iterator end = m_info->mimes.end();
+ for (Vector<MimeClassInfo*>::iterator itr = m_info->mimes.begin(); itr != end; itr++) {
+ if ((*itr)->type == atomicPropertyName) {
+ slot.setCustom(this, nameGetter);
+ return true;
+ }
+ }
+ }
+
+ return PluginBase::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+/*****************************************************************************/
+
+/*
+@begin MimeTypeTable 4
+ type MimeType::Type DontDelete|ReadOnly
+ suffixes MimeType::Suffixes DontDelete|ReadOnly
+ description MimeType::Description DontDelete|ReadOnly
+ enabledPlugin MimeType::EnabledPlugin DontDelete|ReadOnly
+@end
+*/
+
+JSValue* MimeType::getValueProperty(ExecState* exec, int token) const
+{
+ switch (token) {
+ case Type:
+ return jsString(m_info->type);
+ case Suffixes:
+ return jsString(m_info->suffixes);
+ case Description:
+ return jsString(m_info->desc);
+ case EnabledPlugin: {
+ Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+ ASSERT(frame);
+ Settings* settings = frame->settings();
+ if (settings && settings->arePluginsEnabled())
+ return new Plugin(exec, m_info->plugin);
+ else
+ return jsUndefined();
+ }
+ default:
+ return jsUndefined();
+ }
+}
+
+bool MimeType::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return getStaticValueSlot<MimeType, PluginBase>(exec, &MimeTypeTable, this, propertyName, slot);
+}
+
+JSValue* pluginsFunctionRefresh(ExecState* exec, JSObject*, const List& args)
+{
+ PluginBase::refresh(args[0]->toBoolean(exec));
+ return jsUndefined();
+}
+
+JSValue* navigatorProtoFuncJavaEnabled(ExecState* exec, JSObject* thisObj, const List&)
+{
+ if (!thisObj->inherits(&Navigator::info))
+ return throwError(exec, TypeError);
+ Navigator* nav = static_cast<Navigator*>(thisObj);
+ Settings* settings = nav->frame() ? nav->frame()->settings() : 0;
+ return jsBoolean(settings && settings->isJavaEnabled());
+}
+
+} // namespace
diff --git a/WebCore/bindings/js/kjs_navigator.h b/WebCore/bindings/js/kjs_navigator.h
new file mode 100644
index 0000000..e16f7ea
--- /dev/null
+++ b/WebCore/bindings/js/kjs_navigator.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_navigator_h
+#define kjs_navigator_h
+
+#include "kjs_binding.h"
+
+namespace WebCore {
+
+ class Frame;
+
+ class Navigator : public DOMObject {
+ public:
+ Navigator(KJS::JSObject* prototype, Frame*);
+
+ virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);
+ KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;
+ virtual const KJS::ClassInfo* classInfo() const { return &info; }
+ static const KJS::ClassInfo info;
+
+ enum { AppCodeName, AppName, AppVersion, Language, UserAgent, Platform,
+ _Plugins, _MimeTypes, Product, ProductSub, Vendor, VendorSub, CookieEnabled };
+
+ Frame* frame() const { return m_frame; }
+
+ private:
+ Frame* m_frame;
+ };
+
+ KJS::JSValue* navigatorProtoFuncJavaEnabled(KJS::ExecState*, KJS::JSObject*, const KJS::List&);
+
+} // namespace
+
+#endif
diff --git a/WebCore/bindings/js/kjs_proxy.cpp b/WebCore/bindings/js/kjs_proxy.cpp
new file mode 100644
index 0000000..7b29b4b
--- /dev/null
+++ b/WebCore/bindings/js/kjs_proxy.cpp
@@ -0,0 +1,196 @@
+/*
+ * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "config.h"
+#include "kjs_proxy.h"
+
+#include "Chrome.h"
+#include "Document.h"
+#include "Event.h"
+#include "EventNames.h"
+#include "Frame.h"
+#include "FrameLoader.h"
+#include "GCController.h"
+#include "JSDocument.h"
+#include "JSDOMWindow.h"
+#include "Page.h"
+#include "Settings.h"
+#include "kjs_events.h"
+#include "kjs_window.h"
+
+#if ENABLE(SVG)
+#include "JSSVGLazyEventListener.h"
+#endif
+
+using namespace KJS;
+using namespace WebCore::EventNames;
+
+namespace WebCore {
+
+KJSProxy::KJSProxy(Frame* frame)
+ : m_frame(frame)
+ , m_handlerLineno(0)
+ , m_processingTimerCallback(0)
+ , m_processingInlineCode(0)
+{
+}
+
+KJSProxy::~KJSProxy()
+{
+ if (m_globalObject) {
+ m_globalObject = 0;
+
+ // It's likely that releasing the global object has created a lot of garbage.
+ gcController().garbageCollectSoon();
+ }
+}
+
+JSValue* KJSProxy::evaluate(const String& filename, int baseLine, const String& str)
+{
+ // evaluate code. Returns the JS return value or 0
+ // if there was none, an error occured or the type couldn't be converted.
+
+ initScriptIfNeeded();
+ // inlineCode is true for <a href="javascript:doSomething()">
+ // and false for <script>doSomething()</script>. Check if it has the
+ // expected value in all cases.
+ // See smart window.open policy for where this is used.
+ ExecState* exec = m_globalObject->globalExec();
+ m_processingInlineCode = filename.isNull();
+
+ JSLock lock;
+
+ // Evaluating the JavaScript could cause the frame to be deallocated
+ // so we start the keep alive timer here.
+ m_frame->keepAlive();
+
+ JSValue* thisNode = Window::retrieve(m_frame);
+
+ m_globalObject->startTimeoutCheck();
+ Completion comp = Interpreter::evaluate(exec, filename, baseLine, reinterpret_cast<const KJS::UChar*>(str.characters()), str.length(), thisNode);
+ m_globalObject->stopTimeoutCheck();
+
+ if (comp.complType() == Normal || comp.complType() == ReturnValue) {
+ m_processingInlineCode = false;
+ return comp.value();
+ }
+
+ if (comp.complType() == Throw) {
+ UString errorMessage = comp.value()->toString(exec);
+ int lineNumber = comp.value()->toObject(exec)->get(exec, "line")->toInt32(exec);
+ UString sourceURL = comp.value()->toObject(exec)->get(exec, "sourceURL")->toString(exec);
+ if (Page* page = m_frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, errorMessage, lineNumber, sourceURL);
+ }
+
+ m_processingInlineCode = false;
+ return 0;
+}
+
+void KJSProxy::clear()
+{
+ // clear resources allocated by the global object, and make it ready to be used by another page
+ // We have to keep it, so that the Window object for the frame remains the same.
+ // (we used to delete and re-create it, previously)
+ if (m_globalObject)
+ m_globalObject->clear();
+}
+
+EventListener* KJSProxy::createHTMLEventHandler(const String& functionName, const String& code, Node* node)
+{
+ initScriptIfNeeded();
+ JSLock lock;
+ return new JSLazyEventListener(functionName, code, Window::retrieveWindow(m_frame), node, m_handlerLineno);
+}
+
+#if ENABLE(SVG)
+EventListener* KJSProxy::createSVGEventHandler(const String& functionName, const String& code, Node* node)
+{
+ initScriptIfNeeded();
+ JSLock lock;
+ return new JSSVGLazyEventListener(functionName, code, Window::retrieveWindow(m_frame), node, m_handlerLineno);
+}
+#endif
+
+void KJSProxy::finishedWithEvent(Event* event)
+{
+ // This is called when the DOM implementation has finished with a particular event. This
+ // is the case in sitations where an event has been created just for temporary usage,
+ // e.g. an image load or mouse move. Once the event has been dispatched, it is forgotten
+ // by the DOM implementation and so does not need to be cached still by the interpreter
+ ScriptInterpreter::forgetDOMObject(event);
+}
+
+void KJSProxy::initScript()
+{
+ if (m_globalObject)
+ return;
+
+ JSLock lock;
+
+ m_globalObject = new JSDOMWindow(m_frame->domWindow());
+
+ m_frame->loader()->dispatchWindowObjectAvailable();
+}
+
+void KJSProxy::clearDocumentWrapper()
+{
+ if (!m_globalObject)
+ return;
+
+ JSLock lock;
+ m_globalObject->removeDirect("document");
+}
+
+bool KJSProxy::processingUserGesture() const
+{
+ if (!m_globalObject)
+ return false;
+
+ if (Event* event = m_globalObject->currentEvent()) {
+ const AtomicString& type = event->type();
+ if ( // mouse events
+ type == clickEvent || type == mousedownEvent ||
+ type == mouseupEvent || type == dblclickEvent ||
+ // keyboard events
+ type == keydownEvent || type == keypressEvent ||
+ type == keyupEvent ||
+ // other accepted events
+ type == selectEvent || type == changeEvent ||
+ type == focusEvent || type == blurEvent ||
+ type == submitEvent)
+ return true;
+ } else { // no event
+ if (m_processingInlineCode && !m_processingTimerCallback) {
+ // This is the <a href="javascript:window.open('...')> case -> we let it through
+ return true;
+ }
+ // This is the <script>window.open(...)</script> case or a timer callback -> block it
+ }
+ return false;
+}
+
+bool KJSProxy::isEnabled()
+{
+ Settings* settings = m_frame->settings();
+ return (settings && settings->isJavaScriptEnabled());
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/kjs_proxy.h b/WebCore/bindings/js/kjs_proxy.h
new file mode 100644
index 0000000..c746566
--- /dev/null
+++ b/WebCore/bindings/js/kjs_proxy.h
@@ -0,0 +1,89 @@
+/*
+ * This file is part of the KDE libraries
+ * Copyright (C) 1999 Harri Porten (porten@kde.org)
+ * Copyright (C) 2001 Peter Kelly (pmk@post.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_proxy_h
+#define kjs_proxy_h
+
+#include "JSDOMWindow.h"
+#include <kjs/protect.h>
+#include <wtf/RefPtr.h>
+
+namespace KJS {
+ class JSGlobalObject;
+ class JSValue;
+}
+
+namespace WebCore {
+
+class Event;
+class EventListener;
+class Frame;
+class Node;
+class String;
+
+// FIXME: Rename this class to JSController and the Frame function to javaScript().
+
+class KJSProxy {
+public:
+ KJSProxy(Frame*);
+ ~KJSProxy();
+
+ bool haveGlobalObject() const { return m_globalObject; }
+ JSDOMWindow* globalObject()
+ {
+ initScriptIfNeeded();
+ return m_globalObject;
+ }
+
+ KJS::JSValue* evaluate(const String& filename, int baseLine, const String& code);
+ void clear();
+ EventListener* createHTMLEventHandler(const String& functionName, const String& code, Node*);
+#if ENABLE(SVG)
+ EventListener* createSVGEventHandler(const String& functionName, const String& code, Node*);
+#endif
+ void finishedWithEvent(Event*);
+ void setEventHandlerLineno(int lineno) { m_handlerLineno = lineno; }
+
+ void clearDocumentWrapper();
+
+ void setProcessingTimerCallback(bool b) { m_processingTimerCallback = b; }
+ bool processingUserGesture() const;
+
+ bool isEnabled();
+
+private:
+ void initScriptIfNeeded()
+ {
+ if (!m_globalObject)
+ initScript();
+ }
+ void initScript();
+
+ KJS::ProtectedPtr<JSDOMWindow> m_globalObject;
+ Frame* m_frame;
+ int m_handlerLineno;
+
+ bool m_processingTimerCallback;
+ bool m_processingInlineCode;
+};
+
+}
+
+#endif
diff --git a/WebCore/bindings/js/kjs_window.cpp b/WebCore/bindings/js/kjs_window.cpp
new file mode 100644
index 0000000..04d65cc
--- /dev/null
+++ b/WebCore/bindings/js/kjs_window.cpp
@@ -0,0 +1,1503 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2006 Jon Shier (jshier@iastate.edu)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
+ * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
+ * USA
+ */
+
+#include "config.h"
+#include "kjs_window.h"
+
+#include "Base64.h"
+#include "CString.h"
+#include "Chrome.h"
+#include "DOMWindow.h"
+#include "Element.h"
+#include "EventListener.h"
+#include "EventNames.h"
+#include "ExceptionCode.h"
+#include "FloatRect.h"
+#include "Frame.h"
+#include "FrameLoadRequest.h"
+#include "FrameLoader.h"
+#include "FrameTree.h"
+#include "GCController.h"
+#include "HTMLDocument.h"
+#include "JSDOMWindow.h"
+#include "JSEvent.h"
+#include "JSAudioConstructor.h"
+#include "JSHTMLCollection.h"
+#include "JSHTMLOptionElementConstructor.h"
+#include "JSXMLHttpRequest.h"
+#include "JSLocation.h"
+#include "Logging.h"
+#include "MediaPlayer.h"
+#include "Page.h"
+#include "PausedTimeouts.h"
+#include "PlatformScreen.h"
+#include "PluginInfoStore.h"
+#include "RenderView.h"
+#include "ScheduledAction.h"
+#include "SecurityOrigin.h"
+#include "Settings.h"
+#include "WindowFeatures.h"
+#include "htmlediting.h"
+#include "kjs_css.h"
+#include "kjs_events.h"
+#include "kjs_navigator.h"
+#include "kjs_proxy.h"
+#include <wtf/AlwaysInline.h>
+#include <wtf/MathExtras.h>
+
+#if ENABLE(XSLT)
+#include "JSXSLTProcessor.h"
+#endif
+
+using namespace WebCore;
+using namespace EventNames;
+
+namespace KJS {
+
+static int lastUsedTimeoutId;
+
+static int timerNestingLevel = 0;
+const int cMaxTimerNestingLevel = 5;
+const double cMinimumTimerInterval = 0.010;
+
+struct WindowPrivate {
+ WindowPrivate()
+ : loc(0)
+ , m_evt(0)
+ , m_returnValueSlot(0)
+ {
+ }
+
+ Window::ListenersMap jsEventListeners;
+ Window::ListenersMap jsHTMLEventListeners;
+ Window::UnprotectedListenersMap jsUnprotectedEventListeners;
+ Window::UnprotectedListenersMap jsUnprotectedHTMLEventListeners;
+ mutable WebCore::JSLocation* loc;
+ WebCore::Event* m_evt;
+ JSValue** m_returnValueSlot;
+
+ typedef HashMap<int, DOMWindowTimer*> TimeoutsMap;
+ TimeoutsMap m_timeouts;
+};
+
+class DOMWindowTimer : public TimerBase {
+public:
+ DOMWindowTimer(int timeoutId, int nestingLevel, Window* object, WebCore::ScheduledAction* action)
+ : m_timeoutId(timeoutId)
+ , m_nestingLevel(nestingLevel)
+ , m_object(object)
+ , m_action(action)
+ {
+ }
+
+ virtual ~DOMWindowTimer()
+ {
+ JSLock lock;
+ delete m_action;
+ }
+
+ int timeoutId() const { return m_timeoutId; }
+
+ int nestingLevel() const { return m_nestingLevel; }
+ void setNestingLevel(int n) { m_nestingLevel = n; }
+
+ WebCore::ScheduledAction* action() const { return m_action; }
+ WebCore::ScheduledAction* takeAction() { WebCore::ScheduledAction* a = m_action; m_action = 0; return a; }
+
+private:
+ virtual void fired();
+
+ int m_timeoutId;
+ int m_nestingLevel;
+ Window* m_object;
+ WebCore::ScheduledAction* m_action;
+};
+
+} // namespace KJS
+
+#include "kjs_window.lut.h"
+
+namespace KJS {
+
+////////////////////// Window Object ////////////////////////
+
+const ClassInfo Window::info = { "Window", 0, &WindowTable };
+
+/*
+@begin WindowTable 118
+# Warning, when adding a function to this object you need to add a case in Window::get
+# -- Functions --
+ atob windowProtoFuncAToB DontDelete|Function 1
+ btoa windowProtoFuncBToA DontDelete|Function 1
+ open windowProtoFuncOpen DontDelete|Function 3
+ setTimeout windowProtoFuncSetTimeout DontDelete|Function 2
+ clearTimeout windowProtoFuncClearTimeout DontDelete|Function 1
+ setInterval windowProtoFuncSetInterval DontDelete|Function 2
+ clearInterval windowProtoFuncClearTimeout DontDelete|Function 1
+ addEventListener windowProtoFuncAddEventListener DontDelete|Function 3
+ removeEventListener windowProtoFuncRemoveEventListener DontDelete|Function 3
+ showModalDialog windowProtoFuncShowModalDialog DontDelete|Function 1
+# Not implemented
+ captureEvents windowProtoFuncNotImplemented DontDelete|Function 0
+ releaseEvents windowProtoFuncNotImplemented DontDelete|Function 0
+
+# -- Attributes --
+ crypto Window::Crypto DontDelete|ReadOnly
+ event Window::Event_ DontDelete
+ location Window::Location_ DontDelete
+ navigator Window::Navigator_ DontDelete
+ clientInformation Window::ClientInformation DontDelete
+# -- Event Listeners --
+ onabort Window::Onabort DontDelete
+ onblur Window::Onblur DontDelete
+ onchange Window::Onchange DontDelete
+ onclick Window::Onclick DontDelete
+ ondblclick Window::Ondblclick DontDelete
+ onerror Window::Onerror DontDelete
+ onfocus Window::Onfocus DontDelete
+ onkeydown Window::Onkeydown DontDelete
+ onkeypress Window::Onkeypress DontDelete
+ onkeyup Window::Onkeyup DontDelete
+ onload Window::Onload DontDelete
+ onmousedown Window::Onmousedown DontDelete
+ onmousemove Window::Onmousemove DontDelete
+ onmouseout Window::Onmouseout DontDelete
+ onmouseover Window::Onmouseover DontDelete
+ onmouseup Window::Onmouseup DontDelete
+ onmousewheel Window::OnWindowMouseWheel DontDelete
+ onreset Window::Onreset DontDelete
+ onresize Window::Onresize DontDelete
+ onscroll Window::Onscroll DontDelete
+ onsearch Window::Onsearch DontDelete
+ onselect Window::Onselect DontDelete
+ onsubmit Window::Onsubmit DontDelete
+ onunload Window::Onunload DontDelete
+ onbeforeunload Window::Onbeforeunload DontDelete
+# -- Constructors --
+ Audio Window::Audio DontDelete
+ Image Window::Image DontDelete
+ Option Window::Option DontDelete
+ XMLHttpRequest Window::XMLHttpRequest DontDelete
+ XSLTProcessor Window::XSLTProcessor_ DontDelete
+@end
+*/
+
+Window::Window(JSObject* prototype, DOMWindow* window)
+ : JSGlobalObject(prototype)
+ , m_impl(window)
+ , d(new WindowPrivate)
+{
+ // Window destruction is not thread-safe because of
+ // the non-thread-safe WebCore structures it references.
+ Collector::collectOnMainThreadOnly(this);
+
+ // Time in milliseconds before the script timeout handler kicks in.
+ setTimeoutTime(10000);
+}
+
+Window::~Window()
+{
+ clearAllTimeouts();
+
+ // Clear any backpointers to the window
+
+ ListenersMap::iterator i2 = d->jsEventListeners.begin();
+ ListenersMap::iterator e2 = d->jsEventListeners.end();
+ for (; i2 != e2; ++i2)
+ i2->second->clearWindowObj();
+ i2 = d->jsHTMLEventListeners.begin();
+ e2 = d->jsHTMLEventListeners.end();
+ for (; i2 != e2; ++i2)
+ i2->second->clearWindowObj();
+
+ UnprotectedListenersMap::iterator i1 = d->jsUnprotectedEventListeners.begin();
+ UnprotectedListenersMap::iterator e1 = d->jsUnprotectedEventListeners.end();
+ for (; i1 != e1; ++i1)
+ i1->second->clearWindowObj();
+ i1 = d->jsUnprotectedHTMLEventListeners.begin();
+ e1 = d->jsUnprotectedHTMLEventListeners.end();
+ for (; i1 != e1; ++i1)
+ i1->second->clearWindowObj();
+}
+
+Window* Window::retrieveWindow(Frame* frame)
+{
+ JSObject* o = retrieve(frame)->getObject();
+
+ ASSERT(o || !frame->scriptProxy()->isEnabled());
+ return static_cast<Window*>(o);
+}
+
+Window* Window::retrieveActive(ExecState* exec)
+{
+ JSGlobalObject* globalObject = exec->dynamicGlobalObject();
+ ASSERT(globalObject);
+ return static_cast<Window*>(globalObject);
+}
+
+JSValue* Window::retrieve(Frame* frame)
+{
+ ASSERT(frame);
+ if (frame->scriptProxy()->isEnabled())
+ return frame->scriptProxy()->globalObject(); // the Global object is the "window"
+
+ return jsUndefined(); // This can happen with JS disabled on the domain of that window
+}
+
+WebCore::JSLocation* Window::location() const
+{
+ if (!d->loc)
+ d->loc = new JSLocation(0, impl()->frame()); // FIXME: we need to pass a prototype.
+ return d->loc;
+}
+
+void Window::mark()
+{
+ Base::mark();
+ if (d->loc && !d->loc->marked())
+ d->loc->mark();
+}
+
+static bool allowPopUp(ExecState* exec)
+{
+ Frame* frame = Window::retrieveActive(exec)->impl()->frame();
+
+ ASSERT(frame);
+ if (frame->scriptProxy()->processingUserGesture())
+ return true;
+ Settings* settings = frame->settings();
+ return settings && settings->JavaScriptCanOpenWindowsAutomatically();
+}
+
+static HashMap<String, String> parseModalDialogFeatures(const String& featuresArg)
+{
+ HashMap<String, String> map;
+
+ Vector<String> features;
+ featuresArg.split(';', features);
+ Vector<String>::const_iterator end = features.end();
+ for (Vector<String>::const_iterator it = features.begin(); it != end; ++it) {
+ String s = *it;
+ int pos = s.find('=');
+ int colonPos = s.find(':');
+ if (pos >= 0 && colonPos >= 0)
+ continue; // ignore any strings that have both = and :
+ if (pos < 0)
+ pos = colonPos;
+ if (pos < 0) {
+ // null string for value means key without value
+ map.set(s.stripWhiteSpace().lower(), String());
+ } else {
+ String key = s.left(pos).stripWhiteSpace().lower();
+ String val = s.substring(pos + 1).stripWhiteSpace().lower();
+ int spacePos = val.find(' ');
+ if (spacePos != -1)
+ val = val.left(spacePos);
+ map.set(key, val);
+ }
+ }
+
+ return map;
+}
+
+static Frame* createWindow(ExecState* exec, Frame* openerFrame, const String& url,
+ const String& frameName, const WindowFeatures& windowFeatures, JSValue* dialogArgs)
+{
+ Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
+
+ ResourceRequest request;
+ if (activeFrame)
+ request.setHTTPReferrer(activeFrame->loader()->outgoingReferrer());
+ FrameLoadRequest frameRequest(request, frameName);
+
+ FrameLoader* loader;
+ if (activeFrame)
+ // We need to use the active frame's loader to let FrameLoader know
+ // which principal is requesting the navigation. Unfortunately, there
+ // might not be an activeFrame, in which case we resort to using the
+ // opener's loader.
+ //
+ // See http://bugs.webkit.org/show_bug.cgi?id=16522
+ loader = activeFrame->loader();
+ else
+ loader = openerFrame->loader();
+
+ // FIXME: It's much better for client API if a new window starts with a URL, here where we
+ // know what URL we are going to open. Unfortunately, this code passes the empty string
+ // for the URL, but there's a reason for that. Before loading we have to set up the opener,
+ // openedByDOM, and dialogArguments values. Also, to decide whether to use the URL we currently
+ // do an allowsAccessFrom call using the window we create, which can't be done before creating it.
+ // We'd have to resolve all those issues to pass the URL instead of "".
+
+ bool created;
+ Frame* newFrame = loader->createWindow(frameRequest, windowFeatures, created);
+ if (!newFrame)
+ return 0;
+
+ newFrame->loader()->setOpener(openerFrame);
+ newFrame->loader()->setOpenedByDOM();
+
+ Window* newWindow = Window::retrieveWindow(newFrame);
+
+ if (dialogArgs)
+ newWindow->putDirect("dialogArguments", dialogArgs);
+
+ if (!protocolIs(url, "javascript") || newWindow->allowsAccessFrom(exec)) {
+ KURL completedURL = url.isEmpty() ? KURL("") : activeFrame->document()->completeURL(url);
+ bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
+
+ if (created) {
+ newFrame->loader()->changeLocation(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture);
+ if (Document* oldDoc = openerFrame->document())
+ newFrame->document()->setBaseURL(oldDoc->baseURL());
+ } else if (!url.isEmpty())
+ newFrame->loader()->scheduleLocationChange(completedURL.string(), activeFrame->loader()->outgoingReferrer(), false, userGesture);
+ }
+
+ return newFrame;
+}
+
+static bool canShowModalDialog(const Frame* frame)
+{
+ if (!frame)
+ return false;
+ return frame->page()->chrome()->canRunModal();
+}
+
+static bool canShowModalDialogNow(const Frame* frame)
+{
+ if (!frame)
+ return false;
+ return frame->page()->chrome()->canRunModalNow();
+}
+
+static JSValue* showModalDialog(ExecState* exec, Frame* frame, const String& url, JSValue* dialogArgs, const String& featureArgs)
+{
+ if (!canShowModalDialogNow(frame) || !allowPopUp(exec))
+ return jsUndefined();
+
+ const HashMap<String, String> features = parseModalDialogFeatures(featureArgs);
+
+ const bool trusted = false;
+
+ // The following features from Microsoft's documentation are not implemented:
+ // - default font settings
+ // - width, height, left, and top specified in units other than "px"
+ // - edge (sunken or raised, default is raised)
+ // - dialogHide: trusted && boolFeature(features, "dialoghide"), makes dialog hide when you print
+ // - help: boolFeature(features, "help", true), makes help icon appear in dialog (what does it do on Windows?)
+ // - unadorned: trusted && boolFeature(features, "unadorned");
+
+ if (!frame)
+ return jsUndefined();
+
+ FloatRect screenRect = screenAvailableRect(frame->view());
+
+ WindowFeatures wargs;
+ wargs.width = WindowFeatures::floatFeature(features, "dialogwidth", 100, screenRect.width(), 620); // default here came from frame size of dialog in MacIE
+ wargs.widthSet = true;
+ wargs.height = WindowFeatures::floatFeature(features, "dialogheight", 100, screenRect.height(), 450); // default here came from frame size of dialog in MacIE
+ wargs.heightSet = true;
+
+ wargs.x = WindowFeatures::floatFeature(features, "dialogleft", screenRect.x(), screenRect.right() - wargs.width, -1);
+ wargs.xSet = wargs.x > 0;
+ wargs.y = WindowFeatures::floatFeature(features, "dialogtop", screenRect.y(), screenRect.bottom() - wargs.height, -1);
+ wargs.ySet = wargs.y > 0;
+
+ if (WindowFeatures::boolFeature(features, "center", true)) {
+ if (!wargs.xSet) {
+ wargs.x = screenRect.x() + (screenRect.width() - wargs.width) / 2;
+ wargs.xSet = true;
+ }
+ if (!wargs.ySet) {
+ wargs.y = screenRect.y() + (screenRect.height() - wargs.height) / 2;
+ wargs.ySet = true;
+ }
+ }
+
+ wargs.dialog = true;
+ wargs.resizable = WindowFeatures::boolFeature(features, "resizable");
+ wargs.scrollbarsVisible = WindowFeatures::boolFeature(features, "scroll", true);
+ wargs.statusBarVisible = WindowFeatures::boolFeature(features, "status", !trusted);
+ wargs.menuBarVisible = false;
+ wargs.toolBarVisible = false;
+ wargs.locationBarVisible = false;
+ wargs.fullscreen = false;
+
+ Frame* dialogFrame = createWindow(exec, frame, url, "", wargs, dialogArgs);
+ if (!dialogFrame)
+ return jsUndefined();
+
+ Window* dialogWindow = Window::retrieveWindow(dialogFrame);
+
+ // Get the return value either just before clearing the dialog window's
+ // properties (in Window::clear), or when on return from runModal.
+ JSValue* returnValue = 0;
+ dialogWindow->setReturnValueSlot(&returnValue);
+ dialogFrame->page()->chrome()->runModal();
+ dialogWindow->setReturnValueSlot(0);
+
+ // If we don't have a return value, get it now.
+ // Either Window::clear was not called yet, or there was no return value,
+ // and in that case, there's no harm in trying again (no benefit either).
+ if (!returnValue)
+ returnValue = dialogWindow->getDirect("returnValue");
+
+ return returnValue ? returnValue : jsUndefined();
+}
+
+JSValue *Window::getValueProperty(ExecState *exec, int token) const
+{
+ ASSERT(impl()->frame());
+
+ switch (token) {
+ case Crypto:
+ return jsUndefined(); // FIXME: implement this
+ case Event_:
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+ if (!d->m_evt)
+ return jsUndefined();
+ return toJS(exec, d->m_evt);
+ case Location_:
+ return location();
+ case Navigator_:
+ case ClientInformation: {
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+ // Store the navigator in the object so we get the same one each time.
+ Navigator* n = new Navigator(exec->lexicalGlobalObject()->objectPrototype(), impl()->frame());
+ // FIXME: this will make the "navigator" object accessible from windows that fail
+ // the security check the first time, but not subsequent times, seems weird.
+ const_cast<Window *>(this)->putDirect("navigator", n, DontDelete);
+ const_cast<Window *>(this)->putDirect("clientInformation", n, DontDelete);
+ return n;
+ }
+ case Image:
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+ // FIXME: this property (and the few below) probably shouldn't create a new object every
+ // time
+ return new ImageConstructorImp(exec, impl()->frame()->document());
+ case Option:
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+ return new JSHTMLOptionElementConstructor(exec, impl()->frame()->document());
+ case XMLHttpRequest:
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+ return new JSXMLHttpRequestConstructorImp(exec, impl()->frame()->document());
+ case Audio:
+#if ENABLE(VIDEO)
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+ if (!MediaPlayer::isAvailable())
+ return jsUndefined();
+ return new JSAudioConstructor(exec, impl()->frame()->document());
+#else
+ return jsUndefined();
+#endif
+#if ENABLE(XSLT)
+ case XSLTProcessor_:
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+ return new XSLTProcessorConstructorImp(exec);
+#else
+ case XSLTProcessor_:
+ return jsUndefined();
+#endif
+ }
+
+ if (!allowsAccessFrom(exec))
+ return jsUndefined();
+
+ switch (token) {
+ case Onabort:
+ return getListener(exec, abortEvent);
+ case Onblur:
+ return getListener(exec, blurEvent);
+ case Onchange:
+ return getListener(exec, changeEvent);
+ case Onclick:
+ return getListener(exec, clickEvent);
+ case Ondblclick:
+ return getListener(exec, dblclickEvent);
+ case Onerror:
+ return getListener(exec, errorEvent);
+ case Onfocus:
+ return getListener(exec, focusEvent);
+ case Onkeydown:
+ return getListener(exec, keydownEvent);
+ case Onkeypress:
+ return getListener(exec, keypressEvent);
+ case Onkeyup:
+ return getListener(exec, keyupEvent);
+ case Onload:
+ return getListener(exec, loadEvent);
+ case Onmousedown:
+ return getListener(exec, mousedownEvent);
+ case Onmousemove:
+ return getListener(exec, mousemoveEvent);
+ case Onmouseout:
+ return getListener(exec, mouseoutEvent);
+ case Onmouseover:
+ return getListener(exec, mouseoverEvent);
+ case Onmouseup:
+ return getListener(exec, mouseupEvent);
+ case OnWindowMouseWheel:
+ return getListener(exec, mousewheelEvent);
+ case Onreset:
+ return getListener(exec, resetEvent);
+ case Onresize:
+ return getListener(exec,resizeEvent);
+ case Onscroll:
+ return getListener(exec,scrollEvent);
+ case Onsearch:
+ return getListener(exec,searchEvent);
+ case Onselect:
+ return getListener(exec,selectEvent);
+ case Onsubmit:
+ return getListener(exec,submitEvent);
+ case Onbeforeunload:
+ return getListener(exec, beforeunloadEvent);
+ case Onunload:
+ return getListener(exec, unloadEvent);
+ }
+ ASSERT_NOT_REACHED();
+ return jsUndefined();
+}
+
+JSValue* Window::childFrameGetter(ExecState*, JSObject*, const Identifier& propertyName, const PropertySlot& slot)
+{
+ return retrieve(static_cast<Window*>(slot.slotBase())->impl()->frame()->tree()->child(AtomicString(propertyName)));
+}
+
+JSValue* Window::indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot& slot)
+{
+ return retrieve(static_cast<Window*>(slot.slotBase())->impl()->frame()->tree()->child(slot.index()));
+}
+
+JSValue* Window::namedItemGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)
+{
+ Window* thisObj = static_cast<Window*>(slot.slotBase());
+ Document* doc = thisObj->impl()->frame()->document();
+ ASSERT(thisObj->allowsAccessFrom(exec));
+ ASSERT(doc);
+ ASSERT(doc->isHTMLDocument());
+
+ RefPtr<WebCore::HTMLCollection> collection = doc->windowNamedItems(propertyName);
+ if (collection->length() == 1)
+ return toJS(exec, collection->firstItem());
+ return toJS(exec, collection.get());
+}
+
+bool Window::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ // Check for child frames by name before built-in properties to
+ // match Mozilla. This does not match IE, but some sites end up
+ // naming frames things that conflict with window properties that
+ // are in Moz but not IE. Since we have some of these, we have to do
+ // it the Moz way.
+ if (impl()->frame()->tree()->child(propertyName)) {
+ slot.setCustom(this, childFrameGetter);
+ return true;
+ }
+
+ const HashEntry* entry = Lookup::findEntry(&WindowTable, propertyName);
+ if (entry) {
+ if (entry->attr & Function) {
+ if (entry->value.functionValue == windowProtoFuncShowModalDialog) {
+ if (!canShowModalDialog(impl()->frame()))
+ return false;
+ }
+ if (allowsAccessFrom(exec))
+ slot.setStaticEntry(this, entry, staticFunctionGetter);
+ else
+ slot.setUndefined(this);
+ } else
+ slot.setStaticEntry(this, entry, staticValueGetter<Window>);
+ return true;
+ }
+
+ // Do prototype lookup early so that functions and attributes in the prototype can have
+ // precedence over the index and name getters.
+ JSValue* proto = prototype();
+ if (proto->isObject()) {
+ if (static_cast<JSObject*>(proto)->getPropertySlot(exec, propertyName, slot)) {
+ if (!allowsAccessFrom(exec))
+ slot.setUndefined(this);
+ return true;
+ }
+ }
+
+ // FIXME: Search the whole frame hierachy somewhere around here.
+ // We need to test the correct priority order.
+
+ // allow window[1] or parent[1] etc. (#56983)
+ bool ok;
+ unsigned i = propertyName.toArrayIndex(&ok);
+ if (ok && i < impl()->frame()->tree()->childCount()) {
+ slot.setCustomIndex(this, i, indexGetter);
+ return true;
+ }
+
+ if (!allowsAccessFrom(exec)) {
+ slot.setUndefined(this);
+ return true;
+ }
+
+ // Allow shortcuts like 'Image1' instead of document.images.Image1
+ Document* doc = impl()->frame()->document();
+ if (doc && doc->isHTMLDocument()) {
+ AtomicString atomicPropertyName = propertyName;
+ if (static_cast<HTMLDocument*>(doc)->hasNamedItem(atomicPropertyName) || doc->getElementById(atomicPropertyName)) {
+ slot.setCustom(this, namedItemGetter);
+ return true;
+ }
+ }
+
+ return Base::getOwnPropertySlot(exec, propertyName, slot);
+}
+
+void Window::put(ExecState* exec, const Identifier& propertyName, JSValue* value)
+{
+ const HashEntry* entry = Lookup::findEntry(&WindowTable, propertyName);
+ if (entry) {
+ if (entry->attr & Function) {
+ if (allowsAccessFrom(exec))
+ Base::put(exec, propertyName, value);
+ return;
+ }
+ if (entry->attr & ReadOnly)
+ return;
+
+ switch (entry->value.intValue) {
+ case Location_: {
+ if (Frame* p = Window::retrieveActive(exec)->impl()->frame()) {
+ // To avoid breaking old widgets, make "var location =" in a top-level frame create
+ // a property named "location" instead of performing a navigation (<rdar://problem/5688039>).
+ if (Settings* settings = p->settings()) {
+ if (settings->usesDashboardBackwardCompatibilityMode() && !p->tree()->parent()) {
+ if (allowsAccessFrom(exec))
+ putDirect(propertyName, value);
+ return;
+ }
+ }
+
+ if (!p->loader()->shouldAllowNavigation(impl()->frame()))
+ return;
+ String dstUrl = p->loader()->completeURL(value->toString(exec)).string();
+ if (!protocolIs(dstUrl, "javascript") || allowsAccessFrom(exec)) {
+ bool userGesture = p->scriptProxy()->processingUserGesture();
+ // We want a new history item if this JS was called via a user gesture
+ impl()->frame()->loader()->scheduleLocationChange(dstUrl, p->loader()->outgoingReferrer(), false, userGesture);
+ }
+ }
+ return;
+ }
+ case Onabort:
+ if (allowsAccessFrom(exec))
+ setListener(exec, abortEvent,value);
+ return;
+ case Onblur:
+ if (allowsAccessFrom(exec))
+ setListener(exec, blurEvent,value);
+ return;
+ case Onchange:
+ if (allowsAccessFrom(exec))
+ setListener(exec, changeEvent,value);
+ return;
+ case Onclick:
+ if (allowsAccessFrom(exec))
+ setListener(exec,clickEvent,value);
+ return;
+ case Ondblclick:
+ if (allowsAccessFrom(exec))
+ setListener(exec, dblclickEvent,value);
+ return;
+ case Onerror:
+ if (allowsAccessFrom(exec))
+ setListener(exec, errorEvent, value);
+ return;
+ case Onfocus:
+ if (allowsAccessFrom(exec))
+ setListener(exec,focusEvent,value);
+ return;
+ case Onkeydown:
+ if (allowsAccessFrom(exec))
+ setListener(exec,keydownEvent,value);
+ return;
+ case Onkeypress:
+ if (allowsAccessFrom(exec))
+ setListener(exec,keypressEvent,value);
+ return;
+ case Onkeyup:
+ if (allowsAccessFrom(exec))
+ setListener(exec,keyupEvent,value);
+ return;
+ case Onload:
+ if (allowsAccessFrom(exec))
+ setListener(exec,loadEvent,value);
+ return;
+ case Onmousedown:
+ if (allowsAccessFrom(exec))
+ setListener(exec,mousedownEvent,value);
+ return;
+ case Onmousemove:
+ if (allowsAccessFrom(exec))
+ setListener(exec,mousemoveEvent,value);
+ return;
+ case Onmouseout:
+ if (allowsAccessFrom(exec))
+ setListener(exec,mouseoutEvent,value);
+ return;
+ case Onmouseover:
+ if (allowsAccessFrom(exec))
+ setListener(exec,mouseoverEvent,value);
+ return;
+ case Onmouseup:
+ if (allowsAccessFrom(exec))
+ setListener(exec,mouseupEvent,value);
+ return;
+ case OnWindowMouseWheel:
+ if (allowsAccessFrom(exec))
+ setListener(exec, mousewheelEvent,value);
+ return;
+ case Onreset:
+ if (allowsAccessFrom(exec))
+ setListener(exec,resetEvent,value);
+ return;
+ case Onresize:
+ if (allowsAccessFrom(exec))
+ setListener(exec,resizeEvent,value);
+ return;
+ case Onscroll:
+ if (allowsAccessFrom(exec))
+ setListener(exec,scrollEvent,value);
+ return;
+ case Onsearch:
+ if (allowsAccessFrom(exec))
+ setListener(exec,searchEvent,value);
+ return;
+ case Onselect:
+ if (allowsAccessFrom(exec))
+ setListener(exec,selectEvent,value);
+ return;
+ case Onsubmit:
+ if (allowsAccessFrom(exec))
+ setListener(exec,submitEvent,value);
+ return;
+ case Onbeforeunload:
+ if (allowsAccessFrom(exec))
+ setListener(exec, beforeunloadEvent, value);
+ return;
+ case Onunload:
+ if (allowsAccessFrom(exec))
+ setListener(exec, unloadEvent, value);
+ return;
+ default:
+ break;
+ }
+ }
+ if (allowsAccessFrom(exec))
+ Base::put(exec, propertyName, value);
+}
+
+bool Window::allowsAccessFrom(const JSGlobalObject* other) const
+{
+ SecurityOrigin::Reason reason;
+ if (allowsAccessFromPrivate(other, reason))
+ return true;
+ printErrorMessage(crossDomainAccessErrorMessage(other, reason));
+ return false;
+}
+
+bool Window::allowsAccessFrom(ExecState* exec) const
+{
+ SecurityOrigin::Reason reason;
+ if (allowsAccessFromPrivate(exec, reason))
+ return true;
+ printErrorMessage(crossDomainAccessErrorMessage(exec->dynamicGlobalObject(), reason));
+ return false;
+}
+
+bool Window::allowsAccessFromNoErrorMessage(ExecState* exec) const
+{
+ SecurityOrigin::Reason reason;
+ return allowsAccessFromPrivate(exec, reason);
+}
+
+bool Window::allowsAccessFrom(ExecState* exec, String& message) const
+{
+ SecurityOrigin::Reason reason;
+ if (allowsAccessFromPrivate(exec, reason))
+ return true;
+ message = crossDomainAccessErrorMessage(exec->dynamicGlobalObject(), reason);
+ return false;
+}
+
+ALWAYS_INLINE bool Window::allowsAccessFromPrivate(const ExecState* exec, SecurityOrigin::Reason& reason) const
+{
+ if (allowsAccessFromPrivate(exec->dynamicGlobalObject(), reason))
+ return true;
+ if (reason == SecurityOrigin::DomainSetInDOMMismatch) {
+ // If the only reason the access failed was a domainSetInDOM bit mismatch, try again against
+ // lexical global object <rdar://problem/5698200>
+ if (allowsAccessFromPrivate(exec->lexicalGlobalObject(), reason))
+ return true;
+ }
+ return false;
+}
+
+ALWAYS_INLINE bool Window::allowsAccessFromPrivate(const JSGlobalObject* other, SecurityOrigin::Reason& reason) const
+{
+ const Frame* originFrame = static_cast<const Window*>(other)->impl()->frame();
+ if (!originFrame) {
+ reason = SecurityOrigin::GenericMismatch;
+ return false;
+ }
+
+ const Frame* targetFrame = impl()->frame();
+
+ if (originFrame == targetFrame)
+ return true;
+
+ if (!targetFrame) {
+ reason = SecurityOrigin::GenericMismatch;
+ return false;
+ }
+
+ WebCore::Document* targetDocument = targetFrame->document();
+
+ // JS may be attempting to access the "window" object, which should be valid,
+ // even if the document hasn't been constructed yet. If the document doesn't
+ // exist yet allow JS to access the window object.
+ if (!targetDocument)
+ return true;
+
+ WebCore::Document* originDocument = originFrame->document();
+
+ const SecurityOrigin* originSecurityOrigin = originDocument->securityOrigin();
+ const SecurityOrigin* targetSecurityOrigin = targetDocument->securityOrigin();
+
+ if (originSecurityOrigin->canAccess(targetSecurityOrigin, reason))
+ return true;
+
+ return false;
+}
+
+String Window::crossDomainAccessErrorMessage(const JSGlobalObject* other, SecurityOrigin::Reason) const
+{
+ const Frame* originFrame = static_cast<const Window*>(other)->impl()->frame();
+ const Frame* targetFrame = impl()->frame();
+ if (!originFrame || !targetFrame)
+ return String();
+ WebCore::Document* targetDocument = targetFrame->document();
+ WebCore::Document* originDocument = originFrame->document();
+ if (!originDocument || !targetDocument)
+ return String();
+ // FIXME: this error message should contain more specifics of why the same origin check has failed.
+ return String::format("Unsafe JavaScript attempt to access frame with URL %s from frame with URL %s. Domains, protocols and ports must match.\n",
+ targetDocument->url().string().utf8().data(), originDocument->url().string().utf8().data());
+}
+
+void Window::printErrorMessage(const String& message) const
+{
+ if (message.isEmpty())
+ return;
+
+ Frame* frame = impl()->frame();
+ if (!frame)
+ return;
+
+ if (frame->settings()->privateBrowsingEnabled())
+ return;
+
+ if (Interpreter::shouldPrintExceptions())
+ printf("%s", message.utf8().data());
+
+ if (Page* page = frame->page())
+ page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, message, 1, String()); // FIXME: provide a real line number and source URL.
+}
+
+ExecState* Window::globalExec()
+{
+ // We need to make sure that any script execution happening in this
+ // frame does not destroy it
+ ASSERT(impl()->frame());
+ impl()->frame()->keepAlive();
+ return Base::globalExec();
+}
+
+bool Window::shouldInterruptScript() const
+{
+ ASSERT(impl()->frame());
+ Page* page = impl()->frame()->page();
+
+ // See <rdar://problem/5479443>. We don't think that page can ever be NULL
+ // in this case, but if it is, we've gotten into a state where we may have
+ // hung the UI, with no way to ask the client whether to cancel execution.
+ // For now, our solution is just to cancel execution no matter what,
+ // ensuring that we never hang. We might want to consider other solutions
+ // if we discover problems with this one.
+ ASSERT(page);
+ if (!page)
+ return true;
+
+ return page->chrome()->shouldInterruptJavaScript();
+}
+
+void Window::setListener(ExecState* exec, const AtomicString& eventType, JSValue* func)
+{
+ ASSERT(impl()->frame());
+ Document* doc = impl()->frame()->document();
+ if (!doc)
+ return;
+
+ doc->setHTMLWindowEventListener(eventType, findOrCreateJSEventListener(func, true));
+}
+
+JSValue* Window::getListener(ExecState* exec, const AtomicString& eventType) const
+{
+ ASSERT(impl()->frame());
+ Document* doc = impl()->frame()->document();
+ if (!doc)
+ return jsUndefined();
+
+ WebCore::EventListener* listener = doc->getHTMLWindowEventListener(eventType);
+ if (listener && static_cast<JSEventListener*>(listener)->listenerObj())
+ return static_cast<JSEventListener*>(listener)->listenerObj();
+ return jsNull();
+}
+
+JSEventListener* Window::findJSEventListener(JSValue* val, bool html)
+{
+ if (!val->isObject())
+ return 0;
+ JSObject* object = static_cast<JSObject*>(val);
+ ListenersMap& listeners = html ? d->jsHTMLEventListeners : d->jsEventListeners;
+ return listeners.get(object);
+}
+
+JSEventListener* Window::findOrCreateJSEventListener(JSValue* val, bool html)
+{
+ JSEventListener* listener = findJSEventListener(val, html);
+ if (listener)
+ return listener;
+
+ if (!val->isObject())
+ return 0;
+ JSObject* object = static_cast<JSObject*>(val);
+
+ // Note that the JSEventListener constructor adds it to our jsEventListeners list
+ return new JSEventListener(object, this, html);
+}
+
+JSUnprotectedEventListener* Window::findJSUnprotectedEventListener(JSValue* val, bool html)
+{
+ if (!val->isObject())
+ return 0;
+ JSObject* object = static_cast<JSObject*>(val);
+ UnprotectedListenersMap& listeners = html ? d->jsUnprotectedHTMLEventListeners : d->jsUnprotectedEventListeners;
+ return listeners.get(object);
+}
+
+JSUnprotectedEventListener* Window::findOrCreateJSUnprotectedEventListener(JSValue* val, bool html)
+{
+ JSUnprotectedEventListener* listener = findJSUnprotectedEventListener(val, html);
+ if (listener)
+ return listener;
+ if (!val->isObject())
+ return 0;
+ JSObject* object = static_cast<JSObject*>(val);
+
+ // The JSUnprotectedEventListener constructor adds it to our jsUnprotectedEventListeners map.
+ return new JSUnprotectedEventListener(object, this, html);
+}
+
+void Window::clearHelperObjectProperties()
+{
+ d->loc = 0;
+ d->m_evt = 0;
+}
+
+void Window::clear()
+{
+ JSLock lock;
+
+ if (d->m_returnValueSlot && !*d->m_returnValueSlot)
+ *d->m_returnValueSlot = getDirect("returnValue");
+
+ clearAllTimeouts();
+ clearHelperObjectProperties();
+
+ // Now recreate a working global object for the next URL that will use us; but only if we haven't been
+ // disconnected yet
+ if (Frame* frame = impl()->frame())
+ frame->scriptProxy()->globalObject()->reset(JSDOMWindowPrototype::self());
+
+ // there's likely to be lots of garbage now
+ gcController().garbageCollectSoon();
+}
+
+void Window::setCurrentEvent(Event* evt)
+{
+ d->m_evt = evt;
+}
+
+Event* Window::currentEvent()
+{
+ return d->m_evt;
+}
+
+JSValue* windowProtoFuncAToB(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ if (!static_cast<Window*>(thisObj)->allowsAccessFrom(exec))
+ return jsUndefined();
+
+ if (args.size() < 1)
+ return throwError(exec, SyntaxError, "Not enough arguments");
+
+ JSValue* v = args[0];
+ if (v->isNull())
+ return jsString();
+
+ UString s = v->toString(exec);
+ if (!s.is8Bit()) {
+ setDOMException(exec, INVALID_CHARACTER_ERR);
+ return jsUndefined();
+ }
+
+ Vector<char> in(s.size());
+ for (int i = 0; i < s.size(); ++i)
+ in[i] = static_cast<char>(s.data()[i].unicode());
+ Vector<char> out;
+
+ if (!base64Decode(in, out))
+ return throwError(exec, GeneralError, "Cannot decode base64");
+
+ return jsString(String(out.data(), out.size()));
+}
+
+JSValue* windowProtoFuncBToA(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ if (!static_cast<Window*>(thisObj)->allowsAccessFrom(exec))
+ return jsUndefined();
+
+ if (args.size() < 1)
+ return throwError(exec, SyntaxError, "Not enough arguments");
+
+ JSValue* v = args[0];
+ if (v->isNull())
+ return jsString();
+
+ UString s = v->toString(exec);
+ if (!s.is8Bit()) {
+ setDOMException(exec, INVALID_CHARACTER_ERR);
+ return jsUndefined();
+ }
+
+ Vector<char> in(s.size());
+ for (int i = 0; i < s.size(); ++i)
+ in[i] = static_cast<char>(s.data()[i].unicode());
+ Vector<char> out;
+
+ base64Encode(in, out);
+
+ return jsString(String(out.data(), out.size()));
+}
+
+JSValue* windowProtoFuncOpen(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ Window* window = static_cast<Window*>(thisObj);
+ if (!window->allowsAccessFrom(exec))
+ return jsUndefined();
+
+ Frame* frame = window->impl()->frame();
+ if (!frame)
+ return jsUndefined();
+ Frame* activeFrame = Window::retrieveActive(exec)->impl()->frame();
+ if (!activeFrame)
+ return jsUndefined();
+
+ Page* page = frame->page();
+
+ String urlString = valueToStringWithUndefinedOrNullCheck(exec, args[0]);
+ AtomicString frameName = args[1]->isUndefinedOrNull() ? "_blank" : AtomicString(args[1]->toString(exec));
+
+ // Because FrameTree::find() returns true for empty strings, we must check for empty framenames.
+ // Otherwise, illegitimate window.open() calls with no name will pass right through the popup blocker.
+ if (!allowPopUp(exec) && (frameName.isEmpty() || !frame->tree()->find(frameName)))
+ return jsUndefined();
+
+ // Get the target frame for the special cases of _top and _parent. In those
+ // cases, we can schedule a location change right now and return early.
+ bool topOrParent = false;
+ if (frameName == "_top") {
+ frame = frame->tree()->top();
+ topOrParent = true;
+ } else if (frameName == "_parent") {
+ if (Frame* parent = frame->tree()->parent())
+ frame = parent;
+ topOrParent = true;
+ }
+ if (topOrParent) {
+ if (!activeFrame->loader()->shouldAllowNavigation(frame))
+ return jsUndefined();
+
+ String completedURL;
+ if (!urlString.isEmpty())
+ completedURL = activeFrame->document()->completeURL(urlString).string();
+
+ const Window* targetedWindow = Window::retrieveWindow(frame);
+ if (!completedURL.isEmpty() && (!protocolIs(completedURL, "javascript") || (targetedWindow && targetedWindow->allowsAccessFrom(exec)))) {
+ bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
+ frame->loader()->scheduleLocationChange(completedURL, activeFrame->loader()->outgoingReferrer(), false, userGesture);
+ }
+ return Window::retrieve(frame);
+ }
+
+ // In the case of a named frame or a new window, we'll use the createWindow() helper
+ WindowFeatures windowFeatures(valueToStringWithUndefinedOrNullCheck(exec, args[2]));
+ FloatRect windowRect(windowFeatures.x, windowFeatures.y, windowFeatures.width, windowFeatures.height);
+ WebCore::DOMWindow::adjustWindowRect(screenAvailableRect(page->mainFrame()->view()), windowRect, windowRect);
+
+ windowFeatures.x = windowRect.x();
+ windowFeatures.y = windowRect.y();
+ windowFeatures.height = windowRect.height();
+ windowFeatures.width = windowRect.width();
+
+ frame = createWindow(exec, frame, urlString, frameName, windowFeatures, 0);
+
+ if (!frame)
+ return jsUndefined();
+
+ return Window::retrieve(frame); // global object
+}
+
+JSValue* windowProtoFuncSetTimeout(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ Window* window = static_cast<Window*>(thisObj);
+ if (!window->allowsAccessFrom(exec))
+ return jsUndefined();
+
+ JSValue* v = args[0];
+ if (v->isString())
+ return jsNumber(window->installTimeout(v->toString(exec), args[1]->toInt32(exec), true /*single shot*/));
+ if (v->isObject() && static_cast<JSObject*>(v)->implementsCall()) {
+ List argsTail;
+ args.getSlice(2, argsTail);
+ return jsNumber(window->installTimeout(v, argsTail, args[1]->toInt32(exec), true /*single shot*/));
+ }
+
+ return jsUndefined();
+}
+
+JSValue* windowProtoFuncClearTimeout(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ // Also the implementation for window.clearInterval()
+
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ Window* window = static_cast<Window*>(thisObj);
+ if (!window->allowsAccessFrom(exec))
+ return jsUndefined();
+
+ window->clearTimeout(args[0]->toInt32(exec));
+ return jsUndefined();
+}
+
+JSValue* windowProtoFuncSetInterval(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ Window* window = static_cast<Window*>(thisObj);
+ if (!window->allowsAccessFrom(exec))
+ return jsUndefined();
+
+ if (args.size() >= 2) {
+ JSValue* v = args[0];
+ int delay = args[1]->toInt32(exec);
+ if (v->isString())
+ return jsNumber(window->installTimeout(v->toString(exec), delay, false));
+ if (v->isObject() && static_cast<JSObject*>(v)->implementsCall()) {
+ List argsTail;
+ args.getSlice(2, argsTail);
+ return jsNumber(window->installTimeout(v, argsTail, delay, false));
+ }
+ }
+
+ return jsUndefined();
+
+}
+
+JSValue* windowProtoFuncAddEventListener(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ Window* window = static_cast<Window*>(thisObj);
+ if (!window->allowsAccessFrom(exec))
+ return jsUndefined();
+ Frame* frame = window->impl()->frame();
+ if (!frame)
+ return jsUndefined();
+
+ if (JSEventListener* listener = window->findOrCreateJSEventListener(args[1])) {
+ if (Document* doc = frame->document())
+ doc->addWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec));
+ }
+
+ return jsUndefined();
+}
+
+JSValue* windowProtoFuncRemoveEventListener(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ Window* window = static_cast<Window*>(thisObj);
+ if (!window->allowsAccessFrom(exec))
+ return jsUndefined();
+ Frame* frame = window->impl()->frame();
+ if (!frame)
+ return jsUndefined();
+
+ if (JSEventListener* listener = window->findJSEventListener(args[1])) {
+ if (Document* doc = frame->document())
+ doc->removeWindowEventListener(AtomicString(args[0]->toString(exec)), listener, args[2]->toBoolean(exec));
+ }
+
+ return jsUndefined();
+}
+
+JSValue* windowProtoFuncShowModalDialog(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+ Window* window = static_cast<Window*>(thisObj);
+ Frame* frame = window->impl()->frame();
+ if (!frame)
+ return jsUndefined();
+
+ return showModalDialog(exec, frame, valueToStringWithUndefinedOrNullCheck(exec, args[0]), args[1], valueToStringWithUndefinedOrNullCheck(exec, args[2]));
+}
+
+JSValue* windowProtoFuncNotImplemented(ExecState* exec, JSObject* thisObj, const List& args)
+{
+ if (!thisObj->inherits(&Window::info))
+ return throwError(exec, TypeError);
+
+ return jsUndefined();
+}
+
+void Window::setReturnValueSlot(JSValue** slot)
+{
+ d->m_returnValueSlot = slot;
+}
+
+////////////////////// timeouts ////////////////////////
+
+void Window::clearAllTimeouts()
+{
+ deleteAllValues(d->m_timeouts);
+ d->m_timeouts.clear();
+}
+
+int Window::installTimeout(WebCore::ScheduledAction* a, int t, bool singleShot)
+{
+ int timeoutId = ++lastUsedTimeoutId;
+
+ // avoid wraparound going negative on us
+ if (timeoutId <= 0)
+ timeoutId = 1;
+
+ int nestLevel = timerNestingLevel + 1;
+ DOMWindowTimer* timer = new DOMWindowTimer(timeoutId, nestLevel, this, a);
+ ASSERT(!d->m_timeouts.get(timeoutId));
+ d->m_timeouts.set(timeoutId, timer);
+ // Use a minimum interval of 10 ms to match other browsers, but only once we've
+ // nested enough to notice that we're repeating.
+ // Faster timers might be "better", but they're incompatible.
+ double interval = max(0.001, t * 0.001);
+ if (interval < cMinimumTimerInterval && nestLevel >= cMaxTimerNestingLevel)
+ interval = cMinimumTimerInterval;
+ if (singleShot)
+ timer->startOneShot(interval);
+ else
+ timer->startRepeating(interval);
+ return timeoutId;
+}
+
+int Window::installTimeout(const UString& handler, int t, bool singleShot)
+{
+ return installTimeout(new WebCore::ScheduledAction(handler), t, singleShot);
+}
+
+int Window::installTimeout(JSValue* func, const List& args, int t, bool singleShot)
+{
+ return installTimeout(new WebCore::ScheduledAction(func, args), t, singleShot);
+}
+
+WebCore::PausedTimeouts* Window::pauseTimeouts()
+{
+ size_t count = d->m_timeouts.size();
+ if (count == 0)
+ return 0;
+
+ PausedTimeout* t = new PausedTimeout [count];
+ PausedTimeouts* result = new PausedTimeouts(t, count);
+
+ WindowPrivate::TimeoutsMap::iterator it = d->m_timeouts.begin();
+ for (size_t i = 0; i != count; ++i, ++it) {
+ int timeoutId = it->first;
+ DOMWindowTimer* timer = it->second;
+ t[i].timeoutId = timeoutId;
+ t[i].nestingLevel = timer->nestingLevel();
+ t[i].nextFireInterval = timer->nextFireInterval();
+ t[i].repeatInterval = timer->repeatInterval();
+ t[i].action = timer->takeAction();
+ }
+ ASSERT(it == d->m_timeouts.end());
+
+ deleteAllValues(d->m_timeouts);
+ d->m_timeouts.clear();
+
+ return result;
+}
+
+void Window::resumeTimeouts(PausedTimeouts* timeouts)
+{
+ if (!timeouts)
+ return;
+ size_t count = timeouts->numTimeouts();
+ PausedTimeout* array = timeouts->takeTimeouts();
+ for (size_t i = 0; i != count; ++i) {
+ int timeoutId = array[i].timeoutId;
+ DOMWindowTimer* timer = new DOMWindowTimer(timeoutId, array[i].nestingLevel, this, array[i].action);
+ d->m_timeouts.set(timeoutId, timer);
+ timer->start(array[i].nextFireInterval, array[i].repeatInterval);
+ }
+ delete [] array;
+}
+
+void Window::clearTimeout(int timeoutId, bool delAction)
+{
+ // timeout IDs have to be positive, and 0 and -1 are unsafe to
+ // even look up since they are the empty and deleted value
+ // respectively
+ if (timeoutId <= 0)
+ return;
+
+ delete d->m_timeouts.take(timeoutId);
+}
+
+void Window::timerFired(DOMWindowTimer* timer)
+{
+ // Simple case for non-one-shot timers.
+ if (timer->isActive()) {
+ int timeoutId = timer->timeoutId();
+
+ timer->action()->execute(this);
+ // The DOMWindowTimer object may have been deleted or replaced during execution,
+ // so we re-fetch it.
+ timer = d->m_timeouts.get(timeoutId);
+ if (!timer)
+ return;
+
+ if (timer->repeatInterval() && timer->repeatInterval() < cMinimumTimerInterval) {
+ timer->setNestingLevel(timer->nestingLevel() + 1);
+ if (timer->nestingLevel() >= cMaxTimerNestingLevel)
+ timer->augmentRepeatInterval(cMinimumTimerInterval - timer->repeatInterval());
+ }
+ return;
+ }
+
+ // Delete timer before executing the action for one-shot timers.
+ WebCore::ScheduledAction* action = timer->takeAction();
+ d->m_timeouts.remove(timer->timeoutId());
+ delete timer;
+ action->execute(this);
+
+ JSLock lock;
+ delete action;
+}
+
+void Window::disconnectFrame()
+{
+ clearAllTimeouts();
+ if (d->loc)
+ d->loc->m_frame = 0;
+}
+
+Window::ListenersMap& Window::jsEventListeners()
+{
+ return d->jsEventListeners;
+}
+
+Window::ListenersMap& Window::jsHTMLEventListeners()
+{
+ return d->jsHTMLEventListeners;
+}
+
+Window::UnprotectedListenersMap& Window::jsUnprotectedEventListeners()
+{
+ return d->jsUnprotectedEventListeners;
+}
+
+Window::UnprotectedListenersMap& Window::jsUnprotectedHTMLEventListeners()
+{
+ return d->jsUnprotectedHTMLEventListeners;
+}
+
+/////////////////////////////////////////////////////////////////////////////
+
+void DOMWindowTimer::fired()
+{
+ timerNestingLevel = m_nestingLevel;
+ m_object->timerFired(this);
+ timerNestingLevel = 0;
+}
+
+} // namespace KJS
+
+using namespace KJS;
+
+namespace WebCore {
+
+JSValue* toJS(ExecState*, DOMWindow* domWindow)
+{
+ if (!domWindow)
+ return jsNull();
+ Frame* frame = domWindow->frame();
+ if (!frame)
+ return jsNull();
+ return Window::retrieve(frame);
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/js/kjs_window.h b/WebCore/bindings/js/kjs_window.h
new file mode 100644
index 0000000..ad415aa
--- /dev/null
+++ b/WebCore/bindings/js/kjs_window.h
@@ -0,0 +1,191 @@
+/*
+ * Copyright (C) 2000 Harri Porten (porten@kde.org)
+ * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reseved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef kjs_window_h
+#define kjs_window_h
+
+#include "PlatformString.h"
+#include "kjs_binding.h"
+#include <kjs/protect.h>
+#include "SecurityOrigin.h"
+#include <wtf/HashMap.h>
+#include <wtf/Noncopyable.h>
+#include <wtf/OwnPtr.h>
+
+namespace WebCore {
+ class AtomicString;
+ class DOMWindow;
+ class Frame;
+ class JSEventListener;
+ class JSLocation;
+ class JSUnprotectedEventListener;
+ class PausedTimeouts;
+ class ScheduledAction;
+}
+
+namespace KJS {
+
+ class DOMWindowTimer;
+ class WindowPrivate;
+
+ // This is the only WebCore JS binding which does not inherit from DOMObject
+ class Window : public JSGlobalObject {
+ typedef JSGlobalObject Base;
+
+ friend class WebCore::ScheduledAction;
+ protected:
+ Window(JSObject* prototype, WebCore::DOMWindow*);
+
+ public:
+ virtual ~Window();
+
+ WebCore::DOMWindow* impl() const { return m_impl.get(); }
+
+ void disconnectFrame();
+
+ // Returns and registers a window object. In case there's already a Window
+ // for the specified frame p this will be returned in order to have unique
+ // bindings.
+ static JSValue* retrieve(WebCore::Frame*);
+
+ // Returns the Window object for a given HTML frame
+ static Window* retrieveWindow(WebCore::Frame*);
+
+ // Returns a pointer to the Window object this javascript interpreting instance
+ // was called from.
+ static Window* retrieveActive(ExecState*);
+
+ virtual void mark();
+
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ JSValue* getValueProperty(ExecState*, int token) const;
+ virtual void put(ExecState*, const Identifier& propertyName, JSValue*);
+
+ int installTimeout(const UString& handler, int t, bool singleShot);
+ int installTimeout(JSValue* function, const List& args, int t, bool singleShot);
+ void clearTimeout(int timerId, bool delAction = true);
+ WebCore::PausedTimeouts* pauseTimeouts();
+ void resumeTimeouts(WebCore::PausedTimeouts*);
+
+ void timerFired(DOMWindowTimer*);
+
+ WebCore::JSLocation* location() const;
+
+ // Finds a wrapper of a JS EventListener, returns 0 if no existing one.
+ WebCore::JSEventListener* findJSEventListener(JSValue*, bool html = false);
+
+ // Finds or creates a wrapper of a JS EventListener. JS EventListener object is GC-protected.
+ WebCore::JSEventListener *findOrCreateJSEventListener(JSValue*, bool html = false);
+
+ // Finds a wrapper of a GC-unprotected JS EventListener, returns 0 if no existing one.
+ WebCore::JSUnprotectedEventListener* findJSUnprotectedEventListener(JSValue*, bool html = false);
+
+ // Finds or creates a wrapper of a JS EventListener. JS EventListener object is *NOT* GC-protected.
+ WebCore::JSUnprotectedEventListener *findOrCreateJSUnprotectedEventListener(JSValue*, bool html = false);
+
+ void clear();
+
+ void setCurrentEvent(WebCore::Event*);
+ WebCore::Event* currentEvent();
+
+ // Set a place to put a dialog return value when the window is cleared.
+ void setReturnValueSlot(JSValue** slot);
+
+ typedef HashMap<JSObject*, WebCore::JSEventListener*> ListenersMap;
+ typedef HashMap<JSObject*, WebCore::JSUnprotectedEventListener*> UnprotectedListenersMap;
+
+ ListenersMap& jsEventListeners();
+ ListenersMap& jsHTMLEventListeners();
+ UnprotectedListenersMap& jsUnprotectedEventListeners();
+ UnprotectedListenersMap& jsUnprotectedHTMLEventListeners();
+
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+
+ virtual ExecState* globalExec();
+
+ virtual bool shouldInterruptScript() const;
+
+ bool allowsAccessFrom(ExecState*) const;
+ bool allowsAccessFromNoErrorMessage(ExecState*) const;
+ bool allowsAccessFrom(ExecState*, WebCore::String& message) const;
+
+ void printErrorMessage(const WebCore::String&) const;
+
+ // Don't call this version of allowsAccessFrom -- it's a slightly incorrect implementation used only by WebScriptObject
+ virtual bool allowsAccessFrom(const JSGlobalObject*) const;
+
+ enum {
+ // Attributes
+ Crypto, Event_, Location_, Navigator_,
+ ClientInformation,
+
+ // Event Listeners
+ Onabort, Onblur, Onchange, Onclick,
+ Ondblclick, Onerror, Onfocus, Onkeydown,
+ Onkeypress, Onkeyup, Onload, Onmousedown,
+ Onmousemove, Onmouseout, Onmouseover, Onmouseup,
+ OnWindowMouseWheel, Onreset, Onresize, Onscroll,
+ Onsearch, Onselect, Onsubmit, Onunload,
+ Onbeforeunload,
+
+ // Constructors
+ DOMException, Audio, Image, Option, XMLHttpRequest,
+ XSLTProcessor_
+ };
+
+ private:
+ JSValue* getListener(ExecState*, const WebCore::AtomicString& eventType) const;
+ void setListener(ExecState*, const WebCore::AtomicString& eventType, JSValue* func);
+
+ static JSValue* childFrameGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+ static JSValue* indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+ static JSValue* namedItemGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot&);
+
+ void clearHelperObjectProperties();
+ void clearAllTimeouts();
+ int installTimeout(WebCore::ScheduledAction*, int interval, bool singleShot);
+
+ bool allowsAccessFromPrivate(const JSGlobalObject*, WebCore::SecurityOrigin::Reason&) const;
+ bool allowsAccessFromPrivate(const ExecState*, WebCore::SecurityOrigin::Reason&) const;
+ WebCore::String crossDomainAccessErrorMessage(const JSGlobalObject*, WebCore::SecurityOrigin::Reason) const;
+
+ RefPtr<WebCore::DOMWindow> m_impl;
+ OwnPtr<WindowPrivate> d;
+ };
+
+ // Functions
+ JSValue* windowProtoFuncAToB(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncBToA(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncOpen(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncSetTimeout(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncClearTimeout(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncSetInterval(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncAddEventListener(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncRemoveEventListener(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncShowModalDialog(ExecState*, JSObject*, const List&);
+ JSValue* windowProtoFuncNotImplemented(ExecState*, JSObject*, const List&);
+
+} // namespace KJS
+
+namespace WebCore {
+ KJS::JSValue* toJS(KJS::ExecState*, DOMWindow*);
+} // namespace WebCore
+
+#endif // kjs_window_h
diff --git a/WebCore/bindings/objc/DOM.h b/WebCore/bindings/objc/DOM.h
new file mode 100644
index 0000000..a3d6201
--- /dev/null
+++ b/WebCore/bindings/objc/DOM.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCore.h>
+#import <WebCore/DOMCSS.h>
+#import <WebCore/DOMExtensions.h>
+#import <WebCore/DOMEvents.h>
+#import <WebCore/DOMHTML.h>
+#import <WebCore/DOMRanges.h>
+#import <WebCore/DOMStylesheets.h>
+#import <WebCore/DOMTraversal.h>
+#import <WebCore/DOMViews.h>
+#import <WebCore/DOMXPath.h>
diff --git a/WebCore/bindings/objc/DOM.mm b/WebCore/bindings/objc/DOM.mm
new file mode 100644
index 0000000..4c2605e
--- /dev/null
+++ b/WebCore/bindings/objc/DOM.mm
@@ -0,0 +1,815 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 James G. Speth (speth@end.com)
+ * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "DOM.h"
+
+#import "CDATASection.h"
+#import "CSSHelper.h"
+#import "CSSStyleSheet.h"
+#import "Comment.h"
+#import "DOMHTMLCanvasElement.h"
+#import "DOMInternal.h"
+#import "DOMPrivate.h"
+#import "Document.h"
+#import "DocumentFragment.h"
+#import "DocumentType.h"
+#import "EntityReference.h"
+#import "Event.h"
+#import "EventListener.h"
+#import "EventTarget.h"
+#import "ExceptionHandlers.h"
+#import "FoundationExtras.h"
+#import "Frame.h"
+#import "FrameView.h"
+#import "HTMLDocument.h"
+#import "HTMLNames.h"
+#import "HTMLPlugInElement.h"
+#import "Image.h"
+#import "IntRect.h"
+#import "NodeFilter.h"
+#import "NodeFilterCondition.h"
+#import "NodeIterator.h"
+#import "NodeList.h"
+#import "ProcessingInstruction.h"
+#import "QualifiedName.h"
+#import "Range.h"
+#import "RenderImage.h"
+#import "RenderView.h"
+#import "SimpleFontData.h"
+#import "Text.h"
+#import "TreeWalker.h"
+#import "WebScriptObjectPrivate.h"
+#import <objc/objc-class.h>
+#import <wtf/HashMap.h>
+
+#if ENABLE(SVG)
+#import "SVGDocument.h"
+#import "SVGElement.h"
+#import "SVGNames.h"
+#import "DOMSVG.h"
+#endif
+
+using namespace KJS;
+using namespace WebCore;
+
+namespace WebCore {
+
+class ObjCEventListener : public EventListener {
+public:
+ static ObjCEventListener* find(id <DOMEventListener>);
+ static ObjCEventListener* create(id <DOMEventListener>);
+
+private:
+ ObjCEventListener(id <DOMEventListener>);
+ virtual ~ObjCEventListener();
+
+ virtual void handleEvent(Event*, bool isWindowEvent);
+
+ id <DOMEventListener> m_listener;
+};
+
+typedef HashMap<id, ObjCEventListener*> ListenerMap;
+static ListenerMap* listenerMap;
+
+} // namespace WebCore
+
+
+//------------------------------------------------------------------------------------------
+// DOMNode
+
+namespace WebCore {
+
+typedef HashMap<const QualifiedName::QualifiedNameImpl*, Class> ObjCClassMap;
+static ObjCClassMap* elementClassMap;
+
+static void addElementClass(const QualifiedName& tag, Class objCClass)
+{
+ elementClassMap->set(tag.impl(), objCClass);
+}
+
+static void createElementClassMap()
+{
+ // Create the table.
+ elementClassMap = new ObjCClassMap;
+
+ // FIXME: Reflect marquee once the API has been determined.
+
+ // Populate it with HTML and SVG element classes.
+ addElementClass(HTMLNames::aTag, [DOMHTMLAnchorElement class]);
+ addElementClass(HTMLNames::appletTag, [DOMHTMLAppletElement class]);
+ addElementClass(HTMLNames::areaTag, [DOMHTMLAreaElement class]);
+ addElementClass(HTMLNames::baseTag, [DOMHTMLBaseElement class]);
+ addElementClass(HTMLNames::basefontTag, [DOMHTMLBaseFontElement class]);
+ addElementClass(HTMLNames::bodyTag, [DOMHTMLBodyElement class]);
+ addElementClass(HTMLNames::brTag, [DOMHTMLBRElement class]);
+ addElementClass(HTMLNames::buttonTag, [DOMHTMLButtonElement class]);
+ addElementClass(HTMLNames::canvasTag, [DOMHTMLCanvasElement class]);
+ addElementClass(HTMLNames::captionTag, [DOMHTMLTableCaptionElement class]);
+ addElementClass(HTMLNames::colTag, [DOMHTMLTableColElement class]);
+ addElementClass(HTMLNames::colgroupTag, [DOMHTMLTableColElement class]);
+ addElementClass(HTMLNames::delTag, [DOMHTMLModElement class]);
+ addElementClass(HTMLNames::dirTag, [DOMHTMLDirectoryElement class]);
+ addElementClass(HTMLNames::divTag, [DOMHTMLDivElement class]);
+ addElementClass(HTMLNames::dlTag, [DOMHTMLDListElement class]);
+ addElementClass(HTMLNames::embedTag, [DOMHTMLEmbedElement class]);
+ addElementClass(HTMLNames::fieldsetTag, [DOMHTMLFieldSetElement class]);
+ addElementClass(HTMLNames::fontTag, [DOMHTMLFontElement class]);
+ addElementClass(HTMLNames::formTag, [DOMHTMLFormElement class]);
+ addElementClass(HTMLNames::frameTag, [DOMHTMLFrameElement class]);
+ addElementClass(HTMLNames::framesetTag, [DOMHTMLFrameSetElement class]);
+ addElementClass(HTMLNames::h1Tag, [DOMHTMLHeadingElement class]);
+ addElementClass(HTMLNames::h2Tag, [DOMHTMLHeadingElement class]);
+ addElementClass(HTMLNames::h3Tag, [DOMHTMLHeadingElement class]);
+ addElementClass(HTMLNames::h4Tag, [DOMHTMLHeadingElement class]);
+ addElementClass(HTMLNames::h5Tag, [DOMHTMLHeadingElement class]);
+ addElementClass(HTMLNames::h6Tag, [DOMHTMLHeadingElement class]);
+ addElementClass(HTMLNames::headTag, [DOMHTMLHeadElement class]);
+ addElementClass(HTMLNames::hrTag, [DOMHTMLHRElement class]);
+ addElementClass(HTMLNames::htmlTag, [DOMHTMLHtmlElement class]);
+ addElementClass(HTMLNames::iframeTag, [DOMHTMLIFrameElement class]);
+ addElementClass(HTMLNames::imgTag, [DOMHTMLImageElement class]);
+ addElementClass(HTMLNames::inputTag, [DOMHTMLInputElement class]);
+ addElementClass(HTMLNames::insTag, [DOMHTMLModElement class]);
+ addElementClass(HTMLNames::isindexTag, [DOMHTMLIsIndexElement class]);
+ addElementClass(HTMLNames::labelTag, [DOMHTMLLabelElement class]);
+ addElementClass(HTMLNames::legendTag, [DOMHTMLLegendElement class]);
+ addElementClass(HTMLNames::liTag, [DOMHTMLLIElement class]);
+ addElementClass(HTMLNames::linkTag, [DOMHTMLLinkElement class]);
+ addElementClass(HTMLNames::listingTag, [DOMHTMLPreElement class]);
+ addElementClass(HTMLNames::mapTag, [DOMHTMLMapElement class]);
+ addElementClass(HTMLNames::marqueeTag, [DOMHTMLMarqueeElement class]);
+ addElementClass(HTMLNames::menuTag, [DOMHTMLMenuElement class]);
+ addElementClass(HTMLNames::metaTag, [DOMHTMLMetaElement class]);
+ addElementClass(HTMLNames::objectTag, [DOMHTMLObjectElement class]);
+ addElementClass(HTMLNames::olTag, [DOMHTMLOListElement class]);
+ addElementClass(HTMLNames::optgroupTag, [DOMHTMLOptGroupElement class]);
+ addElementClass(HTMLNames::optionTag, [DOMHTMLOptionElement class]);
+ addElementClass(HTMLNames::pTag, [DOMHTMLParagraphElement class]);
+ addElementClass(HTMLNames::paramTag, [DOMHTMLParamElement class]);
+ addElementClass(HTMLNames::preTag, [DOMHTMLPreElement class]);
+ addElementClass(HTMLNames::qTag, [DOMHTMLQuoteElement class]);
+ addElementClass(HTMLNames::scriptTag, [DOMHTMLScriptElement class]);
+ addElementClass(HTMLNames::keygenTag, [DOMHTMLSelectElement class]);
+ addElementClass(HTMLNames::selectTag, [DOMHTMLSelectElement class]);
+ addElementClass(HTMLNames::styleTag, [DOMHTMLStyleElement class]);
+ addElementClass(HTMLNames::tableTag, [DOMHTMLTableElement class]);
+ addElementClass(HTMLNames::tbodyTag, [DOMHTMLTableSectionElement class]);
+ addElementClass(HTMLNames::tdTag, [DOMHTMLTableCellElement class]);
+ addElementClass(HTMLNames::textareaTag, [DOMHTMLTextAreaElement class]);
+ addElementClass(HTMLNames::tfootTag, [DOMHTMLTableSectionElement class]);
+ addElementClass(HTMLNames::thTag, [DOMHTMLTableCellElement class]);
+ addElementClass(HTMLNames::theadTag, [DOMHTMLTableSectionElement class]);
+ addElementClass(HTMLNames::titleTag, [DOMHTMLTitleElement class]);
+ addElementClass(HTMLNames::trTag, [DOMHTMLTableRowElement class]);
+ addElementClass(HTMLNames::ulTag, [DOMHTMLUListElement class]);
+ addElementClass(HTMLNames::xmpTag, [DOMHTMLPreElement class]);
+
+#if ENABLE(SVG)
+ addElementClass(SVGNames::aTag, [DOMSVGAElement class]);
+#if ENABLE(SVG_ANIMATION)
+ addElementClass(SVGNames::animateTag, [DOMSVGAnimateElement class]);
+ addElementClass(SVGNames::animateColorTag, [DOMSVGAnimateColorElement class]);
+ addElementClass(SVGNames::animateTransformTag, [DOMSVGAnimateTransformElement class]);
+#endif
+ addElementClass(SVGNames::circleTag, [DOMSVGCircleElement class]);
+ addElementClass(SVGNames::clipPathTag, [DOMSVGClipPathElement class]);
+ addElementClass(SVGNames::cursorTag, [DOMSVGCursorElement class]);
+#if ENABLE(SVG_FONTS)
+ addElementClass(SVGNames::definition_srcTag, [DOMSVGDefinitionSrcElement class]);
+#endif
+ addElementClass(SVGNames::defsTag, [DOMSVGDefsElement class]);
+ addElementClass(SVGNames::descTag, [DOMSVGDescElement class]);
+ addElementClass(SVGNames::ellipseTag, [DOMSVGEllipseElement class]);
+#if ENABLE(SVG_FILTERS)
+ addElementClass(SVGNames::feBlendTag, [DOMSVGFEBlendElement class]);
+ addElementClass(SVGNames::feColorMatrixTag, [DOMSVGFEColorMatrixElement class]);
+ addElementClass(SVGNames::feComponentTransferTag, [DOMSVGFEComponentTransferElement class]);
+ addElementClass(SVGNames::feCompositeTag, [DOMSVGFECompositeElement class]);
+ addElementClass(SVGNames::feDiffuseLightingTag, [DOMSVGFEDiffuseLightingElement class]);
+ addElementClass(SVGNames::feDisplacementMapTag, [DOMSVGFEDisplacementMapElement class]);
+ addElementClass(SVGNames::feDistantLightTag, [DOMSVGFEDistantLightElement class]);
+ addElementClass(SVGNames::feFloodTag, [DOMSVGFEFloodElement class]);
+ addElementClass(SVGNames::feFuncATag, [DOMSVGFEFuncAElement class]);
+ addElementClass(SVGNames::feFuncBTag, [DOMSVGFEFuncBElement class]);
+ addElementClass(SVGNames::feFuncGTag, [DOMSVGFEFuncGElement class]);
+ addElementClass(SVGNames::feFuncRTag, [DOMSVGFEFuncRElement class]);
+ addElementClass(SVGNames::feGaussianBlurTag, [DOMSVGFEGaussianBlurElement class]);
+ addElementClass(SVGNames::feImageTag, [DOMSVGFEImageElement class]);
+ addElementClass(SVGNames::feMergeTag, [DOMSVGFEMergeElement class]);
+ addElementClass(SVGNames::feMergeNodeTag, [DOMSVGFEMergeNodeElement class]);
+ addElementClass(SVGNames::feOffsetTag, [DOMSVGFEOffsetElement class]);
+ addElementClass(SVGNames::fePointLightTag, [DOMSVGFEPointLightElement class]);
+ addElementClass(SVGNames::feSpecularLightingTag, [DOMSVGFESpecularLightingElement class]);
+ addElementClass(SVGNames::feSpotLightTag, [DOMSVGFESpotLightElement class]);
+ addElementClass(SVGNames::feTileTag, [DOMSVGFETileElement class]);
+ addElementClass(SVGNames::feTurbulenceTag, [DOMSVGFETurbulenceElement class]);
+ addElementClass(SVGNames::filterTag, [DOMSVGFilterElement class]);
+#endif
+#if ENABLE(SVG_FONTS)
+ addElementClass(SVGNames::fontTag, [DOMSVGFontElement class]);
+ addElementClass(SVGNames::font_faceTag, [DOMSVGFontFaceElement class]);
+ addElementClass(SVGNames::font_face_formatTag, [DOMSVGFontFaceFormatElement class]);
+ addElementClass(SVGNames::font_face_nameTag, [DOMSVGFontFaceNameElement class]);
+ addElementClass(SVGNames::font_face_srcTag, [DOMSVGFontFaceSrcElement class]);
+ addElementClass(SVGNames::font_face_uriTag, [DOMSVGFontFaceUriElement class]);
+ addElementClass(SVGNames::glyphTag, [DOMSVGGlyphElement class]);
+#endif
+ addElementClass(SVGNames::gTag, [DOMSVGGElement class]);
+ addElementClass(SVGNames::imageTag, [DOMSVGImageElement class]);
+ addElementClass(SVGNames::lineTag, [DOMSVGLineElement class]);
+ addElementClass(SVGNames::linearGradientTag, [DOMSVGLinearGradientElement class]);
+ addElementClass(SVGNames::markerTag, [DOMSVGMarkerElement class]);
+ addElementClass(SVGNames::maskTag, [DOMSVGMaskElement class]);
+ addElementClass(SVGNames::metadataTag, [DOMSVGMetadataElement class]);
+#if ENABLE(SVG_FONTS)
+ addElementClass(SVGNames::missing_glyphTag, [DOMSVGMissingGlyphElement class]);
+#endif
+ addElementClass(SVGNames::pathTag, [DOMSVGPathElement class]);
+ addElementClass(SVGNames::patternTag, [DOMSVGPatternElement class]);
+ addElementClass(SVGNames::polygonTag, [DOMSVGPolygonElement class]);
+ addElementClass(SVGNames::polylineTag, [DOMSVGPolylineElement class]);
+ addElementClass(SVGNames::radialGradientTag, [DOMSVGRadialGradientElement class]);
+ addElementClass(SVGNames::rectTag, [DOMSVGRectElement class]);
+ addElementClass(SVGNames::scriptTag, [DOMSVGScriptElement class]);
+ addElementClass(SVGNames::setTag, [DOMSVGSetElement class]);
+ addElementClass(SVGNames::stopTag, [DOMSVGStopElement class]);
+ addElementClass(SVGNames::styleTag, [DOMSVGStyleElement class]);
+ addElementClass(SVGNames::svgTag, [DOMSVGSVGElement class]);
+ addElementClass(SVGNames::switchTag, [DOMSVGSwitchElement class]);
+ addElementClass(SVGNames::symbolTag, [DOMSVGSymbolElement class]);
+ addElementClass(SVGNames::textTag, [DOMSVGTextElement class]);
+ addElementClass(SVGNames::titleTag, [DOMSVGTitleElement class]);
+ addElementClass(SVGNames::trefTag, [DOMSVGTRefElement class]);
+ addElementClass(SVGNames::tspanTag, [DOMSVGTSpanElement class]);
+ addElementClass(SVGNames::textPathTag, [DOMSVGTextPathElement class]);
+ addElementClass(SVGNames::useTag, [DOMSVGUseElement class]);
+ addElementClass(SVGNames::viewTag, [DOMSVGViewElement class]);
+#endif
+}
+
+static Class lookupElementClass(const QualifiedName& tag)
+{
+ // Do a special lookup to ignore element prefixes
+ if (tag.hasPrefix())
+ return elementClassMap->get(QualifiedName(nullAtom, tag.localName(), tag.namespaceURI()).impl());
+
+ return elementClassMap->get(tag.impl());
+}
+
+static Class elementClass(const QualifiedName& tag, Class defaultClass)
+{
+ if (!elementClassMap)
+ createElementClassMap();
+ Class objcClass = lookupElementClass(tag);
+ if (!objcClass)
+ objcClass = defaultClass;
+ return objcClass;
+}
+
+static NSArray *kit(const Vector<IntRect>& rects)
+{
+ size_t size = rects.size();
+ NSMutableArray *array = [NSMutableArray arrayWithCapacity:size];
+ for (size_t i = 0; i < size; ++i)
+ [array addObject:[NSValue valueWithRect:rects[i]]];
+ return array;
+}
+
+} // namespace WebCore
+
+@implementation DOMNode (WebCoreInternal)
+
+// FIXME: should this go in the main implementation?
+- (NSString *)description
+{
+ if (!_internal)
+ return [NSString stringWithFormat:@"<%@: null>", [[self class] description], self];
+
+ NSString *value = [self nodeValue];
+ if (value)
+ return [NSString stringWithFormat:@"<%@ [%@]: %p '%@'>",
+ [[self class] description], [self nodeName], _internal, value];
+
+ return [NSString stringWithFormat:@"<%@ [%@]: %p>", [[self class] description], [self nodeName], _internal];
+}
+
+- (id)_initWithNode:(WebCore::Node *)impl
+{
+ ASSERT(impl);
+
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMNode *)_wrapNode:(WebCore::Node *)impl
+{
+ if (!impl)
+ return nil;
+
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ Class wrapperClass = nil;
+ switch (impl->nodeType()) {
+ case WebCore::Node::ELEMENT_NODE:
+ if (impl->isHTMLElement())
+ wrapperClass = WebCore::elementClass(static_cast<WebCore::HTMLElement*>(impl)->tagQName(), [DOMHTMLElement class]);
+#if ENABLE(SVG)
+ else if (impl->isSVGElement())
+ wrapperClass = WebCore::elementClass(static_cast<WebCore::SVGElement*>(impl)->tagQName(), [DOMSVGElement class]);
+#endif
+ else
+ wrapperClass = [DOMElement class];
+ break;
+ case WebCore::Node::ATTRIBUTE_NODE:
+ wrapperClass = [DOMAttr class];
+ break;
+ case WebCore::Node::TEXT_NODE:
+ wrapperClass = [DOMText class];
+ break;
+ case WebCore::Node::CDATA_SECTION_NODE:
+ wrapperClass = [DOMCDATASection class];
+ break;
+ case WebCore::Node::ENTITY_REFERENCE_NODE:
+ wrapperClass = [DOMEntityReference class];
+ break;
+ case WebCore::Node::ENTITY_NODE:
+ wrapperClass = [DOMEntity class];
+ break;
+ case WebCore::Node::PROCESSING_INSTRUCTION_NODE:
+ wrapperClass = [DOMProcessingInstruction class];
+ break;
+ case WebCore::Node::COMMENT_NODE:
+ wrapperClass = [DOMComment class];
+ break;
+ case WebCore::Node::DOCUMENT_NODE:
+ if (static_cast<WebCore::Document*>(impl)->isHTMLDocument())
+ wrapperClass = [DOMHTMLDocument class];
+#if ENABLE(SVG)
+ else if (static_cast<WebCore::Document*>(impl)->isSVGDocument())
+ wrapperClass = [DOMSVGDocument class];
+#endif
+ else
+ wrapperClass = [DOMDocument class];
+ break;
+ case WebCore::Node::DOCUMENT_TYPE_NODE:
+ wrapperClass = [DOMDocumentType class];
+ break;
+ case WebCore::Node::DOCUMENT_FRAGMENT_NODE:
+ wrapperClass = [DOMDocumentFragment class];
+ break;
+ case WebCore::Node::NOTATION_NODE:
+ wrapperClass = [DOMNotation class];
+ break;
+ case WebCore::Node::XPATH_NAMESPACE_NODE:
+ // FIXME: Create an XPath objective C wrapper
+ // See http://bugs.webkit.org/show_bug.cgi?id=8755
+ return nil;
+ }
+ return [[[wrapperClass alloc] _initWithNode:impl] autorelease];
+}
+
++ (id <DOMEventTarget>)_wrapEventTarget:(WebCore::EventTarget *)eventTarget
+{
+ if (!eventTarget)
+ return nil;
+
+ // We don't have an ObjC binding for XMLHttpRequest
+ return [DOMNode _wrapNode:eventTarget->toNode()];
+}
+
+- (WebCore::Node *)_node
+{
+ return reinterpret_cast<WebCore::Node*>(_internal);
+}
+
+- (KJS::Bindings::RootObject*)_rootObject
+{
+ if (WebCore::Node *n = [self _node]) {
+ if (WebCore::Frame* frame = n->document()->frame())
+ return frame->bindingRootObject();
+ }
+ return 0;
+}
+
+@end
+
+@implementation DOMNode (DOMNodeExtensions)
+
+// FIXME: This should be implemented in Node so we don't have to fetch the renderer.
+// If it was, we could even autogenerate.
+- (NSRect)boundingBox
+{
+ [self _node]->document()->updateLayoutIgnorePendingStylesheets();
+ WebCore::RenderObject *renderer = [self _node]->renderer();
+ if (renderer)
+ return renderer->absoluteBoundingBoxRect();
+ return NSZeroRect;
+}
+
+// FIXME: This should be implemented in Node so we don't have to fetch the renderer.
+// If it was, we could even autogenerate.
+- (NSArray *)lineBoxRects
+{
+ [self _node]->document()->updateLayoutIgnorePendingStylesheets();
+ WebCore::RenderObject *renderer = [self _node]->renderer();
+ if (renderer) {
+ Vector<WebCore::IntRect> rects;
+ renderer->addLineBoxRects(rects);
+ return kit(rects);
+ }
+ return nil;
+}
+
+@end
+
+@implementation DOMRange (DOMRangeExtensions)
+
+- (NSRect)boundingBox
+{
+ [self _range]->ownerDocument()->updateLayoutIgnorePendingStylesheets();
+ return [self _range]->boundingBox();
+}
+
+- (NSArray *)lineBoxRects
+{
+ Vector<WebCore::IntRect> rects;
+ [self _range]->ownerDocument()->updateLayoutIgnorePendingStylesheets();
+ [self _range]->addLineBoxRects(rects);
+ return kit(rects);
+}
+
+@end
+
+// FIXME: this should be auto-generated
+@implementation DOMNode (DOMEventTarget)
+
+- (void)addEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture
+{
+ if (![self _node]->isEventTargetNode())
+ WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR);
+
+ WebCore::EventListener *wrapper = WebCore::ObjCEventListener::create(listener);
+ WebCore::EventTargetNodeCast([self _node])->addEventListener(type, wrapper, useCapture);
+ wrapper->deref();
+}
+
+- (void)addEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
+{
+ // FIXME: this method can be removed once Mail changes to use the new method <rdar://problem/4746649>
+ [self addEventListener:type listener:listener useCapture:useCapture];
+}
+
+- (void)removeEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture
+{
+ if (![self _node]->isEventTargetNode())
+ WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR);
+
+ if (WebCore::EventListener *wrapper = WebCore::ObjCEventListener::find(listener))
+ WebCore::EventTargetNodeCast([self _node])->removeEventListener(type, wrapper, useCapture);
+}
+
+- (void)removeEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture
+{
+ // FIXME: this method can be removed once Mail changes to use the new method <rdar://problem/4746649>
+ [self removeEventListener:type listener:listener useCapture:useCapture];
+}
+
+- (BOOL)dispatchEvent:(DOMEvent *)event
+{
+ if (![self _node]->isEventTargetNode())
+ WebCore::raiseDOMException(DOM_NOT_SUPPORTED_ERR);
+
+ WebCore::ExceptionCode ec = 0;
+ BOOL result = WebCore::EventTargetNodeCast([self _node])->dispatchEvent([event _event], ec);
+ WebCore::raiseOnDOMError(ec);
+ return result;
+}
+
+@end
+
+//------------------------------------------------------------------------------------------
+// DOMElement
+
+// FIXME: this should be auto-generated in DOMElement.mm
+@implementation DOMElement (DOMElementAppKitExtensions)
+
+// FIXME: this should be implemented in the implementation
+- (NSImage*)image
+{
+ WebCore::RenderObject* renderer = [self _element]->renderer();
+ if (renderer && renderer->isImage()) {
+ WebCore::RenderImage* img = static_cast<WebCore::RenderImage*>(renderer);
+ if (img->cachedImage() && !img->cachedImage()->errorOccurred())
+ return img->cachedImage()->image()->getNSImage();
+ }
+ return nil;
+}
+
+@end
+
+@implementation DOMElement (WebPrivate)
+
+// FIXME: this should be implemented in the implementation
+- (NSFont *)_font
+{
+ WebCore::RenderObject* renderer = [self _element]->renderer();
+ if (renderer)
+ return renderer->style()->font().primaryFont()->getNSFont();
+ return nil;
+}
+
+// FIXME: this should be implemented in the implementation
+- (NSData *)_imageTIFFRepresentation
+{
+ WebCore::RenderObject* renderer = [self _element]->renderer();
+ if (renderer && renderer->isImage()) {
+ WebCore::RenderImage* img = static_cast<WebCore::RenderImage*>(renderer);
+ if (img->cachedImage() && !img->cachedImage()->errorOccurred())
+ return (NSData*)(img->cachedImage()->image()->getTIFFRepresentation());
+ }
+ return nil;
+}
+
+- (NSRect)_windowClipRect
+{
+ WebCore::RenderObject* renderer = [self _element]->renderer();
+ if (renderer && renderer->view()) {
+ WebCore::FrameView* frameView = renderer->view()->frameView();
+ if (!frameView)
+ return WebCore::IntRect();
+ return frameView->windowClipRectForLayer(renderer->enclosingLayer(), true);
+ }
+ return WebCore::IntRect();
+}
+
+// FIXME: this should be implemented in the implementation
+- (NSURL *)_getURLAttribute:(NSString *)name
+{
+ ASSERT(name);
+ WebCore::Element* element = [self _element];
+ ASSERT(element);
+ return element->document()->completeURL(parseURL(element->getAttribute(name)));
+}
+
+// FIXME: this should be implemented in the implementation
+- (void *)_NPObject
+{
+#if USE(NPOBJECT)
+ WebCore::Element* element = [self _element];
+ if (element->hasTagName(WebCore::HTMLNames::appletTag) || element->hasTagName(WebCore::HTMLNames::embedTag) || element->hasTagName(WebCore::HTMLNames::objectTag))
+ return static_cast<WebCore::HTMLPlugInElement*>(element)->getNPObject();
+#endif
+ return 0;
+}
+
+// FIXME: this should be implemented in the implementation
+- (BOOL)isFocused
+{
+ WebCore::Element* impl = [self _element];
+ if (impl->document()->focusedNode() == impl)
+ return YES;
+ return NO;
+}
+
+@end
+
+
+//------------------------------------------------------------------------------------------
+// DOMRange
+
+@implementation DOMRange (WebPrivate)
+
+- (NSString *)description
+{
+ if (!_internal)
+ return @"<DOMRange: null>";
+ return [NSString stringWithFormat:@"<DOMRange: %@ %d %@ %d>",
+ [self startContainer], [self startOffset], [self endContainer], [self endOffset]];
+}
+
+// FIXME: this should be removed as soon as all internal Apple uses of it have been replaced with
+// calls to the public method - (NSString *)text.
+- (NSString *)_text
+{
+ return [self text];
+}
+
+@end
+
+
+//------------------------------------------------------------------------------------------
+// DOMNodeFilter
+
+// FIXME: This implementation should be in it's own file.
+
+@implementation DOMNodeFilter
+
+- (id)_initWithNodeFilter:(WebCore::NodeFilter *)impl
+{
+ ASSERT(impl);
+
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMNodeFilter *)_wrapNodeFilter:(WebCore::NodeFilter *)impl
+{
+ if (!impl)
+ return nil;
+
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ return [[[self alloc] _initWithNodeFilter:impl] autorelease];
+}
+
+- (WebCore::NodeFilter *)_nodeFilter
+{
+ return reinterpret_cast<WebCore::NodeFilter*>(_internal);
+}
+
+- (void)dealloc
+{
+ if (_internal)
+ reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref();
+ [super dealloc];
+}
+
+- (void)finalize
+{
+ if (_internal)
+ reinterpret_cast<WebCore::NodeFilter*>(_internal)->deref();
+ [super finalize];
+}
+
+- (short)acceptNode:(DOMNode *)node
+{
+ return [self _nodeFilter]->acceptNode([node _node]);
+}
+
+@end
+
+//------------------------------------------------------------------------------------------
+// ObjCNodeFilterCondition
+
+namespace WebCore {
+
+class ObjCNodeFilterCondition : public NodeFilterCondition {
+public:
+ ObjCNodeFilterCondition(id <DOMNodeFilter>);
+ virtual ~ObjCNodeFilterCondition();
+ virtual short acceptNode(Node*, JSValue*& exception) const;
+
+private:
+ ObjCNodeFilterCondition(const ObjCNodeFilterCondition&);
+ ObjCNodeFilterCondition &operator=(const ObjCNodeFilterCondition&);
+
+ id <DOMNodeFilter> m_filter;
+};
+
+ObjCNodeFilterCondition::ObjCNodeFilterCondition(id <DOMNodeFilter> filter)
+ : m_filter(filter)
+{
+ ASSERT(m_filter);
+ HardRetain(m_filter);
+}
+
+ObjCNodeFilterCondition::~ObjCNodeFilterCondition()
+{
+ HardRelease(m_filter);
+}
+
+short ObjCNodeFilterCondition::acceptNode(Node* node, JSValue*&) const
+{
+ if (!node)
+ return NodeFilter::FILTER_REJECT;
+ return [m_filter acceptNode:[DOMNode _wrapNode:node]];
+}
+
+} // namespace WebCore
+
+//------------------------------------------------------------------------------------------
+// DOMDocument (DOMDocumentTraversal)
+
+// FIXME: this should be auto-generated in DOMDocument.mm
+@implementation DOMDocument (DOMDocumentTraversal)
+
+- (DOMNodeIterator *)createNodeIterator:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences
+{
+ RefPtr<NodeFilter> cppFilter;
+ if (filter)
+ cppFilter = new NodeFilter(new ObjCNodeFilterCondition(filter));
+ ExceptionCode ec = 0;
+ RefPtr<NodeIterator> impl = [self _document]->createNodeIterator([root _node], whatToShow, cppFilter.release(), expandEntityReferences, ec);
+ raiseOnDOMError(ec);
+ return [DOMNodeIterator _wrapNodeIterator:impl.get() filter:filter];
+}
+
+- (DOMTreeWalker *)createTreeWalker:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences
+{
+ RefPtr<NodeFilter> cppFilter;
+ if (filter)
+ cppFilter = new NodeFilter(new ObjCNodeFilterCondition(filter));
+ ExceptionCode ec = 0;
+ RefPtr<TreeWalker> impl = [self _document]->createTreeWalker([root _node], whatToShow, cppFilter.release(), expandEntityReferences, ec);
+ raiseOnDOMError(ec);
+ return [DOMTreeWalker _wrapTreeWalker:impl.get() filter:filter];
+}
+
+@end
+
+@implementation DOMDocument (DOMDocumentTraversalDeprecated)
+
+- (DOMNodeIterator *)createNodeIterator:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
+{
+ return [self createNodeIterator:root whatToShow:whatToShow filter:filter expandEntityReferences:expandEntityReferences];
+}
+
+- (DOMTreeWalker *)createTreeWalker:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences
+{
+ return [self createTreeWalker:root whatToShow:whatToShow filter:filter expandEntityReferences:expandEntityReferences];
+}
+
+@end
+
+
+//------------------------------------------------------------------------------------------
+// ObjCEventListener
+
+namespace WebCore {
+
+ObjCEventListener* ObjCEventListener::find(id <DOMEventListener> listener)
+{
+ if (ListenerMap* map = listenerMap)
+ return map->get(listener);
+ return 0;
+}
+
+ObjCEventListener *ObjCEventListener::create(id <DOMEventListener> listener)
+{
+ ObjCEventListener* wrapper = find(listener);
+ if (!wrapper)
+ wrapper = new ObjCEventListener(listener);
+ wrapper->ref();
+ return wrapper;
+}
+
+ObjCEventListener::ObjCEventListener(id <DOMEventListener> listener)
+ : m_listener([listener retain])
+{
+ ListenerMap* map = listenerMap;
+ if (!map) {
+ map = new ListenerMap;
+ listenerMap = map;
+ }
+ map->set(listener, this);
+}
+
+ObjCEventListener::~ObjCEventListener()
+{
+ listenerMap->remove(m_listener);
+ [m_listener release];
+}
+
+void ObjCEventListener::handleEvent(Event* event, bool)
+{
+ [m_listener handleEvent:[DOMEvent _wrapEvent:event]];
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/objc/DOMCSS.h b/WebCore/bindings/objc/DOMCSS.h
new file mode 100644
index 0000000..7bae9ed
--- /dev/null
+++ b/WebCore/bindings/objc/DOMCSS.h
@@ -0,0 +1,296 @@
+/*
+ * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCore.h>
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMElement.h>
+#import <WebCore/DOMObject.h>
+#import <WebCore/DOMStylesheets.h>
+
+#import <WebCore/DOMCSSCharsetRule.h>
+#import <WebCore/DOMCSSFontFaceRule.h>
+#import <WebCore/DOMCSSImportRule.h>
+#import <WebCore/DOMCSSMediaRule.h>
+#import <WebCore/DOMCSSPageRule.h>
+#import <WebCore/DOMCSSPrimitiveValue.h>
+#import <WebCore/DOMCSSRule.h>
+#import <WebCore/DOMCSSRuleList.h>
+#import <WebCore/DOMCSSStyleDeclaration.h>
+#import <WebCore/DOMCSSStyleRule.h>
+#import <WebCore/DOMCSSStyleSheet.h>
+#import <WebCore/DOMCSSUnknownRule.h>
+#import <WebCore/DOMCSSValue.h>
+#import <WebCore/DOMCSSValueList.h>
+#import <WebCore/DOMCounter.h>
+#import <WebCore/DOMRGBColor.h>
+#import <WebCore/DOMRect.h>
+
+@interface DOMCSSStyleDeclaration (DOMCSS2Properties)
+- (NSString *)azimuth;
+- (void)setAzimuth:(NSString *)azimuth;
+- (NSString *)background;
+- (void)setBackground:(NSString *)background;
+- (NSString *)backgroundAttachment;
+- (void)setBackgroundAttachment:(NSString *)backgroundAttachment;
+- (NSString *)backgroundColor;
+- (void)setBackgroundColor:(NSString *)backgroundColor;
+- (NSString *)backgroundImage;
+- (void)setBackgroundImage:(NSString *)backgroundImage;
+- (NSString *)backgroundPosition;
+- (void)setBackgroundPosition:(NSString *)backgroundPosition;
+- (NSString *)backgroundRepeat;
+- (void)setBackgroundRepeat:(NSString *)backgroundRepeat;
+- (NSString *)border;
+- (void)setBorder:(NSString *)border;
+- (NSString *)borderCollapse;
+- (void)setBorderCollapse:(NSString *)borderCollapse;
+- (NSString *)borderColor;
+- (void)setBorderColor:(NSString *)borderColor;
+- (NSString *)borderSpacing;
+- (void)setBorderSpacing:(NSString *)borderSpacing;
+- (NSString *)borderStyle;
+- (void)setBorderStyle:(NSString *)borderStyle;
+- (NSString *)borderTop;
+- (void)setBorderTop:(NSString *)borderTop;
+- (NSString *)borderRight;
+- (void)setBorderRight:(NSString *)borderRight;
+- (NSString *)borderBottom;
+- (void)setBorderBottom:(NSString *)borderBottom;
+- (NSString *)borderLeft;
+- (void)setBorderLeft:(NSString *)borderLeft;
+- (NSString *)borderTopColor;
+- (void)setBorderTopColor:(NSString *)borderTopColor;
+- (NSString *)borderRightColor;
+- (void)setBorderRightColor:(NSString *)borderRightColor;
+- (NSString *)borderBottomColor;
+- (void)setBorderBottomColor:(NSString *)borderBottomColor;
+- (NSString *)borderLeftColor;
+- (void)setBorderLeftColor:(NSString *)borderLeftColor;
+- (NSString *)borderTopStyle;
+- (void)setBorderTopStyle:(NSString *)borderTopStyle;
+- (NSString *)borderRightStyle;
+- (void)setBorderRightStyle:(NSString *)borderRightStyle;
+- (NSString *)borderBottomStyle;
+- (void)setBorderBottomStyle:(NSString *)borderBottomStyle;
+- (NSString *)borderLeftStyle;
+- (void)setBorderLeftStyle:(NSString *)borderLeftStyle;
+- (NSString *)borderTopWidth;
+- (void)setBorderTopWidth:(NSString *)borderTopWidth;
+- (NSString *)borderRightWidth;
+- (void)setBorderRightWidth:(NSString *)borderRightWidth;
+- (NSString *)borderBottomWidth;
+- (void)setBorderBottomWidth:(NSString *)borderBottomWidth;
+- (NSString *)borderLeftWidth;
+- (void)setBorderLeftWidth:(NSString *)borderLeftWidth;
+- (NSString *)borderWidth;
+- (void)setBorderWidth:(NSString *)borderWidth;
+- (NSString *)bottom;
+- (void)setBottom:(NSString *)bottom;
+- (NSString *)captionSide;
+- (void)setCaptionSide:(NSString *)captionSide;
+- (NSString *)clear;
+- (void)setClear:(NSString *)clear;
+- (NSString *)clip;
+- (void)setClip:(NSString *)clip;
+- (NSString *)color;
+- (void)setColor:(NSString *)color;
+- (NSString *)content;
+- (void)setContent:(NSString *)content;
+- (NSString *)counterIncrement;
+- (void)setCounterIncrement:(NSString *)counterIncrement;
+- (NSString *)counterReset;
+- (void)setCounterReset:(NSString *)counterReset;
+- (NSString *)cue;
+- (void)setCue:(NSString *)cue;
+- (NSString *)cueAfter;
+- (void)setCueAfter:(NSString *)cueAfter;
+- (NSString *)cueBefore;
+- (void)setCueBefore:(NSString *)cueBefore;
+- (NSString *)cursor;
+- (void)setCursor:(NSString *)cursor;
+- (NSString *)direction;
+- (void)setDirection:(NSString *)direction;
+- (NSString *)display;
+- (void)setDisplay:(NSString *)display;
+- (NSString *)elevation;
+- (void)setElevation:(NSString *)elevation;
+- (NSString *)emptyCells;
+- (void)setEmptyCells:(NSString *)emptyCells;
+- (NSString *)cssFloat;
+- (void)setCssFloat:(NSString *)cssFloat;
+- (NSString *)font;
+- (void)setFont:(NSString *)font;
+- (NSString *)fontFamily;
+- (void)setFontFamily:(NSString *)fontFamily;
+- (NSString *)fontSize;
+- (void)setFontSize:(NSString *)fontSize;
+- (NSString *)fontSizeAdjust;
+- (void)setFontSizeAdjust:(NSString *)fontSizeAdjust;
+- (NSString *)fontStretch;
+- (void)setFontStretch:(NSString *)fontStretch;
+- (NSString *)fontStyle;
+- (void)setFontStyle:(NSString *)fontStyle;
+- (NSString *)fontVariant;
+- (void)setFontVariant:(NSString *)fontVariant;
+- (NSString *)fontWeight;
+- (void)setFontWeight:(NSString *)fontWeight;
+- (NSString *)height;
+- (void)setHeight:(NSString *)height;
+- (NSString *)left;
+- (void)setLeft:(NSString *)left;
+- (NSString *)letterSpacing;
+- (void)setLetterSpacing:(NSString *)letterSpacing;
+- (NSString *)lineHeight;
+- (void)setLineHeight:(NSString *)lineHeight;
+- (NSString *)listStyle;
+- (void)setListStyle:(NSString *)listStyle;
+- (NSString *)listStyleImage;
+- (void)setListStyleImage:(NSString *)listStyleImage;
+- (NSString *)listStylePosition;
+- (void)setListStylePosition:(NSString *)listStylePosition;
+- (NSString *)listStyleType;
+- (void)setListStyleType:(NSString *)listStyleType;
+- (NSString *)margin;
+- (void)setMargin:(NSString *)margin;
+- (NSString *)marginTop;
+- (void)setMarginTop:(NSString *)marginTop;
+- (NSString *)marginRight;
+- (void)setMarginRight:(NSString *)marginRight;
+- (NSString *)marginBottom;
+- (void)setMarginBottom:(NSString *)marginBottom;
+- (NSString *)marginLeft;
+- (void)setMarginLeft:(NSString *)marginLeft;
+- (NSString *)markerOffset;
+- (void)setMarkerOffset:(NSString *)markerOffset;
+- (NSString *)marks;
+- (void)setMarks:(NSString *)marks;
+- (NSString *)maxHeight;
+- (void)setMaxHeight:(NSString *)maxHeight;
+- (NSString *)maxWidth;
+- (void)setMaxWidth:(NSString *)maxWidth;
+- (NSString *)minHeight;
+- (void)setMinHeight:(NSString *)minHeight;
+- (NSString *)minWidth;
+- (void)setMinWidth:(NSString *)minWidth;
+- (NSString *)orphans;
+- (void)setOrphans:(NSString *)orphans;
+- (NSString *)outline;
+- (void)setOutline:(NSString *)outline;
+- (NSString *)outlineColor;
+- (void)setOutlineColor:(NSString *)outlineColor;
+- (NSString *)outlineStyle;
+- (void)setOutlineStyle:(NSString *)outlineStyle;
+- (NSString *)outlineWidth;
+- (void)setOutlineWidth:(NSString *)outlineWidth;
+- (NSString *)overflow;
+- (void)setOverflow:(NSString *)overflow;
+- (NSString *)padding;
+- (void)setPadding:(NSString *)padding;
+- (NSString *)paddingTop;
+- (void)setPaddingTop:(NSString *)paddingTop;
+- (NSString *)paddingRight;
+- (void)setPaddingRight:(NSString *)paddingRight;
+- (NSString *)paddingBottom;
+- (void)setPaddingBottom:(NSString *)paddingBottom;
+- (NSString *)paddingLeft;
+- (void)setPaddingLeft:(NSString *)paddingLeft;
+- (NSString *)page;
+- (void)setPage:(NSString *)page;
+- (NSString *)pageBreakAfter;
+- (void)setPageBreakAfter:(NSString *)pageBreakAfter;
+- (NSString *)pageBreakBefore;
+- (void)setPageBreakBefore:(NSString *)pageBreakBefore;
+- (NSString *)pageBreakInside;
+- (void)setPageBreakInside:(NSString *)pageBreakInside;
+- (NSString *)pause;
+- (void)setPause:(NSString *)pause;
+- (NSString *)pauseAfter;
+- (void)setPauseAfter:(NSString *)pauseAfter;
+- (NSString *)pauseBefore;
+- (void)setPauseBefore:(NSString *)pauseBefore;
+- (NSString *)pitch;
+- (void)setPitch:(NSString *)pitch;
+- (NSString *)pitchRange;
+- (void)setPitchRange:(NSString *)pitchRange;
+- (NSString *)playDuring;
+- (void)setPlayDuring:(NSString *)playDuring;
+- (NSString *)position;
+- (void)setPosition:(NSString *)position;
+- (NSString *)quotes;
+- (void)setQuotes:(NSString *)quotes;
+- (NSString *)richness;
+- (void)setRichness:(NSString *)richness;
+- (NSString *)right;
+- (void)setRight:(NSString *)right;
+- (NSString *)size;
+- (void)setSize:(NSString *)size;
+- (NSString *)speak;
+- (void)setSpeak:(NSString *)speak;
+- (NSString *)speakHeader;
+- (void)setSpeakHeader:(NSString *)speakHeader;
+- (NSString *)speakNumeral;
+- (void)setSpeakNumeral:(NSString *)speakNumeral;
+- (NSString *)speakPunctuation;
+- (void)setSpeakPunctuation:(NSString *)speakPunctuation;
+- (NSString *)speechRate;
+- (void)setSpeechRate:(NSString *)speechRate;
+- (NSString *)stress;
+- (void)setStress:(NSString *)stress;
+- (NSString *)tableLayout;
+- (void)setTableLayout:(NSString *)tableLayout;
+- (NSString *)textAlign;
+- (void)setTextAlign:(NSString *)textAlign;
+- (NSString *)textDecoration;
+- (void)setTextDecoration:(NSString *)textDecoration;
+- (NSString *)textIndent;
+- (void)setTextIndent:(NSString *)textIndent;
+- (NSString *)textShadow;
+- (void)setTextShadow:(NSString *)textShadow;
+- (NSString *)textTransform;
+- (void)setTextTransform:(NSString *)textTransform;
+- (NSString *)top;
+- (void)setTop:(NSString *)top;
+- (NSString *)unicodeBidi;
+- (void)setUnicodeBidi:(NSString *)unicodeBidi;
+- (NSString *)verticalAlign;
+- (void)setVerticalAlign:(NSString *)verticalAlign;
+- (NSString *)visibility;
+- (void)setVisibility:(NSString *)visibility;
+- (NSString *)voiceFamily;
+- (void)setVoiceFamily:(NSString *)voiceFamily;
+- (NSString *)volume;
+- (void)setVolume:(NSString *)volume;
+- (NSString *)whiteSpace;
+- (void)setWhiteSpace:(NSString *)whiteSpace;
+- (NSString *)widows;
+- (void)setWidows:(NSString *)widows;
+- (NSString *)width;
+- (void)setWidth:(NSString *)width;
+- (NSString *)wordSpacing;
+- (void)setWordSpacing:(NSString *)wordSpacing;
+- (NSString *)zIndex;
+- (void)setZIndex:(NSString *)zIndex;
+@end
diff --git a/WebCore/bindings/objc/DOMCSS.mm b/WebCore/bindings/objc/DOMCSS.mm
new file mode 100644
index 0000000..83ba748
--- /dev/null
+++ b/WebCore/bindings/objc/DOMCSS.mm
@@ -0,0 +1,1443 @@
+/*
+ * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 James G. Speth (speth@end.com)
+ * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "DOMCSS.h"
+
+#import "CSSCharsetRule.h"
+#import "CSSFontFaceRule.h"
+#import "CSSImportRule.h"
+#import "CSSMediaRule.h"
+#import "CSSPageRule.h"
+#import "CSSPrimitiveValue.h"
+#import "CSSRule.h"
+#import "CSSRuleList.h"
+#import "CSSStyleDeclaration.h"
+#import "CSSStyleRule.h"
+#import "CSSStyleSheet.h"
+#import "CSSValueList.h"
+#import "DOMInternal.h"
+#import "DOMPrivate.h"
+#import "StyleSheet.h"
+#import <objc/objc-class.h>
+
+#if ENABLE(SVG)
+#import "DOMSVGColor.h"
+#import "DOMSVGPaint.h"
+#endif
+
+//------------------------------------------------------------------------------------------
+// DOMStyleSheet
+
+@implementation DOMStyleSheet (WebCoreInternal)
+
+- (WebCore::StyleSheet *)_styleSheet
+{
+ return reinterpret_cast<WebCore::StyleSheet*>(_internal);
+}
+
+- (id)_initWithStyleSheet:(WebCore::StyleSheet *)impl
+{
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMStyleSheet *)_wrapStyleSheet:(WebCore::StyleSheet *)impl
+{
+ if (!impl)
+ return nil;
+
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ Class wrapperClass;
+ if (impl->isCSSStyleSheet())
+ wrapperClass = [DOMCSSStyleSheet class];
+ else
+ wrapperClass = [DOMStyleSheet class];
+ return [[[wrapperClass alloc] _initWithStyleSheet:impl] autorelease];
+}
+
+@end
+
+//------------------------------------------------------------------------------------------
+// DOMCSSRule
+
+@implementation DOMCSSRule (WebCoreInternal)
+
+- (WebCore::CSSRule *)_CSSRule
+{
+ return reinterpret_cast<WebCore::CSSRule*>(_internal);
+}
+
+- (id)_initWithCSSRule:(WebCore::CSSRule *)impl
+{
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMCSSRule *)_wrapCSSRule:(WebCore::CSSRule *)impl
+{
+ if (!impl)
+ return nil;
+
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ Class wrapperClass = nil;
+ switch (impl->type()) {
+ case DOM_UNKNOWN_RULE:
+ wrapperClass = [DOMCSSUnknownRule class];
+ break;
+ case DOM_STYLE_RULE:
+ wrapperClass = [DOMCSSStyleRule class];
+ break;
+ case DOM_CHARSET_RULE:
+ wrapperClass = [DOMCSSCharsetRule class];
+ break;
+ case DOM_IMPORT_RULE:
+ wrapperClass = [DOMCSSImportRule class];
+ break;
+ case DOM_MEDIA_RULE:
+ wrapperClass = [DOMCSSMediaRule class];
+ break;
+ case DOM_FONT_FACE_RULE:
+ wrapperClass = [DOMCSSFontFaceRule class];
+ break;
+ case DOM_PAGE_RULE:
+ wrapperClass = [DOMCSSPageRule class];
+ break;
+ }
+ return [[[wrapperClass alloc] _initWithCSSRule:impl] autorelease];
+}
+
+@end
+
+
+//------------------------------------------------------------------------------------------
+// DOMCSSValue
+
+@implementation DOMCSSValue (WebCoreInternal)
+
+- (WebCore::CSSValue *)_CSSValue
+{
+ return reinterpret_cast<WebCore::CSSValue*>(_internal);
+}
+
+- (id)_initWithCSSValue:(WebCore::CSSValue *)impl
+{
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMCSSValue *)_wrapCSSValue:(WebCore::CSSValue *)impl
+{
+ if (!impl)
+ return nil;
+
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ Class wrapperClass = nil;
+ switch (impl->cssValueType()) {
+ case DOM_CSS_PRIMITIVE_VALUE:
+ wrapperClass = [DOMCSSPrimitiveValue class];
+ break;
+ case DOM_CSS_VALUE_LIST:
+ wrapperClass = [DOMCSSValueList class];
+ break;
+ case DOM_CSS_INHERIT:
+ wrapperClass = [DOMCSSValue class];
+ break;
+ case DOM_CSS_CUSTOM:
+#if ENABLE(SVG)
+ if (impl->isSVGPaint())
+ wrapperClass = [DOMSVGPaint class];
+ else if (impl->isSVGColor())
+ wrapperClass = [DOMSVGColor class];
+ else
+#endif
+ wrapperClass = [DOMCSSValue class];
+ break;
+ }
+ return [[[wrapperClass alloc] _initWithCSSValue:impl] autorelease];
+}
+
+@end
+
+
+//------------------------------------------------------------------------------------------
+// DOMCSSStyleDeclaration CSS2 Properties
+
+@implementation DOMCSSStyleDeclaration (DOMCSS2Properties)
+
+- (NSString *)azimuth
+{
+ return [self getPropertyValue:@"azimuth"];
+}
+
+- (void)setAzimuth:(NSString *)azimuth
+{
+ [self setProperty:@"azimuth" value:azimuth priority:@""];
+}
+
+- (NSString *)background
+{
+ return [self getPropertyValue:@"background"];
+}
+
+- (void)setBackground:(NSString *)background
+{
+ [self setProperty:@"background" value:background priority:@""];
+}
+
+- (NSString *)backgroundAttachment
+{
+ return [self getPropertyValue:@"background-attachment"];
+}
+
+- (void)setBackgroundAttachment:(NSString *)backgroundAttachment
+{
+ [self setProperty:@"background-attachment" value:backgroundAttachment priority:@""];
+}
+
+- (NSString *)backgroundColor
+{
+ return [self getPropertyValue:@"background-color"];
+}
+
+- (void)setBackgroundColor:(NSString *)backgroundColor
+{
+ [self setProperty:@"background-color" value:backgroundColor priority:@""];
+}
+
+- (NSString *)backgroundImage
+{
+ return [self getPropertyValue:@"background-image"];
+}
+
+- (void)setBackgroundImage:(NSString *)backgroundImage
+{
+ [self setProperty:@"background-image" value:backgroundImage priority:@""];
+}
+
+- (NSString *)backgroundPosition
+{
+ return [self getPropertyValue:@"background-position"];
+}
+
+- (void)setBackgroundPosition:(NSString *)backgroundPosition
+{
+ [self setProperty:@"background-position" value:backgroundPosition priority:@""];
+}
+
+- (NSString *)backgroundRepeat
+{
+ return [self getPropertyValue:@"background-repeat"];
+}
+
+- (void)setBackgroundRepeat:(NSString *)backgroundRepeat
+{
+ [self setProperty:@"background-repeat" value:backgroundRepeat priority:@""];
+}
+
+- (NSString *)border
+{
+ return [self getPropertyValue:@"border"];
+}
+
+- (void)setBorder:(NSString *)border
+{
+ [self setProperty:@"border" value:border priority:@""];
+}
+
+- (NSString *)borderCollapse
+{
+ return [self getPropertyValue:@"border-collapse"];
+}
+
+- (void)setBorderCollapse:(NSString *)borderCollapse
+{
+ [self setProperty:@"border-collapse" value:borderCollapse priority:@""];
+}
+
+- (NSString *)borderColor
+{
+ return [self getPropertyValue:@"border-color"];
+}
+
+- (void)setBorderColor:(NSString *)borderColor
+{
+ [self setProperty:@"border-color" value:borderColor priority:@""];
+}
+
+- (NSString *)borderSpacing
+{
+ return [self getPropertyValue:@"border-spacing"];
+}
+
+- (void)setBorderSpacing:(NSString *)borderSpacing
+{
+ [self setProperty:@"border-spacing" value:borderSpacing priority:@""];
+}
+
+- (NSString *)borderStyle
+{
+ return [self getPropertyValue:@"border-style"];
+}
+
+- (void)setBorderStyle:(NSString *)borderStyle
+{
+ [self setProperty:@"border-style" value:borderStyle priority:@""];
+}
+
+- (NSString *)borderTop
+{
+ return [self getPropertyValue:@"border-top"];
+}
+
+- (void)setBorderTop:(NSString *)borderTop
+{
+ [self setProperty:@"border-top" value:borderTop priority:@""];
+}
+
+- (NSString *)borderRight
+{
+ return [self getPropertyValue:@"border-right"];
+}
+
+- (void)setBorderRight:(NSString *)borderRight
+{
+ [self setProperty:@"border-right" value:borderRight priority:@""];
+}
+
+- (NSString *)borderBottom
+{
+ return [self getPropertyValue:@"border-bottom"];
+}
+
+- (void)setBorderBottom:(NSString *)borderBottom
+{
+ [self setProperty:@"border-bottom" value:borderBottom priority:@""];
+}
+
+- (NSString *)borderLeft
+{
+ return [self getPropertyValue:@"border-left"];
+}
+
+- (void)setBorderLeft:(NSString *)borderLeft
+{
+ [self setProperty:@"border-left" value:borderLeft priority:@""];
+}
+
+- (NSString *)borderTopColor
+{
+ return [self getPropertyValue:@"border-top-color"];
+}
+
+- (void)setBorderTopColor:(NSString *)borderTopColor
+{
+ [self setProperty:@"border-top-color" value:borderTopColor priority:@""];
+}
+
+- (NSString *)borderRightColor
+{
+ return [self getPropertyValue:@"border-right-color"];
+}
+
+- (void)setBorderRightColor:(NSString *)borderRightColor
+{
+ [self setProperty:@"border-right-color" value:borderRightColor priority:@""];
+}
+
+- (NSString *)borderBottomColor
+{
+ return [self getPropertyValue:@"border-bottom-color"];
+}
+
+- (void)setBorderBottomColor:(NSString *)borderBottomColor
+{
+ [self setProperty:@"border-bottom-color" value:borderBottomColor priority:@""];
+}
+
+- (NSString *)borderLeftColor
+{
+ return [self getPropertyValue:@"border-left-color"];
+}
+
+- (void)setBorderLeftColor:(NSString *)borderLeftColor
+{
+ [self setProperty:@"border-left-color" value:borderLeftColor priority:@""];
+}
+
+- (NSString *)borderTopStyle
+{
+ return [self getPropertyValue:@"border-top-style"];
+}
+
+- (void)setBorderTopStyle:(NSString *)borderTopStyle
+{
+ [self setProperty:@"border-top-style" value:borderTopStyle priority:@""];
+}
+
+- (NSString *)borderRightStyle
+{
+ return [self getPropertyValue:@"border-right-style"];
+}
+
+- (void)setBorderRightStyle:(NSString *)borderRightStyle
+{
+ [self setProperty:@"border-right-style" value:borderRightStyle priority:@""];
+}
+
+- (NSString *)borderBottomStyle
+{
+ return [self getPropertyValue:@"border-bottom-style"];
+}
+
+- (void)setBorderBottomStyle:(NSString *)borderBottomStyle
+{
+ [self setProperty:@"border-bottom-style" value:borderBottomStyle priority:@""];
+}
+
+- (NSString *)borderLeftStyle
+{
+ return [self getPropertyValue:@"border-left-style"];
+}
+
+- (void)setBorderLeftStyle:(NSString *)borderLeftStyle
+{
+ [self setProperty:@"border-left-style" value:borderLeftStyle priority:@""];
+}
+
+- (NSString *)borderTopWidth
+{
+ return [self getPropertyValue:@"border-top-width"];
+}
+
+- (void)setBorderTopWidth:(NSString *)borderTopWidth
+{
+ [self setProperty:@"border-top-width" value:borderTopWidth priority:@""];
+}
+
+- (NSString *)borderRightWidth
+{
+ return [self getPropertyValue:@"border-right-width"];
+}
+
+- (void)setBorderRightWidth:(NSString *)borderRightWidth
+{
+ [self setProperty:@"border-right-width" value:borderRightWidth priority:@""];
+}
+
+- (NSString *)borderBottomWidth
+{
+ return [self getPropertyValue:@"border-bottom-width"];
+}
+
+- (void)setBorderBottomWidth:(NSString *)borderBottomWidth
+{
+ [self setProperty:@"border-bottom-width" value:borderBottomWidth priority:@""];
+}
+
+- (NSString *)borderLeftWidth
+{
+ return [self getPropertyValue:@"border-left-width"];
+}
+
+- (void)setBorderLeftWidth:(NSString *)borderLeftWidth
+{
+ [self setProperty:@"border-left-width" value:borderLeftWidth priority:@""];
+}
+
+- (NSString *)borderWidth
+{
+ return [self getPropertyValue:@"border-width"];
+}
+
+- (void)setBorderWidth:(NSString *)borderWidth
+{
+ [self setProperty:@"border-width" value:borderWidth priority:@""];
+}
+
+- (NSString *)bottom
+{
+ return [self getPropertyValue:@"bottom"];
+}
+
+- (void)setBottom:(NSString *)bottom
+{
+ [self setProperty:@"bottom" value:bottom priority:@""];
+}
+
+- (NSString *)captionSide
+{
+ return [self getPropertyValue:@"caption-side"];
+}
+
+- (void)setCaptionSide:(NSString *)captionSide
+{
+ [self setProperty:@"caption-side" value:captionSide priority:@""];
+}
+
+- (NSString *)clear
+{
+ return [self getPropertyValue:@"clear"];
+}
+
+- (void)setClear:(NSString *)clear
+{
+ [self setProperty:@"clear" value:clear priority:@""];
+}
+
+- (NSString *)clip
+{
+ return [self getPropertyValue:@"clip"];
+}
+
+- (void)setClip:(NSString *)clip
+{
+ [self setProperty:@"clip" value:clip priority:@""];
+}
+
+- (NSString *)color
+{
+ return [self getPropertyValue:@"color"];
+}
+
+- (void)setColor:(NSString *)color
+{
+ [self setProperty:@"color" value:color priority:@""];
+}
+
+- (NSString *)content
+{
+ return [self getPropertyValue:@"content"];
+}
+
+- (void)setContent:(NSString *)content
+{
+ [self setProperty:@"content" value:content priority:@""];
+}
+
+- (NSString *)counterIncrement
+{
+ return [self getPropertyValue:@"counter-increment"];
+}
+
+- (void)setCounterIncrement:(NSString *)counterIncrement
+{
+ [self setProperty:@"counter-increment" value:counterIncrement priority:@""];
+}
+
+- (NSString *)counterReset
+{
+ return [self getPropertyValue:@"counter-reset"];
+}
+
+- (void)setCounterReset:(NSString *)counterReset
+{
+ [self setProperty:@"counter-reset" value:counterReset priority:@""];
+}
+
+- (NSString *)cue
+{
+ return [self getPropertyValue:@"cue"];
+}
+
+- (void)setCue:(NSString *)cue
+{
+ [self setProperty:@"cue" value:cue priority:@""];
+}
+
+- (NSString *)cueAfter
+{
+ return [self getPropertyValue:@"cue-after"];
+}
+
+- (void)setCueAfter:(NSString *)cueAfter
+{
+ [self setProperty:@"cue-after" value:cueAfter priority:@""];
+}
+
+- (NSString *)cueBefore
+{
+ return [self getPropertyValue:@"cue-before"];
+}
+
+- (void)setCueBefore:(NSString *)cueBefore
+{
+ [self setProperty:@"cue-before" value:cueBefore priority:@""];
+}
+
+- (NSString *)cursor
+{
+ return [self getPropertyValue:@"cursor"];
+}
+
+- (void)setCursor:(NSString *)cursor
+{
+ [self setProperty:@"cursor" value:cursor priority:@""];
+}
+
+- (NSString *)direction
+{
+ return [self getPropertyValue:@"direction"];
+}
+
+- (void)setDirection:(NSString *)direction
+{
+ [self setProperty:@"direction" value:direction priority:@""];
+}
+
+- (NSString *)display
+{
+ return [self getPropertyValue:@"display"];
+}
+
+- (void)setDisplay:(NSString *)display
+{
+ [self setProperty:@"display" value:display priority:@""];
+}
+
+- (NSString *)elevation
+{
+ return [self getPropertyValue:@"elevation"];
+}
+
+- (void)setElevation:(NSString *)elevation
+{
+ [self setProperty:@"elevation" value:elevation priority:@""];
+}
+
+- (NSString *)emptyCells
+{
+ return [self getPropertyValue:@"empty-cells"];
+}
+
+- (void)setEmptyCells:(NSString *)emptyCells
+{
+ [self setProperty:@"empty-cells" value:emptyCells priority:@""];
+}
+
+- (NSString *)cssFloat
+{
+ return [self getPropertyValue:@"css-float"];
+}
+
+- (void)setCssFloat:(NSString *)cssFloat
+{
+ [self setProperty:@"css-float" value:cssFloat priority:@""];
+}
+
+- (NSString *)font
+{
+ return [self getPropertyValue:@"font"];
+}
+
+- (void)setFont:(NSString *)font
+{
+ [self setProperty:@"font" value:font priority:@""];
+}
+
+- (NSString *)fontFamily
+{
+ return [self getPropertyValue:@"font-family"];
+}
+
+- (void)setFontFamily:(NSString *)fontFamily
+{
+ [self setProperty:@"font-family" value:fontFamily priority:@""];
+}
+
+- (NSString *)fontSize
+{
+ return [self getPropertyValue:@"font-size"];
+}
+
+- (void)setFontSize:(NSString *)fontSize
+{
+ [self setProperty:@"font-size" value:fontSize priority:@""];
+}
+
+- (NSString *)fontSizeAdjust
+{
+ return [self getPropertyValue:@"font-size-adjust"];
+}
+
+- (void)setFontSizeAdjust:(NSString *)fontSizeAdjust
+{
+ [self setProperty:@"font-size-adjust" value:fontSizeAdjust priority:@""];
+}
+
+- (NSString *)_fontSizeDelta
+{
+ return [self getPropertyValue:@"-webkit-font-size-delta"];
+}
+
+- (void)_setFontSizeDelta:(NSString *)fontSizeDelta
+{
+ [self setProperty:@"-webkit-font-size-delta" value:fontSizeDelta priority:@""];
+}
+
+- (NSString *)fontStretch
+{
+ return [self getPropertyValue:@"font-stretch"];
+}
+
+- (void)setFontStretch:(NSString *)fontStretch
+{
+ [self setProperty:@"font-stretch" value:fontStretch priority:@""];
+}
+
+- (NSString *)fontStyle
+{
+ return [self getPropertyValue:@"font-style"];
+}
+
+- (void)setFontStyle:(NSString *)fontStyle
+{
+ [self setProperty:@"font-style" value:fontStyle priority:@""];
+}
+
+- (NSString *)fontVariant
+{
+ return [self getPropertyValue:@"font-variant"];
+}
+
+- (void)setFontVariant:(NSString *)fontVariant
+{
+ [self setProperty:@"font-variant" value:fontVariant priority:@""];
+}
+
+- (NSString *)fontWeight
+{
+ return [self getPropertyValue:@"font-weight"];
+}
+
+- (void)setFontWeight:(NSString *)fontWeight
+{
+ [self setProperty:@"font-weight" value:fontWeight priority:@""];
+}
+
+- (NSString *)height
+{
+ return [self getPropertyValue:@"height"];
+}
+
+- (void)setHeight:(NSString *)height
+{
+ [self setProperty:@"height" value:height priority:@""];
+}
+
+- (NSString *)left
+{
+ return [self getPropertyValue:@"left"];
+}
+
+- (void)setLeft:(NSString *)left
+{
+ [self setProperty:@"left" value:left priority:@""];
+}
+
+- (NSString *)letterSpacing
+{
+ return [self getPropertyValue:@"letter-spacing"];
+}
+
+- (void)setLetterSpacing:(NSString *)letterSpacing
+{
+ [self setProperty:@"letter-spacing" value:letterSpacing priority:@""];
+}
+
+- (NSString *)lineHeight
+{
+ return [self getPropertyValue:@"line-height"];
+}
+
+- (void)setLineHeight:(NSString *)lineHeight
+{
+ [self setProperty:@"line-height" value:lineHeight priority:@""];
+}
+
+- (NSString *)listStyle
+{
+ return [self getPropertyValue:@"list-style"];
+}
+
+- (void)setListStyle:(NSString *)listStyle
+{
+ [self setProperty:@"list-style" value:listStyle priority:@""];
+}
+
+- (NSString *)listStyleImage
+{
+ return [self getPropertyValue:@"list-style-image"];
+}
+
+- (void)setListStyleImage:(NSString *)listStyleImage
+{
+ [self setProperty:@"list-style-image" value:listStyleImage priority:@""];
+}
+
+- (NSString *)listStylePosition
+{
+ return [self getPropertyValue:@"list-style-position"];
+}
+
+- (void)setListStylePosition:(NSString *)listStylePosition
+{
+ [self setProperty:@"list-style-position" value:listStylePosition priority:@""];
+}
+
+- (NSString *)listStyleType
+{
+ return [self getPropertyValue:@"list-style-type"];
+}
+
+- (void)setListStyleType:(NSString *)listStyleType
+{
+ [self setProperty:@"list-style-type" value:listStyleType priority:@""];
+}
+
+- (NSString *)margin
+{
+ return [self getPropertyValue:@"margin"];
+}
+
+- (void)setMargin:(NSString *)margin
+{
+ [self setProperty:@"margin" value:margin priority:@""];
+}
+
+- (NSString *)marginTop
+{
+ return [self getPropertyValue:@"margin-top"];
+}
+
+- (void)setMarginTop:(NSString *)marginTop
+{
+ [self setProperty:@"margin-top" value:marginTop priority:@""];
+}
+
+- (NSString *)marginRight
+{
+ return [self getPropertyValue:@"margin-right"];
+}
+
+- (void)setMarginRight:(NSString *)marginRight
+{
+ [self setProperty:@"margin-right" value:marginRight priority:@""];
+}
+
+- (NSString *)marginBottom
+{
+ return [self getPropertyValue:@"margin-bottom"];
+}
+
+- (void)setMarginBottom:(NSString *)marginBottom
+{
+ [self setProperty:@"margin-bottom" value:marginBottom priority:@""];
+}
+
+- (NSString *)marginLeft
+{
+ return [self getPropertyValue:@"margin-left"];
+}
+
+- (void)setMarginLeft:(NSString *)marginLeft
+{
+ [self setProperty:@"margin-left" value:marginLeft priority:@""];
+}
+
+- (NSString *)markerOffset
+{
+ return [self getPropertyValue:@"marker-offset"];
+}
+
+- (void)setMarkerOffset:(NSString *)markerOffset
+{
+ [self setProperty:@"marker-offset" value:markerOffset priority:@""];
+}
+
+- (NSString *)marks
+{
+ return [self getPropertyValue:@"marks"];
+}
+
+- (void)setMarks:(NSString *)marks
+{
+ [self setProperty:@"marks" value:marks priority:@""];
+}
+
+- (NSString *)maxHeight
+{
+ return [self getPropertyValue:@"max-height"];
+}
+
+- (void)setMaxHeight:(NSString *)maxHeight
+{
+ [self setProperty:@"max-height" value:maxHeight priority:@""];
+}
+
+- (NSString *)maxWidth
+{
+ return [self getPropertyValue:@"max-width"];
+}
+
+- (void)setMaxWidth:(NSString *)maxWidth
+{
+ [self setProperty:@"max-width" value:maxWidth priority:@""];
+}
+
+- (NSString *)minHeight
+{
+ return [self getPropertyValue:@"min-height"];
+}
+
+- (void)setMinHeight:(NSString *)minHeight
+{
+ [self setProperty:@"min-height" value:minHeight priority:@""];
+}
+
+- (NSString *)minWidth
+{
+ return [self getPropertyValue:@"min-width"];
+}
+
+- (void)setMinWidth:(NSString *)minWidth
+{
+ [self setProperty:@"min-width" value:minWidth priority:@""];
+}
+
+- (NSString *)orphans
+{
+ return [self getPropertyValue:@"orphans"];
+}
+
+- (void)setOrphans:(NSString *)orphans
+{
+ [self setProperty:@"orphans" value:orphans priority:@""];
+}
+
+- (NSString *)outline
+{
+ return [self getPropertyValue:@"outline"];
+}
+
+- (void)setOutline:(NSString *)outline
+{
+ [self setProperty:@"outline" value:outline priority:@""];
+}
+
+- (NSString *)outlineColor
+{
+ return [self getPropertyValue:@"outline-color"];
+}
+
+- (void)setOutlineColor:(NSString *)outlineColor
+{
+ [self setProperty:@"outline-color" value:outlineColor priority:@""];
+}
+
+- (NSString *)outlineStyle
+{
+ return [self getPropertyValue:@"outline-style"];
+}
+
+- (void)setOutlineStyle:(NSString *)outlineStyle
+{
+ [self setProperty:@"outline-style" value:outlineStyle priority:@""];
+}
+
+- (NSString *)outlineWidth
+{
+ return [self getPropertyValue:@"outline-width"];
+}
+
+- (void)setOutlineWidth:(NSString *)outlineWidth
+{
+ [self setProperty:@"outline-width" value:outlineWidth priority:@""];
+}
+
+- (NSString *)overflow
+{
+ return [self getPropertyValue:@"overflow"];
+}
+
+- (void)setOverflow:(NSString *)overflow
+{
+ [self setProperty:@"overflow" value:overflow priority:@""];
+}
+
+- (NSString *)padding
+{
+ return [self getPropertyValue:@"padding"];
+}
+
+- (void)setPadding:(NSString *)padding
+{
+ [self setProperty:@"padding" value:padding priority:@""];
+}
+
+- (NSString *)paddingTop
+{
+ return [self getPropertyValue:@"padding-top"];
+}
+
+- (void)setPaddingTop:(NSString *)paddingTop
+{
+ [self setProperty:@"padding-top" value:paddingTop priority:@""];
+}
+
+- (NSString *)paddingRight
+{
+ return [self getPropertyValue:@"padding-right"];
+}
+
+- (void)setPaddingRight:(NSString *)paddingRight
+{
+ [self setProperty:@"padding-right" value:paddingRight priority:@""];
+}
+
+- (NSString *)paddingBottom
+{
+ return [self getPropertyValue:@"padding-bottom"];
+}
+
+- (void)setPaddingBottom:(NSString *)paddingBottom
+{
+ [self setProperty:@"padding-bottom" value:paddingBottom priority:@""];
+}
+
+- (NSString *)paddingLeft
+{
+ return [self getPropertyValue:@"padding-left"];
+}
+
+- (void)setPaddingLeft:(NSString *)paddingLeft
+{
+ [self setProperty:@"padding-left" value:paddingLeft priority:@""];
+}
+
+- (NSString *)page
+{
+ return [self getPropertyValue:@"page"];
+}
+
+- (void)setPage:(NSString *)page
+{
+ [self setProperty:@"page" value:page priority:@""];
+}
+
+- (NSString *)pageBreakAfter
+{
+ return [self getPropertyValue:@"page-break-after"];
+}
+
+- (void)setPageBreakAfter:(NSString *)pageBreakAfter
+{
+ [self setProperty:@"page-break-after" value:pageBreakAfter priority:@""];
+}
+
+- (NSString *)pageBreakBefore
+{
+ return [self getPropertyValue:@"page-break-before"];
+}
+
+- (void)setPageBreakBefore:(NSString *)pageBreakBefore
+{
+ [self setProperty:@"page-break-before" value:pageBreakBefore priority:@""];
+}
+
+- (NSString *)pageBreakInside
+{
+ return [self getPropertyValue:@"page-break-inside"];
+}
+
+- (void)setPageBreakInside:(NSString *)pageBreakInside
+{
+ [self setProperty:@"page-break-inside" value:pageBreakInside priority:@""];
+}
+
+- (NSString *)pause
+{
+ return [self getPropertyValue:@"pause"];
+}
+
+- (void)setPause:(NSString *)pause
+{
+ [self setProperty:@"pause" value:pause priority:@""];
+}
+
+- (NSString *)pauseAfter
+{
+ return [self getPropertyValue:@"pause-after"];
+}
+
+- (void)setPauseAfter:(NSString *)pauseAfter
+{
+ [self setProperty:@"pause-after" value:pauseAfter priority:@""];
+}
+
+- (NSString *)pauseBefore
+{
+ return [self getPropertyValue:@"pause-before"];
+}
+
+- (void)setPauseBefore:(NSString *)pauseBefore
+{
+ [self setProperty:@"pause-before" value:pauseBefore priority:@""];
+}
+
+- (NSString *)pitch
+{
+ return [self getPropertyValue:@"pitch"];
+}
+
+- (void)setPitch:(NSString *)pitch
+{
+ [self setProperty:@"pitch" value:pitch priority:@""];
+}
+
+- (NSString *)pitchRange
+{
+ return [self getPropertyValue:@"pitch-range"];
+}
+
+- (void)setPitchRange:(NSString *)pitchRange
+{
+ [self setProperty:@"pitch-range" value:pitchRange priority:@""];
+}
+
+- (NSString *)playDuring
+{
+ return [self getPropertyValue:@"play-during"];
+}
+
+- (void)setPlayDuring:(NSString *)playDuring
+{
+ [self setProperty:@"play-during" value:playDuring priority:@""];
+}
+
+- (NSString *)position
+{
+ return [self getPropertyValue:@"position"];
+}
+
+- (void)setPosition:(NSString *)position
+{
+ [self setProperty:@"position" value:position priority:@""];
+}
+
+- (NSString *)quotes
+{
+ return [self getPropertyValue:@"quotes"];
+}
+
+- (void)setQuotes:(NSString *)quotes
+{
+ [self setProperty:@"quotes" value:quotes priority:@""];
+}
+
+- (NSString *)richness
+{
+ return [self getPropertyValue:@"richness"];
+}
+
+- (void)setRichness:(NSString *)richness
+{
+ [self setProperty:@"richness" value:richness priority:@""];
+}
+
+- (NSString *)right
+{
+ return [self getPropertyValue:@"right"];
+}
+
+- (void)setRight:(NSString *)right
+{
+ [self setProperty:@"right" value:right priority:@""];
+}
+
+- (NSString *)size
+{
+ return [self getPropertyValue:@"size"];
+}
+
+- (void)setSize:(NSString *)size
+{
+ [self setProperty:@"size" value:size priority:@""];
+}
+
+- (NSString *)speak
+{
+ return [self getPropertyValue:@"speak"];
+}
+
+- (void)setSpeak:(NSString *)speak
+{
+ [self setProperty:@"speak" value:speak priority:@""];
+}
+
+- (NSString *)speakHeader
+{
+ return [self getPropertyValue:@"speak-header"];
+}
+
+- (void)setSpeakHeader:(NSString *)speakHeader
+{
+ [self setProperty:@"speak-header" value:speakHeader priority:@""];
+}
+
+- (NSString *)speakNumeral
+{
+ return [self getPropertyValue:@"speak-numeral"];
+}
+
+- (void)setSpeakNumeral:(NSString *)speakNumeral
+{
+ [self setProperty:@"speak-numeral" value:speakNumeral priority:@""];
+}
+
+- (NSString *)speakPunctuation
+{
+ return [self getPropertyValue:@"speak-punctuation"];
+}
+
+- (void)setSpeakPunctuation:(NSString *)speakPunctuation
+{
+ [self setProperty:@"speak-punctuation" value:speakPunctuation priority:@""];
+}
+
+- (NSString *)speechRate
+{
+ return [self getPropertyValue:@"speech-rate"];
+}
+
+- (void)setSpeechRate:(NSString *)speechRate
+{
+ [self setProperty:@"speech-rate" value:speechRate priority:@""];
+}
+
+- (NSString *)stress
+{
+ return [self getPropertyValue:@"stress"];
+}
+
+- (void)setStress:(NSString *)stress
+{
+ [self setProperty:@"stress" value:stress priority:@""];
+}
+
+- (NSString *)tableLayout
+{
+ return [self getPropertyValue:@"table-layout"];
+}
+
+- (void)setTableLayout:(NSString *)tableLayout
+{
+ [self setProperty:@"table-layout" value:tableLayout priority:@""];
+}
+
+- (NSString *)textAlign
+{
+ return [self getPropertyValue:@"text-align"];
+}
+
+- (void)setTextAlign:(NSString *)textAlign
+{
+ [self setProperty:@"text-align" value:textAlign priority:@""];
+}
+
+- (NSString *)textDecoration
+{
+ return [self getPropertyValue:@"text-decoration"];
+}
+
+- (void)setTextDecoration:(NSString *)textDecoration
+{
+ [self setProperty:@"text-decoration" value:textDecoration priority:@""];
+}
+
+- (NSString *)textIndent
+{
+ return [self getPropertyValue:@"text-indent"];
+}
+
+- (void)setTextIndent:(NSString *)textIndent
+{
+ [self setProperty:@"text-indent" value:textIndent priority:@""];
+}
+
+- (NSString *)textShadow
+{
+ return [self getPropertyValue:@"text-shadow"];
+}
+
+- (void)setTextShadow:(NSString *)textShadow
+{
+ [self setProperty:@"text-shadow" value:textShadow priority:@""];
+}
+
+- (NSString *)textTransform
+{
+ return [self getPropertyValue:@"text-transform"];
+}
+
+- (void)setTextTransform:(NSString *)textTransform
+{
+ [self setProperty:@"text-transform" value:textTransform priority:@""];
+}
+
+- (NSString *)top
+{
+ return [self getPropertyValue:@"top"];
+}
+
+- (void)setTop:(NSString *)top
+{
+ [self setProperty:@"top" value:top priority:@""];
+}
+
+- (NSString *)unicodeBidi
+{
+ return [self getPropertyValue:@"unicode-bidi"];
+}
+
+- (void)setUnicodeBidi:(NSString *)unicodeBidi
+{
+ [self setProperty:@"unicode-bidi" value:unicodeBidi priority:@""];
+}
+
+- (NSString *)verticalAlign
+{
+ return [self getPropertyValue:@"vertical-align"];
+}
+
+- (void)setVerticalAlign:(NSString *)verticalAlign
+{
+ [self setProperty:@"vertical-align" value:verticalAlign priority:@""];
+}
+
+- (NSString *)visibility
+{
+ return [self getPropertyValue:@"visibility"];
+}
+
+- (void)setVisibility:(NSString *)visibility
+{
+ [self setProperty:@"visibility" value:visibility priority:@""];
+}
+
+- (NSString *)voiceFamily
+{
+ return [self getPropertyValue:@"voice-family"];
+}
+
+- (void)setVoiceFamily:(NSString *)voiceFamily
+{
+ [self setProperty:@"voice-family" value:voiceFamily priority:@""];
+}
+
+- (NSString *)volume
+{
+ return [self getPropertyValue:@"volume"];
+}
+
+- (void)setVolume:(NSString *)volume
+{
+ [self setProperty:@"volume" value:volume priority:@""];
+}
+
+- (NSString *)whiteSpace
+{
+ return [self getPropertyValue:@"white-space"];
+}
+
+- (void)setWhiteSpace:(NSString *)whiteSpace
+{
+ [self setProperty:@"white-space" value:whiteSpace priority:@""];
+}
+
+- (NSString *)widows
+{
+ return [self getPropertyValue:@"widows"];
+}
+
+- (void)setWidows:(NSString *)widows
+{
+ [self setProperty:@"widows" value:widows priority:@""];
+}
+
+- (NSString *)width
+{
+ return [self getPropertyValue:@"width"];
+}
+
+- (void)setWidth:(NSString *)width
+{
+ [self setProperty:@"width" value:width priority:@""];
+}
+
+- (NSString *)wordSpacing
+{
+ return [self getPropertyValue:@"word-spacing"];
+}
+
+- (void)setWordSpacing:(NSString *)wordSpacing
+{
+ [self setProperty:@"word-spacing" value:wordSpacing priority:@""];
+}
+
+- (NSString *)zIndex
+{
+ return [self getPropertyValue:@"z-index"];
+}
+
+- (void)setZIndex:(NSString *)zIndex
+{
+ [self setProperty:@"z-index" value:zIndex priority:@""];
+}
+
+@end
diff --git a/WebCore/bindings/objc/DOMCore.h b/WebCore/bindings/objc/DOMCore.h
new file mode 100644
index 0000000..afac8ed
--- /dev/null
+++ b/WebCore/bindings/objc/DOMCore.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMAttr.h>
+#import <WebCore/DOMCDATASection.h>
+#import <WebCore/DOMCharacterData.h>
+#import <WebCore/DOMComment.h>
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMDocumentFragment.h>
+#import <WebCore/DOMDocumentType.h>
+#import <WebCore/DOMElement.h>
+#import <WebCore/DOMEntity.h>
+#import <WebCore/DOMEntityReference.h>
+#import <WebCore/DOMException.h>
+#import <WebCore/DOMDOMImplementation.h>
+#import <WebCore/DOMNamedNodeMap.h>
+#import <WebCore/DOMNode.h>
+#import <WebCore/DOMNodeList.h>
+#import <WebCore/DOMNotation.h>
+#import <WebCore/DOMObject.h>
+#import <WebCore/DOMProcessingInstruction.h>
+#import <WebCore/DOMText.h>
diff --git a/WebCore/bindings/objc/DOMCustomXPathNSResolver.h b/WebCore/bindings/objc/DOMCustomXPathNSResolver.h
new file mode 100644
index 0000000..2609e90
--- /dev/null
+++ b/WebCore/bindings/objc/DOMCustomXPathNSResolver.h
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef DOMCustomXPathNSResolver_h
+#define DOMCustomXPathNSResolver_h
+
+#if ENABLE(XPATH)
+
+#include "XPathNSResolver.h"
+
+#include "DOMXPathNSResolver.h"
+#include <wtf/PassRefPtr.h>
+
+namespace WebCore {
+
+ class Frame;
+
+ class DOMCustomXPathNSResolver : public XPathNSResolver {
+ public:
+ static PassRefPtr<DOMCustomXPathNSResolver> create(id <DOMXPathNSResolver> customResolver) { return adoptRef(new DOMCustomXPathNSResolver(customResolver)); }
+ virtual ~DOMCustomXPathNSResolver();
+
+ virtual String lookupNamespaceURI(const String& prefix);
+
+ private:
+ DOMCustomXPathNSResolver(id <DOMXPathNSResolver>);
+ id <DOMXPathNSResolver> m_customResolver; // DOMCustomXPathNSResolvers are always temporary, thus no need to GC protect the object.
+ };
+
+} // namespace WebCore
+
+#endif // ENABLE(XPATH)
+
+#endif // DOMCustomXPathNSResolver_h
diff --git a/WebCore/bindings/objc/DOMCustomXPathNSResolver.mm b/WebCore/bindings/objc/DOMCustomXPathNSResolver.mm
new file mode 100644
index 0000000..670c836
--- /dev/null
+++ b/WebCore/bindings/objc/DOMCustomXPathNSResolver.mm
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2007 Alexey Proskuryakov (ap@nypop.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "DOMCustomXPathNSResolver.h"
+
+#if ENABLE(XPATH)
+
+#include "BlockExceptions.h"
+#include "PlatformString.h"
+
+namespace WebCore {
+
+DOMCustomXPathNSResolver::DOMCustomXPathNSResolver(id <DOMXPathNSResolver> customResolver)
+ : m_customResolver(customResolver)
+{
+}
+
+DOMCustomXPathNSResolver::~DOMCustomXPathNSResolver()
+{
+}
+
+String DOMCustomXPathNSResolver::lookupNamespaceURI(const String& prefix)
+{
+ NSString *namespaceURI = nil;
+
+ BEGIN_BLOCK_OBJC_EXCEPTIONS;
+ namespaceURI = [m_customResolver lookupNamespaceURI:prefix];
+ END_BLOCK_OBJC_EXCEPTIONS;
+
+ return namespaceURI;
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(XPATH)
diff --git a/WebCore/bindings/objc/DOMEventException.h b/WebCore/bindings/objc/DOMEventException.h
new file mode 100644
index 0000000..4e805ad
--- /dev/null
+++ b/WebCore/bindings/objc/DOMEventException.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+@class NSString;
+
+extern NSString * const DOMEventException;
+
+enum DOMEventExceptionCode {
+ DOM_UNSPECIFIED_EVENT_TYPE_ERR = 0
+};
diff --git a/WebCore/bindings/objc/DOMEvents.h b/WebCore/bindings/objc/DOMEvents.h
new file mode 100644
index 0000000..d7248a5
--- /dev/null
+++ b/WebCore/bindings/objc/DOMEvents.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMNode.h>
+#import <WebCore/DOMObject.h>
+#import <WebCore/DOMViews.h>
+
+#import <WebCore/DOMEvent.h>
+#import <WebCore/DOMEventException.h>
+#import <WebCore/DOMEventListener.h>
+#import <WebCore/DOMEventTarget.h>
+#import <WebCore/DOMKeyboardEvent.h>
+#import <WebCore/DOMMouseEvent.h>
+#import <WebCore/DOMMutationEvent.h>
+#import <WebCore/DOMOverflowEvent.h>
+#import <WebCore/DOMUIEvent.h>
+#import <WebCore/DOMWheelEvent.h>
+
+@interface DOMNode (DOMEventTarget) <DOMEventTarget>
+@end
diff --git a/WebCore/bindings/objc/DOMEvents.mm b/WebCore/bindings/objc/DOMEvents.mm
new file mode 100644
index 0000000..3b95006
--- /dev/null
+++ b/WebCore/bindings/objc/DOMEvents.mm
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2004, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Jonas Witt <jonas.witt@gmail.com>
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 ec 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "DOMEvents.h"
+
+#import "DOMInternal.h"
+#import "DOMPrivate.h"
+#import "DOMProgressEvent.h"
+#import "Event.h"
+#import "KeyboardEvent.h"
+#import "MouseEvent.h"
+#import "MutationEvent.h"
+#import "OverflowEvent.h"
+#import "ProgressEvent.h"
+#import "UIEvent.h"
+
+#if ENABLE(CROSS_DOCUMENT_MESSAGING)
+#import "DOMMessageEvent.h"
+#import "MessageEvent.h"
+#endif
+
+#if ENABLE(SVG)
+#import "DOMSVGZoomEvent.h"
+#import "SVGZoomEvent.h"
+#endif
+
+//------------------------------------------------------------------------------------------
+// DOMEvent
+
+@implementation DOMEvent (WebCoreInternal)
+
+- (WebCore::Event *)_event
+{
+ return reinterpret_cast<WebCore::Event*>(_internal);
+}
+
+- (id)_initWithEvent:(WebCore::Event *)impl
+{
+ ASSERT(impl);
+
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal *>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMEvent *)_wrapEvent:(WebCore::Event *)impl
+{
+ if (!impl)
+ return nil;
+
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ Class wrapperClass = nil;
+ if (impl->isUIEvent()) {
+ if (impl->isKeyboardEvent())
+ wrapperClass = [DOMKeyboardEvent class];
+ else if (impl->isTextEvent())
+ wrapperClass = [DOMTextEvent class];
+ else if (impl->isMouseEvent())
+ wrapperClass = [DOMMouseEvent class];
+ else if (impl->isWheelEvent())
+ wrapperClass = [DOMWheelEvent class];
+#if ENABLE(SVG)
+ else if (impl->isSVGZoomEvent())
+ wrapperClass = [DOMSVGZoomEvent class];
+#endif
+ else
+ wrapperClass = [DOMUIEvent class];
+ } else if (impl->isMutationEvent())
+ wrapperClass = [DOMMutationEvent class];
+ else if (impl->isOverflowEvent())
+ wrapperClass = [DOMOverflowEvent class];
+#if ENABLE(CROSS_DOCUMENT_MESSAGING)
+ else if (impl->isMessageEvent())
+ wrapperClass = [DOMMessageEvent class];
+#endif
+ else if (impl->isProgressEvent())
+ wrapperClass = [DOMProgressEvent class];
+ else
+ wrapperClass = [DOMEvent class];
+
+ return [[[wrapperClass alloc] _initWithEvent:impl] autorelease];
+}
+
+@end
diff --git a/WebCore/bindings/objc/DOMException.h b/WebCore/bindings/objc/DOMException.h
new file mode 100644
index 0000000..1efdf24
--- /dev/null
+++ b/WebCore/bindings/objc/DOMException.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+@class NSString;
+
+extern NSString * const DOMException;
+
+// DOM exception codes
+enum {
+ DOM_INDEX_SIZE_ERR = 1,
+ DOM_DOMSTRING_SIZE_ERR = 2,
+ DOM_HIERARCHY_REQUEST_ERR = 3,
+ DOM_WRONG_DOCUMENT_ERR = 4,
+ DOM_INVALID_CHARACTER_ERR = 5,
+ DOM_NO_DATA_ALLOWED_ERR = 6,
+ DOM_NO_MODIFICATION_ALLOWED_ERR = 7,
+ DOM_NOT_FOUND_ERR = 8,
+ DOM_NOT_SUPPORTED_ERR = 9,
+ DOM_INUSE_ATTRIBUTE_ERR = 10,
+ DOM_INVALID_STATE_ERR = 11,
+ DOM_SYNTAX_ERR = 12,
+ DOM_INVALID_MODIFICATION_ERR = 13,
+ DOM_NAMESPACE_ERR = 14,
+ DOM_INVALID_ACCESS_ERR = 15
+};
diff --git a/WebCore/bindings/objc/DOMExtensions.h b/WebCore/bindings/objc/DOMExtensions.h
new file mode 100644
index 0000000..8188c30
--- /dev/null
+++ b/WebCore/bindings/objc/DOMExtensions.h
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMAttr.h>
+#import <WebCore/DOMCSS.h>
+#import <WebCore/DOMCSSStyleDeclaration.h>
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMElement.h>
+#import <WebCore/DOMHTML.h>
+#import <WebCore/DOMHTMLAnchorElement.h>
+#import <WebCore/DOMHTMLAreaElement.h>
+#import <WebCore/DOMHTMLDocument.h>
+#import <WebCore/DOMHTMLElement.h>
+#import <WebCore/DOMHTMLEmbedElement.h>
+#import <WebCore/DOMHTMLImageElement.h>
+#import <WebCore/DOMHTMLInputElement.h>
+#import <WebCore/DOMHTMLLinkElement.h>
+#import <WebCore/DOMHTMLObjectElement.h>
+#import <WebCore/DOMNode.h>
+#import <WebCore/DOMRGBColor.h>
+#import <WebCore/DOMRange.h>
+
+@class NSArray;
+@class NSImage;
+@class NSURL;
+
+@interface DOMNode (DOMNodeExtensions)
+- (NSRect)boundingBox;
+- (NSArray *)lineBoxRects;
+@end
+
+@interface DOMElement (DOMElementAppKitExtensions)
+- (NSImage *)image;
+@end
+
+@interface DOMHTMLDocument (DOMHTMLDocumentExtensions)
+- (DOMDocumentFragment *)createDocumentFragmentWithMarkupString:(NSString *)markupString baseURL:(NSURL *)baseURL;
+- (DOMDocumentFragment *)createDocumentFragmentWithText:(NSString *)text;
+@end
diff --git a/WebCore/bindings/objc/DOMHTML.h b/WebCore/bindings/objc/DOMHTML.h
new file mode 100644
index 0000000..cd80612
--- /dev/null
+++ b/WebCore/bindings/objc/DOMHTML.h
@@ -0,0 +1,86 @@
+/*
+ * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCore.h>
+
+#import <WebCore/DOMHTMLAnchorElement.h>
+#import <WebCore/DOMHTMLAppletElement.h>
+#import <WebCore/DOMHTMLAreaElement.h>
+#import <WebCore/DOMHTMLBRElement.h>
+#import <WebCore/DOMHTMLBaseElement.h>
+#import <WebCore/DOMHTMLBaseFontElement.h>
+#import <WebCore/DOMHTMLBodyElement.h>
+#import <WebCore/DOMHTMLButtonElement.h>
+#import <WebCore/DOMHTMLCollection.h>
+#import <WebCore/DOMHTMLDListElement.h>
+#import <WebCore/DOMHTMLDirectoryElement.h>
+#import <WebCore/DOMHTMLDivElement.h>
+#import <WebCore/DOMHTMLDocument.h>
+#import <WebCore/DOMHTMLElement.h>
+#import <WebCore/DOMHTMLEmbedElement.h>
+#import <WebCore/DOMHTMLFieldSetElement.h>
+#import <WebCore/DOMHTMLFontElement.h>
+#import <WebCore/DOMHTMLFormElement.h>
+#import <WebCore/DOMHTMLFrameElement.h>
+#import <WebCore/DOMHTMLFrameSetElement.h>
+#import <WebCore/DOMHTMLHRElement.h>
+#import <WebCore/DOMHTMLHeadElement.h>
+#import <WebCore/DOMHTMLHeadingElement.h>
+#import <WebCore/DOMHTMLHtmlElement.h>
+#import <WebCore/DOMHTMLIFrameElement.h>
+#import <WebCore/DOMHTMLImageElement.h>
+#import <WebCore/DOMHTMLInputElement.h>
+#import <WebCore/DOMHTMLIsIndexElement.h>
+#import <WebCore/DOMHTMLLIElement.h>
+#import <WebCore/DOMHTMLLabelElement.h>
+#import <WebCore/DOMHTMLLegendElement.h>
+#import <WebCore/DOMHTMLLinkElement.h>
+#import <WebCore/DOMHTMLMapElement.h>
+#import <WebCore/DOMHTMLMarqueeElement.h>
+#import <WebCore/DOMHTMLMenuElement.h>
+#import <WebCore/DOMHTMLMetaElement.h>
+#import <WebCore/DOMHTMLModElement.h>
+#import <WebCore/DOMHTMLOListElement.h>
+#import <WebCore/DOMHTMLObjectElement.h>
+#import <WebCore/DOMHTMLOptGroupElement.h>
+#import <WebCore/DOMHTMLOptionElement.h>
+#import <WebCore/DOMHTMLOptionsCollection.h>
+#import <WebCore/DOMHTMLParagraphElement.h>
+#import <WebCore/DOMHTMLParamElement.h>
+#import <WebCore/DOMHTMLPreElement.h>
+#import <WebCore/DOMHTMLQuoteElement.h>
+#import <WebCore/DOMHTMLScriptElement.h>
+#import <WebCore/DOMHTMLSelectElement.h>
+#import <WebCore/DOMHTMLStyleElement.h>
+#import <WebCore/DOMHTMLTableCaptionElement.h>
+#import <WebCore/DOMHTMLTableCellElement.h>
+#import <WebCore/DOMHTMLTableColElement.h>
+#import <WebCore/DOMHTMLTableElement.h>
+#import <WebCore/DOMHTMLTableRowElement.h>
+#import <WebCore/DOMHTMLTableSectionElement.h>
+#import <WebCore/DOMHTMLTextAreaElement.h>
+#import <WebCore/DOMHTMLTitleElement.h>
+#import <WebCore/DOMHTMLUListElement.h>
diff --git a/WebCore/bindings/objc/DOMHTML.mm b/WebCore/bindings/objc/DOMHTML.mm
new file mode 100644
index 0000000..bf50e1b
--- /dev/null
+++ b/WebCore/bindings/objc/DOMHTML.mm
@@ -0,0 +1,187 @@
+/*
+ * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "DOMHTML.h"
+
+#import "CSSHelper.h"
+#import "DOMExtensions.h"
+#import "DOMInternal.h"
+#import "DOMPrivate.h"
+#import "DocumentFragment.h"
+#import "FrameView.h"
+#import "HTMLDocument.h"
+#import "HTMLInputElement.h"
+#import "HTMLObjectElement.h"
+#import "Range.h"
+#import "RenderTextControl.h"
+#import "markup.h"
+
+//------------------------------------------------------------------------------------------
+// DOMHTMLDocument
+
+@implementation DOMHTMLDocument (DOMHTMLDocumentExtensions)
+
+- (DOMDocumentFragment *)createDocumentFragmentWithMarkupString:(NSString *)markupString baseURL:(NSURL *)baseURL
+{
+ return [DOMDocumentFragment _wrapDocumentFragment:createFragmentFromMarkup([self _document], markupString, [baseURL absoluteString]).get()];
+}
+
+- (DOMDocumentFragment *)createDocumentFragmentWithText:(NSString *)text
+{
+ // FIXME: Since this is not a contextual fragment, it won't handle whitespace properly.
+ return [DOMDocumentFragment _wrapDocumentFragment:createFragmentFromText([self _document]->createRange().get(), text).get()];
+}
+
+@end
+
+@implementation DOMHTMLDocument (WebPrivate)
+
+- (DOMDocumentFragment *)_createDocumentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString
+{
+ NSURL *baseURL = [self _document]->completeURL(WebCore::parseURL(baseURLString));
+ return [self createDocumentFragmentWithMarkupString:markupString baseURL:baseURL];
+}
+
+- (DOMDocumentFragment *)_createDocumentFragmentWithText:(NSString *)text
+{
+ return [self createDocumentFragmentWithText:text];
+}
+
+@end
+
+#pragma mark DOM EXTENSIONS
+
+@implementation DOMHTMLInputElement(FormAutoFillTransition)
+
+- (BOOL)_isTextField
+{
+ // We could make this public API as-is, or we could change it into a method that returns whether
+ // the element is a text field or a button or ... ?
+ static NSArray *textInputTypes = nil;
+#ifndef NDEBUG
+ static NSArray *nonTextInputTypes = nil;
+#endif
+
+ NSString *fieldType = [self type];
+
+ // No type at all is treated as text type
+ if ([fieldType length] == 0)
+ return YES;
+
+ if (textInputTypes == nil)
+ textInputTypes = [[NSSet alloc] initWithObjects:@"text", @"password", @"search", @"isindex", nil];
+
+ BOOL isText = [textInputTypes containsObject:[fieldType lowercaseString]];
+
+#ifndef NDEBUG
+ if (nonTextInputTypes == nil)
+ nonTextInputTypes = [[NSSet alloc] initWithObjects:@"checkbox", @"radio", @"submit", @"reset", @"file", @"hidden", @"image", @"button", @"range", nil];
+
+ // Catch cases where a new input type has been added that's not in these lists.
+ ASSERT(isText || [nonTextInputTypes containsObject:[fieldType lowercaseString]]);
+#endif
+
+ return isText;
+}
+
+- (NSRect)_rectOnScreen
+{
+ // Returns bounding rect of text field, in screen coordinates.
+ NSRect result = [self boundingBox];
+ if (![self _HTMLInputElement]->document()->view())
+ return result;
+
+ NSView* view = [self _HTMLInputElement]->document()->view()->getDocumentView();
+ result = [view convertRect:result toView:nil];
+ result.origin = [[view window] convertBaseToScreen:result.origin];
+ return result;
+}
+
+- (void)_replaceCharactersInRange:(NSRange)targetRange withString:(NSString *)replacementString selectingFromIndex:(int)index
+{
+ WebCore::HTMLInputElement* inputElement = [self _HTMLInputElement];
+ if (inputElement) {
+ WebCore::String newValue = inputElement->value();
+ newValue.replace(targetRange.location, targetRange.length, replacementString);
+ inputElement->setValue(newValue);
+ inputElement->setSelectionRange(index, newValue.length());
+ }
+}
+
+- (NSRange)_selectedRange
+{
+ WebCore::HTMLInputElement* inputElement = [self _HTMLInputElement];
+ if (inputElement) {
+ int start = inputElement->selectionStart();
+ int end = inputElement->selectionEnd();
+ return NSMakeRange(start, end - start);
+ }
+ return NSMakeRange(NSNotFound, 0);
+}
+
+- (void)_setAutofilled:(BOOL)filled
+{
+ // This notifies the input element that the content has been autofilled
+ // This allows WebKit to obey the -webkit-autofill pseudo style, which
+ // changes the background color.
+ WebCore::HTMLInputElement* inputElement = [self _HTMLInputElement];
+ if (inputElement)
+ inputElement->setAutofilled(filled);
+}
+
+@end
+
+@implementation DOMHTMLSelectElement(FormAutoFillTransition)
+
+- (void)_activateItemAtIndex:(int)index
+{
+ // FIXME: Needs implementation for non-NSView <select>!
+}
+
+@end
+
+@implementation DOMHTMLInputElement (FormPromptAdditions)
+- (BOOL)_isEdited
+{
+ WebCore::RenderObject *renderer = [self _node]->renderer();
+ if (renderer && [self _isTextField])
+ return static_cast<WebCore::RenderTextControl *>(renderer)->isUserEdited();
+
+ return NO;
+}
+@end
+
+@implementation DOMHTMLTextAreaElement (FormPromptAdditions)
+- (BOOL)_isEdited
+{
+ WebCore::RenderObject *renderer = [self _node]->renderer();
+ if (renderer)
+ return static_cast<WebCore::RenderTextControl *>(renderer)->isUserEdited();
+
+ return NO;
+}
+@end
diff --git a/WebCore/bindings/objc/DOMImplementationFront.cpp b/WebCore/bindings/objc/DOMImplementationFront.cpp
new file mode 100644
index 0000000..19a2d76
--- /dev/null
+++ b/WebCore/bindings/objc/DOMImplementationFront.cpp
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#include "config.h"
+#include "DOMImplementationFront.h"
+
+#include "CSSStyleSheet.h"
+#include "DocumentType.h"
+#include "DOMImplementation.h"
+#include "HTMLDocument.h"
+#include "JSDOMImplementation.h"
+
+namespace WebCore {
+
+DOMImplementationFront* implementationFront(Document* document)
+{
+ return reinterpret_cast<DOMImplementationFront*>(document->implementation());
+}
+
+DOMImplementationFront* implementationFront(JSDOMImplementation* wrapper)
+{
+ return reinterpret_cast<DOMImplementationFront*>(wrapper->impl());
+}
+
+void DOMImplementationFront::ref()
+{
+ reinterpret_cast<DOMImplementation*>(this)->ref();
+}
+
+void DOMImplementationFront::deref()
+{
+ reinterpret_cast<DOMImplementation*>(this)->deref();
+}
+
+bool DOMImplementationFront::hasFeature(const String& feature, const String& version) const
+{
+ return reinterpret_cast<const DOMImplementation*>(this)->hasFeature(feature, version);
+}
+
+PassRefPtr<DocumentType> DOMImplementationFront::createDocumentType(const String& qualifiedName, const String& publicId, const String& systemId, ExceptionCode& ec)
+{
+ return reinterpret_cast<DOMImplementation*>(this)->createDocumentType(qualifiedName, publicId, systemId, ec);
+}
+
+PassRefPtr<Document> DOMImplementationFront::createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType* type, ExceptionCode& ec)
+{
+ return reinterpret_cast<DOMImplementation*>(this)->createDocument(namespaceURI, qualifiedName, type, ec);
+}
+
+DOMImplementationFront* DOMImplementationFront::getInterface(const String& feature) const
+{
+ return reinterpret_cast<DOMImplementationFront*>(reinterpret_cast<const DOMImplementation*>(this)->getInterface(feature));
+}
+
+PassRefPtr<CSSStyleSheet> DOMImplementationFront::createCSSStyleSheet(const String& title, const String& media, ExceptionCode& ec)
+{
+ return reinterpret_cast<DOMImplementation*>(this)->createCSSStyleSheet(title, media, ec);
+}
+
+PassRefPtr<HTMLDocument> DOMImplementationFront::createHTMLDocument(const String& title)
+{
+ return reinterpret_cast<DOMImplementation*>(this)->createHTMLDocument(title);
+}
+
+} //namespace
diff --git a/WebCore/bindings/objc/DOMImplementationFront.h b/WebCore/bindings/objc/DOMImplementationFront.h
new file mode 100644
index 0000000..14c1037
--- /dev/null
+++ b/WebCore/bindings/objc/DOMImplementationFront.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef DOMImplementationFront_h
+#define DOMImplementationFront_h
+
+// FIXME: This source file exists to work around a problem that occurs trying
+// to mix DOMImplementation and WebCore::DOMImplementation in DOM.mm.
+// It seems to affect only older versions of gcc. Once the buildbot is upgraded,
+// we should consider increasing the minimum required version of gcc to build
+// WebCore, and rolling the change that introduced this file back.
+
+#include <wtf/Forward.h>
+
+namespace WebCore {
+
+class CSSStyleSheet;
+class Document;
+class DocumentType;
+class HTMLDocument;
+class JSDOMImplementation;
+class String;
+
+typedef int ExceptionCode;
+
+class DOMImplementationFront {
+public:
+ void ref();
+ void deref();
+ bool hasFeature(const String& feature, const String& version) const;
+ PassRefPtr<DocumentType> createDocumentType(const String& qualifiedName, const String& publicId, const String& systemId, ExceptionCode&);
+ PassRefPtr<Document> createDocument(const String& namespaceURI, const String& qualifiedName, DocumentType*, ExceptionCode&);
+ DOMImplementationFront* getInterface(const String& feature) const;
+ PassRefPtr<CSSStyleSheet> createCSSStyleSheet(const String& title, const String& media, ExceptionCode&);
+ PassRefPtr<HTMLDocument> createHTMLDocument(const String& title);
+};
+
+DOMImplementationFront* implementationFront(Document*);
+DOMImplementationFront* implementationFront(JSDOMImplementation*);
+
+} // namespace WebCore
+
+#endif // DOMImplementationFront_h
diff --git a/WebCore/bindings/objc/DOMInternal.h b/WebCore/bindings/objc/DOMInternal.h
new file mode 100644
index 0000000..5bd8c77
--- /dev/null
+++ b/WebCore/bindings/objc/DOMInternal.h
@@ -0,0 +1,356 @@
+/*
+ * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 James G. Speth (speth@end.com)
+ * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "DOM.h"
+
+#import "Color.h"
+#import "DOMObject.h"
+#import "DOMRGBColor.h"
+#import "HitTestResult.h"
+
+#if ENABLE(XPATH)
+#import "DOMXPathExpressionInternal.h"
+#import "DOMXPathNSResolver.h"
+#import "DOMXPathResultInternal.h"
+#endif // ENABLE(XPATH)
+
+// Auto-generated internal interfaces
+#import "DOMAbstractViewInternal.h"
+#import "DOMAttrInternal.h"
+#import "DOMCDATASectionInternal.h"
+#import "DOMCSSCharsetRuleInternal.h"
+#import "DOMCSSFontFaceRuleInternal.h"
+#import "DOMCSSImportRuleInternal.h"
+#import "DOMCSSMediaRuleInternal.h"
+#import "DOMCSSPageRuleInternal.h"
+#import "DOMCSSPrimitiveValueInternal.h"
+#import "DOMCSSRuleInternal.h"
+#import "DOMCSSRuleListInternal.h"
+#import "DOMCSSStyleDeclarationInternal.h"
+#import "DOMCSSStyleRuleInternal.h"
+#import "DOMCSSStyleSheetInternal.h"
+#import "DOMCSSUnknownRuleInternal.h"
+#import "DOMCSSValueInternal.h"
+#import "DOMCSSValueListInternal.h"
+#import "DOMCharacterDataInternal.h"
+#import "DOMCommentInternal.h"
+#import "DOMCounterInternal.h"
+#import "DOMDOMImplementationInternal.h"
+#import "DOMDocumentFragmentInternal.h"
+#import "DOMDocumentInternal.h"
+#import "DOMDocumentTypeInternal.h"
+#import "DOMElementInternal.h"
+#import "DOMEntityInternal.h"
+#import "DOMEntityReferenceInternal.h"
+#import "DOMEventInternal.h"
+#import "DOMHTMLAnchorElementInternal.h"
+#import "DOMHTMLAppletElementInternal.h"
+#import "DOMHTMLAreaElementInternal.h"
+#import "DOMHTMLBRElementInternal.h"
+#import "DOMHTMLBaseElementInternal.h"
+#import "DOMHTMLBaseFontElementInternal.h"
+#import "DOMHTMLBodyElementInternal.h"
+#import "DOMHTMLButtonElementInternal.h"
+#import "DOMHTMLCollectionInternal.h"
+#import "DOMHTMLDListElementInternal.h"
+#import "DOMHTMLDirectoryElementInternal.h"
+#import "DOMHTMLDivElementInternal.h"
+#import "DOMHTMLDocumentInternal.h"
+#import "DOMHTMLElementInternal.h"
+#import "DOMHTMLEmbedElementInternal.h"
+#import "DOMHTMLFieldSetElementInternal.h"
+#import "DOMHTMLFontElementInternal.h"
+#import "DOMHTMLFormElementInternal.h"
+#import "DOMHTMLFrameElementInternal.h"
+#import "DOMHTMLFrameSetElementInternal.h"
+#import "DOMHTMLHRElementInternal.h"
+#import "DOMHTMLHeadElementInternal.h"
+#import "DOMHTMLHeadingElementInternal.h"
+#import "DOMHTMLHtmlElementInternal.h"
+#import "DOMHTMLIFrameElementInternal.h"
+#import "DOMHTMLImageElementInternal.h"
+#import "DOMHTMLInputElementInternal.h"
+#import "DOMHTMLIsIndexElementInternal.h"
+#import "DOMHTMLLIElementInternal.h"
+#import "DOMHTMLLabelElementInternal.h"
+#import "DOMHTMLLegendElementInternal.h"
+#import "DOMHTMLLinkElementInternal.h"
+#import "DOMHTMLMapElementInternal.h"
+#import "DOMHTMLMarqueeElementInternal.h"
+#import "DOMHTMLMenuElementInternal.h"
+#import "DOMHTMLMetaElementInternal.h"
+#import "DOMHTMLModElementInternal.h"
+#import "DOMHTMLOListElementInternal.h"
+#import "DOMHTMLObjectElementInternal.h"
+#import "DOMHTMLOptGroupElementInternal.h"
+#import "DOMHTMLOptionElementInternal.h"
+#import "DOMHTMLOptionsCollectionInternal.h"
+#import "DOMHTMLParagraphElementInternal.h"
+#import "DOMHTMLParamElementInternal.h"
+#import "DOMHTMLPreElementInternal.h"
+#import "DOMHTMLQuoteElementInternal.h"
+#import "DOMHTMLScriptElementInternal.h"
+#import "DOMHTMLSelectElementInternal.h"
+#import "DOMHTMLStyleElementInternal.h"
+#import "DOMHTMLTableCaptionElementInternal.h"
+#import "DOMHTMLTableCellElementInternal.h"
+#import "DOMHTMLTableColElementInternal.h"
+#import "DOMHTMLTableElementInternal.h"
+#import "DOMHTMLTableRowElementInternal.h"
+#import "DOMHTMLTableSectionElementInternal.h"
+#import "DOMHTMLTextAreaElementInternal.h"
+#import "DOMHTMLTitleElementInternal.h"
+#import "DOMHTMLUListElementInternal.h"
+#import "DOMKeyboardEventInternal.h"
+#import "DOMMediaListInternal.h"
+#import "DOMMouseEventInternal.h"
+#import "DOMMutationEventInternal.h"
+#import "DOMNamedNodeMapInternal.h"
+#import "DOMNodeInternal.h"
+#import "DOMNodeIteratorInternal.h"
+#import "DOMNodeListInternal.h"
+#import "DOMNotationInternal.h"
+#import "DOMOverflowEventInternal.h"
+#import "DOMProcessingInstructionInternal.h"
+#import "DOMRangeInternal.h"
+#import "DOMRectInternal.h"
+#import "DOMStyleSheetInternal.h"
+#import "DOMStyleSheetListInternal.h"
+#import "DOMTextInternal.h"
+#import "DOMTextEventInternal.h"
+#import "DOMTreeWalkerInternal.h"
+#import "DOMUIEventInternal.h"
+#import "DOMWheelEventInternal.h"
+
+#if ENABLE(SVG)
+#import "DOMSVGAElementInternal.h"
+#import "DOMSVGAngleInternal.h"
+#import "DOMSVGAnimateColorElementInternal.h"
+#import "DOMSVGAnimateElementInternal.h"
+#import "DOMSVGAnimateTransformElementInternal.h"
+#import "DOMSVGAnimatedAngleInternal.h"
+#import "DOMSVGAnimatedBooleanInternal.h"
+#import "DOMSVGAnimatedEnumerationInternal.h"
+#import "DOMSVGAnimatedIntegerInternal.h"
+#import "DOMSVGAnimatedLengthInternal.h"
+#import "DOMSVGAnimatedLengthListInternal.h"
+#import "DOMSVGAnimatedNumberInternal.h"
+#import "DOMSVGAnimatedNumberListInternal.h"
+#import "DOMSVGAnimatedPreserveAspectRatioInternal.h"
+#import "DOMSVGAnimatedRectInternal.h"
+#import "DOMSVGAnimatedStringInternal.h"
+#import "DOMSVGAnimatedTransformListInternal.h"
+#import "DOMSVGAnimationElementInternal.h"
+#import "DOMSVGCircleElementInternal.h"
+#import "DOMSVGClipPathElementInternal.h"
+#import "DOMSVGColorInternal.h"
+#import "DOMSVGComponentTransferFunctionElementInternal.h"
+#import "DOMSVGCursorElementInternal.h"
+#import "DOMSVGDefsElementInternal.h"
+#import "DOMSVGDefinitionSrcElementInternal.h"
+#import "DOMSVGDescElementInternal.h"
+#import "DOMSVGDocumentInternal.h"
+#import "DOMSVGElementInternal.h"
+#import "DOMSVGElementInstanceInternal.h"
+#import "DOMSVGElementInstanceListInternal.h"
+#import "DOMSVGEllipseElementInternal.h"
+#import "DOMSVGFEBlendElementInternal.h"
+#import "DOMSVGFEColorMatrixElementInternal.h"
+#import "DOMSVGFEComponentTransferElementInternal.h"
+#import "DOMSVGFECompositeElementInternal.h"
+#import "DOMSVGFEDiffuseLightingElementInternal.h"
+#import "DOMSVGFEDisplacementMapElementInternal.h"
+#import "DOMSVGFEDistantLightElementInternal.h"
+#import "DOMSVGFEFloodElementInternal.h"
+#import "DOMSVGFEFuncAElementInternal.h"
+#import "DOMSVGFEFuncBElementInternal.h"
+#import "DOMSVGFEFuncGElementInternal.h"
+#import "DOMSVGFEFuncRElementInternal.h"
+#import "DOMSVGFEGaussianBlurElementInternal.h"
+#import "DOMSVGFEImageElementInternal.h"
+#import "DOMSVGFEMergeElementInternal.h"
+#import "DOMSVGFEMergeNodeElementInternal.h"
+#import "DOMSVGFEOffsetElementInternal.h"
+#import "DOMSVGFEPointLightElementInternal.h"
+#import "DOMSVGFESpecularLightingElementInternal.h"
+#import "DOMSVGFESpotLightElementInternal.h"
+#import "DOMSVGFETileElementInternal.h"
+#import "DOMSVGFETurbulenceElementInternal.h"
+#import "DOMSVGFilterElementInternal.h"
+#import "DOMSVGFontElementInternal.h"
+#import "DOMSVGFontFaceElementInternal.h"
+#import "DOMSVGFontFaceFormatElementInternal.h"
+#import "DOMSVGFontFaceNameElementInternal.h"
+#import "DOMSVGFontFaceSrcElementInternal.h"
+#import "DOMSVGFontFaceUriElementInternal.h"
+#import "DOMSVGForeignObjectElementInternal.h"
+#import "DOMSVGGElementInternal.h"
+#import "DOMSVGGlyphElementInternal.h"
+#import "DOMSVGGradientElementInternal.h"
+#import "DOMSVGImageElementInternal.h"
+#import "DOMSVGLengthInternal.h"
+#import "DOMSVGLengthListInternal.h"
+#import "DOMSVGLineElementInternal.h"
+#import "DOMSVGLinearGradientElementInternal.h"
+#import "DOMSVGMarkerElementInternal.h"
+#import "DOMSVGMaskElementInternal.h"
+#import "DOMSVGMatrixInternal.h"
+#import "DOMSVGMetadataElementInternal.h"
+#import "DOMSVGMissingGlyphElementInternal.h"
+#import "DOMSVGNumberInternal.h"
+#import "DOMSVGNumberListInternal.h"
+#import "DOMSVGPaintInternal.h"
+#import "DOMSVGPathElementInternal.h"
+#import "DOMSVGPathSegArcAbsInternal.h"
+#import "DOMSVGPathSegArcRelInternal.h"
+#import "DOMSVGPathSegClosePathInternal.h"
+#import "DOMSVGPathSegCurvetoCubicAbsInternal.h"
+#import "DOMSVGPathSegCurvetoCubicRelInternal.h"
+#import "DOMSVGPathSegCurvetoCubicSmoothAbsInternal.h"
+#import "DOMSVGPathSegCurvetoCubicSmoothRelInternal.h"
+#import "DOMSVGPathSegCurvetoQuadraticAbsInternal.h"
+#import "DOMSVGPathSegCurvetoQuadraticRelInternal.h"
+#import "DOMSVGPathSegCurvetoQuadraticSmoothAbsInternal.h"
+#import "DOMSVGPathSegCurvetoQuadraticSmoothRelInternal.h"
+#import "DOMSVGPathSegInternal.h"
+#import "DOMSVGPathSegLinetoAbsInternal.h"
+#import "DOMSVGPathSegLinetoHorizontalAbsInternal.h"
+#import "DOMSVGPathSegLinetoHorizontalRelInternal.h"
+#import "DOMSVGPathSegLinetoRelInternal.h"
+#import "DOMSVGPathSegLinetoVerticalAbsInternal.h"
+#import "DOMSVGPathSegLinetoVerticalRelInternal.h"
+#import "DOMSVGPathSegListInternal.h"
+#import "DOMSVGPathSegMovetoAbsInternal.h"
+#import "DOMSVGPathSegMovetoRelInternal.h"
+#import "DOMSVGPatternElementInternal.h"
+#import "DOMSVGPointInternal.h"
+#import "DOMSVGPointListInternal.h"
+#import "DOMSVGPolygonElementInternal.h"
+#import "DOMSVGPolylineElementInternal.h"
+#import "DOMSVGPreserveAspectRatioInternal.h"
+#import "DOMSVGRadialGradientElementInternal.h"
+#import "DOMSVGRectElementInternal.h"
+#import "DOMSVGRectInternal.h"
+#import "DOMSVGRenderingIntentInternal.h"
+#import "DOMSVGSVGElementInternal.h"
+#import "DOMSVGScriptElementInternal.h"
+#import "DOMSVGSetElementInternal.h"
+#import "DOMSVGStopElementInternal.h"
+#import "DOMSVGStringListInternal.h"
+#import "DOMSVGStyleElementInternal.h"
+#import "DOMSVGSwitchElementInternal.h"
+#import "DOMSVGSymbolElementInternal.h"
+#import "DOMSVGTRefElementInternal.h"
+#import "DOMSVGTSpanElementInternal.h"
+#import "DOMSVGTextContentElementInternal.h"
+#import "DOMSVGTextElementInternal.h"
+#import "DOMSVGTextPathElementInternal.h"
+#import "DOMSVGTextPositioningElementInternal.h"
+#import "DOMSVGTitleElementInternal.h"
+#import "DOMSVGTransformInternal.h"
+#import "DOMSVGTransformListInternal.h"
+#import "DOMSVGUnitTypesInternal.h"
+#import "DOMSVGUseElementInternal.h"
+#import "DOMSVGViewElementInternal.h"
+#import "DOMSVGZoomEventInternal.h"
+#endif // ENABLE(SVG)
+
+namespace KJS {
+ class JSObject;
+
+ namespace Bindings {
+ class RootObject;
+ }
+}
+
+namespace WebCore {
+ class NodeFilter;
+
+#if ENABLE(SVG)
+ class AffineTransform;
+ class FloatPoint;
+ class FloatRect;
+#endif // ENABLE(SVG)
+
+#if ENABLE(XPATH)
+ class XPathNSResolver;
+#endif // ENABLE(XPATH)
+}
+
+// Core Internal Interfaces
+
+@interface DOMObject (WebCoreInternal)
+- (id)_init;
+@end
+
+// CSS Internal Interfaces
+
+@interface DOMRGBColor (WebCoreInternal)
++ (DOMRGBColor *)_wrapRGBColor:(WebCore::RGBA32)value;
+- (WebCore::RGBA32)_RGBColor;
+@end
+
+// Traversal Internal Interfaces
+
+@interface DOMNodeFilter : DOMObject <DOMNodeFilter>
++ (DOMNodeFilter *)_wrapNodeFilter:(WebCore::NodeFilter *)impl;
+@end
+
+#if ENABLE(XPATH)
+
+// XPath Internal Interfaces
+
+@interface DOMNativeXPathNSResolver : DOMObject <DOMXPathNSResolver>
++ (DOMNativeXPathNSResolver *)_wrapXPathNSResolver:(WebCore::XPathNSResolver *)impl;
+- (WebCore::XPathNSResolver *)_xpathNSResolver;
+@end
+
+#endif // ENABLE(XPATH)
+
+// Helper functions for DOM wrappers and gluing to Objective-C
+
+namespace WebCore {
+
+ id createDOMWrapper(KJS::JSObject*, PassRefPtr<KJS::Bindings::RootObject> origin, PassRefPtr<KJS::Bindings::RootObject> current);
+
+ NSObject* getDOMWrapper(DOMObjectInternal*);
+ void addDOMWrapper(NSObject* wrapper, DOMObjectInternal*);
+ void removeDOMWrapper(DOMObjectInternal*);
+
+ template <class Source>
+ inline id getDOMWrapper(Source impl)
+ {
+ return getDOMWrapper(reinterpret_cast<DOMObjectInternal*>(impl));
+ }
+
+ template <class Source>
+ inline void addDOMWrapper(NSObject* wrapper, Source impl)
+ {
+ addDOMWrapper(wrapper, reinterpret_cast<DOMObjectInternal*>(impl));
+ }
+
+} // namespace WebCore
diff --git a/WebCore/bindings/objc/DOMInternal.mm b/WebCore/bindings/objc/DOMInternal.mm
new file mode 100644
index 0000000..afef8c8
--- /dev/null
+++ b/WebCore/bindings/objc/DOMInternal.mm
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "DOMInternal.h"
+
+#import "Document.h"
+#import "Event.h"
+#import "Frame.h"
+#import "JSNode.h"
+#import "Node.h"
+#import "PlatformString.h"
+#import "Range.h"
+#import "RangeException.h"
+#import "SVGException.h"
+#import "WebScriptObjectPrivate.h"
+#import "XPathEvaluator.h"
+#import "kjs_proxy.h"
+
+//------------------------------------------------------------------------------------------
+// Wrapping WebCore implementation objects
+
+namespace WebCore {
+
+typedef HashMap<DOMObjectInternal*, NSObject*> DOMWrapperMap;
+static DOMWrapperMap* DOMWrapperCache;
+
+NSObject* getDOMWrapper(DOMObjectInternal* impl)
+{
+ if (!DOMWrapperCache)
+ return nil;
+ return DOMWrapperCache->get(impl);
+}
+
+void addDOMWrapper(NSObject* wrapper, DOMObjectInternal* impl)
+{
+ if (!DOMWrapperCache)
+ DOMWrapperCache = new DOMWrapperMap;
+ DOMWrapperCache->set(impl, wrapper);
+}
+
+void removeDOMWrapper(DOMObjectInternal* impl)
+{
+ if (!DOMWrapperCache)
+ return;
+ DOMWrapperCache->remove(impl);
+}
+
+} // namespace WebCore
+
+
+//------------------------------------------------------------------------------------------
+
+@implementation WebScriptObject (WebScriptObjectInternal)
+
+// Only called by DOMObject subclass.
+- (id)_init
+{
+ self = [super init];
+
+ if (![self isKindOfClass:[DOMObject class]]) {
+ [NSException raise:NSGenericException format:@"+%@: _init is an internal initializer", [self class]];
+ return nil;
+ }
+
+ _private = [[WebScriptObjectPrivate alloc] init];
+ _private->isCreatedByDOMWrapper = YES;
+
+ return self;
+}
+
+- (void)_initializeScriptDOMNodeImp
+{
+ assert (_private->isCreatedByDOMWrapper);
+
+ if (![self isKindOfClass:[DOMNode class]]) {
+ // DOMObject can't map back to a document, and thus an interpreter,
+ // so for now only create wrappers for DOMNodes.
+ NSLog(@"%s:%d: We don't know how to create ObjC JS wrappers from DOMObjects yet.", __FILE__, __LINE__);
+ return;
+ }
+
+ // Extract the WebCore::Node from the ObjectiveC wrapper.
+ DOMNode *n = (DOMNode *)self;
+ WebCore::Node *nodeImpl = [n _node];
+
+ // Dig up Interpreter and ExecState.
+ WebCore::Frame *frame = 0;
+ if (WebCore::Document* document = nodeImpl->document())
+ frame = document->frame();
+ if (!frame)
+ return;
+
+ KJS::ExecState *exec = frame->scriptProxy()->globalObject()->globalExec();
+
+ // Get (or create) a cached JS object for the DOM node.
+ KJS::JSObject *scriptImp = static_cast<KJS::JSObject*>(WebCore::toJS(exec, nodeImpl));
+
+ KJS::Bindings::RootObject* rootObject = frame->bindingRootObject();
+
+ [self _setImp:scriptImp originRootObject:rootObject rootObject:rootObject];
+}
+
+@end
diff --git a/WebCore/bindings/objc/DOMObject.h b/WebCore/bindings/objc/DOMObject.h
new file mode 100644
index 0000000..22d739e
--- /dev/null
+++ b/WebCore/bindings/objc/DOMObject.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMException.h>
+#import <WebCore/WebScriptObject.h>
+
+@class DOMStyleSheet;
+
+typedef unsigned long long DOMTimeStamp;
+
+typedef struct DOMObjectInternal DOMObjectInternal;
+
+@interface DOMObject : WebScriptObject <NSCopying>
+{
+ DOMObjectInternal *_internal;
+}
+@end
+
+@interface DOMObject (DOMLinkStyle)
+#ifndef BUILDING_ON_TIGER
+@property(readonly, retain) DOMStyleSheet *sheet;
+#else
+- (DOMStyleSheet *)sheet;
+#endif
+@end
diff --git a/WebCore/bindings/objc/DOMObject.mm b/WebCore/bindings/objc/DOMObject.mm
new file mode 100644
index 0000000..f820df9
--- /dev/null
+++ b/WebCore/bindings/objc/DOMObject.mm
@@ -0,0 +1,100 @@
+/*
+ * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 James G. Speth <speth@end.com>
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "DOMObject.h"
+
+#import "DOMHTMLLinkElement.h"
+#import "DOMHTMLStyleElement.h"
+#import "DOMInternal.h"
+#import "DOMProcessingInstruction.h"
+#import "DOMStyleSheet.h"
+#import "HTMLLinkElement.h"
+#import "HTMLStyleElement.h"
+#import "ProcessingInstruction.h"
+#import "StyleSheet.h"
+#import "WebScriptObjectPrivate.h"
+
+@implementation DOMObject
+
+// Prevent creation of DOM objects by clients who just "[[xxx alloc] init]".
+- (id)init
+{
+ [NSException raise:NSGenericException format:@"+[%@ init]: should never be used", NSStringFromClass([self class])];
+ [self release];
+ return nil;
+}
+
+- (void)dealloc
+{
+ if (_internal)
+ WebCore::removeDOMWrapper(_internal);
+ [super dealloc];
+}
+
+- (void)finalize
+{
+ if (_internal)
+ WebCore::removeDOMWrapper(_internal);
+ [super finalize];
+}
+
+- (id)copyWithZone:(NSZone *)zone
+{
+ return [self retain];
+}
+
+@end
+
+@implementation DOMObject (DOMLinkStyle)
+
+- (DOMStyleSheet *)sheet
+{
+ WebCore::StyleSheet *styleSheet;
+
+ if ([self isKindOfClass:[DOMProcessingInstruction class]])
+ styleSheet = static_cast<WebCore::ProcessingInstruction*>([(DOMProcessingInstruction *)self _node])->sheet();
+ else if ([self isKindOfClass:[DOMHTMLLinkElement class]])
+ styleSheet = static_cast<WebCore::HTMLLinkElement*>([(DOMHTMLLinkElement *)self _node])->sheet();
+ else if ([self isKindOfClass:[DOMHTMLStyleElement class]])
+ styleSheet = static_cast<WebCore::HTMLStyleElement*>([(DOMHTMLStyleElement *)self _node])->sheet();
+ else
+ return nil;
+
+ return [DOMStyleSheet _wrapStyleSheet:styleSheet];
+}
+
+@end
+
+@implementation DOMObject (WebCoreInternal)
+
+- (id)_init
+{
+ return [super _init];
+}
+
+@end
diff --git a/WebCore/bindings/objc/DOMPrivate.h b/WebCore/bindings/objc/DOMPrivate.h
new file mode 100644
index 0000000..1322560
--- /dev/null
+++ b/WebCore/bindings/objc/DOMPrivate.h
@@ -0,0 +1,130 @@
+/*
+ * Copyright (C) 2004-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCSS.h>
+#import <WebCore/DOMCSSStyleDeclaration.h>
+#import <WebCore/DOMElement.h>
+#import <WebCore/DOMEvents.h>
+#import <WebCore/DOMHTML.h>
+#import <WebCore/DOMHTMLDocument.h>
+#import <WebCore/DOMHTMLInputElement.h>
+#import <WebCore/DOMHTMLSelectElement.h>
+#import <WebCore/DOMNode.h>
+#import <WebCore/DOMRGBColor.h>
+#import <WebCore/DOMRange.h>
+
+#import <WebCore/DOMDocumentPrivate.h>
+#import <WebCore/DOMElementPrivate.h>
+#import <WebCore/DOMHTMLAnchorElementPrivate.h>
+#import <WebCore/DOMHTMLAreaElementPrivate.h>
+#import <WebCore/DOMHTMLBodyElementPrivate.h>
+#import <WebCore/DOMHTMLButtonElementPrivate.h>
+#import <WebCore/DOMHTMLDocumentPrivate.h>
+#import <WebCore/DOMHTMLFormElementPrivate.h>
+#import <WebCore/DOMHTMLFrameElementPrivate.h>
+#import <WebCore/DOMHTMLImageElementPrivate.h>
+#import <WebCore/DOMHTMLInputElementPrivate.h>
+#import <WebCore/DOMHTMLLabelElementPrivate.h>
+#import <WebCore/DOMHTMLLegendElementPrivate.h>
+#import <WebCore/DOMHTMLLinkElementPrivate.h>
+#import <WebCore/DOMHTMLOptionsCollectionPrivate.h>
+#import <WebCore/DOMHTMLPreElementPrivate.h>
+#import <WebCore/DOMHTMLStyleElementPrivate.h>
+#import <WebCore/DOMHTMLTextAreaElementPrivate.h>
+#import <WebCore/DOMKeyboardEventPrivate.h>
+#import <WebCore/DOMMouseEventPrivate.h>
+#import <WebCore/DOMNodeIteratorPrivate.h>
+#import <WebCore/DOMNodePrivate.h>
+#import <WebCore/DOMProcessingInstructionPrivate.h>
+#import <WebCore/DOMRangePrivate.h>
+#import <WebCore/DOMUIEventPrivate.h>
+#import <WebCore/DOMWheelEventPrivate.h>
+
+// FIXME: this should be removed as soon as all internal Apple uses of it have been replaced with
+// calls to the public method - (NSColor *)color.
+@interface DOMRGBColor (WebPrivate)
+- (NSColor *)_color;
+@end
+
+// FIXME: this should be removed as soon as all internal Apple uses of it have been replaced with
+// calls to the public method - (NSString *)text.
+@interface DOMRange (WebPrivate)
+- (NSString *)_text;
+@end
+
+@interface DOMRange (DOMRangeExtensions)
+- (NSRect)boundingBox;
+- (NSArray *)lineBoxRects;
+@end
+
+@interface DOMElement (WebPrivate)
+- (NSFont *)_font;
+- (NSData *)_imageTIFFRepresentation;
+- (NSURL *)_getURLAttribute:(NSString *)name;
+- (void *)_NPObject; // For subclasses to implement; we only allow NPObjects to be created for certain element types
+- (NSRect)_windowClipRect; // Clip rect in NSWindow coords (used by plugins)
+- (BOOL)isFocused;
+@end
+
+@interface DOMCSSStyleDeclaration (WebPrivate)
+- (NSString *)_fontSizeDelta;
+- (void)_setFontSizeDelta:(NSString *)fontSizeDelta;
+@end
+
+@interface DOMHTMLDocument (WebPrivate)
+- (DOMDocumentFragment *)_createDocumentFragmentWithMarkupString:(NSString *)markupString baseURLString:(NSString *)baseURLString;
+- (DOMDocumentFragment *)_createDocumentFragmentWithText:(NSString *)text;
+@end
+
+// All the methods in this category are used by Safari forms autofill and should not be used for any other purpose.
+// They are stopgap measures until we finish transitioning form controls to not use NSView. Each one should become
+// replaceable by public DOM API, and when that happens Safari will switch to implementations using that public API,
+// and these will be deleted.
+@interface DOMHTMLInputElement (FormsAutoFillTransition)
+- (BOOL)_isTextField;
+- (NSRect)_rectOnScreen; // bounding box of the text field, in screen coordinates
+- (void)_replaceCharactersInRange:(NSRange)targetRange withString:(NSString *)replacementString selectingFromIndex:(int)index;
+- (NSRange)_selectedRange;
+- (void)_setAutofilled:(BOOL)filled;
+@end
+
+// These changes are necessary to detect whether a form input was modified by a user
+// or javascript
+@interface DOMHTMLInputElement (FormPromptAdditions)
+- (BOOL)_isEdited;
+@end
+
+@interface DOMHTMLTextAreaElement (FormPromptAdditions)
+- (BOOL)_isEdited;
+@end
+
+// All the methods in this category are used by Safari forms autofill and should not be used for any other purpose.
+// They are stopgap measures until we finish transitioning form controls to not use NSView. Each one should become
+// replaceable by public DOM API, and when that happens Safari will switch to implementations using that public API,
+// and these will be deleted.
+@interface DOMHTMLSelectElement (FormsAutoFillTransition)
+- (void)_activateItemAtIndex:(int)index;
+@end
diff --git a/WebCore/bindings/objc/DOMRGBColor.mm b/WebCore/bindings/objc/DOMRGBColor.mm
new file mode 100644
index 0000000..8c35a9f
--- /dev/null
+++ b/WebCore/bindings/objc/DOMRGBColor.mm
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig (sam.weinig@gmail.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "DOMRGBColor.h"
+
+#import "CSSPrimitiveValue.h"
+#import "Color.h"
+#import "ColorMac.h"
+#import "DOMCSSPrimitiveValue.h"
+#import "DOMInternal.h"
+#import "WebCoreObjCExtras.h"
+#import <wtf/GetPtr.h>
+
+namespace WebCore {
+
+static CFMutableDictionaryRef wrapperCache = NULL;
+
+id getWrapperForRGB(WebCore::RGBA32 value)
+{
+ if (!wrapperCache)
+ return nil;
+ return (id)CFDictionaryGetValue(wrapperCache, reinterpret_cast<const void*>(value));
+}
+
+void setWrapperForRGB(id wrapper, WebCore::RGBA32 value)
+{
+ if (!wrapperCache)
+ // No need to retain/free either impl key, or id value. Items will be removed
+ // from the cache in dealloc methods.
+ wrapperCache = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);
+ CFDictionarySetValue(wrapperCache, reinterpret_cast<const void*>(value), wrapper);
+}
+
+void removeWrapperForRGB(WebCore::RGBA32 value)
+{
+ if (!wrapperCache)
+ return;
+ CFDictionaryRemoveValue(wrapperCache, reinterpret_cast<const void*>(value));
+}
+
+} // namespace WebCore
+
+
+@implementation DOMRGBColor
+
+#ifndef BUILDING_ON_TIGER
++ (void)initialize
+{
+ WebCoreObjCFinalizeOnMainThread(self);
+}
+#endif
+
+- (void)dealloc
+{
+ WebCore::removeWrapperForRGB(reinterpret_cast<uintptr_t>(_internal));
+ _internal = 0;
+ [super dealloc];
+}
+
+- (void)finalize
+{
+ WebCore::removeWrapperForRGB(reinterpret_cast<uintptr_t>(_internal));
+ [super finalize];
+}
+
+- (DOMCSSPrimitiveValue *)red
+{
+ WebCore::RGBA32 rgb = reinterpret_cast<uintptr_t>(_internal);
+ int value = (rgb >> 16) & 0xFF;
+ return [DOMCSSPrimitiveValue _wrapCSSPrimitiveValue:new WebCore::CSSPrimitiveValue(value, WebCore::CSSPrimitiveValue::CSS_NUMBER)];
+}
+
+- (DOMCSSPrimitiveValue *)green
+{
+ WebCore::RGBA32 rgb = reinterpret_cast<uintptr_t>(_internal);
+ int value = (rgb >> 8) & 0xFF;
+ return [DOMCSSPrimitiveValue _wrapCSSPrimitiveValue:new WebCore::CSSPrimitiveValue(value, WebCore::CSSPrimitiveValue::CSS_NUMBER)];
+}
+
+- (DOMCSSPrimitiveValue *)blue
+{
+ WebCore::RGBA32 rgb = reinterpret_cast<uintptr_t>(_internal);
+ int value = rgb & 0xFF;
+ return [DOMCSSPrimitiveValue _wrapCSSPrimitiveValue:new WebCore::CSSPrimitiveValue(value, WebCore::CSSPrimitiveValue::CSS_NUMBER)];
+}
+
+- (DOMCSSPrimitiveValue *)alpha
+{
+ WebCore::RGBA32 rgb = reinterpret_cast<uintptr_t>(_internal);
+ float value = static_cast<float>(WebCore::Color(rgb).alpha()) / 0xFF;
+ return [DOMCSSPrimitiveValue _wrapCSSPrimitiveValue:new WebCore::CSSPrimitiveValue(value, WebCore::CSSPrimitiveValue::CSS_NUMBER)];
+
+}
+
+- (NSColor *)color
+{
+ WebCore::RGBA32 rgb = reinterpret_cast<uintptr_t>(_internal);
+ return WebCore::nsColor(WebCore::Color(rgb));
+}
+
+@end
+
+@implementation DOMRGBColor (WebPrivate)
+
+// FIXME: this should be removed as soon as all internal Apple uses of it have been replaced with
+// calls to the public method - (NSColor *)color.
+- (NSColor *)_color
+{
+ return [self color];
+}
+
+@end
+
+@implementation DOMRGBColor (WebCoreInternal)
+
+- (WebCore::RGBA32)_RGBColor
+{
+ return static_cast<WebCore::RGBA32>(reinterpret_cast<uintptr_t>(_internal));
+}
+
+- (id)_initWithRGB:(WebCore::RGBA32)value
+{
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(value);
+ WebCore::setWrapperForRGB(self, value);
+ return self;
+}
+
++ (DOMRGBColor *)_wrapRGBColor:(WebCore::RGBA32)value
+{
+ id cachedInstance;
+ cachedInstance = WebCore::getWrapperForRGB(value);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+ return [[[self alloc] _initWithRGB:value] autorelease];
+}
+
+@end
diff --git a/WebCore/bindings/objc/DOMRangeException.h b/WebCore/bindings/objc/DOMRangeException.h
new file mode 100644
index 0000000..a625d49
--- /dev/null
+++ b/WebCore/bindings/objc/DOMRangeException.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+@class NSString;
+
+extern NSString * const DOMRangeException;
+
+enum DOMRangeExceptionCode {
+ DOM_BAD_BOUNDARYPOINTS_ERR = 1,
+ DOM_INVALID_NODE_TYPE_ERR = 2
+};
diff --git a/WebCore/bindings/objc/DOMRanges.h b/WebCore/bindings/objc/DOMRanges.h
new file mode 100644
index 0000000..c7e9ffc
--- /dev/null
+++ b/WebCore/bindings/objc/DOMRanges.h
@@ -0,0 +1,28 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMRange.h>
+#import <WebCore/DOMRangeException.h>
diff --git a/WebCore/bindings/objc/DOMSVG.h b/WebCore/bindings/objc/DOMSVG.h
new file mode 100644
index 0000000..8a7388f
--- /dev/null
+++ b/WebCore/bindings/objc/DOMSVG.h
@@ -0,0 +1,169 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMSVGAElement.h>
+#import <WebCore/DOMSVGAngle.h>
+#import <WebCore/DOMSVGAnimateColorElement.h>
+#import <WebCore/DOMSVGAnimateElement.h>
+#import <WebCore/DOMSVGAnimateTransformElement.h>
+#import <WebCore/DOMSVGAnimatedAngle.h>
+#import <WebCore/DOMSVGAnimatedBoolean.h>
+#import <WebCore/DOMSVGAnimatedEnumeration.h>
+#import <WebCore/DOMSVGAnimatedInteger.h>
+#import <WebCore/DOMSVGAnimatedLength.h>
+#import <WebCore/DOMSVGAnimatedLengthList.h>
+#import <WebCore/DOMSVGAnimatedNumber.h>
+#import <WebCore/DOMSVGAnimatedNumberList.h>
+#import <WebCore/DOMSVGAnimatedPathData.h>
+#import <WebCore/DOMSVGAnimatedPoints.h>
+#import <WebCore/DOMSVGAnimatedPreserveAspectRatio.h>
+#import <WebCore/DOMSVGAnimatedRect.h>
+#import <WebCore/DOMSVGAnimatedString.h>
+#import <WebCore/DOMSVGAnimatedTransformList.h>
+#import <WebCore/DOMSVGAnimationElement.h>
+#import <WebCore/DOMSVGCircleElement.h>
+#import <WebCore/DOMSVGClipPathElement.h>
+#import <WebCore/DOMSVGColor.h>
+#import <WebCore/DOMSVGComponentTransferFunctionElement.h>
+#import <WebCore/DOMSVGCursorElement.h>
+#import <WebCore/DOMSVGDefinitionSrcElement.h>
+#import <WebCore/DOMSVGDefsElement.h>
+#import <WebCore/DOMSVGDescElement.h>
+#import <WebCore/DOMSVGDocument.h>
+#import <WebCore/DOMSVGElement.h>
+#import <WebCore/DOMSVGElementInstance.h>
+#import <WebCore/DOMSVGElementInstanceList.h>
+#import <WebCore/DOMSVGEllipseElement.h>
+#import <WebCore/DOMSVGException.h>
+#import <WebCore/DOMSVGExternalResourcesRequired.h>
+#import <WebCore/DOMSVGFEBlendElement.h>
+#import <WebCore/DOMSVGFEColorMatrixElement.h>
+#import <WebCore/DOMSVGFEComponentTransferElement.h>
+#import <WebCore/DOMSVGFECompositeElement.h>
+#import <WebCore/DOMSVGFEDiffuseLightingElement.h>
+#import <WebCore/DOMSVGFEDisplacementMapElement.h>
+#import <WebCore/DOMSVGFEDistantLightElement.h>
+#import <WebCore/DOMSVGFEFloodElement.h>
+#import <WebCore/DOMSVGFEFuncAElement.h>
+#import <WebCore/DOMSVGFEFuncBElement.h>
+#import <WebCore/DOMSVGFEFuncGElement.h>
+#import <WebCore/DOMSVGFEFuncRElement.h>
+#import <WebCore/DOMSVGFEGaussianBlurElement.h>
+#import <WebCore/DOMSVGFEImageElement.h>
+#import <WebCore/DOMSVGFEMergeElement.h>
+#import <WebCore/DOMSVGFEMergeNodeElement.h>
+#import <WebCore/DOMSVGFEOffsetElement.h>
+#import <WebCore/DOMSVGFEPointLightElement.h>
+#import <WebCore/DOMSVGFESpecularLightingElement.h>
+#import <WebCore/DOMSVGFESpotLightElement.h>
+#import <WebCore/DOMSVGFETileElement.h>
+#import <WebCore/DOMSVGFETurbulenceElement.h>
+#import <WebCore/DOMSVGFilterElement.h>
+#import <WebCore/DOMSVGFilterPrimitiveStandardAttributes.h>
+#import <WebCore/DOMSVGFitToViewBox.h>
+#import <WebCore/DOMSVGFontElement.h>
+#import <WebCore/DOMSVGFontFaceElement.h>
+#import <WebCore/DOMSVGFontFaceFormatElement.h>
+#import <WebCore/DOMSVGFontFaceNameElement.h>
+#import <WebCore/DOMSVGFontFaceSrcElement.h>
+#import <WebCore/DOMSVGFontFaceUriElement.h>
+#import <WebCore/DOMSVGForeignObjectElement.h>
+#import <WebCore/DOMSVGGElement.h>
+#import <WebCore/DOMSVGGlyphElement.h>
+#import <WebCore/DOMSVGGradientElement.h>
+#import <WebCore/DOMSVGImageElement.h>
+#import <WebCore/DOMSVGLangSpace.h>
+#import <WebCore/DOMSVGLength.h>
+#import <WebCore/DOMSVGLengthList.h>
+#import <WebCore/DOMSVGLineElement.h>
+#import <WebCore/DOMSVGLinearGradientElement.h>
+#import <WebCore/DOMSVGLocatable.h>
+#import <WebCore/DOMSVGMarkerElement.h>
+#import <WebCore/DOMSVGMaskElement.h>
+#import <WebCore/DOMSVGMatrix.h>
+#import <WebCore/DOMSVGMetadataElement.h>
+#import <WebCore/DOMSVGMissingGlyphElement.h>
+#import <WebCore/DOMSVGNumber.h>
+#import <WebCore/DOMSVGNumberList.h>
+#import <WebCore/DOMSVGPaint.h>
+#import <WebCore/DOMSVGPathElement.h>
+#import <WebCore/DOMSVGPathSeg.h>
+#import <WebCore/DOMSVGPathSegArcAbs.h>
+#import <WebCore/DOMSVGPathSegArcRel.h>
+#import <WebCore/DOMSVGPathSegClosePath.h>
+#import <WebCore/DOMSVGPathSegCurvetoCubicAbs.h>
+#import <WebCore/DOMSVGPathSegCurvetoCubicRel.h>
+#import <WebCore/DOMSVGPathSegCurvetoCubicSmoothAbs.h>
+#import <WebCore/DOMSVGPathSegCurvetoCubicSmoothRel.h>
+#import <WebCore/DOMSVGPathSegCurvetoQuadraticAbs.h>
+#import <WebCore/DOMSVGPathSegCurvetoQuadraticRel.h>
+#import <WebCore/DOMSVGPathSegCurvetoQuadraticSmoothAbs.h>
+#import <WebCore/DOMSVGPathSegCurvetoQuadraticSmoothRel.h>
+#import <WebCore/DOMSVGPathSegLinetoAbs.h>
+#import <WebCore/DOMSVGPathSegLinetoHorizontalAbs.h>
+#import <WebCore/DOMSVGPathSegLinetoHorizontalRel.h>
+#import <WebCore/DOMSVGPathSegLinetoRel.h>
+#import <WebCore/DOMSVGPathSegLinetoVerticalAbs.h>
+#import <WebCore/DOMSVGPathSegLinetoVerticalRel.h>
+#import <WebCore/DOMSVGPathSegList.h>
+#import <WebCore/DOMSVGPathSegMovetoAbs.h>
+#import <WebCore/DOMSVGPathSegMovetoRel.h>
+#import <WebCore/DOMSVGPatternElement.h>
+#import <WebCore/DOMSVGPoint.h>
+#import <WebCore/DOMSVGPointList.h>
+#import <WebCore/DOMSVGPolygonElement.h>
+#import <WebCore/DOMSVGPolylineElement.h>
+#import <WebCore/DOMSVGPreserveAspectRatio.h>
+#import <WebCore/DOMSVGRadialGradientElement.h>
+#import <WebCore/DOMSVGRect.h>
+#import <WebCore/DOMSVGRectElement.h>
+#import <WebCore/DOMSVGRenderingIntent.h>
+#import <WebCore/DOMSVGSVGElement.h>
+#import <WebCore/DOMSVGScriptElement.h>
+#import <WebCore/DOMSVGSetElement.h>
+#import <WebCore/DOMSVGStopElement.h>
+#import <WebCore/DOMSVGStringList.h>
+#import <WebCore/DOMSVGStylable.h>
+#import <WebCore/DOMSVGStyleElement.h>
+#import <WebCore/DOMSVGSwitchElement.h>
+#import <WebCore/DOMSVGSymbolElement.h>
+#import <WebCore/DOMSVGTRefElement.h>
+#import <WebCore/DOMSVGTSpanElement.h>
+#import <WebCore/DOMSVGTests.h>
+#import <WebCore/DOMSVGTextContentElement.h>
+#import <WebCore/DOMSVGTextElement.h>
+#import <WebCore/DOMSVGTextPathElement.h>
+#import <WebCore/DOMSVGTextPositioningElement.h>
+#import <WebCore/DOMSVGTitleElement.h>
+#import <WebCore/DOMSVGTransform.h>
+#import <WebCore/DOMSVGTransformList.h>
+#import <WebCore/DOMSVGTransformable.h>
+#import <WebCore/DOMSVGURIReference.h>
+#import <WebCore/DOMSVGUnitTypes.h>
+#import <WebCore/DOMSVGUseElement.h>
+#import <WebCore/DOMSVGViewElement.h>
+#import <WebCore/DOMSVGZoomAndPan.h>
+#import <WebCore/DOMSVGZoomEvent.h>
diff --git a/WebCore/bindings/objc/DOMSVGException.h b/WebCore/bindings/objc/DOMSVGException.h
new file mode 100644
index 0000000..1eb121a
--- /dev/null
+++ b/WebCore/bindings/objc/DOMSVGException.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+@class NSString;
+
+extern NSString * const DOMSVGException;
+
+enum DOMSVGException {
+ DOM_SVG_WRONG_TYPE_ERR = 0,
+ DOM_SVG_INVALID_VALUE_ERR = 1,
+ DOM_SVG_MATRIX_NOT_INVERTABLE = 2
+};
diff --git a/WebCore/bindings/objc/DOMSVGPathSegInternal.mm b/WebCore/bindings/objc/DOMSVGPathSegInternal.mm
new file mode 100644
index 0000000..cbbe6bd
--- /dev/null
+++ b/WebCore/bindings/objc/DOMSVGPathSegInternal.mm
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+
+#if ENABLE(SVG)
+
+#import "DOMSVGPathSegInternal.h"
+
+#import "DOMInternal.h"
+#import "DOMSVGPathSeg.h"
+#import "DOMSVGPathSegArcAbs.h"
+#import "DOMSVGPathSegArcRel.h"
+#import "DOMSVGPathSegClosePath.h"
+#import "DOMSVGPathSegCurvetoCubicAbs.h"
+#import "DOMSVGPathSegCurvetoCubicRel.h"
+#import "DOMSVGPathSegCurvetoCubicSmoothAbs.h"
+#import "DOMSVGPathSegCurvetoCubicSmoothRel.h"
+#import "DOMSVGPathSegCurvetoQuadraticAbs.h"
+#import "DOMSVGPathSegCurvetoQuadraticRel.h"
+#import "DOMSVGPathSegCurvetoQuadraticSmoothAbs.h"
+#import "DOMSVGPathSegCurvetoQuadraticSmoothRel.h"
+#import "DOMSVGPathSegLinetoAbs.h"
+#import "DOMSVGPathSegLinetoHorizontalAbs.h"
+#import "DOMSVGPathSegLinetoHorizontalRel.h"
+#import "DOMSVGPathSegLinetoRel.h"
+#import "DOMSVGPathSegLinetoVerticalAbs.h"
+#import "DOMSVGPathSegLinetoVerticalRel.h"
+#import "DOMSVGPathSegList.h"
+#import "DOMSVGPathSegMovetoAbs.h"
+#import "DOMSVGPathSegMovetoRel.h"
+#import "SVGPathSeg.h"
+#import <objc/objc-class.h>
+
+@implementation DOMSVGPathSeg (WebCoreInternal)
+
+- (WebCore::SVGPathSeg *)_SVGPathSeg
+{
+ return reinterpret_cast<WebCore::SVGPathSeg*>(_internal);
+}
+
+- (id)_initWithSVGPathSeg:(WebCore::SVGPathSeg *)impl
+{
+ ASSERT(impl);
+
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMSVGPathSeg *)_wrapSVGPathSeg:(WebCore::SVGPathSeg *)impl
+{
+ if (!impl)
+ return nil;
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ Class wrapperClass = nil;
+ switch (impl->pathSegType()) {
+ case WebCore::SVGPathSeg::PATHSEG_UNKNOWN:
+ wrapperClass = [DOMSVGPathSeg class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CLOSEPATH:
+ wrapperClass = [DOMSVGPathSegClosePath class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_MOVETO_ABS:
+ wrapperClass = [DOMSVGPathSegMovetoAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_MOVETO_REL:
+ wrapperClass = [DOMSVGPathSegMovetoRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_LINETO_ABS:
+ wrapperClass = [DOMSVGPathSegLinetoAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_LINETO_REL:
+ wrapperClass = [DOMSVGPathSegLinetoRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
+ wrapperClass = [DOMSVGPathSegCurvetoCubicAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_CUBIC_REL:
+ wrapperClass = [DOMSVGPathSegCurvetoCubicRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS:
+ wrapperClass = [DOMSVGPathSegCurvetoQuadraticAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL:
+ wrapperClass = [DOMSVGPathSegCurvetoQuadraticRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_ARC_ABS:
+ wrapperClass = [DOMSVGPathSegArcAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_ARC_REL:
+ wrapperClass = [DOMSVGPathSegArcRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS:
+ wrapperClass = [DOMSVGPathSegLinetoHorizontalAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL:
+ wrapperClass = [DOMSVGPathSegLinetoHorizontalRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS:
+ wrapperClass = [DOMSVGPathSegLinetoVerticalAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_LINETO_VERTICAL_REL:
+ wrapperClass = [DOMSVGPathSegLinetoVerticalRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
+ wrapperClass = [DOMSVGPathSegCurvetoCubicSmoothAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
+ wrapperClass = [DOMSVGPathSegCurvetoCubicSmoothRel class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
+ wrapperClass = [DOMSVGPathSegCurvetoQuadraticSmoothAbs class];
+ break;
+ case WebCore::SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
+ wrapperClass = [DOMSVGPathSegCurvetoQuadraticSmoothRel class];
+ break;
+ }
+
+ return [[[wrapperClass alloc] _initWithSVGPathSeg:impl] autorelease];
+}
+
+@end
+
+#endif // ENABLE(SVG)
diff --git a/WebCore/bindings/objc/DOMStylesheets.h b/WebCore/bindings/objc/DOMStylesheets.h
new file mode 100644
index 0000000..81b5def
--- /dev/null
+++ b/WebCore/bindings/objc/DOMStylesheets.h
@@ -0,0 +1,33 @@
+/*
+ * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCore.h>
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMObject.h>
+
+#import <WebCore/DOMStyleSheet.h>
+#import <WebCore/DOMStyleSheetList.h>
+#import <WebCore/DOMMediaList.h>
diff --git a/WebCore/bindings/objc/DOMTraversal.h b/WebCore/bindings/objc/DOMTraversal.h
new file mode 100644
index 0000000..e2d291e
--- /dev/null
+++ b/WebCore/bindings/objc/DOMTraversal.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright (C) 2004, 2005, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCore.h>
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMObject.h>
+
+#import <WebCore/DOMNodeFilter.h>
+#import <WebCore/DOMNodeIterator.h>
+#import <WebCore/DOMTreeWalker.h>
+
+@interface DOMDocument (DOMDocumentTraversal)
+- (DOMNodeIterator *)createNodeIterator:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences;
+- (DOMTreeWalker *)createTreeWalker:(DOMNode *)root whatToShow:(unsigned)whatToShow filter:(id <DOMNodeFilter>)filter expandEntityReferences:(BOOL)expandEntityReferences;
+@end
+
+@interface DOMDocument (DOMDocumentTraversalDeprecated)
+#ifndef BUILDING_ON_TIGER
+- (DOMNodeIterator *)createNodeIterator:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER;
+- (DOMTreeWalker *)createTreeWalker:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER;
+#else
+- (DOMNodeIterator *)createNodeIterator:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences;
+- (DOMTreeWalker *)createTreeWalker:(DOMNode *)root :(unsigned)whatToShow :(id <DOMNodeFilter>)filter :(BOOL)expandEntityReferences;
+#endif
+@end
diff --git a/WebCore/bindings/objc/DOMUtility.mm b/WebCore/bindings/objc/DOMUtility.mm
new file mode 100644
index 0000000..16204a3
--- /dev/null
+++ b/WebCore/bindings/objc/DOMUtility.mm
@@ -0,0 +1,126 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 James G. Speth (speth@end.com)
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+
+#import "DOMImplementationFront.h"
+#import "DOMInternal.h"
+#import "JSCSSRule.h"
+#import "JSCSSRuleList.h"
+#import "JSCSSStyleDeclaration.h"
+#import "JSCSSValue.h"
+#import "JSCounter.h"
+#import "JSDOMImplementation.h"
+#import "JSEvent.h"
+#import "JSHTMLCollection.h"
+#import "JSHTMLOptionsCollection.h"
+#import "JSMediaList.h"
+#import "JSNamedNodeMap.h"
+#import "JSNode.h"
+#import "JSNodeIterator.h"
+#import "JSNodeList.h"
+#import "JSRange.h"
+#import "JSRect.h"
+#import "JSStyleSheet.h"
+#import "JSStyleSheetList.h"
+#import "JSTreeWalker.h"
+#import "JSXPathExpression.h"
+#import "JSXPathResult.h"
+#import "Node.h"
+#import "WebScriptObjectPrivate.h"
+#import "kjs_css.h"
+#import "kjs_html.h"
+#import "kjs_window.h"
+#import <objc/objc-runtime.h>
+
+// This file makes use of both the ObjC DOM API and the C++ DOM API, so we need to be careful about what
+// headers are included and what namespaces we use to avoid naming conflicts.
+
+// FIXME: This has to be in the KJS namespace to avoid an Objective-C++ ambiguity with C++ and
+// Objective-C classes of the same name (even when not in the same namespace). That's also the
+// reason for the use of objc_getClass in the WRAP_OLD macro below.
+
+// Some day if the compiler is fixed, or if all the JS wrappers are named with a "JS" prefix,
+// we could move the function into the WebCore namespace where it belongs.
+
+namespace KJS {
+
+static inline id createDOMWrapper(KJS::JSObject* object)
+{
+ #define WRAP(className) \
+ if (object->inherits(&WebCore::JS##className::info)) \
+ return [DOM##className _wrap##className:static_cast<WebCore::JS##className*>(object)->impl()];
+
+ WRAP(CSSRule)
+ WRAP(CSSRuleList)
+ WRAP(CSSStyleDeclaration)
+ WRAP(CSSValue)
+ WRAP(Counter)
+ WRAP(Event)
+ WRAP(HTMLOptionsCollection)
+ WRAP(MediaList)
+ WRAP(NamedNodeMap)
+ WRAP(Node)
+ WRAP(NodeList)
+ WRAP(RGBColor)
+ WRAP(Range)
+ WRAP(Rect)
+ WRAP(StyleSheet)
+ WRAP(StyleSheetList)
+ WRAP(XPathExpression)
+ WRAP(XPathResult)
+
+ // This must be after the HTMLOptionsCollection check, because it's a subclass in the JavaScript
+ // binding, but not a subclass in the ObjC binding.
+ WRAP(HTMLCollection)
+
+ #undef WRAP
+
+ if (object->inherits(&Window::info))
+ return [DOMAbstractView _wrapAbstractView:static_cast<Window*>(object)->impl()];
+ if (object->inherits(&WebCore::JSDOMImplementation::info))
+ return [DOMImplementation _wrapDOMImplementation:implementationFront(static_cast<WebCore::JSDOMImplementation*>(object))];
+ if (object->inherits(&WebCore::JSNodeIterator::info))
+ return [DOMNodeIterator _wrapNodeIterator:static_cast<WebCore::JSNodeIterator*>(object)->impl() filter:nil];
+ if (object->inherits(&WebCore::JSTreeWalker::info))
+ return [DOMTreeWalker _wrapTreeWalker:static_cast<WebCore::JSTreeWalker*>(object)->impl() filter:nil];
+
+ return nil;
+}
+
+}
+
+namespace WebCore {
+
+id createDOMWrapper(KJS::JSObject* object, PassRefPtr<KJS::Bindings::RootObject> origin, PassRefPtr<KJS::Bindings::RootObject> current)
+{
+ id wrapper = KJS::createDOMWrapper(object);
+ if (![wrapper _hasImp]) // new wrapper, not from cache
+ [wrapper _setImp:object originRootObject:origin rootObject:current];
+ return wrapper;
+}
+
+}
diff --git a/WebCore/bindings/objc/DOMViews.h b/WebCore/bindings/objc/DOMViews.h
new file mode 100644
index 0000000..4b625c8
--- /dev/null
+++ b/WebCore/bindings/objc/DOMViews.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCore.h>
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMObject.h>
+
+#import <WebCore/DOMAbstractView.h>
diff --git a/WebCore/bindings/objc/DOMXPath.h b/WebCore/bindings/objc/DOMXPath.h
new file mode 100644
index 0000000..f5472c3
--- /dev/null
+++ b/WebCore/bindings/objc/DOMXPath.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <WebCore/DOMCore.h>
+#import <WebCore/DOMDocument.h>
+#import <WebCore/DOMObject.h>
+
+#import <WebCore/DOMXPathException.h>
+#import <WebCore/DOMXPathExpression.h>
+#import <WebCore/DOMXPathNSResolver.h>
+#import <WebCore/DOMXPathResult.h>
diff --git a/WebCore/bindings/objc/DOMXPath.mm b/WebCore/bindings/objc/DOMXPath.mm
new file mode 100644
index 0000000..0d008f1
--- /dev/null
+++ b/WebCore/bindings/objc/DOMXPath.mm
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+
+#if ENABLE(XPATH)
+
+#import "DOMXPath.h"
+
+#import "DOMInternal.h"
+#import "PlatformString.h"
+#import "XPathNSResolver.h"
+
+//------------------------------------------------------------------------------------------
+// DOMNativeXPathNSResolver
+
+@implementation DOMNativeXPathNSResolver
+
+#define IMPL reinterpret_cast<WebCore::XPathNSResolver*>(_internal)
+
+- (void)dealloc
+{
+ if (_internal)
+ IMPL->deref();
+ [super dealloc];
+}
+
+- (void)finalize
+{
+ if (_internal)
+ IMPL->deref();
+ [super finalize];
+}
+
+- (WebCore::XPathNSResolver *)_xpathNSResolver
+{
+ return IMPL;
+}
+
+- (id)_initWithXPathNSResolver:(WebCore::XPathNSResolver *)impl
+{
+ ASSERT(impl);
+
+ [super _init];
+ _internal = reinterpret_cast<DOMObjectInternal*>(impl);
+ impl->ref();
+ WebCore::addDOMWrapper(self, impl);
+ return self;
+}
+
++ (DOMNativeXPathNSResolver *)_wrapXPathNSResolver:(WebCore::XPathNSResolver *)impl
+{
+ if (!impl)
+ return nil;
+
+ id cachedInstance;
+ cachedInstance = WebCore::getDOMWrapper(impl);
+ if (cachedInstance)
+ return [[cachedInstance retain] autorelease];
+
+ return [[[DOMNativeXPathNSResolver alloc] _initWithXPathNSResolver:impl] autorelease];
+}
+
+- (NSString *)lookupNamespaceURI:(NSString *)prefix
+{
+ return IMPL->lookupNamespaceURI(prefix);
+}
+
+@end
+
+#endif // ENABLE(XPATH)
diff --git a/WebCore/bindings/objc/DOMXPathException.h b/WebCore/bindings/objc/DOMXPathException.h
new file mode 100644
index 0000000..6db8292
--- /dev/null
+++ b/WebCore/bindings/objc/DOMXPathException.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+@class NSString;
+
+extern NSString * const DOMXPathException;
+
+enum DOMXPathExceptionCode {
+ DOM_INVALID_EXPRESSION_ERR = 51,
+ DOM_TYPE_ERR = 52
+};
diff --git a/WebCore/bindings/objc/ExceptionHandlers.h b/WebCore/bindings/objc/ExceptionHandlers.h
new file mode 100644
index 0000000..5f85b9b
--- /dev/null
+++ b/WebCore/bindings/objc/ExceptionHandlers.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef ExceptionHandlers_h
+#define ExceptionHandlers_h
+
+#include <JavaScriptCore/Assertions.h>
+
+#if !defined(NDEBUG) && !defined(DISABLE_THREAD_CHECK)
+#define DOM_ASSERT_MAIN_THREAD() do \
+ if (!pthread_main_np()) { \
+ WTFReportAssertionFailure(__FILE__, __LINE__, WTF_PRETTY_FUNCTION, "DOM access on non-main thread -- you will probably crash soon!"); \
+ } \
+while (0)
+#else
+#define DOM_ASSERT_MAIN_THREAD() ((void)0)
+#endif
+
+namespace WebCore {
+
+ typedef int ExceptionCode;
+
+ class SelectionController;
+ class Range;
+
+ void raiseDOMException(ExceptionCode);
+
+ inline void raiseOnDOMError(ExceptionCode ec)
+ {
+ if (ec)
+ raiseDOMException(ec);
+ }
+
+} // namespace WebCore
+
+#endif // ExceptionHandlers_h
diff --git a/WebCore/bindings/objc/ExceptionHandlers.mm b/WebCore/bindings/objc/ExceptionHandlers.mm
new file mode 100644
index 0000000..e9e42a8
--- /dev/null
+++ b/WebCore/bindings/objc/ExceptionHandlers.mm
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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 "ExceptionHandlers.h"
+
+#include "ExceptionCode.h"
+
+NSString * DOMException = @"DOMException";
+NSString * DOMRangeException = @"DOMRangeException";
+NSString * DOMEventException = @"DOMEventException";
+NSString * DOMSVGException = @"DOMSVGException";
+NSString * DOMXPathException = @"DOMXPathException";
+
+namespace WebCore {
+
+void raiseDOMException(ExceptionCode ec)
+{
+ ASSERT(ec);
+
+ ExceptionCodeDescription description;
+ getExceptionCodeDescription(ec, description);
+
+ NSString *exceptionName;
+ if (strcmp(description.typeName, "DOM Range") == 0)
+ exceptionName = DOMRangeException;
+ else if (strcmp(description.typeName, "DOM Events") == 0)
+ exceptionName = DOMEventException;
+ else if (strcmp(description.typeName, "DOM SVG") == 0)
+ exceptionName = DOMSVGException;
+ else if (strcmp(description.typeName, "DOM XPath") == 0)
+ exceptionName = DOMXPathException;
+ else
+ exceptionName = DOMException;
+
+ NSString *reason;
+ if (description.name)
+ reason = [[NSString alloc] initWithFormat:@"*** %s: %@ %d", description.name, exceptionName, description.code];
+ else
+ reason = [[NSString alloc] initWithFormat:@"*** %@ %d", exceptionName, description.code];
+
+ NSDictionary *userInfo = [[NSDictionary alloc] initWithObjectsAndKeys:[NSNumber numberWithInt:description.code], exceptionName, nil];
+
+ NSException *exception = [NSException exceptionWithName:exceptionName reason:reason userInfo:userInfo];
+
+ [reason release];
+ [userInfo release];
+
+ [exception raise];
+}
+
+} // namespace WebCore
diff --git a/WebCore/bindings/objc/PublicDOMInterfaces.h b/WebCore/bindings/objc/PublicDOMInterfaces.h
new file mode 100644
index 0000000..00591f6
--- /dev/null
+++ b/WebCore/bindings/objc/PublicDOMInterfaces.h
@@ -0,0 +1,1092 @@
+// Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+// Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+//
+// 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+// CONTRIBUTORS 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.
+
+// This file is used by bindings/scripts/CodeGeneratorObjC.pm to determine public API.
+// All public DOM class interfaces, properties and methods need to be in this file.
+// Anything not in the file will be generated into the appropriate private header file.
+
+#ifndef OBJC_CODE_GENERATION
+#error Do not include this header, instead include the appropriate DOM header.
+#endif
+
+@interface DOMAttr : DOMNode
+@property(readonly, copy) NSString *name;
+@property(readonly) BOOL specified;
+@property(copy) NSString *value;
+@property(readonly, retain) DOMElement *ownerElement;
+@property(readonly, retain) DOMCSSStyleDeclaration *style;
+@end
+
+@interface DOMCDATASection : DOMText
+@end
+
+@interface DOMCharacterData : DOMNode
+@property(copy) NSString *data;
+@property(readonly) unsigned length;
+- (NSString *)substringData:(unsigned)offset :(unsigned)length;
+- (NSString *)substringData:(unsigned)offset length:(unsigned)length;
+- (void)appendData:(NSString *)data;
+- (void)insertData:(unsigned)offset :(NSString *)data;
+- (void)deleteData:(unsigned)offset :(unsigned)length;
+- (void)replaceData:(unsigned)offset :(unsigned)length :(NSString *)data;
+- (void)insertData:(unsigned)offset data:(NSString *)data;
+- (void)deleteData:(unsigned)offset length:(unsigned)length;
+- (void)replaceData:(unsigned)offset length:(unsigned)length data:(NSString *)data;
+@end
+
+@interface DOMComment : DOMCharacterData
+@end
+
+@interface DOMImplementation : DOMObject
+- (BOOL)hasFeature:(NSString *)feature :(NSString *)version;
+- (DOMDocumentType *)createDocumentType:(NSString *)qualifiedName :(NSString *)publicId :(NSString *)systemId;
+- (DOMDocument *)createDocument:(NSString *)namespaceURI :(NSString *)qualifiedName :(DOMDocumentType *)doctype;
+- (DOMCSSStyleSheet *)createCSSStyleSheet:(NSString *)title :(NSString *)media;
+- (BOOL)hasFeature:(NSString *)feature version:(NSString *)version;
+- (DOMDocumentType *)createDocumentType:(NSString *)qualifiedName publicId:(NSString *)publicId systemId:(NSString *)systemId;
+- (DOMDocument *)createDocument:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName doctype:(DOMDocumentType *)doctype;
+- (DOMCSSStyleSheet *)createCSSStyleSheet:(NSString *)title media:(NSString *)media;
+- (DOMHTMLDocument *)createHTMLDocument:(NSString *)title;
+@end
+
+@interface DOMAbstractView : DOMObject
+@property(readonly, retain) DOMDocument *document;
+@end
+
+@interface DOMDocument : DOMNode
+@property(readonly, retain) DOMDocumentType *doctype;
+@property(readonly, retain) DOMImplementation *implementation;
+@property(readonly, retain) DOMElement *documentElement;
+@property(readonly, retain) DOMAbstractView *defaultView;
+@property(readonly, retain) DOMStyleSheetList *styleSheets;
+@property(readonly, retain) DOMHTMLCollection *images;
+@property(readonly, retain) DOMHTMLCollection *applets;
+@property(readonly, retain) DOMHTMLCollection *links;
+@property(readonly, retain) DOMHTMLCollection *forms;
+@property(readonly, retain) DOMHTMLCollection *anchors;
+@property(copy) NSString *title;
+@property(readonly, copy) NSString *referrer;
+@property(readonly, copy) NSString *domain;
+@property(readonly, copy) NSString *URL;
+@property(retain) DOMHTMLElement *body;
+@property(copy) NSString *cookie;
+- (DOMElement *)createElement:(NSString *)tagName;
+- (DOMDocumentFragment *)createDocumentFragment;
+- (DOMText *)createTextNode:(NSString *)data;
+- (DOMComment *)createComment:(NSString *)data;
+- (DOMCDATASection *)createCDATASection:(NSString *)data;
+- (DOMProcessingInstruction *)createProcessingInstruction:(NSString *)target :(NSString *)data;
+- (DOMProcessingInstruction *)createProcessingInstruction:(NSString *)target data:(NSString *)data;
+- (DOMAttr *)createAttribute:(NSString *)name;
+- (DOMEntityReference *)createEntityReference:(NSString *)name;
+- (DOMNodeList *)getElementsByTagName:(NSString *)tagname;
+- (DOMNode *)importNode:(DOMNode *)importedNode :(BOOL)deep;
+- (DOMElement *)createElementNS:(NSString *)namespaceURI :(NSString *)qualifiedName;
+- (DOMAttr *)createAttributeNS:(NSString *)namespaceURI :(NSString *)qualifiedName;
+- (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName;
+- (DOMNode *)importNode:(DOMNode *)importedNode deep:(BOOL)deep;
+- (DOMNode *)adoptNode:(DOMNode *)source;
+- (DOMElement *)createElementNS:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName;
+- (DOMAttr *)createAttributeNS:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName;
+- (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI localName:(NSString *)localName;
+- (DOMElement *)getElementById:(NSString *)elementId;
+- (DOMEvent *)createEvent:(NSString *)eventType;
+- (DOMRange *)createRange;
+- (DOMCSSStyleDeclaration *)createCSSStyleDeclaration;
+- (DOMCSSStyleDeclaration *)getOverrideStyle:(DOMElement *)element :(NSString *)pseudoElement;
+- (DOMCSSStyleDeclaration *)getOverrideStyle:(DOMElement *)element pseudoElement:(NSString *)pseudoElement;
+- (DOMCSSStyleDeclaration *)getComputedStyle:(DOMElement *)element :(NSString *)pseudoElement;
+- (DOMCSSStyleDeclaration *)getComputedStyle:(DOMElement *)element pseudoElement:(NSString *)pseudoElement;
+- (DOMCSSRuleList *)getMatchedCSSRules:(DOMElement *)element pseudoElement:(NSString *)pseudoElement;
+- (DOMCSSRuleList *)getMatchedCSSRules:(DOMElement *)element pseudoElement:(NSString *)pseudoElement authorOnly:(BOOL)authorOnly;
+- (DOMNodeList *)getElementsByName:(NSString *)elementName;
+#ifdef ENABLE_XPATH
+- (DOMXPathExpression *)createExpression:(NSString *)expression :(id <DOMXPathNSResolver>)resolver;
+- (DOMXPathExpression *)createExpression:(NSString *)expression resolver:(id <DOMXPathNSResolver>)resolver;
+- (id <DOMXPathNSResolver>)createNSResolver:(DOMNode *)nodeResolver;
+- (DOMXPathResult *)evaluate:(NSString *)expression :(DOMNode *)contextNode :(id <DOMXPathNSResolver>)resolver :(unsigned short)type :(DOMXPathResult *)inResult;
+- (DOMXPathResult *)evaluate:(NSString *)expression contextNode:(DOMNode *)contextNode resolver:(id <DOMXPathNSResolver>)resolver type:(unsigned short)type inResult:(DOMXPathResult *)inResult;
+#endif
+@end
+
+@interface DOMDocumentFragment : DOMNode
+@end
+
+@interface DOMDocumentType : DOMNode
+@property(readonly, copy) NSString *name;
+@property(readonly, retain) DOMNamedNodeMap *entities;
+@property(readonly, retain) DOMNamedNodeMap *notations;
+@property(readonly, copy) NSString *publicId;
+@property(readonly, copy) NSString *systemId;
+@property(readonly, copy) NSString *internalSubset;
+@end
+
+@interface DOMElement : DOMNode
+@property(readonly, copy) NSString *tagName;
+@property(readonly, retain) DOMCSSStyleDeclaration *style;
+@property(readonly) int offsetLeft;
+@property(readonly) int offsetTop;
+@property(readonly) int offsetWidth;
+@property(readonly) int offsetHeight;
+@property(readonly, retain) DOMElement *offsetParent;
+@property(readonly) int clientWidth;
+@property(readonly) int clientHeight;
+@property int scrollLeft;
+@property int scrollTop;
+@property(readonly) int scrollWidth;
+@property(readonly) int scrollHeight;
+- (NSString *)getAttribute:(NSString *)name;
+- (void)setAttribute:(NSString *)name :(NSString *)value;
+- (void)setAttribute:(NSString *)name value:(NSString *)value;
+- (void)removeAttribute:(NSString *)name;
+- (DOMAttr *)getAttributeNode:(NSString *)name;
+- (DOMAttr *)setAttributeNode:(DOMAttr *)newAttr;
+- (DOMAttr *)removeAttributeNode:(DOMAttr *)oldAttr;
+- (DOMNodeList *)getElementsByTagName:(NSString *)name;
+- (NSString *)getAttributeNS:(NSString *)namespaceURI :(NSString *)localName;
+- (void)setAttributeNS:(NSString *)namespaceURI :(NSString *)qualifiedName :(NSString *)value;
+- (void)removeAttributeNS:(NSString *)namespaceURI :(NSString *)localName;
+- (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI :(NSString *)localName;
+- (DOMAttr *)getAttributeNodeNS:(NSString *)namespaceURI :(NSString *)localName;
+- (NSString *)getAttributeNS:(NSString *)namespaceURI localName:(NSString *)localName;
+- (void)setAttributeNS:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName value:(NSString *)value;
+- (void)removeAttributeNS:(NSString *)namespaceURI localName:(NSString *)localName;
+- (DOMNodeList *)getElementsByTagNameNS:(NSString *)namespaceURI localName:(NSString *)localName;
+- (DOMAttr *)getAttributeNodeNS:(NSString *)namespaceURI localName:(NSString *)localName;
+- (DOMAttr *)setAttributeNodeNS:(DOMAttr *)newAttr;
+- (BOOL)hasAttribute:(NSString *)name;
+- (BOOL)hasAttributeNS:(NSString *)namespaceURI :(NSString *)localName;
+- (BOOL)hasAttributeNS:(NSString *)namespaceURI localName:(NSString *)localName;
+- (void)focus;
+- (void)blur;
+- (void)scrollIntoView:(BOOL)alignWithTop;
+- (void)scrollIntoViewIfNeeded:(BOOL)centerIfNeeded;
+@end
+
+@interface DOMEntity : DOMNode
+@property(readonly, copy) NSString *publicId;
+@property(readonly, copy) NSString *systemId;
+@property(readonly, copy) NSString *notationName;
+@end
+
+@interface DOMEntityReference : DOMNode
+@end
+
+@interface DOMNamedNodeMap : DOMObject
+@property(readonly) unsigned length;
+- (DOMNode *)getNamedItem:(NSString *)name;
+- (DOMNode *)setNamedItem:(DOMNode *)node;
+- (DOMNode *)removeNamedItem:(NSString *)name;
+- (DOMNode *)item:(unsigned)index;
+- (DOMNode *)getNamedItemNS:(NSString *)namespaceURI :(NSString *)localName;
+- (DOMNode *)getNamedItemNS:(NSString *)namespaceURI localName:(NSString *)localName;
+- (DOMNode *)setNamedItemNS:(DOMNode *)node;
+- (DOMNode *)removeNamedItemNS:(NSString *)namespaceURI :(NSString *)localName;
+- (DOMNode *)removeNamedItemNS:(NSString *)namespaceURI localName:(NSString *)localName;
+@end
+
+@interface DOMNode : DOMObject
+@property(readonly, copy) NSString *nodeName;
+@property(copy) NSString *nodeValue;
+@property(readonly) unsigned short nodeType;
+@property(readonly, retain) DOMNode *parentNode;
+@property(readonly, retain) DOMNodeList *childNodes;
+@property(readonly, retain) DOMNode *firstChild;
+@property(readonly, retain) DOMNode *lastChild;
+@property(readonly, retain) DOMNode *previousSibling;
+@property(readonly, retain) DOMNode *nextSibling;
+@property(readonly, retain) DOMNamedNodeMap *attributes;
+@property(readonly, retain) DOMDocument *ownerDocument;
+@property(readonly, copy) NSString *namespaceURI;
+@property(copy) NSString *prefix;
+@property(readonly, copy) NSString *localName;
+@property(copy) NSString *textContent;
+- (DOMNode *)insertBefore:(DOMNode *)newChild :(DOMNode *)refChild;
+- (DOMNode *)insertBefore:(DOMNode *)newChild refChild:(DOMNode *)refChild;
+- (DOMNode *)replaceChild:(DOMNode *)newChild :(DOMNode *)oldChild;
+- (DOMNode *)replaceChild:(DOMNode *)newChild oldChild:(DOMNode *)oldChild;
+- (DOMNode *)removeChild:(DOMNode *)oldChild;
+- (DOMNode *)appendChild:(DOMNode *)newChild;
+- (BOOL)hasChildNodes;
+- (DOMNode *)cloneNode:(BOOL)deep;
+- (void)normalize;
+- (BOOL)isSupported:(NSString *)feature :(NSString *)version;
+- (BOOL)isSupported:(NSString *)feature version:(NSString *)version;
+- (BOOL)hasAttributes;
+- (BOOL)isSameNode:(DOMNode *)other;
+- (BOOL)isEqualNode:(DOMNode *)other;
+@end
+
+@interface DOMNodeList : DOMObject
+@property(readonly) unsigned length;
+- (DOMNode *)item:(unsigned)index;
+@end
+
+@interface DOMNotation : DOMNode
+@property(readonly, copy) NSString *publicId;
+@property(readonly, copy) NSString *systemId;
+@end
+
+@interface DOMProcessingInstruction : DOMNode
+@property(readonly, copy) NSString *target;
+@property(copy) NSString *data;
+@end
+
+@interface DOMText : DOMCharacterData
+- (DOMText *)splitText:(unsigned)offset;
+@end
+
+@interface DOMHTMLAnchorElement : DOMHTMLElement
+@property(copy) NSString *accessKey;
+@property(copy) NSString *charset;
+@property(copy) NSString *coords;
+@property(copy) NSString *href;
+@property(copy) NSString *hreflang;
+@property(copy) NSString *name;
+@property(copy) NSString *rel;
+@property(copy) NSString *rev;
+@property(copy) NSString *shape;
+@property int tabIndex;
+@property(copy) NSString *target;
+@property(copy) NSString *type;
+@property(readonly, copy) NSURL *absoluteLinkURL;
+- (void)blur;
+- (void)focus;
+@end
+
+@interface DOMHTMLAppletElement : DOMHTMLElement
+@property(copy) NSString *align;
+@property(copy) NSString *alt;
+@property(copy) NSString *archive;
+@property(copy) NSString *code;
+@property(copy) NSString *codeBase;
+@property(copy) NSString *height;
+@property int hspace;
+@property(copy) NSString *name;
+@property(copy) NSString *object;
+@property int vspace;
+@property(copy) NSString *width;
+@end
+
+@interface DOMHTMLAreaElement : DOMHTMLElement
+@property(copy) NSString *accessKey;
+@property(copy) NSString *alt;
+@property(copy) NSString *coords;
+@property(copy) NSString *href;
+@property BOOL noHref;
+@property(copy) NSString *shape;
+@property int tabIndex;
+@property(copy) NSString *target;
+@property(readonly, copy) NSURL *absoluteLinkURL;
+@end
+
+@interface DOMHTMLBRElement : DOMHTMLElement
+@property(copy) NSString *clear;
+@end
+
+@interface DOMHTMLBaseElement : DOMHTMLElement
+@property(copy) NSString *href;
+@property(copy) NSString *target;
+@end
+
+@interface DOMHTMLBaseFontElement : DOMHTMLElement
+@property(copy) NSString *color;
+@property(copy) NSString *face;
+@property(copy) NSString *size;
+@end
+
+@interface DOMHTMLBodyElement : DOMHTMLElement
+@property(copy) NSString *aLink;
+@property(copy) NSString *background;
+@property(copy) NSString *bgColor;
+@property(copy) NSString *link;
+@property(copy) NSString *text;
+@property(copy) NSString *vLink;
+@end
+
+@interface DOMHTMLButtonElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(copy) NSString *accessKey;
+@property BOOL disabled;
+@property(copy) NSString *name;
+@property int tabIndex;
+@property(readonly, copy) NSString *type;
+@property(copy) NSString *value;
+@end
+
+@interface DOMHTMLCanvasElement : DOMHTMLElement
+@property int height;
+@property int width;
+@end
+
+@interface DOMHTMLCollection : DOMObject
+@property(readonly) unsigned length;
+- (DOMNode *)item:(unsigned)index;
+- (DOMNode *)namedItem:(NSString *)name;
+@end
+
+@interface DOMHTMLDListElement : DOMHTMLElement
+@property BOOL compact;
+@end
+
+@interface DOMHTMLDirectoryElement : DOMHTMLElement
+@property BOOL compact;
+@end
+
+@interface DOMHTMLDivElement : DOMHTMLElement
+@property(copy) NSString *align;
+@end
+
+@interface DOMHTMLDocument : DOMDocument
+- (void)open;
+- (void)close;
+- (void)write:(NSString *)text;
+- (void)writeln:(NSString *)text;
+@end
+
+@interface DOMHTMLElement : DOMElement
+@property(copy) NSString *title;
+@property(copy) NSString *idName;
+@property(copy) NSString *lang;
+@property(copy) NSString *dir;
+@property(copy) NSString *className;
+@property(copy) NSString *innerHTML;
+@property(copy) NSString *innerText;
+@property(copy) NSString *outerHTML;
+@property(copy) NSString *outerText;
+@property(readonly, retain) DOMHTMLCollection *children;
+@property(copy) NSString *contentEditable;
+@property(readonly) BOOL isContentEditable;
+@property(readonly, copy) NSString *titleDisplayString;
+@end
+
+@interface DOMHTMLEmbedElement : DOMHTMLElement
+@property(copy) NSString *align;
+@property int height;
+@property(copy) NSString *name;
+@property(copy) NSString *src;
+@property(copy) NSString *type;
+@property int width;
+@end
+
+@interface DOMHTMLFieldSetElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLFormElement *form;
+@end
+
+@interface DOMHTMLFontElement : DOMHTMLElement
+@property(copy) NSString *color;
+@property(copy) NSString *face;
+@property(copy) NSString *size;
+@end
+
+@interface DOMHTMLFormElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLCollection *elements;
+@property(readonly) int length;
+@property(copy) NSString *name;
+@property(copy) NSString *acceptCharset;
+@property(copy) NSString *action;
+@property(copy) NSString *enctype;
+@property(copy) NSString *method;
+@property(copy) NSString *target;
+- (void)submit;
+- (void)reset;
+@end
+
+@interface DOMHTMLFrameElement : DOMHTMLElement
+@property(copy) NSString *frameBorder;
+@property(copy) NSString *longDesc;
+@property(copy) NSString *marginHeight;
+@property(copy) NSString *marginWidth;
+@property(copy) NSString *name;
+@property BOOL noResize;
+@property(copy) NSString *scrolling;
+@property(copy) NSString *src;
+@property(readonly, retain) DOMDocument *contentDocument;
+@end
+
+@interface DOMHTMLFrameSetElement : DOMHTMLElement
+@property(copy) NSString *cols;
+@property(copy) NSString *rows;
+@end
+
+@interface DOMHTMLHRElement : DOMHTMLElement
+@property(copy) NSString *align;
+@property BOOL noShade;
+@property(copy) NSString *size;
+@property(copy) NSString *width;
+@end
+
+@interface DOMHTMLHeadElement : DOMHTMLElement
+@property(copy) NSString *profile;
+@end
+
+@interface DOMHTMLHeadingElement : DOMHTMLElement
+@property(copy) NSString *align;
+@end
+
+@interface DOMHTMLHtmlElement : DOMHTMLElement
+@property(copy) NSString *version;
+@end
+
+@interface DOMHTMLIFrameElement : DOMHTMLElement
+@property(copy) NSString *align;
+@property(copy) NSString *frameBorder;
+@property(copy) NSString *height;
+@property(copy) NSString *longDesc;
+@property(copy) NSString *marginHeight;
+@property(copy) NSString *marginWidth;
+@property(copy) NSString *name;
+@property(copy) NSString *scrolling;
+@property(copy) NSString *src;
+@property(copy) NSString *width;
+@property(readonly, retain) DOMDocument *contentDocument;
+@end
+
+@interface DOMHTMLImageElement : DOMHTMLElement
+@property(copy) NSString *name;
+@property(copy) NSString *align;
+@property(copy) NSString *alt;
+@property(copy) NSString *border;
+@property int height;
+@property int hspace;
+@property BOOL isMap;
+@property(copy) NSString *longDesc;
+@property(copy) NSString *src;
+@property(copy) NSString *useMap;
+@property int vspace;
+@property int width;
+@property(readonly, copy) NSString *altDisplayString;
+@property(readonly, copy) NSURL *absoluteImageURL;
+@end
+
+@interface DOMHTMLInputElement : DOMHTMLElement
+@property(copy) NSString *defaultValue;
+@property BOOL defaultChecked;
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(copy) NSString *accept;
+@property(copy) NSString *accessKey;
+@property(copy) NSString *align;
+@property(copy) NSString *alt;
+@property BOOL checked;
+@property BOOL disabled;
+@property int maxLength;
+@property(copy) NSString *name;
+@property BOOL readOnly;
+@property(copy) NSString *size;
+@property(copy) NSString *src;
+@property int tabIndex;
+@property(copy) NSString *type;
+@property(copy) NSString *useMap;
+@property(copy) NSString *value;
+@property(readonly, copy) NSString *altDisplayString;
+@property(readonly, copy) NSURL *absoluteImageURL;
+- (void)blur;
+- (void)focus;
+- (void)select;
+- (void)click;
+@end
+
+@interface DOMHTMLIsIndexElement : DOMHTMLInputElement
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(copy) NSString *prompt;
+@end
+
+@interface DOMHTMLLIElement : DOMHTMLElement
+@property(copy) NSString *type;
+@property int value;
+@end
+
+@interface DOMHTMLLabelElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(copy) NSString *accessKey;
+@property(copy) NSString *htmlFor;
+@end
+
+@interface DOMHTMLLegendElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(copy) NSString *accessKey;
+@property(copy) NSString *align;
+@end
+
+@interface DOMHTMLLinkElement : DOMHTMLElement
+@property BOOL disabled;
+@property(copy) NSString *charset;
+@property(copy) NSString *href;
+@property(copy) NSString *hreflang;
+@property(copy) NSString *media;
+@property(copy) NSString *rel;
+@property(copy) NSString *rev;
+@property(copy) NSString *target;
+@property(copy) NSString *type;
+@property(readonly, copy) NSURL *absoluteLinkURL;
+@end
+
+@interface DOMHTMLMapElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLCollection *areas;
+@property(copy) NSString *name;
+@end
+
+@interface DOMHTMLMarqueeElement : DOMHTMLElement
+- (void)start;
+- (void)stop;
+@end
+
+@interface DOMHTMLMenuElement : DOMHTMLElement
+@property BOOL compact;
+@end
+
+@interface DOMHTMLMetaElement : DOMHTMLElement
+@property(copy) NSString *content;
+@property(copy) NSString *httpEquiv;
+@property(copy) NSString *name;
+@property(copy) NSString *scheme;
+@end
+
+@interface DOMHTMLModElement : DOMHTMLElement
+@property(copy) NSString *cite;
+@property(copy) NSString *dateTime;
+@end
+
+@interface DOMHTMLOListElement : DOMHTMLElement
+@property BOOL compact;
+@property int start;
+@property(copy) NSString *type;
+@end
+
+@interface DOMHTMLObjectElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(copy) NSString *code;
+@property(copy) NSString *align;
+@property(copy) NSString *archive;
+@property(copy) NSString *border;
+@property(copy) NSString *codeBase;
+@property(copy) NSString *codeType;
+@property(copy) NSString *data;
+@property BOOL declare;
+@property(copy) NSString *height;
+@property int hspace;
+@property(copy) NSString *name;
+@property(copy) NSString *standby;
+@property int tabIndex;
+@property(copy) NSString *type;
+@property(copy) NSString *useMap;
+@property int vspace;
+@property(copy) NSString *width;
+@property(readonly, retain) DOMDocument *contentDocument;
+@property(readonly, copy) NSURL *absoluteImageURL;
+@end
+
+@interface DOMHTMLOptGroupElement : DOMHTMLElement
+@property BOOL disabled;
+@property(copy) NSString *label;
+@end
+
+@interface DOMHTMLOptionElement : DOMHTMLElement
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property BOOL defaultSelected;
+@property(readonly, copy) NSString *text;
+@property(readonly) int index;
+@property BOOL disabled;
+@property(copy) NSString *label;
+@property BOOL selected;
+@property(copy) NSString *value;
+@end
+
+@interface DOMHTMLOptionsCollection : DOMObject
+@property unsigned length;
+- (DOMNode *)item:(unsigned)index;
+- (DOMNode *)namedItem:(NSString *)name;
+@end
+
+@interface DOMHTMLParagraphElement : DOMHTMLElement
+@property(copy) NSString *align;
+@end
+
+@interface DOMHTMLParamElement : DOMHTMLElement
+@property(copy) NSString *name;
+@property(copy) NSString *type;
+@property(copy) NSString *value;
+@property(copy) NSString *valueType;
+@end
+
+@interface DOMHTMLPreElement : DOMHTMLElement
+@property int width;
+@end
+
+@interface DOMHTMLQuoteElement : DOMHTMLElement
+@property(copy) NSString *cite;
+@end
+
+@interface DOMHTMLScriptElement : DOMHTMLElement
+@property(copy) NSString *text;
+@property(copy) NSString *htmlFor;
+@property(copy) NSString *event;
+@property(copy) NSString *charset;
+@property BOOL defer;
+@property(copy) NSString *src;
+@property(copy) NSString *type;
+@end
+
+@interface DOMHTMLSelectElement : DOMHTMLElement
+@property(readonly, copy) NSString *type;
+@property int selectedIndex;
+@property(copy) NSString *value;
+@property(readonly) int length;
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(readonly, retain) DOMHTMLOptionsCollection *options;
+@property BOOL disabled;
+@property BOOL multiple;
+@property(copy) NSString *name;
+@property int size;
+@property int tabIndex;
+- (void)add:(DOMHTMLElement *)element :(DOMHTMLElement *)before;
+- (void)add:(DOMHTMLElement *)element before:(DOMHTMLElement *)before;
+- (void)remove:(int)index;
+- (void)blur;
+- (void)focus;
+@end
+
+@interface DOMHTMLStyleElement : DOMHTMLElement
+@property BOOL disabled;
+@property(copy) NSString *media;
+@property(copy) NSString *type;
+@end
+
+@interface DOMHTMLTableCaptionElement : DOMHTMLElement
+@property(copy) NSString *align;
+@end
+
+@interface DOMHTMLTableCellElement : DOMHTMLElement
+@property(readonly) int cellIndex;
+@property(copy) NSString *abbr;
+@property(copy) NSString *align;
+@property(copy) NSString *axis;
+@property(copy) NSString *bgColor;
+@property(copy) NSString *ch;
+@property(copy) NSString *chOff;
+@property int colSpan;
+@property(copy) NSString *headers;
+@property(copy) NSString *height;
+@property BOOL noWrap;
+@property int rowSpan;
+@property(copy) NSString *scope;
+@property(copy) NSString *vAlign;
+@property(copy) NSString *width;
+@end
+
+@interface DOMHTMLTableColElement : DOMHTMLElement
+@property(copy) NSString *align;
+@property(copy) NSString *ch;
+@property(copy) NSString *chOff;
+@property int span;
+@property(copy) NSString *vAlign;
+@property(copy) NSString *width;
+@end
+
+@interface DOMHTMLTableElement : DOMHTMLElement
+@property(retain) DOMHTMLTableCaptionElement *caption;
+@property(retain) DOMHTMLTableSectionElement *tHead;
+@property(retain) DOMHTMLTableSectionElement *tFoot;
+@property(readonly, retain) DOMHTMLCollection *rows;
+@property(readonly, retain) DOMHTMLCollection *tBodies;
+@property(copy) NSString *align;
+@property(copy) NSString *bgColor;
+@property(copy) NSString *border;
+@property(copy) NSString *cellPadding;
+@property(copy) NSString *cellSpacing;
+@property(copy) NSString *frameBorders;
+@property(copy) NSString *rules;
+@property(copy) NSString *summary;
+@property(copy) NSString *width;
+- (DOMHTMLElement *)createTHead;
+- (void)deleteTHead;
+- (DOMHTMLElement *)createTFoot;
+- (void)deleteTFoot;
+- (DOMHTMLElement *)createCaption;
+- (void)deleteCaption;
+- (DOMHTMLElement *)insertRow:(int)index;
+- (void)deleteRow:(int)index;
+@end
+
+@interface DOMHTMLTableRowElement : DOMHTMLElement
+@property(readonly) int rowIndex;
+@property(readonly) int sectionRowIndex;
+@property(readonly, retain) DOMHTMLCollection *cells;
+@property(copy) NSString *align;
+@property(copy) NSString *bgColor;
+@property(copy) NSString *ch;
+@property(copy) NSString *chOff;
+@property(copy) NSString *vAlign;
+- (DOMHTMLElement *)insertCell:(int)index;
+- (void)deleteCell:(int)index;
+@end
+
+@interface DOMHTMLTableSectionElement : DOMHTMLElement
+@property(copy) NSString *align;
+@property(copy) NSString *ch;
+@property(copy) NSString *chOff;
+@property(copy) NSString *vAlign;
+@property(readonly, retain) DOMHTMLCollection *rows;
+- (DOMHTMLElement *)insertRow:(int)index;
+- (void)deleteRow:(int)index;
+@end
+
+@interface DOMHTMLTextAreaElement : DOMHTMLElement
+@property(copy) NSString *defaultValue;
+@property(readonly, retain) DOMHTMLFormElement *form;
+@property(copy) NSString *accessKey;
+@property int cols;
+@property BOOL disabled;
+@property(copy) NSString *name;
+@property BOOL readOnly;
+@property int rows;
+@property int tabIndex;
+@property(readonly, copy) NSString *type;
+@property(copy) NSString *value;
+- (void)blur;
+- (void)focus;
+- (void)select;
+@end
+
+@interface DOMHTMLTitleElement : DOMHTMLElement
+@property(copy) NSString *text;
+@end
+
+@interface DOMHTMLUListElement : DOMHTMLElement
+@property BOOL compact;
+@property(copy) NSString *type;
+@end
+
+@interface DOMStyleSheetList : DOMObject
+@property(readonly) unsigned length;
+- (DOMStyleSheet *)item:(unsigned)index;
+@end
+
+@interface DOMCSSCharsetRule : DOMCSSRule
+@property(readonly, copy) NSString *encoding;
+@end
+
+@interface DOMCSSFontFaceRule : DOMCSSRule
+@property(readonly, retain) DOMCSSStyleDeclaration *style;
+@end
+
+@interface DOMCSSImportRule : DOMCSSRule
+@property(readonly, copy) NSString *href;
+@property(readonly, retain) DOMMediaList *media;
+@property(readonly, retain) DOMCSSStyleSheet *styleSheet;
+@end
+
+@interface DOMCSSMediaRule : DOMCSSRule
+@property(readonly, retain) DOMMediaList *media;
+@property(readonly, retain) DOMCSSRuleList *cssRules;
+- (unsigned)insertRule:(NSString *)rule :(unsigned)index;
+- (unsigned)insertRule:(NSString *)rule index:(unsigned)index;
+- (void)deleteRule:(unsigned)index;
+@end
+
+@interface DOMCSSPageRule : DOMCSSRule
+@property(copy) NSString *selectorText;
+@property(readonly, retain) DOMCSSStyleDeclaration *style;
+@end
+
+@interface DOMCSSPrimitiveValue : DOMCSSValue
+@property(readonly) unsigned short primitiveType;
+- (void)setFloatValue:(unsigned short)unitType :(float)floatValue;
+- (void)setFloatValue:(unsigned short)unitType floatValue:(float)floatValue;
+- (float)getFloatValue:(unsigned short)unitType;
+- (void)setStringValue:(unsigned short)stringType :(NSString *)stringValue;
+- (void)setStringValue:(unsigned short)stringType stringValue:(NSString *)stringValue;
+- (NSString *)getStringValue;
+- (DOMCounter *)getCounterValue;
+- (DOMRect *)getRectValue;
+- (DOMRGBColor *)getRGBColorValue;
+@end
+
+@interface DOMRGBColor : DOMObject
+@property(readonly, retain) DOMCSSPrimitiveValue *red;
+@property(readonly, retain) DOMCSSPrimitiveValue *green;
+@property(readonly, retain) DOMCSSPrimitiveValue *blue;
+@property(readonly, retain) DOMCSSPrimitiveValue *alpha;
+@property(readonly, copy) NSColor *color;
+@end
+
+@interface DOMCSSRule : DOMObject
+@property(readonly) unsigned short type;
+@property(copy) NSString *cssText;
+@property(readonly, retain) DOMCSSStyleSheet *parentStyleSheet;
+@property(readonly, retain) DOMCSSRule *parentRule;
+@end
+
+@interface DOMCSSRuleList : DOMObject
+@property(readonly) unsigned length;
+- (DOMCSSRule *)item:(unsigned)index;
+@end
+
+@interface DOMCSSStyleDeclaration : DOMObject
+@property(copy) NSString *cssText;
+@property(readonly) unsigned length;
+@property(readonly, retain) DOMCSSRule *parentRule;
+- (NSString *)getPropertyValue:(NSString *)propertyName;
+- (DOMCSSValue *)getPropertyCSSValue:(NSString *)propertyName;
+- (NSString *)removeProperty:(NSString *)propertyName;
+- (NSString *)getPropertyPriority:(NSString *)propertyName;
+- (void)setProperty:(NSString *)propertyName :(NSString *)value :(NSString *)priority;
+- (void)setProperty:(NSString *)propertyName value:(NSString *)value priority:(NSString *)priority;
+- (NSString *)item:(unsigned)index;
+- (NSString *)getPropertyShorthand:(NSString *)propertyName;
+- (BOOL)isPropertyImplicit:(NSString *)propertyName;
+@end
+
+@interface DOMCSSStyleRule : DOMCSSRule
+@property(copy) NSString *selectorText;
+@property(readonly, retain) DOMCSSStyleDeclaration *style;
+@end
+
+@interface DOMStyleSheet : DOMObject
+@property(readonly, copy) NSString *type;
+@property BOOL disabled;
+@property(readonly, retain) DOMNode *ownerNode;
+@property(readonly, retain) DOMStyleSheet *parentStyleSheet;
+@property(readonly, copy) NSString *href;
+@property(readonly, copy) NSString *title;
+@property(readonly, retain) DOMMediaList *media;
+@end
+
+@interface DOMCSSStyleSheet : DOMStyleSheet
+@property(readonly, retain) DOMCSSRule *ownerRule;
+@property(readonly, retain) DOMCSSRuleList *cssRules;
+- (unsigned)insertRule:(NSString *)rule :(unsigned)index;
+- (unsigned)insertRule:(NSString *)rule index:(unsigned)index;
+- (void)deleteRule:(unsigned)index;
+@end
+
+@interface DOMCSSValue : DOMObject
+@property(copy) NSString *cssText;
+@property(readonly) unsigned short cssValueType;
+@end
+
+@interface DOMCSSValueList : DOMCSSValue
+@property(readonly) unsigned length;
+- (DOMCSSValue *)item:(unsigned)index;
+@end
+
+@interface DOMCSSUnknownRule : DOMCSSRule
+@end
+
+@interface DOMCounter : DOMObject
+@property(readonly, copy) NSString *identifier;
+@property(readonly, copy) NSString *listStyle;
+@property(readonly, copy) NSString *separator;
+@end
+
+@interface DOMRect : DOMObject
+@property(readonly, retain) DOMCSSPrimitiveValue *top;
+@property(readonly, retain) DOMCSSPrimitiveValue *right;
+@property(readonly, retain) DOMCSSPrimitiveValue *bottom;
+@property(readonly, retain) DOMCSSPrimitiveValue *left;
+@end
+
+@interface DOMEvent : DOMObject
+@property(readonly, copy) NSString *type;
+@property(readonly, retain) id <DOMEventTarget> target;
+@property(readonly, retain) id <DOMEventTarget> currentTarget;
+@property(readonly) unsigned short eventPhase;
+@property(readonly) BOOL bubbles;
+@property(readonly) BOOL cancelable;
+@property(readonly) DOMTimeStamp timeStamp;
+- (void)stopPropagation;
+- (void)preventDefault;
+- (void)initEvent:(NSString *)eventTypeArg canBubbleArg:(BOOL)canBubbleArg cancelableArg:(BOOL)cancelableArg;
+- (void)initEvent:(NSString *)eventTypeArg :(BOOL)canBubbleArg :(BOOL)cancelableArg;
+@end
+
+@interface DOMUIEvent : DOMEvent
+@property(readonly, retain) DOMAbstractView *view;
+@property(readonly) int detail;
+- (void)initUIEvent:(NSString *)type canBubble:(BOOL)canBubble cancelable:(BOOL)cancelable view:(DOMAbstractView *)view detail:(int)detail;
+- (void)initUIEvent:(NSString *)type :(BOOL)canBubble :(BOOL)cancelable :(DOMAbstractView *)view :(int)detail;
+@end
+
+@interface DOMMutationEvent : DOMEvent
+@property(readonly, retain) DOMNode *relatedNode;
+@property(readonly, copy) NSString *prevValue;
+@property(readonly, copy) NSString *newValue;
+@property(readonly, copy) NSString *attrName;
+@property(readonly) unsigned short attrChange;
+- (void)initMutationEvent:(NSString *)type canBubble:(BOOL)canBubble cancelable:(BOOL)cancelable relatedNode:(DOMNode *)relatedNode prevValue:(NSString *)prevValue newValue:(NSString *)newValue attrName:(NSString *)attrName attrChange:(unsigned short)attrChange;
+- (void)initMutationEvent:(NSString *)type :(BOOL)canBubble :(BOOL)cancelable :(DOMNode *)relatedNode :(NSString *)prevValue :(NSString *)newValue :(NSString *)attrName :(unsigned short)attrChange;
+@end
+
+@interface DOMOverflowEvent : DOMEvent
+@property(readonly) unsigned short orient;
+@property(readonly) BOOL horizontalOverflow;
+@property(readonly) BOOL verticalOverflow;
+- (void)initOverflowEvent:(unsigned short)orient horizontalOverflow:(BOOL)horizontalOverflow verticalOverflow:(BOOL)verticalOverflow;
+@end
+
+@interface DOMWheelEvent : DOMUIEvent
+@property(readonly) int screenX;
+@property(readonly) int screenY;
+@property(readonly) int clientX;
+@property(readonly) int clientY;
+@property(readonly) BOOL ctrlKey;
+@property(readonly) BOOL shiftKey;
+@property(readonly) BOOL altKey;
+@property(readonly) BOOL metaKey;
+@property(readonly) BOOL isHorizontal;
+@property(readonly) int wheelDelta;
+@end
+
+@interface DOMKeyboardEvent : DOMUIEvent
+@property(readonly, copy) NSString *keyIdentifier;
+@property(readonly) unsigned keyLocation;
+@property(readonly) BOOL ctrlKey;
+@property(readonly) BOOL shiftKey;
+@property(readonly) BOOL altKey;
+@property(readonly) BOOL metaKey;
+@property(readonly) int keyCode;
+@property(readonly) int charCode;
+- (BOOL)getModifierState:(NSString *)keyIdentifierArg;
+@end
+
+@interface DOMMouseEvent : DOMUIEvent
+@property(readonly) int screenX;
+@property(readonly) int screenY;
+@property(readonly) int clientX;
+@property(readonly) int clientY;
+@property(readonly) BOOL ctrlKey;
+@property(readonly) BOOL shiftKey;
+@property(readonly) BOOL altKey;
+@property(readonly) BOOL metaKey;
+@property(readonly) unsigned short button;
+@property(readonly, retain) id <DOMEventTarget> relatedTarget;
+- (void)initMouseEvent:(NSString *)type canBubble:(BOOL)canBubble cancelable:(BOOL)cancelable view:(DOMAbstractView *)view detail:(int)detail screenX:(int)screenX screenY:(int)screenY clientX:(int)clientX clientY:(int)clientY ctrlKey:(BOOL)ctrlKey altKey:(BOOL)altKey shiftKey:(BOOL)shiftKey metaKey:(BOOL)metaKey button:(unsigned short)button relatedTarget:(id <DOMEventTarget>)relatedTarget;
+- (void)initMouseEvent:(NSString *)type :(BOOL)canBubble :(BOOL)cancelable :(DOMAbstractView *)view :(int)detail :(int)screenX :(int)screenY :(int)clientX :(int)clientY :(BOOL)ctrlKey :(BOOL)altKey :(BOOL)shiftKey :(BOOL)metaKey :(unsigned short)button :(id <DOMEventTarget>)relatedTarget;
+@end
+
+@interface DOMRange : DOMObject
+@property(readonly, retain) DOMNode *startContainer;
+@property(readonly) int startOffset;
+@property(readonly, retain) DOMNode *endContainer;
+@property(readonly) int endOffset;
+@property(readonly) BOOL collapsed;
+@property(readonly, retain) DOMNode *commonAncestorContainer;
+@property(readonly, copy) NSString *text;
+- (void)setStart:(DOMNode *)refNode offset:(int)offset;
+- (void)setStart:(DOMNode *)refNode :(int)offset;
+- (void)setEnd:(DOMNode *)refNode offset:(int)offset;
+- (void)setEnd:(DOMNode *)refNode :(int)offset;
+- (void)setStartBefore:(DOMNode *)refNode;
+- (void)setStartAfter:(DOMNode *)refNode;
+- (void)setEndBefore:(DOMNode *)refNode;
+- (void)setEndAfter:(DOMNode *)refNode;
+- (void)collapse:(BOOL)toStart;
+- (void)selectNode:(DOMNode *)refNode;
+- (void)selectNodeContents:(DOMNode *)refNode;
+- (short)compareBoundaryPoints:(unsigned short)how sourceRange:(DOMRange *)sourceRange;
+- (short)compareBoundaryPoints:(unsigned short)how :(DOMRange *)sourceRange;
+- (void)deleteContents;
+- (DOMDocumentFragment *)extractContents;
+- (DOMDocumentFragment *)cloneContents;
+- (void)insertNode:(DOMNode *)newNode;
+- (void)surroundContents:(DOMNode *)newParent;
+- (DOMRange *)cloneRange;
+- (NSString *)toString;
+- (void)detach;
+@end
+
+@interface DOMNodeIterator : DOMObject
+@property(readonly, retain) DOMNode *root;
+@property(readonly) unsigned whatToShow;
+@property(readonly, retain) id <DOMNodeFilter> filter;
+@property(readonly) BOOL expandEntityReferences;
+- (DOMNode *)nextNode;
+- (DOMNode *)previousNode;
+- (void)detach;
+@end
+
+@interface DOMMediaList : DOMObject
+@property(copy) NSString *mediaText;
+@property(readonly) unsigned length;
+- (NSString *)item:(unsigned)index;
+- (void)deleteMedium:(NSString *)oldMedium;
+- (void)appendMedium:(NSString *)newMedium;
+@end
+
+@interface DOMTreeWalker : DOMObject
+@property(readonly, retain) DOMNode *root;
+@property(readonly) unsigned whatToShow;
+@property(readonly, retain) id <DOMNodeFilter> filter;
+@property(readonly) BOOL expandEntityReferences;
+@property(retain) DOMNode *currentNode;
+- (DOMNode *)parentNode;
+- (DOMNode *)firstChild;
+- (DOMNode *)lastChild;
+- (DOMNode *)previousSibling;
+- (DOMNode *)nextSibling;
+- (DOMNode *)previousNode;
+- (DOMNode *)nextNode;
+@end
+
+@interface DOMXPathResult : DOMObject
+@property(readonly) unsigned short resultType;
+@property(readonly) double numberValue;
+@property(readonly, copy) NSString *stringValue;
+@property(readonly) BOOL booleanValue;
+@property(readonly, retain) DOMNode *singleNodeValue;
+@property(readonly) BOOL invalidIteratorState;
+@property(readonly) unsigned snapshotLength;
+- (DOMNode *)iterateNext;
+- (DOMNode *)snapshotItem:(unsigned)index;
+@end
+
+@interface DOMXPathExpression : DOMObject
+// We should be able to remove the old style version of this method
+// once we can verify that all the internal Apple usages have switched
+// to the new style, because this has never been in a public release.
+- (DOMXPathResult *)evaluate:(DOMNode *)contextNode type:(unsigned short)type inResult:(DOMXPathResult *)inResult;
+- (DOMXPathResult *)evaluate:(DOMNode *)contextNode :(unsigned short)type :(DOMXPathResult *)inResult;
+@end
+
+// Protocols
+
+@protocol DOMEventListener <NSObject>
+- (void)handleEvent:(DOMEvent *)evt;
+@end
+
+@protocol DOMEventTarget <NSObject, NSCopying>
+- (void)addEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture;
+- (void)removeEventListener:(NSString *)type :(id <DOMEventListener>)listener :(BOOL)useCapture;
+- (void)addEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture;
+- (void)removeEventListener:(NSString *)type listener:(id <DOMEventListener>)listener useCapture:(BOOL)useCapture;
+- (BOOL)dispatchEvent:(DOMEvent *)event;
+@end
+
+@protocol DOMNodeFilter <NSObject>
+- (short)acceptNode:(DOMNode *)n;
+@end
+
+@protocol DOMXPathNSResolver <NSObject>
+- (NSString *)lookupNamespaceURI:(NSString *)prefix;
+@end
diff --git a/WebCore/bindings/objc/WebScriptObject.h b/WebCore/bindings/objc/WebScriptObject.h
new file mode 100644
index 0000000..3af774c
--- /dev/null
+++ b/WebCore/bindings/objc/WebScriptObject.h
@@ -0,0 +1,313 @@
+/*
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. 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 APPLE INC. ``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 APPLE INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import <Foundation/Foundation.h>
+#import <JavaScriptCore/JSBase.h>
+
+// NSObject (WebScripting) -----------------------------------------------------
+
+/*
+ Classes may implement one or more methods in WebScripting to export interfaces
+ to WebKit's JavaScript environment.
+
+ By default, no properties or functions are exported. A class must implement
+ +isKeyExcludedFromWebScript: and/or +isSelectorExcludedFromWebScript: to
+ expose selected properties and methods, respectively, to JavaScript.
+
+ Access to exported properties is done using KVC -- specifically, the following
+ KVC methods:
+
+ - (void)setValue:(id)value forKey:(NSString *)key
+ - (id)valueForKey:(NSString *)key
+
+ Clients may also intercept property set/get operations that are made by the
+ scripting environment for properties that are not exported. This is done using
+ the KVC methods:
+
+ - (void)setValue:(id)value forUndefinedKey:(NSString *)key
+ - (id)valueForUndefinedKey:(NSString *)key
+
+ Similarly, clients may intercept method invocations that are made by the
+ scripting environment for methods that are not exported. This is done using
+ the method:
+
+ - (id)invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)args;
+
+ If clients need to raise an exception in the script environment
+ they can call [WebScriptObject throwException:]. Note that throwing an
+ exception using this method will only succeed if the method that throws the exception
+ is being called within the scope of a script invocation.
+
+ Not all methods are exposed. Only those methods whose parameters and return
+ type meets the export criteria are exposed. Valid types are Objective-C instances
+ and scalars. Other types are not allowed.
+
+ Types will be converted automatically between JavaScript and Objective-C in
+ the following manner:
+
+ JavaScript ObjC
+ ---------- ----------
+ null => nil
+ undefined => WebUndefined
+ number => NSNumber
+ boolean => CFBoolean
+ string => NSString
+ object => id
+
+ The object => id conversion occurs as follows: if the object wraps an underlying
+ Objective-C object (i.e., if it was created by a previous ObjC => JavaScript conversion),
+ then the underlying Objective-C object is returned. Otherwise, a new WebScriptObject
+ is created and returned.
+
+ The above conversions occur only if the declared ObjC type is an object type.
+ For primitive types like int and char, a numeric cast is performed.
+
+ ObjC JavaScript
+ ---- ----------
+ NSNull => null
+ nil => undefined
+ WebUndefined => undefined
+ CFBoolean => boolean
+ NSNumber => number
+ NSString => string
+ NSArray => array object
+ WebScriptObject => object
+
+ The above conversions occur only if the declared ObjC type is an object type.
+ For primitive type like int and char, a numeric cast is performed.
+*/
+@interface NSObject (WebScripting)
+
+/*!
+ @method webScriptNameForSelector:
+ @param selector The selector that will be exposed to the script environment.
+ @discussion Use the returned string as the exported name for the selector
+ in the script environment. It is the responsibility of the class to ensure
+ uniqueness of the returned name. If nil is returned or this
+ method is not implemented the default name for the selector will
+ be used. The default name concatenates the components of the
+ Objective-C selector name and replaces ':' with '_'. '_' characters
+ are escaped with an additional '$', i.e. '_' becomes "$_". '$' are
+ also escaped, i.e.
+ Objective-C name Default script name
+ moveTo:: move__
+ moveTo_ moveTo$_
+ moveTo$_ moveTo$$$_
+ @result Returns the name to be used to represent the specified selector in the
+ scripting environment.
+*/
++ (NSString *)webScriptNameForSelector:(SEL)selector;
+
+/*!
+ @method isSelectorExcludedFromWebScript:
+ @param selector The selector the will be exposed to the script environment.
+ @discussion Return NO to export the selector to the script environment.
+ Return YES to prevent the selector from being exported to the script environment.
+ If this method is not implemented on the class no selectors will be exported.
+ @result Returns YES to hide the selector, NO to export the selector.
+*/
++ (BOOL)isSelectorExcludedFromWebScript:(SEL)selector;
+
+/*!
+ @method webScriptNameForKey:
+ @param name The name of the instance variable that will be exposed to the
+ script environment. Only instance variables that meet the export criteria will
+ be exposed.
+ @discussion Provide an alternate name for a property.
+ @result Returns the name to be used to represent the specified property in the
+ scripting environment.
+*/
++ (NSString *)webScriptNameForKey:(const char *)name;
+
+/*!
+ @method isKeyExcludedFromWebScript:
+ @param name The name of the instance variable that will be exposed to the
+ script environment.
+ @discussion Return NO to export the property to the script environment.
+ Return YES to prevent the property from being exported to the script environment.
+ @result Returns YES to hide the property, NO to export the property.
+*/
++ (BOOL)isKeyExcludedFromWebScript:(const char *)name;
+
+/*!
+ @method invokeUndefinedMethodFromWebScript:withArguments:
+ @param name The name of the method to invoke.
+ @param arguments The arguments to pass the method.
+ @discussion If a script attempts to invoke a method that is not exported,
+ invokeUndefinedMethodFromWebScript:withArguments: will be called.
+ @result The return value of the invocation. The value will be converted as appropriate
+ for the script environment.
+*/
+- (id)invokeUndefinedMethodFromWebScript:(NSString *)name withArguments:(NSArray *)arguments;
+
+/*!
+ @method invokeDefaultMethodWithArguments:
+ @param arguments The arguments to pass the method.
+ @discussion If a script attempts to call an exposed object as a function,
+ this method will be called.
+ @result The return value of the call. The value will be converted as appropriate
+ for the script environment.
+*/
+- (id)invokeDefaultMethodWithArguments:(NSArray *)arguments;
+
+/*!
+ @method finalizeForWebScript
+ @discussion finalizeForScript is called on objects exposed to the script
+ environment just before the script environment garbage collects the object.
+ Subsequently, any references to WebScriptObjects made by the exposed object will
+ be invalid and have undefined consequences.
+*/
+- (void)finalizeForWebScript;
+
+@end
+
+
+// WebScriptObject --------------------------------------------------
+
+@class WebScriptObjectPrivate;
+@class WebFrame;
+
+/*!
+ @class WebScriptObject
+ @discussion WebScriptObjects are used to wrap script objects passed from
+ script environments to Objective-C. WebScriptObjects cannot be created
+ directly. In normal uses of WebKit, you gain access to the script
+ environment using the "windowScriptObject" method on WebView.
+
+ The following KVC methods are commonly used to access properties of the
+ WebScriptObject:
+
+ - (void)setValue:(id)value forKey:(NSString *)key
+ - (id)valueForKey:(NSString *)key
+
+ As it possible to remove attributes from web script objects, the following
+ additional method augments the basic KVC methods:
+
+ - (void)removeWebScriptKey:(NSString *)name;
+
+ Also, since the sparse array access allowed in script objects doesn't map well
+ to NSArray, the following methods can be used to access index based properties:
+
+ - (id)webScriptValueAtIndex:(unsigned)index;
+ - (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value;
+*/
+@interface WebScriptObject : NSObject
+{
+ WebScriptObjectPrivate *_private;
+}
+
+/*!
+ @method throwException:
+ @discussion Throws an exception in the current script execution context.
+ @result Either NO if an exception could not be raised, YES otherwise.
+*/
++ (BOOL)throwException:(NSString *)exceptionMessage;
+
+/*!
+ @method JSObject
+ @result The equivalent JSObjectRef for this WebScriptObject.
+ @discussion Use this method to bridge between the WebScriptObject and
+ JavaScriptCore APIs.
+*/
+- (JSObjectRef)JSObject;
+
+/*!
+ @method callWebScriptMethod:withArguments:
+ @param name The name of the method to call in the script environment.
+ @param arguments The arguments to pass to the script environment.
+ @discussion Calls the specified method in the script environment using the
+ specified arguments.
+ @result Returns the result of calling the script method.
+ Returns WebUndefined when an exception is thrown in the script environment.
+*/
+- (id)callWebScriptMethod:(NSString *)name withArguments:(NSArray *)arguments;
+
+/*!
+ @method evaluateWebScript:
+ @param script The script to execute in the target script environment.
+ @discussion The script will be executed in the target script environment. The format
+ of the script is dependent of the target script environment.
+ @result Returns the result of evaluating the script in the script environment.
+ Returns WebUndefined when an exception is thrown in the script environment.
+*/
+- (id)evaluateWebScript:(NSString *)script;
+
+/*!
+ @method removeWebScriptKey:
+ @param name The name of the property to remove.
+ @discussion Removes the property from the object in the script environment.
+*/
+- (void)removeWebScriptKey:(NSString *)name;
+
+/*!
+ @method stringRepresentation
+ @discussion Converts the target object to a string representation. The coercion
+ of non string objects type is dependent on the script environment.
+ @result Returns the string representation of the object.
+*/
+- (NSString *)stringRepresentation;
+
+/*!
+ @method webScriptValueAtIndex:
+ @param index The index of the property to return.
+ @discussion Gets the value of the property at the specified index.
+ @result The value of the property. Returns WebUndefined when an exception is
+ thrown in the script environment.
+*/
+- (id)webScriptValueAtIndex:(unsigned)index;
+
+/*!
+ @method setWebScriptValueAtIndex:value:
+ @param index The index of the property to set.
+ @param value The value of the property to set.
+ @discussion Sets the property value at the specified index.
+*/
+- (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value;
+
+/*!
+ @method setException:
+ @param description The description of the exception.
+ @discussion Raises an exception in the script environment in the context of the
+ current object.
+*/
+- (void)setException:(NSString *)description;
+
+@end
+
+
+// WebUndefined --------------------------------------------------------------
+
+/*!
+ @class WebUndefined
+*/
+@interface WebUndefined : NSObject <NSCoding, NSCopying>
+
+/*!
+ @method undefined
+ @result The WebUndefined shared instance.
+*/
++ (WebUndefined *)undefined;
+
+@end
diff --git a/WebCore/bindings/objc/WebScriptObject.mm b/WebCore/bindings/objc/WebScriptObject.mm
new file mode 100644
index 0000000..4f1168b
--- /dev/null
+++ b/WebCore/bindings/objc/WebScriptObject.mm
@@ -0,0 +1,655 @@
+/*
+ * Copyright (C) 2004, 2006, 2007 Apple Inc. 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#import "config.h"
+#import "WebScriptObjectPrivate.h"
+
+#import "DOMInternal.h"
+#import "Frame.h"
+#import "PlatformString.h"
+#import "WebCoreObjCExtras.h"
+#import "WebCoreFrameBridge.h"
+#import <JavaScriptCore/ExecState.h>
+#import <JavaScriptCore/objc_instance.h>
+#import <JavaScriptCore/runtime_object.h>
+#import <JavaScriptCore/APICast.h>
+#import <JavaScriptCore/JSGlobalObject.h>
+#import <JavaScriptCore/interpreter.h>
+
+using namespace KJS;
+using namespace KJS::Bindings;
+using namespace WebCore;
+
+#define LOG_EXCEPTION(exec) \
+ if (Interpreter::shouldPrintExceptions()) \
+ printf("%s:%d:[%d] JavaScript exception: %s\n", __FILE__, __LINE__, getpid(), exec->exception()->toObject(exec)->get(exec, exec->propertyNames().message)->toString(exec).ascii());
+
+@interface WebFrame
+- (WebCoreFrameBridge *)_bridge; // implemented in WebKit
+@end
+
+namespace WebCore {
+
+typedef HashMap<JSObject*, NSObject*> JSWrapperMap;
+static JSWrapperMap* JSWrapperCache;
+
+NSObject* getJSWrapper(JSObject* impl)
+{
+ if (!JSWrapperCache)
+ return nil;
+ return JSWrapperCache->get(impl);
+}
+
+void addJSWrapper(NSObject* wrapper, JSObject* impl)
+{
+ if (!JSWrapperCache)
+ JSWrapperCache = new JSWrapperMap;
+ JSWrapperCache->set(impl, wrapper);
+}
+
+void removeJSWrapper(JSObject* impl)
+{
+ if (!JSWrapperCache)
+ return;
+ JSWrapperCache->remove(impl);
+}
+
+id createJSWrapper(KJS::JSObject* object, PassRefPtr<KJS::Bindings::RootObject> origin, PassRefPtr<KJS::Bindings::RootObject> root)
+{
+ if (id wrapper = getJSWrapper(object))
+ return [[wrapper retain] autorelease];
+ return [[[WebScriptObject alloc] _initWithJSObject:object originRootObject:origin rootObject:root] autorelease];
+}
+
+} // namespace WebCore
+
+@implementation WebScriptObjectPrivate
+
+@end
+
+@implementation WebScriptObject
+
+#ifndef BUILDING_ON_TIGER
++ (void)initialize
+{
+ WebCoreObjCFinalizeOnMainThread(self);
+}
+#endif
+
++ (id)scriptObjectForJSObject:(JSObjectRef)jsObject originRootObject:(RootObject*)originRootObject rootObject:(RootObject*)rootObject
+{
+ if (id domWrapper = WebCore::createDOMWrapper(toJS(jsObject), originRootObject, rootObject))
+ return domWrapper;
+
+ return WebCore::createJSWrapper(toJS(jsObject), originRootObject, rootObject);
+}
+
+static void _didExecute(WebScriptObject *obj)
+{
+ ASSERT(JSLock::lockCount() > 0);
+
+ RootObject* root = [obj _rootObject];
+ if (!root)
+ return;
+
+ ExecState* exec = root->globalObject()->globalExec();
+ KJSDidExecuteFunctionPtr func = Instance::didExecuteFunction();
+ if (func)
+ func(exec, root->globalObject());
+}
+
+- (void)_setImp:(JSObject*)imp originRootObject:(PassRefPtr<RootObject>)originRootObject rootObject:(PassRefPtr<RootObject>)rootObject
+{
+ // This function should only be called once, as a (possibly lazy) initializer.
+ ASSERT(!_private->imp);
+ ASSERT(!_private->rootObject);
+ ASSERT(!_private->originRootObject);
+ ASSERT(imp);
+
+ _private->imp = imp;
+ _private->rootObject = rootObject.releaseRef();
+ _private->originRootObject = originRootObject.releaseRef();
+
+ WebCore::addJSWrapper(self, imp);
+
+ if (_private->rootObject)
+ _private->rootObject->gcProtect(imp);
+}
+
+- (void)_setOriginRootObject:(PassRefPtr<RootObject>)originRootObject andRootObject:(PassRefPtr<RootObject>)rootObject
+{
+ ASSERT(_private->imp);
+
+ if (rootObject)
+ rootObject->gcProtect(_private->imp);
+
+ if (_private->rootObject && _private->rootObject->isValid())
+ _private->rootObject->gcUnprotect(_private->imp);
+
+ if (_private->rootObject)
+ _private->rootObject->deref();
+
+ if (_private->originRootObject)
+ _private->originRootObject->deref();
+
+ _private->rootObject = rootObject.releaseRef();
+ _private->originRootObject = originRootObject.releaseRef();
+}
+
+- (id)_initWithJSObject:(KJS::JSObject*)imp originRootObject:(PassRefPtr<KJS::Bindings::RootObject>)originRootObject rootObject:(PassRefPtr<KJS::Bindings::RootObject>)rootObject
+{
+ ASSERT(imp);
+
+ self = [super init];
+ _private = [[WebScriptObjectPrivate alloc] init];
+ [self _setImp:imp originRootObject:originRootObject rootObject:rootObject];
+
+ return self;
+}
+
+- (JSObject*)_imp
+{
+ // Associate the WebScriptObject with the JS wrapper for the ObjC DOM wrapper.
+ // This is done on lazily, on demand.
+ if (!_private->imp && _private->isCreatedByDOMWrapper)
+ [self _initializeScriptDOMNodeImp];
+ return [self _rootObject] ? _private->imp : 0;
+}
+
+- (BOOL)_hasImp
+{
+ return _private->imp != nil;
+}
+
+// Node that DOMNode overrides this method. So you should almost always
+// use this method call instead of _private->rootObject directly.
+- (RootObject*)_rootObject
+{
+ return _private->rootObject && _private->rootObject->isValid() ? _private->rootObject : 0;
+}
+
+- (RootObject *)_originRootObject
+{
+ return _private->originRootObject && _private->originRootObject->isValid() ? _private->originRootObject : 0;
+}
+
+- (BOOL)_isSafeScript
+{
+ RootObject *root = [self _rootObject];
+ if (!root)
+ return false;
+
+ if (!_private->originRootObject)
+ return true;
+
+ if (!_private->originRootObject->isValid())
+ return false;
+
+ return root->globalObject()->allowsAccessFrom(_private->originRootObject->globalObject());
+}
+
+- (void)dealloc
+{
+ if (_private->imp)
+ WebCore::removeJSWrapper(_private->imp);
+
+ if (_private->rootObject && _private->rootObject->isValid())
+ _private->rootObject->gcUnprotect(_private->imp);
+
+ if (_private->rootObject)
+ _private->rootObject->deref();
+
+ if (_private->originRootObject)
+ _private->originRootObject->deref();
+
+ [_private release];
+
+ [super dealloc];
+}
+
+- (void)finalize
+{
+ if (_private->imp)
+ WebCore::removeJSWrapper(_private->imp);
+
+ if (_private->rootObject && _private->rootObject->isValid())
+ _private->rootObject->gcUnprotect(_private->imp);
+
+ if (_private->rootObject)
+ _private->rootObject->deref();
+
+ if (_private->originRootObject)
+ _private->originRootObject->deref();
+
+ [super finalize];
+}
+
++ (BOOL)throwException:(NSString *)exceptionMessage
+{
+ JSLock lock;
+
+ // This code assumes that we only ever have one running interpreter. A
+ // good assumption for now, as we depend on that elsewhere. However,
+ // in the future we may have the ability to run multiple interpreters,
+ // in which case this will have to change.
+
+ if (ExecState::activeExecStates().size()) {
+ throwError(ExecState::activeExecStates().last(), GeneralError, exceptionMessage);
+ return YES;
+ }
+
+ return NO;
+}
+
+static void getListFromNSArray(ExecState *exec, NSArray *array, RootObject* rootObject, List& aList)
+{
+ int i, numObjects = array ? [array count] : 0;
+
+ for (i = 0; i < numObjects; i++) {
+ id anObject = [array objectAtIndex:i];
+ aList.append(convertObjcValueToValue(exec, &anObject, ObjcObjectType, rootObject));
+ }
+}
+
+- (id)callWebScriptMethod:(NSString *)name withArguments:(NSArray *)args
+{
+ if (![self _isSafeScript])
+ return nil;
+
+ // Look up the function object.
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+ ASSERT(!exec->hadException());
+
+ JSLock lock;
+
+ JSValue* func = [self _imp]->get(exec, String(name));
+
+ if (!func || !func->isObject())
+ // Maybe throw an exception here?
+ return 0;
+
+ // Call the function object.
+ JSObject *funcImp = static_cast<JSObject*>(func);
+ if (!funcImp->implementsCall())
+ return 0;
+
+ List argList;
+ getListFromNSArray(exec, args, [self _rootObject], argList);
+
+ if (![self _isSafeScript])
+ return nil;
+
+ [self _rootObject]->globalObject()->startTimeoutCheck();
+ JSValue *result = funcImp->call(exec, [self _imp], argList);
+ [self _rootObject]->globalObject()->stopTimeoutCheck();
+
+ if (exec->hadException()) {
+ LOG_EXCEPTION(exec);
+ result = jsUndefined();
+ exec->clearException();
+ }
+
+ // Convert and return the result of the function call.
+ id resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];
+
+ _didExecute(self);
+
+ return resultObj;
+}
+
+- (id)evaluateWebScript:(NSString *)script
+{
+ if (![self _isSafeScript])
+ return nil;
+
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+ ASSERT(!exec->hadException());
+
+ JSValue *result;
+ JSLock lock;
+
+ [self _rootObject]->globalObject()->startTimeoutCheck();
+ Completion completion = Interpreter::evaluate([self _rootObject]->globalObject()->globalExec(), UString(), 0, String(script));
+ [self _rootObject]->globalObject()->stopTimeoutCheck();
+ ComplType type = completion.complType();
+
+ if (type == Normal) {
+ result = completion.value();
+ if (!result)
+ result = jsUndefined();
+ } else
+ result = jsUndefined();
+
+ if (exec->hadException()) {
+ LOG_EXCEPTION(exec);
+ result = jsUndefined();
+ exec->clearException();
+ }
+
+ id resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];
+
+ _didExecute(self);
+
+ return resultObj;
+}
+
+- (void)setValue:(id)value forKey:(NSString *)key
+{
+ if (![self _isSafeScript])
+ return;
+
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+ ASSERT(!exec->hadException());
+
+ JSLock lock;
+ [self _imp]->put(exec, String(key), convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject]));
+
+ if (exec->hadException()) {
+ LOG_EXCEPTION(exec);
+ exec->clearException();
+ }
+
+ _didExecute(self);
+}
+
+- (id)valueForKey:(NSString *)key
+{
+ if (![self _isSafeScript])
+ return nil;
+
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+ ASSERT(!exec->hadException());
+
+ id resultObj;
+ {
+ // Need to scope this lock to ensure that we release the lock before calling
+ // [super valueForKey:key] which might throw an exception and bypass the JSLock destructor,
+ // leaving the lock permanently held
+ JSLock lock;
+
+ JSValue *result = [self _imp]->get(exec, String(key));
+
+ if (exec->hadException()) {
+ LOG_EXCEPTION(exec);
+ result = jsUndefined();
+ exec->clearException();
+ }
+
+ resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];
+ }
+
+ if ([resultObj isKindOfClass:[WebUndefined class]])
+ resultObj = [super valueForKey:key]; // defaults to throwing an exception
+
+ JSLock lock;
+ _didExecute(self);
+
+ return resultObj;
+}
+
+- (void)removeWebScriptKey:(NSString *)key
+{
+ if (![self _isSafeScript])
+ return;
+
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+ ASSERT(!exec->hadException());
+
+ JSLock lock;
+ [self _imp]->deleteProperty(exec, String(key));
+
+ if (exec->hadException()) {
+ LOG_EXCEPTION(exec);
+ exec->clearException();
+ }
+
+ _didExecute(self);
+}
+
+- (NSString *)stringRepresentation
+{
+ if (![self _isSafeScript])
+ // This is a workaround for a gcc 3.3 internal compiler error.
+ return @"Undefined";
+
+ JSLock lock;
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+
+ id result = convertValueToObjcValue(exec, [self _imp], ObjcObjectType).objectValue;
+
+ NSString *description = [result description];
+
+ _didExecute(self);
+
+ return description;
+}
+
+- (id)webScriptValueAtIndex:(unsigned)index
+{
+ if (![self _isSafeScript])
+ return nil;
+
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+ ASSERT(!exec->hadException());
+
+ JSLock lock;
+ JSValue *result = [self _imp]->get(exec, index);
+
+ if (exec->hadException()) {
+ LOG_EXCEPTION(exec);
+ result = jsUndefined();
+ exec->clearException();
+ }
+
+ id resultObj = [WebScriptObject _convertValueToObjcValue:result originRootObject:[self _originRootObject] rootObject:[self _rootObject]];
+
+ _didExecute(self);
+
+ return resultObj;
+}
+
+- (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value
+{
+ if (![self _isSafeScript])
+ return;
+
+ ExecState* exec = [self _rootObject]->globalObject()->globalExec();
+ ASSERT(!exec->hadException());
+
+ JSLock lock;
+ [self _imp]->put(exec, index, convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject]));
+
+ if (exec->hadException()) {
+ LOG_EXCEPTION(exec);
+ exec->clearException();
+ }
+
+ _didExecute(self);
+}
+
+- (void)setException:(NSString *)description
+{
+ if (![self _rootObject])
+ return;
+
+ JSLock lock;
+
+ ExecState* exec = 0;
+ JSObject* globalObject = [self _rootObject]->globalObject();
+ ExecStateStack::const_iterator end = ExecState::activeExecStates().end();
+ for (ExecStateStack::const_iterator it = ExecState::activeExecStates().begin(); it != end; ++it)
+ if ((*it)->dynamicGlobalObject() == globalObject)
+ exec = *it;
+
+ if (exec)
+ throwError(exec, GeneralError, description);
+}
+
+- (JSObjectRef)JSObject
+{
+ if (![self _isSafeScript])
+ return NULL;
+
+ return toRef([self _imp]);
+}
+
++ (id)_convertValueToObjcValue:(JSValue*)value originRootObject:(RootObject*)originRootObject rootObject:(RootObject*)rootObject
+{
+ if (value->isObject()) {
+ JSObject* object = static_cast<JSObject*>(value);
+ ExecState* exec = rootObject->globalObject()->globalExec();
+ JSLock lock;
+
+ if (object->classInfo() != &RuntimeObjectImp::info) {
+ JSValue* runtimeObject = object->get(exec, "__apple_runtime_object");
+ if (runtimeObject && runtimeObject->isObject())
+ object = static_cast<RuntimeObjectImp*>(runtimeObject);
+ }
+
+ if (object->classInfo() == &RuntimeObjectImp::info) {
+ RuntimeObjectImp* imp = static_cast<RuntimeObjectImp*>(object);
+ ObjcInstance *instance = static_cast<ObjcInstance*>(imp->getInternalInstance());
+ if (instance)
+ return instance->getObject();
+ return nil;
+ }
+
+ return [WebScriptObject scriptObjectForJSObject:toRef(object) originRootObject:originRootObject rootObject:rootObject];
+ }
+
+ if (value->isString()) {
+ UString u = value->getString();
+ return [NSString stringWithCharacters:(const unichar*)u.data() length:u.size()];
+ }
+
+ if (value->isNumber())
+ return [NSNumber numberWithDouble:value->getNumber()];
+
+ if (value->isBoolean())
+ return [NSNumber numberWithBool:value->getBoolean()];
+
+ if (value->isUndefined())
+ return [WebUndefined undefined];
+
+ // jsNull is not returned as NSNull because existing applications do not expect
+ // that return value. Return as nil for compatibility. <rdar://problem/4651318> <rdar://problem/4701626>
+ // Other types (e.g., UnspecifiedType) also return as nil.
+ return nil;
+}
+
+@end
+
+@interface WebScriptObject (WebKitCocoaBindings)
+
+- (id)objectAtIndex:(unsigned)index;
+
+@end
+
+@implementation WebScriptObject (WebKitCocoaBindings)
+
+#if 0
+// FIXME: presence of 'count' method on WebScriptObject breaks Democracy player
+// http://bugs.webkit.org/show_bug.cgi?id=13129
+
+- (unsigned)count
+{
+ id length = [self valueForKey:@"length"];
+ if ([length respondsToSelector:@selector(intValue)])
+ return [length intValue];
+ else
+ return 0;
+}
+
+#endif
+
+- (id)objectAtIndex:(unsigned)index
+{
+ return [self webScriptValueAtIndex:index];
+}
+
+@end
+
+@implementation WebUndefined
+
++ (id)allocWithZone:(NSZone *)zone
+{
+ static WebUndefined *sharedUndefined = 0;
+ if (!sharedUndefined)
+ sharedUndefined = [super allocWithZone:NULL];
+ return sharedUndefined;
+}
+
+- (NSString *)description
+{
+ return @"undefined";
+}
+
+- (id)initWithCoder:(NSCoder *)coder
+{
+ return self;
+}
+
+- (void)encodeWithCoder:(NSCoder *)encoder
+{
+}
+
+- (id)copyWithZone:(NSZone *)zone
+{
+ return self;
+}
+
+- (id)retain
+{
+ return self;
+}
+
+- (void)release
+{
+}
+
+- (unsigned)retainCount
+{
+ return UINT_MAX;
+}
+
+- (id)autorelease
+{
+ return self;
+}
+
+- (void)dealloc
+{
+ ASSERT(false);
+ return;
+ [super dealloc]; // make -Wdealloc-check happy
+}
+
++ (WebUndefined *)undefined
+{
+ return [WebUndefined allocWithZone:NULL];
+}
+
+@end
+
diff --git a/WebCore/bindings/objc/WebScriptObjectPrivate.h b/WebCore/bindings/objc/WebScriptObjectPrivate.h
new file mode 100644
index 0000000..421209d
--- /dev/null
+++ b/WebCore/bindings/objc/WebScriptObjectPrivate.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. 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 APPLE INC. ``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 APPLE INC. OR
+ * CONTRIBUTORS 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.
+ */
+
+#ifndef _WEB_SCRIPT_OBJECT_PRIVATE_H_
+#define _WEB_SCRIPT_OBJECT_PRIVATE_H_
+
+#import "WebScriptObject.h"
+
+#include <JavaScriptCore/internal.h>
+#include <JavaScriptCore/object.h>
+#include <JavaScriptCore/runtime_root.h>
+#include <JavaScriptCore/APICast.h>
+
+namespace WebCore {
+ NSObject* getJSWrapper(KJS::JSObject*);
+ void addJSWrapper(NSObject* wrapper, KJS::JSObject*);
+ void removeJSWrapper(KJS::JSObject*);
+ id createJSWrapper(KJS::JSObject*, PassRefPtr<KJS::Bindings::RootObject> origin, PassRefPtr<KJS::Bindings::RootObject> root);
+}
+
+@interface WebScriptObject (Private)
++ (id)_convertValueToObjcValue:(KJS::JSValue*)value originRootObject:(KJS::Bindings::RootObject*)originRootObject rootObject:(KJS::Bindings::RootObject*)rootObject;
++ (id)scriptObjectForJSObject:(JSObjectRef)jsObject originRootObject:(KJS::Bindings::RootObject*)originRootObject rootObject:(KJS::Bindings::RootObject*)rootObject;
+- (id)_init;
+- (id)_initWithJSObject:(KJS::JSObject*)imp originRootObject:(PassRefPtr<KJS::Bindings::RootObject>)originRootObject rootObject:(PassRefPtr<KJS::Bindings::RootObject>)rootObject;
+- (void)_setImp:(KJS::JSObject*)imp originRootObject:(PassRefPtr<KJS::Bindings::RootObject>)originRootObject rootObject:(PassRefPtr<KJS::Bindings::RootObject>)rootObject;
+- (void)_setOriginRootObject:(PassRefPtr<KJS::Bindings::RootObject>)originRootObject andRootObject:(PassRefPtr<KJS::Bindings::RootObject>)rootObject;
+- (void)_initializeScriptDOMNodeImp;
+- (KJS::JSObject *)_imp;
+- (BOOL)_hasImp;
+- (KJS::Bindings::RootObject*)_rootObject;
+- (KJS::Bindings::RootObject*)_originRootObject;
+@end
+
+@interface WebScriptObjectPrivate : NSObject
+{
+@public
+ KJS::JSObject *imp;
+ KJS::Bindings::RootObject* rootObject;
+ KJS::Bindings::RootObject* originRootObject;
+ BOOL isCreatedByDOMWrapper;
+}
+@end
+
+
+#endif
diff --git a/WebCore/bindings/scripts/CodeGenerator.pm b/WebCore/bindings/scripts/CodeGenerator.pm
new file mode 100644
index 0000000..2095c88
--- /dev/null
+++ b/WebCore/bindings/scripts/CodeGenerator.pm
@@ -0,0 +1,382 @@
+#
+# WebKit IDL parser
+#
+# Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org>
+# Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
+# Copyright (C) 2007 Apple Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# aint with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+
+package CodeGenerator;
+
+my $useDocument = "";
+my $useGenerator = "";
+my $useOutputDir = "";
+my $useDirectories = "";
+my $useLayerOnTop = 0;
+my $preprocessor;
+
+my $codeGenerator = 0;
+
+my $verbose = 0;
+
+my %primitiveTypeHash = ("int" => 1, "short" => 1, "long" => 1,
+ "unsigned int" => 1, "unsigned short" => 1,
+ "unsigned long" => 1, "float" => 1,
+ "double" => 1, "boolean" => 1, "void" => 1);
+
+my %podTypeHash = ("RGBColor" => 1, "SVGLength" => 1, "SVGPoint" => 1, "SVGRect" => 1, "SVGNumber" => 1, "SVGMatrix" => 1, "SVGTransform" => 1);
+
+my %stringTypeHash = ("DOMString" => 1, "AtomicString" => 1);
+
+my %nonPointerTypeHash = ("DOMTimeStamp" => 1, "CompareHow" => 1, "SVGPaintType" => 1);
+
+my %svgAnimatedTypeHash = ("SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1,
+ "SVGAnimatedEnumeration" => 1, "SVGAnimatedInteger" => 1,
+ "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1,
+ "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1,
+ "SVGAnimatedPreserveAspectRatio" => 1,
+ "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1,
+ "SVGAnimatedTransformList" => 1);
+
+# Helpers for 'ScanDirectory'
+my $endCondition = 0;
+my $foundFilename = "";
+my @foundFilenames = ();
+my $ignoreParent = 1;
+my $defines = "";
+
+# Default constructor
+sub new
+{
+ my $object = shift;
+ my $reference = { };
+
+ $useDirectories = shift;
+ $useGenerator = shift;
+ $useOutputDir = shift;
+ $useLayerOnTop = shift;
+ $preprocessor = shift;
+
+ bless($reference, $object);
+ return $reference;
+}
+
+sub StripModule($)
+{
+ my $object = shift;
+ my $name = shift;
+ $name =~ s/[a-zA-Z0-9]*:://;
+ return $name;
+}
+
+sub ProcessDocument
+{
+ my $object = shift;
+ $useDocument = shift;
+ $defines = shift;
+
+ my $ifaceName = "CodeGenerator" . $useGenerator;
+
+ # Dynamically load external code generation perl module
+ require $ifaceName . ".pm";
+ $codeGenerator = $ifaceName->new($object, $useOutputDir, $useLayerOnTop, $preprocessor);
+ unless (defined($codeGenerator)) {
+ my $classes = $useDocument->classes;
+ foreach my $class (@$classes) {
+ print "Skipping $useGenerator code generation for IDL interface \"" . $class->name . "\".\n" if $verbose;
+ }
+ return;
+ }
+
+ # Start the actual code generation!
+ $codeGenerator->GenerateModule($useDocument, $defines);
+
+ my $classes = $useDocument->classes;
+ foreach my $class (@$classes) {
+ print "Generating $useGenerator bindings code for IDL interface \"" . $class->name . "\"...\n" if $verbose;
+ $codeGenerator->GenerateInterface($class, $defines);
+ }
+
+ $codeGenerator->finish();
+}
+
+sub AddMethodsConstantsAndAttributesFromParentClasses
+{
+ # For the passed interface, recursively parse all parent
+ # IDLs in order to find out all inherited properties/methods.
+
+ my $object = shift;
+ my $dataNode = shift;
+
+ my @parents = @{$dataNode->parents};
+ my $parentsMax = @{$dataNode->parents};
+
+ my $constantsRef = $dataNode->constants;
+ my $functionsRef = $dataNode->functions;
+ my $attributesRef = $dataNode->attributes;
+
+ # Exception: For the DOM 'Node' is our topmost baseclass, not EventTargetNode.
+ return if $parentsMax eq 1 and $parents[0] eq "EventTargetNode";
+
+ foreach (@{$dataNode->parents}) {
+ if ($ignoreParent) {
+ # Ignore first parent class, already handled by the generation itself.
+ $ignoreParent = 0;
+ next;
+ }
+
+ my $interface = $object->StripModule($_);
+
+ # Step #1: Find the IDL file associated with 'interface'
+ $endCondition = 0;
+ $foundFilename = "";
+
+ foreach (@{$useDirectories}) {
+ $object->ScanDirectory("$interface.idl", $_, $_, 0) if ($foundFilename eq "");
+ }
+
+ if ($foundFilename ne "") {
+ print " | |> Parsing parent IDL \"$foundFilename\" for interface \"$interface\"\n" if $verbose;
+
+ # Step #2: Parse the found IDL file (in quiet mode).
+ my $parser = IDLParser->new(1);
+ my $document = $parser->Parse($foundFilename, $defines, $preprocessor);
+
+ foreach my $class (@{$document->classes}) {
+ # Step #3: Enter recursive parent search
+ AddMethodsConstantsAndAttributesFromParentClasses($object, $class);
+
+ # Step #4: Collect constants & functions & attributes of this parent-class
+ my $constantsMax = @{$class->constants};
+ my $functionsMax = @{$class->functions};
+ my $attributesMax = @{$class->attributes};
+
+ print " | |> -> Inheriting $constantsMax constants, $functionsMax functions, $attributesMax attributes...\n | |>\n" if $verbose;
+
+ # Step #5: Concatenate data
+ push(@$constantsRef, $_) foreach (@{$class->constants});
+ push(@$functionsRef, $_) foreach (@{$class->functions});
+ push(@$attributesRef, $_) foreach (@{$class->attributes});
+ }
+ } else {
+ die("Could NOT find specified parent interface \"$interface\"!\n");
+ }
+ }
+}
+
+sub GetMethodsAndAttributesFromParentClasses
+{
+ # For the passed interface, recursively parse all parent
+ # IDLs in order to find out all inherited properties/methods.
+
+ my $object = shift;
+ my $dataNode = shift;
+
+ my @parents = @{$dataNode->parents};
+
+ return if @{$dataNode->parents} == 0;
+
+ my @parentList = ();
+
+ foreach (@{$dataNode->parents}) {
+ my $interface = $object->StripModule($_);
+ if ($interface eq "EventTargetNode") {
+ $interface = "Node";
+ }
+
+ # Step #1: Find the IDL file associated with 'interface'
+ $endCondition = 0;
+ $foundFilename = "";
+
+ foreach (@{$useDirectories}) {
+ $object->ScanDirectory("${interface}.idl", $_, $_, 0) if $foundFilename eq "";
+ }
+
+ die("Could NOT find specified parent interface \"$interface\"!\n") if $foundFilename eq "";
+
+ print " | |> Parsing parent IDL \"$foundFilename\" for interface \"$interface\"\n" if $verbose;
+
+ # Step #2: Parse the found IDL file (in quiet mode).
+ my $parser = IDLParser->new(1);
+ my $document = $parser->Parse($foundFilename, $defines);
+
+ foreach my $class (@{$document->classes}) {
+ # Step #3: Enter recursive parent search
+ push(@parentList, GetMethodsAndAttributesFromParentClasses($object, $class));
+
+ # Step #4: Collect constants & functions & attributes of this parent-class
+
+ # print " | |> -> Inheriting $functionsMax functions amd $attributesMax attributes...\n | |>\n" if $verbose;
+ my $hash = {
+ "name" => $class->name,
+ "functions" => $class->functions,
+ "attributes" => $class->attributes
+ };
+
+ # Step #5: Concatenate data
+ unshift(@parentList, $hash);
+ }
+ }
+
+ return @parentList;
+}
+
+sub ParseInterface
+{
+ my ($object, $interfaceName) = @_;
+
+ # Step #1: Find the IDL file associated with 'interface'
+ $endCondition = 0;
+ $foundFilename = "";
+
+ foreach (@{$useDirectories}) {
+ $object->ScanDirectory("${interfaceName}.idl", $_, $_, 0) if $foundFilename eq "";
+ }
+ die "Could NOT find specified parent interface \"$interfaceName\"!\n" if $foundFilename eq "";
+
+ print " | |> Parsing parent IDL \"$foundFilename\" for interface \"$interfaceName\"\n" if $verbose;
+
+ # Step #2: Parse the found IDL file (in quiet mode).
+ my $parser = IDLParser->new(1);
+ my $document = $parser->Parse($foundFilename, $defines);
+
+ foreach my $interface (@{$document->classes}) {
+ return $interface if $interface->name eq $interfaceName;
+ }
+
+ die "Interface definition not found";
+}
+
+# Helpers for all CodeGenerator***.pm modules
+sub IsPodType
+{
+ my $object = shift;
+ my $type = shift;
+
+ return 1 if $podTypeHash{$type};
+ return 0;
+}
+
+sub IsPrimitiveType
+{
+ my $object = shift;
+ my $type = shift;
+
+ return 1 if $primitiveTypeHash{$type};
+ return 0;
+}
+
+sub IsStringType
+{
+ my $object = shift;
+ my $type = shift;
+
+ return 1 if $stringTypeHash{$type};
+ return 0;
+}
+
+sub IsNonPointerType
+{
+ my $object = shift;
+ my $type = shift;
+
+ return 1 if $nonPointerTypeHash{$type} or $primitiveTypeHash{$type};
+ return 0;
+}
+
+sub IsSVGAnimatedType
+{
+ my $object = shift;
+ my $type = shift;
+
+ return 1 if $svgAnimatedTypeHash{$type};
+ return 0;
+}
+
+# Internal Helper
+sub ScanDirectory
+{
+ my $object = shift;
+
+ my $interface = shift;
+ my $directory = shift;
+ my $useDirectory = shift;
+ my $reportAllFiles = shift;
+
+ return if ($endCondition eq 1) and ($reportAllFiles eq 0);
+
+ my $sourceRoot = $ENV{SOURCE_ROOT};
+ my $thisDir = $sourceRoot ? "$sourceRoot/$directory" : $directory;
+
+ if (!opendir(DIR, $thisDir)) {
+ opendir(DIR, $directory) or die "[ERROR] Can't open directory $thisDir or $directory: \"$!\"\n";
+ $thisDir = $directory;
+ }
+
+ my @names = readdir(DIR) or die "[ERROR] Cant't read directory $thisDir \"$!\"\n";
+ closedir(DIR);
+
+ foreach my $name (@names) {
+ # Skip if we already found the right file or
+ # if we encounter 'exotic' stuff (ie. '.', '..', '.svn')
+ next if ($endCondition eq 1) or ($name =~ /^\./);
+
+ # Recurisvely enter directory
+ if (-d "$thisDir/$name") {
+ $object->ScanDirectory($interface, "$directory/$name", $useDirectory, $reportAllFiles);
+ next;
+ }
+
+ # Check wheter we found the desired file
+ my $condition = ($name eq $interface);
+ $condition = 1 if ($interface eq "allidls") and ($name =~ /\.idl$/);
+
+ if ($condition) {
+ $foundFilename = "$thisDir/$name";
+
+ if ($reportAllFiles eq 0) {
+ $endCondition = 1;
+ } else {
+ push(@foundFilenames, $foundFilename);
+ }
+ }
+ }
+}
+
+# Uppercase the first letter while respecting WebKit style guidelines.
+# E.g., xmlEncoding becomes XMLEncoding, but xmlllang becomes Xmllang.
+sub WK_ucfirst
+{
+ my ($object, $param) = @_;
+ my $ret = ucfirst($param);
+ $ret =~ s/Xml/XML/ if $ret =~ /^Xml[^a-z]/;
+ return $ret;
+}
+
+# Lowercase the first letter while respecting WebKit style guidelines.
+# URL becomes url, but SetURL becomes setURL.
+sub WK_lcfirst
+{
+ my ($object, $param) = @_;
+ my $ret = lcfirst($param);
+ $ret =~ s/uRL/url/ if $ret =~ /^uRL/;
+ $ret =~ s/jS/js/ if $ret =~ /^jS/;
+ return $ret;
+}
+
+1;
diff --git a/WebCore/bindings/scripts/CodeGeneratorCOM.pm b/WebCore/bindings/scripts/CodeGeneratorCOM.pm
new file mode 100644
index 0000000..f2b1cdd
--- /dev/null
+++ b/WebCore/bindings/scripts/CodeGeneratorCOM.pm
@@ -0,0 +1,1313 @@
+#
+# Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
+# Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
+# Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
+# Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
+# Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# aint with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+package CodeGeneratorCOM;
+
+use File::stat;
+
+# Global Variables
+my $module = "";
+my $outputDir = "";
+
+my @IDLHeader = ();
+my @IDLContent = ();
+my %IDLIncludes = ();
+my %IDLForwardDeclarations = ();
+my %IDLDontForwardDeclare = ();
+my %IDLImports = ();
+my %IDLDontImport = ();
+
+my @CPPInterfaceHeader = ();
+
+my @CPPHeaderHeader = ();
+my @CPPHeaderContent = ();
+my %CPPHeaderIncludes = ();
+my %CPPHeaderIncludesAngle = ();
+my %CPPHeaderForwardDeclarations = ();
+my %CPPHeaderDontForwardDeclarations = ();
+
+my @CPPImplementationHeader = ();
+my @CPPImplementationContent = ();
+my %CPPImplementationIncludes = ();
+my %CPPImplementationWebCoreIncludes = ();
+my %CPPImplementationIncludesAngle = ();
+my %CPPImplementationDontIncludes = ();
+
+my @additionalInterfaceDefinitions = ();
+
+my $DASHES = "----------------------------------------";
+my $TEMP_PREFIX = "GEN_";
+
+# Hashes
+
+my %includeCorrector = map {($_, 1)} qw{UIEvent KeyboardEvent MouseEvent
+ MutationEvent OverflowEvent WheelEvent};
+
+my %conflictMethod = (
+ # FIXME: Add C language keywords?
+);
+
+# Default License Templates
+my @licenseTemplate = split(/\r/, << "EOF");
+/*
+ * Copyright (C) 2007 Apple Inc. 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.
+ * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
+ * its contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "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 APPLE OR ITS CONTRIBUTORS 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.
+ */
+EOF
+
+# Default constructor
+sub new
+{
+ my $object = shift;
+ my $reference = { };
+
+ $codeGenerator = shift;
+ $outputDir = shift;
+
+ bless($reference, $object);
+ return $reference;
+}
+
+sub finish
+{
+ my $object = shift;
+}
+
+# Params: 'domClass' struct
+sub GenerateInterface
+{
+ my $object = shift;
+ my $dataNode = shift;
+ my $defines = shift;
+
+ my $name = $dataNode->name;
+
+ my $pureInterface = $dataNode->extendedAttributes->{"PureInterface"};
+
+ # Start actual generation..
+ $object->GenerateIDL($dataNode, $pureInterface);
+ if ($pureInterface) {
+ $object->GenerateInterfaceHeader($dataNode);
+ } else {
+ $object->GenerateCPPHeader($dataNode);
+ $object->GenerateCPPImplementation($dataNode);
+ }
+
+ # Write changes.
+ $object->WriteData($name, $pureInterface);
+}
+
+# Params: 'idlDocument' struct
+sub GenerateModule
+{
+ my $object = shift;
+ my $dataNode = shift;
+
+ $module = $dataNode->module;
+}
+
+sub GetInterfaceName
+{
+ my $name = $codeGenerator->StripModule(shift);
+
+ die "GetInterfaceName should only be used on interfaces." if ($codeGenerator->IsStringType($name) or $codeGenerator->IsPrimitiveType($name));
+
+ # special cases
+ return "I" . $TEMP_PREFIX . "DOMAbstractView" if $name eq "DOMWindow";
+ return "I" . $TEMP_PREFIX . $name if $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
+
+ # Default, assume COM type has the same type name as
+ # idl type prefixed with "IDOM".
+ return "I" . $TEMP_PREFIX . "DOM" . $name;
+}
+
+sub GetClassName
+{
+ my $name = $codeGenerator->StripModule(shift);
+
+ # special cases
+ return "BSTR" if $codeGenerator->IsStringType($name);
+ return "BOOL" if $name eq "boolean";
+ return "unsigned" if $name eq "unsigned long";
+ return "int" if $name eq "long";
+ return $name if $codeGenerator->IsPrimitiveType($name);
+ return $TEMP_PREFIX . "DOMAbstractView" if $name eq "DOMWindow";
+ return $TEMP_PREFIX . $name if $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
+
+ # Default, assume COM type has the same type name as
+ # idl type prefixed with "DOM".
+ return $TEMP_PREFIX . "DOM" . $name;
+}
+
+sub GetCOMType
+{
+ my ($type) = @_;
+
+ die "Don't use GetCOMType for string types, use one of In/Out variants instead." if $codeGenerator->IsStringType($type);
+
+ return "BOOL" if $type eq "boolean";
+ return "UINT" if $type eq "unsigned long";
+ return "INT" if $type eq "long";
+ return $type if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
+ # return "unsigned short" if $type eq "CompareHow" or $type eq "SVGPaintType";
+
+ return GetInterfaceName($type) . "*";
+}
+
+sub GetCOMTypeIn
+{
+ my ($type) = @_;
+ return "LPCTSTR" if $codeGenerator->IsStringType($type);
+ return GetCOMType($type);
+}
+
+sub GetCOMTypeOut
+{
+ my ($type) = @_;
+ return "BSTR" if $codeGenerator->IsStringType($type);
+ return GetCOMType($type);
+}
+
+sub IDLTypeToImplementationType
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ return "bool" if $type eq "boolean";
+ return "unsigned" if $type eq "unsigned long";
+ return "int" if $type eq "long";
+ return $type if $codeGenerator->IsPrimitiveType($type);
+
+ return "WebCore::String" if $codeGenerator->IsStringType($type);
+ return "WebCore::${type}";
+}
+
+sub StripNamespace
+{
+ my ($type) = @_;
+
+ $type =~ s/^WebCore:://;
+
+ return $type;
+}
+
+sub GetParentInterface
+{
+ my ($dataNode) = @_;
+ return "I" . $TEMP_PREFIX . "DOMObject" if (@{$dataNode->parents} == 0);
+ return "I" . $TEMP_PREFIX . "DOMNode" if $codeGenerator->StripModule($dataNode->parents(0)) eq "EventTargetNode";
+ return GetInterfaceName($codeGenerator->StripModule($dataNode->parents(0)));
+}
+
+sub GetParentClass
+{
+ my ($dataNode) = @_;
+ return $TEMP_PREFIX . "DOMObject" if (@{$dataNode->parents} == 0);
+ return $TEMP_PREFIX . "DOMNode" if $codeGenerator->StripModule($dataNode->parents(0)) eq "EventTargetNode";
+ return GetClassName($codeGenerator->StripModule($dataNode->parents(0)));
+}
+
+sub AddForwardDeclarationsForTypeInIDL
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ return if $codeGenerator->IsNonPointerType($type) or $codeGenerator->IsStringType($type);
+
+ my $interface = GetInterfaceName($type);
+ $IDLForwardDeclarations{$interface} = 1;
+ $IDLImports{$interface} = 1;
+}
+
+sub AddIncludesForTypeInCPPHeader
+{
+ my $type = $codeGenerator->StripModule(shift);
+ my $useAngleBrackets = shift;
+
+ return if $codeGenerator->IsNonPointerType($type);
+
+ # Add special Cases HERE
+
+ if ($type =~ m/^I/) {
+ $type = "WebKit";
+ }
+
+ if ($useAngleBrackets) {
+ $CPPHeaderIncludesAngle{"$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "GEN_DOMImplementation") {
+ $CPPHeaderIncludes{"GEN_DOMDOMImplementation.h"} = 1;
+ return;
+ }
+
+ if ($type eq "IGEN_DOMImplementation") {
+ $CPPHeaderIncludes{"IGEN_DOMDOMImplementation.h"} = 1;
+ return;
+ }
+
+ $CPPHeaderIncludes{"$type.h"} = 1;
+}
+
+sub AddForwardDeclarationsForTypeInCPPHeader
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ return if $codeGenerator->IsNonPointerType($type) or $codeGenerator->IsStringType($type);
+
+ my $interface = GetInterfaceName($type);
+ $CPPHeaderForwardDeclarations{$interface} = 1;
+}
+
+sub AddIncludesForTypeInCPPImplementation
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ die "Include type not supported!" if $includeCorrector{$type};
+
+ return if $codeGenerator->IsNonPointerType($type);
+
+ if ($codeGenerator->IsStringType($type)) {
+ $CPPImplementationWebCoreIncludes{"AtomicString.h"} = 1;
+ $CPPImplementationWebCoreIncludes{"BString.h"} = 1;
+ $CPPImplementationWebCoreIncludes{"KURL.h"} = 1;
+ return;
+ }
+
+ # Special casing
+ $CPPImplementationWebCoreIncludes{"EventTargetNode.h"} = 1 if $type eq "Node";
+ $CPPImplementationWebCoreIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
+ $CPPImplementationWebCoreIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration";
+
+ # Add implementation type
+ $CPPImplementationWebCoreIncludes{StripNamespace(IDLTypeToImplementationType($type)) . ".h"} = 1;
+
+ my $COMClassName = GetClassName($type);
+ $CPPImplementationIncludes{"${COMClassName}.h"} = 1;
+}
+
+sub GetAdditionalInterfaces
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ return ("EventTarget") if $type eq "Node";
+ return ();
+}
+
+sub GenerateIDL
+{
+ my ($object, $dataNode, $pureInterface) = @_;
+
+ my $inInterfaceName = $dataNode->name;
+ my $outInterfaceName = GetInterfaceName($inInterfaceName);
+ my $uuid = $dataNode->extendedAttributes->{"InterfaceUUID"} || die "All classes require an InterfaceUUID extended attribute.";
+
+ my $parentInterfaceName = ($pureInterface) ? "IUnknown" : GetParentInterface($dataNode);
+
+ my $numConstants = @{$dataNode->constants};
+ my $numAttributes = @{$dataNode->attributes};
+ my $numFunctions = @{$dataNode->functions};
+
+ # - Add default header template
+ @IDLHeader = @licenseTemplate;
+ push(@IDLHeader, "\n");
+
+ # - INCLUDES -
+ push(@IDLHeader, "#ifndef DO_NO_IMPORTS\n");
+ push(@IDLHeader, "import \"oaidl.idl\";\n");
+ push(@IDLHeader, "import \"ocidl.idl\";\n");
+ push(@IDLHeader, "#endif\n\n");
+
+ unless ($pureInterface) {
+ push(@IDLHeader, "#ifndef DO_NO_IMPORTS\n");
+ push(@IDLHeader, "import \"${parentInterfaceName}.idl\";\n");
+ push(@IDLHeader, "#endif\n\n");
+
+ $IDLDontForwardDeclare{$outInterfaceName} = 1;
+ $IDLDontImport{$outInterfaceName} = 1;
+ $IDLDontForwardDeclare{$parentInterfaceName} = 1;
+ $IDLDontImport{$parentInterfaceName} = 1;
+ }
+
+ # - Begin
+ # -- Attributes
+ push(@IDLContent, "[\n");
+ push(@IDLContent, " object,\n");
+ push(@IDLContent, " oleautomation,\n");
+ push(@IDLContent, " uuid(" . $uuid . "),\n");
+ push(@IDLContent, " pointer_default(unique)\n");
+ push(@IDLContent, "]\n");
+
+ # -- Interface
+ push(@IDLContent, "interface " . $outInterfaceName . " : " . $parentInterfaceName . "\n");
+ push(@IDLContent, "{\n");
+
+
+ # - FIXME: Add constants.
+
+
+ # - Add attribute getters/setters.
+ if ($numAttributes > 0) {
+ foreach my $attribute (@{$dataNode->attributes}) {
+ my $attributeName = $attribute->signature->name;
+ my $attributeIDLType = $attribute->signature->type;
+ my $attributeTypeIn = GetCOMTypeIn($attributeIDLType);
+ my $attributeTypeOut = GetCOMTypeOut($attributeIDLType);
+ my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
+
+ AddForwardDeclarationsForTypeInIDL($attributeIDLType);
+
+ unless ($attributeIsReadonly) {
+ # Setter
+ my $setterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
+ my $setter = " HRESULT " . $setterName . "([in] " . $attributeTypeIn . ");\n";
+ push(@IDLContent, $setter);
+ }
+
+ # Getter
+ my $getter = " HRESULT " . $attributeName . "([out, retval] " . $attributeTypeOut . "*);\n\n";
+ push(@IDLContent, $getter);
+ }
+ }
+
+ # - Add functions.
+ if ($numFunctions > 0) {
+ foreach my $function (@{$dataNode->functions}) {
+ my $functionName = $function->signature->name;
+ my $returnIDLType = $function->signature->type;
+ my $returnType = GetCOMTypeOut($returnIDLType);
+ my $noReturn = ($returnType eq "void");
+
+ AddForwardDeclarationsForTypeInIDL($returnIDLType);
+
+ my @paramArgList = ();
+ foreach my $param (@{$function->parameters}) {
+ my $paramName = $param->name;
+ my $paramIDLType = $param->type;
+ my $paramType = GetCOMTypeIn($param->type);
+
+ AddForwardDeclarationsForTypeInIDL($paramIDLType);
+
+ # Form parameter
+ my $parameter = "[in] ${paramType} ${paramName}";
+
+ # Add parameter to function signature
+ push(@paramArgList, $parameter);
+ }
+
+ unless ($noReturn) {
+ my $resultParameter = "[out, retval] " . $returnType . "* result";
+ push(@paramArgList, $resultParameter);
+ }
+
+ my $functionSig = " HRESULT " . $functionName . "(";
+ $functionSig .= join(", ", @paramArgList);
+ $functionSig .= ");\n\n";
+ push(@IDLContent, $functionSig);
+ }
+ }
+
+ # - End
+ push(@IDLContent, "}\n\n");
+}
+
+sub GenerateInterfaceHeader
+{
+ my ($object, $dataNode) = @_;
+
+ my $IDLType = $dataNode->name;
+ my $implementationClass = IDLTypeToImplementationType($IDLType);
+ my $implementationClassWithoutNamespace = StripNamespace($implementationClass);
+ my $className = GetClassName($IDLType);
+ my $interfaceName = GetInterfaceName($IDLType);
+
+ # - Add default header template
+ @CPPInterfaceHeader = @licenseTemplate;
+ push(@CPPInterfaceHeader, "\n");
+
+ # - Header gaurds -
+ push(@CPPInterfaceHeader, "#ifndef " . $className . "_h\n");
+ push(@CPPInterfaceHeader, "#define " . $className . "_h\n\n");
+
+ # - Forward Declarations -
+ push(@CPPInterfaceHeader, "interface ${interfaceName};\n\n");
+ push(@CPPInterfaceHeader, "namespace WebCore {\n");
+ push(@CPPInterfaceHeader, " class ${implementationClassWithoutNamespace};\n");
+ push(@CPPInterfaceHeader, "}\n\n");
+
+ # - Default Interface Creator -
+ push(@CPPInterfaceHeader, "${interfaceName}* to${interfaceName}(${implementationClass}*) { return 0; }\n\n");
+
+ push(@CPPInterfaceHeader, "#endif // " . $className . "_h\n");
+}
+
+# -----------------------------------------------------------------------------
+# CPP Helper Functions
+# -----------------------------------------------------------------------------
+
+sub GenerateCPPAttributeSignature
+{
+ my ($attribute, $className, $options) = @_;
+
+ my $attributeName = $attribute->signature->name;
+ my $isReadonly = ($attribute->type =~ /^readonly/);
+
+ my $newline = $$options{"NewLines"} ? "\n" : "";
+ my $indent = $$options{"Indent"} ? " " x $$options{"Indent"} : "";
+ my $semicolon = $$options{"IncludeSemiColon"} ? ";" : "";
+ my $virtual = $$options{"AddVirtualKeyword"} ? "virtual " : "";
+ my $class = $$options{"UseClassName"} ? "${className}::" : "";
+ my $forwarder = $$options{"Forwarder"} ? 1 : 0;
+ my $joiner = ($$options{"NewLines"} ? "\n" . $indent . " " : "");
+
+ my %attributeSignatures = ();
+
+ unless ($isReadonly) {
+ my $attributeTypeIn = GetCOMTypeIn($attribute->signature->type);
+ my $setterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
+ my $setter = $indent . $virtual . "HRESULT STDMETHODCALLTYPE ". $class . $setterName . "(";
+ $setter .= $joiner . "/* [in] */ ${attributeTypeIn} ${attributeName})" . $semicolon . $newline;
+ if ($forwarder) {
+ $setter .= " { return " . $$options{"Forwarder"} . "::" . $setterName . "(${attributeName}); }\n";
+ }
+ $attributeSignatures{"Setter"} = $setter;
+ }
+
+ my $attributeTypeOut = GetCOMTypeOut($attribute->signature->type);
+ my $getter = $indent . $virtual . "HRESULT STDMETHODCALLTYPE " . $class . $attributeName . "(";
+ $getter .= $joiner . "/* [retval][out] */ ${attributeTypeOut}* result)" . $semicolon . $newline;
+ if ($forwarder) {
+ $getter .= " { return " . $$options{"Forwarder"} . "::" . $attributeName . "(result); }\n";
+ }
+ $attributeSignatures{"Getter"} = $getter;
+
+ return %attributeSignatures;
+}
+
+
+sub GenerateCPPAttribute
+{
+ my ($attribute, $className, $implementationClass) = @_;
+
+ my $implementationClassWithoutNamespace = StripNamespace($implementationClass);
+
+ my $attributeName = $attribute->signature->name;
+ my $attributeIDLType = $attribute->signature->type;
+ my $hasSetterException = @{$attribute->setterExceptions};
+ my $hasGetterException = @{$attribute->getterExceptions};
+ my $isReadonly = ($attribute->type =~ /^readonly/);
+ my $attributeTypeIsPrimitive = $codeGenerator->IsPrimitiveType($attributeIDLType);
+ my $attributeTypeIsString = $codeGenerator->IsStringType($attributeIDLType);
+ my $attributeImplementationType = IDLTypeToImplementationType($attributeIDLType);
+ my $attributeImplementationTypeWithoutNamespace = StripNamespace($attributeImplementationType);
+ my $attributeTypeCOMClassName = GetClassName($attributeIDLType);
+
+ $CPPImplementationWebCoreIncludes{"ExceptionCode.h"} = 1 if $hasSetterException or $hasGetterException;
+
+ my %signatures = GenerateCPPAttributeSignature($attribute, $className, { "NewLines" => 1,
+ "Indent" => 0,
+ "IncludeSemiColon" => 0,
+ "UseClassName" => 1,
+ "AddVirtualKeyword" => 0 });
+
+ my %attrbutesToReturn = ();
+
+ unless ($isReadonly) {
+ my @setterImplementation = ();
+ push(@setterImplementation, $signatures{"Setter"});
+ push(@setterImplementation, "{\n");
+
+ my $setterName = "set" . $codeGenerator->WK_ucfirst($attributeName);
+
+ my @setterParams = ();
+ if ($attributeTypeIsString) {
+ push(@setterParams, $attributeName);
+ if ($hasSetterException) {
+ push(@setterImplementation, " WebCore::ExceptionCode ec = 0;\n");
+ push(@setterParams, "ec");
+ }
+ } elsif ($attributeTypeIsPrimitive) {
+ if ($attribute->signature->extendedAttributes->{"ConvertFromString"}) {
+ push(@setterParams, "WebCore::String::number(${attributeName})");
+ } elsif ($attributeIDLType eq "boolean") {
+ push(@setterParams, "!!${attributeName}");
+ } else {
+ my $primitiveImplementationType = IDLTypeToImplementationType($attributeIDLType);
+ push(@setterParams, "static_cast<${primitiveImplementationType}>(${attributeName})");
+ }
+
+ if ($hasSetterException) {
+ push(@setterImplementation, " WebCore::ExceptionCode ec = 0;\n");
+ push(@setterParams, "ec");
+ }
+ } else {
+ $CPPImplementationWebCoreIncludes{"COMPtr.h"} = 1;
+
+ push(@setterImplementation, " if (!${attributeName})\n");
+ push(@setterImplementation, " return E_POINTER;\n\n");
+ push(@setterImplementation, " COMPtr<${attributeTypeCOMClassName}> ptr(Query, ${attributeName});\n");
+ push(@setterImplementation, " if (!ptr)\n");
+ push(@setterImplementation, " return E_NOINTERFACE;\n");
+
+ push(@setterParams, "ptr->impl${attributeImplementationTypeWithoutNamespace}()");
+ if ($hasSetterException) {
+ push(@setterImplementation, " WebCore::ExceptionCode ec = 0;\n");
+ push(@setterParams, "ec");
+ }
+ }
+
+ # FIXME: CHECK EXCEPTION AND DO SOMETHING WITH IT
+
+ my $setterCall = " impl${implementationClassWithoutNamespace}()->${setterName}(" . join(", ", @setterParams) . ");\n";
+
+ push(@setterImplementation, $setterCall);
+ push(@setterImplementation, " return S_OK;\n");
+ push(@setterImplementation, "}\n\n");
+
+ $attrbutesToReturn{"Setter"} = join("", @setterImplementation);
+ }
+
+ my @getterImplementation = ();
+ push(@getterImplementation, $signatures{"Getter"});
+ push(@getterImplementation, "{\n");
+ push(@getterImplementation, " if (!result)\n");
+ push(@getterImplementation, " return E_POINTER;\n\n");
+
+ my $implementationGetter = "impl${implementationClassWithoutNamespace}()->" . $codeGenerator->WK_lcfirst($attributeName) . "(" . ($hasGetterException ? "ec" : ""). ")";
+
+ push(@getterImplementation, " WebCore::ExceptionCode ec = 0;\n") if $hasGetterException;
+
+ if ($attributeTypeIsString) {
+ push(@getterImplementation, " *result = WebCore::BString(${implementationGetter}).release();\n");
+ } elsif ($attributeTypeIsPrimitive) {
+ if ($attribute->signature->extendedAttributes->{"ConvertFromString"}) {
+ push(@getterImplementation, " *result = static_cast<${attributeTypeCOMClassName}>(${implementationGetter}.toInt());\n");
+ } else {
+ push(@getterImplementation, " *result = static_cast<${attributeTypeCOMClassName}>(${implementationGetter});\n");
+ }
+ } else {
+ $CPPImplementationIncludesAngle{"wtf/GetPtr.h"} = 1;
+ my $attributeTypeCOMInterfaceName = GetInterfaceName($attributeIDLType);
+ push(@getterImplementation, " *result = 0;\n");
+ push(@getterImplementation, " ${attributeImplementationType}* resultImpl = WTF::getPtr(${implementationGetter});\n");
+ push(@getterImplementation, " if (!resultImpl)\n");
+ push(@getterImplementation, " return E_POINTER;\n\n");
+ push(@getterImplementation, " *result = to${attributeTypeCOMInterfaceName}(resultImpl);\n");
+ }
+
+ # FIXME: CHECK EXCEPTION AND DO SOMETHING WITH IT
+
+ push(@getterImplementation, " return S_OK;\n");
+ push(@getterImplementation, "}\n\n");
+
+ $attrbutesToReturn{"Getter"} = join("", @getterImplementation);
+
+ return %attrbutesToReturn;
+}
+
+sub GenerateCPPFunctionSignature
+{
+ my ($function, $className, $options) = @_;
+
+ my $functionName = $function->signature->name;
+ my $returnIDLType = $function->signature->type;
+ my $returnType = GetCOMTypeOut($returnIDLType);
+ my $noReturn = ($returnType eq "void");
+
+ my $newline = $$options{"NewLines"} ? "\n" : "";
+ my $indent = $$options{"Indent"} ? " " x $$options{"Indent"} : "";
+ my $semicolon = $$options{"IncludeSemiColon"} ? ";" : "";
+ my $virtual = $$options{"AddVirtualKeyword"} ? "virtual " : "";
+ my $class = $$options{"UseClassName"} ? "${className}::" : "";
+ my $forwarder = $$options{"Forwarder"} ? 1 : 0;
+ my $joiner = ($$options{"NewLines"} ? "\n" . $indent . " " : " ");
+
+ my @paramArgList = ();
+ foreach my $param (@{$function->parameters}) {
+ my $paramName = $param->name;
+ my $paramType = GetCOMTypeIn($param->type);
+ my $parameter = "/* [in] */ ${paramType} ${paramName}";
+ push(@paramArgList, $parameter);
+ }
+
+ unless ($noReturn) {
+ my $resultParameter .= "/* [out, retval] */ ${returnType}* result";
+ push(@paramArgList, $resultParameter);
+ }
+
+ my $functionSig = $indent . $virtual . "HRESULT STDMETHODCALLTYPE " . $class . $functionName . "(";
+ $functionSig .= $joiner . join("," . $joiner, @paramArgList) if @paramArgList > 0;
+ $functionSig .= ")" . $semicolon . $newline;
+ if ($forwarder) {
+ my @paramNameList = ();
+ push(@paramNameList, $_->name) foreach (@{$function->parameters});
+ push(@paramNameList, "result") unless $noReturn;
+ $functionSig .= " { return " . $$options{"Forwarder"} . "::" . $functionName . "(" . join(", ", @paramNameList) . "); }\n";
+ }
+
+ return $functionSig
+}
+
+sub GenerateCPPFunction
+{
+ my ($function, $className, $implementationClass) = @_;
+
+ my @functionImplementation = ();
+
+ my $signature = GenerateCPPFunctionSignature($function, $className, { "NewLines" => 1,
+ "Indent" => 0,
+ "IncludeSemiColon" => 0,
+ "UseClassName" => 1,
+ "AddVirtualKeyword" => 0 });
+
+ my $implementationClassWithoutNamespace = StripNamespace($implementationClass);
+
+ my $functionName = $function->signature->name;
+ my $returnIDLType = $function->signature->type;
+ my $noReturn = ($returnIDLType eq "void");
+ my $requiresEventTargetNodeCast = $function->signature->extendedAttributes->{"EventTargetNodeCast"};
+ my $raisesExceptions = @{$function->raisesExceptions};
+
+ AddIncludesForTypeInCPPImplementation($returnIDLType);
+ $CPPImplementationWebCoreIncludes{"ExceptionCode.h"} = 1 if $raisesExceptions;
+
+ my %needsCustom = ();
+ my @parameterInitialization = ();
+ my @parameterList = ();
+ foreach my $param (@{$function->parameters}) {
+ my $paramName = $param->name;
+ my $paramIDLType = $param->type;
+
+ my $paramTypeIsPrimitive = $codeGenerator->IsPrimitiveType($paramIDLType);
+ my $paramTypeIsString = $codeGenerator->IsStringType($paramIDLType);
+
+ $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"Return"};
+
+ AddIncludesForTypeInCPPImplementation($paramIDLType);
+
+ # FIXME: We may need to null check the arguments as well
+
+ if ($paramTypeIsString) {
+ push(@parameterList, $paramName);
+ } elsif ($paramTypeIsPrimitive) {
+ if ($paramIDLType eq "boolean") {
+ push(@parameterList, "!!${paramName}");
+ } else {
+ my $primitiveImplementationType = IDLTypeToImplementationType($paramIDLType);
+ push(@parameterList, "static_cast<${primitiveImplementationType}>(${paramName})");
+ }
+ } else {
+ $CPPImplementationWebCoreIncludes{"COMPtr.h"} = 1;
+
+ $needsCustom{"CanReturnEarly"} = 1;
+
+ my $paramTypeCOMClassName = GetClassName($paramIDLType);
+ my $paramTypeImplementationWithoutNamespace = StripNamespace(IDLTypeToImplementationType($paramIDLType));
+ my $ptrName = "ptrFor" . $codeGenerator->WK_ucfirst($paramName);
+ my $paramInit = " COMPtr<${paramTypeCOMClassName}> ${ptrName}(Query, ${paramName});\n";
+ $paramInit .= " if (!${ptrName})\n";
+ $paramInit .= " return E_NOINTERFACE;";
+ push(@parameterInitialization, $paramInit);
+ push(@parameterList, "${ptrName}->impl${paramTypeImplementationWithoutNamespace}()");
+ }
+ }
+
+ push(@parameterList, "ec") if $raisesExceptions;
+
+ my $implementationGetter = "impl${implementationClassWithoutNamespace}()";
+ if ($requiresEventTargetNodeCast) {
+ $implementationGetter = "WebCore::EventTargetNodeCast(${implementationGetter})";
+ }
+
+ my $callSigBegin = " ";
+ my $callSigMiddle = "${implementationGetter}->" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterList) . ")";
+ my $callSigEnd = ";\n";
+
+ if (defined $needsCustom{"NodeToReturn"}) {
+ my $nodeToReturn = $needsCustom{"NodeToReturn"};
+ $callSigBegin .= "if (";
+ $callSigEnd = ")\n";
+ $callSigEnd .= " *result = ${nodeToReturn};";
+ } elsif (!$noReturn) {
+ my $returnTypeIsString = $codeGenerator->IsStringType($returnIDLType);
+ my $returnTypeIsPrimitive = $codeGenerator->IsPrimitiveType($returnIDLType);
+
+ if ($returnTypeIsString) {
+ $callSigBegin .= "*result = WebCore::BString(";
+ $callSigEnd = ").release();\n";
+ } elsif ($returnTypeIsPrimitive) {
+ my $primitiveCOMType = GetClassName($returnIDLType);
+ $callSigBegin .= "*result = static_cast<${primitiveCOMType}>(";
+ $callSigEnd = ");";
+ } else {
+ $CPPImplementationIncludesAngle{"wtf/GetPtr.h"} = 1;
+ my $returnImplementationType = IDLTypeToImplementationType($returnIDLType);
+ my $returnTypeCOMInterfaceName = GetInterfaceName($returnIDLType);
+ $callSigBegin .= "${returnImplementationType}* resultImpl = WTF::getPtr(";
+ $callSigEnd = ");\n";
+ $callSigEnd .= " if (!resultImpl)\n";
+ $callSigEnd .= " return E_POINTER;\n\n";
+ $callSigEnd .= " *result = to${returnTypeCOMInterfaceName}(resultImpl);";
+ }
+ }
+
+ push(@functionImplementation, $signature);
+ push(@functionImplementation, "{\n");
+ unless ($noReturn) {
+ push(@functionImplementation, " if (!result)\n");
+ push(@functionImplementation, " return E_POINTER;\n\n");
+ push(@functionImplementation, " *result = 0;\n\n") if $needsCustom{"CanReturnEarly"};
+ }
+ push(@functionImplementation, " WebCore::ExceptionCode ec = 0;\n") if $raisesExceptions; # FIXME: CHECK EXCEPTION AND DO SOMETHING WITH IT
+ push(@functionImplementation, join("\n", @parameterInitialization) . (@parameterInitialization > 0 ? "\n" : ""));
+ if ($requiresEventTargetNodeCast) {
+ push(@functionImplementation, " if (!impl${implementationClassWithoutNamespace}()->isEventTargetNode())\n");
+ push(@functionImplementation, " return E_FAIL;\n");
+ }
+ push(@functionImplementation, $callSigBegin . $callSigMiddle . $callSigEnd . "\n");
+ push(@functionImplementation, " return S_OK;\n");
+ push(@functionImplementation, "}\n\n");
+
+ return join("", @functionImplementation);
+}
+
+
+# -----------------------------------------------------------------------------
+# CPP Header
+# -----------------------------------------------------------------------------
+
+sub GenerateCPPHeader
+{
+ my ($object, $dataNode) = @_;
+
+ my $IDLType = $dataNode->name;
+ my $implementationClass = IDLTypeToImplementationType($IDLType);
+ my $implementationClassWithoutNamespace = StripNamespace($implementationClass);
+ my $className = GetClassName($IDLType);
+ my $interfaceName = GetInterfaceName($IDLType);
+
+ my $parentClassName = GetParentClass($dataNode);
+ my @otherInterfacesImplemented = GetAdditionalInterfaces($IDLType);
+ foreach my $otherInterface (@otherInterfacesImplemented) {
+ push(@additionalInterfaceDefinitions, $codeGenerator->ParseInterface($otherInterface));
+ }
+
+ # FIXME: strip whitespace from UUID
+ my $uuid = $dataNode->extendedAttributes->{"ImplementationUUID"} || die "All classes require an ImplementationUUID extended attribute.";
+
+ my $numAttributes = @{$dataNode->attributes};
+ my $numFunctions = @{$dataNode->functions};
+
+ # - Add default header template
+ @CPPHeaderHeader = @licenseTemplate;
+ push(@CPPHeaderHeader, "\n");
+
+ # - Header gaurds -
+ push(@CPPHeaderHeader, "#ifndef " . $className . "_h\n");
+ push(@CPPHeaderHeader, "#define " . $className . "_h\n\n");
+
+ AddIncludesForTypeInCPPHeader($interfaceName);
+ AddIncludesForTypeInCPPHeader($parentClassName);
+ $CPPHeaderDontForwardDeclarations{$className} = 1;
+ $CPPHeaderDontForwardDeclarations{$interfaceName} = 1;
+ $CPPHeaderDontForwardDeclarations{$parentClassName} = 1;
+
+ # -- Forward declare implementation type
+ push(@CPPHeaderContent, "namespace WebCore {\n");
+ push(@CPPHeaderContent, " class ". StripNamespace($implementationClass) . ";\n");
+ push(@CPPHeaderContent, "}\n\n");
+
+ # -- Start Class --
+ my @parentsClasses = ($parentClassName, $interfaceName);
+ push(@parentsClasses, map { GetInterfaceName($_) } @otherInterfacesImplemented);
+ push(@CPPHeaderContent, "class __declspec(uuid(\"$uuid\")) ${className} : " . join(", ", map { "public $_" } @parentsClasses) . " {\n");
+
+ # Add includes for all additional interfaces to implement
+ map { AddIncludesForTypeInCPPHeader(GetInterfaceName($_)) } @otherInterfacesImplemented;
+
+ # -- BASICS --
+ # FIXME: The constructor and destructor should be protected, but the current design of
+ # createInstance requires them to be public. One solution is to friend the constructor
+ # of the top-level-class with every one of its child classes, but that requires information
+ # this script currently does not have, though possibly could determine.
+ push(@CPPHeaderContent, "public:\n");
+ push(@CPPHeaderContent, " ${className}(${implementationClass}*);\n");
+ push(@CPPHeaderContent, " virtual ~${className}();\n\n");
+
+ push(@CPPHeaderContent, "public:\n");
+ push(@CPPHeaderContent, " static ${className}* createInstance(${implementationClass}*);\n\n");
+
+ push(@CPPHeaderContent, " // IUnknown\n");
+ push(@CPPHeaderContent, " virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void** ppvObject);\n");
+ push(@CPPHeaderContent, " virtual ULONG STDMETHODCALLTYPE AddRef() { return ${parentClassName}::AddRef(); }\n");
+ push(@CPPHeaderContent, " virtual ULONG STDMETHODCALLTYPE Release() { return ${parentClassName}::Release(); }\n\n");
+
+
+ # -- Parent Class Forwards --
+ if (@{$dataNode->parents}) {
+ my %attributeNameSet = map {($_->signature->name, 1)} @{$dataNode->attributes};
+ my %functionNameSet = map {($_->signature->name, 1)} @{$dataNode->functions};
+
+ my @parentLists = $codeGenerator->GetMethodsAndAttributesFromParentClasses($dataNode);
+ push(@CPPHeaderContent, "\n");
+ foreach my $parentHash (@parentLists) {
+
+ push(@CPPHeaderContent, " // " . GetInterfaceName($parentHash->{'name'}) . $DASHES . "\n");
+
+ my @attributeList = @{$parentHash->{'attributes'}};
+ push(@CPPHeaderContent, " // Attributes\n");
+ foreach my $attribute (@attributeList) {
+ # Don't forward an attribute that this class redefines.
+ next if $attributeNameSet{$attribute->signature->name};
+
+ AddForwardDeclarationsForTypeInCPPHeader($attribute->signature->type);
+
+ my %attributes = GenerateCPPAttributeSignature($attribute, $className, { "NewLines" => 0,
+ "Indent" => 4,
+ "IncludeSemiColon" => 0,
+ "AddVirtualKeyword" => 1,
+ "UseClassName" => 0,
+ "Forwarder" => $parentClassName });
+ push(@CPPHeaderContent, values(%attributes));
+ }
+
+ # Add attribute names to attribute names set in case other ancestors
+ # also define them.
+ $attributeNameSet{$_->signature->name} = 1 foreach @attributeList;
+
+ push(@CPPHeaderContent, "\n");
+
+ my @functionList = @{$parentHash->{'functions'}};
+ push(@CPPHeaderContent, " // Functions\n");
+ foreach my $function (@functionList) {
+ # Don't forward a function that this class redefines.
+ next if $functionNameSet{$function->signature->name};
+
+ AddForwardDeclarationsForTypeInCPPHeader($function->signature->type);
+ AddForwardDeclarationsForTypeInCPPHeader($_->type) foreach (@{$function->parameters});
+
+ my $functionSig = GenerateCPPFunctionSignature($function, $className, { "NewLines" => 0,
+ "Indent" => 4,
+ "IncludeSemiColon" => 0,
+ "AddVirtualKeyword" => 1,
+ "UseClassName" => 0,
+ "Forwarder" => $parentClassName });
+
+ push(@CPPHeaderContent, $functionSig);
+ }
+ # Add functions names to functions names set in case other ancestors
+ # also define them.
+ $functionNameSet{$_->signature->name} = 1 foreach @functionList;
+
+ push(@CPPHeaderContent, "\n");
+ }
+ }
+
+ # - Additional interfaces to implement -
+ foreach my $interfaceToImplement (@additionalInterfaceDefinitions) {
+ my $IDLTypeOfInterfaceToImplement = $interfaceToImplement->name;
+ my $nameOfInterfaceToImplement = GetInterfaceName($IDLTypeOfInterfaceToImplement);
+ my $numAttributesInInterface = @{$interfaceToImplement->attributes};
+ my $numFunctionsInInterface = @{$interfaceToImplement->functions};
+
+ push(@CPPHeaderContent, " // ${nameOfInterfaceToImplement} ${DASHES}\n\n");
+
+ # - Add attribute getters/setters.
+ if ($numAttributesInInterface > 0) {
+ push(@CPPHeaderContent, " // Attributes\n\n");
+ foreach my $attribute (@{$interfaceToImplement->attributes}) {
+ AddForwardDeclarationsForTypeInCPPHeader($attribute->signature->type);
+
+ my %attributeSigs = GenerateCPPAttributeSignature($attribute, $className, { "NewLines" => 1,
+ "Indent" => 4,
+ "IncludeSemiColon" => 1,
+ "AddVirtualKeyword" => 1,
+ "UseClassName" => 0 });
+
+ push(@CPPHeaderContent, values(%attributeSigs));
+ push(@CPPHeaderContent, "\n");
+ }
+ }
+
+ # - Add functions.
+ if ($numFunctionsInInterface > 0) {
+ push(@CPPHeaderContent, " // Functions\n\n");
+ foreach my $function (@{$interfaceToImplement->functions}) {
+ AddForwardDeclarationsForTypeInCPPHeader($function->signature->type);
+ AddForwardDeclarationsForTypeInCPPHeader($_->type) foreach (@{$function->parameters});
+
+ my $functionSig = GenerateCPPFunctionSignature($function, $className, { "NewLines" => 1,
+ "Indent" => 4,
+ "IncludeSemiColon" => 1,
+ "AddVirtualKeyword" => 1,
+ "UseClassName" => 0 });
+
+ push(@CPPHeaderContent, $functionSig);
+ push(@CPPHeaderContent, "\n");
+ }
+ }
+ }
+
+ if ($numAttributes > 0 || $numFunctions > 0) {
+ push(@CPPHeaderContent, " // ${interfaceName} ${DASHES}\n\n");
+ }
+
+ # - Add constants COMING SOON
+
+ # - Add attribute getters/setters.
+ if ($numAttributes > 0) {
+ push(@CPPHeaderContent, " // Attributes\n\n");
+ foreach my $attribute (@{$dataNode->attributes}) {
+ AddForwardDeclarationsForTypeInCPPHeader($attribute->signature->type);
+
+ my %attributeSigs = GenerateCPPAttributeSignature($attribute, $className, { "NewLines" => 1,
+ "Indent" => 4,
+ "IncludeSemiColon" => 1,
+ "AddVirtualKeyword" => 1,
+ "UseClassName" => 0 });
+
+ push(@CPPHeaderContent, values(%attributeSigs));
+ push(@CPPHeaderContent, "\n");
+ }
+ }
+
+ # - Add functions.
+ if ($numFunctions > 0) {
+ push(@CPPHeaderContent, " // Functions\n\n");
+ foreach my $function (@{$dataNode->functions}) {
+ AddForwardDeclarationsForTypeInCPPHeader($function->signature->type);
+ AddForwardDeclarationsForTypeInCPPHeader($_->type) foreach (@{$function->parameters});
+
+ my $functionSig = GenerateCPPFunctionSignature($function, $className, { "NewLines" => 1,
+ "Indent" => 4,
+ "IncludeSemiColon" => 1,
+ "AddVirtualKeyword" => 1,
+ "UseClassName" => 0 });
+
+ push(@CPPHeaderContent, $functionSig);
+ push(@CPPHeaderContent, "\n");
+ }
+ }
+
+ push(@CPPHeaderContent, " ${implementationClass}* impl${implementationClassWithoutNamespace}() const;\n");
+
+ if (@{$dataNode->parents} == 0) {
+ AddIncludesForTypeInCPPHeader("wtf/RefPtr", 1);
+ push(@CPPHeaderContent, "\n");
+ push(@CPPHeaderContent, " ${implementationClass}* impl() const { return m_impl.get(); }\n\n");
+ push(@CPPHeaderContent, "private:\n");
+ push(@CPPHeaderContent, " RefPtr<${implementationClass}> m_impl;\n");
+ }
+
+ # -- End Class --
+ push(@CPPHeaderContent, "};\n\n");
+
+ # -- Default Interface Creator --
+ push(@CPPHeaderContent, "${interfaceName}* to${interfaceName}(${implementationClass}*);\n\n");
+
+ push(@CPPHeaderContent, "#endif // " . $className . "_h\n");
+}
+
+
+# -----------------------------------------------------------------------------
+# CPP Implementation
+# -----------------------------------------------------------------------------
+
+sub GenerateCPPImplementation
+{
+ my ($object, $dataNode) = @_;
+
+ my $IDLType = $dataNode->name;
+ my $implementationClass = IDLTypeToImplementationType($IDLType);
+ my $implementationClassWithoutNamespace = StripNamespace($implementationClass);
+ my $className = GetClassName($IDLType);
+ my $interfaceName = GetInterfaceName($IDLType);
+
+ my $parentClassName = GetParentClass($dataNode);
+ my $isBaseClass = (@{$dataNode->parents} == 0);
+
+ my $uuid = $dataNode->extendedAttributes->{"ImplementationUUID"} || die "All classes require an ImplementationUUID extended attribute.";
+
+ my $numAttributes = @{$dataNode->attributes};
+ my $numFunctions = @{$dataNode->functions};
+
+ # - Add default header template
+ @CPPImplementationHeader = @licenseTemplate;
+ push(@CPPImplementationHeader, "\n");
+
+ push(@CPPImplementationHeader, "#include \"config.h\"\n");
+ push(@CPPImplementationHeader, "#include \"WebKitDLL.h\"\n");
+ push(@CPPImplementationHeader, "#include " . ($className eq "GEN_DOMImplementation" ? "\"GEN_DOMDOMImplementation.h\"" : "\"${className}.h\"") . "\n");
+ $CPPImplementationDontIncludes{"${className}.h"} = 1;
+ $CPPImplementationWebCoreIncludes{"${implementationClassWithoutNamespace}.h"} = 1;
+
+ # -- Constructor --
+ push(@CPPImplementationContent, "${className}::${className}(${implementationClass}* impl)\n");
+ if ($isBaseClass) {
+ push(@CPPImplementationContent, " : m_impl(impl)\n");
+ push(@CPPImplementationContent, "{\n");
+ push(@CPPImplementationContent, " ASSERT_ARG(impl, impl);\n");
+ push(@CPPImplementationContent, "}\n\n");
+ } else {
+ push(@CPPImplementationContent, " : ${parentClassName}(impl)\n");
+ push(@CPPImplementationContent, "{\n");
+ push(@CPPImplementationContent, "}\n\n");
+ }
+
+ # -- Destructor --
+ push(@CPPImplementationContent, "${className}::~${className}()\n");
+ push(@CPPImplementationContent, "{\n");
+ if ($isBaseClass) {
+ $CPPImplementationIncludes{"DOMCreateInstance.h"} = 1;
+ push(@CPPImplementationContent, " removeDOMWrapper(impl());\n");
+ }
+ push(@CPPImplementationContent, "}\n\n");
+
+ push(@CPPImplementationContent, "${implementationClass}* ${className}::impl${implementationClassWithoutNamespace}() const\n");
+ push(@CPPImplementationContent, "{\n");
+ push(@CPPImplementationContent, " return static_cast<${implementationClass}*>(impl());\n");
+ push(@CPPImplementationContent, "}\n\n");
+
+ # Base classes must implement the createInstance method externally.
+ if (@{$dataNode->parents} != 0) {
+ push(@CPPImplementationContent, "${className}* ${className}::createInstance(${implementationClass}* impl)\n");
+ push(@CPPImplementationContent, "{\n");
+ push(@CPPImplementationContent, " return static_cast<${className}*>(${parentClassName}::createInstance(impl));\n");
+ push(@CPPImplementationContent, "}\n");
+ }
+
+ push(@CPPImplementationContent, "// IUnknown $DASHES\n\n");
+
+ # -- QueryInterface --
+ push(@CPPImplementationContent, "HRESULT STDMETHODCALLTYPE ${className}::QueryInterface(REFIID riid, void** ppvObject)\n");
+ push(@CPPImplementationContent, "{\n");
+ push(@CPPImplementationContent, " *ppvObject = 0;\n");
+ push(@CPPImplementationContent, " if (IsEqualGUID(riid, IID_${interfaceName}))\n");
+ push(@CPPImplementationContent, " *ppvObject = reinterpret_cast<${interfaceName}*>(this);\n");
+ push(@CPPImplementationContent, " else if (IsEqualGUID(riid, __uuidof(${className})))\n");
+ push(@CPPImplementationContent, " *ppvObject = reinterpret_cast<${className}*>(this);\n");
+ push(@CPPImplementationContent, " else\n");
+ push(@CPPImplementationContent, " return ${parentClassName}::QueryInterface(riid, ppvObject);\n\n");
+ push(@CPPImplementationContent, " AddRef();\n");
+ push(@CPPImplementationContent, " return S_OK;\n");
+ push(@CPPImplementationContent, "}\n\n");
+
+ # - Additional interfaces to implement -
+ foreach my $interfaceToImplement (@additionalInterfaceDefinitions) {
+ my $IDLTypeOfInterfaceToImplement = $interfaceToImplement->name;
+ my $nameOfInterfaceToImplement = GetInterfaceName($IDLTypeOfInterfaceToImplement);
+ my $numAttributesInInterface = @{$interfaceToImplement->attributes};
+ my $numFunctionsInInterface = @{$interfaceToImplement->functions};
+
+ push(@CPPImplementationContent, " // ${nameOfInterfaceToImplement} ${DASHES}\n\n");
+
+ if ($numAttributesInInterface > 0) {
+ push(@CPPImplementationContent, "// Attributes\n\n");
+ foreach my $attribute (@{$interfaceToImplement->attributes}) {
+ # FIXME: Do this in one step.
+ # FIXME: Implement exception handling.
+
+ AddIncludesForTypeInCPPImplementation($attribute->signature->type);
+
+ my %attributes = GenerateCPPAttribute($attribute, $className, $implementationClass);
+ push(@CPPImplementationContent, values(%attributes));
+ }
+ }
+
+ # - Add functions.
+ if ($numFunctionsInInterface > 0) {
+ push(@CPPImplementationContent, "// Functions\n\n");
+
+ foreach my $function (@{$interfaceToImplement->functions}) {
+ my $functionImplementation = GenerateCPPFunction($function, $className, $implementationClass);
+ push(@CPPImplementationContent, $functionImplementation);
+ }
+ }
+ }
+
+ push(@CPPImplementationContent, "// ${interfaceName} $DASHES\n\n");
+
+ # - Add attribute getters/setters.
+ if ($numAttributes > 0) {
+ push(@CPPImplementationContent, "// Attributes\n\n");
+ foreach my $attribute (@{$dataNode->attributes}) {
+ # FIXME: do this in one step
+ my $hasSetterException = @{$attribute->setterExceptions};
+ my $hasGetterException = @{$attribute->getterExceptions};
+
+ AddIncludesForTypeInCPPImplementation($attribute->signature->type);
+
+ my %attributes = GenerateCPPAttribute($attribute, $className, $implementationClass);
+ push(@CPPImplementationContent, values(%attributes));
+ }
+ }
+
+ # - Add functions.
+ if ($numFunctions > 0) {
+ push(@CPPImplementationContent, "// Functions\n\n");
+
+ foreach my $function (@{$dataNode->functions}) {
+ my $functionImplementation = GenerateCPPFunction($function, $className, $implementationClass);
+ push(@CPPImplementationContent, $functionImplementation);
+ }
+ }
+
+ # - Default implementation for interface creator.
+ # FIXME: add extended attribute to add custom implementation if necessary.
+ push(@CPPImplementationContent, "${interfaceName}* to${interfaceName}(${implementationClass}* impl)\n");
+ push(@CPPImplementationContent, "{\n");
+ push(@CPPImplementationContent, " return ${className}::createInstance(impl);\n");
+ push(@CPPImplementationContent, "}\n");
+}
+
+sub WriteData
+{
+ my ($object, $name, $pureInterface) = @_;
+
+ # -- IDL --
+ my $IDLFileName = "$outputDir/I" . $TEMP_PREFIX . "DOM" . $name . ".idl";
+ unlink($IDLFileName);
+
+ # Write to output IDL.
+ open(OUTPUTIDL, ">$IDLFileName") or die "Couldn't open file $IDLFileName";
+
+ # Add header
+ print OUTPUTIDL @IDLHeader;
+
+ # Add forward declarations and imorts
+ delete $IDLForwardDeclarations{keys(%IDLDontForwardDeclare)};
+ delete $IDLImports{keys(%IDLDontImport)};
+
+ print OUTPUTIDL map { "cpp_quote(\"interface $_;\")\n" } sort keys(%IDLForwardDeclarations);
+ print OUTPUTIDL "\n";
+
+ print OUTPUTIDL map { "interface $_;\n" } sort keys(%IDLForwardDeclarations);
+ print OUTPUTIDL "\n";
+ print OUTPUTIDL "#ifndef DO_NO_IMPORTS\n";
+ print OUTPUTIDL map { ($_ eq "IGEN_DOMImplementation") ? "import \"IGEN_DOMDOMImplementation.idl\";\n" : "import \"$_.idl\";\n" } sort keys(%IDLImports);
+ print OUTPUTIDL "#endif\n";
+ print OUTPUTIDL "\n";
+
+ # Add content
+ print OUTPUTIDL @IDLContent;
+
+ close(OUTPUTIDL);
+
+ @IDLHeader = ();
+ @IDLContent = ();
+
+ if ($pureInterface) {
+ my $CPPInterfaceHeaderFileName = "$outputDir/" . $TEMP_PREFIX . "DOM" . $name . ".h";
+ unlink($CPPInterfaceHeaderFileName);
+
+ open(OUTPUTCPPInterfaceHeader, ">$CPPInterfaceHeaderFileName") or die "Couldn't open file $CPPInterfaceHeaderFileName";
+
+ print OUTPUTCPPInterfaceHeader @CPPInterfaceHeader;
+
+ close(OUTPUTCPPInterfaceHeader);
+
+ @CPPInterfaceHeader = ();
+ } else {
+ my $CPPHeaderFileName = "$outputDir/" . $TEMP_PREFIX . "DOM" . $name . ".h";
+ unlink($CPPHeaderFileName);
+
+ # -- CPP Header --
+ open(OUTPUTCPPHeader, ">$CPPHeaderFileName") or die "Couldn't open file $CPPHeaderFileName";
+
+ # Add header
+ print OUTPUTCPPHeader @CPPHeaderHeader;
+
+ # Add includes
+ print OUTPUTCPPHeader map { ($_ eq "GEN_DOMImplementation.h") ? "#include \"GEN_DOMDOMImplementation.h\"\n" : "#include \"$_\"\n" } sort keys(%CPPHeaderIncludes);
+ print OUTPUTCPPHeader map { "#include <$_>\n" } sort keys(%CPPHeaderIncludesAngle);
+
+ foreach my $dontDeclare (keys(%CPPHeaderDontForwardDeclarations)) {
+ delete $CPPHeaderForwardDeclarations{$dontDeclare} if ($CPPHeaderForwardDeclarations{$dontDeclare});
+ }
+ print OUTPUTCPPHeader "\n";
+ print OUTPUTCPPHeader map { "interface $_;\n" } sort keys(%CPPHeaderForwardDeclarations);
+ print OUTPUTCPPHeader "\n";
+
+ # Add content
+ print OUTPUTCPPHeader @CPPHeaderContent;
+
+ close(OUTPUTCPPHeader);
+
+ @CPPHeaderHeader = ();
+ @CPPHeaderContent = ();
+
+
+ # -- CPP Implementation --
+ my $CPPImplementationFileName = "$outputDir/" . $TEMP_PREFIX . "DOM" . $name . ".cpp";
+ unlink($CPPImplementationFileName);
+
+ open(OUTPUTCPPImplementation, ">$CPPImplementationFileName") or die "Couldn't open file $CPPImplementationFileName";
+
+ # Add header
+ print OUTPUTCPPImplementation @CPPImplementationHeader;
+ print OUTPUTCPPImplementation "\n";
+
+ # Add includes
+ foreach my $dontInclude (keys(%CPPImplementationDontIncludes)) {
+ delete $CPPImplementationIncludes{$dontInclude} if ($CPPImplementationIncludes{$dontInclude});
+ }
+ print OUTPUTCPPImplementation map { ($_ eq "GEN_DOMImplementation.h") ? "#include \"GEN_DOMDOMImplementation.h\"\n" : "#include \"$_\"\n" } sort keys(%CPPImplementationIncludes);
+ print OUTPUTCPPImplementation map { "#include <$_>\n" } sort keys(%CPPImplementationIncludesAngle);
+ print OUTPUTCPPImplementation "\n";
+
+ print OUTPUTCPPImplementation "#pragma warning(push, 0)\n";
+ print OUTPUTCPPImplementation map { "#include <WebCore/$_>\n" } sort keys(%CPPImplementationWebCoreIncludes);
+ print OUTPUTCPPImplementation "#pragma warning(pop)\n";
+
+ # Add content
+ print OUTPUTCPPImplementation @CPPImplementationContent;
+
+ close(OUTPUTCPPImplementation);
+
+ @CPPImplementationHeader = ();
+ @CPPImplementationContent = ();
+ }
+}
+
+1;
diff --git a/WebCore/bindings/scripts/CodeGeneratorJS.pm b/WebCore/bindings/scripts/CodeGeneratorJS.pm
new file mode 100644
index 0000000..2568b0d
--- /dev/null
+++ b/WebCore/bindings/scripts/CodeGeneratorJS.pm
@@ -0,0 +1,1864 @@
+#
+# Copyright (C) 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org>
+# Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
+# Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
+# Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
+# Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# aint with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+
+package CodeGeneratorJS;
+
+use File::stat;
+
+my $module = "";
+my $outputDir = "";
+
+my @headerContent = ();
+my @implContentHeader = ();
+my @implContent = ();
+my %implIncludes = ();
+
+# Default .h template
+my $headerTemplate = << "EOF";
+/*
+ This file is part of the WebKit open source project.
+ This file has been generated by generate-bindings.pl. DO NOT MODIFY!
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; see the file COPYING.LIB. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301, USA.
+*/
+EOF
+
+# Default constructor
+sub new
+{
+ my $object = shift;
+ my $reference = { };
+
+ $codeGenerator = shift;
+ $outputDir = shift;
+
+ bless($reference, $object);
+ return $reference;
+}
+
+sub finish
+{
+ my $object = shift;
+
+ # Commit changes!
+ $object->WriteData();
+}
+
+sub leftShift($$) {
+ my ($value, $distance) = @_;
+ return (($value << $distance) & 0xFFFFFFFF);
+}
+
+# Params: 'domClass' struct
+sub GenerateInterface
+{
+ my $object = shift;
+ my $dataNode = shift;
+ my $defines = shift;
+
+ # Start actual generation
+ $object->GenerateHeader($dataNode);
+ $object->GenerateImplementation($dataNode);
+
+ my $name = $dataNode->name;
+
+ # Open files for writing
+ my $headerFileName = "$outputDir/JS$name.h";
+ my $implFileName = "$outputDir/JS$name.cpp";
+
+ open($IMPL, ">$implFileName") || die "Couldn't open file $implFileName";
+ open($HEADER, ">$headerFileName") || die "Couldn't open file $headerFileName";
+}
+
+# Params: 'idlDocument' struct
+sub GenerateModule
+{
+ my $object = shift;
+ my $dataNode = shift;
+
+ $module = $dataNode->module;
+}
+
+sub GetParentClassName
+{
+ my $dataNode = shift;
+
+ return $dataNode->extendedAttributes->{"LegacyParent"} if $dataNode->extendedAttributes->{"LegacyParent"};
+ return "DOMObject" if @{$dataNode->parents} eq 0;
+ return "JS" . $codeGenerator->StripModule($dataNode->parents(0));
+}
+
+sub GetLegacyHeaderIncludes
+{
+ my $legacyParent = shift;
+
+ return "#include \"JSHTMLInputElementBase.h\"\n\n" if $legacyParent eq "JSHTMLInputElementBase";
+ return "#include \"kjs_window.h\"\n\n" if $legacyParent eq "KJS::Window";
+ return "#include \"kjs_events.h\"\n\n" if $module eq "events";
+ return "#include \"kjs_css.h\"\n\n" if $module eq "css";
+ return "#include \"kjs_html.h\"\n\n" if $module eq "html";
+
+ die "Don't know what headers to include for module $module";
+}
+
+sub GetVisibleClassName
+{
+ my $className = shift;
+
+ return "DOMException" if $className eq "DOMCoreException";
+ return $className;
+}
+
+sub AvoidInclusionOfType
+{
+ my $type = shift;
+
+ # Special case: SVGRect.h / SVGPoint.h / SVGNumber.h / SVGMatrix.h do not exist.
+ return 1 if $type eq "SVGRect" or $type eq "SVGPoint" or $type eq "SVGNumber" or $type eq "SVGMatrix";
+ return 0;
+}
+
+sub UsesManualToJSImplementation
+{
+ my $type = shift;
+
+ return 1 if $type eq "Node" or $type eq "Document" or $type eq "HTMLCollection" or $type eq "SVGPathSeg" or $type eq "StyleSheet" or $type eq "CSSRule" or $type eq "CSSValue" or $type eq "Event" or $type eq "CanvasPixelArray";
+ return 0;
+}
+
+sub IndexGetterReturnsStrings
+{
+ my $type = shift;
+
+ return 1 if $type eq "CSSStyleDeclaration" or $type eq "MediaList";
+ return 0;
+}
+
+sub CreateSVGContextInterfaceName
+{
+ my $type = shift;
+
+ return $type if $codeGenerator->IsSVGAnimatedType($type);
+ return "SVGPathSeg" if $type =~ /^SVGPathSeg/ and $type ne "SVGPathSegList";
+
+ return "";
+}
+
+sub AddIncludesForType
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ # When we're finished with the one-file-per-class
+ # reorganization, we won't need these special cases.
+ if ($codeGenerator->IsPrimitiveType($type) or AvoidInclusionOfType($type)
+ or $type eq "DOMString" or $type eq "DOMObject" or $type eq "RGBColor") {
+ } elsif ($type =~ /SVGPathSeg/) {
+ $joinedName = $type;
+ $joinedName =~ s/Abs|Rel//;
+ $implIncludes{"${joinedName}.h"} = 1;
+ } elsif ($type eq "XPathNSResolver") {
+ $implIncludes{"JSXPathNSResolver.h"} = 1;
+ $implIncludes{"JSCustomXPathNSResolver.h"} = 1;
+ } else {
+ # default, include the same named file
+ $implIncludes{"${type}.h"} = 1;
+ }
+
+ # additional includes (things needed to compile the bindings but not the header)
+
+ if ($type eq "CanvasRenderingContext2D") {
+ $implIncludes{"CanvasGradient.h"} = 1;
+ $implIncludes{"CanvasPattern.h"} = 1;
+ $implIncludes{"CanvasStyle.h"} = 1;
+ }
+
+ if ($type eq "CanvasGradient" or $type eq "XPathNSResolver") {
+ $implIncludes{"PlatformString.h"} = 1;
+ }
+
+ if ($type eq "Document") {
+ $implIncludes{"NodeFilter.h"} = 1;
+ }
+}
+
+sub AddIncludesForSVGAnimatedType
+{
+ my $type = shift;
+ $type =~ s/SVGAnimated//;
+
+ if ($type eq "Point" or $type eq "Rect") {
+ $implIncludes{"Float$type.h"} = 1;
+ } elsif ($type eq "String") {
+ $implIncludes{"PlatformString.h"} = 1;
+ }
+}
+
+sub AddClassForwardIfNeeded
+{
+ my $implClassName = shift;
+
+ # SVGAnimatedLength/Number/etc.. are typedefs to SVGAnimtatedTemplate, so don't use class forwards for them!
+ push(@headerContent, "class $implClassName;\n\n") unless $codeGenerator->IsSVGAnimatedType($implClassName);
+}
+
+sub IsSVGTypeNeedingContextParameter
+{
+ my $implClassName = shift;
+
+ if ($implClassName =~ /SVG/ and not $implClassName =~ /Element/) {
+ return 1 unless $implClassName =~ /SVGPaint/ or $implClassName =~ /SVGColor/ or $implClassName =~ /SVGDocument/;
+ }
+
+ return 0;
+}
+
+sub HashValueForClassAndName
+{
+ my $class = shift;
+ my $name = shift;
+
+ # SVG Filter enums live in WebCore namespace (platform/graphics/)
+ if ($class =~ /^SVGFE*/ or $class =~ /^SVGComponentTransferFunctionElement$/) {
+ return "WebCore::$name";
+ }
+
+ return "${class}::$name";
+}
+
+sub GenerateHeader
+{
+ my $object = shift;
+ my $dataNode = shift;
+
+ my $interfaceName = $dataNode->name;
+ my $className = "JS$interfaceName";
+ my $implClassName = $interfaceName;
+
+ # We only support multiple parents with SVG (for now).
+ if (@{$dataNode->parents} > 1) {
+ die "A class can't have more than one parent" unless $interfaceName =~ /SVG/;
+ $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode);
+ }
+
+ my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};
+ my $hasRealParent = @{$dataNode->parents} > 0;
+ my $hasParent = $hasLegacyParent || $hasRealParent;
+ my $parentClassName = GetParentClassName($dataNode);
+ my $conditional = $dataNode->extendedAttributes->{"Conditional"};
+
+ # - Add default header template
+ @headerContent = split("\r", $headerTemplate);
+
+ # - Add header protection
+ push(@headerContent, "\n#ifndef $className" . "_H");
+ push(@headerContent, "\n#define $className" . "_H\n\n");
+
+ my $conditionalString;
+ if ($conditional) {
+ $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
+ push(@headerContent, "\n#if ${conditionalString}\n\n");
+ }
+
+ if (exists $dataNode->extendedAttributes->{"LegacyParent"}) {
+ push(@headerContent, GetLegacyHeaderIncludes($dataNode->extendedAttributes->{"LegacyParent"}));
+ } else {
+ if ($hasParent) {
+ push(@headerContent, "#include \"$parentClassName.h\"\n");
+ } else {
+ push(@headerContent, "#include \"kjs_binding.h\"\n");
+ push(@headerContent, "#include <kjs/JSGlobalObject.h>\n");
+ push(@headerContent, "#include <kjs/object_object.h>\n");
+ }
+ }
+
+ # Get correct pass/store types respecting PODType flag
+ my $podType = $dataNode->extendedAttributes->{"PODType"};
+ my $passType = $podType ? "JSSVGPODTypeWrapper<$podType>*" : "$implClassName*";
+ push(@headerContent, "#include \"$podType.h\"\n") if $podType and $podType ne "float";
+
+ push(@headerContent, "#include \"JSSVGPODTypeWrapper.h\"\n") if $podType;
+
+ my $numConstants = @{$dataNode->constants};
+ my $numAttributes = @{$dataNode->attributes};
+ my $numFunctions = @{$dataNode->functions};
+
+ push(@headerContent, "\nnamespace WebCore {\n\n");
+
+ # Implementation class forward declaration
+ AddClassForwardIfNeeded($implClassName) unless $podType;
+
+ # Class declaration
+ push(@headerContent, "class $className : public $parentClassName {\n");
+ push(@headerContent, " typedef $parentClassName Base;\n");
+ push(@headerContent, "public:\n");
+
+ # Constructor
+ if ($dataNode->extendedAttributes->{"DoNotCache"}) {
+ push(@headerContent, " $className($passType);\n");
+ } else {
+ push(@headerContent, " $className(KJS::JSObject* prototype, $passType" . (IsSVGTypeNeedingContextParameter($implClassName) ? ", SVGElement* context" : "") .");\n");
+ }
+
+ # Destructor
+ push(@headerContent, " virtual ~$className();\n") if (!$hasParent or $interfaceName eq "Document");
+
+ my $hasGetter = $numAttributes > 0
+ || $dataNode->extendedAttributes->{"GenerateConstructor"}
+ || $dataNode->extendedAttributes->{"HasIndexGetter"}
+ || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}
+ || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"}
+ || $dataNode->extendedAttributes->{"HasNameGetter"}
+ || $dataNode->extendedAttributes->{"HasOverridingNameGetter"};
+
+ # Getters
+ if ($hasGetter) {
+ push(@headerContent, " virtual bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier& propertyName, KJS::PropertySlot&);\n");
+ push(@headerContent, " virtual bool getOwnPropertySlot(KJS::ExecState*, unsigned propertyName, KJS::PropertySlot&);\n") if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) && !$dataNode->extendedAttributes->{"HasOverridingNameGetter"};
+ push(@headerContent, " KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;\n") if $numAttributes > 0 || $dataNode->extendedAttributes->{"GenerateConstructor"};
+ push(@headerContent, " bool customGetOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);\n") if $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"};
+ }
+
+ # Check if we have any writable properties
+ my $hasReadWriteProperties = 0;
+ foreach (@{$dataNode->attributes}) {
+ if ($_->type !~ /^readonly\ attribute$/) {
+ $hasReadWriteProperties = 1;
+ }
+ }
+
+ my $hasSetter = $hasReadWriteProperties
+ || $dataNode->extendedAttributes->{"CustomPutFunction"}
+ || $dataNode->extendedAttributes->{"HasCustomIndexSetter"};
+
+ # Getters
+ if ($hasSetter) {
+ push(@headerContent, " virtual void put(KJS::ExecState*, const KJS::Identifier& propertyName, KJS::JSValue*);\n");
+ push(@headerContent, " virtual void put(KJS::ExecState*, unsigned propertyName, KJS::JSValue*);\n") if $dataNode->extendedAttributes->{"HasCustomIndexSetter"};
+ push(@headerContent, " void putValueProperty(KJS::ExecState*, int, KJS::JSValue*);\n") if $hasReadWriteProperties;
+ push(@headerContent, " bool customPut(KJS::ExecState*, const KJS::Identifier&, KJS::JSValue*);\n") if $dataNode->extendedAttributes->{"CustomPutFunction"};
+ }
+
+ # Class info
+ push(@headerContent, " virtual const KJS::ClassInfo* classInfo() const { return &info; }\n");
+ push(@headerContent, " static const KJS::ClassInfo info;\n\n");
+
+ # Custom mark function
+ push(@headerContent, " virtual void mark();\n\n") if $dataNode->extendedAttributes->{"CustomMarkFunction"};
+
+ # Custom pushEventHandlerScope function
+ push(@headerContent, " virtual void pushEventHandlerScope(KJS::ExecState*, KJS::ScopeChain&) const;\n\n") if $dataNode->extendedAttributes->{"CustomPushEventHandlerScope"};
+
+ # Custom call functions
+ if ($dataNode->extendedAttributes->{"CustomCall"}) {
+ push(@headerContent, " virtual KJS::JSValue* callAsFunction(KJS::ExecState*, KJS::JSObject*, const KJS::List&);\n");
+ push(@headerContent, " virtual bool implementsCall() const;\n\n");
+ }
+
+ # Custom deleteProperty function
+ push(@headerContent, " virtual bool deleteProperty(KJS::ExecState*, const KJS::Identifier&);\n") if $dataNode->extendedAttributes->{"CustomDeleteProperty"};
+
+ # Custom getPropertyNames function
+ push(@headerContent, " virtual void getPropertyNames(KJS::ExecState*, KJS::PropertyNameArray&);\n") if ($dataNode->extendedAttributes->{"CustomGetPropertyNames"} || $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"});
+ push(@headerContent, " bool customGetPropertyNames(KJS::ExecState*, KJS::PropertyNameArray&);\n") if $dataNode->extendedAttributes->{"CustomGetPropertyNames"};
+
+ # Constructor object getter
+ push(@headerContent, " static KJS::JSValue* getConstructor(KJS::ExecState*);\n") if $dataNode->extendedAttributes->{"GenerateConstructor"};
+
+ my $numCustomFunctions = 0;
+ my $numCustomAttributes = 0;
+
+ # Attribute and function enums
+ my $hasAttrEnum = ($numAttributes > 0) || $dataNode->extendedAttributes->{"GenerateConstructor"};
+ push(@headerContent, " enum {\n") if ($hasAttrEnum);
+
+ if ($numAttributes > 0) {
+ push(@headerContent, " // Attributes\n ");
+
+ my $i = -1;
+ foreach (@{$dataNode->attributes}) {
+ my $attribute = $_;
+
+ $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"Custom"};
+ $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"CustomGetter"};
+ $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"CustomSetter"};
+
+ $i++;
+ if ((($i % 4) eq 0) and ($i ne 0)) {
+ push(@headerContent, "\n ");
+ }
+
+ my $value = $codeGenerator->WK_ucfirst($attribute->signature->name)
+ . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "")
+ . "AttrNum";
+ $value .= ", " if (($i < $numAttributes - 1) or (($i eq $numAttributes - 1) and (($numFunctions ne 0) or $dataNode->extendedAttributes->{"GenerateConstructor"})));
+ push(@headerContent, $value);
+ }
+ }
+
+ if ($dataNode->extendedAttributes->{"GenerateConstructor"}) {
+ push(@headerContent, "\n\n") if $numAttributes > 0;
+ push(@headerContent, " // The Constructor Attribute\n");
+ push(@headerContent, " ConstructorAttrNum");
+ }
+
+ push(@headerContent, "\n };\n") if ($hasAttrEnum);
+
+ if ($numCustomAttributes > 0) {
+ push(@headerContent, "\n // Custom attributes\n");
+
+ foreach my $attribute (@{$dataNode->attributes}) {
+ if ($attribute->signature->extendedAttributes->{"Custom"}) {
+ push(@headerContent, " KJS::JSValue* " . $codeGenerator->WK_lcfirst($attribute->signature->name) . "(KJS::ExecState*) const;\n");
+ if ($attribute->type !~ /^readonly/) {
+ push(@headerContent, " void set" . $codeGenerator->WK_ucfirst($attribute->signature->name) . "(KJS::ExecState*, KJS::JSValue*);\n");
+ }
+ } elsif ($attribute->signature->extendedAttributes->{"CustomGetter"}) {
+ push(@headerContent, " KJS::JSValue* " . $codeGenerator->WK_lcfirst($attribute->signature->name) . "(KJS::ExecState*) const;\n");
+ } elsif ($attribute->signature->extendedAttributes->{"CustomSetter"}) {
+ if ($attribute->type !~ /^readonly/) {
+ push(@headerContent, " void set" . $codeGenerator->WK_ucfirst($attribute->signature->name) . "(KJS::ExecState*, KJS::JSValue*);\n");
+ }
+ }
+ }
+ }
+
+ foreach my $function (@{$dataNode->functions}) {
+ $numCustomFunctions++ if $function->signature->extendedAttributes->{"Custom"};
+ }
+
+ if ($numCustomFunctions > 0) {
+ push(@headerContent, "\n // Custom functions\n");
+ foreach my $function (@{$dataNode->functions}) {
+ if ($function->signature->extendedAttributes->{"Custom"}) {
+ push(@headerContent, " KJS::JSValue* " . $codeGenerator->WK_lcfirst($function->signature->name) . "(KJS::ExecState*, const KJS::List&);\n");
+ }
+ }
+ }
+
+ if (!$hasParent) {
+ if ($podType) {
+ push(@headerContent, " JSSVGPODTypeWrapper<$podType>* impl() const { return m_impl.get(); }\n");
+ push(@headerContent, " SVGElement* context() const { return m_context.get(); }\n\n");
+ push(@headerContent, "private:\n");
+ push(@headerContent, " RefPtr<SVGElement> m_context;\n");
+ push(@headerContent, " RefPtr<JSSVGPODTypeWrapper<$podType> > m_impl;\n");
+ } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
+ push(@headerContent, " $implClassName* impl() const { return m_impl.get(); }\n");
+ push(@headerContent, " SVGElement* context() const { return m_context.get(); }\n\n");
+ push(@headerContent, "private:\n");
+ push(@headerContent, " RefPtr<SVGElement> m_context;\n");
+ push(@headerContent, " RefPtr<$implClassName > m_impl;\n");
+ } else {
+ push(@headerContent, " $implClassName* impl() const { return m_impl.get(); }\n\n");
+ push(@headerContent, "private:\n");
+ push(@headerContent, " RefPtr<$implClassName> m_impl;\n");
+ }
+ } elsif ($dataNode->extendedAttributes->{"GenerateNativeConverter"}) {
+ push(@headerContent, " $implClassName* impl() const;\n");
+ }
+
+ # Index getter
+ if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) {
+ push(@headerContent, " static KJS::JSValue* indexGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);\n");
+ }
+
+ # Index setter
+ if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
+ push(@headerContent, " void indexSetter(KJS::ExecState*, unsigned index, KJS::JSValue*);\n");
+ }
+ # Name getter
+ if ($dataNode->extendedAttributes->{"HasNameGetter"} || $dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
+ push(@headerContent, "private:\n");
+ push(@headerContent, " static bool canGetItemsForName(KJS::ExecState*, $implClassName*, const KJS::Identifier&);\n");
+ push(@headerContent, " static KJS::JSValue* nameGetter(KJS::ExecState*, KJS::JSObject*, const KJS::Identifier&, const KJS::PropertySlot&);\n");
+ }
+
+ push(@headerContent, "};\n\n");
+
+ if (!$hasParent || $dataNode->extendedAttributes->{"GenerateToJS"}) {
+ if ($podType) {
+ push(@headerContent, "KJS::JSValue* toJS(KJS::ExecState*, JSSVGPODTypeWrapper<$podType>*, SVGElement* context);\n");
+ } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
+ push(@headerContent, "KJS::JSValue* toJS(KJS::ExecState*, $passType, SVGElement* context);\n");
+ } elsif ($interfaceName eq "Node") {
+ push(@headerContent, "KJS::JSValue* toJS(KJS::ExecState*, PassRefPtr<Node>);\n");
+ } else {
+ push(@headerContent, "KJS::JSValue* toJS(KJS::ExecState*, $passType);\n");
+ }
+ }
+ if (!$hasParent || $dataNode->extendedAttributes->{"GenerateNativeConverter"}) {
+ if ($podType) {
+ push(@headerContent, "$podType to${interfaceName}(KJS::JSValue*);\n");
+ } else {
+ push(@headerContent, "$implClassName* to${interfaceName}(KJS::JSValue*);\n");
+ }
+ }
+ push(@headerContent, "\n");
+
+ # Add prototype declaration -- code adopted from the KJS_DEFINE_PROTOTYPE and KJS_DEFINE_PROTOTYPE_WITH_PROTOTYPE macros
+ push(@headerContent, "class ${className}Prototype : public KJS::JSObject {\n");
+ push(@headerContent, "public:\n");
+ if ($dataNode->extendedAttributes->{"DoNotCache"}) {
+ push(@headerContent, " static KJS::JSObject* self();\n");
+ } else {
+ push(@headerContent, " static KJS::JSObject* self(KJS::ExecState* exec);\n");
+ }
+ push(@headerContent, " virtual const KJS::ClassInfo* classInfo() const { return &info; }\n");
+ push(@headerContent, " static const KJS::ClassInfo info;\n");
+ if ($numFunctions > 0 || $numConstants > 0) {
+ push(@headerContent, " bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&);\n");
+ }
+ if ($numConstants ne 0) {
+ push(@headerContent, " KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const;\n");
+ }
+ if ($dataNode->extendedAttributes->{"DoNotCache"}) {
+ push(@headerContent, " ${className}Prototype() { }\n");
+ } else {
+ push(@headerContent, " ${className}Prototype(KJS::ExecState* exec)\n");
+ if ($hasParent && $parentClassName ne "KJS::DOMNodeFilter") {
+ push(@headerContent, " : KJS::JSObject(${parentClassName}Prototype::self(exec)) { }\n");
+ } else {
+ push(@headerContent, " : KJS::JSObject(exec->lexicalGlobalObject()->objectPrototype()) { }\n");
+ }
+ }
+
+ push(@headerContent, "};\n\n");
+
+ if ($numFunctions > 0) {
+ push(@headerContent,"// Functions\n\n");
+ foreach my $function (@{$dataNode->functions}) {
+ my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
+ push(@headerContent, "KJS::JSValue* ${functionName}(KJS::ExecState*, KJS::JSObject*, const KJS::List&);\n");
+ }
+ }
+
+ push(@headerContent, "} // namespace WebCore\n\n");
+ push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditional;
+ push(@headerContent, "#endif\n");
+}
+
+sub GenerateImplementation
+{
+ my ($object, $dataNode) = @_;
+
+ my $interfaceName = $dataNode->name;
+ my $className = "JS$interfaceName";
+ my $implClassName = $interfaceName;
+
+ my $hasLegacyParent = $dataNode->extendedAttributes->{"LegacyParent"};
+ my $hasRealParent = @{$dataNode->parents} > 0;
+ my $hasParent = $hasLegacyParent || $hasRealParent;
+ my $parentClassName = GetParentClassName($dataNode);
+ my $conditional = $dataNode->extendedAttributes->{"Conditional"};
+ my $visibleClassName = GetVisibleClassName($interfaceName);
+
+ # - Add default header template
+ @implContentHeader = split("\r", $headerTemplate);
+ push(@implContentHeader, "\n#include \"config.h\"\n\n");
+ my $conditionalString;
+ if ($conditional) {
+ $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
+ push(@implContentHeader, "\n#if ${conditionalString}\n\n");
+ }
+
+ if ($className =~ /^JSSVG/) {
+ push(@implContentHeader, "#include \"Document.h\"\n");
+ push(@implContentHeader, "#include \"Frame.h\"\n");
+ push(@implContentHeader, "#include \"SVGDocumentExtensions.h\"\n");
+ push(@implContentHeader, "#include \"SVGElement.h\"\n");
+ push(@implContentHeader, "#include \"SVGAnimatedTemplate.h\"\n");
+
+ if ($className =~ /^JSSVGAnimated/) {
+ AddIncludesForSVGAnimatedType($interfaceName);
+ }
+ }
+
+ push(@implContentHeader, "#include \"$className.h\"\n\n");
+ push(@implContentHeader, "#include <wtf/GetPtr.h>\n\n");
+
+ push(@implContentHeader, "#include <kjs/PropertyNameArray.h>\n") if $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"};
+
+ AddIncludesForType($interfaceName);
+
+ @implContent = ();
+
+ push(@implContent, "\nusing namespace KJS;\n\n");
+ push(@implContent, "namespace WebCore {\n\n");
+
+ # - Add all attributes in a hashtable definition
+ my $numAttributes = @{$dataNode->attributes};
+ $numAttributes++ if $dataNode->extendedAttributes->{"GenerateConstructor"};
+
+ if ($numAttributes > 0) {
+ my $hashSize = $numAttributes;
+ my $hashName = $className . "Table";
+
+ my @hashKeys = (); # ie. 'insertBefore'
+ my @hashValues = (); # ie. 'JSNode::InsertBefore'
+ my @hashSpecials = (); # ie. 'DontDelete|Function'
+ my @hashParameters = (); # ie. '2'
+
+ foreach my $attribute (@{$dataNode->attributes}) {
+ my $name = $attribute->signature->name;
+ push(@hashKeys, $name);
+
+ my $value = $className . "::" . $codeGenerator->WK_ucfirst($attribute->signature->name)
+ . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "")
+ . "AttrNum";
+ push(@hashValues, $value);
+
+ my @specials = ();
+ push(@specials, "DontDelete") unless $attribute->signature->extendedAttributes->{"Deletable"};
+ push(@specials, "DontEnum") if $attribute->signature->extendedAttributes->{"DontEnum"};
+ push(@specials, "ReadOnly") if $attribute->type =~ /readonly/;
+ my $special = (@specials > 0) ? join("|", @specials) : "0";
+ push(@hashSpecials, $special);
+
+ my $numParameters = "0";
+ push(@hashParameters, $numParameters);
+ }
+
+ if ($dataNode->extendedAttributes->{"GenerateConstructor"}) {
+ push(@hashKeys, "constructor");
+ push(@hashValues, $className . "::ConstructorAttrNum");
+ push(@hashSpecials, "DontEnum");
+ push(@hashParameters, "0");
+ }
+
+ $object->GenerateHashTable($hashName, $hashSize,
+ \@hashKeys, \@hashValues,
+ \@hashSpecials, \@hashParameters);
+ }
+
+ my $numConstants = @{$dataNode->constants};
+ my $numFunctions = @{$dataNode->functions};
+
+ # - Add all constants
+ if ($dataNode->extendedAttributes->{"GenerateConstructor"}) {
+ $hashSize = $numConstants;
+ $hashName = $className . "ConstructorTable";
+
+ @hashKeys = ();
+ @hashValues = ();
+ @hashSpecials = ();
+ @hashParameters = ();
+
+ foreach my $constant (@{$dataNode->constants}) {
+ my $name = $constant->name;
+ push(@hashKeys, $name);
+
+ my $value = $constant->value;
+ push(@hashValues, $value);
+
+ my $special = "DontDelete|ReadOnly";
+ push(@hashSpecials, $special);
+
+ my $numParameters = 0;
+ push(@hashParameters, $numParameters);
+ }
+
+ $object->GenerateHashTable($hashName, $hashSize,
+ \@hashKeys, \@hashValues,
+ \@hashSpecials, \@hashParameters);
+
+ my $protoClassName;
+ $protoClassName = "${className}Prototype";
+
+ push(@implContent, constructorFor($className, $protoClassName, $interfaceName, $visibleClassName, $dataNode->extendedAttributes->{"CanBeConstructed"}));
+ }
+
+ # - Add functions and constants to a hashtable definition
+ $hashSize = $numFunctions + $numConstants;
+ $hashName = $className . "PrototypeTable";
+
+ @hashKeys = ();
+ @hashValues = ();
+ @hashSpecials = ();
+ @hashParameters = ();
+
+ foreach my $constant (@{$dataNode->constants}) {
+ my $name = $constant->name;
+ push(@hashKeys, $name);
+
+ my $value = $constant->value;
+ push(@hashValues, $value);
+
+ my $special = "DontDelete|ReadOnly";
+ push(@hashSpecials, $special);
+
+ my $numParameters = 0;
+ push(@hashParameters, $numParameters);
+ }
+
+ foreach my $function (@{$dataNode->functions}) {
+ my $name = $function->signature->name;
+ push(@hashKeys, $name);
+
+ my $value = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($name);
+ push(@hashValues, $value);
+
+ my @specials = ();
+ push(@specials, "DontDelete") unless $function->signature->extendedAttributes->{"Deletable"};
+ push(@specials, "DontEnum") if $function->signature->extendedAttributes->{"DontEnum"};
+ push(@specials, "Function");
+ my $special = (@specials > 0) ? join("|", @specials) : "0";
+ push(@hashSpecials, $special);
+
+ my $numParameters = @{$function->parameters};
+ push(@hashParameters, $numParameters);
+ }
+
+ $object->GenerateHashTable($hashName, $hashSize,
+ \@hashKeys, \@hashValues,
+ \@hashSpecials, \@hashParameters);
+
+ push(@implContent, "const ClassInfo ${className}Prototype::info = { \"${visibleClassName}Prototype\", 0, &${className}PrototypeTable };\n\n");
+ if ($dataNode->extendedAttributes->{"DoNotCache"}) {
+ push(@implContent, "JSObject* ${className}Prototype::self()\n");
+ push(@implContent, "{\n");
+ push(@implContent, " return new ${className}Prototype();\n");
+ push(@implContent, "}\n\n");
+ } else {
+ push(@implContent, "JSObject* ${className}Prototype::self(ExecState* exec)\n");
+ push(@implContent, "{\n");
+ push(@implContent, " return KJS::cacheGlobalObject<${className}Prototype>(exec, \"[[${className}.prototype]]\");\n");
+ push(@implContent, "}\n\n");
+ }
+ if ($numConstants > 0 || $numFunctions > 0) {
+ push(@implContent, "bool ${className}Prototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)\n");
+ push(@implContent, "{\n");
+ if ($numConstants eq 0) {
+ push(@implContent, " return getStaticFunctionSlot<JSObject>(exec, &${className}PrototypeTable, this, propertyName, slot);\n");
+ } elsif ($numFunctions eq 0) {
+ push(@implContent, " return getStaticValueSlot<${className}Prototype, JSObject>(exec, &${className}PrototypeTable, this, propertyName, slot);\n");
+ } else {
+ push(@implContent, " return getStaticPropertySlot<${className}Prototype, JSObject>(exec, &${className}PrototypeTable, this, propertyName, slot);\n");
+ }
+ push(@implContent, "}\n\n");
+ }
+ if ($numConstants ne 0) {
+ push(@implContent, "JSValue* ${className}Prototype::getValueProperty(ExecState*, int token) const\n{\n");
+ push(@implContent, " // The token is the numeric value of its associated constant\n");
+ push(@implContent, " return jsNumber(token);\n}\n\n");
+ }
+
+ # - Initialize static ClassInfo object
+ push(@implContent, "const ClassInfo $className" . "::info = { \"${visibleClassName}\", ");
+ if ($hasParent) {
+ push(@implContent, "&" . $parentClassName . "::info, ");
+ } else {
+ push(@implContent, "0, ");
+ }
+
+ if ($numAttributes > 0) {
+ push(@implContent, "&${className}Table ");
+ } else {
+ push(@implContent, "0 ")
+ }
+ push(@implContent, "};\n\n");
+
+ # Get correct pass/store types respecting PODType flag
+ my $podType = $dataNode->extendedAttributes->{"PODType"};
+ my $passType = $podType ? "JSSVGPODTypeWrapper<$podType>*" : "$implClassName*";
+
+ my $needsSVGContext = IsSVGTypeNeedingContextParameter($implClassName);
+ my $parentNeedsSVGContext = ($needsSVGContext and $parentClassName =~ /SVG/);
+
+ # Constructor
+ if ($dataNode->extendedAttributes->{"DoNotCache"}) {
+ push(@implContent, "${className}::$className($passType impl)\n");
+ push(@implContent, " : $parentClassName(${className}Prototype::self(), impl)\n");
+ } else {
+ push(@implContent, "${className}::$className(JSObject* prototype, $passType impl" . ($needsSVGContext ? ", SVGElement* context" : "") . ")\n");
+ if ($hasParent) {
+ push(@implContent, " : $parentClassName(prototype, impl" . ($parentNeedsSVGContext ? ", context" : "") . ")\n");
+ } else {
+ push(@implContent, " : $parentClassName(prototype)\n");
+ push(@implContent, " , m_context(context)\n") if $needsSVGContext;
+ push(@implContent, " , m_impl(impl)\n");
+ }
+
+ }
+ push(@implContent, "{\n");
+ push(@implContent, "}\n\n");
+
+ # Destructor
+ if (!$hasParent) {
+ push(@implContent, "${className}::~$className()\n");
+ push(@implContent, "{\n");
+
+ if ($interfaceName eq "Node") {
+ push(@implContent, " ScriptInterpreter::forgetDOMNodeForDocument(m_impl->document(), m_impl.get());\n");
+ } else {
+ if ($podType) {
+ my $animatedType = $implClassName;
+ $animatedType =~ s/SVG/SVGAnimated/;
+
+ # Special case for JSSVGNumber
+ if ($codeGenerator->IsSVGAnimatedType($animatedType) and $podType ne "float") {
+ push(@implContent, " JSSVGPODTypeWrapperCache<$podType, $animatedType>::forgetWrapper(m_impl.get());\n");
+ }
+ }
+ push(@implContent, " ScriptInterpreter::forgetDOMObject(m_impl.get());\n");
+ }
+
+ push(@implContent, "\n}\n\n");
+ }
+
+ # Document needs a special destructor because it's a special case for caching. It needs
+ # its own special handling rather than relying on the caching that Node normally does.
+ if ($interfaceName eq "Document") {
+ push(@implContent, "${className}::~$className()\n");
+ push(@implContent, "{\n ScriptInterpreter::forgetDOMObject(static_cast<${implClassName}*>(impl()));\n}\n\n");
+ }
+
+ my $hasGetter = $numAttributes > 0
+ || $dataNode->extendedAttributes->{"GenerateConstructor"}
+ || $dataNode->extendedAttributes->{"HasIndexGetter"}
+ || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}
+ || $dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"}
+ || $dataNode->extendedAttributes->{"HasNameGetter"}
+ || $dataNode->extendedAttributes->{"HasOverridingNameGetter"};
+
+ # Attributes
+ if ($hasGetter) {
+ push(@implContent, "bool ${className}::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)\n");
+ push(@implContent, "{\n");
+
+ if ($interfaceName eq "NamedNodeMap" or $interfaceName eq "HTMLCollection") {
+ push(@implContent, " JSValue* proto = prototype();\n");
+ push(@implContent, " if (proto->isObject() && static_cast<JSObject*>(proto)->hasProperty(exec, propertyName))\n");
+ push(@implContent, " return false;\n\n");
+ }
+
+ my $hasNameGetterGeneration = sub {
+ push(@implContent, " if (canGetItemsForName(exec, static_cast<$implClassName*>(impl()), propertyName)) {\n");
+ push(@implContent, " slot.setCustom(this, nameGetter);\n");
+ push(@implContent, " return true;\n");
+ push(@implContent, " }\n");
+ $implIncludes{"AtomicString.h"} = 1;
+ };
+
+ if ($dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
+ &$hasNameGetterGeneration();
+ }
+
+ my $requiresManualLookup = $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasNameGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"};
+ if ($requiresManualLookup) {
+ push(@implContent, " const HashEntry* entry = Lookup::findEntry(&${className}Table, propertyName);\n");
+ push(@implContent, " if (entry) {\n");
+ push(@implContent, " slot.setStaticEntry(this, entry, staticValueGetter<$className>);\n");
+ push(@implContent, " return true;\n");
+ push(@implContent, " }\n");
+ }
+
+ if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) {
+ push(@implContent, " bool ok;\n");
+ push(@implContent, " unsigned index = propertyName.toUInt32(&ok, false);\n");
+ push(@implContent, " if (ok && index < static_cast<$implClassName*>(impl())->length()) {\n");
+ push(@implContent, " slot.setCustomIndex(this, index, indexGetter);\n");
+ push(@implContent, " return true;\n");
+ push(@implContent, " }\n");
+ }
+
+ if ($dataNode->extendedAttributes->{"HasNameGetter"}) {
+ &$hasNameGetterGeneration();
+ }
+
+ if ($dataNode->extendedAttributes->{"CustomGetOwnPropertySlot"}) {
+ push(@implContent, " if (customGetOwnPropertySlot(exec, propertyName, slot))\n");
+ push(@implContent, " return true;\n");
+ }
+
+ if ($numAttributes > 0) {
+ push(@implContent, " return getStaticValueSlot<$className, Base>(exec, &${className}Table, this, propertyName, slot);\n");
+ } else {
+ push(@implContent, " return Base::getOwnPropertySlot(exec, propertyName, slot);\n");
+ }
+ push(@implContent, "}\n\n");
+
+ if (($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"})
+ && !$dataNode->extendedAttributes->{"HasOverridingNameGetter"}) {
+ push(@implContent, "bool ${className}::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)\n");
+ push(@implContent, "{\n");
+ push(@implContent, " if (propertyName < static_cast<$implClassName*>(impl())->length()) {\n");
+ push(@implContent, " slot.setCustomIndex(this, propertyName, indexGetter);\n");
+ push(@implContent, " return true;\n");
+ push(@implContent, " }\n");
+ push(@implContent, " return getOwnPropertySlot(exec, Identifier::from(propertyName), slot);\n");
+ push(@implContent, "}\n\n");
+ }
+
+ if ($numAttributes > 0) {
+ push(@implContent, "JSValue* ${className}::getValueProperty(ExecState* exec, int token) const\n");
+ push(@implContent, "{\n");
+
+ push(@implContent, " switch (token) {\n");
+
+ foreach my $attribute (@{$dataNode->attributes}) {
+ my $getterFunctionName = $codeGenerator->WK_lcfirst($attribute->signature->name);
+
+ my $implClassNameForValueConversion = "";
+ if (!$podType and ($codeGenerator->IsSVGAnimatedType($implClassName) or $attribute->type !~ /^readonly/)) {
+ $implClassNameForValueConversion = $implClassName;
+ }
+
+ push(@implContent, " case " . $codeGenerator->WK_ucfirst($attribute->signature->name)
+ . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "")
+ . "AttrNum: {\n");
+
+ if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} &&
+ !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurity"} &&
+ !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurityOnGet"}) {
+ push(@implContent, " if (!allowsAccessFrom(exec))\n");
+ push(@implContent, " return jsUndefined();\n");
+ }
+
+ if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"CustomGetter"}) {
+ push(@implContent, " return $getterFunctionName(exec);\n");
+ } elsif ($attribute->signature->extendedAttributes->{"CheckNodeSecurity"}) {
+ $implIncludes{"kjs_dom.h"} = 1;
+ push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(impl());\n");
+ push(@implContent, " return checkNodeSecurity(exec, imp->$getterFunctionName()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$getterFunctionName()") . " : jsUndefined();\n");
+ } elsif ($attribute->signature->extendedAttributes->{"CheckFrameSecurity"}) {
+ $implIncludes{"Document.h"} = 1;
+ $implIncludes{"kjs_dom.h"} = 1;
+ push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(impl());\n");
+ push(@implContent, " return checkNodeSecurity(exec, imp->contentDocument()) ? " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$getterFunctionName()") . " : jsUndefined();\n");
+ } elsif ($attribute->signature->type =~ /Constructor$/) {
+ my $constructorType = $codeGenerator->StripModule($attribute->signature->type);
+ $constructorType =~ s/Constructor$//;
+ push(@implContent, " return JS" . $constructorType . "::getConstructor(exec);\n");
+ } elsif (!@{$attribute->getterExceptions}) {
+ if ($podType) {
+ push(@implContent, " $podType imp(*impl());\n");
+ if ($podType eq "float") { # Special case for JSSVGNumber
+ push(@implContent, " return " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp") . ";\n");
+ } else {
+ push(@implContent, " return " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp.$getterFunctionName()") . ";\n");
+ }
+ } else {
+ push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(impl());\n");
+ my $type = $codeGenerator->StripModule($attribute->signature->type);
+ my $jsType = NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$getterFunctionName()");
+ if ($codeGenerator->IsSVGAnimatedType($type)) {
+ push(@implContent, " RefPtr<$type> obj = $jsType;\n");
+ push(@implContent, " return toJS(exec, obj.get(), imp);\n");
+ } else {
+ push(@implContent, " return $jsType;\n");
+ }
+ }
+ } else {
+ push(@implContent, " ExceptionCode ec = 0;\n");
+
+ if ($podType) {
+ push(@implContent, " $podType imp(*impl());\n");
+ push(@implContent, " KJS::JSValue* result = " . NativeToJSValue($attribute->signature, 0, $implClassName, "", "imp.$getterFunctionName(ec)") . ";\n");
+ } else {
+ push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(impl());\n");
+ push(@implContent, " KJS::JSValue* result = " . NativeToJSValue($attribute->signature, 0, $implClassName, $implClassNameForValueConversion, "imp->$getterFunctionName(ec)") . ";\n");
+ }
+
+ push(@implContent, " setDOMException(exec, ec);\n");
+ push(@implContent, " return result;\n");
+ }
+ push(@implContent, " }\n");
+ }
+
+ if ($dataNode->extendedAttributes->{"GenerateConstructor"}) {
+ push(@implContent, " case ConstructorAttrNum:\n");
+ push(@implContent, " return getConstructor(exec);\n");
+ }
+
+ push(@implContent, " }\n");
+ push(@implContent, " return 0;\n");
+ push(@implContent, "}\n\n");
+ }
+
+ # Check if we have any writable attributes
+ my $hasReadWriteProperties = 0;
+ foreach my $attribute (@{$dataNode->attributes}) {
+ $hasReadWriteProperties = 1 if $attribute->type !~ /^readonly/;
+ }
+
+ my $hasSetter = $hasReadWriteProperties
+ || $dataNode->extendedAttributes->{"CustomPutFunction"}
+ || $dataNode->extendedAttributes->{"HasCustomIndexSetter"};
+
+ if ($hasSetter) {
+ push(@implContent, "void ${className}::put(ExecState* exec, const Identifier& propertyName, JSValue* value)\n");
+ push(@implContent, "{\n");
+ if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
+ push(@implContent, " bool ok;\n");
+ push(@implContent, " unsigned index = propertyName.toUInt32(&ok, false);\n");
+ push(@implContent, " if (ok) {\n");
+ push(@implContent, " indexSetter(exec, index, value);\n");
+ push(@implContent, " return;\n");
+ push(@implContent, " }\n");
+ }
+ if ($dataNode->extendedAttributes->{"CustomPutFunction"}) {
+ push(@implContent, " if (customPut(exec, propertyName, value))\n");
+ push(@implContent, " return;\n");
+ }
+
+ if ($hasReadWriteProperties) {
+ push(@implContent, " lookupPut<$className, Base>(exec, propertyName, value, &${className}Table, this);\n");
+ } else {
+ push(@implContent, " Base::put(exec, propertyName, value);\n");
+ }
+ push(@implContent, "}\n\n");
+
+ if ($dataNode->extendedAttributes->{"HasCustomIndexSetter"}) {
+ push(@implContent, "void ${className}::put(ExecState* exec, unsigned propertyName, JSValue* value)\n");
+ push(@implContent, "{\n");
+ push(@implContent, " indexSetter(exec, propertyName, value);\n");
+ push(@implContent, " return;\n");
+ push(@implContent, "}\n\n");
+ }
+
+ if ($hasReadWriteProperties) {
+ push(@implContent, "void ${className}::putValueProperty(ExecState* exec, int token, JSValue* value)\n");
+ push(@implContent, "{\n");
+
+ push(@implContent, " switch (token) {\n");
+
+ foreach my $attribute (@{$dataNode->attributes}) {
+ if ($attribute->type !~ /^readonly/) {
+ my $name = $attribute->signature->name;
+ my $setterFunctionName = $codeGenerator->WK_ucfirst($name);
+
+ push(@implContent, " case " . $codeGenerator->WK_ucfirst($attribute->signature->name)
+ . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : "")
+ . "AttrNum: {\n");
+
+ if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
+ if ($interfaceName eq "DOMWindow") {
+ push(@implContent, " if (!allowsAccessFrom(exec))\n");
+ } else {
+ push(@implContent, " if (!allowsAccessFromFrame(exec, impl()->frame()))\n");
+ }
+ push(@implContent, " return;\n");
+ }
+
+ if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"CustomSetter"}) {
+ push(@implContent, " set$setterFunctionName(exec, value);\n");
+ } elsif ($attribute->signature->type =~ /Constructor$/) {
+ my $constructorType = $attribute->signature->type;
+ $constructorType =~ s/Constructor$//;
+ $implIncludes{"JS" . $constructorType . ".h"} = 1;
+ push(@implContent, " // Shadowing a built-in constructor\n");
+ push(@implContent, " putDirect(\"$name\", value);\n");
+ } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) {
+ push(@implContent, " putDirect(\"$name\", value);\n");
+ } else {
+ if ($podType) {
+ push(@implContent, " $podType imp(*impl());\n");
+ if ($podType eq "float") { # Special case for JSSVGNumber
+ push(@implContent, " imp = " . JSValueToNative($attribute->signature, "value") . ";\n");
+ } else {
+ push(@implContent, " imp.set$setterFunctionName(" . JSValueToNative($attribute->signature, "value") . ");\n");
+ }
+ push(@implContent, " m_impl->commitChange(imp, context());\n");
+ } else {
+ push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(impl());\n");
+ push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions};
+ push(@implContent, " imp->set$setterFunctionName(" . JSValueToNative($attribute->signature, "value"));
+ push(@implContent, ", ec") if @{$attribute->setterExceptions};
+ push(@implContent, ");\n");
+ push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions};
+
+ if (IsSVGTypeNeedingContextParameter($implClassName)) {
+ push(@implContent, " if (context())\n");
+ push(@implContent, " context()->svgAttributeChanged(impl()->associatedAttributeName());\n");
+ }
+ }
+ }
+ push(@implContent, " break;\n");
+ push(@implContent, " }\n");
+ }
+ }
+ push(@implContent, " }\n"); # end switch
+ push(@implContent, "}\n\n"); # end function
+ }
+ }
+ }
+
+ if ($dataNode->extendedAttributes->{"CustomGetPropertyNames"} || $dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) {
+ push(@implContent, "void ${className}::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)\n");
+ push(@implContent, "{\n");
+ if ($dataNode->extendedAttributes->{"CustomGetPropertyNames"}) {
+ push(@implContent, " if (customGetPropertyNames(exec, propertyNames))\n");
+ push(@implContent, " return;\n");
+ }
+ if ($dataNode->extendedAttributes->{"HasIndexGetter"} || $dataNode->extendedAttributes->{"HasCustomIndexGetter"}) {
+ push(@implContent, " for (unsigned i = 0; i < static_cast<${implClassName}*>(impl())->length(); ++i)\n");
+ push(@implContent, " propertyNames.add(Identifier::from(i));\n");
+ }
+ push(@implContent, " Base::getPropertyNames(exec, propertyNames);\n");
+ push(@implContent, "}\n\n");
+ }
+
+ if ($dataNode->extendedAttributes->{"GenerateConstructor"}) {
+ push(@implContent, "JSValue* ${className}::getConstructor(ExecState* exec)\n{\n");
+ push(@implContent, " return KJS::cacheGlobalObject<${className}Constructor>(exec, \"[[${interfaceName}.constructor]]\");\n");
+ push(@implContent, "}\n\n");
+ }
+
+ # Functions
+ if ($numFunctions > 0) {
+ foreach my $function (@{$dataNode->functions}) {
+ my $functionName = $codeGenerator->WK_lcfirst($className) . "PrototypeFunction" . $codeGenerator->WK_ucfirst($function->signature->name);
+ push(@implContent, "JSValue* ${functionName}(ExecState* exec, JSObject* thisObj, const List& args)\n");
+ push(@implContent, "{\n");
+ push(@implContent, " if (!thisObj->inherits(&${className}::info))\n");
+ push(@implContent, " return throwError(exec, TypeError);\n");
+
+ AddIncludesForType($function->signature->type);
+
+ push(@implContent, " $className* castedThisObj = static_cast<$className*>(thisObj);\n");
+
+ if ($dataNode->extendedAttributes->{"CheckDomainSecurity"} &&
+ !$function->signature->extendedAttributes->{"DoNotCheckDomainSecurity"}) {
+ push(@implContent, " if (!castedThisObj->allowsAccessFrom(exec))\n");
+ push(@implContent, " return jsUndefined();\n");
+ }
+
+ if ($function->signature->extendedAttributes->{"Custom"}) {
+ push(@implContent, " return castedThisObj->" . $codeGenerator->WK_lcfirst($function->signature->name) . "(exec, args);\n");
+ } else {
+ if ($podType) {
+ push(@implContent, " JSSVGPODTypeWrapper<$podType>* wrapper = castedThisObj->impl();\n");
+ push(@implContent, " $podType imp(*wrapper);\n");
+ } else {
+ push(@implContent, " $implClassName* imp = static_cast<$implClassName*>(castedThisObj->impl());\n");
+ }
+
+ my $numParameters = @{$function->parameters};
+
+ if ($function->signature->extendedAttributes->{"RequiresAllArguments"}) {
+ push(@implContent, " if (args.size() < $numParameters)\n");
+ push(@implContent, " return jsUndefined();\n");
+ }
+
+ if (@{$function->raisesExceptions}) {
+ push(@implContent, " ExceptionCode ec = 0;\n");
+ }
+
+ if ($function->signature->extendedAttributes->{"SVGCheckSecurityDocument"}) {
+ push(@implContent, " if (!checkNodeSecurity(exec, imp->getSVGDocument(" . (@{$function->raisesExceptions} ? "ec" : "") .")))\n");
+ push(@implContent, " return jsUndefined();\n");
+ $implIncludes{"kjs_dom.h"} = 1;
+ }
+
+ my $paramIndex = 0;
+ my $functionString = "imp" . ($podType ? "." : "->") . $codeGenerator->WK_lcfirst($function->signature->name) . "(";
+
+ my $hasOptionalArguments = 0;
+
+ foreach my $parameter (@{$function->parameters}) {
+ if (!$hasOptionalArguments && $parameter->extendedAttributes->{"Optional"}) {
+ push(@implContent, "\n int argsCount = args.size();\n");
+ $hasOptionalArguments = 1;
+ }
+
+ if ($hasOptionalArguments) {
+ push(@implContent, " if (argsCount < " . ($paramIndex + 1) . ") {\n");
+ GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " " x 2, $podType, $implClassName);
+ push(@implContent, " }\n\n");
+ }
+
+ my $name = $parameter->name;
+
+ if ($parameter->type eq "XPathNSResolver") {
+ push(@implContent, " RefPtr<XPathNSResolver> customResolver;\n");
+ push(@implContent, " XPathNSResolver* resolver = toXPathNSResolver(args[$paramIndex]);\n");
+ push(@implContent, " if (!resolver) {\n");
+ push(@implContent, " customResolver = JSCustomXPathNSResolver::create(exec, args[$paramIndex]);\n");
+ push(@implContent, " if (exec->hadException())\n");
+ push(@implContent, " return jsUndefined();\n");
+ push(@implContent, " resolver = customResolver.get();\n");
+ push(@implContent, " }\n");
+ } else {
+ push(@implContent, " bool ${name}Ok;\n") if TypeCanFailConversion($parameter);
+ push(@implContent, " " . GetNativeTypeFromSignature($parameter) . " $name = " . JSValueToNative($parameter, "args[$paramIndex]", TypeCanFailConversion($parameter) ? "${name}Ok" : undef) . ";\n");
+ if (TypeCanFailConversion($parameter)) {
+ push(@implContent, " if (!${name}Ok) {\n");
+ push(@implContent, " setDOMException(exec, TYPE_MISMATCH_ERR);\n");
+ push(@implContent, " return jsUndefined();\n");
+ push(@implContent, " }\n");
+ }
+
+ # If a parameter is "an index", it should throw an INDEX_SIZE_ERR
+ # exception
+ if ($parameter->extendedAttributes->{"IsIndex"}) {
+ $implIncludes{"ExceptionCode.h"} = 1;
+ push(@implContent, " if ($name < 0) {\n");
+ push(@implContent, " setDOMException(exec, INDEX_SIZE_ERR);\n");
+ push(@implContent, " return jsUndefined();\n");
+ push(@implContent, " }\n");
+ }
+ }
+
+ $functionString .= ", " if $paramIndex;
+ $functionString .= $name;
+
+ $paramIndex++;
+ }
+
+ push(@implContent, "\n");
+ GenerateImplementationFunctionCall($function, $functionString, $paramIndex, " ", $podType, $implClassName);
+ }
+ push(@implContent, "}\n\n");
+ }
+ }
+
+ if ($dataNode->extendedAttributes->{"HasIndexGetter"}) {
+ push(@implContent, "\nJSValue* ${className}::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot)\n");
+ push(@implContent, "{\n");
+ push(@implContent, " ${className}* thisObj = static_cast<$className*>(slot.slotBase());\n");
+ if (IndexGetterReturnsStrings($implClassName)) {
+ $implIncludes{"KURL.h"} = 1;
+ push(@implContent, " return jsStringOrNull(thisObj->impl()->item(slot.index()));\n");
+ } else {
+ push(@implContent, " return toJS(exec, static_cast<$implClassName*>(thisObj->impl())->item(slot.index()));\n");
+ }
+ push(@implContent, "}\n");
+ if ($interfaceName eq "HTMLCollection") {
+ $implIncludes{"JSNode.h"} = 1;
+ $implIncludes{"Node.h"} = 1;
+ }
+ }
+
+ if ((!$hasParent or $dataNode->extendedAttributes->{"GenerateToJS"}) and !UsesManualToJSImplementation($implClassName)) {
+ if ($podType) {
+ push(@implContent, "KJS::JSValue* toJS(KJS::ExecState* exec, JSSVGPODTypeWrapper<$podType>* obj, SVGElement* context)\n");
+ } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
+ push(@implContent, "KJS::JSValue* toJS(KJS::ExecState* exec, $passType obj, SVGElement* context)\n");
+ } else {
+ push(@implContent, "KJS::JSValue* toJS(KJS::ExecState* exec, $passType obj)\n");
+ }
+
+ push(@implContent, "{\n");
+ if ($podType) {
+ push(@implContent, " return cacheSVGDOMObject<JSSVGPODTypeWrapper<$podType>, $className, ${className}Prototype>(exec, obj, context);\n");
+ } elsif (IsSVGTypeNeedingContextParameter($implClassName)) {
+ push(@implContent, " return cacheSVGDOMObject<$implClassName, $className, ${className}Prototype>(exec, obj, context);\n");
+ } else {
+ push(@implContent, " return cacheDOMObject<$implClassName, $className, ${className}Prototype>(exec, obj);\n");
+ }
+ push(@implContent, "}\n");
+ }
+
+ if ((!$hasParent or $dataNode->extendedAttributes->{"GenerateNativeConverter"}) and !$dataNode->extendedAttributes->{"CustomNativeConverter"}) {
+ if ($podType) {
+ push(@implContent, "$podType to${interfaceName}(KJS::JSValue* val)\n");
+ } else {
+ push(@implContent, "$implClassName* to${interfaceName}(KJS::JSValue* val)\n");
+ }
+
+ push(@implContent, "{\n");
+
+ push(@implContent, " return val->isObject(&${className}::info) ? " . ($podType ? "($podType) *" : "") . "static_cast<$className*>(val)->impl() : ");
+ if ($podType and $podType ne "float") {
+ push(@implContent, "$podType();\n}\n");
+ } else {
+ push(@implContent, "0;\n}\n");
+ }
+ }
+
+ if ($dataNode->extendedAttributes->{"GenerateNativeConverter"} && $hasParent) {
+ push(@implContent, "\n$implClassName* ${className}::impl() const\n");
+ push(@implContent, "{\n");
+ push(@implContent, " return static_cast<$implClassName*>(Base::impl());\n");
+ push(@implContent, "}\n");
+ }
+
+ push(@implContent, "\n}\n");
+
+ push(@implContent, "\n#endif // ${conditionalString}\n") if $conditional;
+}
+
+sub GenerateImplementationFunctionCall()
+{
+ my $function = shift;
+ my $functionString = shift;
+ my $paramIndex = shift;
+ my $indent = shift;
+ my $podType = shift;
+ my $implClassName = shift;
+
+ if (@{$function->raisesExceptions}) {
+ $functionString .= ", " if $paramIndex;
+ $functionString .= "ec";
+ }
+ $functionString .= ")";
+
+ if ($function->signature->type eq "void") {
+ push(@implContent, $indent . "$functionString;\n");
+ push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
+
+ if ($podType) {
+ push(@implContent, $indent . "wrapper->commitChange(imp, castedThisObj->context());\n");
+ }
+
+ push(@implContent, $indent . "return jsUndefined();\n");
+ } else {
+ push(@implContent, "\n" . $indent . "KJS::JSValue* result = " . NativeToJSValue($function->signature, 1, $implClassName, "", $functionString) . ";\n");
+ push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions};
+
+ if ($podType) {
+ push(@implContent, $indent . "wrapper->commitChange(imp, castedThisObj->context());\n");
+ }
+
+ push(@implContent, $indent . "return result;\n");
+ }
+}
+
+sub GetNativeTypeFromSignature
+{
+ my $signature = shift;
+ my $type = $codeGenerator->StripModule($signature->type);
+
+ if ($type eq "unsigned long" and $signature->extendedAttributes->{"IsIndex"}) {
+ # Special-case index arguments because we need to check that they aren't < 0.
+ return "int";
+ }
+
+ return GetNativeType($type);
+}
+
+my %nativeType = (
+ "AtomicString" => "AtomicString",
+ "CompareHow" => "Range::CompareHow",
+ "DOMString" => "String",
+ "EventTarget" => "EventTargetNode*",
+ "SVGLength" => "SVGLength",
+ "SVGMatrix" => "AffineTransform",
+ "SVGNumber" => "float",
+ "SVGPaintType" => "SVGPaint::SVGPaintType",
+ "SVGPoint" => "FloatPoint",
+ "SVGRect" => "FloatRect",
+ "SVGTransform" => "SVGTransform",
+ "boolean" => "bool",
+ "double" => "double",
+ "float" => "float",
+ "long" => "int",
+ "unsigned long" => "unsigned",
+ "unsigned short" => "unsigned short",
+);
+
+sub GetNativeType
+{
+ my $type = shift;
+
+ return $nativeType{$type} if exists $nativeType{$type};
+
+ # For all other types, the native type is a pointer with same type name as the IDL type.
+ return "${type}*";
+}
+
+my %typeCanFailConversion = (
+ "AtomicString" => 0,
+ "Attr" => 1,
+ "CompareHow" => 0,
+ "DOMString" => 0,
+ "DOMWindow" => 0,
+ "DocumentType" => 0,
+ "Element" => 0,
+ "Event" => 0,
+ "EventListener" => 0,
+ "EventTarget" => 0,
+ "HTMLElement" => 0,
+ "HTMLOptionElement" => 0,
+ "Node" => 0,
+ "NodeFilter" => 0,
+ "Range" => 0,
+ "SQLResultSet" => 0,
+ "SVGAngle" => 0,
+ "SVGElement" => 0,
+ "SVGLength" => 0,
+ "SVGMatrix" => 0,
+ "SVGNumber" => 0,
+ "SVGPaintType" => 0,
+ "SVGPathSeg" => 0,
+ "SVGPoint" => 0,
+ "SVGRect" => 0,
+ "SVGTransform" => 0,
+ "VoidCallback" => 1,
+ "XPathEvaluator" => 0,
+ "XPathNSResolver" => 0,
+ "XPathResult" => 0,
+ "boolean" => 0,
+ "double" => 0,
+ "float" => 0,
+ "long" => 0,
+ "unsigned long" => 0,
+ "unsigned short" => 0,
+);
+
+sub TypeCanFailConversion
+{
+ my $signature = shift;
+
+ my $type = $codeGenerator->StripModule($signature->type);
+
+ $implIncludes{"ExceptionCode.h"} = 1 if $type eq "Attr";
+
+ return $typeCanFailConversion{$type} if exists $typeCanFailConversion{$type};
+
+ die "Don't know whether a JS value can fail conversion to type $type.";
+}
+
+sub JSValueToNative
+{
+ my $signature = shift;
+ my $value = shift;
+ my $okParam = shift;
+ my $maybeOkParam = $okParam ? ", ${okParam}" : "";
+
+ my $type = $codeGenerator->StripModule($signature->type);
+
+ return "$value->toBoolean(exec)" if $type eq "boolean";
+ return "$value->toNumber(exec)" if $type eq "double";
+ return "$value->toFloat(exec)" if $type eq "float" or $type eq "SVGNumber";
+ return "$value->toInt32(exec${maybeOkParam})" if $type eq "unsigned long" or $type eq "long" or $type eq "unsigned short";
+
+ return "static_cast<Range::CompareHow>($value->toInt32(exec))" if $type eq "CompareHow";
+ return "static_cast<SVGPaint::SVGPaintType>($value->toInt32(exec))" if $type eq "SVGPaintType";
+
+ return "$value->toString(exec)" if $type eq "AtomicString";
+ if ($type eq "DOMString") {
+ return "valueToStringWithNullCheck(exec, $value)" if $signature->extendedAttributes->{"ConvertNullToNullString"};
+ return "valueToStringWithUndefinedOrNullCheck(exec, $value)" if $signature->extendedAttributes->{"ConvertUndefinedOrNullToNullString"};
+ return "$value->toString(exec)";
+ }
+
+ if ($type eq "EventTarget") {
+ $implIncludes{"JSEventTargetNode.h"} = 1;
+ return "toEventTargetNode($value)";
+ }
+
+ if ($type eq "Attr") {
+ $implIncludes{"kjs_dom.h"} = 1;
+ return "toAttr($value${maybeOkParam})";
+ }
+
+ if ($type eq "VoidCallback") {
+ $implIncludes{"JSCustomVoidCallback.h"} = 1;
+ return "toVoidCallback(exec, $value${maybeOkParam})";
+ }
+
+ $implIncludes{"FloatPoint.h"} = 1 if $type eq "SVGPoint";
+ $implIncludes{"FloatRect.h"} = 1 if $type eq "SVGRect";
+ $implIncludes{"HTMLOptionElement.h"} = 1 if $type eq "HTMLOptionElement";
+
+ # Default, assume autogenerated type conversion routines
+ $implIncludes{"JS$type.h"} = 1;
+ return "to$type($value)";
+}
+
+sub NativeToJSValue
+{
+ my $signature = shift;
+ my $inFunctionCall = shift;
+ my $implClassName = shift;
+ my $implClassNameForValueConversion = shift;
+ my $value = shift;
+
+ my $type = $codeGenerator->StripModule($signature->type);
+
+ return "jsBoolean($value)" if $type eq "boolean";
+ return "jsNumber($value)" if $codeGenerator->IsPrimitiveType($type) or $type eq "SVGPaintType" or $type eq "DOMTimeStamp";
+
+ if ($codeGenerator->IsStringType($type)) {
+ $implIncludes{"KURL.h"} = 1;
+ my $conv = $signature->extendedAttributes->{"ConvertNullStringTo"};
+ if (defined $conv) {
+ return "jsStringOrNull($value)" if $conv eq "Null";
+ return "jsStringOrUndefined($value)" if $conv eq "Undefined";
+ return "jsStringOrFalse($value)" if $conv eq "False";
+
+ die "Unknown value for ConvertNullStringTo extended attribute";
+ }
+ return "jsString($value)";
+ }
+
+ if ($type eq "RGBColor") {
+ $implIncludes{"kjs_css.h"} = 1;
+ return "getJSRGBColor(exec, $value)";
+ }
+
+ if ($codeGenerator->IsPodType($type)) {
+ $implIncludes{"JS$type.h"} = 1;
+
+ my $nativeType = GetNativeType($type);
+
+ my $getter = $value;
+ $getter =~ s/imp->//;
+ $getter =~ s/\(\)//;
+
+ my $setter = "set" . $codeGenerator->WK_ucfirst($getter);
+
+ if ($implClassNameForValueConversion eq "") {
+ if (IsSVGTypeNeedingContextParameter($implClassName)) {
+ return "toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<$nativeType>($value), castedThisObj->context())" if $inFunctionCall eq 1;
+
+ # Special case: SVGZoomEvent - it doesn't have a context, but it's no problem, as there are no readwrite props
+ return "toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<$nativeType>($value), 0)" if $implClassName eq "SVGZoomEvent";
+ return "toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<$nativeType>($value), context())";
+ } else {
+ return "toJS(exec, new JSSVGPODTypeWrapperCreatorReadOnly<$nativeType>($value), imp)";
+ }
+ } else { # These classes, always have a m_context pointer!
+ return "toJS(exec, JSSVGPODTypeWrapperCache<$nativeType, $implClassNameForValueConversion>::lookupOrCreateWrapper(imp, &${implClassNameForValueConversion}::$getter, &${implClassNameForValueConversion}::$setter), context())";
+ }
+ }
+
+ if ($codeGenerator->IsSVGAnimatedType($type)) {
+ $value =~ s/\(\)//;
+ $value .= "Animated()";
+ }
+
+ if ($type eq "CSSStyleDeclaration") {
+ $implIncludes{"CSSMutableStyleDeclaration.h"} = 1;
+ }
+
+ if ($type eq "NamedNodeMap") {
+ $implIncludes{"NamedAttrMap.h"} = 1;
+ }
+
+ if ($type eq "NodeList") {
+ $implIncludes{"NameNodeList.h"} = 1;
+ }
+
+ if ($type eq "EventTarget") {
+ $implIncludes{"EventTargetNode.h"} = 1;
+ $implIncludes{"JSEventTargetNode.h"} = 1;
+ $implIncludes{"kjs_dom.h"} = 1;
+ } elsif ($type eq "DOMWindow") {
+ $implIncludes{"kjs_window.h"} = 1;
+ } elsif ($type eq "DOMObject") {
+ $implIncludes{"JSCanvasRenderingContext2D.h"} = 1;
+ } elsif ($type eq "Clipboard") {
+ $implIncludes{"kjs_events.h"} = 1;
+ $implIncludes{"Clipboard.h"} = 1;
+ } elsif ($type =~ /SVGPathSeg/) {
+ $implIncludes{"JS$type.h"} = 1;
+ $joinedName = $type;
+ $joinedName =~ s/Abs|Rel//;
+ $implIncludes{"$joinedName.h"} = 1;
+ } else {
+ # Default, include header with same name.
+ $implIncludes{"JS$type.h"} = 1;
+ $implIncludes{"$type.h"} = 1;
+ }
+
+ return $value if $codeGenerator->IsSVGAnimatedType($type);
+
+ if (IsSVGTypeNeedingContextParameter($type)) {
+ if (IsSVGTypeNeedingContextParameter($implClassName)) {
+ if ($inFunctionCall eq 1) {
+ return "toJS(exec, WTF::getPtr($value), castedThisObj->context())";
+ } else {
+ return "toJS(exec, WTF::getPtr($value), context())";
+ }
+ } else {
+ return "toJS(exec, WTF::getPtr($value), imp)";
+ }
+ }
+
+ return "toJS(exec, WTF::getPtr($value))";
+}
+
+sub ceilingToPowerOf2
+{
+ my ($size) = @_;
+
+ my $powerOf2 = 1;
+ while ($size > $powerOf2) {
+ $powerOf2 <<= 1;
+ }
+
+ return $powerOf2;
+}
+
+# Internal Helper
+sub GenerateHashTable
+{
+ my $object = shift;
+
+ my $name = shift;
+ my $size = shift;
+ my $keys = shift;
+ my $values = shift;
+ my $specials = shift;
+ my $parameters = shift;
+
+ # Helpers
+ my @table = ();
+ my @links = ();
+
+ $size = ceilingToPowerOf2($size * 2);
+
+ my $maxDepth = 0;
+ my $collisions = 0;
+ my $numEntries = $size;
+
+ # Collect hashtable information
+ my $i = 0;
+ foreach (@{$keys}) {
+ my $depth = 0;
+ my $h = $object->GenerateHashValue($_) % $numEntries;
+
+ while (defined($table[$h])) {
+ if (defined($links[$h])) {
+ $h = $links[$h];
+ $depth++;
+ } else {
+ $collisions++;
+ $links[$h] = $size;
+ $h = $size;
+ $size++;
+ }
+ }
+
+ $table[$h] = $i;
+
+ $i++;
+ $maxDepth = $depth if ($depth > $maxDepth);
+ }
+
+ # Ensure table is big enough (in case of undef entries at the end)
+ if ($#table + 1 < $size) {
+ $#table = $size - 1;
+ }
+
+ # Start outputing the hashtables
+ my $nameEntries = "${name}Entries";
+ $nameEntries =~ s/:/_/g;
+
+ if (($name =~ /Prototype/) or ($name =~ /Constructor/)) {
+ my $type = $name;
+ my $implClass;
+
+ if ($name =~ /Prototype/) {
+ $type =~ s/Prototype.*//;
+ $implClass = $type; $implClass =~ s/Wrapper$//;
+ push(@implContent, "/* Hash table for prototype */\n");
+ } else {
+ $type =~ s/Constructor.*//;
+ $implClass = $type; $implClass =~ s/Constructor$//;
+ push(@implContent, "/* Hash table for constructor */\n");
+ }
+ } else {
+ push(@implContent, "/* Hash table */\n");
+ }
+
+ # Dump the hash table
+ push(@implContent, "\nstatic const HashEntry $nameEntries\[\] =\n\{\n");
+
+ $i = 0;
+ foreach $entry (@table) {
+ if (defined($entry)) {
+ my $key = @$keys[$entry];
+
+ push(@implContent, " \{ \"" . $key . "\"");
+ push(@implContent, ", \{ (intptr_t)" . @$values[$entry] . " \}");
+ push(@implContent, ", " . @$specials[$entry]);
+ push(@implContent, ", " . @$parameters[$entry]);
+ push(@implContent, ", ");
+
+ if (defined($links[$i])) {
+ push(@implContent, "&" . $nameEntries . "[$links[$i]]" . " \}");
+ } else {
+ push(@implContent, "0 \}");
+ }
+ } else {
+ push(@implContent, " { 0, { 0 }, 0, 0, 0 }");
+ }
+
+ push(@implContent, ",") unless($i eq $size - 1);
+ push(@implContent, "\n");
+
+ $i++;
+ }
+
+ my $sizeMask = $numEntries - 1;
+
+ push(@implContent, "};\n\n");
+ push(@implContent, "static const HashTable $name = \n");
+ push(@implContent, "{\n 3, $size, $nameEntries, $sizeMask\n};\n\n");
+}
+
+# Internal helper
+sub GenerateHashValue
+{
+ my $object = shift;
+
+ @chars = split(/ */, $_[0]);
+
+ # This hash is designed to work on 16-bit chunks at a time. But since the normal case
+ # (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they
+ # were 16-bit chunks, which should give matching results
+
+ my $EXP2_32 = 4294967296;
+
+ my $hash = 0x9e3779b9;
+ my $l = scalar @chars; #I wish this was in Ruby --- Maks
+ my $rem = $l & 1;
+ $l = $l >> 1;
+
+ my $s = 0;
+
+ # Main loop
+ for (; $l > 0; $l--) {
+ $hash += ord($chars[$s]);
+ my $tmp = leftShift(ord($chars[$s+1]), 11) ^ $hash;
+ $hash = (leftShift($hash, 16)% $EXP2_32) ^ $tmp;
+ $s += 2;
+ $hash += $hash >> 11;
+ $hash %= $EXP2_32;
+ }
+
+ # Handle end case
+ if ($rem != 0) {
+ $hash += ord($chars[$s]);
+ $hash ^= (leftShift($hash, 11)% $EXP2_32);
+ $hash += $hash >> 17;
+ }
+
+ # Force "avalanching" of final 127 bits
+ $hash ^= leftShift($hash, 3);
+ $hash += ($hash >> 5);
+ $hash = ($hash% $EXP2_32);
+ $hash ^= (leftShift($hash, 2)% $EXP2_32);
+ $hash += ($hash >> 15);
+ $hash = $hash% $EXP2_32;
+ $hash ^= (leftShift($hash, 10)% $EXP2_32);
+
+ # this avoids ever returning a hash code of 0, since that is used to
+ # signal "hash not computed yet", using a value that is likely to be
+ # effectively the same as 0 when the low bits are masked
+ $hash = 0x80000000 if ($hash == 0);
+
+ return $hash;
+}
+
+# Internal helper
+sub WriteData
+{
+ if (defined($IMPL)) {
+ # Write content to file.
+ print $IMPL @implContentHeader;
+
+ foreach my $implInclude (sort keys(%implIncludes)) {
+ my $checkType = $implInclude;
+ $checkType =~ s/\.h//;
+
+ print $IMPL "#include \"$implInclude\"\n" unless $codeGenerator->IsSVGAnimatedType($checkType);
+ }
+
+ print $IMPL @implContent;
+ close($IMPL);
+ undef($IMPL);
+
+ @implContentHeader = ();
+ @implContent = ();
+ %implIncludes = ();
+ }
+
+ if (defined($HEADER)) {
+ # Write content to file.
+ print $HEADER @headerContent;
+ close($HEADER);
+ undef($HEADER);
+
+ @headerContent = ();
+ }
+}
+
+sub constructorFor
+{
+ my $className = shift;
+ my $protoClassName = shift;
+ my $interfaceName = shift;
+ my $visibleClassName = shift;
+ my $canConstruct = shift;
+
+my $implContent = << "EOF";
+class ${className}Constructor : public DOMObject {
+public:
+ ${className}Constructor(ExecState* exec)
+ : DOMObject(exec->lexicalGlobalObject()->objectPrototype())
+ {
+ putDirect(exec->propertyNames().prototype, ${protoClassName}::self(exec), None);
+ }
+ virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
+ JSValue* getValueProperty(ExecState*, int token) const;
+ virtual const ClassInfo* classInfo() const { return &info; }
+ static const ClassInfo info;
+
+ virtual bool implementsHasInstance() const { return true; }
+EOF
+
+ if ($canConstruct) {
+$implContent .= << "EOF";
+ virtual bool implementsConstruct() const { return true; }
+ virtual JSObject* construct(ExecState* exec, const List& args) { return static_cast<JSObject*>(toJS(exec, ${interfaceName}::create())); }
+EOF
+ }
+
+$implContent .= << "EOF";
+};
+
+const ClassInfo ${className}Constructor::info = { "${visibleClassName}Constructor", 0, &${className}ConstructorTable };
+
+bool ${className}Constructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
+{
+ return getStaticValueSlot<${className}Constructor, DOMObject>(exec, &${className}ConstructorTable, this, propertyName, slot);
+}
+
+JSValue* ${className}Constructor::getValueProperty(ExecState*, int token) const
+{
+ // The token is the numeric value of its associated constant
+ return jsNumber(token);
+}
+
+EOF
+
+ return $implContent;
+}
+
+1;
diff --git a/WebCore/bindings/scripts/CodeGeneratorObjC.pm b/WebCore/bindings/scripts/CodeGeneratorObjC.pm
new file mode 100644
index 0000000..82fdabb
--- /dev/null
+++ b/WebCore/bindings/scripts/CodeGeneratorObjC.pm
@@ -0,0 +1,1626 @@
+#
+# Copyright (C) 2005, 2006 Nikolas Zimmermann <zimmermann@kde.org>
+# Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
+# Copyright (C) 2006, 2007 Samuel Weinig <sam@webkit.org>
+# Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
+# Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# aint with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+
+package CodeGeneratorObjC;
+
+use File::stat;
+
+# Global Variables
+my $module = "";
+my $outputDir = "";
+my %publicInterfaces = ();
+my $newPublicClass = 0;
+my $isProtocol = 0;
+my $noImpl = 0;
+my @ivars = ();
+
+my @headerContentHeader = ();
+my @headerContent = ();
+my %headerForwardDeclarations = ();
+my %headerForwardDeclarationsForProtocols = ();
+
+my @privateHeaderContentHeader = ();
+my @privateHeaderContent = ();
+my %privateHeaderForwardDeclarations = ();
+my %privateHeaderForwardDeclarationsForProtocols = ();
+
+my @internalHeaderContent = ();
+
+my @implContentHeader = ();
+my @implContent = ();
+my %implIncludes = ();
+
+# Hashes
+my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1,
+ "SVGLocatable" => 1, "SVGTransformable" => 1, "SVGStylable" => 1, "SVGFilterPrimitiveStandardAttributes" => 1,
+ "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1,
+ "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 1, "SVGAnimatedPoints" => 1);
+my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1);
+
+# FIXME: this should be replaced with a function that recurses up the tree
+# to find the actual base type.
+my %baseTypeHash = ("Object" => 1, "Node" => 1, "NodeList" => 1, "NamedNodeMap" => 1, "DOMImplementation" => 1,
+ "Event" => 1, "CSSRule" => 1, "CSSValue" => 1, "StyleSheet" => 1, "MediaList" => 1,
+ "Counter" => 1, "Rect" => 1, "RGBColor" => 1, "XPathExpression" => 1, "XPathResult" => 1,
+ "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1,
+ "SVGAngle" => 1, "SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, "SVGAnimatedEnumeration" => 1,
+ "SVGAnimatedInteger" => 1, "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1,
+ "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1, "SVGAnimatedPoints" => 1,
+ "SVGAnimatedPreserveAspectRatio" => 1, "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1,
+ "SVGAnimatedTransformList" => 1, "SVGLength" => 1, "SVGLengthList" => 1, "SVGMatrix" => 1,
+ "SVGNumber" => 1, "SVGNumberList" => 1, "SVGPathSeg" => 1, "SVGPathSegList" => 1, "SVGPoint" => 1,
+ "SVGPointList" => 1, "SVGPreserveAspectRatio" => 1, "SVGRect" => 1, "SVGRenderingIntent" => 1,
+ "SVGStringList" => 1, "SVGTransform" => 1, "SVGTransformList" => 1, "SVGUnitTypes" => 1);
+
+# Constants
+my $buildingForTigerOrEarlier = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} <= 10.4;
+my $buildingForLeopardOrLater = 1 if $ENV{"MACOSX_DEPLOYMENT_TARGET"} and $ENV{"MACOSX_DEPLOYMENT_TARGET"} >= 10.5;
+my $exceptionInit = "WebCore::ExceptionCode ec = 0;";
+my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);";
+my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheck(); }";
+
+my %conflictMethod = (
+ # FIXME: Add C language keywords?
+ # FIXME: Add other predefined types like "id"?
+
+ "callWebScriptMethod:withArguments:" => "WebScriptObject",
+ "evaluateWebScript:" => "WebScriptObject",
+ "removeWebScriptKey:" => "WebScriptObject",
+ "setException:" => "WebScriptObject",
+ "setWebScriptValueAtIndex:value:" => "WebScriptObject",
+ "stringRepresentation" => "WebScriptObject",
+ "webScriptValueAtIndex:" => "WebScriptObject",
+
+ "autorelease" => "NSObject",
+ "awakeAfterUsingCoder:" => "NSObject",
+ "class" => "NSObject",
+ "classForCoder" => "NSObject",
+ "conformsToProtocol:" => "NSObject",
+ "copy" => "NSObject",
+ "copyWithZone:" => "NSObject",
+ "dealloc" => "NSObject",
+ "description" => "NSObject",
+ "doesNotRecognizeSelector:" => "NSObject",
+ "encodeWithCoder:" => "NSObject",
+ "finalize" => "NSObject",
+ "forwardInvocation:" => "NSObject",
+ "hash" => "NSObject",
+ "init" => "NSObject",
+ "initWithCoder:" => "NSObject",
+ "isEqual:" => "NSObject",
+ "isKindOfClass:" => "NSObject",
+ "isMemberOfClass:" => "NSObject",
+ "isProxy" => "NSObject",
+ "methodForSelector:" => "NSObject",
+ "methodSignatureForSelector:" => "NSObject",
+ "mutableCopy" => "NSObject",
+ "mutableCopyWithZone:" => "NSObject",
+ "performSelector:" => "NSObject",
+ "release" => "NSObject",
+ "replacementObjectForCoder:" => "NSObject",
+ "respondsToSelector:" => "NSObject",
+ "retain" => "NSObject",
+ "retainCount" => "NSObject",
+ "self" => "NSObject",
+ "superclass" => "NSObject",
+ "zone" => "NSObject",
+);
+
+my $fatalError = 0;
+
+# Default Licence Templates
+my $headerLicenceTemplate = << "EOF";
+/*
+ * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006 Samuel Weinig <sam.weinig\@gmail.com>
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+EOF
+
+my $implementationLicenceTemplate = << "EOF";
+/*
+ * This file is part of the WebKit open source project.
+ * This file has been generated by generate-bindings.pl. DO NOT MODIFY!
+ *
+ * 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 APPLE COMPUTER, INC. ``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 APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS 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.
+ */
+EOF
+
+# Default constructor
+sub new
+{
+ my $object = shift;
+ my $reference = { };
+
+ $codeGenerator = shift;
+ $outputDir = shift;
+
+ bless($reference, $object);
+ return $reference;
+}
+
+sub finish
+{
+ my $object = shift;
+}
+
+sub ReadPublicInterfaces
+{
+ my $class = shift;
+ my $superClass = shift;
+ my $defines = shift;
+ my $isProtocol = shift;
+
+ my $found = 0;
+ my $actualSuperClass;
+ %publicInterfaces = ();
+
+ my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h";
+ open FILE, "-|", "/usr/bin/gcc", "-E", "-P", "-x", "objective-c",
+ (map { "-D$_" } split(/ /, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName";
+ my @documentContent = <FILE>;
+ close FILE;
+
+ foreach $line (@documentContent) {
+ if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*/) {
+ if ($superClass ne $1) {
+ warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)";
+ $fatalError = 1;
+ }
+
+ $found = 1;
+ next;
+ } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*/) {
+ $found = 1;
+ next;
+ }
+
+ last if $found and $line =~ /^\s?\@end\s?$/;
+
+ if ($found) {
+ # trim whitspace
+ $line =~ s/^\s+//;
+ $line =~ s/\s+$//;
+ $publicInterfaces{$line} = 1 if length($line);
+ }
+ }
+
+ # If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class.
+ $newPublicClass = ! $found;
+}
+
+# Params: 'domClass' struct
+sub GenerateInterface
+{
+ my $object = shift;
+ my $dataNode = shift;
+ my $defines = shift;
+
+ $fatalError = 0;
+
+ my $name = $dataNode->name;
+ my $className = GetClassName($name);
+ my $parentClassName = "DOM" . GetParentImplClassName($dataNode);
+ $isProtocol = $dataNode->extendedAttributes->{ObjCProtocol};
+ $noImpl = $dataNode->extendedAttributes->{ObjCCustomImplementation} || $isProtocol;
+
+ ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol);
+
+ # Start actual generation..
+ $object->GenerateHeader($dataNode);
+ $object->GenerateImplementation($dataNode) unless $noImpl;
+
+ # Write changes.
+ $object->WriteData("DOM" . $name);
+
+ # Check for missing public API
+ if (keys %publicInterfaces > 0) {
+ my $missing = join("\n", keys %publicInterfaces);
+ warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n";
+ $fatalError = 1;
+ }
+
+ die if $fatalError;
+}
+
+# Params: 'idlDocument' struct
+sub GenerateModule
+{
+ my $object = shift;
+ my $dataNode = shift;
+
+ $module = $dataNode->module;
+}
+
+sub GetClassName
+{
+ my $name = $codeGenerator->StripModule(shift);
+
+ # special cases
+ return "NSString" if $codeGenerator->IsStringType($name);
+ return "NS$name" if IsNativeObjCType($name);
+ return "BOOL" if $name eq "boolean";
+ return "unsigned" if $name eq "unsigned long";
+ return "int" if $name eq "long";
+ return "DOMAbstractView" if $name eq "DOMWindow";
+ return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp";
+
+ # Default, assume Objective-C type has the same type name as
+ # idl type prefixed with "DOM".
+ return "DOM$name";
+}
+
+sub GetClassHeaderName
+{
+ my $name = shift;
+
+ return "DOMDOMImplementation" if $name eq "DOMImplementation";
+ return $name;
+}
+
+sub GetImplClassName
+{
+ my $name = $codeGenerator->StripModule(shift);
+
+ return "DOMImplementationFront" if $name eq "DOMImplementation";
+ return "DOMWindow" if $name eq "AbstractView";
+ return $name;
+}
+
+sub GetParentImplClassName
+{
+ my $dataNode = shift;
+
+ return "Object" if @{$dataNode->parents} eq 0;
+
+ my $parent = $codeGenerator->StripModule($dataNode->parents(0));
+
+ # special cases
+ return "Node" if $parent eq "EventTargetNode";
+ return "Object" if $parent eq "HTMLCollection";
+
+ return $parent;
+}
+
+sub GetParentAndProtocols
+{
+ my $dataNode = shift;
+ my $numParents = @{$dataNode->parents};
+
+ my $parent = "";
+ my @protocols = ();
+ if ($numParents eq 0) {
+ if ($isProtocol) {
+ push(@protocols, "NSObject");
+ push(@protocols, "NSCopying") if $dataNode->name eq "EventTarget";
+ } else {
+ $parent = "DOMObject";
+ }
+ } elsif ($numParents eq 1) {
+ my $parentName = $codeGenerator->StripModule($dataNode->parents(0));
+ if ($isProtocol) {
+ die "Parents of protocols must also be protocols." unless IsProtocolType($parentName);
+ push(@protocols, "DOM" . $parentName);
+ } else {
+ if (IsProtocolType($parentName)) {
+ push(@protocols, "DOM" . $parentName);
+ } elsif ($parentName eq "EventTargetNode") {
+ $parent = "DOMNode";
+ } elsif ($parentName eq "HTMLCollection") {
+ $parent = "DOMObject";
+ } else {
+ $parent = "DOM" . $parentName;
+ }
+ }
+ } else {
+ my @parents = @{$dataNode->parents};
+ my $firstParent = $codeGenerator->StripModule(shift(@parents));
+ if (IsProtocolType($firstParent)) {
+ push(@protocols, "DOM" . $firstParent);
+ if (!$isProtocol) {
+ $parent = "DOMObject";
+ }
+ } else {
+ $parent = "DOM" . $firstParent;
+ }
+
+ foreach my $parentName (@parents) {
+ $parentName = $codeGenerator->StripModule($parentName);
+ die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName);
+
+ push(@protocols, "DOM" . $parentName);
+ }
+ }
+
+ return ($parent, @protocols);
+}
+
+sub GetBaseClass
+{
+ $parent = shift;
+
+ return $parent if $parent eq "Object" or IsBaseType($parent);
+ return "Event" if $parent eq "UIEvent";
+ return "CSSValue" if $parent eq "SVGColor";
+ return "Node";
+}
+
+sub IsBaseType
+{
+ my $type = shift;
+
+ return 1 if $baseTypeHash{$type};
+ return 0;
+}
+
+sub IsProtocolType
+{
+ my $type = shift;
+
+ return 1 if $protocolTypeHash{$type};
+ return 0;
+}
+
+sub IsNativeObjCType
+{
+ my $type = shift;
+
+ return 1 if $nativeObjCTypeHash{$type};
+ return 0;
+}
+
+sub GetObjCType
+{
+ my $type = shift;
+ my $name = GetClassName($type);
+
+ return "id <$name>" if IsProtocolType($type);
+ return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp";
+ return "unsigned short" if $type eq "CompareHow" or $type eq "SVGPaintType";
+ return "$name *";
+}
+
+sub GetPropertyAttributes
+{
+ my $type = $codeGenerator->StripModule(shift);
+ my $readOnly = shift;
+
+ my @attributes = ();
+
+ push(@attributes, "readonly") if $readOnly;
+
+# FIXME: uncomment these lines once <rdar://problem/4996504> is fixed.
+# unless ($readOnly) {
+ if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) {
+ push(@attributes, "copy");
+ } elsif ($codeGenerator->IsPodType($type) || $codeGenerator->IsSVGAnimatedType($type)) {
+ push(@attributes, "retain");
+ } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow" && $type ne "SVGPaintType") {
+ push(@attributes, "retain");
+ }
+# }
+
+ return "" unless @attributes > 0;
+ return "(" . join(", ", @attributes) . ")";
+}
+
+sub GetObjCTypeMaker
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ return "" if $codeGenerator->IsNonPointerType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
+ return "_wrapAbstractView" if $type eq "DOMWindow";
+ return "_wrap$type";
+}
+
+sub GetObjCTypeGetterName
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ my $typeGetter = "";
+ if ($type =~ /^(HTML|CSS|SVG)/ or $type eq "DOMImplementation" or $type eq "CDATASection") {
+ $typeGetter = $type;
+ } elsif ($type =~ /^XPath(.+)/) {
+ $typeGetter = "xpath" . $1;
+ } elsif ($type eq "DOMWindow") {
+ $typeGetter = "abstractView";
+ } else {
+ $typeGetter = lcfirst($type);
+ }
+
+ # put into the form "_fooBar" for type FooBar.
+ return "_" . $typeGetter;
+}
+
+sub GetObjCTypeGetter
+{
+ my $argName = shift;
+ my $type = $codeGenerator->StripModule(shift);
+
+ return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type);
+ return $argName . "EventTarget" if $type eq "EventTarget";
+ return "static_cast<WebCore::Range::CompareHow>($argName)" if $type eq "CompareHow";
+ return "static_cast<WebCore::SVGPaint::SVGPaintType>($argName)" if $type eq "SVGPaintType";
+
+ my $typeGetterMethodName = GetObjCTypeGetterName($type);
+
+ return "nativeResolver" if $type eq "XPathNSResolver";
+ return "[$argName $typeGetterMethodName]";
+}
+
+sub AddForwardDeclarationsForType
+{
+ my $type = $codeGenerator->StripModule(shift);
+ my $public = shift;
+
+ return if $codeGenerator->IsNonPointerType($type) ;
+
+ my $class = GetClassName($type);
+
+ if (IsProtocolType($type)) {
+ $headerForwardDeclarationsForProtocols{$class} = 1 if $public;
+ $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class};
+ return;
+ }
+
+ $headerForwardDeclarations{$class} = 1 if $public;
+
+ # Private headers include the public header, so only add a forward declaration to the private header
+ # if the public header does not already have the same forward declaration.
+ $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class};
+}
+
+sub AddIncludesForType
+{
+ my $type = $codeGenerator->StripModule(shift);
+
+ return if $codeGenerator->IsNonPointerType($type) or IsNativeObjCType($type);
+
+ if ($codeGenerator->IsStringType($type)) {
+ $implIncludes{"KURL.h"} = 1;
+ return;
+ }
+
+ if ($type eq "RGBColor") {
+ $implIncludes{"Color.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "DOMWindow") {
+ $implIncludes{"DOMAbstractView.h"} = 1;
+ $implIncludes{"$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "DOMImplementation") {
+ $implIncludes{"DOMImplementationFront.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "EventTarget") {
+ $implIncludes{"EventTargetNode.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($codeGenerator->IsSVGAnimatedType($type)) {
+ $implIncludes{"SVGAnimatedTemplate.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "SVGRect") {
+ $implIncludes{"FloatRect.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "SVGPoint") {
+ $implIncludes{"FloatPoint.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "SVGMatrix") {
+ $implIncludes{"AffineTransform.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ $implIncludes{"SVGException.h"} = 1;
+ return;
+ }
+
+ if ($type eq "SVGNumber") {
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($type =~ /(\w+)(Abs|Rel)$/) {
+ $implIncludes{"$1.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+ return;
+ }
+
+ if ($type eq "XPathNSResolver") {
+ $implIncludes{"DOMCustomXPathNSResolver.h"} = 1;
+ }
+
+ # FIXME: won't compile without these
+ $implIncludes{"CSSMutableStyleDeclaration.h"} = 1 if $type eq "CSSStyleDeclaration";
+ $implIncludes{"NamedAttrMap.h"} = 1 if $type eq "NamedNodeMap";
+ $implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList";
+
+ # Default, include the same named file (the implementation) and the same name prefixed with "DOM".
+ $implIncludes{"$type.h"} = 1;
+ $implIncludes{"DOM$type.h"} = 1;
+}
+
+sub GenerateHeader
+{
+ my $object = shift;
+ my $dataNode = shift;
+
+ # We only support multiple parents with SVG (for now).
+ if (@{$dataNode->parents} > 1) {
+ die "A class can't have more than one parent" unless $module eq "svg";
+ }
+
+ my $interfaceName = $dataNode->name;
+ my $className = GetClassName($interfaceName);
+
+ my $parentName = "";
+ my @protocolsToImplement = ();
+ ($parentName, @protocolsToImplement) = GetParentAndProtocols($dataNode);
+
+ my $numConstants = @{$dataNode->constants};
+ my $numAttributes = @{$dataNode->attributes};
+ my $numFunctions = @{$dataNode->functions};
+
+ # - Add default header template
+ @headerContentHeader = split("\r", $headerLicenceTemplate);
+ push(@headerContentHeader, "\n");
+
+ # - INCLUDES -
+ unless ($isProtocol) {
+ my $parentHeaderName = GetClassHeaderName($parentName);
+ push(@headerContentHeader, "#import <WebCore/$parentHeaderName.h>\n");
+ }
+ foreach my $parentProtocol (@protocolsToImplement) {
+ next if $parentProtocol =~ /^NS/;
+ $parentProtocol = GetClassHeaderName($parentProtocol);
+ push(@headerContentHeader, "#import <WebCore/$parentProtocol.h>\n");
+ }
+
+ # Special case needed for legacy support of DOMRange
+ if ($interfaceName eq "Range") {
+ push(@headerContentHeader, "#import <WebCore/DOMCore.h>\n");
+ push(@headerContentHeader, "#import <WebCore/DOMDocument.h>\n");
+ push(@headerContentHeader, "#import <WebCore/DOMRangeException.h>\n");
+ }
+
+ push(@headerContentHeader, "\n");
+
+ # - Add constants.
+ if ($numConstants > 0) {
+ my @headerConstants = ();
+
+ # FIXME: we need a way to include multiple enums.
+ foreach my $constant (@{$dataNode->constants}) {
+ my $constantName = $constant->name;
+ my $constantValue = $constant->value;
+
+ my $output = " DOM_" . $constantName . " = " . $constantValue;
+ push(@headerConstants, $output);
+ }
+
+ my $combinedConstants = join(",\n", @headerConstants);
+
+ # FIXME: the formatting of the enums should line up the equal signs.
+ # FIXME: enums are unconditionally placed in the public header.
+ push(@headerContent, "enum {\n");
+ push(@headerContent, $combinedConstants);
+ push(@headerContent, "\n};\n\n");
+ }
+
+ # - Begin @interface or @protocol
+ if ($isProtocol) {
+ my $parentProtocols = join(", ", @protocolsToImplement);
+ push(@headerContent, "\@protocol $className <$parentProtocols>\n");
+ } else {
+ if (@protocolsToImplement eq 0) {
+ push(@headerContent, "\@interface $className : $parentName\n");
+ } else {
+ my $parentProtocols = join(", ", @protocolsToImplement);
+ push(@headerContent, "\@interface $className : $parentName <$parentProtocols>\n");
+ }
+ }
+
+ my @headerAttributes = ();
+ my @privateHeaderAttributes = ();
+
+ # - Add attribute getters/setters.
+ if ($numAttributes > 0) {
+ # Add ivars, if any, first
+ @ivars = ();
+ foreach my $attribute (@{$dataNode->attributes}) {
+ push(@ivars, $attribute) if $attribute->signature->extendedAttributes->{"ObjCIvar"};
+ }
+
+ if (@ivars > 0) {
+ push(@headerContent, "{\n");
+ foreach my $attribute (@ivars) {
+ my $type = GetObjCType($attribute->signature->type);;
+ my $name = "m_" . $attribute->signature->name;
+ my $ivarDeclaration = "$type $name";
+ push(@headerContent, " $ivarDeclaration;\n");
+ }
+ push(@headerContent, "}\n");
+ }
+
+ foreach my $attribute (@{$dataNode->attributes}) {
+ my $attributeName = $attribute->signature->name;
+
+ if ($attributeName eq "id" or $attributeName eq "hash") {
+ # Special case attributes id and hash to be idName and hashName to avoid ObjC naming conflict.
+ $attributeName .= "Name";
+ } elsif ($attributeName eq "frame") {
+ # Special case attribute frame to be frameBorders.
+ $attributeName .= "Borders";
+ }
+
+ my $attributeType = GetObjCType($attribute->signature->type);
+ my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
+
+ my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly);
+ $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName . ";";
+
+ my $public = ($publicInterfaces{$property} or $newPublicClass);
+ delete $publicInterfaces{$property};
+
+ AddForwardDeclarationsForType($attribute->signature->type, $public);
+
+ my $setterName = "set" . ucfirst($attributeName) . ":";
+
+ my $conflict = $conflictMethod{$attributeName};
+ if ($conflict) {
+ warn "$className conflicts with $conflict method $attributeName\n";
+ $fatalError = 1;
+ }
+
+ $conflict = $conflictMethod{$setterName};
+ if ($conflict) {
+ warn "$className conflicts with $conflict method $setterName\n";
+ $fatalError = 1;
+ }
+
+ if ($buildingForLeopardOrLater) {
+ $property .= "\n";
+ push(@headerAttributes, $property) if $public;
+ push(@privateHeaderAttributes, $property) unless $public;
+ } else {
+ # - GETTER
+ my $getter = "- (" . $attributeType . ")" . $attributeName . ";\n";
+ push(@headerAttributes, $getter) if $public;
+ push(@privateHeaderAttributes, $getter) unless $public;
+
+ # - SETTER
+ if (!$attributeIsReadonly) {
+ my $setter = "- (void)$setterName(" . $attributeType . ")new" . ucfirst($attributeName) . ";\n";
+ push(@headerAttributes, $setter) if $public;
+ push(@privateHeaderAttributes, $setter) unless $public;
+ }
+ }
+ }
+
+ push(@headerContent, @headerAttributes) if @headerAttributes > 0;
+ }
+
+ my @headerFunctions = ();
+ my @privateHeaderFunctions = ();
+ my @deprecatedHeaderFunctions = ();
+
+ # - Add functions.
+ if ($numFunctions > 0) {
+ foreach my $function (@{$dataNode->functions}) {
+ my $functionName = $function->signature->name;
+
+ my $returnType = GetObjCType($function->signature->type);
+ my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"});
+ my $numberOfParameters = @{$function->parameters};
+ my %typesToForwardDeclare = ($function->signature->type => 1);
+
+ my $parameterIndex = 0;
+ my $functionSig = "- ($returnType)$functionName";
+ my $methodName = $functionName;
+ foreach my $param (@{$function->parameters}) {
+ my $paramName = $param->name;
+ my $paramType = GetObjCType($param->type);
+
+ $typesToForwardDeclare{$param->type} = 1;
+
+ if ($parameterIndex >= 1) {
+ my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
+ $paramPrefix = $paramName unless defined($paramPrefix);
+ $functionSig .= " $paramPrefix";
+ $methodName .= $paramPrefix;
+ }
+
+ $functionSig .= ":($paramType)$paramName";
+ $methodName .= ":";
+
+ $parameterIndex++;
+ }
+
+ $functionSig .= ";";
+
+ my $conflict = $conflictMethod{$methodName};
+ if ($conflict) {
+ warn "$className conflicts with $conflict method $methodName\n";
+ $fatalError = 1;
+ }
+
+ if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$functionSig}) {
+ warn "Protocol method $functionSig is not in PublicDOMInterfaces.h. Protocols require all methods to be public";
+ $fatalError = 1;
+ }
+
+ my $public = ($publicInterfaces{$functionSig} or $newPublicClass);
+ delete $publicInterfaces{$functionSig};
+
+ $functionSig .= "\n";
+
+ foreach my $type (keys %typesToForwardDeclare) {
+ # add any forward declarations to the public header if a deprecated version will be generated
+ AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion;
+ AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion;
+ }
+
+ push(@headerFunctions, $functionSig) if $public;
+ push(@privateHeaderFunctions, $functionSig) unless $public;
+
+ # generate the old style method names with un-named parameters, these methods are deprecated
+ if ($needsDeprecatedVersion) {
+ my $deprecatedFunctionSig = $functionSig;
+ $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
+ my $deprecatedFunctionKey = $deprecatedFunctionSig;
+
+ $deprecatedFunctionSig =~ s/;\n$/ DEPRECATED_IN_MAC_OS_X_VERSION_10_5_AND_LATER;\n/ if $buildingForLeopardOrLater;
+ push(@deprecatedHeaderFunctions, $deprecatedFunctionSig);
+
+ $deprecatedFunctionKey =~ s/\n$//; # remove the newline
+
+ unless (defined $publicInterfaces{$deprecatedFunctionKey}) {
+ warn "Deprecated method $deprecatedFunctionKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the OldStyleObjC IDL attribute removed";
+ $fatalError = 1;
+ }
+
+ delete $publicInterfaces{$deprecatedFunctionKey};
+ }
+ }
+
+ if (@headerFunctions > 0) {
+ push(@headerContent, "\n") if $buildingForLeopardOrLater and @headerAttributes > 0;
+ push(@headerContent, @headerFunctions);
+ }
+ }
+
+ if (@deprecatedHeaderFunctions > 0 && $isProtocol) {
+ push(@headerContent, @deprecatedHeaderFunctions);
+ }
+
+ # - End @interface or @protocol
+ push(@headerContent, "\@end\n");
+
+ if (@deprecatedHeaderFunctions > 0 && !$isProtocol) {
+ # - Deprecated category @interface
+ push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n");
+ push(@headerContent, @deprecatedHeaderFunctions);
+ push(@headerContent, "\@end\n");
+ }
+
+ my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement);
+
+ if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0
+ or exists $alwaysGenerateForNoSVGBuild{$className}) {
+ # - Private category @interface
+ @privateHeaderContentHeader = split("\r", $headerLicenceTemplate);
+ push(@headerContentHeader, "\n");
+
+ my $classHeaderName = GetClassHeaderName($className);
+ push(@privateHeaderContentHeader, "#import <WebCore/$classHeaderName.h>\n\n");
+
+ @privateHeaderContent = ();
+ push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n");
+ push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0;
+ push(@privateHeaderContent, "\n") if $buildingForLeopardOrLater and @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0;
+ push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0;
+ push(@privateHeaderContent, "\@end\n");
+ }
+}
+
+sub GenerateImplementation
+{
+ my $object = shift;
+ my $dataNode = shift;
+
+ # We only support multiple parents with SVG (for now).
+ if (@{$dataNode->parents} > 1) {
+ die "A class can't have more than one parent" unless $module eq "svg";
+ $codeGenerator->AddMethodsConstantsAndAttributesFromParentClasses($dataNode);
+ }
+
+ my $interfaceName = $dataNode->name;
+ my $className = GetClassName($interfaceName);
+ my $implClassName = GetImplClassName($interfaceName);
+ my $parentImplClassName = GetParentImplClassName($dataNode);
+ my $implClassNameWithNamespace = "WebCore::" . $implClassName;
+ my $baseClass = GetBaseClass($parentImplClassName);
+ my $classHeaderName = GetClassHeaderName($className);
+ my $conditional = $dataNode->extendedAttributes->{"Conditional"};
+
+ my $numAttributes = @{$dataNode->attributes};
+ my $numFunctions = @{$dataNode->functions};
+
+ my $podType = $dataNode->extendedAttributes->{"PODType"};
+ my $podTypeWithNamespace;
+
+ if ($podType) {
+ $podTypeWithNamespace = ($podType eq "float") ? "$podType" : "WebCore::$podType";
+ }
+
+ # - Add default header template.
+ @implContentHeader = split("\r", $implementationLicenceTemplate);
+
+ # - INCLUDES -
+ push(@implContentHeader, "\n#import \"config.h\"\n");
+
+ my $conditionalString;
+ if ($conditional) {
+ $conditionalString = "ENABLE(" . join(") && ENABLE(", split(/&/, $conditional)) . ")";
+ push(@implContentHeader, "\n#if ${conditionalString}\n");
+ }
+
+ push(@implContentHeader, "\n#import \"$classHeaderName.h\"\n\n");
+
+ push(@implContentHeader, "#import \"ThreadCheck.h\"\n");
+ push(@implContentHeader, "#import <wtf/GetPtr.h>\n\n");
+
+ if ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
+ $implIncludes{"SVGAnimatedTemplate.h"} = 1;
+ } elsif ($interfaceName =~ /(\w+)(Abs|Rel)$/) {
+ $implIncludes{"$1.h"} = 1;
+ } else {
+ if (!$podType) {
+ $implIncludes{"$implClassName.h"} = 1;
+ } else {
+ $implIncludes{"$podType.h"} = 1 unless $podType eq "float";
+ }
+ }
+
+ $implIncludes{"DOMInternal.h"} = 1;
+ $implIncludes{"ExceptionHandlers.h"} = 1;
+
+ @implContent = ();
+
+ # add implementation accessor
+ if ($podType) {
+ push(@implContent, "#define IMPL reinterpret_cast<$podTypeWithNamespace*>(_internal)\n\n");
+ } elsif ($parentImplClassName eq "Object") {
+ push(@implContent, "#define IMPL reinterpret_cast<$implClassNameWithNamespace*>(_internal)\n\n");
+ } else {
+ my $baseClassWithNamespace = "WebCore::$baseClass";
+ push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n");
+ }
+
+ # START implementation
+ push(@implContent, "\@implementation $className\n\n");
+
+ # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject.
+ if ($parentImplClassName eq "Object") {
+ my @ivarsToRelease = ();
+ if (@ivars > 0) {
+ foreach $attribute (@ivars) {
+ my $name = "m_" . $attribute->signature->name;
+ push(@ivarsToRelease, " [$name release];\n");
+ }
+ }
+
+ push(@implContent, "- (void)dealloc\n");
+ push(@implContent, "{\n");
+ push(@implContent, " $assertMainThread\n");
+ push(@implContent, @ivarsToRelease);
+ if ($interfaceName eq "NodeIterator") {
+ push(@implContent, " if (_internal) {\n");
+ push(@implContent, " [self detach];\n");
+ push(@implContent, " IMPL->deref();\n");
+ push(@implContent, " };\n");
+ } elsif ($podType) {
+ push(@implContent, " delete IMPL;\n");
+ } else {
+ push(@implContent, " if (_internal)\n");
+ push(@implContent, " IMPL->deref();\n");
+ }
+ push(@implContent, " [super dealloc];\n");
+ push(@implContent, "}\n\n");
+
+ push(@implContent, "- (void)finalize\n");
+ push(@implContent, "{\n");
+ if ($interfaceName eq "NodeIterator") {
+ push(@implContent, " if (_internal) {\n");
+ push(@implContent, " [self detach];\n");
+ push(@implContent, " IMPL->deref();\n");
+ push(@implContent, " };\n");
+ } elsif ($podType) {
+ push(@implContent, " delete IMPL;\n");
+ } else {
+ push(@implContent, " if (_internal)\n");
+ push(@implContent, " IMPL->deref();\n");
+ }
+ push(@implContent, " [super finalize];\n");
+ push(@implContent, "}\n\n");
+
+ }
+
+ %attributeNames = ();
+
+ # - Attributes
+ if ($numAttributes > 0) {
+ foreach my $attribute (@{$dataNode->attributes}) {
+ AddIncludesForType($attribute->signature->type);
+
+ my $idlType = $codeGenerator->StripModule($attribute->signature->type);
+
+ my $attributeName = $attribute->signature->name;
+ my $attributeType = GetObjCType($attribute->signature->type);
+ my $attributeIsReadonly = ($attribute->type =~ /^readonly/);
+ my $attributeClassName = GetClassName($attribute->signature->type);
+
+ my $attributeInterfaceName = $attributeName;
+ if ($attributeName eq "id" or $attributeName eq "hash") {
+ # Special case attributes id and hash to be idName and hashName to avoid ObjC naming conflict.
+ $attributeInterfaceName .= "Name";
+ } elsif ($attributeName eq "frame") {
+ # Special case attribute frame to be frameBorders.
+ $attributeInterfaceName .= "Borders";
+ } elsif ($attributeName eq "ownerDocument") {
+ # FIXME: for now special case attribute ownerDocument to call document, this is incorrect
+ # legacy behavior. (see http://bugs.webkit.org/show_bug.cgi?id=10889)
+ $attributeName = "document";
+ } elsif ($codeGenerator->IsSVGAnimatedType($idlType)) {
+ # Special case for animated types.
+ $attributeName .= "Animated";
+ }
+
+ $attributeNames{$attributeInterfaceName} = 1;
+
+ # - GETTER
+ my $getterSig = "- ($attributeType)$attributeInterfaceName\n";
+ my $hasGetterException = @{$attribute->getterExceptions};
+ my $getterContentHead = "IMPL->" . $codeGenerator->WK_lcfirst($attributeName) . "(";
+ my $getterContentTail = ")";
+
+ # Special case for DOMSVGNumber
+ if ($podType and $podType eq "float") {
+ $getterContentHead = "*IMPL";
+ $getterContentTail = "";
+ }
+
+ my $attributeTypeSansPtr = $attributeType;
+ $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types.
+
+ # special case for EventTarget protocol
+ $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget";
+
+ my $typeMaker = GetObjCTypeMaker($attribute->signature->type);
+
+ # Special cases
+ my @customGetterContent = ();
+ if ($attributeTypeSansPtr eq "DOMImplementation") {
+ # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed
+ $getterContentHead = "[$attributeTypeSansPtr $typeMaker:implementationFront(IMPL";
+ $getterContentTail .= "]";
+ } elsif ($attributeName =~ /(\w+)DisplayString$/) {
+ my $attributeToDisplay = $1;
+ $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), [self _element]";
+ } elsif ($attributeName =~ /^absolute(\w+)URL$/) {
+ my $typeOfURL = $1;
+ $getterContentHead = "[self _getURLAttribute:";
+ if ($typeOfURL eq "Link") {
+ $getterContentTail = "\@\"href\"]";
+ } elsif ($typeOfURL eq "Image") {
+ if ($interfaceName eq "HTMLObjectElement") {
+ $getterContentTail = "\@\"data\"]";
+ } else {
+ $getterContentTail = "\@\"src\"]";
+ }
+ unless ($interfaceName eq "HTMLImageElement") {
+ push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n");
+ push(@customGetterContent, " return nil;\n");
+ $implIncludes{"RenderObject.h"} = 1;
+ }
+ }
+ $implIncludes{"DOMPrivate.h"} = 1;
+ } elsif ($idlType eq "NodeFilter") {
+ push(@customGetterContent, " if (m_filter)\n");
+ push(@customGetterContent, " // This node iterator was created from the Objective-C side.\n");
+ push(@customGetterContent, " return [[m_filter retain] autorelease];\n\n");
+ push(@customGetterContent, " // This node iterator was created from the C++ side.\n");
+ $getterContentHead = "[$attributeClassName $typeMaker:WTF::getPtr(" . $getterContentHead;
+ $getterContentTail .= ")]";
+ } elsif ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
+ $getterContentHead = "WebCore::String::number(" . $getterContentHead;
+ $getterContentTail .= ")";
+ } elsif ($attribute->signature->extendedAttributes->{"ConvertFromString"}) {
+ $getterContentTail .= ".toInt()";
+ } elsif ($codeGenerator->IsPodType($idlType)) {
+ $getterContentHead = "[$attributeTypeSansPtr $typeMaker:" . $getterContentHead;
+ $getterContentTail .= "]";
+ } elsif ($typeMaker ne "") {
+ # Surround getter with TypeMaker
+ $getterContentHead = "[$attributeTypeSansPtr $typeMaker:WTF::getPtr(" . $getterContentHead;
+ $getterContentTail .= ")]";
+ }
+
+ my $getterContent;
+ if ($hasGetterException) {
+ $getterContent = $getterContentHead . "ec" . $getterContentTail;
+ } else {
+ $getterContent = $getterContentHead . $getterContentTail;
+ }
+
+ push(@implContent, $getterSig);
+ push(@implContent, "{\n");
+ push(@implContent, @customGetterContent);
+ if ($hasGetterException) {
+ # Differentiated between when the return type is a pointer and
+ # not for white space issue (ie. Foo *result vs. int result).
+ if ($attributeType =~ /\*$/) {
+ $getterContent = $attributeType . "result = " . $getterContent;
+ } else {
+ $getterContent = $attributeType . " result = " . $getterContent;
+ }
+
+ push(@implContent, " $exceptionInit\n");
+ push(@implContent, " $getterContent;\n");
+ push(@implContent, " $exceptionRaiseOnError\n");
+ push(@implContent, " return result;\n");
+ } else {
+ push(@implContent, " return $getterContent;\n");
+ }
+ push(@implContent, "}\n\n");
+
+ # - SETTER
+ if (!$attributeIsReadonly) {
+ # Exception handling
+ my $hasSetterException = @{$attribute->setterExceptions};
+
+ $attributeName = "set" . $codeGenerator->WK_ucfirst($attributeName);
+ my $setterName = "set" . ucfirst($attributeInterfaceName);
+ my $argName = "new" . ucfirst($attributeInterfaceName);
+ my $arg = GetObjCTypeGetter($argName, $idlType);
+
+ # The definition of ConvertFromString and ConvertToString is flipped for the setter
+ if ($attribute->signature->extendedAttributes->{"ConvertFromString"}) {
+ $arg = "WebCore::String::number($arg)";
+ } elsif ($attribute->signature->extendedAttributes->{"ConvertToString"}) {
+ $arg = "WebCore::String($arg).toInt()";
+ }
+
+ my $setterSig = "- (void)$setterName:($attributeType)$argName\n";
+
+ push(@implContent, $setterSig);
+ push(@implContent, "{\n");
+
+ unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
+ push(@implContent, " ASSERT($argName);\n\n");
+ }
+
+ if ($podType) {
+ # Special case for DOMSVGNumber
+ if ($podType eq "float") {
+ push(@implContent, " *IMPL = $arg;\n");
+ } else {
+ push(@implContent, " IMPL->$attributeName($arg);\n");
+ }
+ } elsif ($hasSetterException) {
+ push(@implContent, " $exceptionInit\n");
+ push(@implContent, " IMPL->$attributeName($arg, ec);\n");
+ push(@implContent, " $exceptionRaiseOnError\n");
+ } else {
+ push(@implContent, " IMPL->$attributeName($arg);\n");
+ }
+
+ push(@implContent, "}\n\n");
+ }
+ }
+ }
+
+ my @deprecatedFunctions = ();
+
+ # - Functions
+ if ($numFunctions > 0) {
+ foreach my $function (@{$dataNode->functions}) {
+ AddIncludesForType($function->signature->type);
+
+ my $functionName = $function->signature->name;
+ my $returnType = GetObjCType($function->signature->type);
+ my $hasParameters = @{$function->parameters};
+ my $raisesExceptions = @{$function->raisesExceptions};
+
+ my @parameterNames = ();
+ my @needsAssert = ();
+ my %needsCustom = ();
+
+ my $parameterIndex = 0;
+ my $functionSig = "- ($returnType)$functionName";
+ foreach my $param (@{$function->parameters}) {
+ my $paramName = $param->name;
+ my $paramType = GetObjCType($param->type);
+
+ # make a new parameter name if the original conflicts with a property name
+ $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName};
+
+ AddIncludesForType($param->type);
+
+ my $idlType = $codeGenerator->StripModule($param->type);
+ my $implGetter = GetObjCTypeGetter($paramName, $idlType);
+
+ push(@parameterNames, $implGetter);
+ $needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver";
+ $needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget";
+ $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"Return"};
+
+ unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) {
+ push(@needsAssert, " ASSERT($paramName);\n");
+ }
+
+ if ($parameterIndex >= 1) {
+ my $paramPrefix = $param->extendedAttributes->{"ObjCPrefix"};
+ $paramPrefix = $param->name unless defined($paramPrefix);
+ $functionSig .= " $paramPrefix";
+ }
+
+ $functionSig .= ":($paramType)$paramName";
+
+ $parameterIndex++;
+ }
+
+ my @functionContent = ();
+ my $caller = "IMPL";
+
+ # special case the XPathNSResolver
+ if (defined $needsCustom{"XPathNSResolver"}) {
+ my $paramName = $needsCustom{"XPathNSResolver"};
+ push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n");
+ push(@functionContent, " RefPtr<WebCore::XPathNSResolver> customResolver;\n");
+ push(@functionContent, " if ($paramName) {\n");
+ push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n");
+ push(@functionContent, " nativeResolver = [(DOMNativeXPathNSResolver *)$paramName _xpathNSResolver];\n");
+ push(@functionContent, " else {\n");
+ push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n");
+ push(@functionContent, " nativeResolver = customResolver.get();\n");
+ push(@functionContent, " }\n");
+ push(@functionContent, " }\n");
+ }
+
+ # special case the EventTarget
+ if (defined $needsCustom{"EventTarget"}) {
+ my $paramName = $needsCustom{"EventTarget"};
+ push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n");
+ push(@functionContent, " WebCore::Node* ${paramName}Node = [${paramName}ObjC _node];\n");
+ push(@functionContent, " WebCore::EventTargetNode* ${paramName}EventTarget = (${paramName}Node && ${paramName}Node->isEventTargetNode()) ? static_cast<WebCore::EventTargetNode*>(${paramName}Node) : 0;\n\n");
+ $implIncludes{"DOMNode.h"} = 1;
+ $implIncludes{"Node.h"} = 1;
+ }
+
+ if ($function->signature->extendedAttributes->{"UsesView"}) {
+ push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n");
+ push(@functionContent, " if (!dv)\n");
+ push(@functionContent, " return nil;\n");
+ $implIncludes{"DOMWindow.h"} = 1;
+ $caller = "dv";
+ }
+
+ # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGMatrixCustom.mm
+ my $svgMatrixRotateFromVector = ($podType and $podType eq "AffineTransform" and $functionName eq "rotateFromVector");
+ my $svgMatrixInverse = ($podType and $podType eq "AffineTransform" and $functionName eq "inverse");
+
+ push(@parameterNames, "ec") if $raisesExceptions and !($svgMatrixRotateFromVector || $svgMatrixInverse);
+ my $content = $caller . "->" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")";
+
+ if ($svgMatrixRotateFromVector) {
+ # Special case with rotateFromVector & SVGMatrix
+ push(@functionContent, " $exceptionInit\n");
+ push(@functionContent, " if (x == 0.0 || y == 0.0)\n");
+ push(@functionContent, " ec = WebCore::SVGException::SVG_INVALID_VALUE_ERR;\n");
+ push(@functionContent, " $exceptionRaiseOnError\n");
+ push(@functionContent, " return [DOMSVGMatrix _wrapSVGMatrix:$content];\n");
+ } elsif ($svgMatrixInverse) {
+ # Special case with inverse & SVGMatrix
+ push(@functionContent, " $exceptionInit\n");
+ push(@functionContent, " if (!$caller->isInvertible())\n");
+ push(@functionContent, " ec = WebCore::SVGException::SVG_MATRIX_NOT_INVERTABLE;\n");
+ push(@functionContent, " $exceptionRaiseOnError\n");
+ push(@functionContent, " return [DOMSVGMatrix _wrapSVGMatrix:$content];\n");
+ } elsif ($returnType eq "void") {
+ # Special case 'void' return type.
+ if ($raisesExceptions) {
+ push(@functionContent, " $exceptionInit\n");
+ push(@functionContent, " $content;\n");
+ push(@functionContent, " $exceptionRaiseOnError\n");
+ } else {
+ push(@functionContent, " $content;\n");
+ }
+ } elsif (defined $needsCustom{"NodeToReturn"}) {
+ # Special case the insertBefore, replaceChild, removeChild
+ # and appendChild functions from DOMNode
+ my $toReturn = $needsCustom{"NodeToReturn"};
+ if ($raisesExceptions) {
+ push(@functionContent, " $exceptionInit\n");
+ push(@functionContent, " if ($content)\n");
+ push(@functionContent, " return $toReturn;\n");
+ push(@functionContent, " $exceptionRaiseOnError\n");
+ push(@functionContent, " return nil;\n");
+ } else {
+ push(@functionContent, " if ($content)\n");
+ push(@functionContent, " return $toReturn;\n");
+ push(@functionContent, " return nil;\n");
+ }
+ } else {
+ my $typeMaker = GetObjCTypeMaker($function->signature->type);
+ unless ($typeMaker eq "") {
+ my $returnTypeClass = "";
+ if ($function->signature->type eq "XPathNSResolver") {
+ # Special case XPathNSResolver
+ $returnTypeClass = "DOMNativeXPathNSResolver";
+ } else {
+ # Remove trailing " *" from pointer types.
+ $returnTypeClass = $returnType;
+ $returnTypeClass =~ s/ \*$//;
+ }
+
+ # Surround getter with TypeMaker
+ my $idlType = $returnTypeClass;
+ $idlType =~ s/^DOM//;
+
+ if ($codeGenerator->IsPodType($idlType)) {
+ $content = "[$returnTypeClass $typeMaker:" . $content . "]";
+ } else {
+ $content = "[$returnTypeClass $typeMaker:WTF::getPtr(" . $content . ")]";
+ }
+ }
+
+ if ($raisesExceptions) {
+ # Differentiated between when the return type is a pointer and
+ # not for white space issue (ie. Foo *result vs. int result).
+ if ($returnType =~ /\*$/) {
+ $content = $returnType . "result = " . $content;
+ } else {
+ $content = $returnType . " result = " . $content;
+ }
+
+ push(@functionContent, " $exceptionInit\n");
+ push(@functionContent, " $content;\n");
+ push(@functionContent, " $exceptionRaiseOnError\n");
+ push(@functionContent, " return result;\n");
+ } else {
+ push(@functionContent, " return $content;\n");
+ }
+ }
+
+ push(@implContent, "$functionSig\n");
+ push(@implContent, "{\n");
+ push(@implContent, @functionContent);
+ push(@implContent, "}\n\n");
+
+ # generate the old style method names with un-named parameters, these methods are deprecated
+ if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"OldStyleObjC"}) {
+ my $deprecatedFunctionSig = $functionSig;
+ $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names
+
+ push(@deprecatedFunctions, "$deprecatedFunctionSig\n");
+ push(@deprecatedFunctions, "{\n");
+ push(@deprecatedFunctions, @functionContent);
+ push(@deprecatedFunctions, "}\n\n");
+ }
+
+ # Clear the hash
+ %needsCustom = ();
+ }
+ }
+
+ # END implementation
+ push(@implContent, "\@end\n");
+
+ if (@deprecatedFunctions > 0) {
+ # - Deprecated category @implementation
+ push(@implContent, "\n\@implementation $className (" . $className . "Deprecated)\n\n");
+ push(@implContent, @deprecatedFunctions);
+ push(@implContent, "\@end\n");
+ }
+
+
+ # Generate internal interfaces
+
+ # - Type-Getter
+ # - (WebCore::FooBar *)_fooBar for implementation class FooBar
+ my $typeGetterName = GetObjCTypeGetterName($interfaceName);
+ my $typeGetterSig = "- " . ($podType ? "($podTypeWithNamespace)" : "($implClassNameWithNamespace *)") . $typeGetterName;
+
+ my @ivarsToRetain = ();
+ my $ivarsToInit = "";
+ my $typeMakerSigAddition = "";
+ if (@ivars > 0) {
+ my @ivarsInitSig = ();
+ my @ivarsInitCall = ();
+ foreach $attribute (@ivars) {
+ my $name = $attribute->signature->name;
+ my $memberName = "m_" . $name;
+ my $varName = "in" . $name;
+ my $type = GetObjCType($attribute->signature->type);
+ push(@ivarsInitSig, "$name:($type)$varName");
+ push(@ivarsInitCall, "$name:$varName");
+ push(@ivarsToRetain, " $memberName = [$varName retain];\n");
+ }
+ $ivarsToInit = " " . join(" ", @ivarsInitCall);
+ $typeMakerSigAddition = " " . join(" ", @ivarsInitSig);
+ }
+
+ # - Type-Maker
+ my $typeMakerName = GetObjCTypeMaker($interfaceName);
+ my $typeMakerSig = "+ ($className *)$typeMakerName:($implClassNameWithNamespace *)impl" . $typeMakerSigAddition;
+ $typeMakerSig = "+ ($className *)$typeMakerName:($podTypeWithNamespace)impl" . $typeMakerSigAddition if $podType;
+
+ # Generate interface definitions.
+ @internalHeaderContent = split("\r", $implementationLicenceTemplate);
+ push(@internalHeaderContent, "\n#import <WebCore/$className.h>\n");
+ if ($interfaceName eq "Node") {
+ push(@internalHeaderContent, "\n\@protocol DOMEventTarget;\n");
+ }
+ if ($codeGenerator->IsSVGAnimatedType($interfaceName)) {
+ push(@internalHeaderContent, "#import <WebCore/SVGAnimatedTemplate.h>\n\n");
+ } else {
+ if ($podType and $podType ne "float") {
+ push(@internalHeaderContent, "\nnamespace WebCore { class $podType; }\n\n");
+ } elsif ($interfaceName eq "Node") {
+ push(@internalHeaderContent, "\nnamespace WebCore { class Node; class EventTarget; }\n\n");
+ } else {
+ push(@internalHeaderContent, "\nnamespace WebCore { class $implClassName; }\n\n");
+ }
+ }
+
+ push(@internalHeaderContent, "\@interface $className (WebCoreInternal)\n");
+ push(@internalHeaderContent, $typeGetterSig . ";\n");
+ push(@internalHeaderContent, $typeMakerSig . ";\n");
+ if ($interfaceName eq "Node") {
+ push(@internalHeaderContent, "+ (id <DOMEventTarget>)_wrapEventTarget:(WebCore::EventTarget *)eventTarget;\n");
+ }
+ push(@internalHeaderContent, "\@end\n");
+
+ unless ($dataNode->extendedAttributes->{ObjCCustomInternalImpl}) {
+ # - BEGIN WebCoreInternal category @implementation
+ push(@implContent, "\n\@implementation $className (WebCoreInternal)\n\n");
+
+ push(@implContent, "$typeGetterSig\n");
+ push(@implContent, "{\n");
+
+ if ($podType) {
+ push(@implContent, " return *IMPL;\n");
+ } else {
+ push(@implContent, " return IMPL;\n");
+ }
+
+ push(@implContent, "}\n\n");
+
+ if ($podType) {
+ # - (id)_initWithFooBar:(WebCore::FooBar)impl for implementation class FooBar
+ my $initWithImplName = "_initWith" . $implClassName;
+ my $initWithSig = "- (id)$initWithImplName:($podTypeWithNamespace)impl" . $typeMakerSigAddition;
+
+ # FIXME: Implement Caching
+ push(@implContent, "$initWithSig\n");
+ push(@implContent, "{\n");
+ push(@implContent, " $assertMainThread;\n");
+ push(@implContent, " [super _init];\n");
+ push(@implContent, " $podTypeWithNamespace* _impl = new $podTypeWithNamespace(impl);\n");
+ push(@implContent, " _internal = reinterpret_cast<DOMObjectInternal*>(_impl);\n");
+ push(@implContent, " return self;\n");
+ push(@implContent, "}\n\n");
+
+ # - (DOMFooBar)_wrapFooBar:(WebCore::FooBar)impl for implementation class FooBar
+ push(@implContent, "$typeMakerSig\n");
+ push(@implContent, "{\n");
+ push(@implContent, " $assertMainThread;\n");
+ push(@implContent, " return [[[self alloc] $initWithImplName:impl] autorelease];\n");
+ push(@implContent, "}\n\n");
+ } elsif ($parentImplClassName eq "Object") {
+ # - (id)_initWithFooBar:(WebCore::FooBar *)impl for implementation class FooBar
+ my $initWithImplName = "_initWith" . $implClassName;
+ my $initWithSig = "- (id)$initWithImplName:($implClassNameWithNamespace *)impl" . $typeMakerSigAddition;
+
+ push(@implContent, "$initWithSig\n");
+ push(@implContent, "{\n");
+ push(@implContent, " $assertMainThread;\n");
+ push(@implContent, " [super _init];\n");
+ push(@implContent, " _internal = reinterpret_cast<DOMObjectInternal*>(impl);\n");
+ push(@implContent, " impl->ref();\n");
+ push(@implContent, " WebCore::addDOMWrapper(self, impl);\n");
+ push(@implContent, @ivarsToRetain);
+ push(@implContent, " return self;\n");
+ push(@implContent, "}\n\n");
+
+ # - (DOMFooBar)_wrapFooBar:(WebCore::FooBar *)impl for implementation class FooBar
+ push(@implContent, "$typeMakerSig\n");
+ push(@implContent, "{\n");
+ push(@implContent, " $assertMainThread;\n");
+ push(@implContent, " if (!impl)\n");
+ push(@implContent, " return nil;\n");
+ push(@implContent, " id cachedInstance;\n");
+ push(@implContent, " cachedInstance = WebCore::getDOMWrapper(impl);\n");
+ push(@implContent, " if (cachedInstance)\n");
+ push(@implContent, " return [[cachedInstance retain] autorelease];\n");
+ push(@implContent, " return [[[self alloc] $initWithImplName:impl" . $ivarsToInit . "] autorelease];\n");
+ push(@implContent, "}\n\n");
+ } else {
+ my $internalBaseType = "DOM$baseClass";
+ my $internalBaseTypeMaker = GetObjCTypeMaker($baseClass);
+
+ # - (DOMFooBar)_wrapFooBar:(WebCore::FooBar *)impl for implementation class FooBar
+ push(@implContent, "$typeMakerSig\n");
+ push(@implContent, "{\n");
+ push(@implContent, " $assertMainThread;\n");
+ push(@implContent, " return static_cast<$className*>([$internalBaseType $internalBaseTypeMaker:impl]);\n");
+ push(@implContent, "}\n\n");
+ }
+
+ # END WebCoreInternal category
+ push(@implContent, "\@end\n");
+ }
+
+ # - End the ifdef conditional if necessary
+ push(@implContent, "\n#endif // ${conditionalString}\n") if $conditional;
+}
+
+# Internal helper
+sub WriteData
+{
+ my $object = shift;
+ my $name = shift;
+
+ # Open files for writing...
+ my $headerFileName = "$outputDir/" . $name . ".h";
+ my $privateHeaderFileName = "$outputDir/" . $name . "Private.h";
+ my $implFileName = "$outputDir/" . $name . ".mm";
+ my $internalHeaderFileName = "$outputDir/" . $name . "Internal.h";
+
+ # Remove old files.
+ unlink($headerFileName);
+ unlink($privateHeaderFileName);
+ unlink($implFileName);
+ unlink($internalHeaderFileName);
+
+ # Write public header.
+ open(HEADER, ">$headerFileName") or die "Couldn't open file $headerFileName";
+
+ print HEADER @headerContentHeader;
+ print HEADER map { "\@class $_;\n" } sort keys(%headerForwardDeclarations);
+ print HEADER map { "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols);
+
+ my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols);
+ print HEADER "\n" if $hasForwardDeclarations;
+ print HEADER @headerContent;
+
+ close(HEADER);
+
+ @headerContentHeader = ();
+ @headerContent = ();
+ %headerForwardDeclarations = ();
+ %headerForwardDeclarationsForProtocols = ();
+
+ if (@privateHeaderContent > 0) {
+ open(PRIVATE_HEADER, ">$privateHeaderFileName") or die "Couldn't open file $privateHeaderFileName";
+
+ print PRIVATE_HEADER @privateHeaderContentHeader;
+ print PRIVATE_HEADER map { "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations);
+ print PRIVATE_HEADER map { "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols);
+
+ $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols);
+ print PRIVATE_HEADER "\n" if $hasForwardDeclarations;
+ print PRIVATE_HEADER @privateHeaderContent;
+
+ close(PRIVATE_HEADER);
+
+ @privateHeaderContentHeader = ();
+ @privateHeaderContent = ();
+ %privateHeaderForwardDeclarations = ();
+ %privateHeaderForwardDeclarationsForProtocols = ();
+ }
+
+ # Write implementation file.
+ unless ($noImpl) {
+ open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName";
+
+ print IMPL @implContentHeader;
+ print IMPL map { "#import \"$_\"\n" } sort keys(%implIncludes);
+
+ print IMPL "\n" if keys(%implIncludes);
+ print IMPL @implContent;
+
+ close(IMPL);
+
+ @implContentHeader = ();
+ @implContent = ();
+ %implIncludes = ();
+ }
+
+ if (@internalHeaderContent > 0) {
+ open(INTERNAL_HEADER, ">$internalHeaderFileName") or die "Couldn't open file $internalHeaderFileName";
+
+ print INTERNAL_HEADER @internalHeaderContent;
+
+ close(INTERNAL_HEADER);
+
+ @internalHeaderContent = ();
+ }
+}
+
+1;
diff --git a/WebCore/bindings/scripts/IDLParser.pm b/WebCore/bindings/scripts/IDLParser.pm
new file mode 100644
index 0000000..de7cf9c
--- /dev/null
+++ b/WebCore/bindings/scripts/IDLParser.pm
@@ -0,0 +1,416 @@
+#
+# KDOM IDL parser
+#
+# Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org>
+#
+# This file is part of the KDE project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# aint with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+
+package IDLParser;
+
+use IPC::Open2;
+use IDLStructure;
+
+use constant MODE_UNDEF => 0; # Default mode.
+
+use constant MODE_MODULE => 10; # 'module' section
+use constant MODE_INTERFACE => 11; # 'interface' section
+use constant MODE_EXCEPTION => 12; # 'exception' section
+use constant MODE_ALIAS => 13; # 'alias' section
+
+# Helper variables
+my @temporaryContent = "";
+
+my $parseMode = MODE_UNDEF;
+my $preservedParseMode = MODE_UNDEF;
+
+my $beQuiet; # Should not display anything on STDOUT?
+my $document = 0; # Will hold the resulting 'idlDocument'
+
+# Default Constructor
+sub new
+{
+ my $object = shift;
+ my $reference = { };
+
+ $document = 0;
+ $beQuiet = shift;
+
+ bless($reference, $object);
+ return $reference;
+}
+
+# Returns the parsed 'idlDocument'
+sub Parse
+{
+ my $object = shift;
+ my $fileName = shift;
+ my $defines = shift;
+ my $preprocessor = shift;
+
+ if (!$preprocessor) {
+ $preprocessor = "/usr/bin/gcc -E -P -x c++";
+ }
+
+ if (!$defines) {
+ $defines = "";
+ }
+
+ print " | *** Starting to parse $fileName...\n |\n" unless $beQuiet;
+
+ open2(\*PP_OUT, \*PP_IN, split(' ', $preprocessor), (map { "-D$_" } split(' ', $defines)), $fileName);
+ close PP_IN;
+ my @documentContent = <PP_OUT>;
+ close PP_OUT;
+
+ my $dataAvailable = 0;
+
+ # Simple IDL Parser (tm)
+ foreach (@documentContent) {
+ my $newParseMode = $object->DetermineParseMode($_);
+
+ if ($newParseMode ne MODE_UNDEF) {
+ if ($dataAvailable eq 0) {
+ $dataAvailable = 1; # Start node building...
+ } else {
+ $object->ProcessSection();
+ }
+ }
+
+ # Update detected data stream mode...
+ if ($newParseMode ne MODE_UNDEF) {
+ $parseMode = $newParseMode;
+ }
+
+ push(@temporaryContent, $_);
+ }
+
+ # Check if there is anything remaining to parse...
+ if (($parseMode ne MODE_UNDEF) and ($#temporaryContent > 0)) {
+ $object->ProcessSection();
+ }
+
+ print " | *** Finished parsing!\n" unless $beQuiet;
+
+ $document->fileName($fileName);
+
+ return $document;
+}
+
+sub ParseModule
+{
+ my $object = shift;
+ my $dataNode = shift;
+
+ print " |- Trying to parse module...\n" unless $beQuiet;
+
+ my $data = join("", @temporaryContent);
+ $data =~ /$IDLStructure::moduleSelector/;
+
+ my $moduleName = (defined($1) ? $1 : die("Parsing error!\nSource:\n$data\n)"));
+ $dataNode->module($moduleName);
+
+ print " |----> Module; NAME \"$moduleName\"\n |-\n |\n" unless $beQuiet;
+}
+
+sub dumpExtendedAttributes
+{
+ my $padStr = shift;
+ my $attrs = shift;
+
+ if (!%{$attrs}) {
+ return "";
+ }
+
+ my @temp;
+ while (($name, $value) = each(%{$attrs})) {
+ push(@temp, "$name=$value");
+ }
+
+ return $padStr . "[" . join(", ", @temp) . "]";
+}
+
+sub parseExtendedAttributes
+{
+ my $str = shift;
+ $str =~ s/\[\s*(.*?)\s*\]/$1/g;
+
+ my %attrs = ();
+
+ foreach my $value (split(/\s*,\s*/, $str)) {
+ ($name,$value) = split(/\s*=\s*/, $value, 2);
+
+ # Attributes with no value are set to be true
+ $value = 1 unless defined $value;
+ $attrs{$name} = $value;
+ }
+
+ return \%attrs;
+}
+
+sub ParseInterface
+{
+ my $object = shift;
+ my $dataNode = shift;
+ my $sectionName = shift;
+
+ my $data = join("", @temporaryContent);
+
+ # Look for end-of-interface mark
+ $data =~ /};/g;
+ $data = substr($data, index($data, $sectionName), pos($data) - length($data));
+
+ $data =~ s/[\n\r]/ /g;
+
+ # Beginning of the regexp parsing magic
+ if ($sectionName eq "exception") {
+ print " |- Trying to parse exception...\n" unless $beQuiet;
+
+ my $exceptionName = "";
+ my $exceptionData = "";
+ my $exceptionDataName = "";
+ my $exceptionDataType = "";
+
+ # Match identifier of the exception, and enclosed data...
+ $data =~ /$IDLStructure::exceptionSelector/;
+ $exceptionName = (defined($1) ? $1 : die("Parsing error!\nSource:\n$data\n)"));
+ $exceptionData = (defined($2) ? $2 : die("Parsing error!\nSource:\n$data\n)"));
+
+ ('' =~ /^/); # Reset variables needed for regexp matching
+
+ # ... parse enclosed data (get. name & type)
+ $exceptionData =~ /$IDLStructure::exceptionSubSelector/;
+ $exceptionDataType = (defined($1) ? $1 : die("Parsing error!\nSource:\n$data\n)"));
+ $exceptionDataName = (defined($2) ? $2 : die("Parsing error!\nSource:\n$data\n)"));
+
+ # Fill in domClass datastructure
+ $dataNode->name($exceptionName);
+
+ my $newDataNode = new domAttribute();
+ $newDataNode->type("readonly attribute");
+ $newDataNode->signature(new domSignature());
+
+ $newDataNode->signature->name($exceptionDataName);
+ $newDataNode->signature->type($exceptionDataType);
+
+ my $arrayRef = $dataNode->attributes;
+ push(@$arrayRef, $newDataNode);
+
+ print " |----> Exception; NAME \"$exceptionName\" DATA TYPE \"$exceptionDataType\" DATA NAME \"$exceptionDataName\"\n |-\n |\n" unless $beQuiet;
+ } elsif ($sectionName eq "interface") {
+ print " |- Trying to parse interface...\n" unless $beQuiet;
+
+ my $interfaceName = "";
+ my $interfaceData = "";
+
+ # Match identifier of the interface, and enclosed data...
+ $data =~ /$IDLStructure::interfaceSelector/;
+
+ $interfaceExtendedAttributes = (defined($1) ? $1 : " "); chop($interfaceExtendedAttributes);
+ $interfaceName = (defined($2) ? $2 : die("Parsing error!\nSource:\n$data\n)"));
+ $interfaceBase = (defined($3) ? $3 : "");
+ $interfaceData = (defined($4) ? $4 : die("Parsing error!\nSource:\n$data\n)"));
+
+ # Fill in known parts of the domClass datastructure now...
+ $dataNode->name($interfaceName);
+ $dataNode->extendedAttributes(parseExtendedAttributes($interfaceExtendedAttributes));
+
+ # Inheritance detection
+ my @interfaceParents = split(/,/, $interfaceBase);
+ foreach(@interfaceParents) {
+ my $line = $_;
+ $line =~ s/\s*//g;
+
+ my $arrayRef = $dataNode->parents;
+ push(@$arrayRef, $line);
+ }
+
+ $interfaceData =~ s/[\n\r]/ /g;
+ my @interfaceMethods = split(/;/, $interfaceData);
+
+ foreach my $line (@interfaceMethods) {
+ if ($line =~ /attribute/) {
+ $line =~ /$IDLStructure::interfaceAttributeSelector/;
+
+ my $attributeType = (defined($1) ? $1 : die("Parsing error!\nSource:\n$line\n)"));
+ my $attributeExtendedAttributes = (defined($2) ? $2 : " "); chop($attributeExtendedAttributes);
+
+ my $attributeDataType = (defined($3) ? $3 : die("Parsing error!\nSource:\n$line\n)"));
+ my $attributeDataName = (defined($4) ? $4 : die("Parsing error!\nSource:\n$line\n)"));
+
+ ('' =~ /^/); # Reset variables needed for regexp matching
+
+ $line =~ /$IDLStructure::getterRaisesSelector/;
+ my $getterException = (defined($1) ? $1 : "");
+
+ $line =~ /$IDLStructure::setterRaisesSelector/;
+ my $setterException = (defined($1) ? $1 : "");
+
+ my $newDataNode = new domAttribute();
+ $newDataNode->type($attributeType);
+ $newDataNode->signature(new domSignature());
+
+ $newDataNode->signature->name($attributeDataName);
+ $newDataNode->signature->type($attributeDataType);
+ $newDataNode->signature->extendedAttributes(parseExtendedAttributes($attributeExtendedAttributes));
+
+ my $arrayRef = $dataNode->attributes;
+ push(@$arrayRef, $newDataNode);
+
+ print " | |> Attribute; TYPE \"$attributeType\" DATA NAME \"$attributeDataName\" DATA TYPE \"$attributeDataType\" GET EXCEPTION? \"$getterException\" SET EXCEPTION? \"$setterException\"" .
+ dumpExtendedAttributes("\n | ", $newDataNode->signature->extendedAttributes) . "\n" unless $beQuiet;
+
+ $getterException =~ s/\s+//g;
+ $setterException =~ s/\s+//g;
+ @{$newDataNode->getterExceptions} = split(/,/, $getterException);
+ @{$newDataNode->setterExceptions} = split(/,/, $setterException);
+ } elsif (($line !~ s/^\s*$//g) and ($line !~ /^\s*const/)) {
+ $line =~ /$IDLStructure::interfaceMethodSelector/ or die "Parsing error!\nSource:\n$line\n)";
+
+ my $methodExtendedAttributes = (defined($1) ? $1 : " "); chop($methodExtendedAttributes);
+ my $methodType = (defined($2) ? $2 : die("Parsing error!\nSource:\n$line\n)"));
+ my $methodName = (defined($3) ? $3 : die("Parsing error!\nSource:\n$line\n)"));
+ my $methodSignature = (defined($4) ? $4 : die("Parsing error!\nSource:\n$line\n)"));
+
+ ('' =~ /^/); # Reset variables needed for regexp matching
+
+ $line =~ /$IDLStructure::raisesSelector/;
+ my $methodException = (defined($1) ? $1 : "");
+
+ my $newDataNode = new domFunction();
+
+ $newDataNode->signature(new domSignature());
+ $newDataNode->signature->name($methodName);
+ $newDataNode->signature->type($methodType);
+ $newDataNode->signature->extendedAttributes(parseExtendedAttributes($methodExtendedAttributes));
+
+ print " | |- Method; TYPE \"$methodType\" NAME \"$methodName\" EXCEPTION? \"$methodException\"" .
+ dumpExtendedAttributes("\n | ", $newDataNode->signature->extendedAttributes) . "\n" unless $beQuiet;
+
+ $methodException =~ s/\s+//g;
+ @{$newDataNode->raisesExceptions} = split(/,/, $methodException);
+
+ my @params = split(/,/, $methodSignature);
+ foreach(@params) {
+ my $line = $_;
+
+ $line =~ /$IDLStructure::interfaceParameterSelector/;
+ my $paramExtendedAttributes = (defined($1) ? $1 : " "); chop($paramExtendedAttributes);
+ my $paramType = (defined($2) ? $2 : die("Parsing error!\nSource:\n$line\n)"));
+ my $paramName = (defined($3) ? $3 : die("Parsing error!\nSource:\n$line\n)"));
+
+ my $paramDataNode = new domSignature();
+ $paramDataNode->name($paramName);
+ $paramDataNode->type($paramType);
+ $paramDataNode->extendedAttributes(parseExtendedAttributes($paramExtendedAttributes));
+
+ my $arrayRef = $newDataNode->parameters;
+ push(@$arrayRef, $paramDataNode);
+
+ print " | |> Param; TYPE \"$paramType\" NAME \"$paramName\"" .
+ dumpExtendedAttributes("\n | ", $paramDataNode->extendedAttributes) . "\n" unless $beQuiet;
+ }
+
+ my $arrayRef = $dataNode->functions;
+ push(@$arrayRef, $newDataNode);
+ } elsif ($line =~ /^\s*const/) {
+ $line =~ /$IDLStructure::constantSelector/;
+ my $constType = (defined($1) ? $1 : die("Parsing error!\nSource:\n$line\n)"));
+ my $constName = (defined($2) ? $2 : die("Parsing error!\nSource:\n$line\n)"));
+ my $constValue = (defined($3) ? $3 : die("Parsing error!\nSource:\n$line\n)"));
+
+ my $newDataNode = new domConstant();
+ $newDataNode->name($constName);
+ $newDataNode->type($constType);
+ $newDataNode->value($constValue);
+
+ my $arrayRef = $dataNode->constants;
+ push(@$arrayRef, $newDataNode);
+
+ print " | |> Constant; TYPE \"$constType\" NAME \"$constName\" VALUE \"$constValue\"\n" unless $beQuiet;
+ }
+ }
+
+ print " |----> Interface; NAME \"$interfaceName\"" .
+ dumpExtendedAttributes("\n | ", $dataNode->extendedAttributes) . "\n |-\n |\n" unless $beQuiet;
+ }
+}
+
+# Internal helper
+sub DetermineParseMode
+{
+ my $object = shift;
+ my $line = shift;
+
+ my $mode = MODE_UNDEF;
+ if ($_ =~ /module/) {
+ $mode = MODE_MODULE;
+ } elsif ($_ =~ /interface/) {
+ $mode = MODE_INTERFACE;
+ } elsif ($_ =~ /exception/) {
+ $mode = MODE_EXCEPTION;
+ } elsif ($_ =~ /alias/) {
+ $mode = MODE_ALIAS;
+ }
+
+ return $mode;
+}
+
+# Internal helper
+sub ProcessSection
+{
+ my $object = shift;
+
+ if ($parseMode eq MODE_MODULE) {
+ die ("Two modules in one file! Fatal error!\n") if ($document ne 0);
+ $document = new idlDocument();
+ $object->ParseModule($document);
+ } elsif ($parseMode eq MODE_INTERFACE) {
+ my $node = new domClass();
+ $object->ParseInterface($node, "interface");
+
+ die ("No module specified! Fatal Error!\n") if ($document eq 0);
+ my $arrayRef = $document->classes;
+ push(@$arrayRef, $node);
+ } elsif($parseMode eq MODE_EXCEPTION) {
+ my $node = new domClass();
+ $object->ParseInterface($node, "exception");
+
+ die ("No module specified! Fatal Error!\n") if ($document eq 0);
+ my $arrayRef = $document->classes;
+ push(@$arrayRef, $node);
+ } elsif($parseMode eq MODE_ALIAS) {
+ print " |- Trying to parse alias...\n" unless $beQuiet;
+
+ my $line = join("", @temporaryContent);
+ $line =~ /$IDLStructure::aliasSelector/;
+
+ my $interfaceName = (defined($1) ? $1 : die("Parsing error!\nSource:\n$line\n)"));
+ my $wrapperName = (defined($2) ? $2 : die("Parsing error!\nSource:\n$line\n)"));
+
+ print " |----> Alias; INTERFACE \"$interfaceName\" WRAPPER \"$wrapperName\"\n |-\n |\n" unless $beQuiet;
+
+ # FIXME: Check if alias is already in aliases
+ my $aliases = $document->aliases;
+ $aliases->{$interfaceName} = $wrapperName;
+ }
+
+ @temporaryContent = "";
+}
+
+1;
diff --git a/WebCore/bindings/scripts/IDLStructure.pm b/WebCore/bindings/scripts/IDLStructure.pm
new file mode 100644
index 0000000..4d41350
--- /dev/null
+++ b/WebCore/bindings/scripts/IDLStructure.pm
@@ -0,0 +1,107 @@
+#
+# KDOM IDL parser
+#
+# Copyright (C) 2005 Nikolas Zimmermann <wildfox@kde.org>
+#
+# This file is part of the KDE project
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# aint with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+
+package IDLStructure;
+
+use Class::Struct;
+
+# Used to represent a parsed IDL document
+struct( idlDocument => {
+ module => '$', # Module identifier
+ classes => '@', # All parsed interfaces
+ fileName => '$' # file name
+});
+
+# Used to represent 'interface' / 'exception' blocks
+struct( domClass => {
+ name => '$', # Class identifier (without module)
+ parents => '@', # List of strings
+ constants => '@', # List of 'domConstant'
+ functions => '@', # List of 'domFunction'
+ attributes => '@', # List of 'domAttribute'
+ extendedAttributes => '$', # Extended attributes
+});
+
+# Used to represent domClass contents (name of method, signature)
+struct( domFunction => {
+ signature => '$', # Return type/Object name/extended attributes
+ parameters => '@', # List of 'domSignature'
+ raisesExceptions => '@', # Possibly raised exceptions.
+});
+
+# Used to represent domClass contents (name of attribute, signature)
+struct( domAttribute => {
+ type => '$', # Attribute type (including namespace)
+ signature => '$', # Attribute signature
+ getterExceptions => '@', # Possibly raised exceptions.
+ setterExceptions => '@', # Possibly raised exceptions.
+});
+
+# Used to represent a map of 'variable name' <-> 'variable type'
+struct( domSignature => {
+ name => '$', # Variable name
+ type => '$', # Variable type
+ extendedAttributes => '$' # Extended attributes
+});
+
+# Used to represent string constants
+struct( domConstant => {
+ name => '$', # DOM Constant identifier
+ type => '$', # Type of data
+ value => '$', # Constant value
+});
+
+# Helpers
+$idlId = '[a-zA-Z0-9]'; # Generic identifier
+$idlIdNs = '[a-zA-Z0-9:]'; # Generic identifier including namespace
+$idlIdNsList = '[a-zA-Z0-9:,\ ]'; # List of Generic identifiers including namespace
+
+$idlType = '[a-zA-Z0-9_]'; # Generic type/"value string" identifier
+$idlDataType = '[a-zA-Z0-9\ ]'; # Generic data type identifier
+
+# Magic IDL parsing regular expressions
+my $supportedTypes = "((?:unsigned )?(?:int|short|long)|(?:$idlIdNs*))";
+
+# Special IDL notations
+$extendedAttributeSyntax = '\[[^]]*\]'; # Used for extended attributes
+
+# Regular expression based IDL 'syntactical tokenizer' used in the IDLParser
+$moduleSelector = 'module\s*(' . $idlId . '*)\s*{';
+$moduleNSSelector = 'module\s*(' . $idlId . '*)\s*\[ns\s*(' . $idlIdNs . '*)\s*(' . $idlIdNs . '*)\]\s*;';
+$constantSelector = 'const\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*=\s*(' . $idlType . '*)';
+$raisesSelector = 'raises\s*\((' . $idlIdNsList . '*)\s*\)';
+$getterRaisesSelector = '\bgetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)';
+$setterRaisesSelector = '\bsetter\s+raises\s*\((' . $idlIdNsList . '*)\s*\)';
+
+$typeNamespaceSelector = '((?:' . $idlId . '*::)*)\s*(' . $idlDataType . '*)';
+
+$exceptionSelector = 'exception\s*(' . $idlIdNs . '*)\s*([a-zA-Z\s{;]*};)';
+$exceptionSubSelector = '{\s*' . $supportedTypes . '\s*(' . $idlType . '*)\s*;\s*}';
+
+$interfaceSelector = 'interface\s*((?:' . $extendedAttributeSyntax . ' )?)(' . $idlIdNs . '*)\s*(?::(\s*[^{]*))?{([a-zA-Z0-9_=\s(),;:\[\]]*)';
+$interfaceMethodSelector = '\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)\s*\(\s*([a-zA-Z0-9:\s,=\[\]]*)';
+$interfaceParameterSelector = 'in\s*((?:' . $extendedAttributeSyntax . ' )?)' . $supportedTypes . '\s*(' . $idlIdNs . '*)';
+
+$interfaceAttributeSelector = '\s*(readonly attribute|attribute)\s*(' . $extendedAttributeSyntax . ' )?' . $supportedTypes . '\s*(' . $idlType . '*)';
+
+1;
diff --git a/WebCore/bindings/scripts/generate-bindings.pl b/WebCore/bindings/scripts/generate-bindings.pl
new file mode 100755
index 0000000..afc730e
--- /dev/null
+++ b/WebCore/bindings/scripts/generate-bindings.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/perl -w
+#
+# Copyright (C) 2005 Apple Computer, Inc.
+# Copyright (C) 2006 Anders Carlsson <andersca@mac.com>
+#
+# This file is part of WebKit
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public
+# License as published by the Free Software Foundation; either
+# version 2 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+#
+# You should have received a copy of the GNU Library General Public License
+# aint with this library; see the file COPYING.LIB. If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301, USA.
+#
+
+# This script is a temporary hack.
+# Files are generated in the source directory, when they really should go
+# to the DerivedSources directory.
+# This should also eventually be a build rule driven off of .idl files
+# however a build rule only solution is blocked by several radars:
+# <rdar://problems/4251781&4251785>
+
+use strict;
+
+use File::Path;
+use Getopt::Long;
+use Cwd;
+
+use IDLParser;
+use CodeGenerator;
+
+my @idlDirectories;
+my $outputDirectory;
+my $generator;
+my $defines;
+my $preprocessor;
+
+GetOptions('include=s@' => \@idlDirectories,
+ 'outputdir=s' => \$outputDirectory,
+ 'generator=s' => \$generator,
+ 'defines=s' => \$defines,
+ 'preprocessor=s' => \$preprocessor);
+
+my $idlFile = $ARGV[0];
+
+die('Must specify input file.') unless defined($idlFile);
+die('Must specify IDL search path.') unless @idlDirectories;
+die('Must specify generator') unless defined($generator);
+die('Must specify input file.') unless defined($idlFile);
+die('Must specify output directory.') unless defined($outputDirectory);
+die('Must specify defines') unless defined($defines);
+
+$defines =~ s/^\s+|\s+$//g; # trim whitespace
+
+# Parse the given IDL file.
+my $parser = IDLParser->new(1);
+my $document = $parser->Parse($idlFile, $defines, $preprocessor);
+
+# Generate desired output for given IDL file.
+my $codeGen = CodeGenerator->new(\@idlDirectories, $generator, $outputDirectory, 0, $preprocessor);
+$codeGen->ProcessDocument($document, $defines);