Changeset 115971 in webkit


Ignore:
Timestamp:
May 3, 2012 7:45:12 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Broken handling of pseudo-elements in selectors API
https://bugs.webkit.org/show_bug.cgi?id=83446

Patch by Arpita Bahuguna <arpitabahuguna@gmail.com> on 2012-05-03
Reviewed by Antti Koivisto.

Source/WebCore:

Test: fast/dom/Window/querySelectorAll-with-pseudo-elements.html

  • css/SelectorChecker.cpp:

(WebCore::SelectorChecker::SelectorChecker):
Setting the default value for the enum member m_mode to ResolvingStyle.

(WebCore::SelectorChecker::checkSelector):
Instead of verifying against the bool m_isCollectingRulesOnly, we now check whether or not
m_mode is set to ResolvingStyle.

(WebCore::SelectorChecker::checkOneSelector):
Instead of verifying against the bool m_isCollectingRulesOnly, we now check whether or not
m_mode is set to ResolvingStyle. Also, for the pseudo-elements case we check if its
value is set to QueryingRules in which case we return false.

  • css/SelectorChecker.h:

(WebCore::SelectorChecker::mode):
Returns the mode (m_mode) value.

(WebCore::SelectorChecker::setMode):
Sets the mode (m_mode) to the passed enum value.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::sortAndTransferMatchedRules):
(WebCore::StyleResolver::collectMatchingRulesForList):
Retrieves SelectorChecker's mode value.

  • dom/SelectorQuery.cpp:

(WebCore::SelectorQuery::SelectorQuery):
Sets SelectorChecker's mode to QueryingRules.

  • html/shadow/ContentSelectorQuery.cpp:

(WebCore::ContentSelectorQuery::ContentSelectorQuery):
Sets SelectorChecker's mode to CollectingRules.

LayoutTests:

  • fast/dom/Window/querySelectorAll-with-pseudo-elements-expected.txt: Added.
  • fast/dom/Window/querySelectorAll-with-pseudo-elements.html: Added.

New layout testcase added for verifying that the querySelectorAll() API returns zero
when querying for pseudo-elements selectors; as per the specification.

