[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: Re: [PATCH] Last version of the "fix label form focus" (59489)
From: bj () altern ! org
Date: 2004-07-07 21:36:47
Message-ID: 200407072344.05719.bj () altern ! org
[Download RAW message or body]
Grmbl!
Sorry for spamming this list with this ever changing patch, but at least I am
learning things!
Now works also with <select> and <textarea>...
Didn't add a defaultEventHandler method for HTMLTextAreaElementImpl and
HTMLSelectElementImpl, since all is needed is to focus them... If that's
another of my bad ideas, let me know.
regards
["forms.diff" (text/x-diff)]
Index: khtmlview.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/khtmlview.cpp,v
retrieving revision 1.640
diff -u -3 -r1.640 khtmlview.cpp
--- khtmlview.cpp 30 Jun 2004 16:20:34 -0000 1.640
+++ khtmlview.cpp 7 Jul 2004 21:09:56 -0000
@@ -1885,7 +1885,7 @@
static_cast< HTMLAreaElementImpl* >( node )->click();
break;
case ID_LABEL:
- // TODO should be click(), after it works for label
+ static_cast< HTMLLabelElementImpl* >( node )->click();
break;
case ID_TEXTAREA:
break; // just focusing it is enough
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 7 Jul 2004 21:09:57 -0000
@@ -1481,19 +1481,22 @@
{
if (evt->isMouseEvent()) {
- MouseEventImpl *me = static_cast<MouseEventImpl*>(evt);
if ((m_type == RADIO || m_type == CHECKBOX)
- && me->id() == EventImpl::MOUSEUP_EVENT && me->detail() > 0) {
+ && evt->id() == EventImpl::CLICK_EVENT) {
// click will follow
setChecked(m_type == RADIO ? true : !checked());
+ focus(); // nedded for when the input is activated via its label
}
if (evt->id() == EventImpl::CLICK_EVENT && m_type == IMAGE && m_render) \
{ // record the mouse position for when we get the DOMActivate event
int offsetX, offsetY;
+ MouseEventImpl *me = static_cast<MouseEventImpl*>(evt);
m_render->absolutePosition(offsetX,offsetY);
xPos = me->clientX()-offsetX;
yPos = me->clientY()-offsetY;
}
+ if ((m_type == TEXT || m_type == PASSWORD || m_type == FILE) && \
evt->id()==EventImpl::CLICK_EVENT) + focus();
}
if (m_type == RADIO || m_type == CHECKBOX || m_type == SUBMIT || m_type == \
RESET || m_type == BUTTON ) { @@ -1580,15 +1583,52 @@
HTMLElementImpl::attach();
}
-#if 0
-ElementImpl *HTMLLabelElementImpl::formElement()
+void HTMLLabelElementImpl::click()
{
- DOMString formElementId = getAttribute(ATTR_FOR);
- if (formElementId.isEmpty())
- return 0;
- return getDocument()->getElementById(formElementId);
+ QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0,0),Qt::LeftButton, 0);
+ dispatchMouseEvent(&me,EventImpl::CLICK_EVENT, 1);
+}
+
+void HTMLLabelElementImpl::defaultEventHandler(EventImpl *evt)
+ {
+ if (( !m_disabled ) && (evt->isMouseEvent()))
+ if (evt->id() == EventImpl::CLICK_EVENT){
+ DOMString formElementId = getAttribute(ATTR_FOR);
+ NodeImpl *form=0L;
+ if (!formElementId.isEmpty())
+ form=getDocument()->getElementById(formElementId);
+ if (!form){
+ uint children=childNodeCount();
+ if (children>1)
+ for (unsigned int i=0;i<children;i++){
+ uint nodeId=childNode(i)->id();
+ if (nodeId==ID_INPUT || nodeId==ID_SELECT || nodeId==ID_TEXTAREA){
+ form=childNode(i);
+ break;
+ }
+ }
+ }
+ if (form)
+ switch (form->id()){
+ case ID_INPUT:{
+ static_cast<DOM::HTMLInputElementImpl*>(form)->click();
+ break;
+ }
+ case ID_SELECT:{
+ static_cast<DOM::HTMLSelectElementImpl*>(form)->focus();
+ break;
+ }
+ case ID_TEXTAREA:{
+ static_cast<DOM::HTMLTextAreaElementImpl*>(form)->focus();
+ break;
+ }
+ }
+ evt->setDefaultHandled();
+ form=0L;
+ delete form;
+ }
+ HTMLGenericFormElementImpl::defaultEventHandler(evt);
}
-#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 7 Jul 2004 21:09:58 -0000
@@ -319,6 +319,8 @@
virtual Id id() const;
virtual void attach();
+ virtual void defaultEventHandler(EventImpl *evt);
+ void click();
private:
DOMString m_formElementID;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic