⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 118890 in webkit


Ignore:
Timestamp:
May 29, 2012, 9:20:02 PM (14 years ago)
Author:
hayato@chromium.org
Message:

Introduces ComposedShadowTreeParentWalker, extracted from ComposedShadowTreeWalker.
https://bugs.webkit.org/show_bug.cgi?id=87004

Reviewed by Dimitri Glazkov.

Introduces a ComposedShadowTreeParentWalker, which is only used
for traversing a parent node (including shadow roots and insertion
points) and get rid of an equivalent function from
ComposedShadowTreeWalker.

Before this patch, there is an inconsistency inside of
ComposedShadowTreeWalker. The Walker uses 'Policy' to decide
whether it should visit shadow roots or not, but
parentIncludingInsertionPointAndShadowRoot() member function
ignores the policy. We can not add an assertion in its
constructor due to this inconsistency. To resolve it, we could
add yet another special policy, but that makes the implementation
complex and may add some overhead in runtime. So separate the
functionality into another class as ComposedShadowTreeParentWalker.

No new tests, no new functionality except for assertion.

  • dom/ComposedShadowTreeWalker.cpp:

(WebCore::ComposedShadowTreeWalker::ComposedShadowTreeWalker):
(WebCore::ComposedShadowTreeParentWalker::ComposedShadowTreeParentWalker):
(WebCore):
(WebCore::ComposedShadowTreeParentWalker::parentIncludingInsertionPointAndShadowRoot):
(WebCore::ComposedShadowTreeParentWalker::traverseParentIncludingInsertionPointAndShadowRoot):

  • dom/ComposedShadowTreeWalker.h:

(ComposedShadowTreeWalker):
(WebCore::ComposedShadowTreeWalker::assertPrecondition):
(WebCore):
(ComposedShadowTreeParentWalker):
(WebCore::ComposedShadowTreeParentWalker::get):

  • dom/EventDispatcher.cpp:

(WebCore::EventRelatedTargetAdjuster::adjust):
(WebCore::EventDispatcher::ensureEventAncestors):

  • page/EventHandler.cpp:

