[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: Re: activate vs. click event
From: bj () altern ! org
Date: 2004-07-12 9:57:18
Message-ID: 200407121203.33206.bj () altern ! org
[Download RAW message or body]
Ok, last version of my patch.
1) Regarding the label accesskey, I thought of a new way to handle it, simply
passing the label's referrer to the accesskey handler. It seems to me to be
the easiest solution, no need to a HTMLLabelElementImpl::click() method...
2) Clicking on a label will generate a click on it's referrer element. I could
revert to a simple focus, but still I think the biggest interest in the label
element is for checkboxes and radio buttons. It's really nice to be able to
click on their text to check them, like it works in the KDE widgets!
Let me know if you wish me to make any changes, I would like to commit soon if
possible.
["label_activation.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 11 Jul 2004 23:12:01 -0000
@@ -1871,6 +1940,12 @@
if( node != NULL && node->hasOneRef())
return true;
}
+ if (node->id()==ID_LABEL)
+ {
+ // if Accesskey is a label, give focus to the label's referrer.
+ node=static_cast<ElementImpl *>(static_cast< HTMLLabelElementImpl* >( node )->getFormElement());
+ if (!node) return true;
+ }
switch( node->id()) {
case ID_A:
static_cast< HTMLAnchorElementImpl* >( node )->click();
@@ -1884,9 +1959,6 @@
case ID_AREA:
static_cast< HTMLAreaElementImpl* >( node )->click();
break;
- case ID_LABEL:
- // TODO should be click(), after it works for label
- break;
case ID_TEXTAREA:
break; // just focusing it is enough
case ID_LEGEND:
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 11 Jul 2004 23:12:02 -0000
@@ -1150,6 +1150,7 @@
void HTMLInputElementImpl::click()
{
QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0,0),Qt::LeftButton, 0);
+ dispatchMouseEvent(&me,0, 1);
dispatchMouseEvent(&me,EventImpl::CLICK_EVENT, 1);
}
@@ -1580,15 +1581,41 @@
HTMLElementImpl::attach();
}
-#if 0
-ElementImpl *HTMLLabelElementImpl::formElement()
+NodeImpl* HTMLLabelElementImpl::getFormElement()
{
- DOMString formElementId = getAttribute(ATTR_FOR);
- if (formElementId.isEmpty())
- return 0;
- return getDocument()->getElementById(formElementId);
+ DOMString formElementId = getAttribute(ATTR_FOR);
+ NodeImpl *newNode=0L;
+ if (!formElementId.isEmpty())
+ newNode=getDocument()->getElementById(formElementId);
+ if (!newNode){
+ 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){
+ newNode=childNode(i);
+ break;
+ }
+ }
+ }
+return newNode;
+}
+
+void HTMLLabelElementImpl::defaultEventHandler(EventImpl *evt)
+ {
+ if ( !m_disabled &&
+ evt->isMouseEvent() && evt->id() == EventImpl::CLICK_EVENT){
+ NodeImpl *formNode=getFormElement();
+ if (formNode)
+ {
+ getDocument()->setFocusNode(formNode);
+ if (formNode->id()==ID_INPUT)
+ static_cast<DOM::HTMLInputElementImpl*>(formNode)->click();
+ }
+ evt->setDefaultHandled();
+ }
+ 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 11 Jul 2004 23:12:03 -0000
@@ -319,6 +319,8 @@
virtual Id id() const;
virtual void attach();
+ virtual void defaultEventHandler(EventImpl *evt);
+ NodeImpl* getFormElement();
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