Changeset 29944 in webkit


Ignore:
Timestamp:
Feb 2, 2008 6:28:46 PM (16 years ago)
Author:
hyatt@apple.com
Message:

WebCore:

Fix for bug 5468, support CSS3 :only-child and :only-of-type selectors.

Reviewed by olliej

Added fast/css/only-child-pseudo-class.html, fast/css/only-of-type-pseudo-class.html

  • css/CSSSelector.cpp: (WebCore::CSSSelector::extractPseudoType):
  • css/CSSSelector.h: (WebCore::CSSSelector::):
  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::checkOneSelector):

LayoutTests:

Add test for bug 5468, supporting :only-child and :only-of-type in CSS3.

Reviewed by olliej

  • platform/mac/fast/css/only-child-pseudo-class-expected.checksum: Added.
  • platform/mac/fast/css/only-child-pseudo-class-expected.png: Added.
  • platform/mac/fast/css/only-child-pseudo-class-expected.txt: Added.
  • platform/mac/fast/css/only-of-type-pseudo-class-expected.checksum: Added.
  • platform/mac/fast/css/only-of-type-pseudo-class-expected.png: Added.
  • platform/mac/fast/css/only-of-type-pseudo-class-expected.txt: Added.
Location:
trunk
Files:
6 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r29939 r29944  
     12008-02-02  David Hyatt  <hyatt@apple.com>
     2
     3        Add test for bug 5468, supporting :only-child and :only-of-type in CSS3.
     4
     5        Reviewed by olliej
     6
     7        * platform/mac/fast/css/only-child-pseudo-class-expected.checksum: Added.
     8        * platform/mac/fast/css/only-child-pseudo-class-expected.png: Added.
     9        * platform/mac/fast/css/only-child-pseudo-class-expected.txt: Added.
     10        * platform/mac/fast/css/only-of-type-pseudo-class-expected.checksum: Added.
     11        * platform/mac/fast/css/only-of-type-pseudo-class-expected.png: Added.
     12        * platform/mac/fast/css/only-of-type-pseudo-class-expected.txt: Added.
     13
    1142008-02-02  Darin Adler  <darin@apple.com>
    215
  • trunk/WebCore/ChangeLog

    r29943 r29944  
     12008-02-02  David Hyatt  <hyatt@apple.com>
     2
     3        Fix for bug 5468, support CSS3 :only-child and :only-of-type selectors.
     4
     5        Reviewed by olliej
     6
     7        Added fast/css/only-child-pseudo-class.html, fast/css/only-of-type-pseudo-class.html
     8
     9        * css/CSSSelector.cpp:
     10        (WebCore::CSSSelector::extractPseudoType):
     11        * css/CSSSelector.h:
     12        (WebCore::CSSSelector::):
     13        * css/CSSStyleSelector.cpp:
     14        (WebCore::CSSStyleSelector::checkOneSelector):
     15
    1162008-02-02  Darin Adler  <darin@apple.com>
    217
  • trunk/WebCore/css/CSSSelector.cpp

    r29933 r29944  
    101101    static AtomicString mediaControlsFullscreenButton("-webkit-media-controls-fullscreen-button");
    102102    static AtomicString notStr("not(");
     103    static AtomicString onlyChild("only-child");
     104    static AtomicString onlyOfType("only-of-type");
    103105    static AtomicString root("root");
    104106    static AtomicString searchCancelButton("-webkit-search-cancel-button");
     
    148150    else if (m_value == lastOfType)
    149151        m_pseudoType = PseudoLastOfType;
     152    else if (m_value == onlyChild)
     153        m_pseudoType = PseudoOnlyChild;
     154    else if (m_value == onlyOfType)
     155        m_pseudoType = PseudoOnlyOfType;
    150156    else if (m_value == firstLetter) {
    151157        m_pseudoType = PseudoFirstLetter;
  • trunk/WebCore/css/CSSSelector.h

    r29933 r29944  
    124124            PseudoLastChild,
    125125            PseudoLastOfType,
     126            PseudoOnlyChild,
     127            PseudoOnlyOfType,
    126128            PseudoFirstLine,
    127129            PseudoFirstLetter,
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r29933 r29944  
    16461646            }
    16471647            case CSSSelector::PseudoLastChild: {
    1648                 // first-child matches the first child that is an element
     1648                // last-child matches the last child that is an element
    16491649                if (e->parentNode() && e->parentNode()->isElementNode()) {
    16501650                    bool result = false;
     
    16671667            }
    16681668            case CSSSelector::PseudoLastOfType: {
    1669                 // first-of-type matches the first element of its type
     1669                // last-of-type matches the last element of its type
    16701670                if (e->parentNode() && e->parentNode()->isElementNode()) {
    16711671                    bool result = false;
     
    16851685                    }
    16861686                    return result;
     1687                }
     1688                break;
     1689            }
     1690            case CSSSelector::PseudoOnlyChild: {
     1691                if (e->parentNode() && e->parentNode()->isElementNode()) {
     1692                    bool firstChild = false;
     1693                    bool lastChild = false;
     1694                   
     1695                    Node* n = e->previousSibling();
     1696                    while (n && !n->isElementNode())
     1697                        n = n->previousSibling();
     1698                    if (!n)
     1699                        firstChild = true;
     1700                    if (firstChild) {
     1701                        n = e->nextSibling();
     1702                        while (n && !n->isElementNode())
     1703                            n = n->nextSibling();
     1704                        if (!n)
     1705                            lastChild = true;
     1706                    }
     1707                    if (!m_collectRulesOnly) {
     1708                        RenderStyle* childStyle = (m_element == e) ? m_style : e->renderStyle();
     1709                        RenderStyle* parentStyle = (m_element == e) ? m_parentStyle : e->parentNode()->renderStyle();
     1710                        if (parentStyle) {
     1711                            parentStyle->setChildrenAffectedByFirstChildRules();
     1712                            parentStyle->setChildrenAffectedByLastChildRules();
     1713                        }
     1714                        if (firstChild && childStyle)
     1715                            childStyle->setFirstChildState();
     1716                        if (lastChild && childStyle)
     1717                            childStyle->setLastChildState();
     1718                    }
     1719                    return firstChild && lastChild;
     1720                }
     1721                break;
     1722            }
     1723            case CSSSelector::PseudoOnlyOfType: {
     1724                if (e->parentNode() && e->parentNode()->isElementNode()) {
     1725                    bool firstChild = false;
     1726                    bool lastChild = false;
     1727                    const QualifiedName& type = e->tagQName();
     1728                    Node* n = e->previousSibling();
     1729                    while (n) {
     1730                        if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
     1731                            break;
     1732                        n = n->previousSibling();
     1733                    }
     1734                    if (!n)
     1735                        firstChild = true;
     1736                    if (firstChild) {
     1737                        n = e->nextSibling();
     1738                        while (n) {
     1739                            if (n->isElementNode() && static_cast<Element*>(n)->hasTagName(type))
     1740                                break;
     1741                            n = n->nextSibling();
     1742                        }
     1743                        if (!n)
     1744                            lastChild = true;
     1745                    }
     1746                    if (!m_collectRulesOnly) {
     1747                        RenderStyle* parentStyle = (m_element == e) ? m_parentStyle : e->parentNode()->renderStyle();
     1748                        if (parentStyle)
     1749                            parentStyle->setChildrenAffectedByPositionalRules();
     1750                    }
     1751                    return firstChild && lastChild;
    16871752                }
    16881753                break;
Note: See TracChangeset for help on using the changeset viewer.