(WebCore::EventHandler::updateMouseEventTargetNode):

Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r118889 r118890  
     12012-05-29  Hayato Ito  <hayato@chromium.org>
     2
     3        Introduces ComposedShadowTreeParentWalker, extracted from ComposedShadowTreeWalker.
     4        https://bugs.webkit.org/show_bug.cgi?id=87004
     5
     6        Reviewed by Dimitri Glazkov.
     7
     8        Introduces a ComposedShadowTreeParentWalker, which is only used
     9        for traversing a parent node (including shadow roots and insertion
     10        points) and get rid of an equivalent function from
     11        ComposedShadowTreeWalker.
     12
     13        Before this patch, there is an inconsistency inside of
     14        ComposedShadowTreeWalker. The Walker uses 'Policy' to decide
     15        whether it should visit shadow roots or not, but
     16        parentIncludingInsertionPointAndShadowRoot() member function
     17        ignores the policy.  We can not add an assertion in its
     18        constructor due to this inconsistency.  To resolve it, we could
     19        add yet another special policy, but that makes the implementation
     20        complex and may add some overhead in runtime.  So separate the
     21        functionality into another class as ComposedShadowTreeParentWalker.
     22
     23        No new tests, no new functionality except for assertion.
     24
     25        * dom/ComposedShadowTreeWalker.cpp:
     26        (WebCore::ComposedShadowTreeWalker::ComposedShadowTreeWalker):
     27        (WebCore::ComposedShadowTreeParentWalker::ComposedShadowTreeParentWalker):
     28        (WebCore):
     29        (WebCore::ComposedShadowTreeParentWalker::parentIncludingInsertionPointAndShadowRoot):
     30        (WebCore::ComposedShadowTreeParentWalker::traverseParentIncludingInsertionPointAndShadowRoot):
     31        * dom/ComposedShadowTreeWalker.h:
     32        (ComposedShadowTreeWalker):
     33        (WebCore::ComposedShadowTreeWalker::assertPrecondition):
     34        (WebCore):
     35        (ComposedShadowTreeParentWalker):
     36        (WebCore::ComposedShadowTreeParentWalker::get):
     37        * dom/EventDispatcher.cpp:
     38        (WebCore::EventRelatedTargetAdjuster::adjust):
     39        (WebCore::EventDispatcher::ensureEventAncestors):
     40        * page/EventHandler.cpp:
     41        (WebCore::EventHandler::updateMouseEventTargetNode):
     42
    1432012-05-29  Hayato Ito  <hayato@chromium.org>
    244
  • trunk/Source/WebCore/dom/ComposedShadowTreeWalker.cpp

    r118125 r118890  
    5353    , m_policy(policy)
    5454{
    55     // FIXME: Refactor ComposedShadowTreeWalker so that we can assert node here.
    56     // https://bugs.webkit.org/show_bug.cgi?id=87004
     55#ifndef NDEBUG
     56    if (m_node)
     57        assertPrecondition();
     58#endif
    5759}
    5860
     
    199201}
    200202
    201 void ComposedShadowTreeWalker::parentIncludingInsertionPointAndShadowRoot()
    202 {
    203     ASSERT(m_node);
    204     m_node = traverseParentIncludingInsertionPointAndShadowRoot(m_node);
    205 }
    206 
    207 Node* ComposedShadowTreeWalker::traverseParentIncludingInsertionPointAndShadowRoot(const Node* node) const
    208 {
    209     if (ElementShadow* shadow = shadowOfParent(node)) {
    210         if (InsertionPoint* insertionPoint = shadow->insertionPointFor(node))
    211             return insertionPoint;
    212     }
    213     if (!node->isShadowRoot())
    214         return node->parentNode();
    215     const ShadowRoot* shadowRoot = toShadowRoot(node);
    216     if (shadowRoot->isYoungest())
    217         return shadowRoot->host();
    218     InsertionPoint* assignedInsertionPoint = shadowRoot->assignedTo();
    219     ASSERT(assignedInsertionPoint);
    220     return assignedInsertionPoint;
    221 }
    222 
    223203Node* ComposedShadowTreeWalker::traverseParent(const Node* node) const
    224204{
     
    294274}
    295275
     276ComposedShadowTreeParentWalker::ComposedShadowTreeParentWalker(const Node* node)
     277    : m_node(node)
     278{
     279}
     280
     281void ComposedShadowTreeParentWalker::parentIncludingInsertionPointAndShadowRoot()
     282{
     283    ASSERT(m_node);
     284    m_node = traverseParentIncludingInsertionPointAndShadowRoot(m_node);
     285}
     286
     287Node* ComposedShadowTreeParentWalker::traverseParentIncludingInsertionPointAndShadowRoot(const Node* node) const
     288{
     289    if (ElementShadow* shadow = shadowOfParent(node)) {
     290        if (InsertionPoint* insertionPoint = shadow->insertionPointFor(node))
     291            return insertionPoint;
     292    }
     293    if (!node->isShadowRoot())
     294        return node->parentNode();
     295    const ShadowRoot* shadowRoot = toShadowRoot(node);
     296    if (shadowRoot->isYoungest())
     297        return shadowRoot->host();
     298    InsertionPoint* assignedInsertionPoint = shadowRoot->assignedTo();
     299    ASSERT(assignedInsertionPoint);
     300    return assignedInsertionPoint;
     301}
     302
    296303} // namespace
  • trunk/Source/WebCore/dom/ComposedShadowTreeWalker.h

    r117534 r118890  
    6060
    6161    void parent();
    62     // This function ignores policy and always crosses an upper boundary.
    63     void parentIncludingInsertionPointAndShadowRoot();
    6462
    6563    void next();
     
    8280        else
    8381            ASSERT(!m_node->isShadowRoot() || toShadowRoot(m_node)->isYoungest());
    84         ASSERT(!isInsertionPoint(m_node) || !toInsertionPoint(m_node)->isActive());
     82        ASSERT(!isActiveInsertionPoint(m_node));
    8583#endif
    8684    }
     
    10199    Node* traverseChild(const Node*, TraversalDirection) const;
    102100    Node* traverseParent(const Node*) const;
    103     Node* traverseParentIncludingInsertionPointAndShadowRoot(const Node*) const;
    104101
    105102    static Node* traverseNextSibling(const Node*);
     
    120117};
    121118
     119// A special walker class which is only used for traversing a parent node, including
     120// insertion points and shadow roots.
     121class ComposedShadowTreeParentWalker {
     122public:
     123    ComposedShadowTreeParentWalker(const Node*);
     124    void parentIncludingInsertionPointAndShadowRoot();
     125    Node* get() const { return const_cast<Node*>(m_node); }
     126private:
     127    Node* traverseParentIncludingInsertionPointAndShadowRoot(const Node*) const;
     128    const Node* m_node;
     129};
     130
    122131} // namespace
    123132
  • trunk/Source/WebCore/dom/EventDispatcher.cpp

    r118645 r118890  
    6363{
    6464    TreeScope* lastTreeScope = 0;
    65     for (ComposedShadowTreeWalker walker(m_relatedTarget.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
     65    for (ComposedShadowTreeParentWalker walker(m_relatedTarget.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
    6666        TreeScope* scope = walker.get()->treeScope();
    6767        // Skips adding a node to the map if treeScope does not change.
     
    204204    bool isSVGElement = m_node->isSVGElement();
    205205    Vector<EventTarget*> targetStack;
    206     for (ComposedShadowTreeWalker walker(m_node.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
     206    for (ComposedShadowTreeParentWalker walker(m_node.get()); walker.get(); walker.parentIncludingInsertionPointAndShadowRoot()) {
    207207        Node* node = walker.get();
    208208        if (isActiveInsertionPoint(node) || targetStack.isEmpty())
  • trunk/Source/WebCore/page/EventHandler.cpp

    r118611 r118890  
    21192119        // If the target node is a text node, dispatch on the parent node - rdar://4196646
    21202120        if (result && result->isTextNode()) {
    2121             ComposedShadowTreeWalker walker(result);
     2121            ComposedShadowTreeParentWalker walker(result);
    21222122            walker.parentIncludingInsertionPointAndShadowRoot();
    21232123            result = walker.get();
Note: See TracChangeset for help on using the changeset viewer.