Changeset 133577 in webkit


Ignore:
Timestamp:
Nov 6, 2012 2:43:46 AM (11 years ago)
Author:
shinyak@chromium.org
Message:

[Shadow] Using isUnknownPseudoElement() for shadow pseudo id seems confusing
https://bugs.webkit.org/show_bug.cgi?id=100826

Reviewed by Hajime Morita.

Source/WebCore:

We used isUnknownPseudoElement() for these 3 meanings: 1) the element is a custom pseudo-element (starting with 'x-'),
2) the element is a webkit custom pseudo-element (starting with '-webkit-'), and 3) the element has an unknown type.
We would like to distinguish them when parsing CSSSelector types. Also, we disable using (3) type for using
shadowPseudoId.

In this patch, we allow using WebKitCustomPseudoElement in AuthorShadowRoot, and CustomPseudoElement in
UAShadowRoot. However, we will disable them later.

Test: fast/dom/shadow/shadow-pseudo-id.html

  • css/CSSGrammar.y.in: Now we can discard UNKNOWN type. It should not match anything.
  • css/CSSParser.cpp:

(WebCore::CSSParser::updateSpecifiersWithElementName):
(WebCore::CSSParser::updateSpecifiers):

  • css/CSSParserValues.h:

(WebCore::CSSParserSelector::isCustomPseudoElement):
(CSSParserSelector):

  • css/CSSSelector.cpp:

(WebCore::CSSSelector::pseudoId):
(WebCore::CSSSelector::parsePseudoType):
(WebCore::CSSSelector::isCustomPseudoType): Returns true if the type is PseudoUserAgentCustomElement or PseudoWebKitCustomElement.
(WebCore::CSSSelector::extractPseudoType):

  • css/CSSSelector.h:

(CSSSelector):
(WebCore::CSSSelector::isCustomPseudoElement):
(WebCore):

  • css/CSSSelectorList.cpp:

(WebCore::SelectorHasInvalidSelectorFunctor::operator()): We will reject all selectors which were judged as
UNKNOWN before. i.e. It contians all three types for now.
(WebCore::CSSSelectorList::hasInvalidSelector): Renamed.

  • css/CSSSelectorList.h:

(CSSSelectorList):

  • css/RuleSet.cpp:

(WebCore::RuleSet::addRule):

  • css/SelectorChecker.cpp:

(WebCore::SelectorChecker::checkSelector):

  • dom/Element.cpp:

(WebCore::Element::setShadowPseudoId):

  • dom/SelectorQuery.cpp:

(WebCore::SelectorQueryCache::add):

