Fix for onBlur/onFocus
Koos Vriezen
koos.vriezen at xs4all.nl
Sat Aug 24 23:06:28 BST 2002
Hi,
This test case shows two problems with focus handling and form elements.
<html><head><script>
function myOnXX(str) {
document.output.value = document.output.value + "\n" + str;
}
</script></head><body><form>
<input type="text" onFocus="myOnXX('focus')" onBlur="myOnXX('blur')">
<input type="text"><br>
<textarea name='output' rows=50 cols=80></textarea>
</form></body></html>
First, if you move the focus from the first to the second text box with
the mouse, two onBlur events occur. The first patch handles that case.
Second, if you move the focus from the second to the first text box, using
<SHIFT><TAB>, a focus, blur, focus occur. The second patch handles that
in a bit of a crude way. Maybe tell a RenderWidget not to propagate an
event in that case.
Regards,
Koos Vriezen
-------------- next part --------------
Index: rendering/render_replaced.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_replaced.cpp,v
retrieving revision 1.96
diff -u -3 -p -r1.96 render_replaced.cpp
--- rendering/render_replaced.cpp 2002/08/13 01:52:38 1.96
+++ rendering/render_replaced.cpp 2002/08/24 22:05:46
@@ -307,7 +307,7 @@ bool RenderWidget::eventFilter(QObject*
if ( QFocusEvent::reason() != QFocusEvent::Popup )
{
//kdDebug(6000) << "RenderWidget::eventFilter captures FocusOut" << endl;
- element()->dispatchHTMLEvent(EventImpl::BLUR_EVENT,false,false);
+ element()->getDocument()->setFocusNode(0L);
// if ( element()->isEditable() ) {
// KHTMLPartBrowserExtension *ext = static_cast<KHTMLPartBrowserExtension *>( element()->view->part()->browserExtension() );
// if ( ext ) ext->editableWidgetBlurred( m_widget );
-------------- next part --------------
Index: xml/dom_docimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/xml/dom_docimpl.cpp,v
retrieving revision 1.193
diff -u -3 -p -r1.193 dom_docimpl.cpp
--- xml/dom_docimpl.cpp 2002/08/20 00:33:22 1.193
+++ xml/dom_docimpl.cpp 2002/08/24 22:04:49
@@ -1872,6 +1872,11 @@ void DocumentImpl::setFocusNode(NodeImpl
if (newFocusNode && (newFocusNode->getDocument() != this))
return;
+ static int recursion_count = 0;
+ if (recursion_count)
+ return;
+ recursion_count++;
+
if (m_focusNode != newFocusNode) {
NodeImpl *oldFocusNode = m_focusNode;
// Set focus on the new node
@@ -1886,6 +1891,7 @@ void DocumentImpl::setFocusNode(NodeImpl
oldFocusNode->dispatchUIEvent(EventImpl::DOMFOCUSOUT_EVENT);
if ((oldFocusNode == this) && oldFocusNode->hasOneRef()) {
oldFocusNode->deref(); // deletes this
+ recursion_count--;
return;
}
else {
@@ -1912,6 +1918,7 @@ void DocumentImpl::setFocusNode(NodeImpl
updateRendering();
}
+ recursion_count--;
}
void DocumentImpl::attachNodeIterator(NodeIteratorImpl *ni)
More information about the kfm-devel
mailing list