Changeset 109084 in webkit


Ignore:
Timestamp:
Feb 28, 2012 12:05:51 AM (12 years ago)
Author:
shinyak@chromium.org
Message:

Element::removeShadowRoot() and setShadowRoot() should be moved into ShadowTree.
https://bugs.webkit.org/show_bug.cgi?id=78313

Reviewed by Hajime Morita.

.:

  • Source/autotools/symbols.filter:

Source/WebCore:

This patch is for refactoring ShadowTree related code.

(1) Element::removeShadowRoot() and Element::setShadowRoot() are moved into ShadowTree.
(2) ShadowTree is now put on its own heap.

No new tests, no change in behavior.

  • WebCore.exp.in:
  • dom/Element.cpp:

(WebCore::Element::~Element):
(WebCore::Element::shadowTree):
(WebCore::Element::ensureShadowTree):

Ensure the existence of ShadowTree. This does not ensure ShadowRoot exists.

  • dom/Element.h:

(Element):

  • dom/ElementRareData.h: Makes ShadowTree on Heap.

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

  • dom/ShadowRoot.cpp:

(WebCore::ShadowRoot::create):

  • dom/ShadowTree.cpp:

(WebCore::validateShadowRoot):
(WebCore):
(WebCore::ShadowTree::addShadowRoot):
(WebCore::ShadowTree::removeAllShadowRoots):

  • dom/ShadowTree.h:

(ShadowTree):

  • testing/Internals.cpp:

(WebCore::Internals::removeShadowRoot):

