DocumentStyleRootIterator.cpp (1325B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "DocumentStyleRootIterator.h" 8 9 #include "mozilla/dom/Document.h" 10 #include "mozilla/dom/Element.h" 11 #include "nsContentUtils.h" 12 13 namespace mozilla { 14 15 DocumentStyleRootIterator::DocumentStyleRootIterator(nsINode* aStyleRoot) 16 : mPosition(0) { 17 MOZ_COUNT_CTOR(DocumentStyleRootIterator); 18 MOZ_ASSERT(aStyleRoot); 19 if (aStyleRoot->IsElement()) { 20 mStyleRoots.AppendElement(aStyleRoot->AsElement()); 21 return; 22 } 23 24 dom::Document* doc = aStyleRoot->OwnerDoc(); 25 MOZ_ASSERT(doc == aStyleRoot); 26 if (dom::Element* root = doc->GetRootElement()) { 27 mStyleRoots.AppendElement(root); 28 } 29 nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(doc, mStyleRoots); 30 } 31 32 dom::Element* DocumentStyleRootIterator::GetNextStyleRoot() { 33 for (;;) { 34 if (mPosition >= mStyleRoots.Length()) { 35 return nullptr; 36 } 37 38 nsIContent* next = mStyleRoots[mPosition]; 39 ++mPosition; 40 41 if (next->IsElement()) { 42 return next->AsElement(); 43 } 44 } 45 } 46 47 } // namespace mozilla