[PATCH] Re: assigning onload event to an image created with JavaScript doesn't work

David Joham djoham at yahoo.com
Thu Nov 7 16:20:55 GMT 2002


Wow, thanks David! You rock...



--- David Faure <david at mandrakesoft.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
> 
> On Wednesday 06 November 2002 19:59, David Joham wrote:
> > Hello all,
> > 
> > I'm using Konq 3.01 at the moment at work and I've noticed that onload events assigned via
> > Javascript to Image objects don't seem to work. I'm trying to track this down to get the new
> HP
> > site working in Konq.
> > 
> > Here's a small recreation that demonstrates the problem: [...]
> 
> Got it to work... after quite some fighting and rewriting :)
> 
> According to the NS doc (http://docs.sun.com/source/816-6408-10/image.htm)
> (couldn't find a IE doc for this !?), we are still missing _many_ attributes
> for the Image object...
> 
> - -- 
> David FAURE, david at mandrakesoft.com, faure at kde.org
> http://people.mandrakesoft.com/~david/
> Contributing to: http://www.konqueror.org/, http://www.koffice.org/
> Get the latest KOffice - http://download.kde.org/stable/koffice-1.2/
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.0.7 (GNU/Linux)
> 
> iD8DBQE9yaxy72KcVAmwbhARAlF9AJ9TuCNEo5aj1B/QyYLG4PAevdJe3gCfRWgR
> AEPETv3Z95thQPgGz8WSXbY=
> =gC9J
> -----END PGP SIGNATURE-----
> > Index: kjs_html.cpp
> ===================================================================
> RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.cpp,v
> retrieving revision 1.212
> diff -u -p -r1.212 kjs_html.cpp
> --- kjs_html.cpp	2002/11/04 11:25:32	1.212
> +++ kjs_html.cpp	2002/11/06 23:53:49
> @@ -34,12 +34,15 @@
>  #include "html/html_imageimpl.h"
>  #include "html/html_objectimpl.h"
>  #include "html/html_miscimpl.h"
> +#include "xml/dom2_eventsimpl.h"
> +
>  #include <kparts/browserextension.h>
>  
>  #include "khtml_part.h"
>  #include "khtmlview.h"
>  
>  #include "ecma/kjs_css.h"
> +#include "ecma/kjs_events.h"
>  #include "ecma/kjs_html.h"
>  #include "ecma/kjs_window.h"
>  #include "ecma/kjs_html.lut.h"
> @@ -47,6 +50,7 @@
>  #include "java/kjavaappletcontext.h"
>  
>  #include "misc/htmltags.h"
> +#include "misc/htmlattrs.h"
>  #include "rendering/render_object.h"
>  #include "rendering/render_root.h"
>  
> @@ -2846,12 +2850,12 @@ DEFINE_PROTOTYPE("HTMLCollection", HTMLC
>  IMPLEMENT_PROTOFUNC_DOM(HTMLCollectionProtoFunc)
>  IMPLEMENT_PROTOTYPE(HTMLCollectionProto,HTMLCollectionProtoFunc)
>  
> -const ClassInfo HTMLCollection::info = { "HTMLCollection", 0, 0, 0 };
> +const ClassInfo KJS::HTMLCollection::info = { "HTMLCollection", 0, 0, 0 };
>  
> -HTMLCollection::HTMLCollection(ExecState *exec, DOM::HTMLCollection c)
> +KJS::HTMLCollection::HTMLCollection(ExecState *exec, DOM::HTMLCollection c)
>    : DOMObject(HTMLCollectionProto::self(exec)), collection(c) {}
>  
> -HTMLCollection::~HTMLCollection()
> +KJS::HTMLCollection::~HTMLCollection()
>  {
>    ScriptInterpreter::forgetDOMObject(collection.handle());
>  }
> @@ -3186,10 +3190,13 @@ const ClassInfo KJS::Image::info = { "Im
>  @begin ImageTable 3
>    src		Image::Src		DontDelete
>    complete	Image::Complete		DontDelete|ReadOnly
> +  onload	Image::OnLoad		DontDelete
>  @end
>  */
>  Image::Image(ExecState* exec, const DOM::Document &d)
> -  : DOMObject(exec->interpreter()->builtinObjectPrototype()), doc(d), img(0) { }
> +  : DOMObject(exec->interpreter()->builtinObjectPrototype()), doc(d), img(0),
> +  m_onLoadListener(0L)
> +{ }
>  
>  Value Image::tryGet(ExecState *exec, const UString &propertyName) const
>  {
> @@ -3203,6 +3210,10 @@ Value Image::getValueProperty(ExecState 
>      return String(src);
>    case Complete:
>      return Boolean(!img || img->status() >= khtml::CachedObject::Persistent);
> +  case OnLoad:
> +    if ( m_onLoadListener )
> +      return m_onLoadListener->listenerObj();
> +    return Undefined();
>    default:
>      kdWarning() << "Image::getValueProperty unhandled token " << token << endl;
>      return Value();
> @@ -3211,15 +3222,30 @@ Value Image::getValueProperty(ExecState 
>  
>  void Image::tryPut(ExecState *exec, const UString &propertyName, const Value& value, int attr)
>  {
> -  // Not worth using the hashtable
> +  // TODO: use the hashtable
>    if (propertyName == "src") {
>      String str = value.toString(exec);
>      src = str.value();
>      if ( img ) img->deref(this);
>      img = static_cast<DOM::DocumentImpl*>( doc.handle() )->docLoader()->requestImage(
> src.string() );
>      if ( img ) img->ref(this);
> +  } else if (propertyName == "onload" ) {
> +    m_onLoadListener = Window::retrieveActive(exec)->getJSEventListener(value,true);
>    } else {
>      DOMObject::tryPut(exec, propertyName, value, attr);
> +  }
> +}
> +
> +void Image::notifyFinished(khtml::CachedObject * finishedObj)
> +{
> +  if (img == finishedObj /*&& !loadEventSent*/ && m_onLoadListener ) {
> +    //loadEventSent = true;
> +    DOM::EventImpl *evt = new DOM::EventImpl( (DOM::EventImpl::EventId)ATTR_ONLOAD, false,
> false );
> +    evt->setTarget( 0 );
> +    evt->ref();
> +    DOM::Event e(evt);
> +    m_onLoadListener->handleEvent( e );
> +    evt->deref();
>    }
>  }
>  
> Index: kjs_html.h
> ===================================================================
> RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.h,v
> retrieving revision 1.67
> diff -u -p -r1.67 kjs_html.h
> --- kjs_html.h	2002/11/03 20:55:34	1.67
> +++ kjs_html.h	2002/11/06 23:53:49
> @@ -217,13 +217,15 @@ namespace KJS {
>      Value getValueProperty(ExecState *exec, int token) const;
>      virtual void tryPut(ExecState *exec, const UString &propertyName, const Value& value, int
> attr = None);
>      virtual bool toBoolean(ExecState *) const { return true; }
> +    virtual void notifyFinished(khtml::CachedObject * finishedObj);
>      virtual const ClassInfo* classInfo() const { return &info; }
>      static const ClassInfo info;
> -    enum { Src, Complete };
> +    enum { Src, Complete, OnLoad };
>    private:
>      UString src;
>      DOM::Document doc;
>      khtml::CachedImage* img;
> +    JSEventListener *m_onLoadListener;
>    };
>  
>    Value getHTMLCollection(ExecState *exec, DOM::HTMLCollection c);
> Index: kjs_html.lut.h
> ===================================================================
> RCS file: /home/kde/kdelibs/khtml/ecma/kjs_html.lut.h,v
> retrieving revision 1.20
> diff -u -p -r1.20 kjs_html.lut.h
> --- kjs_html.lut.h	2002/11/03 20:55:34	1.20
> +++ kjs_html.lut.h	2002/11/06 23:53:49
> @@ -1098,10 +1098,11 @@ namespace KJS {
>  
>  const struct HashEntry ImageTableEntries[] = {
>     { 0, 0, 0, 0, 0 },
> -   { "src", Image::Src, DontDelete, 0, 0 },
> -   { "complete", Image::Complete, DontDelete|ReadOnly, 0, 0 }
> +   { "src", Image::Src, DontDelete, 0, &ImageTableEntries[3] },
> +   { "complete", Image::Complete, DontDelete|ReadOnly, 0, 0 },
> +   { "onload", Image::OnLoad, DontDelete, 0, 0 }
>  };
>  
> -const struct HashTable ImageTable = { 2, 3, ImageTableEntries, 3 };
> +const struct HashTable ImageTable = { 2, 4, ImageTableEntries, 3 };
>  
>  }; // namespace
> 

__________________________________________________
Do you Yahoo!?
U2 on LAUNCH - Exclusive greatest hits videos
http://launch.yahoo.com/u2




More information about the kfm-devel mailing list