Bug 5468

Summary: CSS3: only-child and only-of-type pseudo-selectors (affects Acid3)
Product: WebKit Reporter: Timothy Hatcher <timothy>
Component: CSSAssignee: Dave Hyatt <hyatt>
Status: RESOLVED FIXED    
Severity: Normal CC: bdakin, cgriego, gabe, hyatt, ian, info, joost, Justin, nickshanks, phiw2, webkit
Priority: P2    
Version: 412   
Hardware: Macintosh   
OS: OS X 10.4   
Bug Depends on: 3442, 4812    
Bug Blocks: 17064, 11390, 13446    
Attachments:
Description Flags
patch to *remove* support for these properties
hyatt: review-
lets see if dave likes this one any better
hyatt: review-
aye aye cap'n!
none
Implement :only-child and :only-of-type
none
Patch oliver: review+

Description Timothy Hatcher 2005-10-23 08:46:17 PDT
bug 3442 laid the framework for this, but didn't finish these 2 pseudo-selectors.

Here are the 2 test cases:
http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/html/tests/css3-modsel-35.html
http://www.w3.org/Style/CSS/Test/CSS3/Selectors/current/html/tests/css3-modsel-36.html
Comment 1 Eric Seidel (no email) 2005-12-27 15:41:55 PST
Joost also just filed a bug asking for the nth- selectors as well.
Comment 3 Nicholas Shanks 2006-11-20 16:17:42 PST
*** Bug 11385 has been marked as a duplicate of this bug. ***
Comment 4 Nicholas Shanks 2006-11-20 16:18:10 PST
*** Bug 11386 has been marked as a duplicate of this bug. ***
Comment 5 mitz 2006-12-08 12:53:32 PST
*** Bug 11785 has been marked as a duplicate of this bug. ***
Comment 6 Nicholas Shanks 2007-02-07 06:52:39 PST
Created attachment 12999 [details]
patch to *remove* support for these properties

Until such time as a correct implementation can be developed, I believe it would be better to not support these at all rather than to support them incorrectly. The current behaviour of :last-child behaving like a base element selector, and :only-child behaving like :first-child is highly detrimental.
Comment 7 Maciej Stachowiak 2007-02-07 08:05:02 PST
This might not be a bad idea, though I think hyatt would be the best judge.
Comment 8 Gabe da Silveira 2007-02-07 08:13:15 PST
I'll put in my vote for that idea as well since this bug bit me in the ass hard a few months ago.
Comment 9 Dave Hyatt 2007-02-07 15:31:08 PST
Comment on attachment 12999 [details]
patch to *remove* support for these properties

Yeah, I agree with removing support for these.

You haven't adequately removed them unless the rules are rejected.  You need to go further and actually yank the names from the list of pseudo types completely.

For  example:

:last-child, div { color: red }

should be rejected since last-child is unrecognized.

Also,

:not(:last-child)

needs to also be rejected.  With your patch :last-child just always returns a failed match, which will cause :not(:last-child) to always match.
Comment 10 Nicholas Shanks 2007-02-07 18:13:52 PST
Created attachment 13032 [details]
lets see if dave likes this one any better
Comment 11 Dave Hyatt 2007-02-08 21:15:10 PST
Comment on attachment 13032 [details]
lets see if dave likes this one any better

Patch looks good.  Since the tests that are being landed are expected failures, I'd prefer they go under css3/expected_failures/ (as we did with table tests that have failing results), so that there's no confusion about the fact that we're deliberately checking in failing test cases.

I'll r+ once the tests are moved.
Comment 12 Dave Hyatt 2007-02-08 21:16:25 PST
(Also changelog typo, I assume you meant "erroneously")
Comment 13 Nicholas Shanks 2007-02-08 21:59:04 PST
Created attachment 13078 [details]
aye aye cap'n!
Comment 14 Dave Hyatt 2007-02-08 22:19:17 PST
Comment on attachment 13078 [details]
aye aye cap'n!

r=me
Comment 15 Mark Rowe (bdash) 2007-02-09 06:06:37 PST
Patch to remove support landed in r19528.
Comment 16 Mark Rowe (bdash) 2007-02-09 06:07:17 PST
Comment on attachment 13078 [details]
aye aye cap'n!

Marking obsolete to get it out of the commit queue.
Comment 17 Mark Rowe (bdash) 2007-02-09 06:08:54 PST
Comment on attachment 13078 [details]
aye aye cap'n!

Apparently being obsolete doesn't matter to the commit queue... Removing review flag to make it go away.
Comment 18 Eric Seidel (no email) 2007-12-28 22:22:31 PST
Acid3, test0 depends on dynamic :last-child support.
Comment 19 Eric Seidel (no email) 2008-01-01 22:22:32 PST
:last-of-type causes test 39 to fail as well.

      selectorTest(function (doc, add, expect) {
        builder(doc);
        var match = add(":last-of-type");
        var values = [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1];
        for (var i = 0; i < elements.length; i += 1)
          expect(elements[i], values[i] ? match : 0, "part 2:" + i);
      });

i = 7 when we fail.
Comment 20 Eric Seidel (no email) 2008-01-09 01:34:15 PST
Returning this to unassigned as it's seen no activity from the assignee in 11 months.
Comment 21 Dave Hyatt 2008-02-02 11:53:05 PST
*** Bug 17155 has been marked as a duplicate of this bug. ***
Comment 22 Dave Hyatt 2008-02-02 11:58:21 PST
Created attachment 18871 [details]
Implement :only-child and :only-of-type
Comment 23 Dave Hyatt 2008-02-02 12:21:51 PST
Created attachment 18872 [details]
Patch
Comment 24 Oliver Hunt 2008-02-02 15:04:19 PST
Comment on attachment 18872 [details]
Patch

r=me
Comment 25 Dave Hyatt 2008-02-02 18:31:33 PST
Fixed in r29944.