Bug 58799 - <td> cellIndex using DOM has incorrect value
Summary: <td> cellIndex using DOM has incorrect value
Status: RESOLVED FIXED
Alias: None
Product: konqueror
Classification: Applications
Component: khtml ecma (show other bugs)
Version: unspecified
Platform: Gentoo Packages Linux
: NOR normal
Target Milestone: ---
Assignee: Konqueror Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-05-22 13:03 UTC by Andrew
Modified: 2005-06-17 04:55 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Poposed patch (1.24 KB, patch)
2004-09-26 21:50 UTC, Rob Buis
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew 2003-05-22 13:03:30 UTC
Version:            (using KDE KDE 3.1.2)
Installed from:    Gentoo Packages
Compiler:          gcc 3.2.2 
OS:          Linux

I'm using javascript as part of a webapp project, and as part of that project, I track which cell a user has click in an html <table>.  Using DOM methods, I lookup the cellIndex of the html element they clicked on.  Opera, IE6, Mozilla1.3, and Netscape7 all return the expected value.  Konqueror does not.
Example:
<html>
<head>
<title>blah</title>
</head>
<body>
<table border=1>
<tr>
<td onclick="alert(this.cellIndex)">Test1</td>
<td onclick="alert(this.cellIndex)">Test2</td>
</tr>
</table>
</body>
</html>

In all the above browsers mentioned (except Konq, of course) clicking on 'Test1' brings up an alert box displaying '0', and clicking Test2 brings up an alert box display '1'.  Konqueror, on the other hand, displays '0' in both cases.  I believe this to be a bug.
Comment 1 George Staikos 2003-07-02 21:12:01 UTC
Yes, cellIndex() is not implemented. 
Comment 2 George Staikos 2003-09-29 09:53:37 UTC
Better return this to the pool.  I don't have time to finish it right now. 
Comment 3 Stephan Kulow 2003-12-02 15:27:42 UTC
JFR: http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID-84150186

cellIndex of type long, readonly 
The index of this cell in the row, starting from 0. This index is in document tree order and not display order.
Comment 4 Rob Buis 2004-09-26 21:50:31 UTC
Created attachment 7690 [details]
Poposed patch

Hi,

The attached patch works for this testcase, but maybe it needs
more testing?
Cheers,

Rob.
Comment 5 Harri Porten 2005-05-07 15:50:40 UTC
Applied the patch. Even if it weren't quite right it's better than nothing.
Comment 6 Maksim Orlovich 2005-06-17 04:48:33 UTC
SVN commit 426346 by orlovich:

justing in #khtml was looking at the cellIndex commit, and asked: 
could there be other tags then TD in a TR? The answer is yes, so
using nodeIndex for cellIndex isn't quite right. This testcase 
shows the difference (and the baseline is right). Proper fix 
upcoming. 
CCBUG:58799



 A             baseline/unsorted/58799.html-dom  
 AM            baseline/unsorted/58799.html-dump.png  
 A             baseline/unsorted/58799.html-render  
 A             tests/unsorted/58799.html  


** trunk/tests/khtmltests/regression/baseline/unsorted/58799.html-dump.png #property changes
Name: svn:mime-type
   + application/octet-stream
Comment 7 Maksim Orlovich 2005-06-17 04:55:58 UTC
SVN commit 426347 by orlovich:

Make cellIndex not count tags != TD, TH  when counting its index.
Code essentially copies from the sectionRowIndex code from TRs.
CCBUG:58799


 M  +11 -1     html_tableimpl.cpp  


--- trunk/KDE/kdelibs/khtml/html/html_tableimpl.cpp #426346:426347
@@ -791,7 +791,17 @@
 
 long HTMLTableCellElementImpl::cellIndex() const
 {
-    return nodeIndex();
+    int cIndex = 0;
+    const NodeImpl *n = this;
+    do {
+        n = n->previousSibling();
+        if (n && (n->isElementNode() && n->id() == ID_TD ||
+                  n->isElementNode() && n->id() == ID_TH))
+            cIndex++;
+    }
+    while (n);
+
+    return cIndex;
 }
 
 void HTMLTableCellElementImpl::parseAttribute(AttributeImpl *attr)