LayoutTests:

  • fast/dom/shadow/shadow-nested-pseudo-id.html: Fixed a testcase so that shadowPseudoId starts with 'x-'.
  • fast/dom/shadow/shadow-pseudo-id-expected.html: Added.
  • fast/dom/shadow/shadow-pseudo-id.html: Added.
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r133575 r133577  
     12012-11-06  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        [Shadow] Using isUnknownPseudoElement() for shadow pseudo id seems confusing
     4        https://bugs.webkit.org/show_bug.cgi?id=100826
     5
     6        Reviewed by Hajime Morita.
     7
     8        * fast/dom/shadow/shadow-nested-pseudo-id.html: Fixed a testcase so that shadowPseudoId starts with 'x-'.
     9        * fast/dom/shadow/shadow-pseudo-id-expected.html: Added.
     10        * fast/dom/shadow/shadow-pseudo-id.html: Added.
     11
    1122012-11-06  Shinya Kawanaka  <shinyak@chromium.org>
    213
  • trunk/LayoutTests/fast/dom/shadow/shadow-nested-pseudo-id.html

    r120147 r133577  
    55<style>
    66
    7 p::-shadow-child {
     7p::x-shadow-child {
    88  color: red;
    99}
    1010
    11 a::-nested-shadow-child {
     11a::x-nested-shadow-child {
    1212  color: blue;
    1313}
    1414
    15 p::-shadow-child::-nested-shadow-child {
     15p::x-shadow-child::x-nested-shadow-child {
    1616  background-color: green;
    1717}
     
    4040   
    4141var host = document.getElementById("host");
    42 var tuple = buildShadowWithOneChild(host, "a", "-shadow-child");
     42var tuple = buildShadowWithOneChild(host, "a", "x-shadow-child");
    4343shouldBe("window.getComputedStyle(tuple.shadowChild).color", "'rgb(255, 0, 0)'");
    44 var shadowTuple = buildShadowWithOneChild(tuple.shadowChild, "b", "-nested-shadow-child");
     44var shadowTuple = buildShadowWithOneChild(tuple.shadowChild, "b", "x-nested-shadow-child");
    4545shouldBe("window.getComputedStyle(shadowTuple.shadowChild).color", "'rgb(0, 0, 255)'");
    4646shouldBe("window.getComputedStyle(shadowTuple.shadowChild).backgroundColor", "'rgb(0, 128, 0)'");
  • trunk/Source/WebCore/ChangeLog

    r133575 r133577  
     12012-11-06  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        [Shadow] Using isUnknownPseudoElement() for shadow pseudo id seems confusing
     4        https://bugs.webkit.org/show_bug.cgi?id=100826
     5
     6        Reviewed by Hajime Morita.
     7
     8        We used isUnknownPseudoElement() for these 3 meanings: 1) the element is a custom pseudo-element (starting with 'x-'),
     9        2) the element is a webkit custom pseudo-element (starting with '-webkit-'), and 3) the element has an unknown type.
     10        We would like to distinguish them when parsing CSSSelector types. Also, we disable using (3) type for using
     11        shadowPseudoId.
     12
     13        In this patch, we allow using WebKitCustomPseudoElement in AuthorShadowRoot, and CustomPseudoElement in
     14        UAShadowRoot. However, we will disable them later.
     15
     16        Test: fast/dom/shadow/shadow-pseudo-id.html
     17
     18        * css/CSSGrammar.y.in: Now we can discard UNKNOWN type. It should not match anything.
     19        * css/CSSParser.cpp:
     20        (WebCore::CSSParser::updateSpecifiersWithElementName):
     21        (WebCore::CSSParser::updateSpecifiers):
     22        * css/CSSParserValues.h:
     23        (WebCore::CSSParserSelector::isCustomPseudoElement):
     24        (CSSParserSelector):
     25        * css/CSSSelector.cpp:
     26        (WebCore::CSSSelector::pseudoId):
     27        (WebCore::CSSSelector::parsePseudoType):
     28        (WebCore::CSSSelector::isCustomPseudoType): Returns true if the type is PseudoUserAgentCustomElement or PseudoWebKitCustomElement.
     29        (WebCore::CSSSelector::extractPseudoType):
     30        * css/CSSSelector.h:
     31        (CSSSelector):
     32        (WebCore::CSSSelector::isCustomPseudoElement):
     33        (WebCore):
     34        * css/CSSSelectorList.cpp:
     35        (WebCore::SelectorHasInvalidSelectorFunctor::operator()): We will reject all selectors which were judged as
     36        UNKNOWN before. i.e. It contians all three types for now.
     37        (WebCore::CSSSelectorList::hasInvalidSelector): Renamed.
     38        * css/CSSSelectorList.h:
     39        (CSSSelectorList):
     40        * css/RuleSet.cpp:
     41        (WebCore::RuleSet::addRule):
     42        * css/SelectorChecker.cpp:
     43        (WebCore::SelectorChecker::checkSelector):
     44        * dom/Element.cpp:
     45        (WebCore::Element::setShadowPseudoId):
     46        * dom/SelectorQuery.cpp:
     47        (WebCore::SelectorQueryCache::add):
     48
    1492012-11-06  Shinya Kawanaka  <shinyak@chromium.org>
    250
  • trunk/Source/WebCore/css/CSSGrammar.y.in

    r133084 r133577  
    13081308        $$->setValue($3);
    13091309        // FIXME: This call is needed to force selector to compute the pseudoType early enough.
    1310         $$->pseudoType();
     1310        CSSSelector::PseudoType type = $$->pseudoType();
     1311        if (type == CSSSelector::PseudoUnknown)
     1312            $$ = 0;
    13111313    }
    13121314    // use by :-webkit-any.
  • trunk/Source/WebCore/css/CSSParser.cpp

    r133545 r133577  
    1025810258    AtomicString determinedNamespace = namespacePrefix != nullAtom && m_styleSheet ? m_styleSheet->determineNamespace(namespacePrefix) : m_defaultNamespace;
    1025910259    QualifiedName tag = QualifiedName(namespacePrefix, elementName, determinedNamespace);
    10260     if (!specifiers->isUnknownPseudoElement()) {
     10260    if (!specifiers->isCustomPseudoElement()) {
    1026110261        specifiers->setTag(tag);
    1026210262        return;
     
    1026710267    while (history->tagHistory()) {
    1026810268        history = history->tagHistory();
    10269         if (history->isUnknownPseudoElement() || history->hasShadowDescendant())
     10269        if (history->isCustomPseudoElement() || history->hasShadowDescendant())
    1027010270            lastShadowDescendant = history;
    1027110271    }
     
    1028610286CSSParserSelector* CSSParser::updateSpecifiers(CSSParserSelector* specifiers, CSSParserSelector* newSpecifier)
    1028710287{
    10288     if (newSpecifier->isUnknownPseudoElement()) {
     10288    if (newSpecifier->isCustomPseudoElement()) {
    1028910289        // Unknown pseudo element always goes at the top of selector chain.
    1029010290        newSpecifier->appendTagHistory(CSSSelector::ShadowDescendant, sinkFloatingSelector(specifiers));
    1029110291        return newSpecifier;
    1029210292    }
    10293     if (specifiers->isUnknownPseudoElement()) {
     10293    if (specifiers->isCustomPseudoElement()) {
    1029410294        // Specifiers for unknown pseudo element go right behind it in the chain.
    1029510295        specifiers->insertTagHistory(CSSSelector::SubSelector, sinkFloatingSelector(newSpecifier), CSSSelector::ShadowDescendant);
  • trunk/Source/WebCore/css/CSSParserValues.h

    r131313 r133577  
    192192
    193193    CSSSelector::PseudoType pseudoType() const { return m_selector->pseudoType(); }
    194     bool isUnknownPseudoElement() const { return m_selector->isUnknownPseudoElement(); }
     194    bool isCustomPseudoElement() const { return m_selector->isCustomPseudoElement(); }
     195
    195196    bool isSimple() const { return !m_tagHistory && m_selector->isSimple(); }
    196197    bool hasShadowDescendant() const;
  • trunk/Source/WebCore/css/CSSSelector.cpp

    r133561 r133577  
    219219    case PseudoInRange:
    220220    case PseudoOutOfRange:
     221    case PseudoUserAgentCustomElement:
     222    case PseudoWebKitCustomElement:
    221223        return NOPSEUDO;
    222224    case PseudoNotParsed:
     
    388390    HashMap<AtomicStringImpl*, CSSSelector::PseudoType>* nameToPseudoType = nameToPseudoTypeMap();
    389391    HashMap<AtomicStringImpl*, CSSSelector::PseudoType>::iterator slot = nameToPseudoType->find(name.impl());
    390     return slot == nameToPseudoType->end() ? PseudoUnknown : slot->value;
    391 }
    392 
    393 bool CSSSelector::isUnknownPseudoType(const AtomicString& name)
    394 {
    395     return parsePseudoType(name) == PseudoUnknown;
     392
     393    if (slot != nameToPseudoType->end())
     394        return slot->value;
     395
     396    if (name.startsWith("-webkit-"))
     397        return PseudoWebKitCustomElement;
     398    if (name.startsWith("x-"))
     399        return PseudoUserAgentCustomElement;
     400
     401    return PseudoUnknown;
     402}
     403
     404bool CSSSelector::isCustomPseudoType(const AtomicString& name)
     405{
     406    CSSSelector::PseudoType type = parsePseudoType(name);
     407    return type == PseudoUserAgentCustomElement || type == PseudoWebKitCustomElement;
    396408}
    397409
     
    421433    case PseudoScrollbarTrackPiece:
    422434    case PseudoSelection:
     435    case PseudoUserAgentCustomElement:
     436    case PseudoWebKitCustomElement:
    423437        element = true;
    424438        break;
  • trunk/Source/WebCore/css/CSSSelector.h

    r129408 r133577  
    155155            PseudoInRange,
    156156            PseudoOutOfRange,
     157            PseudoUserAgentCustomElement,
     158            PseudoWebKitCustomElement,
    157159        };
    158160
     
    184186
    185187        static PseudoType parsePseudoType(const AtomicString&);
    186         static bool isUnknownPseudoType(const AtomicString&);
     188        static bool isCustomPseudoType(const AtomicString&);       
    187189        static PseudoId pseudoId(PseudoType);
    188190
     
    212214        bool matchesPseudoElement() const;
    213215        bool isUnknownPseudoElement() const;
     216        bool isCustomPseudoElement() const;
    214217        bool isSiblingSelector() const;
    215218        bool isAttributeSelector() const;
     
    290293{
    291294    return m_match == PseudoElement && m_pseudoType == PseudoUnknown;
     295}
     296
     297inline bool CSSSelector::isCustomPseudoElement() const
     298{
     299    return m_match == PseudoElement && (m_pseudoType == PseudoUserAgentCustomElement || m_pseudoType == PseudoWebKitCustomElement);
    292300}
    293301
  • trunk/Source/WebCore/css/CSSSelectorList.cpp

    r127869 r133577  
    198198}
    199199
    200 class SelectorHasUnknownPseudoElementFunctor {
     200class SelectorHasInvalidSelectorFunctor {
    201201public:
    202202    bool operator()(CSSSelector* selector)
    203203    {
    204         return selector->isUnknownPseudoElement();
     204        return selector->isUnknownPseudoElement() || selector->isCustomPseudoElement();
    205205    }
    206206};
    207207
    208 bool CSSSelectorList::hasUnknownPseudoElements() const
    209 {
    210     SelectorHasUnknownPseudoElementFunctor functor;
     208bool CSSSelectorList::hasInvalidSelector() const
     209{
     210    SelectorHasInvalidSelectorFunctor functor;
    211211    return forEachSelector(functor, this);
    212212}
  • trunk/Source/WebCore/css/CSSSelectorList.h

    r128418 r133577  
    6060
    6161    bool selectorsNeedNamespaceResolution();
    62     bool hasUnknownPseudoElements() const;
     62    bool hasInvalidSelector() const;
    6363
    6464    String selectorsText() const;
  • trunk/Source/WebCore/css/RuleSet.cpp

    r132941 r133577  
    230230        return;
    231231    }
    232     if (selector->isUnknownPseudoElement()) {
     232    if (selector->isCustomPseudoElement()) {
    233233        addToRuleSet(selector->value().impl(), m_shadowPseudoElementRules, ruleData);
    234234        return;
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r132754 r133577  
    447447
    448448    if (context.selector->m_match == CSSSelector::PseudoElement) {
    449         if (context.selector->isUnknownPseudoElement()) {
     449        if (context.selector->isCustomPseudoElement()) {
    450450            if (context.element->shadowPseudoId() != context.selector->value())
    451451                return SelectorFailsLocally;
  • trunk/Source/WebCore/dom/Element.cpp

    r133492 r133577  
    13601360void Element::setShadowPseudoId(const AtomicString& id, ExceptionCode& ec)
    13611361{
    1362     if (!CSSSelector::isUnknownPseudoType(id)) {
     1362    if (!CSSSelector::isCustomPseudoType(id)) {
    13631363        ec = SYNTAX_ERR;
    13641364        return;
  • trunk/Source/WebCore/dom/SelectorQuery.cpp

    r131209 r133577  
    181181    parser.parseSelector(selectors, selectorList);
    182182
    183     if (!selectorList.first() || selectorList.hasUnknownPseudoElements()) {
     183    if (!selectorList.first() || selectorList.hasInvalidSelector()) {
    184184        ec = SYNTAX_ERR;
    185185        return 0;
Note: See TracChangeset for help on using the changeset viewer.