2006-01-26 Anders Carlsson <andersca@mac.com>
authorandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2006 09:43:42 +0000 (09:43 +0000)
committerandersca <andersca@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 26 Jan 2006 09:43:42 +0000 (09:43 +0000)
        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.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@12387 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebCore/ChangeLog
WebCore/bindings/js/JSEvents.cpp
WebCore/bindings/scripts/CodeGenerator.pm
WebCore/bindings/scripts/CodeGeneratorJS.pm
WebCore/bindings/scripts/generate-bindings.pl
WebCore/khtml/ecma/kjs_events.cpp
WebCore/khtml/ecma/kjs_events.h
WebCore/khtml/ecma/kjs_window.cpp
WebCore/khtml/ecma/kjs_window.h
WebCore/khtml/xml/MutationEvent.idl [new file with mode: 0644]

index 3182c992cdf53446561961a0a4eb1cdf04fde62c..e0ed57a5e9fe8f0d6507f879a898104125a46eb6 100644 (file)
@@ -1,3 +1,36 @@
+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.
index db8a7924262d0dc9b5a2b6ed60cf7faa15c88ea5..9f5b808cf3c388c0fce91854d40b906df574cbbb 100644 (file)
@@ -1,3 +1,6 @@
+#include "config.h"
+
 // These are generated files
 
+#include "JSMutationEvent.cpp"
 #include "JSWheelEvent.cpp"
index e995c08d05f1253c2e34e9040de4ade4b15d3d95..4c51f6345f834f648d51f7323362016bb07dfe4d 100644 (file)
@@ -61,7 +61,8 @@ sub ProcessDocument
 {
   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";
@@ -79,7 +80,7 @@ sub ProcessDocument
   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);
index 766551ca642a4feca29ce404b885df97333328b0..cb62884ed165ecb9b7f584c717ba6432a5532563 100644 (file)
@@ -224,6 +224,7 @@ sub GenerateHeader
   
   my $numAttributes = @{$dataNode->attributes};
   my $numFunctions = @{$dataNode->functions};
+  my $numConstants = @{$dataNode->constants};
   
   push(@headerContent, "\nnamespace WebCore {\n\n");
   
@@ -266,6 +267,11 @@ sub GenerateHeader
   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")
@@ -345,7 +351,7 @@ sub GenerateImplementation
   
   # - 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"}) {
@@ -390,6 +396,58 @@ sub GenerateImplementation
                              \@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) {
@@ -521,10 +579,16 @@ sub GenerateImplementation
           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) {
@@ -652,7 +716,8 @@ sub NativeToJSValue
   
   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)";
index ca773f24fc5cacd6a93689c2f69c292292158c62..59d7644d1e993c8dbf895f1075292dd1c0749893 100755 (executable)
@@ -40,10 +40,12 @@ use CodeGenerator;
 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')
@@ -87,5 +89,5 @@ for my $idlPath (@idlFiles) {
        
        # Generate desired output for given IDL file.
        my $codeGen = CodeGenerator->new(\@idlDirectories, $generator, $outputDirectory);
-       $codeGen->ProcessDocument($document);
+       $codeGen->ProcessDocument($document, $forceGeneration);
 }
index 10d3283cf4821754b339374ac246eaba63adbac7..ac815df76c4839941abacfc7773a5e738337204b 100644 (file)
@@ -35,6 +35,7 @@
 #include "CachedImage.h"
 #include "htmlnames.h"
 
+#include "JSMutationEvent.h"
 #include "JSWheelEvent.h"
 
 #include <kdebug.h>
@@ -367,7 +368,6 @@ const ClassInfo DOMEvent::info = { "Event", 0, &DOMEventTable, 0 };
   initEvent             DOMEvent::InitEvent             DontDelete|Function 3
 @end
 */
-KJS_DEFINE_PROTOTYPE(DOMEventProto)
 KJS_IMPLEMENT_PROTOFUNC(DOMEventProtoFunc)
 KJS_IMPLEMENT_PROTOTYPE("DOMEvent", DOMEventProto, DOMEventProtoFunc)
 
@@ -508,7 +508,7 @@ JSValue *getDOMEvent(ExecState *exec, EventImpl *e)
     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);
 
@@ -822,102 +822,6 @@ JSValue *DOMKeyboardEventProtoFunc::callAsFunction(ExecState *exec, JSObject *th
 
 // -------------------------------------------------------------------------
 
-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.
index 6fd7aee320a4c40db2609f856aba083ac89f6cc1..1e55581353e49a67ca7a5841f850bb16cb02ad04 100644 (file)
@@ -131,6 +131,8 @@ namespace KJS {
 
     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:
@@ -181,31 +183,6 @@ namespace KJS {
         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:
index ad37dadc55992c0a537103803148aea7667a1f7d..afd84339a155305b911a82e35be480c6ac6c6143 100644 (file)
@@ -43,6 +43,7 @@
 #include "kjs_traversal.h"
 #include "kjs_css.h"
 #include "kjs_events.h"
+#include "JSMutationEvent.h"
 #include "JSXMLHttpRequest.h"
 #include "xmlserializer.h"
 #ifdef KHTML_XSLT
@@ -204,6 +205,7 @@ const ClassInfo Window::info = { "Window", 0, &WindowTable, 0 };
   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
@@ -680,6 +682,8 @@ JSValue *Window::getValueProperty(ExecState *exec, int token) const
       return getCSSRuleConstructor(exec);
     case EventCtor:
       return getEventConstructor(exec);
+    case MutationEventCtor:
+      return JSMutationEvent::getConstructor(exec);
     case Frames:
       if (!frames)
         frames = new FrameArray(exec, m_frame);
index 1d89a722e4291dfc2dc1bb28448f9b613fa699a3..dba911d9bf71a27dcc86668b256a70856786f5e2 100644 (file)
@@ -175,7 +175,7 @@ namespace KJS {
     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,
diff --git a/WebCore/khtml/xml/MutationEvent.idl b/WebCore/khtml/xml/MutationEvent.idl
new file mode 100644 (file)
index 0000000..28ca960
--- /dev/null
@@ -0,0 +1,22 @@
+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);
+    };
+}