DocumentInlines.h (2461B)
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 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 #ifndef mozilla_dom_DocumentInlines_h 7 #define mozilla_dom_DocumentInlines_h 8 9 #include "mozilla/PresShell.h" 10 #include "mozilla/ServoStyleSet.h" 11 #include "mozilla/dom/Document.h" 12 #include "mozilla/dom/HTMLBodyElement.h" 13 #include "nsContentUtils.h" 14 #include "nsPresContext.h" 15 #include "nsStyleSheetService.h" 16 17 namespace mozilla::dom { 18 19 inline PresShell* Document::GetObservingPresShell() const { 20 return mPresShell && mPresShell->IsObservingDocument() ? mPresShell : nullptr; 21 } 22 23 inline nsPresContext* Document::GetPresContext() const { 24 PresShell* presShell = GetPresShell(); 25 return presShell ? presShell->GetPresContext() : nullptr; 26 } 27 28 inline HTMLBodyElement* Document::GetBodyElement( 29 const nsIContent* aContentToIgnore) const { 30 return static_cast<HTMLBodyElement*>( 31 GetHtmlChildElement(nsGkAtoms::body, aContentToIgnore)); 32 } 33 34 inline void Document::SetServoRestyleRoot(nsINode* aRoot, uint32_t aDirtyBits) { 35 MOZ_ASSERT(aRoot); 36 37 MOZ_ASSERT(!mServoRestyleRoot || mServoRestyleRoot == aRoot || 38 nsContentUtils::ContentIsFlattenedTreeDescendantOfForStyle( 39 mServoRestyleRoot, aRoot)); 40 MOZ_ASSERT(aRoot == aRoot->OwnerDocAsNode() || aRoot->IsElement()); 41 mServoRestyleRoot = aRoot; 42 SetServoRestyleRootDirtyBits(aDirtyBits); 43 } 44 45 // Note: we break this out of SetServoRestyleRoot so that callers can add 46 // bits without doing a no-op assignment to the restyle root, which would 47 // involve cycle-collected refcount traffic. 48 inline void Document::SetServoRestyleRootDirtyBits(uint32_t aDirtyBits) { 49 MOZ_ASSERT(aDirtyBits); 50 MOZ_ASSERT((aDirtyBits & ~Element::kAllServoDescendantBits) == 0); 51 MOZ_ASSERT((aDirtyBits & mServoRestyleRootDirtyBits) == 52 mServoRestyleRootDirtyBits); 53 MOZ_ASSERT(mServoRestyleRoot); 54 mServoRestyleRootDirtyBits = aDirtyBits; 55 } 56 57 inline ServoStyleSet& Document::EnsureStyleSet() const { 58 MOZ_ASSERT(NS_IsMainThread()); 59 if (!mStyleSet) { 60 Document* doc = const_cast<Document*>(this); 61 doc->mStyleSet = MakeUnique<ServoStyleSet>(*doc); 62 } 63 return *(mStyleSet.get()); 64 } 65 66 } // namespace mozilla::dom 67 68 #endif // mozilla_dom_DocumentInlines_h