Changeset 117796 in webkit


Ignore:
Timestamp:
May 21, 2012 9:59:02 AM (12 years ago)
Author:
morrita@google.com
Message:

[Refactoring] Node should have youngestShadowRoot.
https://bugs.webkit.org/show_bug.cgi?id=86427

Reviewed by Dimitri Glazkov.

This change adds Node::youngestShadowRoot() and replaced
ElementShadow::youngestShadowRoot() with it if appropriate.

By introducing this, traversal across node and its shadow tree can
look more fluent and idiomatic. There are a few non-trivial traversal
remaining like ElementShadow::recalcStyle() and attach().
But they should be flattened out eventually.

No new tests. Refactoring.

  • dom/ContainerNodeAlgorithms.cpp:

(WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree):

  • dom/Document.cpp:

(WebCore::Document::buildAccessKeyMap):

  • dom/ElementShadow.cpp:
  • dom/ElementShadow.h:

(ElementShadow):
(WebCore::Node::youngestShadowRoot):
(WebCore):

  • dom/Node.h:

(Node):

  • dom/TreeScopeAdopter.cpp:

(WebCore::TreeScopeAdopter::moveTreeToNewScope):
(WebCore::TreeScopeAdopter::moveTreeToNewDocument):

  • dom/TreeScopeAdopter.h:

(TreeScopeAdopter):

  • html/shadow/TextFieldDecorationElement.cpp:

