Changeset 107525 in webkit


Ignore:
Timestamp:
Feb 12, 2012 8:15:49 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Introduce ShadowRootList.
https://bugs.webkit.org/show_bug.cgi?id=78069

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

Source/JavaScriptCore:

DoublyLinkedList should have tail() method to take the last element.

  • wtf/DoublyLinkedList.h:

(DoublyLinkedList):
(WTF::::tail):
(WTF):

Source/WebCore:

This is a step to implement multiple shadow subtrees.

This patch introduces a shadow root list. ShadowRootList is a doubly linked list,
and each shadow root now has a younger shadow root and older shadow root,
which are a previous element and a next element respectively.
Since a visual tree traversal, which will be introduced in coming patches, will need a older shadow root,
we make a shadow root list a doubly linked list.

However, ShadowRootList does not have more than one shadow root now.
This will be changed in a series of coming patches.

Element::shadowRoot(), setShadowRoot(), ensureShadowRoot(), and removeShadowRoot() are
emulated using ShadowRootList for a while. These API will be replaced to ShadowRootList API later.

No new tests, no change in behavior.

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

(WebCore::Element::hasShadowRoot):

Retruns true if an element has a shadowRoot.

(WebCore::Element::shadowRootList):

Gets shadow root list if any.

(WebCore::Element::shadowRoot):

Gets the first shadow root from the shadow root list.

(WebCore::Element::setShadowRoot):

Sets the first shadow root to the shadow root list.

(WebCore::Element::removeShadowRoot):

Removes all the shadow roots in the shadow root list.

  • dom/Element.h:

(WebCore):
(Element):

  • dom/ElementRareData.h:

(ElementRareData):
(WebCore::ElementRareData::ElementRareData):

Has shadow root lists instead of shadow root.

(WebCore::ElementRareData::~ElementRareData):

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::ShadowRoot):
(WebCore::ShadowRoot::~ShadowRoot):

  • dom/ShadowRoot.h:

(ShadowRoot):
(WebCore::ShadowRoot::youngerShadowRoot):
(WebCore::ShadowRoot::olderShadowRoot):

  • dom/ShadowRootList.cpp: Added.

(WebCore):
(WebCore::ShadowRootList::ShadowRootList):
(WebCore::ShadowRootList::~ShadowRootList):
(WebCore::ShadowRootList::pushShadowRoot):

Adds a shadow root into the list. Currently we limit the list can have only one shadow root.

(WebCore::ShadowRootList::popShadowRoot):

Removes and returns the youngest shadow root if any.

  • dom/ShadowRootList.h: Added.

(WebCore):
(ShadowRootList):
(WebCore::ShadowRootList::hasShadowRoot):
(WebCore::ShadowRootList::youngestShadowRoot):
(WebCore::ShadowRootList::oldestShadowRoot):

