nsStyleSheetService.h (2275B)
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 "mozilla/Array.h" 13 #include "mozilla/MemoryReporting.h" 14 #include "mozilla/StyleSheet.h" 15 #include "nsIMemoryReporter.h" 16 #include "nsIStyleSheetService.h" 17 18 class nsISimpleEnumerator; 19 20 namespace mozilla { 21 class PresShell; 22 } // namespace mozilla 23 24 #define NS_STYLESHEETSERVICE_CID \ 25 {0x3b55e72e, 0xab7e, 0x431b, {0x89, 0xc0, 0x3b, 0x06, 0xa8, 0xb1, 0x40, 0x16}} 26 27 #define NS_STYLESHEETSERVICE_CONTRACTID \ 28 "@mozilla.org/content/style-sheet-service;1" 29 30 class nsStyleSheetService final : public nsIStyleSheetService, 31 public nsIMemoryReporter { 32 public: 33 typedef nsTArray<RefPtr<mozilla::StyleSheet>> SheetArray; 34 35 nsStyleSheetService(); 36 37 NS_DECL_ISUPPORTS 38 NS_DECL_NSISTYLESHEETSERVICE 39 NS_DECL_NSIMEMORYREPORTER 40 41 nsresult Init(); 42 43 SheetArray* AgentStyleSheets() { return &mSheets[AGENT_SHEET]; } 44 SheetArray* UserStyleSheets() { return &mSheets[USER_SHEET]; } 45 SheetArray* AuthorStyleSheets() { return &mSheets[AUTHOR_SHEET]; } 46 47 void RegisterPresShell(mozilla::PresShell* aPresShell); 48 void UnregisterPresShell(mozilla::PresShell* aPresShell); 49 50 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; 51 52 static nsStyleSheetService* GetInstance(); 53 static nsStyleSheetService* gInstance; 54 55 private: 56 ~nsStyleSheetService(); 57 58 int32_t FindSheetByURI(uint32_t aSheetType, nsIURI* aSheetURI); 59 60 // Like LoadAndRegisterSheet, but doesn't notify. If successful, the 61 // new sheet will be the last sheet in mSheets[aSheetType]. 62 nsresult LoadAndRegisterSheetInternal(nsIURI* aSheetURI, uint32_t aSheetType); 63 64 mozilla::Array<SheetArray, 3> mSheets; 65 66 // Registered PresShells that will be notified when sheets are added and 67 // removed from the style sheet service. 68 nsTArray<RefPtr<mozilla::PresShell>> mPresShells; 69 }; 70 71 #endif