Reviewed by Ken.
authormjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Dec 2003 01:02:38 +0000 (01:02 +0000)
committermjs <mjs@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 9 Dec 2003 01:02:38 +0000 (01:02 +0000)
<rdar://problem/3504047>: XMLHttpRequest object needs onload event

* khtml/ecma/xmlhttprequest.cpp:
        (KJS::XMLHttpRequest::getValueProperty): Implemented onload property.
        (KJS::XMLHttpRequest::putValue): Ditto.
        (KJS::XMLHttpRequest::XMLHttpRequest): Ditto.
        (KJS::XMLHttpRequest::changeState): Ditto.
        * khtml/ecma/xmlhttprequest.h:
        * khtml/ecma/xmlhttprequest.lut.h: Regenerated.

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

WebCore/ChangeLog-2005-08-23
WebCore/khtml/ecma/xmlhttprequest.cpp
WebCore/khtml/ecma/xmlhttprequest.h
WebCore/khtml/ecma/xmlhttprequest.lut.h

index dcb2381..528f8da 100644 (file)
@@ -1,3 +1,17 @@
+2003-12-08  Maciej Stachowiak  <mjs@apple.com>
+
+        Reviewed by Ken.
+
+       <rdar://problem/3504047>: XMLHttpRequest object needs onload event
+        
+       * khtml/ecma/xmlhttprequest.cpp:
+        (KJS::XMLHttpRequest::getValueProperty): Implemented onload property.
+        (KJS::XMLHttpRequest::putValue): Ditto.
+        (KJS::XMLHttpRequest::XMLHttpRequest): Ditto.
+        (KJS::XMLHttpRequest::changeState): Ditto.
+        * khtml/ecma/xmlhttprequest.h:
+        * khtml/ecma/xmlhttprequest.lut.h: Regenerated.
+
 2003-12-08  David Hyatt  <hyatt@apple.com>
 
        Fix for 3503022, asahi.com is too wide.  Bugs in line breaking of breakable Japanese characters caused
index 7434326..3b2e85d 100644 (file)
@@ -106,13 +106,14 @@ Object XMLHttpRequestConstructorImp::construct(ExecState *exec, const List &)
 const ClassInfo XMLHttpRequest::info = { "XMLHttpRequest", 0, &XMLHttpRequestTable, 0 };
 
 /* Source for XMLHttpRequestTable.
-@begin XMLHttpRequestTable 6
+@begin XMLHttpRequestTable 7
   readyState           XMLHttpRequest::ReadyState              DontDelete|ReadOnly
   responseText         XMLHttpRequest::ResponseText            DontDelete|ReadOnly
   responseXML          XMLHttpRequest::ResponseXML             DontDelete|ReadOnly
   status               XMLHttpRequest::Status                  DontDelete|ReadOnly
   statusText           XMLHttpRequest::StatusText              DontDelete|ReadOnly
   onreadystatechange   XMLHttpRequest::Onreadystatechange      DontDelete
+  onload               XMLHttpRequest::Onload                  DontDelete
 @end
 */
 
@@ -140,6 +141,12 @@ Value XMLHttpRequest::getValueProperty(ExecState *, int token) const
    } else {
      return Null();
    }
+  case Onload:
+   if (onLoadListener && onLoadListener->listenerObjImp()) {
+     return onLoadListener->listenerObj();
+   } else {
+     return Null();
+   }
   default:
     kdWarning() << "XMLHttpRequest::getValueProperty unhandled token " << token << endl;
     return Value();
@@ -158,6 +165,10 @@ void XMLHttpRequest::putValue(ExecState *exec, int token, const Value& value, in
     onReadyStateChangeListener = Window::retrieveActive(exec)->getJSEventListener(value, true);
     if (onReadyStateChangeListener) onReadyStateChangeListener->ref();
     break;
+  case Onload:
+    onLoadListener = Window::retrieveActive(exec)->getJSEventListener(value, true);
+    if (onLoadListener) onLoadListener->ref();
+    break;
   default:
     kdWarning() << "HTMLDocument::putValue unhandled token " << token << endl;
   }
