Bug 1864419 - Part 1: Factor out ArgumentsData array into container class r=jandem
[gecko.git] / layout / style / DocumentStyleRootIterator.cpp
blob0d9595c434af97258b7c60374b6749e28d30154d
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/. */
7 #include "DocumentStyleRootIterator.h"
9 #include "mozilla/dom/Document.h"
10 #include "mozilla/dom/Element.h"
11 #include "nsContentUtils.h"
13 namespace mozilla {
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;
24 dom::Document* doc = aStyleRoot->OwnerDoc();
25 MOZ_ASSERT(doc == aStyleRoot);
26 if (dom::Element* root = doc->GetRootElement()) {
27 mStyleRoots.AppendElement(root);
29 nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(doc, mStyleRoots);
32 dom::Element* DocumentStyleRootIterator::GetNextStyleRoot() {
33 for (;;) {
34 if (mPosition >= mStyleRoots.Length()) {
35 return nullptr;
38 nsIContent* next = mStyleRoots[mPosition];
39 ++mPosition;
41 if (next->IsElement()) {
42 return next->AsElement();
47 } // namespace mozilla