Changeset 154734 in webkit


Ignore:
Timestamp:
Aug 28, 2013 5:31:10 AM (11 years ago)
Author:
Antti Koivisto
Message:

Make descendant iterators always require ContainerNode root
https://bugs.webkit.org/show_bug.cgi?id=120393

Reviewed by Andreas Kling.

Remove Node* root versions of the iterators.
Fix the few call sites that required them to have tighter typing.

  • accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::canvasHasFallbackContent):
(WebCore::siblingWithAriaRole):

  • dom/ChildIterator.h:

(WebCore::::ChildIteratorAdapter):
(WebCore::::begin):
(WebCore::::end):
(WebCore::elementChildren):
(WebCore::childrenOfType):

  • dom/DescendantIterator.h:

(WebCore::::DescendantIterator):
(WebCore::::DescendantIteratorAdapter):
(WebCore::::begin):
(WebCore::::end):
(WebCore::elementDescendants):
(WebCore::descendantsOfType):

  • editing/ApplyStyleCommand.cpp:

(WebCore::dummySpanAncestorForNode):
(WebCore::ApplyStyleCommand::cleanupUnstyledAppleStyleSpans):
(WebCore::ApplyStyleCommand::applyInlineStyle):

  • editing/ApplyStyleCommand.h:
Location:
trunk/Source/WebCore
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r154732 r154734  
     12013-08-28  Antti Koivisto  <antti@apple.com>
     2
     3        Make descendant iterators always require ContainerNode root
     4        https://bugs.webkit.org/show_bug.cgi?id=120393
     5
     6        Reviewed by Andreas Kling.
     7
     8        Remove Node* root versions of the iterators.
     9        Fix the few call sites that required them to have tighter typing.
     10
     11        * accessibility/AccessibilityNodeObject.cpp:
     12        (WebCore::AccessibilityNodeObject::canvasHasFallbackContent):
     13        (WebCore::siblingWithAriaRole):
     14        * dom/ChildIterator.h:
     15        (WebCore::::ChildIteratorAdapter):
     16        (WebCore::::begin):
     17        (WebCore::::end):
     18        (WebCore::elementChildren):
     19        (WebCore::childrenOfType):
     20        * dom/DescendantIterator.h:
     21        (WebCore::::DescendantIterator):
     22        (WebCore::::DescendantIteratorAdapter):
     23        (WebCore::::begin):
     24        (WebCore::::end):
     25        (WebCore::elementDescendants):
     26        (WebCore::descendantsOfType):
     27        * editing/ApplyStyleCommand.cpp:
     28        (WebCore::dummySpanAncestorForNode):
     29        (WebCore::ApplyStyleCommand::cleanupUnstyledAppleStyleSpans):
     30        (WebCore::ApplyStyleCommand::applyInlineStyle):
     31        * editing/ApplyStyleCommand.h:
     32
    1332013-08-28  Sergio Villar Senin  <svillar@igalia.com>
    234
  • trunk/Source/WebCore/accessibility/AccessibilityNodeObject.cpp

    r154710 r154734  
    418418    if (!node || !node->hasTagName(canvasTag))
    419419        return false;
    420 
     420    Element* canvasElement = toElement(node);
    421421    // If it has any children that are elements, we'll assume it might be fallback
    422422    // content. If it has no children or its only children are not elements
    423423    // (e.g. just text nodes), it doesn't have fallback content.
    424     return elementChildren(node).begin() != elementChildren(node).end();
     424    return elementChildren(canvasElement).begin() != elementChildren(canvasElement).end();
    425425}
    426426
     
    11231123static Element* siblingWithAriaRole(String role, Node* node)
    11241124{
    1125     Node* parent = node->parentNode();
     1125    ContainerNode* parent = node->parentNode();
    11261126    if (!parent)
    11271127        return 0;
    1128 
    11291128    for (auto sibling = elementChildren(parent).begin(), end = elementChildren(parent).end(); sibling != end; ++sibling) {
    11301129        const AtomicString& siblingAriaRole = sibling->fastGetAttribute(roleAttr);
  • trunk/Source/WebCore/dom/ChildIterator.h

    r154700 r154734  
    5555};
    5656
    57 template <typename ElementType, typename ContainerType>
     57template <typename ElementType>
    5858class ChildIteratorAdapter {
    5959public:
    60     ChildIteratorAdapter(ContainerType* root);
     60    ChildIteratorAdapter(ContainerNode* root);
    6161    ChildIterator<ElementType> begin();
    6262    ChildIterator<ElementType> end();
    6363
    6464private:
    65     const ContainerType* m_root;
     65    const ContainerNode* m_root;
    6666};
    6767
    68 ChildIteratorAdapter<Element, ContainerNode> elementChildren(ContainerNode* root);
    69 ChildIteratorAdapter<Element, Node> elementChildren(Node* root);
    70 template <typename ElementType> ChildIteratorAdapter<ElementType, ContainerNode> childrenOfType(ContainerNode* root);
    71 template <typename ElementType> ChildIteratorAdapter<ElementType, Node> childrenOfType(Node* root);
     68ChildIteratorAdapter<Element> elementChildren(ContainerNode* root);
     69template <typename ElementType> ChildIteratorAdapter<ElementType> childrenOfType(ContainerNode* root);
    7270
    7371template <typename ElementType>
     
    135133}
    136134
    137 template <typename ElementType, typename ContainerType>
    138 inline ChildIteratorAdapter<ElementType, ContainerType>::ChildIteratorAdapter(ContainerType* root)
     135template <typename ElementType>
     136inline ChildIteratorAdapter<ElementType>::ChildIteratorAdapter(ContainerNode* root)
    139137    : m_root(root)
    140138{
    141139}
    142140
    143 template <typename ElementType, typename ContainerType>
    144 inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType, ContainerType>::begin()
     141template <typename ElementType>
     142inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType>::begin()
    145143{
    146144    return ChildIterator<ElementType>(Traversal<ElementType>::firstChild(m_root));
    147145}
    148146
    149 template <typename ElementType, typename ContainerType>
    150 inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType, ContainerType>::end()
     147template <typename ElementType>
     148inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType>::end()
    151149{
    152150    return ChildIterator<ElementType>();
    153151}
    154152
    155 inline ChildIteratorAdapter<Element, ContainerNode> elementChildren(ContainerNode* root)
     153inline ChildIteratorAdapter<Element> elementChildren(ContainerNode* root)
    156154{
    157     return ChildIteratorAdapter<Element, ContainerNode>(root);
    158 }
    159 
    160 inline ChildIteratorAdapter<Element, Node> elementChildren(Node* root)
    161 {
    162     return ChildIteratorAdapter<Element, Node>(root);
     155    return ChildIteratorAdapter<Element>(root);
    163156}
    164157
    165158template <typename ElementType>
    166 inline ChildIteratorAdapter<ElementType, ContainerNode> childrenOfType(ContainerNode* root)
     159inline ChildIteratorAdapter<ElementType> childrenOfType(ContainerNode* root)
    167160{
    168     return ChildIteratorAdapter<ElementType, ContainerNode>(root);
    169 }
    170 
    171 template <typename ElementType>
    172 inline ChildIteratorAdapter<ElementType, Node> childrenOfType(Node* root)
    173 {
    174     return ChildIteratorAdapter<ElementType, Node>(root);
     161    return ChildIteratorAdapter<ElementType>(root);
    175162}
    176163
  • trunk/Source/WebCore/dom/DescendantIterator.h

    r154700 r154734  
    3838class DescendantIterator {
    3939public:
    40     DescendantIterator(const Node* root);
    41     DescendantIterator(const Node* root, ElementType* current);
     40    DescendantIterator(const ContainerNode* root);
     41    DescendantIterator(const ContainerNode* root, ElementType* current);
    4242    DescendantIterator& operator++();
    4343    ElementType& operator*();
     
    4646
    4747private:
    48     const Node* m_root;
     48    const ContainerNode* m_root;
    4949    ElementType* m_current;
    5050
     
    5656};
    5757
    58 template <typename ElementType, typename ContainerType>
     58template <typename ElementType>
    5959class DescendantIteratorAdapter {
    6060public:
    61     DescendantIteratorAdapter(ContainerType* root);
     61    DescendantIteratorAdapter(ContainerNode* root);
    6262    DescendantIterator<ElementType> begin();
    6363    DescendantIterator<ElementType> end();
    6464
    6565private:
    66     ContainerType* m_root;
     66    ContainerNode* m_root;
    6767};
    6868
    69 DescendantIteratorAdapter<Element, ContainerNode> elementDescendants(ContainerNode* root);
    70 DescendantIteratorAdapter<Element, Node> elementDescendants(Node* root);
    71 template <typename ElementType> DescendantIteratorAdapter<ElementType, ContainerNode> descendantsOfType(ContainerNode* root);
    72 template <typename ElementType> DescendantIteratorAdapter<ElementType, Node> descendantsOfType(Node* root);
     69DescendantIteratorAdapter<Element> elementDescendants(ContainerNode* root);
     70template <typename ElementType> DescendantIteratorAdapter<ElementType> descendantsOfType(ContainerNode* root);
    7371
    7472template <typename ElementType>
    75 inline DescendantIterator<ElementType>::DescendantIterator(const Node* root)
     73inline DescendantIterator<ElementType>::DescendantIterator(const ContainerNode* root)
    7674    : m_root(root)
    7775    , m_current(nullptr)
     
    8381
    8482template <typename ElementType>
    85 inline DescendantIterator<ElementType>::DescendantIterator(const Node* root, ElementType* current)
     83inline DescendantIterator<ElementType>::DescendantIterator(const ContainerNode* root, ElementType* current)
    8684    : m_root(root)
    8785    , m_current(current)
     
    139137}
    140138
    141 template <typename ElementType, typename ContainerType>
    142 inline DescendantIteratorAdapter<ElementType, ContainerType>::DescendantIteratorAdapter(ContainerType* root)
     139template <typename ElementType>
     140inline DescendantIteratorAdapter<ElementType>::DescendantIteratorAdapter(ContainerNode* root)
    143141    : m_root(root)
    144142{
    145143}
    146144
    147 template <typename ElementType, typename ContainerType>
    148 inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType, ContainerType>::begin()
     145template <typename ElementType>
     146inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType>::begin()
    149147{
    150148    return DescendantIterator<ElementType>(m_root, Traversal<ElementType>::firstWithin(m_root));
    151149}
    152150
    153 template <typename ElementType, typename ContainerType>
    154 inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType, ContainerType>::end()
     151template <typename ElementType>
     152inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType>::end()
    155153{
    156154    return DescendantIterator<ElementType>(m_root);
    157155}
    158156
    159 inline DescendantIteratorAdapter<Element, ContainerNode> elementDescendants(ContainerNode* root)
     157inline DescendantIteratorAdapter<Element> elementDescendants(ContainerNode* root)
    160158{
    161     return DescendantIteratorAdapter<Element, ContainerNode>(root);
    162 }
    163 
    164 inline DescendantIteratorAdapter<Element, Node> elementDescendants(Node* root)
    165 {
    166     return DescendantIteratorAdapter<Element, Node>(root);
     159    return DescendantIteratorAdapter<Element>(root);
    167160}
    168161
    169162template <typename ElementType>
    170 inline DescendantIteratorAdapter<ElementType, ContainerNode> descendantsOfType(ContainerNode* root)
     163inline DescendantIteratorAdapter<ElementType> descendantsOfType(ContainerNode* root)
    171164{
    172     return DescendantIteratorAdapter<ElementType, ContainerNode>(root);
    173 }
    174 
    175 template <typename ElementType>
    176 inline DescendantIteratorAdapter<ElementType, Node> descendantsOfType(Node* root)
    177 {
    178     return DescendantIteratorAdapter<ElementType, Node>(root);
     165    return DescendantIteratorAdapter<ElementType>(root);
    179166}
    180167
  • trunk/Source/WebCore/editing/ApplyStyleCommand.cpp

    r154581 r154734  
    426426}
    427427
    428 static Node* dummySpanAncestorForNode(const Node* node)
     428static ContainerNode* dummySpanAncestorForNode(const Node* node)
    429429{
    430430    while (node && (!node->isElementNode() || !isStyleSpanOrSpanWithOnlyStyleAttribute(toElement(node))))
     
    434434}
    435435
    436 void ApplyStyleCommand::cleanupUnstyledAppleStyleSpans(Node* dummySpanAncestor)
     436void ApplyStyleCommand::cleanupUnstyledAppleStyleSpans(ContainerNode* dummySpanAncestor)
    437437{
    438438    if (!dummySpanAncestor)
     
    552552void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
    553553{
    554     RefPtr<Node> startDummySpanAncestor = 0;
    555     RefPtr<Node> endDummySpanAncestor = 0;
     554    RefPtr<ContainerNode> startDummySpanAncestor = 0;
     555    RefPtr<ContainerNode> endDummySpanAncestor = 0;
    556556
    557557    // update document layout once before removing styles
  • trunk/Source/WebCore/editing/ApplyStyleCommand.h

    r143821 r154734  
    109109    bool mergeStartWithPreviousIfIdentical(const Position& start, const Position& end);
    110110    bool mergeEndWithNextIfIdentical(const Position& start, const Position& end);
    111     void cleanupUnstyledAppleStyleSpans(Node* dummySpanAncestor);
     111    void cleanupUnstyledAppleStyleSpans(ContainerNode* dummySpanAncestor);
    112112
    113113    void surroundNodeRangeWithElement(PassRefPtr<Node> start, PassRefPtr<Node> end, PassRefPtr<Element>);
Note: See TracChangeset for help on using the changeset viewer.