[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: [PATCH] fix label form focus #59489
From: bj () altern ! org
Date: 2004-06-28 15:29:41
Message-ID: 200406281736.13814.bj () altern ! org
[Download RAW message or body]
[Attachment #2 (multipart/mixed)]
Hello!
Wow, my second patch in 3 days!
The following patch implements (or fixes, since it is a w3c recommandation)
bug 59489 (http://bugs.kde.org/show_bug.cgi?id=59489).
With the patch, you can click on the label of a checkbox/radiobox to select
it.
Clicking on a text input, combobox or anything else label focuses it.
Please review/correct/commit.
regards
["formsclick.diff" (text/x-diff)]
Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.639
diff -u -3 -r1.639 khtmlview.cpp
--- khtmlview.cpp 19 Jun 2004 20:47:34 -0000 1.639
+++ khtmlview.cpp 28 Jun 2004 15:18:40 -0000
@@ -727,17 +733,21 @@
d->clickX = xm;
d->clickY = ym;
}
-
bool swallowEvent = \
dispatchMouseEvent(EventImpl::MOUSEDOWN_EVENT,mev.innerNode.handle(),true,
\
d->clickCount,_mouse,true,DOM::NodeImpl::MousePress);
-
+
khtml::RenderObject* r = mev.innerNode.handle() ? \
mev.innerNode.handle()->renderer() : 0; if (r && r->isWidget())
_mouse->ignore();
-
+
if (!swallowEvent) {
emit m_part->nodeActivated(mev.innerNode);
-
+ if (mev.innerNode.handle()->parentNode()->id()==ID_LABEL)
+ {
+ DOM::ElementImpl *inputForm=static_cast<DOM::HTMLLabelElementImpl*>(mev.innerNode.handle()->parentNode())->formElement();
+ if (inputForm)
+ static_cast<DOM::HTMLInputElementImpl*>(inputForm)->activateInput();
+ }
khtml::MousePressEvent event( _mouse, xm, ym, mev.url, mev.target, mev.innerNode );
QApplication::sendEvent( m_part, &event );
// we might be deleted after this
Index: html/html_formimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.cpp,v
retrieving revision 1.372
diff -u -3 -r1.372 html_formimpl.cpp
--- html/html_formimpl.cpp 22 Jun 2004 05:46:41 -0000 1.372
+++ html/html_formimpl.cpp 28 Jun 2004 15:18:46 -0000
@@ -1553,6 +1553,19 @@
}
}
+void HTMLInputElementImpl::activateInput()
+{
+switch (m_type)
+{
+case RADIO:
+case CHECKBOX:
+setChecked(!checked());
+break;
+default:
+focus();
+}
+}
+
bool HTMLInputElementImpl::isEditable()
{
return ((m_type == TEXT) || (m_type == PASSWORD) || (m_type == ISINDEX) || \
(m_type == FILE)); @@ -1580,15 +1593,20 @@
HTMLElementImpl::attach();
}
-#if 0
+
ElementImpl *HTMLLabelElementImpl::formElement()
{
DOMString formElementId = getAttribute(ATTR_FOR);
if (formElementId.isEmpty())
- return 0;
+ {
+ uint children=childNodeCount();
+ if (children>1)
+ for (unsigned int i=0;i<children;i++)
+ if (childNode(i)->id()==ID_INPUT) return \
static_cast<DOM::ElementImpl*>(childNode(i)); + return 0;
+ }
return getDocument()->getElementById(formElementId);
}
-#endif
// -------------------------------------------------------------------------
Index: html/html_formimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.h,v
retrieving revision 1.152
diff -u -3 -r1.152 html_formimpl.h
--- html/html_formimpl.h 22 Jun 2004 05:46:41 -0000 1.152
+++ html/html_formimpl.h 28 Jun 2004 15:18:46 -0000
@@ -291,6 +291,7 @@
DOMString altText() const;
void activate();
+ void activateInput();
protected:
@@ -319,6 +320,7 @@
virtual Id id() const;
virtual void attach();
+ virtual ElementImpl* formElement();
private:
DOMString m_formElementID;
[Attachment #6 (application/pgp-signature)]
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic