/* * 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. */ #pragma once #include "RenderIterator.h" namespace WebCore { template class RenderAncestorIterator : public RenderIterator { public: RenderAncestorIterator(); explicit RenderAncestorIterator(T* current); RenderAncestorIterator& operator++(); }; template class RenderAncestorConstIterator : public RenderConstIterator { public: RenderAncestorConstIterator(); explicit RenderAncestorConstIterator(const T* current); RenderAncestorConstIterator& operator++(); }; template class RenderAncestorIteratorAdapter { public: RenderAncestorIteratorAdapter(T* first); RenderAncestorIterator begin(); RenderAncestorIterator end(); T* first(); private: T* m_first; }; template class RenderAncestorConstIteratorAdapter { public: RenderAncestorConstIteratorAdapter(const T* first); RenderAncestorConstIterator begin() const; RenderAncestorConstIterator end() const; const T* first() const; private: const T* m_first; }; template RenderAncestorIteratorAdapter ancestorsOfType(RenderObject&); template RenderAncestorConstIteratorAdapter ancestorsOfType(const RenderObject&); template RenderAncestorIteratorAdapter lineageOfType(RenderObject&); template RenderAncestorConstIteratorAdapter lineageOfType(const RenderObject&); // RenderAncestorIterator template inline RenderAncestorIterator::RenderAncestorIterator() : RenderIterator(nullptr) { } template inline RenderAncestorIterator::RenderAncestorIterator(T* current) : RenderIterator(nullptr, current) { } template inline RenderAncestorIterator& RenderAncestorIterator::operator++() { return static_cast&>(RenderIterator::traverseAncestor()); } // RenderAncestorConstIterator template inline RenderAncestorConstIterator::RenderAncestorConstIterator() : RenderConstIterator(nullptr) { } template inline RenderAncestorConstIterator::RenderAncestorConstIterator(const T* current) : RenderConstIterator(nullptr, current) { } template inline RenderAncestorConstIterator& RenderAncestorConstIterator::operator++() { return static_cast&>(RenderConstIterator::traverseAncestor()); } // RenderAncestorIteratorAdapter template inline RenderAncestorIteratorAdapter::RenderAncestorIteratorAdapter(T* first) : m_first(first) { } template inline RenderAncestorIterator RenderAncestorIteratorAdapter::begin() { return RenderAncestorIterator(m_first); } template inline RenderAncestorIterator RenderAncestorIteratorAdapter::end() { return RenderAncestorIterator(); } template inline T* RenderAncestorIteratorAdapter::first() { return m_first; } // RenderAncestorConstIteratorAdapter template inline RenderAncestorConstIteratorAdapter::RenderAncestorConstIteratorAdapter(const T* first) : m_first(first) { } template inline RenderAncestorConstIterator RenderAncestorConstIteratorAdapter::begin() const { return RenderAncestorConstIterator(m_first); } template inline RenderAncestorConstIterator RenderAncestorConstIteratorAdapter::end() const { return RenderAncestorConstIterator(); } template inline const T* RenderAncestorConstIteratorAdapter::first() const { return m_first; } // Standalone functions template inline RenderAncestorIteratorAdapter ancestorsOfType(RenderObject& descendant) { T* first = RenderTraversal::findAncestorOfType(descendant); return RenderAncestorIteratorAdapter(first); } template inline RenderAncestorConstIteratorAdapter ancestorsOfType(const RenderObject& descendant) { const T* first = RenderTraversal::findAncestorOfType(descendant); return RenderAncestorConstIteratorAdapter(first); } template inline RenderAncestorIteratorAdapter lineageOfType(RenderObject& first) { if (isRendererOfType(first)) return RenderAncestorIteratorAdapter(static_cast(&first)); return ancestorsOfType(first); } template inline RenderAncestorConstIteratorAdapter lineageOfType(const RenderObject& first) { if (isRendererOfType(first)) return RenderAncestorConstIteratorAdapter(static_cast(&first)); return ancestorsOfType(first); } } // namespace WebCore