Bug 1550804 - Add color scheme simulation to the inspector. r=pbro
[gecko.git] / layout / style / DocumentStyleRootIterator.cpp
blobcda6667441363eecf6086ebbf9c7f2fccf2aac6a
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/Element.h"
10 #include "nsContentUtils.h"
12 namespace mozilla {
14 DocumentStyleRootIterator::DocumentStyleRootIterator(nsINode* aStyleRoot)
15 : mPosition(0) {
16 MOZ_COUNT_CTOR(DocumentStyleRootIterator);
17 MOZ_ASSERT(aStyleRoot);
18 if (aStyleRoot->IsElement()) {
19 mStyleRoots.AppendElement(aStyleRoot->AsElement());
20 return;
23 dom::Document* doc = aStyleRoot->OwnerDoc();
24 MOZ_ASSERT(doc == aStyleRoot);
25 if (Element* root = doc->GetRootElement()) {
26 mStyleRoots.AppendElement(root);
28 nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(doc, mStyleRoots);
31 Element* DocumentStyleRootIterator::GetNextStyleRoot() {
32 for (;;) {
33 if (mPosition >= mStyleRoots.Length()) {
34 return nullptr;
37 nsIContent* next = mStyleRoots[mPosition];
38 ++mPosition;
40 if (next->IsElement()) {
41 return next->AsElement();
46 } // namespace mozilla