/src/mozilla-central/layout/base/nsStyleSheetService.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 | | |
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 | 0 | "@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 | | SheetArray* AgentStyleSheets() |
49 | 0 | { |
50 | 0 | return &mSheets[AGENT_SHEET]; |
51 | 0 | } |
52 | | SheetArray* UserStyleSheets() |
53 | 0 | { |
54 | 0 | return &mSheets[USER_SHEET]; |
55 | 0 | } |
56 | | SheetArray* AuthorStyleSheets() |
57 | 0 | { |
58 | 0 | return &mSheets[AUTHOR_SHEET]; |
59 | 0 | } |
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 | | mozilla::Array<SheetArray, 3> mSheets; |
85 | | |
86 | | // Registered PresShells that will be notified when sheets are added and |
87 | | // removed from the style sheet service. |
88 | | nsTArray<nsCOMPtr<nsIPresShell>> mPresShells; |
89 | | }; |
90 | | |
91 | | #endif |