Patch: fix for not accounting applets with onLoad events

Koos Vriezen koos.vriezen at xs4all.nl
Fri Nov 8 19:27:58 GMT 2002


On Fri, 8 Nov 2002, Till Krech wrote:

> On Thursday 07 November 2002 22:13, Koos Vriezen wrote:
> > Hi,
> >
> > Pages with applets fires onLoad events before applets are loaded. The
> > attached patch fixes that. This also keeps the wheel spinning until they
> > are loaded.
> This sounds great!
> Will try it out later.
> regards, till

If you do, you might try the attached patch. This one makes most applets
at http://webphysics.davidson.edu/Applets/animator4/default.html work.

Turned out that onLoad events are dispatched even before applets are
created and thus unknown for KJavaAppletContext. I don't like my current
sollution (registerApplet) though, it breaks symmetry between create and
destroy. Still I wonder why onLoad events are generated before the first
layout.

Also I had some trouble where to put d->m_javaContext->appletsLoaded().
KHTMLPart::checkEmitLoadEvent() seem to be too late, onLoad events didn't
occur, KHTMLPart::checkCompleted() does only work if I commented
checkEmitLoadEvent() out in KHTMLPart::slotFinishedParsing().
KHTMLPart::slotFinishedParsing() first does a
checkEmitLoadEvent() and then a checkCompleted() (which also does a
checkEmitLoadEvent()).
Maybe someone can comment on that.

Obviously, this is stuff after 3.1 ...

Koos
-------------- next part --------------
Index: khtml_part.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtml_part.cpp,v
retrieving revision 1.763
diff -u -3 -p -r1.763 khtml_part.cpp
--- khtml_part.cpp	2002/11/06 22:21:18	1.763
+++ khtml_part.cpp	2002/11/08 19:07:18
@@ -731,6 +731,8 @@ KJavaAppletContext *KHTMLPart::createJav
                this, SIGNAL(setStatusBarText(const QString&)) );
       connect( d->m_javaContext, SIGNAL(showDocument(const QString&, const QString&)),
                this, SLOT(slotShowDocument(const QString&, const QString&)) );
+      connect( d->m_javaContext, SIGNAL(appletLoaded()),
+               this, SLOT(checkCompleted()) );
   }
 
   return d->m_javaContext;
