DocumentStyleRootIterator.cpp 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  4. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "DocumentStyleRootIterator.h"
  6. #include "nsContentUtils.h"
  7. namespace mozilla {
  8. DocumentStyleRootIterator::DocumentStyleRootIterator(nsIDocument* aDocument)
  9. : mPosition(0)
  10. {
  11. MOZ_COUNT_CTOR(DocumentStyleRootIterator);
  12. if (Element* root = aDocument->GetRootElement()) {
  13. mStyleRoots.AppendElement(root);
  14. }
  15. nsContentUtils::AppendDocumentLevelNativeAnonymousContentTo(
  16. aDocument, mStyleRoots);
  17. }
  18. Element*
  19. DocumentStyleRootIterator::GetNextStyleRoot()
  20. {
  21. for (;;) {
  22. if (mPosition >= mStyleRoots.Length()) {
  23. return nullptr;
  24. }
  25. nsIContent* next = mStyleRoots[mPosition];
  26. ++mPosition;
  27. if (next->IsElement()) {
  28. return next->AsElement();
  29. }
  30. }
  31. }
  32. } // namespace mozilla