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 :
7 : /* implementation of interface for managing user and user-agent style sheets */
8 :
9 : #ifndef nsStyleSheetService_h_
10 : #define nsStyleSheetService_h_
11 :
12 : #include "nsCOMArray.h"
13 : #include "nsCOMPtr.h"
14 : #include "nsIMemoryReporter.h"
15 : #include "nsIStyleSheetService.h"
16 : #include "mozilla/Array.h"
17 : #include "mozilla/Attributes.h"
18 : #include "mozilla/MemoryReporting.h"
19 : #include "mozilla/StyleSheet.h"
20 :
21 : class nsICategoryManager;
22 : class nsIMemoryReporter;
23 : class nsIPresShell;
24 : class nsISimpleEnumerator;
25 :
26 : #define NS_STYLESHEETSERVICE_CID \
27 : { 0x3b55e72e, 0xab7e, 0x431b, \
28 : { 0x89, 0xc0, 0x3b, 0x06, 0xa8, 0xb1, 0x40, 0x16 } }
29 :
30 : #define NS_STYLESHEETSERVICE_CONTRACTID \
31 : "@mozilla.org/content/style-sheet-service;1"
32 :
33 : class nsStyleSheetService final
34 : : public nsIStyleSheetService
35 : , public nsIMemoryReporter
36 : {
37 : public:
38 : typedef nsTArray<RefPtr<mozilla::StyleSheet>> SheetArray;
39 :
40 : nsStyleSheetService();
41 :
42 : NS_DECL_ISUPPORTS
43 : NS_DECL_NSISTYLESHEETSERVICE
44 : NS_DECL_NSIMEMORYREPORTER
45 :
46 : nsresult Init();
47 :
48 9 : SheetArray* AgentStyleSheets(mozilla::StyleBackendType aType)
49 : {
50 9 : return &Sheets(aType)[AGENT_SHEET];
51 : }
52 9 : SheetArray* UserStyleSheets(mozilla::StyleBackendType aType)
53 : {
54 9 : return &Sheets(aType)[USER_SHEET];
55 : }
56 30 : SheetArray* AuthorStyleSheets(mozilla::StyleBackendType aType)
57 : {
58 30 : return &Sheets(aType)[AUTHOR_SHEET];
59 : }
60 :
61 : void RegisterPresShell(nsIPresShell* aPresShell);
62 : void UnregisterPresShell(nsIPresShell* aPresShell);
63 :
64 : size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
65 :
66 : static nsStyleSheetService *GetInstance();
67 : static nsStyleSheetService *gInstance;
68 :
69 : private:
70 : ~nsStyleSheetService();
71 :
72 : void RegisterFromEnumerator(nsICategoryManager *aManager,
73 : const char *aCategory,
74 : nsISimpleEnumerator *aEnumerator,
75 : uint32_t aSheetType);
76 :
77 : int32_t FindSheetByURI(uint32_t aSheetType, nsIURI* aSheetURI);
78 :
79 : // Like LoadAndRegisterSheet, but doesn't notify. If successful, the
80 : // new sheet will be the last sheet in mSheets[aSheetType].
81 : nsresult LoadAndRegisterSheetInternal(nsIURI *aSheetURI,
82 : uint32_t aSheetType);
83 :
84 48 : mozilla::Array<SheetArray, 3>& Sheets(mozilla::StyleBackendType aType)
85 : {
86 : return aType == mozilla::StyleBackendType::Gecko ? mGeckoSheets
87 48 : : mServoSheets;
88 : }
89 :
90 : mozilla::Array<SheetArray, 3> mGeckoSheets;
91 : mozilla::Array<SheetArray, 3> mServoSheets;
92 :
93 : // Registered PresShells that will be notified when sheets are added and
94 : // removed from the style sheet service.
95 : nsTArray<nsCOMPtr<nsIPresShell>> mPresShells;
96 : };
97 :
98 : #endif
|