Commit 1a7337a9 authored by antti@apple.com's avatar antti@apple.com

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:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@154734 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f4e33d62
2013-08-28 Antti Koivisto <antti@apple.com>
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:
2013-08-28 Sergio Villar Senin <svillar@igalia.com>
WorkerGlobalScopeWebDatabase requires ENABLE(WORKERS)
......@@ -417,11 +417,11 @@ bool AccessibilityNodeObject::canvasHasFallbackContent() const
Node* node = this->node();
if (!node || !node->hasTagName(canvasTag))
return false;
Element* canvasElement = toElement(node);
// If it has any children that are elements, we'll assume it might be fallback
// content. If it has no children or its only children are not elements
// (e.g. just text nodes), it doesn't have fallback content.
return elementChildren(node).begin() != elementChildren(node).end();
return elementChildren(canvasElement).begin() != elementChildren(canvasElement).end();
}
bool AccessibilityNodeObject::isImageButton() const
......@@ -1122,10 +1122,9 @@ String AccessibilityNodeObject::ariaAccessibilityDescription() const
static Element* siblingWithAriaRole(String role, Node* node)
{
Node* parent = node->parentNode();
ContainerNode* parent = node->parentNode();
if (!parent)
return 0;
for (auto sibling = elementChildren(parent).begin(), end = elementChildren(parent).end(); sibling != end; ++sibling) {
const AtomicString& siblingAriaRole = sibling->fastGetAttribute(roleAttr);
if (equalIgnoringCase(siblingAriaRole, role))
......
......@@ -54,21 +54,19 @@ private:
#endif
};
template <typename ElementType, typename ContainerType>
template <typename ElementType>
class ChildIteratorAdapter {
public:
ChildIteratorAdapter(ContainerType* root);
ChildIteratorAdapter(ContainerNode* root);
ChildIterator<ElementType> begin();
ChildIterator<ElementType> end();
private:
const ContainerType* m_root;
const ContainerNode* m_root;
};
ChildIteratorAdapter<Element, ContainerNode> elementChildren(ContainerNode* root);
ChildIteratorAdapter<Element, Node> elementChildren(Node* root);
template <typename ElementType> ChildIteratorAdapter<ElementType, ContainerNode> childrenOfType(ContainerNode* root);
template <typename ElementType> ChildIteratorAdapter<ElementType, Node> childrenOfType(Node* root);
ChildIteratorAdapter<Element> elementChildren(ContainerNode* root);
template <typename ElementType> ChildIteratorAdapter<ElementType> childrenOfType(ContainerNode* root);
template <typename ElementType>
inline ChildIterator<ElementType>::ChildIterator()
......@@ -134,44 +132,33 @@ inline bool ChildIterator<ElementType>::operator!=(const ChildIterator& other) c
return m_current != other.m_current;
}
template <typename ElementType, typename ContainerType>
inline ChildIteratorAdapter<ElementType, ContainerType>::ChildIteratorAdapter(ContainerType* root)
template <typename ElementType>
inline ChildIteratorAdapter<ElementType>::ChildIteratorAdapter(ContainerNode* root)
: m_root(root)
{
}
template <typename ElementType, typename ContainerType>
inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType, ContainerType>::begin()
template <typename ElementType>
inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType>::begin()
{
return ChildIterator<ElementType>(Traversal<ElementType>::firstChild(m_root));
}
template <typename ElementType, typename ContainerType>
inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType, ContainerType>::end()
template <typename ElementType>
inline ChildIterator<ElementType> ChildIteratorAdapter<ElementType>::end()
{
return ChildIterator<ElementType>();
}
inline ChildIteratorAdapter<Element, ContainerNode> elementChildren(ContainerNode* root)
{
return ChildIteratorAdapter<Element, ContainerNode>(root);
}
inline ChildIteratorAdapter<Element, Node> elementChildren(Node* root)
{
return ChildIteratorAdapter<Element, Node>(root);
}
template <typename ElementType>
inline ChildIteratorAdapter<ElementType, ContainerNode> childrenOfType(ContainerNode* root)
inline ChildIteratorAdapter<Element> elementChildren(ContainerNode* root)
{
return ChildIteratorAdapter<ElementType, ContainerNode>(root);
return ChildIteratorAdapter<Element>(root);
}
template <typename ElementType>
inline ChildIteratorAdapter<ElementType, Node> childrenOfType(Node* root)
inline ChildIteratorAdapter<ElementType> childrenOfType(ContainerNode* root)
{
return ChildIteratorAdapter<ElementType, Node>(root);
return ChildIteratorAdapter<ElementType>(root);
}
}
......
......@@ -37,15 +37,15 @@ namespace WebCore {
template <typename ElementType>
class DescendantIterator {
public:
DescendantIterator(const Node* root);
DescendantIterator(const Node* root, ElementType* current);
DescendantIterator(const ContainerNode* root);
DescendantIterator(const ContainerNode* root, ElementType* current);
DescendantIterator& operator++();
ElementType& operator*();
ElementType* operator->();
bool operator!=(const DescendantIterator& other) const;
private:
const Node* m_root;
const ContainerNode* m_root;
ElementType* m_current;
#ifndef NDEBUG
......@@ -55,24 +55,22 @@ private:
#endif
};
template <typename ElementType, typename ContainerType>
template <typename ElementType>
class DescendantIteratorAdapter {
public:
DescendantIteratorAdapter(ContainerType* root);
DescendantIteratorAdapter(ContainerNode* root);
DescendantIterator<ElementType> begin();
DescendantIterator<ElementType> end();
private:
ContainerType* m_root;
ContainerNode* m_root;
};
DescendantIteratorAdapter<Element, ContainerNode> elementDescendants(ContainerNode* root);
DescendantIteratorAdapter<Element, Node> elementDescendants(Node* root);
template <typename ElementType> DescendantIteratorAdapter<ElementType, ContainerNode> descendantsOfType(ContainerNode* root);
template <typename ElementType> DescendantIteratorAdapter<ElementType, Node> descendantsOfType(Node* root);
DescendantIteratorAdapter<Element> elementDescendants(ContainerNode* root);
template <typename ElementType> DescendantIteratorAdapter<ElementType> descendantsOfType(ContainerNode* root);
template <typename ElementType>
inline DescendantIterator<ElementType>::DescendantIterator(const Node* root)
inline DescendantIterator<ElementType>::DescendantIterator(const ContainerNode* root)
: m_root(root)
, m_current(nullptr)
#ifndef NDEBUG
......@@ -82,7 +80,7 @@ inline DescendantIterator<ElementType>::DescendantIterator(const Node* root)
}
template <typename ElementType>
inline DescendantIterator<ElementType>::DescendantIterator(const Node* root, ElementType* current)
inline DescendantIterator<ElementType>::DescendantIterator(const ContainerNode* root, ElementType* current)
: m_root(root)
, m_current(current)
#ifndef NDEBUG
......@@ -138,44 +136,33 @@ inline bool DescendantIterator<ElementType>::operator!=(const DescendantIterator
return m_current != other.m_current;
}
template <typename ElementType, typename ContainerType>
inline DescendantIteratorAdapter<ElementType, ContainerType>::DescendantIteratorAdapter(ContainerType* root)
template <typename ElementType>
inline DescendantIteratorAdapter<ElementType>::DescendantIteratorAdapter(ContainerNode* root)
: m_root(root)
{
}
template <typename ElementType, typename ContainerType>
inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType, ContainerType>::begin()
template <typename ElementType>
inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType>::begin()
{
return DescendantIterator<ElementType>(m_root, Traversal<ElementType>::firstWithin(m_root));
}
template <typename ElementType, typename ContainerType>
inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType, ContainerType>::end()
template <typename ElementType>
inline DescendantIterator<ElementType> DescendantIteratorAdapter<ElementType>::end()
{
return DescendantIterator<ElementType>(m_root);
}
inline DescendantIteratorAdapter<Element, ContainerNode> elementDescendants(ContainerNode* root)
{
return DescendantIteratorAdapter<Element, ContainerNode>(root);
}
inline DescendantIteratorAdapter<Element, Node> elementDescendants(Node* root)
{
return DescendantIteratorAdapter<Element, Node>(root);
}
template <typename ElementType>
inline DescendantIteratorAdapter<ElementType, ContainerNode> descendantsOfType(ContainerNode* root)
inline DescendantIteratorAdapter<Element> elementDescendants(ContainerNode* root)
{
return DescendantIteratorAdapter<ElementType, ContainerNode>(root);
return DescendantIteratorAdapter<Element>(root);
}
template <typename ElementType>
inline DescendantIteratorAdapter<ElementType, Node> descendantsOfType(Node* root)
inline DescendantIteratorAdapter<ElementType> descendantsOfType(ContainerNode* root)
{
return DescendantIteratorAdapter<ElementType, Node>(root);
return DescendantIteratorAdapter<ElementType>(root);
}
}
......
......@@ -425,7 +425,7 @@ void ApplyStyleCommand::applyRelativeFontStyleChange(EditingStyle* style)
removeNodePreservingChildren(unstyledSpans[i].get());
}
static Node* dummySpanAncestorForNode(const Node* node)
static ContainerNode* dummySpanAncestorForNode(const Node* node)
{
while (node && (!node->isElementNode() || !isStyleSpanOrSpanWithOnlyStyleAttribute(toElement(node))))
node = node->parentNode();
......@@ -433,7 +433,7 @@ static Node* dummySpanAncestorForNode(const Node* node)
return node ? node->parentNode() : 0;
}
void ApplyStyleCommand::cleanupUnstyledAppleStyleSpans(Node* dummySpanAncestor)
void ApplyStyleCommand::cleanupUnstyledAppleStyleSpans(ContainerNode* dummySpanAncestor)
{
if (!dummySpanAncestor)
return;
......@@ -551,8 +551,8 @@ static Node* highestEmbeddingAncestor(Node* startNode, Node* enclosingNode)
void ApplyStyleCommand::applyInlineStyle(EditingStyle* style)
{
RefPtr<Node> startDummySpanAncestor = 0;
RefPtr<Node> endDummySpanAncestor = 0;
RefPtr<ContainerNode> startDummySpanAncestor = 0;
RefPtr<ContainerNode> endDummySpanAncestor = 0;
// update document layout once before removing styles
// so that we avoid the expense of updating before each and every call
......
......@@ -108,7 +108,7 @@ private:
bool isValidCaretPositionInTextNode(const Position& position);
bool mergeStartWithPreviousIfIdentical(const Position& start, const Position& end);
bool mergeEndWithNextIfIdentical(const Position& start, const Position& end);
void cleanupUnstyledAppleStyleSpans(Node* dummySpanAncestor);
void cleanupUnstyledAppleStyleSpans(ContainerNode* dummySpanAncestor);
void surroundNodeRangeWithElement(PassRefPtr<Node> start, PassRefPtr<Node> end, PassRefPtr<Element>);
float computedFontSize(Node*);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment