Changeset 104919 in webkit


Ignore:
Timestamp:
Jan 13, 2012 5:04:58 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

ShadowContentElement should be able to use query.
https://bugs.webkit.org/show_bug.cgi?id=75302

Patch by Shinya Kawanaka <shinyak@google.com> on 2012-01-13
Reviewed by Hajime Morita.

Source/WebCore:

This patch introduces a selector to query elements in ShadowContentElement.
This can be used instead of ShadowContentElement::shouldInclude in more sophisticated ways.

Tests: fast/dom/shadow/shadow-contents-select-expected.html

fast/dom/shadow/shadow-contents-select.html

  • CMakeLists.txt:
  • GNUmakefile.list.am:
  • Target.pri:
  • WebCore.gypi:
  • WebCore.vcproj/WebCore.vcproj:
  • WebCore.xcodeproj/project.pbxproj:
  • dom/DOMAllInOne.cpp:
  • dom/SelectorQuery.cpp:

(WebCore::SelectorDataList::SelectorDataList):

Extracted from SelectorQueryto share codes with ShadowContentSelectorQuery.

(WebCore::SelectorDataList::initialize):
(WebCore::SelectorDataList::matches):
(WebCore::SelectorDataList::queryAll):
(WebCore::SelectorDataList::queryFirst):
(WebCore::SelectorDataList::canUseIdLookup):
(WebCore::SelectorDataList::execute):
(WebCore::SelectorQuery::SelectorQuery):
(WebCore::SelectorQuery::queryAll):
(WebCore::SelectorQuery::queryFirst):

  • dom/SelectorQuery.h:

(WebCore::SelectorDataList::size):

  • dom/ShadowContentElement.cpp:

(WebCore::ShadowContentElement::select):
(WebCore::ShadowContentElement::setSelect):

  • dom/ShadowContentElement.h:
  • dom/ShadowContentSelectorQuery.cpp: Added.

(WebCore::ShadowContentSelectorQuery::ShadowContentSelectorQuery):
(WebCore::ShadowContentSelectorQuery::matches):

Returns true if Node is matched by the query.

  • dom/ShadowContentSelectorQuery.h: Copied from Source/WebCore/dom/ShadowContentElement.h.
  • dom/ShadowInclusionSelector.cpp:

(WebCore::ShadowInclusionSelector::select):

  • dom/ShadowInclusionSelector.h:
  • html/HTMLAttributeNames.in:
  • html/HTMLDetailsElement.cpp:

(WebCore::summaryQuerySelector):
(WebCore::DetailsContentElement::DetailsContentElement): Re-implemented using query.
(WebCore::DetailsSummaryElement::DetailsSummaryElement): ditto.

LayoutTests:

Tests for ShadowContentElement query.

  • fast/dom/shadow/shadow-contents-select-expected.html: Added.
  • fast/dom/shadow/shadow-contents-select.html: Added.
