Changeset 190680 in webkit


Ignore:
Timestamp:
Oct 7, 2015 12:59:32 PM (9 years ago)
Author:
Antti Koivisto
Message:

Implement :host pseudo class
https://bugs.webkit.org/show_bug.cgi?id=149440
Source/WebCore:

rdar://problem/22731953

Reviewed by Ryosuke Niwa.

This implements the basic non-function :host syntax.

  • css/CSSSelector.cpp:

(WebCore::CSSSelector::selectorText):

  • css/CSSSelector.h:
  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::matchAuthorRules):
(WebCore::ElementRuleCollector::matchHostPseudoClassRules):
(WebCore::ElementRuleCollector::matchUserRules):

  • css/ElementRuleCollector.h:
  • css/RuleSet.cpp:

(WebCore::computeMatchBasedOnRuleHash):
(WebCore::RuleSet::addRule):

  • css/RuleSet.h:

(WebCore::RuleSet::cuePseudoRules):
(WebCore::RuleSet::hostPseudoClassRules):
(WebCore::RuleSet::focusPseudoClassRules):
(WebCore::RuleSet::universalRules):

  • css/SelectorChecker.cpp:

(WebCore::SelectorChecker::checkOne):

  • css/SelectorPseudoClassAndCompatibilityElementMap.in:
  • cssjit/SelectorCompiler.cpp:

(WebCore::SelectorCompiler::addPseudoClassType):

LayoutTests:

Reviewed by Ryosuke Niwa.

  • fast/shadow-dom/css-scoping-shadow-host-rule.html:

