Bug 59489 - Implement label form focus in khtml
Summary: Implement label form focus in khtml
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml forms (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
: 131730 (view as bug list)
Depends on:
Blocks:
 
Reported: 2003-06-07 23:08 UTC by Shift
Modified: 2006-08-02 15:16 UTC (History)
4 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Shift 2003-06-07 23:08:14 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources

Is it possible to implement focusing on form element if the coressponding label get the focus (mouse clic) ?

For example in this form when you clic on "Denis (Cybercodeur)" the corresponding option is selected (Opera and Mozilla) :
http://www.cybercodeur.net/contact/index.php
(The hand cursor is not in the specification and is just a CSS rule of the author of the page)

Here is what the w3c says :
"When a LABEL element receives focus, it passes the focus on to its associated control. See the section below on access keys for examples."
Cf. http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.9.1

It will be great if you do that :)
Comment 1 Shift 2003-06-07 23:10:25 UTC
Oups !!! 
Sorry I have forgotten to set this bug as a wishlist one :-( 
 
How can I change this ? 
Comment 2 Anna Nymos 2003-06-08 14:03:00 UTC
I think you can't do this. Did it for you. 
Comment 3 fredi 2003-06-17 12:57:25 UTC
I can confirm this BUG (non standard compliance is a BUG IMO) with Konqueror up to (at last) 3.1.2 .
Comment 4 Bernd Wurst 2003-10-29 17:23:32 UTC
This bug is still present in 3.2.0_alpha2.
I also would call this a bug.
Comment 5 Shift 2004-01-24 08:38:47 UTC
Bug always here in KDE CVS
Comment 6 Jesse Pelton 2004-03-17 14:53:37 UTC
Still in 3.2.1.  It would ideally be marked NEW, not UNCONFIRMED, since several people have seen it.  And I too think that since this is a clear failure to implement the HTML spec, this is a bug of at least normal severity, not a wishlist item.

I can create and attach a test case if it would be useful.

Safari would also benefit if this were fixed; maybe Apple would take it on.
Comment 7 Timo A. Hummel 2004-04-23 11:46:55 UTC
I just set this bug to status NEW, severity normal, so that someone can fix this bug.
Comment 8 Mathieu Jobin 2004-05-14 00:51:03 UTC
Here is an easier test case.

<input id="check_group_id_28" type="checkbox" name="selected_group[]" value="28">
<label for="check_group_id_28">Can access Alarm System settings</label>
Comment 9 bj 2004-06-28 17:33:22 UTC
Good news:
I just posted a patch fixing this issue on the kfm-devel mailing list:
http://lists.kde.org/?l=kfm-devel&m=108843658120199&w=2
Waiting for feedback :)
Comment 10 bj 2004-07-12 19:42:14 UTC
CVS commit by mardelle: 

Clicking on a label will focus/activate the form element

CCMAIL: 59489-done@bugs.kde.org


  M +6 -3      khtmlview.cpp   1.643
  M +35 -8     html/html_formimpl.cpp   1.373
  M +3 -1      html/html_formimpl.h   1.153


--- kdelibs/khtml/html/html_formimpl.cpp  #1.372:1.373
@@ -1151,4 +1151,5 @@ void HTMLInputElementImpl::click()
 {
     QMouseEvent me(QEvent::MouseButtonRelease, QPoint(0,0),Qt::LeftButton, 0);
+    dispatchMouseEvent(&me,0, 1);
     dispatchMouseEvent(&me,EventImpl::CLICK_EVENT, 1);
 }
@@ -1581,13 +1582,39 @@ void HTMLLabelElementImpl::attach()
 }
 
-#if 0
-ElementImpl *HTMLLabelElementImpl::formElement()
+NodeImpl* HTMLLabelElementImpl::getFormElement()
 {
     DOMString formElementId = getAttribute(ATTR_FOR);
-    if (formElementId.isEmpty())
-        return 0;
-    return getDocument()->getElementById(formElementId);
+            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
 
 // -------------------------------------------------------------------------

--- kdelibs/khtml/html/html_formimpl.h  #1.152:1.153
@@ -320,4 +320,6 @@ public:
     virtual Id id() const;
     virtual void attach();
+    virtual void defaultEventHandler(EventImpl *evt);
+    NodeImpl* getFormElement();
 
  private:

--- kdelibs/khtml/khtmlview.cpp  #1.642:1.643
@@ -1878,4 +1878,10 @@ bool KHTMLView::focusNodeWithAccessKey( 
             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:
@@ -1891,7 +1897,4 @@ bool KHTMLView::focusNodeWithAccessKey( 
             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


Comment 11 Jozef Kosoru 2004-09-28 19:55:10 UTC
This bug is still present in Konqueror 3.2.2 - so is it really fixed?
Comment 12 Jozef Kosoru 2004-09-28 19:57:14 UTC
Even Konqueror 3.2.3 has still this bug.
Comment 13 Matt Rogers 2004-09-28 21:09:30 UTC
The latest version of Konqueror is 3.3.0. It is most likely fixed in
that version.

Comment 14 Jesse Pelton 2004-09-29 02:42:27 UTC
Yup. Works for me in Konqueror 3.3.
Comment 15 Juergen Heinemann 2006-07-24 22:26:51 UTC
KHTML 3.5.4 svn trunk build 24.07.2006
GCC 3.3.5
label  didn't checked by 
[code]
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" dir="ltr">
  <head>
    <title>Accebility</title>
  </head>
<body>
<div>
	<label>Accebility
		<input type="checkbox" />
	</label>
	<hr />
	<label for="set">Accebility</label>
	<input id="set" type="checkbox" />
</div>
</body>
</html>
[/CODE]
Comment 16 Allan Sandfeld 2006-07-30 16:31:00 UTC
Hmm.. as far as I can see we pass focus, but unlike firefox the button is not checked anymore.
Comment 17 Allan Sandfeld 2006-07-30 16:39:46 UTC
It's a regression 
Comment 18 Allan Sandfeld 2006-07-30 17:04:08 UTC
SVN commit 567892 by carewolf:

Correct the patch for #166092 so it doesn't regress #59489
CCBUG:116092
BUG:59489


 M  +2 -2      html_formimpl.cpp  


--- branches/KDE/3.5/kdelibs/khtml/html/html_formimpl.cpp #567891:567892
@@ -1917,10 +1917,10 @@
 
 	if (act) {
 	    NodeImpl* const formNode=getFormElement();
-	    if (formNode) {
+	    if (formNode && evt->target() != formNode) {
 		getDocument()->setFocusNode(formNode);
 		if (formNode->id()==ID_INPUT)
-		    static_cast<DOM::HTMLInputElementImpl*>(formNode)->defaultEventHandler(evt);
+		    static_cast<DOM::HTMLInputElementImpl*>(formNode)->click();
 		evt->setDefaultHandled();
 	    }
 	}
Comment 19 Allan Sandfeld 2006-08-02 15:16:11 UTC
*** Bug 131730 has been marked as a duplicate of this bug. ***