LayoutAncestorIterator.h [plain text]
#pragma once
#include "LayoutIterator.h"
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
namespace WebCore {
namespace Layout {
template <typename T>
class LayoutAncestorIterator : public LayoutIterator<T> {
public:
LayoutAncestorIterator();
explicit LayoutAncestorIterator(const T* current);
LayoutAncestorIterator& operator++();
};
template <typename T>
class LayoutAncestorIteratorAdapter {
public:
LayoutAncestorIteratorAdapter(const T* first);
LayoutAncestorIterator<T> begin() const;
LayoutAncestorIterator<T> end() const;
const T* first() const;
private:
const T* m_first;
};
template <typename T> LayoutAncestorIteratorAdapter<T> ancestorsOfType(const Box&);
template <typename T> LayoutAncestorIteratorAdapter<T> lineageOfType(const Box&);
template <typename T>
inline LayoutAncestorIterator<T>::LayoutAncestorIterator()
: LayoutIterator<T>(nullptr)
{
}
template <typename T>
inline LayoutAncestorIterator<T>::LayoutAncestorIterator(const T* current)
: LayoutIterator<T>(nullptr, current)
{
}
template <typename T>
inline LayoutAncestorIterator<T>& LayoutAncestorIterator<T>::operator++()
{
return static_cast<LayoutAncestorIterator<T>&>(LayoutIterator<T>::traverseAncestor());
}
template <typename T>
inline LayoutAncestorIteratorAdapter<T>::LayoutAncestorIteratorAdapter(const T* first)
: m_first(first)
{
}
template <typename T>
inline LayoutAncestorIterator<T> LayoutAncestorIteratorAdapter<T>::begin() const
{
return LayoutAncestorIterator<T>(m_first);
}
template <typename T>
inline LayoutAncestorIterator<T> LayoutAncestorIteratorAdapter<T>::end() const
{
return LayoutAncestorIterator<T>();
}
template <typename T>
inline const T* LayoutAncestorIteratorAdapter<T>::first() const
{
return m_first;
}
template <typename T>
inline LayoutAncestorIteratorAdapter<T> ancestorsOfType(const Box& descendant)
{
const T* first = Traversal::findAncestorOfType<const T>(descendant);
return LayoutAncestorIteratorAdapter<T>(first);
}
template <typename T>
inline LayoutAncestorIteratorAdapter<T> lineageOfType(const Box& first)
{
if (isLayoutBoxOfType<T>(first))
return LayoutAncestorIteratorAdapter<T>(static_cast<const T*>(&first));
return ancestorsOfType<T>(first);
}
}
}
#endif