(WebCore::getDecorationRootAndDecoratedRoot):

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r117795 r117796  
     12012-05-21  MORITA Hajime  <morrita@google.com>
     2
     3        [Refactoring] Node should have youngestShadowRoot.
     4        https://bugs.webkit.org/show_bug.cgi?id=86427
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        This change adds Node::youngestShadowRoot() and replaced
     9        ElementShadow::youngestShadowRoot() with it if appropriate.
     10
     11        By introducing this, traversal across node and its shadow tree can
     12        look more fluent and idiomatic. There are a few non-trivial traversal
     13        remaining like ElementShadow::recalcStyle() and attach().
     14        But they should be flattened out eventually.
     15
     16        No new tests. Refactoring.
     17
     18        * dom/ContainerNodeAlgorithms.cpp:
     19        (WebCore::ChildNodeInsertionNotifier::notifyDescendantInsertedIntoTree):
     20        * dom/Document.cpp:
     21        (WebCore::Document::buildAccessKeyMap):
     22        * dom/ElementShadow.cpp:
     23        * dom/ElementShadow.h:
     24        (ElementShadow):
     25        (WebCore::Node::youngestShadowRoot):
     26        (WebCore):
     27        * dom/Node.h:
     28        (Node):
     29        * dom/TreeScopeAdopter.cpp:
     30        (WebCore::TreeScopeAdopter::moveTreeToNewScope):
     31        (WebCore::TreeScopeAdopter::moveTreeToNewDocument):
     32        * dom/TreeScopeAdopter.h:
     33        (TreeScopeAdopter):
     34        * html/shadow/TextFieldDecorationElement.cpp:
     35        (WebCore::getDecorationRootAndDecoratedRoot):
     36
    1372012-05-21  Christophe Dumez  <christophe.dumez@intel.com>
    238
  • trunk/Source/WebCore/dom/ContainerNodeAlgorithms.cpp

    r116629 r117796  
    6262    }
    6363
    64     if (!node->isElementNode())
    65         return;
    66 
    67     if (ElementShadow* shadow = toElement(node)->shadow()) {
    68         for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
    69             notifyNodeInsertedIntoTree(root);
    70     }
     64    for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->olderShadowRoot())
     65        notifyNodeInsertedIntoTree(root);
    7166}
    7267
  • trunk/Source/WebCore/dom/Document.cpp

    r117613 r117796  
    720720            m_elementsByAccessKey.set(accessKey.impl(), element);
    721721
    722         if (ElementShadow* shadow = element->shadow()) {
    723             for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
    724                 buildAccessKeyMap(root);
    725         }
     722        for (ShadowRoot* root = node->youngestShadowRoot(); root; root = root->olderShadowRoot())
     723            buildAccessKeyMap(root);
    726724    }
    727725}
  • trunk/Source/WebCore/dom/ElementShadow.cpp

    r117723 r117796  
    111111}
    112112
    113 void ElementShadow::setParentTreeScope(TreeScope* scope)
    114 {
    115     for (ShadowRoot* root = youngestShadowRoot(); root; root = root->olderShadowRoot())
    116         root->setParentTreeScope(scope);
    117 }
    118 
    119113void ElementShadow::attach()
    120114{
  • trunk/Source/WebCore/dom/ElementShadow.h

    r117033 r117796  
    2929
    3030#include "ContentDistributor.h"
     31#include "Element.h"
    3132#include "ExceptionCode.h"
    3233#include "ShadowRoot.h"
     
    5354
    5455    void addShadowRoot(Element* shadowHost, PassRefPtr<ShadowRoot>, ExceptionCode&);
    55 
    56     void setParentTreeScope(TreeScope*);
    5756
    5857    void attach();
     
    116115}
    117116
     117inline ShadowRoot* Node::youngestShadowRoot() const
     118{
     119    if (!this->isElementNode())
     120        return 0;
     121    if (ElementShadow* shadow = toElement(this)->shadow())
     122        return shadow->youngestShadowRoot();
     123    return 0;
     124}
     125
    118126class ShadowRootVector : public Vector<RefPtr<ShadowRoot> > {
    119127public:
  • trunk/Source/WebCore/dom/Node.h

    r117723 r117796  
    224224    Node* shadowAncestorNode() const;
    225225    ShadowRoot* shadowRoot() const;
     226    ShadowRoot* youngestShadowRoot() const;
     227
    226228    // Returns 0, a child of ShadowRoot, or a legacy shadow root.
    227229    Node* nonBoundaryShadowTreeRootNode();
  • trunk/Source/WebCore/dom/TreeScopeAdopter.cpp

    r116277 r117796  
    6464            moveNodeToNewDocument(node, oldDocument, newDocument);
    6565
    66         if (ElementShadow* shadow = shadowFor(node)) {
     66        for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = shadow->olderShadowRoot()) {
    6767            shadow->setParentTreeScope(m_newScope);
    6868            if (willMoveToNewDocument)
    69                 moveShadowToNewDocument(shadow, oldDocument, newDocument);
     69                moveTreeToNewDocument(shadow, oldDocument, newDocument);
    7070        }
    7171    }
     
    7676    for (Node* node = root; node; node = node->traverseNextNode(root)) {
    7777        moveNodeToNewDocument(node, oldDocument, newDocument);
    78         if (ElementShadow* shadow = shadowFor(node))
    79             moveShadowToNewDocument(shadow, oldDocument, newDocument);
     78        for (ShadowRoot* shadow = node->youngestShadowRoot(); shadow; shadow = shadow->olderShadowRoot())
     79            moveTreeToNewDocument(shadow, oldDocument, newDocument);
    8080    }
    81 }
    82 
    83 inline void TreeScopeAdopter::moveShadowToNewDocument(ElementShadow* shadow, Document* oldDocument, Document* newDocument) const
    84 {
    85     for (ShadowRoot* root = shadow->youngestShadowRoot(); root; root = root->olderShadowRoot())
    86         moveTreeToNewDocument(root, oldDocument, newDocument);
    8781}
    8882
  • trunk/Source/WebCore/dom/TreeScopeAdopter.h

    r116277 r117796  
    4747    void moveTreeToNewDocument(Node*, Document* oldDocument, Document* newDocument) const;
    4848    void moveNodeToNewDocument(Node*, Document* oldDocument, Document* newDocument) const;
    49     void moveShadowToNewDocument(ElementShadow*, Document* oldDocument, Document* newDocument) const;
    5049
    5150    Node* m_toAdopt;
  • trunk/Source/WebCore/html/shadow/TextFieldDecorationElement.cpp

    r117242 r117796  
    6969static inline void getDecorationRootAndDecoratedRoot(HTMLInputElement* input, ShadowRoot*& decorationRoot, ShadowRoot*& decoratedRoot)
    7070{
    71     ShadowRoot* existingRoot = input->shadow()->youngestShadowRoot();
     71    ShadowRoot* existingRoot = input->youngestShadowRoot();
    7272    ShadowRoot* newRoot = 0;
    7373    while (existingRoot->childNodeCount() == 1 && existingRoot->firstChild()->hasTagName(shadowTag)) {
Note: See TracChangeset for help on using the changeset viewer.