+2006-01-26 Anders Carlsson <andersca@mac.com>
+
+ Reviewed by Darin.
+
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=6805
+ Support constants in IDL files
+
+ * bindings/scripts/CodeGeneratorJS.pm:
+ If an interface has constants, generate a constructor
+ object and add the constants as properties. Also add a
+ getConstructor method to the interface object.
+
+ * bindings/scripts/CodeGenerator.pm:
+ * bindings/scripts/generate-bindings.pl:
+ Add a --force-generation flag to force regeneration of files
+ even though nothing has changed.
+
+ * khtml/ecma/kjs_events.cpp:
+ * khtml/ecma/kjs_events.h:
+ Remove MutationEventConstructor and DOMMutationEvent,
+ those are autogenerated now.
+
+ * bindings/js/JSEvents.cpp:
+ Include JSMutationEvent.cpp
+
+ * khtml/ecma/kjs_window.cpp:
+ (KJS::Window::getValueProperty):
+ * khtml/ecma/kjs_window.h:
+ (KJS::Window::):
+ Add MutationEvent property.
+
+ * khtml/xml/MutationEvent.idl: Added.
+
2006-01-25 Alexander Kellett <lypanov@kde.org>
Reviewed by eseidel.
+#include "config.h"
+
// These are generated files
+#include "JSMutationEvent.cpp"
#include "JSWheelEvent.cpp"
{
my $object = shift;
$useDocument = shift;
-
+ $forceGeneration = shift;
+
my $ifaceName = $useGenerator;
$ifaceName =~ s/\b(\w)/\U$1/g; # Make first letter of each word uppercase
$ifaceName = "CodeGenerator$ifaceName";
foreach(@$arrayRef) {
my $class = $_;
- if ($codeGenerator->ShouldGenerateFiles($useDocument, $class->name)) {
+ if ($forceGeneration || $codeGenerator->ShouldGenerateFiles($useDocument, $class->name)) {
print " |- Processing interface \"" . $class->name . "\"...\n";
$codeGenerator->GenerateInterface($class);
my $numAttributes = @{$dataNode->attributes};
my $numFunctions = @{$dataNode->functions};
+ my $numConstants = @{$dataNode->constants};
push(@headerContent, "\nnamespace WebCore {\n\n");
push(@headerContent, " virtual const KJS::ClassInfo* classInfo() const { return &info; }\n");
push(@headerContent, " static const KJS::ClassInfo info;\n");
+ # Constructor object getter
+ if ($numConstants ne 0) {
+ push(@headerContent, " static KJS::JSValue* getConstructor(KJS::ExecState*);\n")
+ }
+
# Attribute and function enums
if ($numAttributes + $numFunctions > 0) {
push(@headerContent, " enum {\n")
# - Add default header template
@implContentHeader = split("\r", $headerTemplate);
- push(@implContentHeader, "\n#include \"config.h\"\n");
+ push(@implContentHeader, "\n");
push(@implContentHeader, "#include \"$className.h\"\n\n");
if (exists $dataNode->extendedAttributes->{"LegacyParent"}) {
\@hashSpecials, \@hashParameters);
}
+ # - Add all constants
+ my $numConstants = @{$dataNode->constants};
+ if ($numConstants ne 0) {
+ $hashSize = $numConstants;
+ $hashName = $className . "ConstructorTable";
+
+ @hashKeys = ();
+ @hashValues = ();
+ @hashSpecials = ();
+ @hashParameters = ();
+
+ foreach my $constant (@{$dataNode->constants}) {
+ my $name = $constant->name;
+ push(@hashKeys, $name);
+
+ my $value = "DOM::${interfaceName}::$name";
+ push(@hashValues, $value);
+
+ my $special = "DontDelete|ReadOnly";
+ push(@hashSpecials, $special);
+
+ my $numParameters = 0;
+ push(@hashParameters, $numParameters);
+ }
+
+ $object->GenerateHashTable($hashName, $hashSize,
+ \@hashKeys, \@hashValues,
+ \@hashSpecials, \@hashParameters);
+
+ # Add Constructor class
+ push(@implContent, "class ${className}Constructor : public DOMObject {\n");
+ push(@implContent, "public:\n");
+ push(@implContent, " ${className}Constructor(ExecState* exec) { " .
+ "setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype()); }\n");
+ push(@implContent, " virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);\n");
+ push(@implContent, " JSValue* getValueProperty(ExecState*, int token) const;\n");
+ push(@implContent, " virtual const ClassInfo* classInfo() const { return &info; }\n");
+ push(@implContent, " static const ClassInfo info;\n");
+ push(@implContent, "};\n\n");
+
+ push(@implContent, "const ClassInfo ${className}Constructor::info = { \"${interfaceName}Constructor\", 0, " .
+ "&${className}ConstructorTable, 0 };\n\n");
+
+ push(@implContent, "bool ${className}Constructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)\n{\n");
+ push(@implContent, " return getStaticValueSlot<${className}Constructor, DOMObject>" .
+ "(exec, &${className}ConstructorTable, this, propertyName, slot);\n}\n\n");
+
+ push(@implContent, "JSValue* ${className}Constructor::getValueProperty(ExecState*, int token) const\n{\n");
+ push(@implContent, " // We use the token as the value to return directly\n");
+ push(@implContent, " return jsNumber(token);\n}\n\n");
+ }
+
# - Add all functions in a hashtable definition, if we have any.
my $numFunctions = @{$dataNode->functions};
if ($numFunctions ne 0) {
push(@implContent, ");\n break;\n");
}
}
- push(@implContent, " }\n}\n\n");
-
+ push(@implContent, " }\n}\n\n");
}
}
+
+
+ if ($numConstants ne 0) {
+ push(@implContent, "JSValue* ${className}::getConstructor(ExecState* exec)\n{\n");
+ push(@implContent, " return cacheGlobalObject<${className}Constructor>(exec, \"[[${className}.constructor]]\");\n");
+ push(@implContent, "}\n");
+ }
# Functions
if($numFunctions ne 0) {
if ($type eq "boolean") {
return "jsBoolean($value)";
- } elsif ($type eq "long" or $type eq "unsigned long") {
+ } elsif ($type eq "long" or $type eq "unsigned long" or
+ $type eq "unsigned short") {
return "jsNumber($value)";
} elsif ($type eq "DOMString") {
return "jsString($value)";
my @idlDirectories;
my $outputDirectory;
my $generator;
+my $forceGeneration = 0;
GetOptions('idldir=s@' => \@idlDirectories,
'outputdir=s' => \$outputDirectory,
- 'generator=s' => \$generator);
+ 'generator=s' => \$generator,
+ 'force-generation' => \$forceGeneration);
if (!defined($generator)) {
die('Must specify generator')
# Generate desired output for given IDL file.
my $codeGen = CodeGenerator->new(\@idlDirectories, $generator, $outputDirectory);
- $codeGen->ProcessDocument($document);
+ $codeGen->ProcessDocument($document, $forceGeneration);
}
#include "CachedImage.h"
#include "htmlnames.h"
+#include "JSMutationEvent.h"
#include "JSWheelEvent.h"
#include <kdebug.h>
initEvent DOMEvent::InitEvent DontDelete|Function 3
@end
*/
-KJS_DEFINE_PROTOTYPE(DOMEventProto)
KJS_IMPLEMENT_PROTOFUNC(DOMEventProtoFunc)
KJS_IMPLEMENT_PROTOTYPE("DOMEvent", DOMEventProto, DOMEventProtoFunc)
else if (e->isUIEvent())
ret = new DOMUIEvent(exec, static_cast<UIEventImpl *>(e));
else if (e->isMutationEvent())
- ret = new DOMMutationEvent(exec, static_cast<MutationEventImpl *>(e));
+ ret = new JSMutationEvent(exec, static_cast<MutationEventImpl *>(e));
else
ret = new DOMEvent(exec, e);
// -------------------------------------------------------------------------
-const ClassInfo MutationEventConstructor::info = { "MutationEventConstructor", 0, &MutationEventConstructorTable, 0 };
-/*
-@begin MutationEventConstructorTable 3
- MODIFICATION DOM::MutationEvent::MODIFICATION DontDelete|ReadOnly
- ADDITION DOM::MutationEvent::ADDITION DontDelete|ReadOnly
- REMOVAL DOM::MutationEvent::REMOVAL DontDelete|ReadOnly
-@end
-*/
-bool MutationEventConstructor::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
-{
- return getStaticValueSlot<MutationEventConstructor, DOMObject>(exec, &MutationEventConstructorTable, this, propertyName, slot);
-}
-
-JSValue *MutationEventConstructor::getValueProperty(ExecState *, int token) const
-{
- // We use the token as the value to return directly
- return jsNumber(token);
-}
-
-JSValue *getMutationEventConstructor(ExecState *exec)
-{
- return cacheGlobalObject<MutationEventConstructor>(exec, "[[mutationEvent.constructor]]");
-}
-
-// -------------------------------------------------------------------------
-
-const ClassInfo DOMMutationEvent::info = { "MutationEvent", &DOMEvent::info, &DOMMutationEventTable, 0 };
-/*
-@begin DOMMutationEventTable 5
- relatedNode DOMMutationEvent::RelatedNode DontDelete|ReadOnly
- prevValue DOMMutationEvent::PrevValue DontDelete|ReadOnly
- newValue DOMMutationEvent::NewValue DontDelete|ReadOnly
- attrName DOMMutationEvent::AttrName DontDelete|ReadOnly
- attrChange DOMMutationEvent::AttrChange DontDelete|ReadOnly
-@end
-@begin DOMMutationEventProtoTable 1
- initMutationEvent DOMMutationEvent::InitMutationEvent DontDelete|Function 8
-@end
-*/
-KJS_DEFINE_PROTOTYPE(DOMMutationEventProto)
-KJS_IMPLEMENT_PROTOFUNC(DOMMutationEventProtoFunc)
-KJS_IMPLEMENT_PROTOTYPE_WITH_PARENT("DOMMutationEvent",DOMMutationEventProto,DOMMutationEventProtoFunc,DOMEventProto)
-
-DOMMutationEvent::DOMMutationEvent(ExecState *exec, MutationEventImpl *e)
- : DOMEvent(exec, e)
-{
- setPrototype(DOMMutationEventProto::self(exec));
-}
-
-bool DOMMutationEvent::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot& slot)
-{
- return getStaticValueSlot<DOMMutationEvent, DOMEvent>(exec, &DOMMutationEventTable, this, propertyName, slot);
-}
-
-JSValue *DOMMutationEvent::getValueProperty(ExecState *exec, int token) const
-{
- MutationEventImpl &event = *static_cast<MutationEventImpl *>(impl());
- switch (token) {
- case RelatedNode:
- return getDOMNode(exec, event.relatedNode());
- case PrevValue:
- return jsString(event.prevValue());
- case NewValue:
- return jsString(event.newValue());
- case AttrName:
- return jsString(event.attrName());
- case AttrChange:
- return jsNumber(event.attrChange());
- default:
- kdWarning() << "Unhandled token in DOMMutationEvent::getValueProperty : " << token << endl;
- return NULL;
- }
-}
-
-JSValue *DOMMutationEventProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
-{
- if (!thisObj->inherits(&DOMMutationEvent::info))
- return throwError(exec, TypeError);
- MutationEventImpl &mutationEvent = *static_cast<MutationEventImpl *>(static_cast<DOMEvent *>(thisObj)->impl());
- switch (id) {
- case DOMMutationEvent::InitMutationEvent:
- mutationEvent.initMutationEvent(AtomicString(args[0]->toString(exec).domString()), // typeArg,
- args[1]->toBoolean(exec), // canBubbleArg
- args[2]->toBoolean(exec), // cancelableArg
- toNode(args[3]), // relatedNodeArg
- args[4]->toString(exec).domString(), // prevValueArg
- args[5]->toString(exec).domString(), // newValueArg
- args[6]->toString(exec).domString(), // attrNameArg
- args[7]->toInt32(exec)); // attrChangeArg
- return jsUndefined();
- }
- return jsUndefined();
-}
-
-// -------------------------------------------------------------------------
-
const ClassInfo Clipboard::info = { "Clipboard", 0, &ClipboardTable, 0 };
/* Source for ClipboardTable. Use "make hashtables" to regenerate.
DOM::EventImpl* toEvent(JSValue*); // returns 0 if value is not a DOMEvent object
+ KJS_DEFINE_PROTOTYPE(DOMEventProto)
+
// Constructor object EventException
class EventExceptionConstructor : public DOMObject {
public:
enum { KeyIdentifier, KeyLocation, CtrlKey, ShiftKey, AltKey, MetaKey, AltGraphKey, InitKeyboardEvent};
};
- // Constructor object MutationEvent
- class MutationEventConstructor : public DOMObject {
- public:
- MutationEventConstructor(ExecState*) { }
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- JSValue* getValueProperty(ExecState*, int token) const;
- // no put - all read-only
- virtual const ClassInfo* classInfo() const { return &info; }
- static const ClassInfo info;
- };
-
- JSValue* getMutationEventConstructor(ExecState*);
-
- class DOMMutationEvent : public DOMEvent {
- public:
- DOMMutationEvent(ExecState*, DOM::MutationEventImpl *me);
- virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
- JSValue* getValueProperty(ExecState*, int token) const;
- // no put - all read-only
- virtual const ClassInfo* classInfo() const { return &info; }
- static const ClassInfo info;
- enum { AttrChange, RelatedNode, AttrName, PrevValue, NewValue,
- InitMutationEvent };
- };
-
class Clipboard : public DOMObject {
friend class ClipboardProtoFunc;
public:
#include "kjs_traversal.h"
#include "kjs_css.h"
#include "kjs_events.h"
+#include "JSMutationEvent.h"
#include "JSXMLHttpRequest.h"
#include "xmlserializer.h"
#ifdef KHTML_XSLT
NodeFilter Window::NodeFilter DontDelete
DOMException Window::DOMException DontDelete
CSSRule Window::CSSRule DontDelete
+ MutationEvent Window::MutationEventCtor DontDelete
frames Window::Frames DontDelete|ReadOnly
history Window::_History DontDelete|ReadOnly
event Window::Event DontDelete
return getCSSRuleConstructor(exec);
case EventCtor:
return getEventConstructor(exec);
+ case MutationEventCtor:
+ return JSMutationEvent::getConstructor(exec);
case Frames:
if (!frames)
frames = new FrameArray(exec, m_frame);
UnprotectedListenersMap jsUnprotectedEventListeners;
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
- enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
+ enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, MutationEventCtor, Range,
NodeFilter, DOMException, CSSRule, Frames, _History, Event, InnerHeight,
InnerWidth, Length, _Location, Locationbar, Name, _Navigator, ClientInformation,
Menubar, OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
--- /dev/null
+module events {
+ interface [LegacyParent=KJS::DOMEvent] MutationEvent : Event {
+ const unsigned short MODIFICATION = 1;
+ const unsigned short ADDITION = 2;
+ const unsigned short REMOVAL = 3;
+
+ readonly attribute Node relatedNode;
+ readonly attribute DOMString prevValue;
+ readonly attribute DOMString newValue;
+ readonly attribute DOMString attrName;
+ readonly attribute unsigned short attrChange;
+
+ void initMutationEvent(in AtomicString typeArg,
+ in boolean canBubbleArg,
+ in boolean cancelableArg,
+ in Node relatedNodeArg,
+ in DOMString prevValueArg,
+ in DOMString newValueArg,
+ in DOMString attrNameArg,
+ in unsigned short attrChangeArg);
+ };
+}