Changeset 164251 in webkit


Ignore:
Timestamp:
Feb 17, 2014 3:29:31 PM (10 years ago)
Author:
Antti Koivisto
Message:

Make TreeScope::rootNode return a reference
https://bugs.webkit.org/show_bug.cgi?id=128934

Reviewed by Andreas Kling.

It is never null.

  • css/ElementRuleCollector.cpp:

(WebCore::ElementRuleCollector::collectMatchingRules):

  • dom/ContainerNode.h:

(WebCore::Node::isTreeScope):

  • dom/Document.cpp:

(WebCore::Document::buildAccessKeyMap):

  • dom/DocumentOrderedMap.cpp:

(WebCore::DocumentOrderedMap::add):
(WebCore::DocumentOrderedMap::get):
(WebCore::DocumentOrderedMap::getAllElementsById):

  • dom/EventDispatcher.cpp:

(WebCore::EventRelatedNodeResolver::moveToParentOrShadowHost):
(WebCore::eventTargetRespectingTargetRules):
(WebCore::shouldEventCrossShadowBoundary):

  • dom/Node.cpp:

(WebCore::Node::containingShadowRoot):
(WebCore::Node::removedFrom):

  • dom/ShadowRoot.h:

(WebCore::isShadowRoot):

  • dom/TreeScope.h:

(WebCore::TreeScope::rootNode):

  • page/DOMSelection.cpp:

(WebCore::DOMSelection::DOMSelection):

  • page/DragController.cpp:

(WebCore::asFileInput):

  • page/FocusController.cpp:

(WebCore::FocusNavigationScope::rootNode):

