Changeset 84394 in webkit


Ignore:
Timestamp:
Apr 20, 2011 10:25:33 AM (13 years ago)
Author:
rolandsteiner@chromium.org
Message:

2011-04-19 Roland Steiner <rolandsteiner@chromium.org>

Reviewed by Dimitri Glazkov.

Bug 52963 - Enable O(1) access to root from any node in shadow DOM subtree
https://bugs.webkit.org/show_bug.cgi?id=52963

.) Change base class of ShadowRoot from DocumentFragment to TreeScope.
.) Re-enable tree scope handling in Node (had ASSERT_NOT_REACHED, etc.).
.) Merged setTreeScope() with setTreeScopeRecursively()
.) Call setTreeScopeRecursively in DOM manipulation functions where applicable.
.) Adapt JavaScript Node wrappers (temporary code - see https://bugs.webkit.org/show_bug.cgi?id=58704).

No new tests. (refactoring)

  • bindings/js/JSNodeCustom.cpp: (WebCore::createWrapperInline):
  • bindings/v8/custom/V8NodeCustom.cpp: (WebCore::toV8Slow):
  • dom/ContainerNode.cpp: (WebCore::ContainerNode::takeAllChildrenFrom): (WebCore::ContainerNode::removeBetween): (WebCore::ContainerNode::removeChildren): (WebCore::ContainerNode::parserAddChild):
  • dom/Document.cpp: (WebCore::Document::Document): (WebCore::Document::~Document): (WebCore::Document::setDocType):
  • dom/Element.h:
  • dom/Node.cpp: (WebCore::Node::treeScope): (WebCore::Node::setTreeScopeRecursively):
  • dom/Node.h: (WebCore::Node::document):
  • dom/ShadowRoot.cpp: (WebCore::ShadowRoot::ShadowRoot): (WebCore::ShadowRoot::~ShadowRoot): (WebCore::ShadowRoot::nodeType): (WebCore::ShadowRoot::cloneNode): (WebCore::ShadowRoot::childTypeAllowed):
  • dom/ShadowRoot.h: (WebCore::toShadowRoot):
  • dom/TreeScope.cpp: (WebCore::TreeScope::TreeScope): (WebCore::TreeScope::setParentTreeScope):
  • dom/TreeScope.h:
  • rendering/RenderSlider.cpp:
Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r84389 r84394  
     12011-04-19  Roland Steiner  <rolandsteiner@chromium.org>
     2
     3        Reviewed by Dimitri Glazkov.
     4
     5        Bug 52963 - Enable O(1) access to root from any node in shadow DOM subtree
     6        https://bugs.webkit.org/show_bug.cgi?id=52963
     7
     8        .) Change base class of ShadowRoot from DocumentFragment to TreeScope.
     9        .) Re-enable tree scope handling in Node (had ASSERT_NOT_REACHED, etc.).
     10        .) Merged setTreeScope() with setTreeScopeRecursively()
     11        .) Call setTreeScopeRecursively in DOM manipulation functions where applicable.
     12        .) Adapt JavaScript Node wrappers (temporary code - see https://bugs.webkit.org/show_bug.cgi?id=58704).
     13
     14        No new tests. (refactoring)
     15
     16        * bindings/js/JSNodeCustom.cpp:
     17        (WebCore::createWrapperInline):
     18        * bindings/v8/custom/V8NodeCustom.cpp:
     19        (WebCore::toV8Slow):
     20        * dom/ContainerNode.cpp:
     21        (WebCore::ContainerNode::takeAllChildrenFrom):
     22        (WebCore::ContainerNode::removeBetween):
     23        (WebCore::ContainerNode::removeChildren):
     24        (WebCore::ContainerNode::parserAddChild):
     25        * dom/Document.cpp:
     26        (WebCore::Document::Document):
     27        (WebCore::Document::~Document):
     28        (WebCore::Document::setDocType):
     29        * dom/Element.h:
     30        * dom/Node.cpp:
     31        (WebCore::Node::treeScope):
     32        (WebCore::Node::setTreeScopeRecursively):
     33        * dom/Node.h:
     34        (WebCore::Node::document):
     35        * dom/ShadowRoot.cpp:
     36        (WebCore::ShadowRoot::ShadowRoot):
     37        (WebCore::ShadowRoot::~ShadowRoot):
     38        (WebCore::ShadowRoot::nodeType):
     39        (WebCore::ShadowRoot::cloneNode):
     40        (WebCore::ShadowRoot::childTypeAllowed):
     41        * dom/ShadowRoot.h:
     42        (WebCore::toShadowRoot):
     43        * dom/TreeScope.cpp:
     44        (WebCore::TreeScope::TreeScope):
     45        (WebCore::TreeScope::setParentTreeScope):
     46        * dom/TreeScope.h:
     47        * rendering/RenderSlider.cpp:
     48
    1492011-04-20  Vsevolod Vlasov  <vsevik@chromium.org>
    250
  • trunk/Source/WebCore/bindings/js/JSNodeCustom.cpp

    r84194 r84394  
    6464#include "ProcessingInstruction.h"
    6565#include "RegisteredEventListener.h"
     66#include "ShadowRoot.h"
    6667#include "StyleSheet.h"
    6768#include "StyledElement.h"
     
    291292            break;
    292293        case Node::DOCUMENT_FRAGMENT_NODE:
    293             wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, DocumentFragment, node);
     294            // FIXME: remove 'if' once ShadowRoot gets its own node type (see bug 58704)
     295            if (node->isShadowBoundary())
     296                wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, Node, node);
     297            else
     298                wrapper = CREATE_DOM_NODE_WRAPPER(exec, globalObject, DocumentFragment, node);
    294299            break;
    295300        case Node::ENTITY_REFERENCE_NODE:
  • trunk/Source/WebCore/bindings/v8/custom/V8NodeCustom.cpp

    r74646 r84394  
    3434#include "Document.h"
    3535#include "EventListener.h"
     36#include "ShadowRoot.h"
    3637
    3738#include "V8AbstractEventListener.h"
     
    163164        return toV8(static_cast<DocumentType*>(impl), forceNewObject);
    164165    case Node::DOCUMENT_FRAGMENT_NODE:
     166        // FIXME: remove 'if' once ShadowRoot gets its own node type (see bug 58704)
     167        if (impl->isShadowBoundary())
     168            return toV8(static_cast<ShadowRoot*>(impl), forceNewObject);
    165169        return toV8(static_cast<DocumentFragment*>(impl), forceNewObject);
    166170    case Node::NOTATION_NODE:
  • trunk/Source/WebCore/dom/ContainerNode.cpp

    r84251 r84394  
    9191        ASSERT(!ec);
    9292        parserAddChild(child.get());
     93        // FIXME: Together with adoptNode above, the tree scope might get updated recursively twice
     94        // (if the document changed or oldParent was in a shadow tree, AND *this is in a shadow tree).
     95        // Can we do better?
     96        child->setTreeScopeRecursively(treeScope());
    9397        if (attached() && !child->attached())
    9498            child->attach();
     
    482486    oldChild->setParent(0);
    483487
     488    oldChild->setTreeScopeRecursively(document());
     489
    484490    allowEventDispatch();
    485491}
     
    531537        n->setNextSibling(0);
    532538        n->setParent(0);
     539        n->setTreeScopeRecursively(document());
    533540
    534541        m_firstChild = next;
     
    649656    // FIXME: This method should take a PassRefPtr.
    650657    appendChildToContainer<Node, ContainerNode>(newChild.get(), this);
     658    newChild->setTreeScopeRecursively(treeScope());
     659   
    651660    allowEventDispatch();
    652661
  • trunk/Source/WebCore/dom/Document.cpp

    r84251 r84394  
    378378
    379379Document::Document(Frame* frame, const KURL& url, bool isXHTML, bool isHTML)
    380     : TreeScope(this)
     380    : TreeScope(0)
    381381    , m_guardRefCount(0)
    382382    , m_compatibilityMode(NoQuirksMode)
     
    514514    ASSERT(!m_styleRecalcTimer.isActive());
    515515    ASSERT(!m_parentTreeScope);
     516    ASSERT(!m_guardRefCount);
    516517
    517518    m_scriptRunner.clear();
     
    671672    m_docType = docType;
    672673    if (m_docType)
    673         m_docType->setTreeScope(this);
     674        m_docType->setTreeScopeRecursively(this);
    674675}
    675676
  • trunk/Source/WebCore/dom/Element.h

    r84251 r84394  
    4040class ElementRareData;
    4141class IntSize;
     42class ShadowRoot;
    4243class WebKitAnimationList;
    4344
     
    230231    virtual void recalcStyle(StyleChange = NoChange);
    231232
     233    // FIXME: Make these return a proper ShadowRoot* (bug 58703).
    232234    ContainerNode* shadowRoot() const;
    233235    ContainerNode* ensureShadowRoot();
  • trunk/Source/WebCore/dom/Node.cpp

    r84371 r84394  
    7777#include "ScopedEventQueue.h"
    7878#include "SelectorNodeList.h"
     79#include "ShadowRoot.h"
    7980#include "StaticNodeList.h"
    8081#include "TagNodeList.h"
     
    468469TreeScope* Node::treeScope() const
    469470{
     471    // FIXME: Using m_document directly is not good -> see comment with document() in the header file.
    470472    if (!hasRareData())
    471         return document();
     473        return m_document;
    472474    TreeScope* scope = rareData()->treeScope();
    473     // FIXME: Until we land shadow scopes, there should be no non-document scopes.
    474     ASSERT(!scope);
    475     return scope ? scope : document();
    476 }
    477 
    478 void Node::setTreeScope(TreeScope* newTreeScope)
    479 {
    480     ASSERT(!isDocumentNode());
     475    return scope ? scope : m_document;
     476}
     477
     478void Node::setTreeScopeRecursively(TreeScope* newTreeScope, bool includeRoot)
     479{
     480    ASSERT(this);
     481    ASSERT(!includeRoot || !isDocumentNode());
    481482    ASSERT(newTreeScope);
    482     ASSERT(!inDocument() || treeScope() == newTreeScope);
    483 
    484     if (newTreeScope->isDocumentNode()) {
    485         if (hasRareData())
    486             rareData()->setTreeScope(0);
    487         // Setting the new document scope will be handled implicitly
    488         // by setDocument() below.
    489     } else {
    490         // FIXME: Until we land shadow scopes, this branch should be inert.
    491         ASSERT_NOT_REACHED();
    492         ensureRareData()->setTreeScope(newTreeScope);
    493     }
    494 
    495     setDocument(newTreeScope->document());
    496 }
    497 
    498 void Node::setTreeScopeRecursively(TreeScope* newTreeScope)
    499 {
    500     ASSERT(!isDocumentNode());
    501     ASSERT(newTreeScope);
    502     if (treeScope() == newTreeScope)
     483    ASSERT(!m_deletionHasBegun);
     484
     485    TreeScope* currentTreeScope = treeScope();
     486    if (currentTreeScope == newTreeScope)
    503487        return;
    504488
     
    512496        currentDocument->incDOMTreeVersion();
    513497
    514     for (Node* node = this; node; node = node->traverseNextNode(this)) {
    515         node->setTreeScope(newTreeScope);
    516         // FIXME: Once shadow scopes are landed, update parent scope, etc.
     498    for (Node* node = includeRoot ? this : traverseNextNode(this); node; node = node->traverseNextNode(this)) {
     499        if (newTreeScope == newDocument) {
     500            if (node->hasRareData())
     501                node->rareData()->setTreeScope(0);
     502            // Setting the new document tree scope will be handled implicitly
     503            // by setDocument() below.
     504        } else
     505            node->ensureRareData()->setTreeScope(newTreeScope);
     506
     507        node->setDocument(newDocument);
     508
     509        if (!node->isElementNode())
     510            continue;
     511        // FIXME: Remove toShadowRoot() once shadowRoot() returns a proper ShadowRoot* (bug 58703).
     512        if (ShadowRoot* shadowRoot = toShadowRoot(toElement(node)->shadowRoot())) {
     513            shadowRoot->setParentTreeScope(newTreeScope);
     514            if (currentDocument != newDocument)
     515                shadowRoot->setDocumentRecursively(newDocument);
     516        }
    517517    }
    518518}
  • trunk/Source/WebCore/dom/Node.h

    r84309 r84394  
    360360    {
    361361        ASSERT(this);
     362        // FIXME: below ASSERT is useful, but prevents the use of document() in the constructor or destructor
     363        // due to the virtual function call to nodeType().
    362364        ASSERT(m_document || (nodeType() == DOCUMENT_TYPE_NODE && !inDocument()));
    363365        return m_document;
     
    366368    TreeScope* treeScope() const;
    367369
    368     // Do not use this method to change the scope of a node until after the node has been
    369     // removed from its previous scope. Do not use to change documents.
    370     void setTreeScope(TreeScope*);
    371 
    372370    // Used by the basic DOM methods (e.g., appendChild()).
    373     void setTreeScopeRecursively(TreeScope*);
     371    void setTreeScopeRecursively(TreeScope*, bool includeRoot = true);
    374372
    375373    // Returns true if this node is associated with a document and is in its associated document's
  • trunk/Source/WebCore/dom/ShadowRoot.cpp

    r84251 r84394  
    2828#include "ShadowRoot.h"
    2929
     30#include "Document.h"
     31#include "NodeRareData.h"
     32
    3033namespace WebCore {
    3134
    3235ShadowRoot::ShadowRoot(Document* document)
    33     : DocumentFragment(document)
     36    : TreeScope(document)
    3437{
    3538    ASSERT(document);
     39   
     40    // Assume document as parent scope.
     41    setParentTreeScope(document);
     42    // Shadow tree scopes have the scope pointer point to themselves.
     43    // This way, direct children will receive the correct scope pointer.
     44    ensureRareData()->setTreeScope(this);
     45}
     46
     47ShadowRoot::~ShadowRoot()
     48{
    3649}
    3750
     
    3952{
    4053    return "#shadow-root";
     54}
     55
     56Node::NodeType ShadowRoot::nodeType() const
     57{
     58    // FIXME: Decide correct node type (bug 58704).
     59    return DOCUMENT_FRAGMENT_NODE;
     60}
     61
     62PassRefPtr<Node> ShadowRoot::cloneNode(bool)
     63{
     64    // ShadowRoot should not be arbitrarily cloned.
     65    return 0;
     66}
     67
     68bool ShadowRoot::childTypeAllowed(NodeType type) const
     69{
     70    switch (type) {
     71    case ELEMENT_NODE:
     72    case PROCESSING_INSTRUCTION_NODE:
     73    case COMMENT_NODE:
     74    case TEXT_NODE:
     75    case CDATA_SECTION_NODE:
     76    case ENTITY_REFERENCE_NODE:
     77        return true;
     78    default:
     79        return false;
     80    }
    4181}
    4282
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r84251 r84394  
    2828#define ShadowRoot_h
    2929
    30 #include "DocumentFragment.h"
     30#include "TreeScope.h"
    3131
    3232namespace WebCore {
     
    3434class Document;
    3535
    36 class ShadowRoot : public DocumentFragment {
     36class ShadowRoot : public TreeScope {
    3737public:
    3838    static PassRefPtr<ShadowRoot> create(Document*);
     
    4343private:
    4444    ShadowRoot(Document*);
     45    virtual ~ShadowRoot();
     46
    4547    virtual String nodeName() const;
     48    virtual NodeType nodeType() const;
     49    virtual PassRefPtr<Node> cloneNode(bool deep);
     50    virtual bool childTypeAllowed(NodeType) const;
    4651};
    4752
     
    5156}
    5257
     58inline ShadowRoot* toShadowRoot(Node* node)
     59{
     60    ASSERT(!node || node->isShadowBoundary());
     61    return static_cast<ShadowRoot*>(node);
     62}
     63
    5364} // namespace
    5465
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r84251 r84394  
    3737using namespace HTMLNames;
    3838
    39 TreeScope::TreeScope(Document* document, ConstructionType constructionType)
    40     : ContainerNode(0, constructionType)
     39TreeScope::TreeScope(Document* document)
     40    : ContainerNode(document)
    4141    , m_parentTreeScope(0)
    4242    , m_accessKeyMapValid(false)
    4343    , m_numNodeListCaches(0)
    4444{
    45     m_document = document;
    46     if (document != this) {
    47         // Assume document as parent scope
    48         m_parentTreeScope = document;
    49         // FIXME: This branch should be inert until shadow scopes are landed.
    50         ASSERT_NOT_REACHED();
    51     }
    5245}
    5346
     
    7063    ASSERT(!isDocumentNode());
    7164    // Every scope other than document needs a parent scope.
    72     ASSERT(m_parentTreeScope);
    7365    ASSERT(newParentScope);
    7466
  • trunk/Source/WebCore/dom/TreeScope.h

    r84251 r84394  
    4040public:
    4141    TreeScope* parentTreeScope() const { return m_parentTreeScope; }
     42    void setParentTreeScope(TreeScope*);
    4243
    4344    Element* getElementById(const AtomicString&) const;
     
    6667
    6768protected:
    68     TreeScope(Document*, ConstructionType = CreateContainer);
    69 
     69    TreeScope(Document*);
    7070    virtual ~TreeScope();
    7171
    7272    void destroyTreeScopeData();
    73 
    74     void setParentTreeScope(TreeScope*);
    7573
    7674private:
  • trunk/Source/WebCore/rendering/RenderSlider.cpp

    r84251 r84394  
    3838#include "RenderTheme.h"
    3939#include "RenderView.h"
    40 #include "ShadowElement.h"
     40#include "ShadowRoot.h"
    4141#include "SliderThumbElement.h"
    4242#include "StepRange.h"
Note: See TracChangeset for help on using the changeset viewer.