Location:
trunk
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r115968 r115971  
     12012-05-03  Arpita Bahuguna  <arpitabahuguna@gmail.com>
     2
     3        Broken handling of pseudo-elements in selectors API
     4        https://bugs.webkit.org/show_bug.cgi?id=83446
     5
     6        Reviewed by Antti Koivisto.
     7
     8        * fast/dom/Window/querySelectorAll-with-pseudo-elements-expected.txt: Added.
     9        * fast/dom/Window/querySelectorAll-with-pseudo-elements.html: Added.
     10        New layout testcase added for verifying that the querySelectorAll() API returns zero
     11        when querying for pseudo-elements selectors; as per the specification.
     12
    1132012-05-03  Sudarsana Nagineni  <sudarsana.nagineni@linux.intel.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r115969 r115971  
     12012-05-03  Arpita Bahuguna  <arpitabahuguna@gmail.com>
     2
     3        Broken handling of pseudo-elements in selectors API
     4        https://bugs.webkit.org/show_bug.cgi?id=83446
     5
     6        Reviewed by Antti Koivisto.
     7
     8        Test: fast/dom/Window/querySelectorAll-with-pseudo-elements.html
     9
     10        * css/SelectorChecker.cpp:
     11        (WebCore::SelectorChecker::SelectorChecker):
     12        Setting the default value for the enum member m_mode to ResolvingStyle.
     13
     14        (WebCore::SelectorChecker::checkSelector):
     15        Instead of verifying against the bool m_isCollectingRulesOnly, we now check whether or not
     16        m_mode is set to ResolvingStyle.
     17
     18        (WebCore::SelectorChecker::checkOneSelector):
     19        Instead of verifying against the bool m_isCollectingRulesOnly, we now check whether or not
     20        m_mode is set to ResolvingStyle. Also, for the pseudo-elements case we check if its
     21        value is set to QueryingRules in which case we return false.
     22
     23        * css/SelectorChecker.h:
     24        (WebCore::SelectorChecker::mode):
     25        Returns the mode (m_mode) value.
     26
     27        (WebCore::SelectorChecker::setMode):
     28        Sets the mode (m_mode) to the passed enum value.
     29
     30        * css/StyleResolver.cpp:
     31        (WebCore::StyleResolver::sortAndTransferMatchedRules):
     32        (WebCore::StyleResolver::collectMatchingRulesForList):
     33        Retrieves SelectorChecker's mode value.
     34
     35        * dom/SelectorQuery.cpp:
     36        (WebCore::SelectorQuery::SelectorQuery):
     37        Sets SelectorChecker's mode to QueryingRules.
     38
     39        * html/shadow/ContentSelectorQuery.cpp:
     40        (WebCore::ContentSelectorQuery::ContentSelectorQuery):
     41        Sets SelectorChecker's mode to CollectingRules.
     42
    1432012-05-03  Pavel Feldman  <pfeldman@chromium.org>
    244
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r111659 r115971  
    7070    , m_strictParsing(strictParsing)
    7171    , m_documentIsHTML(document->isHTMLDocument())
    72     , m_isCollectingRulesOnly(false)
     72    , m_mode(ResolvingStyle)
    7373    , m_pseudoStyle(NOPSEUDO)
    7474    , m_hasUnknownPseudoElements(false)
     
    493493
    494494    case CSSSelector::DirectAdjacent:
    495         if (!m_isCollectingRulesOnly && context.element->parentElement()) {
     495        if (m_mode == ResolvingStyle && context.element->parentElement()) {
    496496            RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : context.element->parentNode()->renderStyle();
    497497            if (parentStyle)
     
    507507
    508508    case CSSSelector::IndirectAdjacent:
    509         if (!m_isCollectingRulesOnly && context.element->parentElement()) {
     509        if (m_mode == ResolvingStyle && context.element->parentElement()) {
    510510            RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : context.element->parentNode()->renderStyle();
    511511            if (parentStyle)
     
    527527        // We make an exception for scrollbar pseudo elements and allow a set of pseudo classes (but nothing else)
    528528        // to follow the pseudo elements.
    529         if ((context.elementStyle || m_isCollectingRulesOnly) && dynamicPseudo != NOPSEUDO && dynamicPseudo != SELECTION
     529        if ((context.elementStyle || m_mode == CollectingRules || m_mode == QueryingRules) && dynamicPseudo != NOPSEUDO && dynamicPseudo != SELECTION
    530530             && !((RenderScrollbar::scrollbarForStyleResolve() || dynamicPseudo == SCROLLBAR_CORNER || dynamicPseudo == RESIZER) && nextContext.selector->m_match == CSSSelector::PseudoClass))
    531531            return SelectorFailsCompletely;
     
    774774                    }
    775775                }
    776                 if (!m_isCollectingRulesOnly) {
     776                if (m_mode == ResolvingStyle) {
    777777                    if (context.elementStyle)
    778778                        context.elementStyle->setEmptyState(result);
     
    788788                if (!element->previousElementSibling())
    789789                    result = true;
    790                 if (!m_isCollectingRulesOnly) {
     790                if (m_mode == ResolvingStyle) {
    791791                    RenderStyle* childStyle = context.elementStyle ? context.elementStyle : element->renderStyle();
    792792                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : element->parentNode()->renderStyle();
     
    810810                    }
    811811                }
    812                 if (!m_isCollectingRulesOnly) {
     812                if (m_mode == ResolvingStyle) {
    813813                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : element->parentNode()->renderStyle();
    814814                    if (parentStyle)
     
    822822            if (Element* parentElement = element->parentElement()) {
    823823                bool result = parentElement->isFinishedParsingChildren() && !element->nextElementSibling();
    824                 if (!m_isCollectingRulesOnly) {
     824                if (m_mode == ResolvingStyle) {
    825825                    RenderStyle* childStyle = context.elementStyle ? context.elementStyle : element->renderStyle();
    826826                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
     
    836836            // last-of-type matches the last element of its type
    837837            if (Element* parentElement = element->parentElement()) {
    838                 if (!m_isCollectingRulesOnly) {
     838                if (m_mode == ResolvingStyle) {
    839839                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
    840840                    if (parentStyle)
     
    856856                bool onlyChild = firstChild && parentElement->isFinishedParsingChildren() && !element->nextElementSibling();
    857857
    858                 if (!m_isCollectingRulesOnly) {
     858                if (m_mode == ResolvingStyle) {
    859859                    RenderStyle* childStyle = context.elementStyle ? context.elementStyle : element->renderStyle();
    860860                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
     
    874874            // FIXME: This selector is very slow.
    875875            if (Element* parentElement = element->parentElement()) {
    876                 if (!m_isCollectingRulesOnly) {
     876                if (m_mode == ResolvingStyle) {
    877877                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
    878878                    if (parentStyle) {
     
    910910                }
    911911
    912                 if (!m_isCollectingRulesOnly) {
     912                if (m_mode == ResolvingStyle) {
    913913                    RenderStyle* childStyle = context.elementStyle ? context.elementStyle : element->renderStyle();
    914914                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
     
    933933                        ++count;
    934934                }
    935                 if (!m_isCollectingRulesOnly) {
     935                if (m_mode == ResolvingStyle) {
    936936                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
    937937                    if (parentStyle)
     
    947947                break;
    948948            if (Element* parentElement = element->parentElement()) {
    949                 if (!m_isCollectingRulesOnly) {
     949                if (m_mode == ResolvingStyle) {
    950950                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
    951951                    if (parentStyle)
     
    965965                break;
    966966            if (Element* parentElement = element->parentElement()) {
    967                 if (!m_isCollectingRulesOnly) {
     967                if (m_mode == ResolvingStyle) {
    968968                    RenderStyle* parentStyle = context.elementStyle ? context.elementParentStyle : parentElement->renderStyle();
    969969                    if (parentStyle)
     
    11701170    }
    11711171    if (selector->m_match == CSSSelector::PseudoElement) {
    1172         if (!context.elementStyle && !m_isCollectingRulesOnly)
     1172        if ((!context.elementStyle && m_mode == ResolvingStyle) || m_mode == QueryingRules)
    11731173            return false;
    11741174
  • trunk/Source/WebCore/css/SelectorChecker.h

    r114265 r115971  
    5353    enum SelectorMatch { SelectorMatches, SelectorFailsLocally, SelectorFailsAllSiblings, SelectorFailsCompletely };
    5454    enum VisitedMatchType { VisitedMatchDisabled, VisitedMatchEnabled };
     55    enum Mode { ResolvingStyle = 0, CollectingRules, QueryingRules };
    5556
    5657    struct SelectorCheckingContext {
     
    9798    bool strictParsing() const { return m_strictParsing; }
    9899
    99     bool isCollectingRulesOnly() const { return m_isCollectingRulesOnly; }
    100     void setCollectingRulesOnly(bool b) { m_isCollectingRulesOnly = b; }
     100    Mode mode() const { return m_mode; }
     101    void setMode(Mode mode) { m_mode = mode; }
    101102
    102103    PseudoId pseudoStyle() const { return m_pseudoStyle; }
     
    136137    bool m_strictParsing;
    137138    bool m_documentIsHTML;
    138     bool m_isCollectingRulesOnly;
     139    Mode m_mode;
    139140    PseudoId m_pseudoStyle;
    140141    mutable bool m_hasUnknownPseudoElements;
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r115860 r115971  
    872872    sortMatchedRules();
    873873
    874     if (m_checker.isCollectingRulesOnly()) {
     874    if (m_checker.mode() == SelectorChecker::CollectingRules) {
    875875        if (!m_ruleList)
    876876            m_ruleList = StaticCSSRuleList::create();
     
    10461046            // we really just matched a pseudo-element.
    10471047            if (m_dynamicPseudo != NOPSEUDO && m_checker.pseudoStyle() == NOPSEUDO) {
    1048                 if (m_checker.isCollectingRulesOnly()) {
     1048                if (m_checker.mode() == SelectorChecker::CollectingRules) {
    10491049                    InspectorInstrumentation::didMatchRule(cookie, false);
    10501050                    continue;
     
    21762176        return 0;
    21772177
    2178     m_checker.setCollectingRulesOnly(true);
     2178    m_checker.setMode(SelectorChecker::CollectingRules);
    21792179
    21802180    initElement(e);
     
    22002200    }
    22012201
    2202     m_checker.setCollectingRulesOnly(false);
     2202    m_checker.setMode(SelectorChecker::ResolvingStyle);
    22032203
    22042204    return m_ruleList.release();
  • trunk/Source/WebCore/dom/SelectorQuery.cpp

    r106902 r115971  
    152152    , m_selectors(selectorList)
    153153{
    154     m_selectorChecker.setCollectingRulesOnly(true);
     154    m_selectorChecker.setMode(SelectorChecker::QueryingRules);
    155155}
    156156
  • trunk/Source/WebCore/html/shadow/ContentSelectorQuery.cpp

    r114217 r115971  
    3838    , m_selectorChecker(insertionPoint->document(), !insertionPoint->document()->inQuirksMode())
    3939{
    40     m_selectorChecker.setCollectingRulesOnly(true);
     40    m_selectorChecker.setMode(SelectorChecker::CollectingRules);
    4141
    4242    if (insertionPoint->select().isNull() || insertionPoint->select().isEmpty()) {
Note: See TracChangeset for help on using the changeset viewer.