Patch: Crash: blocking JS alert and deleting a window
Koos Vriezen
koos.vriezen at xs4all.nl
Sun Oct 27 15:25:26 GMT 2002
On Sun, 27 Oct 2002, Koos Vriezen wrote:
> On Sun, 27 Oct 2002, David Faure wrote:
> Any particular event in mind? Should we catch the CloseEvent of
> KParts::MainWindow and post a new one after calling closeChildDialogs()?
Guess what, it even works:
@@ -276,6 +279,28 @@ KHTMLView::KHTMLView( KHTMLPart *part, Q
init();
viewport()->show();
+
+ d->watched = parent ? parent->topLevelWidget() : this;
+ d->watched->installEventFilter(this);
+}
+
+bool KHTMLView::eventFilter(QObject *watched, QEvent *e) {
+ if (watched != d->watched) // can this happen?
+ return QScrollView::eventFilter(watched, e);
+ if (e->type () == QEvent::Reparent) {
+ kdDebug( 6000 ) << "#####KHTMLView::eventFilter reparent" << endl;
+ watched->removeEventFilter(this);
+ d->watched = topLevelWidget();
+ d->watched->installEventFilter(this);
+ } else if (e->type () == QEvent::Close) {
+ kdDebug( 6000 ) << "####KHTMLView::eventFilter close" << endl;
+ closeChildDialogs();
+ QApplication::postEvent(watched, new QEvent(*e));
+ watched->removeEventFilter(this);
+ d->watched = 0L;
+ return true;
+ }
+ return QScrollView::eventFilter(watched, e);
}
It's a bit ugly. The 'can this happen?' question, should be 'yes it can'.
Lot's of QScrollView or lower events come.
If this is a possible solution, better make a specialized QObject for it I
think.
I do consider this a quick hack for this problem.
> Koos
-------------- next part --------------
Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.492
diff -u -3 -p -r1.492 khtmlview.cpp
--- khtmlview.cpp 2002/10/24 12:10:50 1.492
+++ khtmlview.cpp 2002/10/27 15:21:43
@@ -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>
@@ -106,6 +107,7 @@ public:
complete = false;
tooltip = 0;
possibleTripleClick = false;
+ watched = 0L;
}
~KHTMLViewPrivate()
{
@@ -228,6 +230,7 @@ public:
QRect updateRect;
KHTMLToolTip *tooltip;
QPtrDict<QWidget> visibleWidgets;
+ QObject *watched;
};
#ifndef QT_NO_TOOLTIP
@@ -276,6 +279,28 @@ KHTMLView::KHTMLView( KHTMLPart *part, Q
init();
viewport()->show();
+
+ d->watched = parent ? parent->topLevelWidget() : this;
+ d->watched->installEventFilter(this);
+}
+
+bool KHTMLView::eventFilter(QObject *watched, QEvent *e) {
+ if (watched != d->watched) // can this happen?
+ return QScrollView::eventFilter(watched, e);
+ if (e->type () == QEvent::Reparent) {
+ kdDebug( 6000 ) << "#####KHTMLView::eventFilter reparent" << endl;
+ watched->removeEventFilter(this);
+ d->watched = topLevelWidget();
+ d->watched->installEventFilter(this);
+ } else if (e->type () == QEvent::Close) {
+ kdDebug( 6000 ) << "####KHTMLView::eventFilter close" << endl;
+ closeChildDialogs();
+ QApplication::postEvent(watched, new QEvent(*e));
+ watched->removeEventFilter(this);
+ d->watched = 0L;
+ return true;
+ }
+ return QScrollView::eventFilter(watched, e);
}
KHTMLView::~KHTMLView()
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 15:21:43
@@ -147,6 +147,11 @@ public:
**/
void closeChildDialogs();
+ /**
+ * Monitor our topLevelWidget for unexpected closings
+ */
+ bool eventFilter(QObject *watched, QEvent *e);
+
signals:
void cleared();
void zoomView( int );
More information about the kfm-devel
mailing list