/src/mozilla-central/dom/base/nsIDocumentInlines.h
Line | Count | Source (jump to first uncovered line) |
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 nsIDocumentInlines_h |
7 | | #define nsIDocumentInlines_h |
8 | | |
9 | | #include "nsContentUtils.h" |
10 | | #include "nsIDocument.h" |
11 | | #include "mozilla/dom/HTMLBodyElement.h" |
12 | | #include "nsStyleSheetService.h" |
13 | | |
14 | | inline mozilla::dom::HTMLBodyElement* |
15 | | nsIDocument::GetBodyElement() |
16 | 0 | { |
17 | 0 | return static_cast<mozilla::dom::HTMLBodyElement*>(GetHtmlChildElement(nsGkAtoms::body)); |
18 | 0 | } |
19 | | |
20 | | template<typename T> |
21 | | size_t |
22 | | nsIDocument::FindDocStyleSheetInsertionPoint( |
23 | | const nsTArray<T>& aDocSheets, |
24 | | const mozilla::StyleSheet& aSheet) |
25 | 0 | { |
26 | 0 | nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance(); |
27 | 0 |
|
28 | 0 | // lowest index first |
29 | 0 | int32_t newDocIndex = IndexOfSheet(aSheet); |
30 | 0 |
|
31 | 0 | size_t count = aDocSheets.Length(); |
32 | 0 | size_t index = 0; |
33 | 0 | for (; index < count; index++) { |
34 | 0 | auto* sheet = static_cast<mozilla::StyleSheet*>(aDocSheets[index]); |
35 | 0 | MOZ_ASSERT(sheet); |
36 | 0 | int32_t sheetDocIndex = IndexOfSheet(*sheet); |
37 | 0 | if (sheetDocIndex > newDocIndex) |
38 | 0 | break; |
39 | 0 | |
40 | 0 | // If the sheet is not owned by the document it can be an author |
41 | 0 | // sheet registered at nsStyleSheetService or an additional author |
42 | 0 | // sheet on the document, which means the new |
43 | 0 | // doc sheet should end up before it. |
44 | 0 | if (sheetDocIndex < 0) { |
45 | 0 | if (sheetService) { |
46 | 0 | auto& authorSheets = *sheetService->AuthorStyleSheets(); |
47 | 0 | if (authorSheets.IndexOf(sheet) != authorSheets.NoIndex) { |
48 | 0 | break; |
49 | 0 | } |
50 | 0 | } |
51 | 0 | if (sheet == GetFirstAdditionalAuthorSheet()) { |
52 | 0 | break; |
53 | 0 | } |
54 | 0 | } |
55 | 0 | } |
56 | 0 |
|
57 | 0 | return size_t(index); |
58 | 0 | } |
59 | | |
60 | | inline void |
61 | | nsIDocument::SetServoRestyleRoot(nsINode* aRoot, uint32_t aDirtyBits) |
62 | 0 | { |
63 | 0 | MOZ_ASSERT(aRoot); |
64 | 0 |
|
65 | 0 | MOZ_ASSERT(!mServoRestyleRoot || |
66 | 0 | mServoRestyleRoot == aRoot || |
67 | 0 | nsContentUtils::ContentIsFlattenedTreeDescendantOfForStyle(mServoRestyleRoot, aRoot)); |
68 | 0 | MOZ_ASSERT(aRoot == aRoot->OwnerDocAsNode() || aRoot->IsElement()); |
69 | 0 | mServoRestyleRoot = aRoot; |
70 | 0 | SetServoRestyleRootDirtyBits(aDirtyBits); |
71 | 0 | } |
72 | | |
73 | | // Note: we break this out of SetServoRestyleRoot so that callers can add |
74 | | // bits without doing a no-op assignment to the restyle root, which would |
75 | | // involve cycle-collected refcount traffic. |
76 | | inline void |
77 | | nsIDocument::SetServoRestyleRootDirtyBits(uint32_t aDirtyBits) |
78 | 0 | { |
79 | 0 | MOZ_ASSERT(aDirtyBits); |
80 | 0 | MOZ_ASSERT((aDirtyBits & ~Element::kAllServoDescendantBits) == 0); |
81 | 0 | MOZ_ASSERT((aDirtyBits & mServoRestyleRootDirtyBits) == mServoRestyleRootDirtyBits); |
82 | 0 | MOZ_ASSERT(mServoRestyleRoot); |
83 | 0 | mServoRestyleRootDirtyBits = aDirtyBits; |
84 | 0 | } |
85 | | |
86 | | |
87 | | #endif // nsIDocumentInlines_h |