Location:
trunk
Files:
3 added
17 edited
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r104917 r104919  
     12012-01-13  Shinya Kawanaka  <shinyak@google.com>
     2
     3        ShadowContentElement should be able to use query.
     4        https://bugs.webkit.org/show_bug.cgi?id=75302
     5
     6        Reviewed by Hajime Morita.
     7
     8        Tests for ShadowContentElement query.
     9
     10        * fast/dom/shadow/shadow-contents-select-expected.html: Added.
     11        * fast/dom/shadow/shadow-contents-select.html: Added.
     12
    1132012-01-13  Renata Hodovan  <reni@webkit.org>
    214
  • trunk/Source/WebCore/CMakeLists.txt

    r104827 r104919  
    595595    dom/SelectorQuery.cpp
    596596    dom/ShadowContentElement.cpp
     597    dom/ShadowContentSelectorQuery.cpp
    597598    dom/ShadowInclusionSelector.cpp
    598599    dom/ShadowRoot.cpp
  • trunk/Source/WebCore/ChangeLog

    r104916 r104919  
     12012-01-13  Shinya Kawanaka  <shinyak@google.com>
     2
     3        ShadowContentElement should be able to use query.
     4        https://bugs.webkit.org/show_bug.cgi?id=75302
     5
     6        Reviewed by Hajime Morita.
     7
     8        This patch introduces a selector to query elements in ShadowContentElement.
     9        This can be used instead of ShadowContentElement::shouldInclude in more sophisticated ways.
     10
     11        Tests: fast/dom/shadow/shadow-contents-select-expected.html
     12               fast/dom/shadow/shadow-contents-select.html
     13
     14        * CMakeLists.txt:
     15        * GNUmakefile.list.am:
     16        * Target.pri:
     17        * WebCore.gypi:
     18        * WebCore.vcproj/WebCore.vcproj:
     19        * WebCore.xcodeproj/project.pbxproj:
     20        * dom/DOMAllInOne.cpp:
     21        * dom/SelectorQuery.cpp:
     22        (WebCore::SelectorDataList::SelectorDataList):
     23          Extracted from SelectorQueryto share codes with ShadowContentSelectorQuery.
     24        (WebCore::SelectorDataList::initialize):
     25        (WebCore::SelectorDataList::matches):
     26        (WebCore::SelectorDataList::queryAll):
     27        (WebCore::SelectorDataList::queryFirst):
     28        (WebCore::SelectorDataList::canUseIdLookup):
     29        (WebCore::SelectorDataList::execute):
     30        (WebCore::SelectorQuery::SelectorQuery):
     31        (WebCore::SelectorQuery::queryAll):
     32        (WebCore::SelectorQuery::queryFirst):
     33        * dom/SelectorQuery.h:
     34        (WebCore::SelectorDataList::size):
     35        * dom/ShadowContentElement.cpp:
     36        (WebCore::ShadowContentElement::select):
     37        (WebCore::ShadowContentElement::setSelect):
     38        * dom/ShadowContentElement.h:
     39        * dom/ShadowContentSelectorQuery.cpp: Added.
     40        (WebCore::ShadowContentSelectorQuery::ShadowContentSelectorQuery):
     41        (WebCore::ShadowContentSelectorQuery::matches):
     42          Returns true if Node is matched by the query.
     43        * dom/ShadowContentSelectorQuery.h: Copied from Source/WebCore/dom/ShadowContentElement.h.
     44        * dom/ShadowInclusionSelector.cpp:
     45        (WebCore::ShadowInclusionSelector::select):
     46        * dom/ShadowInclusionSelector.h:
     47        * html/HTMLAttributeNames.in:
     48        * html/HTMLDetailsElement.cpp:
     49        (WebCore::summaryQuerySelector):
     50        (WebCore::DetailsContentElement::DetailsContentElement): Re-implemented using query.
     51        (WebCore::DetailsSummaryElement::DetailsSummaryElement): ditto.
     52
    1532012-01-13  Ilya Tikhonovsky  <loislo@chromium.org>
    254
  • trunk/Source/WebCore/GNUmakefile.list.am

    r104896 r104919  
    16461646        Source/WebCore/dom/ShadowContentElement.cpp \
    16471647        Source/WebCore/dom/ShadowContentElement.h \
     1648        Source/WebCore/dom/ShadowContentSelectorQuery.cpp \
     1649        Source/WebCore/dom/ShadowContentSelectorQuery.h \
    16481650        Source/WebCore/dom/ShadowInclusionSelector.cpp \
    16491651        Source/WebCore/dom/ShadowInclusionSelector.h \
  • trunk/Source/WebCore/Target.pri

    r104896 r104919  
    561561    dom/SelectorQuery.cpp \
    562562    dom/ShadowContentElement.cpp \
     563    dom/ShadowContentSelectorQuery.cpp \
    563564    dom/ShadowInclusionSelector.cpp \
    564565    dom/ShadowRoot.cpp \
     
    16611662    dom/SelectorQuery.h \
    16621663    dom/ShadowContentElement.h \
     1664    dom/ShadowContentSelectorQuery.h \
    16631665    dom/ShadowInclusionSelector.h \
    16641666    dom/ShadowRoot.h \
  • trunk/Source/WebCore/WebCore.gypi

    r104913 r104919  
    10481048            'dom/ShadowRoot.h',
    10491049            'dom/ShadowContentElement.h',
     1050            'dom/ShadowContentSelectorQuery.h',
    10501051            'dom/SpaceSplitString.h',
    10511052            'dom/StyledElement.h',
     
    54605461            'dom/ShadowContentElement.cpp',
    54615462            'dom/ShadowContentElement.h',
     5463            'dom/ShadowContentSelectorQuery.cpp',
     5464            'dom/ShadowContentSelectorQuery.h',
    54625465            'dom/ShadowInclusionSelector.cpp',
    54635466            'dom/ShadowInclusionSelector.h',
  • trunk/Source/WebCore/WebCore.vcproj/WebCore.vcproj

    r104827 r104919  
    5110751107                        </File>
    5110851108                        <File
     51109                                RelativePath="..\dom\ShadowContentSelectorQuery.cpp"
     51110                                >
     51111                        </File>
     51112                        <File
     51113                                RelativePath="..\dom\ShadowContentSelectorQuery.h"
     51114                                >
     51115                        </File>
     51116                        <File
    5110951117                                RelativePath="..\dom\ShadowInclusionSelector.cpp"
    5111051118                                >
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r104896 r104919  
    15631563                550A0BC9085F6039007353D6 /* QualifiedName.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 550A0BC7085F6039007353D6 /* QualifiedName.cpp */; };
    15641564                550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1565                570DBA8114B5804900DAEFA0 /* ShadowContentSelectorQuery.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 570DB7A814B5696A00DAEFA0 /* ShadowContentSelectorQuery.cpp */; };
     1566                570DBA8214B5804B00DAEFA0 /* ShadowContentSelectorQuery.h in Headers */ = {isa = PBXBuildFile; fileRef = 570DB7A914B5696A00DAEFA0 /* ShadowContentSelectorQuery.h */; };
    15651567                5905ADBF1302F3CE00F116DF /* XMLTreeViewer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5905ADBD1302F3CE00F116DF /* XMLTreeViewer.cpp */; };
    15661568                5905ADC01302F3CE00F116DF /* XMLTreeViewer.h in Headers */ = {isa = PBXBuildFile; fileRef = 5905ADBE1302F3CE00F116DF /* XMLTreeViewer.h */; };
     
    83768378                550A0BC7085F6039007353D6 /* QualifiedName.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = QualifiedName.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    83778379                550A0BC8085F6039007353D6 /* QualifiedName.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = QualifiedName.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     8380                570DB7A814B5696A00DAEFA0 /* ShadowContentSelectorQuery.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ShadowContentSelectorQuery.cpp; sourceTree = "<group>"; };
     8381                570DB7A914B5696A00DAEFA0 /* ShadowContentSelectorQuery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ShadowContentSelectorQuery.h; sourceTree = "<group>"; };
    83788382                5905ADBD1302F3CE00F116DF /* XMLTreeViewer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = XMLTreeViewer.cpp; sourceTree = "<group>"; };
    83798383                5905ADBE1302F3CE00F116DF /* XMLTreeViewer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMLTreeViewer.h; sourceTree = "<group>"; };
     
    2051120515                                A766CF8B13810E0C0011A0B3 /* ShadowContentElement.cpp */,
    2051220516                                A74C2D3B13811E0D00F83572 /* ShadowContentElement.h */,
     20517                                570DB7A814B5696A00DAEFA0 /* ShadowContentSelectorQuery.cpp */,
     20518                                570DB7A914B5696A00DAEFA0 /* ShadowContentSelectorQuery.h */,
    2051320519                                A71C30B61381265E00DBC351 /* ShadowInclusionSelector.cpp */,
    2051420520                                A71C30B71381265E00DBC351 /* ShadowInclusionSelector.h */,
     
    2336723373                                0F3DD45012F5EA1B000D9190 /* ShadowBlur.h in Headers */,
    2336823374                                A74C2D3C13811E0D00F83572 /* ShadowContentElement.h in Headers */,
     23375                                570DBA8214B5804B00DAEFA0 /* ShadowContentSelectorQuery.h in Headers */,
    2336923376                                BC5EB8C40E82031B00B25965 /* ShadowData.h in Headers */,
    2337023377                                A71C30B91381265E00DBC351 /* ShadowInclusionSelector.h in Headers */,
     
    2640126408                                0F3DD44F12F5EA1B000D9190 /* ShadowBlur.cpp in Sources */,
    2640226409                                A766CF8C13810E0C0011A0B3 /* ShadowContentElement.cpp in Sources */,
     26410                                570DBA8114B5804900DAEFA0 /* ShadowContentSelectorQuery.cpp in Sources */,
    2640326411                                BC5EB8C30E82031B00B25965 /* ShadowData.cpp in Sources */,
    2640426412                                A71C30B81381265E00DBC351 /* ShadowInclusionSelector.cpp in Sources */,
  • trunk/Source/WebCore/dom/DOMAllInOne.cpp

    r104827 r104919  
    114114#include "SelectorQuery.cpp"
    115115#include "ShadowContentElement.cpp"
     116#include "ShadowContentSelectorQuery.cpp"
    116117#include "ShadowInclusionSelector.cpp"
    117118#include "ShadowRoot.cpp"
  • trunk/Source/WebCore/dom/SelectorQuery.cpp

    r104827 r104919  
    3434namespace WebCore {
    3535
    36 SelectorQuery::SelectorQuery(Node* rootNode, const CSSSelectorList& selectorList)
    37     : m_rootNode(rootNode)
    38     , m_selectorChecker(rootNode->document(), !rootNode->document()->inQuirksMode())
     36SelectorDataList::SelectorDataList()
    3937{
    40     m_selectorChecker.setCollectingRulesOnly(true);
     38}
     39
     40SelectorDataList::SelectorDataList(const CSSSelectorList& selectorList)
     41{
     42    initialize(selectorList);
     43}
     44
     45void SelectorDataList::initialize(const CSSSelectorList& selectorList)
     46{
     47    ASSERT(m_selectors.isEmpty());
    4148
    4249    for (CSSSelector* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector))
    4350        m_selectors.append(SelectorData(selector, SelectorChecker::isFastCheckableSelector(selector)));
    4451}
    45    
    46 PassRefPtr<NodeList> SelectorQuery::queryAll() const
     52
     53bool SelectorDataList::matches(const SelectorChecker& selectorChecker, Element* targetElement) const
     54{
     55    ASSERT(targetElement);
     56
     57    unsigned selectorCount = m_selectors.size();
     58    for (unsigned i = 0; i < selectorCount; ++i) {
     59        if (selectorChecker.checkSelector(m_selectors[i].selector, targetElement, m_selectors[i].isFastCheckable))
     60            return true;
     61    }
     62
     63    return false;
     64}
     65
     66PassRefPtr<NodeList> SelectorDataList::queryAll(const SelectorChecker& selectorChecker, Node* rootNode) const
    4767{
    4868    Vector<RefPtr<Node> > result;
    49     execute<false>(result);
     69    execute<false>(selectorChecker, rootNode, result);
    5070    return StaticNodeList::adopt(result);
    5171}
    5272
    53 PassRefPtr<Element> SelectorQuery::queryFirst() const
    54 { 
     73PassRefPtr<Element> SelectorDataList::queryFirst(const SelectorChecker& selectorChecker, Node* rootNode) const
     74{
    5575    Vector<RefPtr<Node> > result;
    56     execute<true>(result);
     76    execute<true>(selectorChecker, rootNode, result);
    5777    if (result.isEmpty())
    5878        return 0;
     
    6282}
    6383
    64 bool SelectorQuery::canUseIdLookup() const
     84bool SelectorDataList::canUseIdLookup(Node* rootNode) const
    6585{
    6686    // We need to return the matches in document order. To use id lookup while there is possiblity of multiple matches
     
    7090    if (m_selectors[0].selector->m_match != CSSSelector::Id)
    7191        return false;
    72     if (!m_rootNode->inDocument())
     92    if (!rootNode->inDocument())
    7393        return false;
    74     if (m_rootNode->document()->inQuirksMode())
     94    if (rootNode->document()->inQuirksMode())
    7595        return false;
    76     if (m_rootNode->document()->containsMultipleElementsWithId(m_selectors[0].selector->value()))
     96    if (rootNode->document()->containsMultipleElementsWithId(m_selectors[0].selector->value()))
    7797        return false;
    7898    return true;
     
    80100
    81101template <bool firstMatchOnly>
    82 void SelectorQuery::execute(Vector<RefPtr<Node> >& matchedElements) const
     102void SelectorDataList::execute(const SelectorChecker& selectorChecker, Node* rootNode, Vector<RefPtr<Node> >& matchedElements) const
    83103{
    84     if (canUseIdLookup()) {
     104    if (canUseIdLookup(rootNode)) {
    85105        ASSERT(m_selectors.size() == 1);
    86106        CSSSelector* selector = m_selectors[0].selector;
    87         Element* element = m_rootNode->document()->getElementById(selector->value());
    88         if (!element || !(m_rootNode->isDocumentNode() || element->isDescendantOf(m_rootNode)))
     107        Element* element = rootNode->document()->getElementById(selector->value());
     108        if (!element || !(rootNode->isDocumentNode() || element->isDescendantOf(rootNode)))
    89109            return;
    90         if (m_selectorChecker.checkSelector(selector, element, m_selectors[0].isFastCheckable))
     110        if (selectorChecker.checkSelector(m_selectors[0].selector, element, m_selectors[0].isFastCheckable))
    91111            matchedElements.append(element);
    92112        return;
    93113    }
    94    
     114
    95115    unsigned selectorCount = m_selectors.size();
    96    
    97     Node* n = m_rootNode->firstChild();
     116
     117    Node* n = rootNode->firstChild();
    98118    while (n) {
    99119        if (n->isElementNode()) {
    100120            Element* element = static_cast<Element*>(n);
    101121            for (unsigned i = 0; i < selectorCount; ++i) {
    102                 if (m_selectorChecker.checkSelector(m_selectors[i].selector, element, m_selectors[i].isFastCheckable)) {
     122                if (selectorChecker.checkSelector(m_selectors[i].selector, element, m_selectors[i].isFastCheckable)) {
    103123                    matchedElements.append(element);
    104124                    if (firstMatchOnly)
     
    114134        while (!n->nextSibling()) {
    115135            n = n->parentNode();
    116             if (n == m_rootNode)
     136            if (n == rootNode)
    117137                return;
    118138        }
     
    121141}
    122142
     143SelectorQuery::SelectorQuery(Node* rootNode, const CSSSelectorList& selectorList)
     144    : m_rootNode(rootNode)
     145    , m_selectorChecker(rootNode->document(), !rootNode->document()->inQuirksMode())
     146    , m_selectors(selectorList)
     147{
     148    m_selectorChecker.setCollectingRulesOnly(true);
    123149}
     150
     151PassRefPtr<NodeList> SelectorQuery::queryAll() const
     152{
     153    return m_selectors.queryAll(m_selectorChecker, m_rootNode);
     154}
     155
     156PassRefPtr<Element> SelectorQuery::queryFirst() const
     157{
     158    return m_selectors.queryFirst(m_selectorChecker, m_rootNode);
     159}
     160
     161}
  • trunk/Source/WebCore/dom/SelectorQuery.h

    r104827 r104919  
    3838class CSSSelectorList;
    3939
    40 class SelectorQuery {
    41     WTF_MAKE_NONCOPYABLE(SelectorQuery);
     40class SelectorDataList {
    4241public:
    43     SelectorQuery(Node* rootNode, const CSSSelectorList&);
    44    
    45     PassRefPtr<NodeList> queryAll() const;
    46     PassRefPtr<Element> queryFirst() const;
     42    SelectorDataList();
     43    explicit SelectorDataList(const CSSSelectorList&);
     44
     45    void initialize(const CSSSelectorList&);
     46
     47    int size() const { return m_selectors.size(); }
     48
     49    bool matches(const SelectorChecker&, Element*) const;
     50    PassRefPtr<NodeList> queryAll(const SelectorChecker&, Node* rootNode) const;
     51    PassRefPtr<Element> queryFirst(const SelectorChecker&, Node* rootNode) const;
    4752
    4853private:
    49     bool canUseIdLookup() const;
    50 
    51     template <bool firstMatchOnly>
    52     void execute(Vector<RefPtr<Node> >&) const;
    53    
    5454    struct SelectorData {
    5555        SelectorData(CSSSelector* selector, bool isFastCheckable) : selector(selector), isFastCheckable(isFastCheckable) { }
     
    5757        bool isFastCheckable;
    5858    };
     59
     60    bool canUseIdLookup(Node* rootNode) const;
     61    template <bool firstMatchOnly>
     62    void execute(const SelectorChecker&, Node* rootNode, Vector<RefPtr<Node> >&) const;
     63
     64    Vector<SelectorData> m_selectors;
     65};
     66
     67class SelectorQuery {
     68    WTF_MAKE_NONCOPYABLE(SelectorQuery);
     69public:
     70    SelectorQuery(Node* rootNode, const CSSSelectorList&);
     71
     72    PassRefPtr<NodeList> queryAll() const;
     73    PassRefPtr<Element> queryFirst() const;
     74private:
    5975    Node* m_rootNode;
    60     Vector<SelectorData> m_selectors;
    6176    SelectorChecker m_selectorChecker;
     77    SelectorDataList m_selectors;
    6278};
    6379
  • trunk/Source/WebCore/dom/ShadowContentElement.cpp

    r104827 r104919  
    2929
    3030#include "HTMLNames.h"
     31#include "QualifiedName.h"
     32#include "ShadowContentSelectorQuery.h"
    3133#include "ShadowInclusionSelector.h"
    3234#include "ShadowRoot.h"
     35#include <wtf/StdLibExtras.h>
    3336
    3437namespace WebCore {
     38
     39using HTMLNames::selectAttr;
    3540
    3641PassRefPtr<ShadowContentElement> ShadowContentElement::create(Document* document)
     
    7782}
    7883
    79 bool ShadowContentElement::shouldInclude(Node*)
     84const AtomicString& ShadowContentElement::select() const
    8085{
    81     return true;
     86    return getAttribute(selectAttr);
    8287}
    8388
     89void ShadowContentElement::setSelect(const AtomicString& selectValue)
     90{
     91    setAttribute(selectAttr, selectValue);
     92}
    8493
    8594}
  • trunk/Source/WebCore/dom/ShadowContentElement.h

    r104827 r104919  
    3737namespace WebCore {
    3838
     39class ShadowContentSelectorQuery;
    3940class ShadowInclusionList;
    4041
     
    4647
    4748    virtual ~ShadowContentElement();
    48     virtual bool shouldInclude(Node*);
    4949    virtual void attach();
    5050    virtual void detach();
     51
     52    const AtomicString& select() const;
     53
     54    // FIXME: Currently this constructor accepts wider query than shadow dom spec.
     55    // For example, a selector query should not include contextual selectors.
     56    // See https://bugs.webkit.org/show_bug.cgi?id=75946
     57    // FIXME: Currently we don't support setting select value dynamically.
     58    // See https://bugs.webkit.org/show_bug.cgi?id=76261
     59    void setSelect(const AtomicString&);
    5160
    5261    const ShadowInclusionList* inclusions() const { return m_inclusions.get(); }
  • trunk/Source/WebCore/dom/ShadowContentSelectorQuery.h

    r104918 r104919  
    2929 */
    3030
    31 #ifndef ShadowContentElement_h
    32 #define ShadowContentElement_h
     31#ifndef ShadowContentSelectorQuery_h
     32#define ShadowContentSelectorQuery_h
    3333
    34 #include "StyledElement.h"
     34#include "CSSSelectorList.h"
     35#include "SelectorChecker.h"
     36#include "SelectorQuery.h"
    3537#include <wtf/Forward.h>
     38#include <wtf/Vector.h>
    3639
    3740namespace WebCore {
    3841
    39 class ShadowInclusionList;
     42class Document;
     43class Node;
     44class ShadowContentElement;
    4045
    41 // NOTE: Current implementation doesn't support dynamic insertion/deletion of ShadowContentElement.
    42 // You should create ShadowContentElement during the host construction.
    43 class ShadowContentElement : public StyledElement {
     46class ShadowContentSelectorQuery {
     47    WTF_MAKE_NONCOPYABLE(ShadowContentSelectorQuery);
    4448public:
    45     static PassRefPtr<ShadowContentElement> create(Document*);
     49    explicit ShadowContentSelectorQuery(ShadowContentElement*);
    4650
    47     virtual ~ShadowContentElement();
    48     virtual bool shouldInclude(Node*);
    49     virtual void attach();
    50     virtual void detach();
    51 
    52     const ShadowInclusionList* inclusions() const { return m_inclusions.get(); }
    53 
    54 protected:
    55     ShadowContentElement(const QualifiedName&, Document*);
     51    bool matches(Node*) const;
    5652
    5753private:
    58     virtual bool isContentElement() const { return true; }
    59     virtual bool rendererIsNeeded(const NodeRenderingContext&) { return false; }
    60     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) { return 0; }
    61 
    62     OwnPtr<ShadowInclusionList> m_inclusions;
     54    ShadowContentElement* m_contentElement;
     55    SelectorDataList m_selectors;
     56    CSSSelectorList m_selectorList;
     57    SelectorChecker m_selectorChecker;
    6358};
    64 
    65 inline ShadowContentElement* toShadowContentElement(Node* node)
    66 {
    67     ASSERT(!node || node->isContentElement());
    68     return static_cast<ShadowContentElement*>(node);
    69 }
    7059
    7160}
    7261
     62
     63
    7364#endif
  • trunk/Source/WebCore/dom/ShadowInclusionSelector.cpp

    r104827 r104919  
    2929
    3030#include "ShadowContentElement.h"
     31#include "ShadowContentSelectorQuery.h"
    3132#include "ShadowRoot.h"
    3233
     
    112113    ASSERT(inclusions->isEmpty());
    113114
     115    ShadowContentSelectorQuery query(contentElement);
    114116    for (size_t i = 0; i < m_candidates.size(); ++i) {
    115117        Node* child = m_candidates[i].get();
    116118        if (!child)
    117119            continue;
    118         if (!contentElement->shouldInclude(child))
     120        if (!query.matches(child))
    119121            continue;
    120122
  • trunk/Source/WebCore/dom/ShadowInclusionSelector.h

    r104827 r104919  
    138138    bool hasCandidates() const { return !m_candidates.isEmpty(); }
    139139
    140 
    141140private:
    142141    void removeFromSet(ShadowInclusionList*);
  • trunk/Source/WebCore/html/HTMLAttributeNames.in

    r104838 r104919  
    280280scrolldelay
    281281scrolling
     282select
    282283selected
    283284shape
  • trunk/Source/WebCore/html/HTMLDetailsElement.cpp

    r104827 r104919  
    3737using namespace HTMLNames;
    3838
     39static const AtomicString& summaryQuerySelector()
     40{
     41    DEFINE_STATIC_LOCAL(AtomicString, selector, ("summary:first-of-type"));
     42    return selector;
     43};
     44
    3945class DetailsContentElement : public ShadowContentElement {
    4046public:
     
    4652    {
    4753    }
    48 
    49     virtual bool shouldInclude(Node*);
    5054};
    5155
     
    5458    return adoptRef(new DetailsContentElement(document));
    5559}
    56 
    57 bool DetailsContentElement::shouldInclude(Node* node)
    58 {
    59     HTMLDetailsElement* details = static_cast<HTMLDetailsElement*>(shadowAncestorNode());
    60     return details->mainSummary() != node;
    61 }
    62 
    6360
    6461class DetailsSummaryElement : public ShadowContentElement {
     
    7067        : ShadowContentElement(HTMLNames::divTag, document)
    7168    {
    72     }
    73 
    74     virtual bool shouldInclude(Node*);
     69        setSelect(summaryQuerySelector());
     70    }
    7571};
    7672
     
    7975    return adoptRef(new DetailsSummaryElement(document));
    8076}
    81 
    82 bool DetailsSummaryElement::shouldInclude(Node* node)
    83 {
    84     HTMLDetailsElement* details = static_cast<HTMLDetailsElement*>(shadowAncestorNode());
    85     return details->mainSummary() == node;
    86 }
    87 
    8877
    8978PassRefPtr<HTMLDetailsElement> HTMLDetailsElement::create(const QualifiedName& tagName, Document* document)
Note: See TracChangeset for help on using the changeset viewer.