Location:
trunk/Source/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r164249 r164251  
     12014-02-17  Antti Koivisto  <antti@apple.com>
     2
     3        Make TreeScope::rootNode return a reference
     4        https://bugs.webkit.org/show_bug.cgi?id=128934
     5
     6        Reviewed by Andreas Kling.
     7
     8        It is never null.
     9
     10        * css/ElementRuleCollector.cpp:
     11        (WebCore::ElementRuleCollector::collectMatchingRules):
     12        * dom/ContainerNode.h:
     13        (WebCore::Node::isTreeScope):
     14        * dom/Document.cpp:
     15        (WebCore::Document::buildAccessKeyMap):
     16        * dom/DocumentOrderedMap.cpp:
     17        (WebCore::DocumentOrderedMap::add):
     18        (WebCore::DocumentOrderedMap::get):
     19        (WebCore::DocumentOrderedMap::getAllElementsById):
     20        * dom/EventDispatcher.cpp:
     21        (WebCore::EventRelatedNodeResolver::moveToParentOrShadowHost):
     22        (WebCore::eventTargetRespectingTargetRules):
     23        (WebCore::shouldEventCrossShadowBoundary):
     24        * dom/Node.cpp:
     25        (WebCore::Node::containingShadowRoot):
     26        (WebCore::Node::removedFrom):
     27        * dom/ShadowRoot.h:
     28        (WebCore::isShadowRoot):
     29        * dom/TreeScope.h:
     30        (WebCore::TreeScope::rootNode):
     31        * page/DOMSelection.cpp:
     32        (WebCore::DOMSelection::DOMSelection):
     33        * page/DragController.cpp:
     34        (WebCore::asFileInput):
     35        * page/FocusController.cpp:
     36        (WebCore::FocusNavigationScope::rootNode):
     37
    1382014-02-17  Chris Fleizach  <cfleizach@apple.com>
    239
  • trunk/Source/WebCore/css/ElementRuleCollector.cpp

    r164202 r164251  
    156156#endif
    157157    // Only match UA rules in shadow tree.
    158     if (!MatchingUARulesScope::isMatchingUARules() && m_element.treeScope().rootNode()->isShadowRoot())
     158    if (!MatchingUARulesScope::isMatchingUARules() && m_element.treeScope().rootNode().isShadowRoot())
    159159        return;
    160160
  • trunk/Source/WebCore/dom/ContainerNode.h

    r164248 r164251  
    237237inline bool Node::isTreeScope() const
    238238{
    239     return treeScope().rootNode() == this;
     239    return &treeScope().rootNode() == this;
    240240}
    241241
  • trunk/Source/WebCore/dom/Document.cpp

    r164248 r164251  
    713713{
    714714    ASSERT(scope);
    715     ContainerNode* rootNode = scope->rootNode();
    716     for (auto& element : descendantsOfType<Element>(*rootNode)) {
     715    for (auto& element : descendantsOfType<Element>(scope->rootNode())) {
    717716        const AtomicString& accessKey = element.fastGetAttribute(accesskeyAttr);
    718717        if (!accessKey.isEmpty())
  • trunk/Source/WebCore/dom/DocumentOrderedMap.cpp

    r164195 r164251  
    9292    UNUSED_PARAM(treeScope);
    9393    ASSERT_WITH_SECURITY_IMPLICATION(element.isInTreeScope());
    94     ASSERT_WITH_SECURITY_IMPLICATION(treeScope.rootNode()->containsIncludingShadowDOM(&element));
     94    ASSERT_WITH_SECURITY_IMPLICATION(treeScope.rootNode().containsIncludingShadowDOM(&element));
    9595    if (!element.isInTreeScope())
    9696        return;
     
    145145
    146146    // We know there's at least one node that matches; iterate to find the first one.
    147     for (auto& element : descendantsOfType<Element>(*scope.rootNode())) {
     147    for (auto& element : descendantsOfType<Element>(scope.rootNode())) {
    148148        if (!keyMatches(key, element))
    149149            continue;
     
    212212    if (entry.orderedList.isEmpty()) {
    213213        entry.orderedList.reserveCapacity(entry.count);
    214         auto elementDescandents = descendantsOfType<Element>(*scope.rootNode());
     214        auto elementDescandents = descendantsOfType<Element>(scope.rootNode());
    215215        auto it = entry.element ? elementDescandents.beginAt(*entry.element) : elementDescandents.begin();
    216216        auto end = elementDescandents.end();
  • trunk/Source/WebCore/dom/EventDispatcher.cpp

    r163440 r164251  
    144144
    145145        if (m_currentTreeScope) {
    146             ASSERT(m_currentTreeScope->rootNode()->isShadowRoot());
    147             ASSERT(&newTarget == toShadowRoot(m_currentTreeScope->rootNode())->hostElement());
     146            ASSERT(m_currentTreeScope->rootNode().isShadowRoot());
     147            ASSERT(&newTarget == toShadowRoot(m_currentTreeScope->rootNode()).hostElement());
    148148            ASSERT(m_currentTreeScope->parentTreeScope() == &newTreeScope);
    149149        }
     
    185185    // Spec: The event handling for the non-exposed tree works as if the referenced element had been textually included
    186186    // as a deeply cloned child of the 'use' element, except that events are dispatched to the SVGElementInstance objects
    187     Node* rootNode = referenceNode.treeScope().rootNode();
    188     Element* shadowHostElement = rootNode->isShadowRoot() ? toShadowRoot(rootNode)->hostElement() : 0;
     187    auto& rootNode = referenceNode.treeScope().rootNode();
     188    Element* shadowHostElement = rootNode.isShadowRoot() ? toShadowRoot(rootNode).hostElement() : nullptr;
    189189    // At this time, SVG nodes are not supported in non-<use> shadow trees.
    190190    if (!shadowHostElement || !shadowHostElement->hasTagName(SVGNames::useTag))
     
    367367    // See https://bugs.webkit.org/show_bug.cgi?id=52195 for details.
    368368    const AtomicString& eventType = event.type();
    369     bool targetIsInShadowRoot = targetNode && targetNode->treeScope().rootNode() == &shadowRoot;
     369    bool targetIsInShadowRoot = targetNode && &targetNode->treeScope().rootNode() == &shadowRoot;
    370370    return !targetIsInShadowRoot
    371371        || !(eventType == eventNames().abortEvent
  • trunk/Source/WebCore/dom/Node.cpp

    r164248 r164251  
    952952ShadowRoot* Node::containingShadowRoot() const
    953953{
    954     ContainerNode* root = treeScope().rootNode();
    955     return root && root->isShadowRoot() ? toShadowRoot(root) : 0;
     954    ContainerNode& root = treeScope().rootNode();
     955    return root.isShadowRoot() ? toShadowRoot(&root) : nullptr;
    956956}
    957957
     
    10121012    if (insertionPoint.inDocument())
    10131013        clearFlag(InDocumentFlag);
    1014     if (isInShadowTree() && !treeScope().rootNode()->isShadowRoot())
     1014    if (isInShadowTree() && !treeScope().rootNode().isShadowRoot())
    10151015        clearFlag(IsInShadowTreeFlag);
    10161016}
  • trunk/Source/WebCore/dom/ShadowRoot.h

    r164195 r164251  
    9696}
    9797
    98 inline const ShadowRoot* toShadowRoot(const Node* node)
    99 {
    100     ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isShadowRoot());
    101     return static_cast<const ShadowRoot*>(node);
    102 }
     98inline bool isShadowRoot(const Node& node) { return node.isShadowRoot(); }
    10399
    104 inline ShadowRoot* toShadowRoot(Node* node)
    105 {
    106     return const_cast<ShadowRoot*>(toShadowRoot(static_cast<const Node*>(node)));
    107 }
     100NODE_TYPE_CASTS(ShadowRoot)
    108101
    109102inline ShadowRoot* Node::shadowRoot() const
  • trunk/Source/WebCore/dom/TreeScope.cpp

    r164195 r164251  
    9393{
    9494    // A document node cannot be re-parented.
    95     ASSERT(!rootNode()->isDocumentNode());
     95    ASSERT(!m_rootNode.isDocumentNode());
    9696    // Every scope other than document needs a parent scope.
    9797    ASSERT(newParentScope);
     
    199199    if (name.isEmpty())
    200200        return nullptr;
    201     if (rootNode()->document().isHTMLDocument()) {
     201    if (m_rootNode.document().isHTMLDocument()) {
    202202        AtomicString lowercasedName = name.lower();
    203203        return m_imageMapsByName->getElementByLowercasedMapName(*lowercasedName.impl(), *this);
     
    240240Element* TreeScope::elementFromPoint(int x, int y) const
    241241{
    242     Node* node = nodeFromPoint(&rootNode()->document(), x, y);
     242    Node* node = nodeFromPoint(&m_rootNode.document(), x, y);
    243243    while (node && !node->isElementNode())
    244244        node = node->parentNode();
     
    269269        m_labelsByForAttribute = std::make_unique<DocumentOrderedMap>();
    270270
    271         for (auto& label : descendantsOfType<HTMLLabelElement>(*rootNode())) {
     271        for (auto& label : descendantsOfType<HTMLLabelElement>(m_rootNode)) {
    272272            const AtomicString& forValue = label.fastGetAttribute(forAttr);
    273273            if (!forValue.isEmpty())
     
    281281DOMSelection* TreeScope::getSelection() const
    282282{
    283     if (!rootNode()->document().frame())
     283    if (!m_rootNode.document().frame())
    284284        return nullptr;
    285285
     
    287287        return m_selection.get();
    288288
    289     if (this != &rootNode()->document())
    290         return rootNode()->document().getSelection();
    291 
    292     m_selection = DOMSelection::create(&rootNode()->document());
     289    if (this != &m_rootNode.document())
     290        return m_rootNode.document().getSelection();
     291
     292    m_selection = DOMSelection::create(&m_rootNode.document());
    293293    return m_selection.get();
    294294}
     
    300300    if (Element* element = getElementById(name))
    301301        return element;
    302     for (auto& anchor : descendantsOfType<HTMLAnchorElement>(*rootNode())) {
    303         if (rootNode()->document().inQuirksMode()) {
     302    for (auto& anchor : descendantsOfType<HTMLAnchorElement>(m_rootNode)) {
     303        if (m_rootNode.document().inQuirksMode()) {
    304304            // Quirks mode, case insensitive comparison of names.
    305305            if (equalIgnoringCase(anchor.name(), name))
     
    336336Element* TreeScope::focusedElement()
    337337{
    338     Document& document = rootNode()->document();
     338    Document& document = m_rootNode.document();
    339339    Element* element = document.focusedElement();
    340340
     
    345345    TreeScope* treeScope = &element->treeScope();
    346346    while (treeScope != this && treeScope != &document) {
    347         element = toShadowRoot(treeScope->rootNode())->hostElement();
     347        element = toShadowRoot(treeScope->rootNode()).hostElement();
    348348        treeScope = &element->treeScope();
    349349    }
  • trunk/Source/WebCore/dom/TreeScope.h

    r164195 r164251  
    9696    void adoptIfNeeded(Node*);
    9797
    98     ContainerNode* rootNode() const { return &m_rootNode; }
     98    ContainerNode& rootNode() const { return m_rootNode; }
    9999
    100100    IdTargetObserverRegistry& idTargetObserverRegistry() const { return *m_idTargetObserverRegistry.get(); }
  • trunk/Source/WebCore/editing/VisibleSelection.cpp

    r163712 r164251  
    486486    }
    487487
    488     if (Node* lastChild = treeScope.rootNode()->lastChild())
     488    if (Node* lastChild = treeScope.rootNode().lastChild())
    489489        return positionAfterNode(lastChild);
    490490
     
    504504    }
    505505
    506     if (Node* firstChild = treeScope.rootNode()->firstChild())
     506    if (Node* firstChild = treeScope.rootNode().firstChild())
    507507        return positionBeforeNode(firstChild);
    508508
  • trunk/Source/WebCore/page/DOMSelection.cpp

    r164188 r164251  
    5858
    5959DOMSelection::DOMSelection(const TreeScope* treeScope)
    60     : DOMWindowProperty(treeScope->rootNode()->document().frame())
     60    : DOMWindowProperty(treeScope->rootNode().document().frame())
    6161    , m_treeScope(treeScope)
    6262{
  • trunk/Source/WebCore/page/DragController.cpp

    r163739 r164251  
    273273
    274274    // If this is a button inside of the a file input, move up to the file input.
    275     if (inputElement && inputElement->isTextButton() && inputElement->treeScope().rootNode()->isShadowRoot())
    276         inputElement = toShadowRoot(inputElement->treeScope().rootNode())->hostElement()->toInputElement();
     275    if (inputElement && inputElement->isTextButton() && inputElement->treeScope().rootNode().isShadowRoot())
     276        inputElement = toShadowRoot(inputElement->treeScope().rootNode()).hostElement()->toInputElement();
    277277
    278278    return inputElement && inputElement->isFileUpload() ? inputElement : 0;
  • trunk/Source/WebCore/page/FocusController.cpp

    r163524 r164251  
    7575ContainerNode* FocusNavigationScope::rootNode() const
    7676{
    77     return m_rootTreeScope->rootNode();
     77    return &m_rootTreeScope->rootNode();
    7878}
    7979
  • trunk/Source/WebCore/svg/SVGElement.cpp

    r164123 r164251  
    948948    // Walk up the tree, to find out whether we're inside a <use> shadow tree, to find the right title.
    949949    if (isInShadowTree()) {
    950         Element* shadowHostElement = toShadowRoot(treeScope().rootNode())->hostElement();
     950        Element* shadowHostElement = toShadowRoot(treeScope().rootNode()).hostElement();
    951951        // At this time, SVG nodes are not allowed in non-<use> shadow trees, so any shadow root we do
    952952        // have should be a use. The assert and following test is here to catch future shadow DOM changes
  • trunk/Source/WebCore/testing/Internals.cpp

    r164245 r164251  
    366366    if (!node) {
    367367        ec = INVALID_ACCESS_ERR;
    368         return 0;
    369     }
    370 
    371     return node->treeScope().rootNode();
     368        return nullptr;
     369    }
     370
     371    return &node->treeScope().rootNode();
    372372}
    373373
     
    376376    if (!node) {
    377377        ec = INVALID_ACCESS_ERR;
    378         return 0;
     378        return nullptr;
    379379    }
    380380    const TreeScope* parentTreeScope = node->treeScope().parentTreeScope();
    381     return parentTreeScope ? parentTreeScope->rootNode() : 0;
     381    return parentTreeScope ? &parentTreeScope->rootNode() : nullptr;
    382382}
    383383
Note: See TracChangeset for help on using the changeset viewer.