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