@@ -171,6 +182,7 @@ XMLHttpRequest::XMLHttpRequest(ExecState *exec, const DOM::Document &d)
     job(0),
     state(Uninitialized),
     onReadyStateChangeListener(0),
+    onLoadListener(0),
     decoder(0)
 {
 }
@@ -192,6 +204,12 @@ void XMLHttpRequest::changeState(XMLHttpRequestState newState)
       ev.initEvent("readystatechange", true, true);
       onReadyStateChangeListener->handleEvent(ev, true);
     }
+    
+    if (state == Completed && onLoadListener != 0 && doc->part()) {
+      DOM::Event ev = doc->part()->document().createEvent("HTMLEvents");
+      ev.initEvent("load", true, true);
+      onLoadListener->handleEvent(ev, true);
+    }
   }
 }
 
index 9bc6cb7..297dd3c 100644 (file)
@@ -60,7 +60,7 @@ namespace KJS {
     virtual bool toBoolean(ExecState *) const { return true; }
     virtual const ClassInfo* classInfo() const { return &info; }
     static const ClassInfo info;
-    enum { Onreadystatechange, ReadyState, ResponseText, ResponseXML, Status, StatusText, Abort, GetAllResponseHeaders, GetResponseHeader, Open, Send, SetRequestHeader };
+    enum { Onload, Onreadystatechange, ReadyState, ResponseText, ResponseXML, Status, StatusText, Abort, GetAllResponseHeaders, GetResponseHeader, Open, Send, SetRequestHeader };
 
   private:
     friend class XMLHttpRequestProtoFunc;
@@ -100,6 +100,7 @@ namespace KJS {
 
     XMLHttpRequestState state;
     JSEventListener *onReadyStateChangeListener;
+    JSEventListener *onLoadListener;
 
     khtml::Decoder *decoder;
     QString encoding;
index 33f5cba..f3fd803 100644 (file)
@@ -20,17 +20,17 @@ const struct HashTable XMLHttpRequestProtoTable = { 2, 8, XMLHttpRequestProtoTab
 namespace KJS {
 
 const struct HashEntry XMLHttpRequestTableEntries[] = {
+   { "responseXML", XMLHttpRequest::ResponseXML, DontDelete|ReadOnly, 0, &XMLHttpRequestTableEntries[8] },
    { 0, 0, 0, 0, 0 },
-   { 0, 0, 0, 0, 0 },
+   { "onreadystatechange", XMLHttpRequest::Onreadystatechange, DontDelete, 0, 0 },
    { "readyState", XMLHttpRequest::ReadyState, DontDelete|ReadOnly, 0, 0 },
-   { 0, 0, 0, 0, 0 },
-   { "responseText", XMLHttpRequest::ResponseText, DontDelete|ReadOnly, 0, &XMLHttpRequestTableEntries[6] },
-   { "statusText", XMLHttpRequest::StatusText, DontDelete|ReadOnly, 0, &XMLHttpRequestTableEntries[8] },
-   { "responseXML", XMLHttpRequest::ResponseXML, DontDelete|ReadOnly, 0, &XMLHttpRequestTableEntries[7] },
    { "status", XMLHttpRequest::Status, DontDelete|ReadOnly, 0, 0 },
-   { "onreadystatechange", XMLHttpRequest::Onreadystatechange, DontDelete, 0, 0 }
+   { "responseText", XMLHttpRequest::ResponseText, DontDelete|ReadOnly, 0, &XMLHttpRequestTableEntries[7] },
+   { 0, 0, 0, 0, 0 },
+   { "statusText", XMLHttpRequest::StatusText, DontDelete|ReadOnly, 0, 0 },
+   { "onload", XMLHttpRequest::Onload, DontDelete, 0, 0 }
 };
 
-const struct HashTable XMLHttpRequestTable = { 2, 9, XMLHttpRequestTableEntries, 6 };
+const struct HashTable XMLHttpRequestTable = { 2, 9, XMLHttpRequestTableEntries, 7 };
 
 } // namespace