Bug 95266

Summary: [test case] :last-child pseudo-class selects all elements in a list
Product: [Applications] konqueror Reporter: Allan Sandfeld <kde>
Component: khtmlAssignee: Konqueror Bugs <konqueror-bugs-null>
Status: RESOLVED FIXED    
Severity: normal    
Priority: NOR    
Version First Reported In: unspecified   
Target Milestone: ---   
Platform: unspecified   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:
Attachments: Test case
Proposed patch

Description Allan Sandfeld 2004-12-16 14:18:33 UTC
Version:            (using KDE KDE 3.3.0)
Installed from:    Unspecified

Just adding the bug for record-keeping

This is the same bug that creates false results for :only-child and :nth-last-child.

It happens because elements in lists are styled one at a time, and at the time their style is determined, they are all the currently the last element.

I propably happens for other structures than lists, but I think lists demonstrates it most easily.

A possible fix could be too add an extra late restyling run for structures that have been optimized this way. During the first run :last structures would return false, and mark the container as last-child-dirty to indicate a late restyling is needed.
Comment 1 Allan Sandfeld 2004-12-16 14:25:04 UTC
Created attachment 8691 [details]
Test case
Comment 2 Germain Garand 2004-12-16 15:12:36 UTC
yes, there are other instances of that, see e.g #89249
Maybe restyling from a Renderer's ::close() method would be the easier way, since (I believe?) this can only happen while parsing.
Comment 3 Germain Garand 2004-12-16 15:16:32 UTC
(but then maybe the element's style should be marked as somehow uncertain by the pseudo class selection process)
Comment 4 Thiago Macieira 2004-12-16 20:17:30 UTC
Can't it unmark the previous one?

This would solve the problem for :last-child, but I doubt it would work for :nth-*.
Comment 5 Germain Garand 2004-12-16 21:54:14 UTC
I'm speaking about marking the parent node, not the child ; it's because a container has not been entirely parsed (and its associated renderer closed) that new childs can get a too early pseudo-class selection.
Comment 6 Allan Sandfeld 2004-12-17 01:19:04 UTC
Bug #89249 means :empty as well. Still no CSS2 pseudo-classes. 
I think the safe choice is to start by returning false on uncertain classes, and then restyle them completely later. The parent is marked and the element itself is marked.

I hadn't thought about Renderer close(), I thought it would be more logical for the code to belong under html/. The two places in htmlparser.cpp where closeRenderer is called looks promising.
Comment 7 Allan Sandfeld 2004-12-17 16:31:13 UTC
Created attachment 8701 [details]
Proposed patch

Fixed all the current problems, but a few issues remain. First of all tables or
other structures where :last-child already work shouldn't be restyled late. 

Second I discovered the selector test css3-modsel-d4.html. It seems
:first-child and :last-child are supposed to be dynamically updated, if the
ECMAscript are used to move elements around. We don't do that.
Comment 8 Allan Sandfeld 2004-12-18 19:46:50 UTC
CVS commit by carewolf: 

Fix structural pseudo-classes that needs to know the object or parents full 
extent (:empty, :last-child, :only-child and :nth-last-child)
BUG: 89249, 95266


  M +12 -0     ChangeLog   1.356
  M +42 -12    css/cssstyleselector.cpp   1.338
  M +4 -3      html/htmlparser.cpp   1.353
  M +26 -0     xml/dom_elementimpl.cpp   1.203
  M +9 -0      xml/dom_elementimpl.h   1.119
  M +7 -0      xml/dom_nodeimpl.cpp   1.245
  M +7 -0      xml/dom_nodeimpl.h   1.164
  M +1 -1      xml/xml_tokenizer.cpp   1.60