Patch: Crash: blocking JS alert and deleting a window

Koos Vriezen koos.vriezen at xs4all.nl
Sun Oct 27 19:28:33 GMT 2002


On Sun, 27 Oct 2002, Koos Vriezen wrote:

> If this is a possible solution, better make a specialized QObject for it I
> think.

Made it so. Also made closeChildDialogs to return true if there were any
dialogs. Should make this patch invisible for all cases but that test
case.

> I do consider this a quick hack for this problem.

Still is..

>
> > Koos
>
>
-------------- next part --------------
Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.493
diff -u -3 -p -r1.493 khtmlview.cpp
--- khtmlview.cpp	2002/10/27 17:21:10	1.493
+++ khtmlview.cpp	2002/10/27 19:22:33
@@ -38,6 +38,7 @@
 #include "misc/htmlhashes.h"
 #include "misc/helper.h"
 #include "khtml_settings.h"
+#include "khtmlpart_p.h"
 #include "khtml_printsettings.h"
 
 #include <kcursor.h>
@@ -89,6 +90,36 @@ private:
 
 #endif
 
+class EventFilterer : public QObject
+{
+    KHTMLView *view;
+    QObject *watched_object;
+public:
+    EventFilterer(KHTMLView *v, QWidget *parent) : view(v) {
+        watched_object = parent ? parent->topLevelWidget() : view;
+        watched_object->installEventFilter(this);
+    }
+    bool eventFilter(QObject *obj, QEvent *e) {
+        if (obj != watched_object) // can this happen?
+            return false;
+        if (e->type () == QEvent::Reparent) {
+            kdDebug( 6000 ) << "#####KHTMLView::eventFilter reparent" << endl;
+            watched_object->removeEventFilter(this);
+            watched_object = view->topLevelWidget();
+            watched_object->installEventFilter(this);
+        } else if (e->type () == QEvent::Close) {
+            kdDebug( 6000 ) << "####KHTMLView::eventFilter close" << endl;
+            if (view->closeChildDialogs()) {
+                QApplication::postEvent(watched_object, new QEvent(*e));
+                watched_object->removeEventFilter(this);
+                watched_object = 0L;
+                return true;
+            }
+        }
+        return false;
+    }
+};
+
 class KHTMLViewPrivate {
     friend class KHTMLToolTip;
 public:
@@ -107,6 +138,7 @@ public:
         complete = false;
 	tooltip = 0;
         possibleTripleClick = false;
+        event_filterer = 0L;
     }
     ~KHTMLViewPrivate()
     {
@@ -117,6 +149,7 @@ public:
         if (underMouse)
 	    underMouse->deref();
 	delete tooltip;
+        delete event_filterer;
     }
     void reset()
     {
@@ -228,6 +261,7 @@ public:
     bool dirtyLayout;
     QRect updateRect;
     KHTMLToolTip *tooltip;
+    EventFilterer *event_filterer;
     QPtrDict<QWidget> visibleWidgets;
 };
 
@@ -281,6 +315,7 @@ KHTMLView::KHTMLView( KHTMLPart *part, Q
     init();
 
     viewport()->show();
+    d->event_filterer = new EventFilterer(this, parent);
 }
 
 KHTMLView::~KHTMLView()
@@ -459,8 +494,9 @@ void KHTMLView::layout()
     }
 }
 
-void KHTMLView::closeChildDialogs()
+bool KHTMLView::closeChildDialogs()
 {
+    bool retval = false;
     QObjectList *dlgs = queryList("QDialog");
     for (QObject *dlg = dlgs->first(); dlg; dlg = dlgs->next())
     {
@@ -470,6 +506,7 @@ void KHTMLView::closeChildDialogs()
             // close() ends up calling QButton::animateClick, which isn't immediate
             // we need something the exits the event loop immediately (#49068)
             dlgbase->cancel();
+            retval = true;
         }
         else
         {
@@ -478,6 +515,7 @@ void KHTMLView::closeChildDialogs()
         }
     }
     delete dlgs;
+    return retval;
 }
 
 //
Index: khtmlview.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.h,v
retrieving revision 1.166
diff -u -3 -p -r1.166 khtmlview.h
--- khtmlview.h	2002/10/20 23:09:13	1.166
+++ khtmlview.h	2002/10/27 19:22:33
@@ -143,9 +143,9 @@ public:
     void layout();
 
     /**
-     * Close all child dialogs
+     * Close all child dialogs, returns true if there were any
      **/
-    void closeChildDialogs();
+    bool closeChildDialogs();
 
 signals:
     void cleared();


More information about the kfm-devel mailing list