Line data Source code
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 "nsIDocument.h"
10 : #include "mozilla/dom/HTMLBodyElement.h"
11 : #include "nsStyleSheetService.h"
12 :
13 : inline mozilla::dom::HTMLBodyElement*
14 95 : nsIDocument::GetBodyElement()
15 : {
16 95 : return static_cast<mozilla::dom::HTMLBodyElement*>(GetHtmlChildElement(nsGkAtoms::body));
17 : }
18 :
19 : template<typename T>
20 : size_t
21 11 : nsIDocument::FindDocStyleSheetInsertionPoint(
22 : const nsTArray<T>& aDocSheets,
23 : mozilla::StyleSheet* aSheet)
24 : {
25 11 : nsStyleSheetService* sheetService = nsStyleSheetService::GetInstance();
26 :
27 : // lowest index first
28 11 : int32_t newDocIndex = GetIndexOfStyleSheet(aSheet);
29 :
30 11 : int32_t count = aDocSheets.Length();
31 : int32_t index;
32 26 : for (index = 0; index < count; index++) {
33 15 : mozilla::StyleSheet* sheet = static_cast<mozilla::StyleSheet*>(
34 30 : aDocSheets[index]);
35 15 : int32_t sheetDocIndex = GetIndexOfStyleSheet(sheet);
36 15 : if (sheetDocIndex > newDocIndex)
37 0 : break;
38 :
39 : // If the sheet is not owned by the document it can be an author
40 : // sheet registered at nsStyleSheetService or an additional author
41 : // sheet on the document, which means the new
42 : // doc sheet should end up before it.
43 15 : if (sheetDocIndex < 0) {
44 0 : if (sheetService) {
45 : auto& authorSheets =
46 0 : *sheetService->AuthorStyleSheets(GetStyleBackendType());
47 0 : if (authorSheets.IndexOf(sheet) != authorSheets.NoIndex) {
48 0 : break;
49 : }
50 : }
51 0 : if (sheet == GetFirstAdditionalAuthorSheet()) {
52 0 : break;
53 : }
54 : }
55 : }
56 :
57 11 : return size_t(index);
58 : }
59 :
60 : #endif // nsIDocumentInlines_h
|