Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / dom / base / StyleSheetList.h
blob7b097599b1dbf5103b0074f66a01f78143360124
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/. */
7 #ifndef mozilla_dom_StyleSheetList_h
8 #define mozilla_dom_StyleSheetList_h
10 #include "nsContentUtils.h"
11 #include "mozilla/dom/DocumentOrShadowRoot.h"
12 #include "nsStubMutationObserver.h"
13 #include "nsWrapperCache.h"
15 class nsINode;
17 namespace mozilla {
18 class StyleSheet;
20 namespace dom {
22 class StyleSheetList final : public nsStubMutationObserver,
23 public nsWrapperCache {
24 public:
25 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
26 NS_DECL_CYCLE_COLLECTION_WRAPPERCACHE_CLASS(StyleSheetList)
28 NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
30 explicit StyleSheetList(DocumentOrShadowRoot& aScope);
32 JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) final;
34 nsINode* GetParentObject() const {
35 return mDocumentOrShadowRoot ? &mDocumentOrShadowRoot->AsNode() : nullptr;
38 uint32_t Length() const {
39 return mDocumentOrShadowRoot ? mDocumentOrShadowRoot->SheetCount() : 0;
42 StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) const {
43 if (!mDocumentOrShadowRoot) {
44 aFound = false;
45 return nullptr;
48 StyleSheet* sheet = mDocumentOrShadowRoot->SheetAt(aIndex);
49 aFound = !!sheet;
50 return sheet;
53 StyleSheet* Item(uint32_t aIndex) const {
54 bool dummy = false;
55 return IndexedGetter(aIndex, dummy);
58 protected:
59 virtual ~StyleSheetList();
61 DocumentOrShadowRoot*
62 mDocumentOrShadowRoot; // Weak, cleared on "NodeWillBeDestroyed".
65 } // namespace dom
66 } // namespace mozilla
68 #endif // mozilla_dom_StyleSheetList_h