Fix and expand the test case.

  • platform/mac/TestExpectations:
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r190677 r190680  
     12015-10-07  Antti Koivisto  <antti@apple.com>
     2
     3        Implement :host pseudo class
     4        https://bugs.webkit.org/show_bug.cgi?id=149440
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * fast/shadow-dom/css-scoping-shadow-host-rule.html:
     9
     10            Fix and expand the test case.
     11
     12        * platform/mac/TestExpectations:
     13
    1142015-10-07  Brian Burg  <bburg@apple.com>
    215
  • trunk/LayoutTests/fast/shadow-dom/css-scoping-shadow-host-rule.html

    r190098 r190680  
    99<body>
    1010    <style>
    11         my-host, good-host, other-host, other-good-host {
     11        my-host, my-host2, my-host3, my-host4 {
    1212            display: block;
    1313            width: 100px;
    14             height: 50px;
     14            height: 25px;
     15        }
     16        my-host2 {
     17            background: green;
     18        }
     19        my-host3 {
    1520            background: red;
     21            color: green;
    1622        }
    17         good-host, other-good-host {
     23        my-host4 {
    1824            background: green;
     25            color: green;
    1926        }
    2027    </style>
     
    2330        <div>FAIL</div>
    2431    </my-host>
     32    <my-host2>
     33        <div>FAIL</div>
     34    </my-host2>
     35    <my-host3>
     36        <div>FAIL</div>
     37    </my-host3>
    2538    <div class="container">
    26         <good-host>
     39        <my-host4>
    2740            <div>FAIL</div>
    28         </good-host>
     41        </my-host4>
    2942    </div>
    30     <other-host id="bar" class="foo" name="baz">
    31         <div>FAIL</div>
    32     </other-host>
    33     <other-good-host>
    34         <div class="child">FAIL</div>
    35     </other-good-host>
    3643    <script>
    3744
    3845        try {
    3946            var shadowHost = document.querySelector('my-host');
     47            var shadowRoot = shadowHost.attachShadow({mode: 'open'});
     48            shadowRoot.innerHTML = '<style> :host { color: green; background: green; } </style><div>FAIL</div>';
     49
     50            shadowHost = document.querySelector('my-host2');
    4051            shadowRoot = shadowHost.attachShadow({mode: 'open'});
    41             shadowRoot.innerHTML = '<style> :host { background: green; } </style>';
     52            shadowRoot.innerHTML = '<style> :host { color: red; background: red; } div { color: green }</style><div>FAIL</div>';
    4253
    43             shadowHost = document.querySelector('good-host');
     54            shadowHost = document.querySelector('my-host3');
    4455            shadowRoot = shadowHost.attachShadow({mode: 'open'});
    45             shadowRoot.innerHTML = '<style> .container :host { background: red; } </style>';
     56            shadowRoot.innerHTML = '<style> :host { background: green !important; color: green !important; } </style><div>FAIL</div>';
     57
     58            shadowHost = document.querySelector('my-host4');
     59            shadowRoot = shadowHost.attachShadow({mode: 'open'});
     60            shadowRoot.innerHTML = '<style> .container :host { background: red !important; } </style><div>FAIL</div>';
    4661        } catch (exception) {
    4762            document.body.appendChild(document.createTextNode(exception));
  • trunk/LayoutTests/platform/mac/TestExpectations

    r190667 r190680  
    13261326
    13271327webkit.org/b/148695 fast/shadow-dom [ Pass ]
    1328 webkit.org/b/149440 fast/shadow-dom/css-scoping-shadow-host-rule.html [ ImageOnlyFailure ]
    13291328webkit.org/b/149440 fast/shadow-dom/css-scoping-shadow-host-functional-rule.html [ ImageOnlyFailure ]
    13301329webkit.org/b/149441 fast/shadow-dom/css-scoping-shadow-slotted-rule.html [ ImageOnlyFailure ]
  • trunk/Source/WebCore/ChangeLog

    r190674 r190680  
     12015-10-07  Antti Koivisto  <antti@apple.com>
     2
     3        Implement :host pseudo class
     4        https://bugs.webkit.org/show_bug.cgi?id=149440
     5        rdar://problem/22731953
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        This implements the basic non-function :host syntax.
     10
     11        * css/CSSSelector.cpp:
     12        (WebCore::CSSSelector::selectorText):
     13        * css/CSSSelector.h:
     14        * css/ElementRuleCollector.cpp:
     15        (WebCore::ElementRuleCollector::matchAuthorRules):
     16        (WebCore::ElementRuleCollector::matchHostPseudoClassRules):
     17        (WebCore::ElementRuleCollector::matchUserRules):
     18        * css/ElementRuleCollector.h:
     19        * css/RuleSet.cpp:
     20        (WebCore::computeMatchBasedOnRuleHash):
     21        (WebCore::RuleSet::addRule):
     22        * css/RuleSet.h:
     23        (WebCore::RuleSet::cuePseudoRules):
     24        (WebCore::RuleSet::hostPseudoClassRules):
     25        (WebCore::RuleSet::focusPseudoClassRules):
     26        (WebCore::RuleSet::universalRules):
     27        * css/SelectorChecker.cpp:
     28        (WebCore::SelectorChecker::checkOne):
     29        * css/SelectorPseudoClassAndCompatibilityElementMap.in:
     30        * cssjit/SelectorCompiler.cpp:
     31        (WebCore::SelectorCompiler::addPseudoClassType):
     32
    1332015-10-07  Nan Wang  <n_wang@apple.com>
    234
  • trunk/Source/WebCore/css/CSSSelector.cpp

    r187149 r190680  
    633633                str.appendLiteral(":window-inactive");
    634634                break;
     635#if ENABLE(SHADOW_DOM)
     636            case CSSSelector::PseudoClassHost:
     637                str.appendLiteral(":host");
     638                break;
     639#endif
    635640            case CSSSelector::PseudoClassUnknown:
    636641                ASSERT_NOT_REACHED();
  • trunk/Source/WebCore/css/CSSSelector.h

    r187353 r190680  
    160160            PseudoClassRole,
    161161#endif
     162#if ENABLE(SHADOW_DOM)
     163            PseudoClassHost,
     164#endif
    162165        };
    163166
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r190347 r190680  
    189189void ElementRuleCollector::matchAuthorRules(bool includeEmptyRules)
    190190{
     191#if ENABLE(SHADOW_DOM)
     192    if (m_element.shadowRoot())
     193        matchHostPseudoClassRules(includeEmptyRules);
     194#endif
     195
    191196    clearMatchedRules();
    192197    m_result.ranges.lastAuthorRule = m_result.matchedProperties().size() - 1;
     
    200205    sortAndTransferMatchedRules();
    201206}
     207
     208#if ENABLE(SHADOW_DOM)
     209void ElementRuleCollector::matchHostPseudoClassRules(bool includeEmptyRules)
     210{
     211    ASSERT(m_element.shadowRoot());
     212    auto& shadowAuthorStyle = *m_element.shadowRoot()->styleResolver().ruleSets().authorStyle();
     213    auto& shadowHostRules = shadowAuthorStyle.hostPseudoClassRules();
     214    if (shadowHostRules.isEmpty())
     215        return;
     216
     217    clearMatchedRules();
     218    m_result.ranges.lastAuthorRule = m_result.matchedProperties().size() - 1;
     219
     220    auto ruleRange = m_result.ranges.authorRuleRange();
     221    MatchRequest matchRequest(&shadowAuthorStyle, includeEmptyRules);
     222    collectMatchingRulesForList(&shadowHostRules, matchRequest, ruleRange);
     223
     224    // We just sort the host rules before other author rules. This matches the current vague spec language
     225    // but is not necessarily exactly what is needed.
     226    // FIXME: Match the spec when it is finalized.
     227    sortAndTransferMatchedRules();
     228}
     229#endif
    202230
    203231void ElementRuleCollector::matchUserRules(bool includeEmptyRules)
  • trunk/Source/WebCore/css/ElementRuleCollector.h

    r190347 r190680  
    7878
    7979    void matchUARules(RuleSet*);
     80#if ENABLE(SHADOW_DOM)
     81    void matchHostPseudoClassRules(bool includeEmptyRules);
     82#endif
    8083
    8184    void collectMatchingRules(const MatchRequest&, StyleResolver::RuleRange&);
  • trunk/Source/WebCore/css/RuleSet.cpp

    r190347 r190680  
    7171    if (SelectorChecker::isCommonPseudoClassSelector(&selector))
    7272        return MatchBasedOnRuleHash::ClassB;
     73#if ENABLE(SHADOW_DOM)
     74    if (selector.match() == CSSSelector::PseudoClass && selector.pseudoClassType() == CSSSelector::PseudoClassHost)
     75        return MatchBasedOnRuleHash::ClassB;
     76#endif
    7377    if (selector.match() == CSSSelector::Id)
    7478        return MatchBasedOnRuleHash::ClassA;
     
    259263        }
    260264
     265#if ENABLE(SHADOW_DOM)
     266        if (selector->match() == CSSSelector::PseudoClass && selector->pseudoClassType() == CSSSelector::PseudoClassHost) {
     267            m_hostPseudoClassRules.append(ruleData);
     268            return;
     269        }
     270#endif
    261271        if (selector->relation() != CSSSelector::SubSelector)
    262272            break;
  • trunk/Source/WebCore/css/RuleSet.h

    r190347 r190680  
    180180    const RuleDataVector* cuePseudoRules() const { return &m_cuePseudoRules; }
    181181#endif
     182#if ENABLE(SHADOW_DOM)
     183    const RuleDataVector& hostPseudoClassRules() const { return m_hostPseudoClassRules; }
     184#endif
    182185    const RuleDataVector* focusPseudoClassRules() const { return &m_focusPseudoClassRules; }
    183186    const RuleDataVector* universalRules() const { return &m_universalRules; }
     
    202205#if ENABLE(VIDEO_TRACK)
    203206    RuleDataVector m_cuePseudoRules;
     207#endif
     208#if ENABLE(SHADOW_DOM)
     209    RuleDataVector m_hostPseudoClassRules;
    204210#endif
    205211    RuleDataVector m_focusPseudoClassRules;
  • trunk/Source/WebCore/css/SelectorChecker.cpp

    r189841 r190680  
    10141014                break;
    10151015            }
    1016 
     1016#if ENABLE(SHADOW_DOM)
     1017        case CSSSelector::PseudoClassHost:
     1018            // :host matches based on context. Cases that reach selector checker don't match.
     1019            return false;
     1020#endif
    10171021        case CSSSelector::PseudoClassWindowInactive:
    10181022            return isWindowInactive(element);
  • trunk/Source/WebCore/css/SelectorPseudoClassAndCompatibilityElementMap.in

    r182129 r190680  
    7575past
    7676#endif
     77
     78#if ENABLE(SHADOW_DOM)
     79host
     80#endif
  • trunk/Source/WebCore/cssjit/SelectorCompiler.cpp

    r186268 r190680  
    820820            return functionType;
    821821        }
    822 
     822#if ENABLE(SHADOW_DOM)
     823    case CSSSelector::PseudoClassHost:
     824        // :host matches based on context. Cases that reach selector checker don't match.
     825        return FunctionType::CannotMatchAnything;
     826#endif
    823827    case CSSSelector::PseudoClassUnknown:
    824828        ASSERT_NOT_REACHED();
Note: See TracChangeset for help on using the changeset viewer.