/* * Copyright (C) 2013 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef RenderChildIterator_h #define RenderChildIterator_h #include "RenderIterator.h" namespace WebCore { template class RenderChildIterator : public RenderIterator { public: RenderChildIterator(const RenderElement& parent); RenderChildIterator(const RenderElement& parent, T* current); RenderChildIterator& operator++(); }; template class RenderChildConstIterator : public RenderConstIterator { public: RenderChildConstIterator(const RenderElement& parent); RenderChildConstIterator(const RenderElement& parent, const T* current); RenderChildConstIterator& operator++(); }; template class RenderChildIteratorAdapter { public: RenderChildIteratorAdapter(RenderElement& parent); RenderChildIterator begin(); RenderChildIterator end(); T* first(); T* last(); private: RenderElement& m_parent; }; template class RenderChildConstIteratorAdapter { public: RenderChildConstIteratorAdapter(const RenderElement& parent); RenderChildConstIterator begin() const; RenderChildConstIterator end() const; const T* first() const; const T* last() const; private: const RenderElement& m_parent; }; template RenderChildIteratorAdapter childrenOfType(RenderElement&); template RenderChildConstIteratorAdapter childrenOfType(const RenderElement&); // RenderChildIterator template inline RenderChildIterator::RenderChildIterator(const RenderElement& parent) : RenderIterator(&parent) { } template inline RenderChildIterator::RenderChildIterator(const RenderElement& parent, T* current) : RenderIterator(&parent, current) { } template inline RenderChildIterator& RenderChildIterator::operator++() { return static_cast&>(RenderIterator::traverseNextSibling()); } // RenderChildConstIterator template inline RenderChildConstIterator::RenderChildConstIterator(const RenderElement& parent) : RenderConstIterator(&parent) { } template inline RenderChildConstIterator::RenderChildConstIterator(const RenderElement& parent, const T* current) : RenderConstIterator(&parent, current) { } template inline RenderChildConstIterator& RenderChildConstIterator::operator++() { return static_cast&>(RenderConstIterator::traverseNextSibling()); } // RenderChildIteratorAdapter template inline RenderChildIteratorAdapter::RenderChildIteratorAdapter(RenderElement& parent) : m_parent(parent) { } template inline RenderChildIterator RenderChildIteratorAdapter::begin() { return RenderChildIterator(m_parent, RenderTraversal::firstChild(m_parent)); } template inline RenderChildIterator RenderChildIteratorAdapter::end() { return RenderChildIterator(m_parent); } template inline T* RenderChildIteratorAdapter::first() { return RenderTraversal::firstChild(m_parent); } template inline T* RenderChildIteratorAdapter::last() { return RenderTraversal::lastChild(m_parent); } // RenderChildConstIteratorAdapter template inline RenderChildConstIteratorAdapter::RenderChildConstIteratorAdapter(const RenderElement& parent) : m_parent(parent) { } template inline RenderChildConstIterator RenderChildConstIteratorAdapter::begin() const { return RenderChildConstIterator(m_parent, RenderTraversal::firstChild(m_parent)); } template inline RenderChildConstIterator RenderChildConstIteratorAdapter::end() const { return RenderChildConstIterator(m_parent); } template inline const T* RenderChildConstIteratorAdapter::first() const { return RenderTraversal::firstChild(m_parent); } template inline const T* RenderChildConstIteratorAdapter::last() const { return RenderTraversal::lastChild(m_parent); } // Standalone functions template inline RenderChildIteratorAdapter childrenOfType(RenderElement& parent) { return RenderChildIteratorAdapter(parent); } template inline RenderChildConstIteratorAdapter childrenOfType(const RenderElement& parent) { return RenderChildConstIteratorAdapter(parent); } } #endif