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
9 #include "mozilla/dom/Document.h"
11 #include "mozilla/PresShell.h"
12 #include "mozilla/ServoStyleSet.h"
13 #include "mozilla/dom/HTMLBodyElement.h"
14 #include "nsContentUtils.h"
15 #include "nsPresContext.h"
16 #include "nsStyleSheetService.h"
18 namespace mozilla::dom
{
20 inline PresShell
* Document::GetObservingPresShell() const {
21 return mPresShell
&& mPresShell
->IsObservingDocument() ? mPresShell
: nullptr;
24 inline nsPresContext
* Document::GetPresContext() const {
25 PresShell
* presShell
= GetPresShell();
26 return presShell
? presShell
->GetPresContext() : nullptr;
29 inline HTMLBodyElement
* Document::GetBodyElement(
30 const nsIContent
* aContentToIgnore
) const {
31 return static_cast<HTMLBodyElement
*>(
32 GetHtmlChildElement(nsGkAtoms::body
, aContentToIgnore
));
35 inline void Document::SetServoRestyleRoot(nsINode
* aRoot
, uint32_t aDirtyBits
) {
38 MOZ_ASSERT(!mServoRestyleRoot
|| mServoRestyleRoot
== aRoot
||
39 nsContentUtils::ContentIsFlattenedTreeDescendantOfForStyle(
40 mServoRestyleRoot
, aRoot
));
41 MOZ_ASSERT(aRoot
== aRoot
->OwnerDocAsNode() || aRoot
->IsElement());
42 mServoRestyleRoot
= aRoot
;
43 SetServoRestyleRootDirtyBits(aDirtyBits
);
46 // Note: we break this out of SetServoRestyleRoot so that callers can add
47 // bits without doing a no-op assignment to the restyle root, which would
48 // involve cycle-collected refcount traffic.
49 inline void Document::SetServoRestyleRootDirtyBits(uint32_t aDirtyBits
) {
50 MOZ_ASSERT(aDirtyBits
);
51 MOZ_ASSERT((aDirtyBits
& ~Element::kAllServoDescendantBits
) == 0);
52 MOZ_ASSERT((aDirtyBits
& mServoRestyleRootDirtyBits
) ==
53 mServoRestyleRootDirtyBits
);
54 MOZ_ASSERT(mServoRestyleRoot
);
55 mServoRestyleRootDirtyBits
= aDirtyBits
;
58 inline ServoStyleSet
& Document::EnsureStyleSet() const {
59 MOZ_ASSERT(NS_IsMainThread());
61 Document
* doc
= const_cast<Document
*>(this);
62 doc
->mStyleSet
= MakeUnique
<ServoStyleSet
>(*doc
);
64 return *(mStyleSet
.get());
67 } // namespace mozilla::dom
69 #endif // mozilla_dom_DocumentInlines_h