Location:
trunk/Source
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r107514 r107525  
     12012-02-12  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Introduce ShadowRootList.
     4        https://bugs.webkit.org/show_bug.cgi?id=78069
     5
     6        Reviewed by Hajime Morita.
     7
     8        DoublyLinkedList should have tail() method to take the last element.
     9
     10        * wtf/DoublyLinkedList.h:
     11        (DoublyLinkedList):
     12        (WTF::::tail):
     13        (WTF):
     14
    1152012-02-12  Raphael Kubo da Costa  <kubo@profusion.mobi>
    216
  • trunk/Source/JavaScriptCore/wtf/DoublyLinkedList.h

    r105442 r107525  
    7878    T* removeHead();
    7979
     80    T* tail() const;
     81
    8082    void push(T*);
    8183    void append(T*);
     
    115117{
    116118    return m_head;
     119}
     120
     121template<typename T> inline T* DoublyLinkedList<T>::tail() const
     122{
     123    return m_tail;
    117124}
    118125
  • trunk/Source/WebCore/CMakeLists.txt

    r107518 r107525  
    601601    dom/SelectorQuery.cpp
    602602    dom/ShadowRoot.cpp
     603    dom/ShadowRootList.cpp
    603604    dom/SpaceSplitString.cpp
    604605    dom/StaticHashSetNodeList.cpp
  • trunk/Source/WebCore/ChangeLog

    r107524 r107525  
     12012-02-12  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Introduce ShadowRootList.
     4        https://bugs.webkit.org/show_bug.cgi?id=78069
     5
     6        Reviewed by Hajime Morita.
     7
     8        This is a step to implement multiple shadow subtrees.
     9
     10        This patch introduces a shadow root list. ShadowRootList is a doubly linked list,
     11        and each shadow root now has a younger shadow root and older shadow root,
     12        which are a previous element and a next element respectively.
     13        Since a visual tree traversal, which will be introduced in coming patches, will need a older shadow root,
     14        we make a shadow root list a doubly linked list.
     15
     16        However, ShadowRootList does not have more than one shadow root now.
     17        This will be changed in a series of coming patches.
     18
     19        Element::shadowRoot(), setShadowRoot(), ensureShadowRoot(), and removeShadowRoot() are
     20        emulated using ShadowRootList for a while. These API will be replaced to ShadowRootList API later.
     21
     22        No new tests, no change in behavior.
     23
     24        * CMakeLists.txt:
     25        * GNUmakefile.list.am:
     26        * Target.pri:
     27        * WebCore.gypi:
     28        * WebCore.xcodeproj/project.pbxproj:
     29        * dom/DOMAllInOne.cpp:
     30        * dom/Element.cpp:
     31        (WebCore::Element::hasShadowRoot):
     32          Retruns true if an element has a shadowRoot.
     33        (WebCore::Element::shadowRootList):
     34          Gets shadow root list if any.
     35        (WebCore::Element::shadowRoot):
     36          Gets the first shadow root from the shadow root list.
     37        (WebCore::Element::setShadowRoot):
     38          Sets the first shadow root to the shadow root list.
     39        (WebCore::Element::removeShadowRoot):
     40          Removes all the shadow roots in the shadow root list.
     41        * dom/Element.h:
     42        (WebCore):
     43        (Element):
     44        * dom/ElementRareData.h:
     45        (ElementRareData):
     46        (WebCore::ElementRareData::ElementRareData):
     47          Has shadow root lists instead of shadow root.
     48        (WebCore::ElementRareData::~ElementRareData):
     49        * dom/ShadowRoot.cpp:
     50        (WebCore::ShadowRoot::ShadowRoot):
     51        (WebCore::ShadowRoot::~ShadowRoot):
     52        * dom/ShadowRoot.h:
     53        (ShadowRoot):
     54        (WebCore::ShadowRoot::youngerShadowRoot):
     55        (WebCore::ShadowRoot::olderShadowRoot):
     56        * dom/ShadowRootList.cpp: Added.
     57        (WebCore):
     58        (WebCore::ShadowRootList::ShadowRootList):
     59        (WebCore::ShadowRootList::~ShadowRootList):
     60        (WebCore::ShadowRootList::pushShadowRoot):
     61          Adds a shadow root into the list. Currently we limit the list can have only one shadow root.
     62        (WebCore::ShadowRootList::popShadowRoot):
     63          Removes and returns the youngest shadow root if any.
     64        * dom/ShadowRootList.h: Added.
     65        (WebCore):
     66        (ShadowRootList):
     67        (WebCore::ShadowRootList::hasShadowRoot):
     68        (WebCore::ShadowRootList::youngestShadowRoot):
     69        (WebCore::ShadowRootList::oldestShadowRoot):
     70
    1712012-02-12  Shinya Kawanaka  <shinyak@google.com>
    272
  • trunk/Source/WebCore/GNUmakefile.list.am

    r107518 r107525  
    16601660        Source/WebCore/dom/ShadowRoot.cpp \
    16611661        Source/WebCore/dom/ShadowRoot.h \
     1662        Source/WebCore/dom/ShadowRootList.cpp \
     1663        Source/WebCore/dom/ShadowRootList.h \
    16621664        Source/WebCore/dom/SpaceSplitString.cpp \
    16631665        Source/WebCore/dom/SpaceSplitString.h \
  • trunk/Source/WebCore/Target.pri

    r107518 r107525  
    567567    dom/SelectorQuery.cpp \
    568568    dom/ShadowRoot.cpp \
     569    dom/ShadowRootList.cpp \
    569570    dom/SpaceSplitString.cpp \
    570571    dom/StaticNodeList.cpp \
     
    16711672    dom/SelectorQuery.h \
    16721673    dom/ShadowRoot.h \
     1674    dom/ShadowRootList.h \
    16731675    dom/SpaceSplitString.h \
    16741676    dom/StaticNodeList.h \
  • trunk/Source/WebCore/WebCore.gypi

    r107518 r107525  
    620620            'dom/ScriptRunner.h',
    621621            'dom/ShadowRoot.h',
     622            'dom/ShadowRootList.h',
    622623            'dom/SpaceSplitString.h',
    623624            'dom/StyledElement.h',
     
    51025103            'dom/ShadowRoot.cpp',
    51035104            'dom/ShadowRoot.h',
     5105            'dom/ShadowRootList.cpp',
     5106            'dom/ShadowRootList.h',
    51045107            'dom/SpaceSplitString.cpp',
    51055108            'dom/StaticHashSetNodeList.cpp',
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r107518 r107525  
    16031603                550A0BC9085F6039007353D6 /* QualifiedName.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 550A0BC7085F6039007353D6 /* QualifiedName.cpp */; };
    16041604                550A0BCA085F6039007353D6 /* QualifiedName.h in Headers */ = {isa = PBXBuildFile; fileRef = 550A0BC8085F6039007353D6 /* QualifiedName.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1605                572E92FB14E540580087FFBA /* ShadowRootList.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 572E92F914E540580087FFBA /* ShadowRootList.cpp */; };
     1606                572E92FC14E540580087FFBA /* ShadowRootList.h in Headers */ = {isa = PBXBuildFile; fileRef = 572E92FA14E540580087FFBA /* ShadowRootList.h */; };
    16051607                573D134714CE39FF0057ABCA /* InspectorTypeBuilder.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 573D134514CE39FF0057ABCA /* InspectorTypeBuilder.cpp */; };
    16061608                57B791A314C6A62900F202D1 /* ContentInclusionSelector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 57B7919F14C6A62900F202D1 /* ContentInclusionSelector.cpp */; };
     
    84658467                550A0BC7085F6039007353D6 /* QualifiedName.cpp */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.cpp; path = QualifiedName.cpp; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    84668468                550A0BC8085F6039007353D6 /* QualifiedName.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = QualifiedName.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     8469                572E92F914E540580087FFBA /* ShadowRootList.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ShadowRootList.cpp; path = dom/ShadowRootList.cpp; sourceTree = "<group>"; };
     8470                572E92FA14E540580087FFBA /* ShadowRootList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ShadowRootList.h; path = dom/ShadowRootList.h; sourceTree = "<group>"; };
    84678471                573D134514CE39FF0057ABCA /* InspectorTypeBuilder.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorTypeBuilder.cpp; sourceTree = "<group>"; };
    84688472                573D134614CE39FF0057ABCA /* InspectorTypeBuilder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorTypeBuilder.h; sourceTree = "<group>"; };
     
    1339613400                        isa = PBXGroup;
    1339713401                        children = (
     13402                                572E92F914E540580087FFBA /* ShadowRootList.cpp */,
     13403                                572E92FA14E540580087FFBA /* ShadowRootList.h */,
    1339813404                                65C97AF208EA908800ACD273 /* config.h */,
    1339913405                                EDEC98020AED7E170059137F /* WebCorePrefix.h */,
     
    2418124187                                4A957F0714E241300049DBFB /* WebSocketExtensionDispatcher.h in Headers */,
    2418224188                                4ADE25FA14E3BB4C004C2213 /* WebSocketExtensionProcessor.h in Headers */,
     24189                                572E92FC14E540580087FFBA /* ShadowRootList.h in Headers */,
    2418324190                        );
    2418424191                        runOnlyForDeploymentPostprocessing = 0;
     
    2712127128                                7A54881814E432A1006AE05A /* DOMPatchSupport.cpp in Sources */,
    2712227129                                4A957F0614E2412A0049DBFB /* WebSocketExtensionDispatcher.cpp in Sources */,
     27130                                572E92FB14E540580087FFBA /* ShadowRootList.cpp in Sources */,
    2712327131                        );
    2712427132                        runOnlyForDeploymentPostprocessing = 0;
  • trunk/Source/WebCore/dom/DOMAllInOne.cpp

    r107454 r107525  
    118118#include "SelectorQuery.cpp"
    119119#include "ShadowRoot.cpp"
     120#include "ShadowRootList.cpp"
    120121#include "SpaceSplitString.cpp"
    121122#include "StaticHashSetNodeList.cpp"
  • trunk/Source/WebCore/dom/Element.cpp

    r107509 r107525  
    11531153}
    11541154
     1155bool Element::hasShadowRoot() const
     1156{
     1157    if (ShadowRootList* list = shadowRootList())
     1158        return list->hasShadowRoot();
     1159    return false;
     1160}
     1161
     1162ShadowRootList* Element::shadowRootList() const
     1163{
     1164    if (!hasRareData())
     1165        return 0;
     1166
     1167    return &rareData()->m_shadowRootList;
     1168}
     1169
    11551170ShadowRoot* Element::shadowRoot() const
    11561171{
    1157     return hasRareData() ? rareData()->m_shadowRoot : 0;
     1172    if (ShadowRootList* list = shadowRootList())
     1173        return list->youngestShadowRoot();
     1174    return 0;
    11581175}
    11591176
     
    11761193}
    11771194
    1178 void Element::setShadowRoot(PassRefPtr<ShadowRoot> prpShadowRoot, ExceptionCode& ec)
    1179 {
    1180     RefPtr<ShadowRoot> shadowRoot = prpShadowRoot;
     1195void Element::setShadowRoot(PassRefPtr<ShadowRoot> shadowRoot, ExceptionCode& ec)
     1196{
    11811197    if (!validateShadowRoot(document(), shadowRoot.get(), ec))
    11821198        return;
    11831199
     1200    if (!hasRareData())
     1201        ensureRareData();
     1202
    11841203    removeShadowRoot();
    11851204
    1186     ensureRareData()->m_shadowRoot = shadowRoot.get();
    11871205    shadowRoot->setShadowHost(this);
     1206    shadowRootList()->pushShadowRoot(shadowRoot.get());
     1207
    11881208    if (inDocument())
    11891209        shadowRoot->insertedIntoDocument();
     
    12051225void Element::removeShadowRoot()
    12061226{
    1207     if (!hasRareData())
    1208         return;
    1209 
    1210     ElementRareData* data = rareData();
    1211     if (RefPtr<ShadowRoot> oldRoot = data->m_shadowRoot) {
    1212         data->m_shadowRoot = 0;
     1227    if (!hasShadowRoot())
     1228        return;
     1229
     1230    while (RefPtr<ShadowRoot> oldRoot = shadowRootList()->popShadowRoot()) {
    12131231        document()->removeFocusedNodeOfSubtree(oldRoot.get());
    12141232
    1215         // Remove from rendering tree
    12161233        if (oldRoot->attached())
    12171234            oldRoot->detach();
     
    12241241            oldRoot->removedFromTree(true);
    12251242        if (attached()) {
    1226             for (Node* child = firstChild(); child; child = child->nextSibling())
     1243            for (Node* child = firstChild(); child; child = child->nextSibling()) {
    12271244                if (!child->attached())
    12281245                    child->lazyAttach();
     1246            }
    12291247        }
    12301248    }
  • trunk/Source/WebCore/dom/Element.h

    r107477 r107525  
    4343class IntSize;
    4444class ShadowRoot;
     45class ShadowRootList;
    4546class WebKitAnimationList;
    4647
     
    257258    void recalcStyle(StyleChange = NoChange);
    258259
     260    bool hasShadowRoot() const;
     261    ShadowRootList* shadowRootList() const;
     262
     263    // FIXME: These API will be moved to ShadowRootList.
     264    // https://bugs.webkit.org/show_bug.cgi?id=78313
    259265    ShadowRoot* shadowRoot() const;
    260266    void setShadowRoot(PassRefPtr<ShadowRoot>, ExceptionCode&);
  • trunk/Source/WebCore/dom/ElementRareData.h

    r105849 r107525  
    2828#include "HTMLCollection.h"
    2929#include "NodeRareData.h"
     30#include "ShadowRootList.h"
    3031#include <wtf/OwnPtr.h>
    3132
    3233namespace WebCore {
    33 
    34 class ShadowRoot;
    3534
    3635class ElementRareData : public NodeRareData {
     
    7372    LayoutSize m_minimumSizeForResizing;
    7473    RefPtr<RenderStyle> m_computedStyle;
    75     ShadowRoot* m_shadowRoot;
     74    ShadowRootList m_shadowRootList;
    7675    AtomicString m_shadowPseudoId;
    7776
     
    9796inline ElementRareData::ElementRareData()
    9897    : m_minimumSizeForResizing(defaultMinimumSizeForResizing())
    99     , m_shadowRoot(0)
    10098#if ENABLE(STYLE_SCOPED)
    10199    , m_numberOfScopedHTMLStyleChildren(0)
     
    110108inline ElementRareData::~ElementRareData()
    111109{
    112     ASSERT(!m_shadowRoot);
     110    ASSERT(!m_shadowRootList.hasShadowRoot());
    113111}
    114112
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r107509 r107525  
    4242    : DocumentFragment(document, CreateShadowRoot)
    4343    , TreeScope(this)
     44    , m_prev(0)
     45    , m_next(0)
    4446    , m_applyAuthorSheets(false)
    4547    , m_needsRecalculateContent(false)
     
    5658ShadowRoot::~ShadowRoot()
    5759{
     60    ASSERT(!m_prev);
     61    ASSERT(!m_next);
     62
    5863    // We must call clearRareData() here since a ShadowRoot class inherits TreeScope
    5964    // as well as Node. See a comment on TreeScope.h for the reason.
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r107202 r107525  
    3131#include "ExceptionCode.h"
    3232#include "TreeScope.h"
     33#include <wtf/DoublyLinkedList.h>
    3334
    3435namespace WebCore {
     
    3839class HTMLContentElement;
    3940
    40 class ShadowRoot : public DocumentFragment, public TreeScope {
     41class ShadowRoot : public DocumentFragment, public TreeScope, public DoublyLinkedListNode<ShadowRoot> {
     42    friend class WTF::DoublyLinkedListNode<ShadowRoot>;
    4143public:
    4244    static PassRefPtr<ShadowRoot> create(Document*);
     
    7476    ContentInclusionSelector* ensureInclusions();
    7577
     78    ShadowRoot* youngerShadowRoot() const { return prev(); }
     79    ShadowRoot* olderShadowRoot() const { return next(); }
     80
    7681private:
    7782    ShadowRoot(Document*);
     
    8590    bool hasContentElement() const;
    8691
     92    ShadowRoot* m_prev;
     93    ShadowRoot* m_next;
    8794    bool m_applyAuthorSheets : 1;
    8895    bool m_needsRecalculateContent : 1;
Note: See TracChangeset for help on using the changeset viewer.