@@ -1448,7 +1450,7 @@ void KHTMLPart::stopAnimations()
 void KHTMLPart::slotFinishedParsing()
 {
   d->m_doc->setParsing(false);
-  checkEmitLoadEvent();
+  //checkEmitLoadEvent();
   disconnect(d->m_doc,SIGNAL(finishedParsing()),this,SLOT(slotFinishedParsing()));
 
   if (!d->m_view)
@@ -1580,6 +1582,11 @@ void KHTMLPart::checkCompleted()
   if ( requests > 0 )
     return;
 
+#ifndef Q_WS_QWS
+  if (d->m_javaContext && !d->m_javaContext->appletsLoaded())
+      return;
+#endif
+
   // OK, completed.
   // Now do what should be done when we are really completed.
   d->m_bComplete = true;
@@ -1646,7 +1653,6 @@ void KHTMLPart::checkEmitLoadEvent()
   for (; it != end; ++it )
     if ( !(*it).m_bCompleted ) // still got a frame running -> too early
       return;
-
 
   d->m_bLoadEventEmitted = true;
   if (d->m_doc)
Index: java/kjavaapplet.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/java/kjavaapplet.h,v
retrieving revision 1.21
diff -u -3 -p -r1.21 kjavaapplet.h
--- java/kjavaapplet.h	2002/10/17 19:59:26	1.21
+++ java/kjavaapplet.h	2002/11/08 19:07:18
@@ -237,9 +237,9 @@ public:
     */
     void stateChange ( const int newState );
     void setFailed ();
-    AppletState state();
-    bool failed();
-    bool isAlive();
+    AppletState state() const;
+    bool failed() const;
+    bool isAlive() const;
 
 private:
     void showStatus( const QString &msg);
Index: java/kjavaapplet.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/java/kjavaapplet.cpp,v
retrieving revision 1.23
diff -u -3 -p -r1.23 kjavaapplet.cpp
--- java/kjavaapplet.cpp	2002/10/17 19:59:26	1.23
+++ java/kjavaapplet.cpp	2002/11/08 19:07:18
@@ -62,7 +62,7 @@ KJavaApplet::KJavaApplet( KJavaAppletWid
         context = new KJavaAppletContext();
 
     d->reallyExists = false;
-    id = -1;
+    context->registerApplet(this);
 }
 
 KJavaApplet::~KJavaApplet()
@@ -302,7 +302,7 @@ void KJavaApplet::setFailed() {
     d->failed = true;
 }
 
-bool KJavaApplet::isAlive() {
+bool KJavaApplet::isAlive() const {
    return (
         !d->failed 
         && d->state >= INSTANCIATED
@@ -310,11 +310,11 @@ bool KJavaApplet::isAlive() {
    ); 
 }
 
-KJavaApplet::AppletState KJavaApplet::state() {
+KJavaApplet::AppletState KJavaApplet::state() const {
     return d->state;
 }
 
-bool KJavaApplet::failed() {
+bool KJavaApplet::failed() const {
     return d->failed;
 }
 
Index: java/kjavaappletcontext.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/java/kjavaappletcontext.h,v
retrieving revision 1.17
diff -u -3 -p -r1.17 kjavaappletcontext.h
--- java/kjavaappletcontext.h	2002/05/25 11:50:27	1.17
+++ java/kjavaappletcontext.h	2002/11/08 19:07:18
@@ -62,6 +62,11 @@ public:
     void setContextId( int id );
 
     /**
+     * registers applet 
+     **/
+    void registerApplet( KJavaApplet* );
+
+    /**
      * Sends a message to create the applet.
      */
     void create( KJavaApplet* );
@@ -93,6 +98,10 @@ public:
     void processCmd( QString cmd, QStringList args );
 
     /**
+     * Check if the applets are loaded by the Java Virtual Machine
+     **/
+    bool appletsLoaded() const;
+    /**
      * LiveConnect functions
      */
     bool getMember(KJavaApplet *, const unsigned long, const QString &, int &, unsigned long &, QString &);
@@ -110,6 +119,11 @@ signals:
      * Signals the KHTML Part to show a url in a given target
      */
     void showDocument( const QString& url, const QString& target );
+
+    /**
+     * Signals the KHTML Part an applet is loaded
+     **/
+    void appletLoaded();
 
 protected:
     //The counter to generate ID's for the contexts
Index: java/kjavaappletcontext.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/java/kjavaappletcontext.cpp,v
retrieving revision 1.32
diff -u -3 -p -r1.32 kjavaappletcontext.cpp
--- java/kjavaappletcontext.cpp	2002/10/24 23:49:05	1.32
+++ java/kjavaappletcontext.cpp	2002/11/08 19:07:18
@@ -30,15 +30,16 @@
 #include <qstringlist.h>
 #include <qregexp.h>
 
+typedef QMap< int, QGuardedPtr<KJavaApplet> > AppletMap;
+
 // For future expansion
 class KJavaAppletContextPrivate
 {
 friend class KJavaAppletContext;
 private:
-    QMap< int, QGuardedPtr<KJavaApplet> > applets;
+    AppletMap applets;
 };
 
-
 //  Static Factory Functions
 int KJavaAppletContext::contextCount = 0;
 
@@ -73,11 +74,19 @@ void KJavaAppletContext::setContextId( i
     id = _id;
 }
 
-void KJavaAppletContext::create( KJavaApplet* applet )
+void KJavaAppletContext::registerApplet( KJavaApplet* applet )
 {
     static int appletId = 0;
 
-    server->createApplet( id, ++appletId,
+    kdDebug(6100) << "@@@@@@@@@@KJavaAppletContext::register " << applet->appletName() << " " << (void*)this << endl;
+    applet->setAppletId( ++appletId );
+    d->applets.insert( appletId, applet );
+}
+
+void KJavaAppletContext::create( KJavaApplet* applet )
+{
+    kdDebug(6100) << "@@@@@@@@@@KJavaAppletContext::create " << applet->appletName() << " " << (void*)this << endl;
+    server->createApplet( id, applet->appletId(),
                           applet->appletName(),
                           applet->appletClass(),
                           applet->baseURL(),
@@ -87,8 +96,6 @@ void KJavaAppletContext::create( KJavaAp
                           applet->getParams(),
                           applet->getWindowName() );
 
-    applet->setAppletId( appletId );
-    d->applets.insert( appletId, applet );
 }
 
 void KJavaAppletContext::destroy( KJavaApplet* applet )
@@ -205,6 +212,10 @@ void KJavaAppletContext::received( const
                 if (ok)
                 {
                     applet->stateChange(newState);
+                    if (newState == KJavaApplet::INSTANCIATED) {
+                        kdDebug(6002) << "emit appletLoaded" << endl;
+                        emit appletLoaded();
+                    }
                 } else
                     kdError(6002) << "AppletStateNotification: status is not numerical" << endl;
             } else
@@ -226,6 +237,25 @@ void KJavaAppletContext::received( const
             applet->setFailed();
         }
     }
+}
+
+bool KJavaAppletContext::appletsLoaded() const {
+    kdDebug(6002) << "appletsLoaded " << (void*)this << endl;
+    bool ret = true;
+    AppletMap::const_iterator it = d->applets.begin();
+    for (; it != d->applets.end(); it++) {
+        if (!(*it).isNull()) {
+            kdDebug(6002) << "appletsLoaded " << (int)(*it)->state() << " " << (void*)this << endl;
+            if (!(*it)->isAlive()) {
+                ret = false;
+                break;
+                //return false;
+            }
+        }
+    }
+    kdDebug(6002) << "appletsLoaded " << ret << " " << (void*)this << endl;
+    //return true;
+    return ret;
 }
 
 bool KJavaAppletContext::getMember(KJavaApplet * applet, const unsigned long objid, const QString & name, int & type, unsigned long & rid, QString & value) {


More information about the kfm-devel mailing list