Source/WebKit2:

  • win/WebKit2.def:
  • win/WebKit2CFLite.def:
Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r109063 r109084  
     12012-02-27  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        Element::removeShadowRoot() and setShadowRoot() should be moved into ShadowTree.
     4        https://bugs.webkit.org/show_bug.cgi?id=78313
     5
     6        Reviewed by Hajime Morita.
     7
     8        * Source/autotools/symbols.filter:
     9
    1102012-02-27  Dave Tu  <dtu@chromium.org>
    211
  • trunk/Source/WebCore/ChangeLog

    r109081 r109084  
     12012-02-27  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        Element::removeShadowRoot() and setShadowRoot() should be moved into ShadowTree.
     4        https://bugs.webkit.org/show_bug.cgi?id=78313
     5
     6        Reviewed by Hajime Morita.
     7
     8        This patch is for refactoring ShadowTree related code.
     9          (1) Element::removeShadowRoot() and Element::setShadowRoot() are moved into ShadowTree.
     10          (2) ShadowTree is now put on its own heap.
     11
     12        No new tests, no change in behavior.
     13
     14        * WebCore.exp.in:
     15        * dom/Element.cpp:
     16        (WebCore::Element::~Element):
     17        (WebCore::Element::shadowTree):
     18        (WebCore::Element::ensureShadowTree):
     19          Ensure the existence of ShadowTree. This does not ensure ShadowRoot exists.
     20        * dom/Element.h:
     21        (Element):
     22        * dom/ElementRareData.h:
     23          Makes ShadowTree on Heap.
     24        (ElementRareData):
     25        (WebCore::ElementRareData::~ElementRareData):
     26        * dom/ShadowRoot.cpp:
     27        (WebCore::ShadowRoot::create):
     28        * dom/ShadowTree.cpp:
     29        (WebCore::validateShadowRoot):
     30        (WebCore):
     31        (WebCore::ShadowTree::addShadowRoot):
     32        (WebCore::ShadowTree::removeAllShadowRoots):
     33        * dom/ShadowTree.h:
     34        (ShadowTree):
     35        * testing/Internals.cpp:
     36        (WebCore::Internals::removeShadowRoot):
     37
    1382012-02-27  David Barton  <dbarton@mathscribe.com>
    239
  • trunk/Source/WebCore/WebCore.exp.in

    r108959 r109084  
    144144__ZN7WebCore10MouseEvent6createERKN3WTF12AtomicStringENS1_10PassRefPtrINS_9DOMWindowEEERKNS_18PlatformMouseEventEiNS5_INS_4NodeEEE
    145145__ZN7WebCore10MouseEventC1ERKN3WTF12AtomicStringEbbNS1_10PassRefPtrINS_9DOMWindowEEEiiiiibbbbtNS5_INS_11EventTargetEEENS5_INS_9ClipboardEEEb
     146__ZN7WebCore10ShadowTree20removeAllShadowRootsEv
    146147__ZN7WebCore10ScrollView17setUseFixedLayoutEb
    147148__ZN7WebCore10ScrollView18setFixedLayoutSizeERKNS_7IntSizeE
     
    916917__ZN7WebCore7Console21shouldPrintExceptionsEv
    917918__ZN7WebCore7Console24setShouldPrintExceptionsEb
    918 __ZN7WebCore7Element16removeShadowRootEv
    919919__ZN7WebCore7Element21boundsInRootViewSpaceEv
    920920__ZN7WebCore7Element9innerTextEv
  • trunk/Source/WebCore/dom/Element.cpp

    r108980 r109084  
    123123Element::~Element()
    124124{
    125     removeShadowRoot();
     125    if (shadowTree())
     126        rareData()->m_shadowTree.clear();
    126127    if (m_attributeMap)
    127128        m_attributeMap->detachFromElement();
     
    11621163        return 0;
    11631164
    1164     return &rareData()->m_shadowTree;
    1165 }
    1166 
    1167 static bool validateShadowRoot(Document* document, ShadowRoot* shadowRoot, ExceptionCode& ec)
    1168 {
    1169     if (!shadowRoot)
    1170         return true;
    1171 
    1172     if (shadowRoot->shadowHost()) {
    1173         ec = HIERARCHY_REQUEST_ERR;
    1174         return false;
    1175     }
    1176 
    1177     if (shadowRoot->document() != document) {
    1178         ec = WRONG_DOCUMENT_ERR;
    1179         return false;
    1180     }
    1181 
    1182     return true;
    1183 }
    1184 
    1185 void Element::setShadowRoot(PassRefPtr<ShadowRoot> shadowRoot, ExceptionCode& ec)
    1186 {
    1187     if (!validateShadowRoot(document(), shadowRoot.get(), ec))
    1188         return;
    1189 
    1190     if (!hasRareData())
    1191         ensureRareData();
    1192 
    1193     removeShadowRoot();
    1194 
    1195     shadowRoot->setShadowHost(this);
    1196     shadowTree()->pushShadowRoot(shadowRoot.get());
    1197 
    1198     if (inDocument())
    1199         shadowRoot->insertedIntoDocument();
    1200     if (attached()) {
    1201         shadowRoot->lazyAttach();
    1202         for (Node* child = firstChild(); child; child = child->nextSibling())
    1203             child->detach();
    1204     }
     1165    return rareData()->m_shadowTree.get();
     1166}
     1167
     1168ShadowTree* Element::ensureShadowTree()
     1169{
     1170    if (ShadowTree* tree = ensureRareData()->m_shadowTree.get())
     1171        return tree;
     1172
     1173    rareData()->m_shadowTree = adoptPtr(new ShadowTree());
     1174    return rareData()->m_shadowTree.get();
    12051175}
    12061176
     
    12111181
    12121182    return ShadowRoot::create(this, ShadowRoot::CreatingUserAgentShadowRoot).get();
    1213 }
    1214 
    1215 void Element::removeShadowRoot()
    1216 {
    1217     if (!hasShadowRoot())
    1218         return;
    1219 
    1220     while (RefPtr<ShadowRoot> oldRoot = shadowTree()->popShadowRoot()) {
    1221         document()->removeFocusedNodeOfSubtree(oldRoot.get());
    1222 
    1223         if (oldRoot->attached())
    1224             oldRoot->detach();
    1225 
    1226         oldRoot->setShadowHost(0);
    1227         document()->adoptIfNeeded(oldRoot.get());
    1228         if (oldRoot->inDocument())
    1229             oldRoot->removedFromDocument();
    1230         else
    1231             oldRoot->removedFromTree(true);
    1232         if (attached()) {
    1233             for (Node* child = firstChild(); child; child = child->nextSibling()) {
    1234                 if (!child->attached())
    1235                     child->lazyAttach();
    1236             }
    1237         }
    1238     }
    12391183}
    12401184
  • trunk/Source/WebCore/dom/Element.h

    r108959 r109084  
    256256    bool hasShadowRoot() const;
    257257    ShadowTree* shadowTree() const;
    258 
    259     // FIXME: These API will be moved to ShadowTree.
    260     // https://bugs.webkit.org/show_bug.cgi?id=78313
    261     void setShadowRoot(PassRefPtr<ShadowRoot>, ExceptionCode&);
     258    ShadowTree* ensureShadowTree();
     259
     260    // FIXME: Remove Element::ensureShadowRoot
     261    // https://bugs.webkit.org/show_bug.cgi?id=77608
    262262    ShadowRoot* ensureShadowRoot();
    263     void removeShadowRoot();
    264263
    265264    virtual const AtomicString& shadowPseudoId() const;
  • trunk/Source/WebCore/dom/ElementRareData.h

    r108959 r109084  
    6565    LayoutSize m_minimumSizeForResizing;
    6666    RefPtr<RenderStyle> m_computedStyle;
    67     ShadowTree m_shadowTree;
    6867    AtomicString m_shadowPseudoId;
    6968
    7069    OwnPtr<DatasetDOMStringMap> m_datasetDOMStringMap;
    7170    OwnPtr<ClassList> m_classList;
     71    OwnPtr<ShadowTree> m_shadowTree;
    7272
    7373    bool m_styleAffectedByEmpty;
     
    9595inline ElementRareData::~ElementRareData()
    9696{
    97     ASSERT(!m_shadowTree.hasShadowRoot());
     97    ASSERT(!m_shadowTree);
    9898}
    9999
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r108959 r109084  
    124124
    125125    ec = 0;
    126     element->setShadowRoot(shadowRoot, ec);
     126    element->ensureShadowTree()->addShadowRoot(element, shadowRoot, ec);
    127127    if (ec)
    128128        return 0;
  • trunk/Source/WebCore/dom/ShadowTree.cpp

    r108993 r109084  
    4545ShadowTree::~ShadowTree()
    4646{
    47     ASSERT(!hasShadowRoot());
    48 }
    49 
    50 void ShadowTree::pushShadowRoot(ShadowRoot* shadowRoot)
    51 {
     47    if (hasShadowRoot())
     48        removeAllShadowRoots();
     49}
     50
     51static bool validateShadowRoot(Document* document, ShadowRoot* shadowRoot, ExceptionCode& ec)
     52{
     53    if (!shadowRoot)
     54        return true;
     55
     56    if (shadowRoot->shadowHost()) {
     57        ec = HIERARCHY_REQUEST_ERR;
     58        return false;
     59    }
     60
     61    if (shadowRoot->document() != document) {
     62        ec = WRONG_DOCUMENT_ERR;
     63        return false;
     64    }
     65
     66    return true;
     67}
     68
     69void ShadowTree::addShadowRoot(Element* shadowHost, PassRefPtr<ShadowRoot> shadowRoot, ExceptionCode& ec)
     70{
     71    ASSERT(shadowHost);
     72    ASSERT(shadowRoot);
    5273#if ENABLE(SHADOW_DOM)
    53     if (!RuntimeEnabledFeatures::multipleShadowSubtreesEnabled())
    54         ASSERT(!hasShadowRoot());
     74    ASSERT(!hasShadowRoot() || RuntimeEnabledFeatures::multipleShadowSubtreesEnabled());
    5575#else
    5676    ASSERT(!hasShadowRoot());
    5777#endif
    5878
    59     m_shadowRoots.push(shadowRoot);
    60     InspectorInstrumentation::didPushShadowRoot(host(), shadowRoot);
    61 }
    62 
    63 ShadowRoot* ShadowTree::popShadowRoot()
     79    if (!validateShadowRoot(shadowHost->document(), shadowRoot.get(), ec))
     80        return;
     81
     82    shadowRoot->setShadowHost(shadowHost);
     83
     84    if (shadowHost->inDocument())
     85        shadowRoot->insertedIntoDocument();
     86    if (shadowHost->attached()) {
     87        shadowRoot->lazyAttach();
     88        detach();
     89        for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling())
     90            child->detach();
     91    }
     92
     93    m_shadowRoots.push(shadowRoot.get());
     94    InspectorInstrumentation::didPushShadowRoot(shadowHost, shadowRoot.get());
     95}
     96
     97void ShadowTree::removeAllShadowRoots()
    6498{
    6599    if (!hasShadowRoot())
    66         return 0;
    67 
    68     InspectorInstrumentation::willPopShadowRoot(host(), m_shadowRoots.head());
    69     return m_shadowRoots.removeHead();
     100        return;
     101
     102    Element* shadowHost = host();
     103
     104    while (RefPtr<ShadowRoot> oldRoot = m_shadowRoots.removeHead()) {
     105        InspectorInstrumentation::willPopShadowRoot(shadowHost, oldRoot.get());
     106        shadowHost->document()->removeFocusedNodeOfSubtree(oldRoot.get());
     107
     108        if (oldRoot->attached())
     109            oldRoot->detach();
     110
     111        oldRoot->setShadowHost(0);
     112        shadowHost->document()->adoptIfNeeded(oldRoot.get());
     113        if (oldRoot->inDocument())
     114            oldRoot->removedFromDocument();
     115        else
     116            oldRoot->removedFromTree(true);
     117    }
     118
     119    if (shadowHost->attached()) {
     120        for (Node* child = shadowHost->firstChild(); child; child = child->nextSibling()) {
     121            if (!child->attached())
     122                child->lazyAttach();
     123        }
     124    }
    70125}
    71126
  • trunk/Source/WebCore/dom/ShadowTree.h

    r108959 r109084  
    2828#define ShadowTree_h
    2929
     30#include "ExceptionCode.h"
    3031#include "ShadowRoot.h"
    3132#include <wtf/DoublyLinkedList.h>
     
    5051    ShadowRoot* oldestShadowRoot() const;
    5152
    52     void pushShadowRoot(ShadowRoot*);
    53     ShadowRoot* popShadowRoot();
     53    void addShadowRoot(Element* shadowHost, PassRefPtr<ShadowRoot>, ExceptionCode&);
     54    void removeAllShadowRoots();
    5455
    5556    void insertedIntoDocument();
  • trunk/Source/WebCore/testing/Internals.cpp

    r108959 r109084  
    249249    }
    250250
    251     host->removeShadowRoot();
     251    if (host->hasShadowRoot())
     252        host->shadowTree()->removeAllShadowRoots();
    252253}
    253254
  • trunk/Source/WebKit2/ChangeLog

    r109055 r109084  
     12012-02-27  Shinya Kawanaka  <shinyak@chromium.org>
     2
     3        Element::removeShadowRoot() and setShadowRoot() should be moved into ShadowTree.
     4        https://bugs.webkit.org/show_bug.cgi?id=78313
     5
     6        Reviewed by Hajime Morita.
     7
     8        * win/WebKit2.def:
     9        * win/WebKit2CFLite.def:
     10
    1112012-02-27  Brady Eidson  <beidson@apple.com>
    212
  • trunk/Source/WebKit2/win/WebKit2.def

    r108959 r109084  
    177177        ?paintControlTints@FrameView@WebCore@@AAEXXZ
    178178        ?rangeFromLocationAndLength@TextIterator@WebCore@@SA?AV?$PassRefPtr@VRange@WebCore@@@WTF@@PAVElement@2@HH_N@Z
    179         ?removeShadowRoot@Element@WebCore@@QAEXXZ
     179        ?removeAllShadowRoots@ShadowTree@WebCore@@QAEXXZ
    180180        ?scriptExecutionContext@JSDOMGlobalObject@WebCore@@QBEPAVScriptExecutionContext@2@XZ
    181181        ?scrollElementToRect@FrameView@WebCore@@QAEXPAVElement@2@ABVIntRect@2@@Z
  • trunk/Source/WebKit2/win/WebKit2CFLite.def

    r108959 r109084  
    170170        ?paintControlTints@FrameView@WebCore@@AAEXXZ
    171171        ?rangeFromLocationAndLength@TextIterator@WebCore@@SA?AV?$PassRefPtr@VRange@WebCore@@@WTF@@PAVElement@2@HH_N@Z
    172         ?removeShadowRoot@Element@WebCore@@QAEXXZ
     172        ?removeAllShadowRoots@ShadowTree@WebCore@@QAEXXZ
    173173        ?scriptExecutionContext@JSDOMGlobalObject@WebCore@@QBEPAVScriptExecutionContext@2@XZ
    174174        ?scrollElementToRect@FrameView@WebCore@@QAEXPAVElement@2@ABVIntRect@2@@Z
  • trunk/Source/autotools/symbols.filter

    r108959 r109084  
    4343_ZN7WebCore10ClientRectC1ERKNS_7IntRectE;
    4444_ZN7WebCore10ShadowRoot6createEPNS_7ElementERi;
     45_ZN7WebCore10ShadowTree20removeAllShadowRootsEv;
    4546_ZN7WebCore11EventTarget17toGeneratedStreamEv;
    4647_ZN7WebCore11EventTarget8toStreamEv;
     
    6768_ZN7WebCore6JSNode6s_infoE;
    6869_ZN7WebCore6toNodeEN3JSC7JSValueE;
    69 _ZN7WebCore7Element16removeShadowRootEv;
    7070_ZN7WebCore7toRangeEN3JSC7JSValueE;
    7171_ZN7WebCore9JSElement10putVirtualEPN3JSC9ExecStateERKNS1_10IdentifierENS1_7JSValueERNS1_15PutPropertySlotE;
Note: See TracChangeset for help on using the changeset viewer.